Browse Source

Merge pull request #118 from jl777/dPoW

DPoW
master
jl777 8 years ago
committed by GitHub
parent
commit
a8feea34a5
  1. 1
      basilisk/basilisk_bitcoin.c
  2. 4
      crypto777/bitcoind_RPC.c
  3. 1
      datachain/datachain.c
  4. 541
      deprecated/obsolete.h
  5. 2
      gecko/gecko_blocks.c
  6. 2
      iguana/coins/genREVS
  7. 2
      iguana/coins/revs_7776
  8. 2
      iguana/coins/zec
  9. 44
      iguana/dPoW.h
  10. 469
      iguana/dpow/dpow_fsm.c
  11. 602
      iguana/dpow/dpow_network.c
  12. 21
      iguana/dpow/dpow_prices.c
  13. 82
      iguana/dpow/dpow_rpc.c
  14. 367
      iguana/dpow/dpow_tx.c
  15. 2
      iguana/iguana777.c
  16. 2
      iguana/iguana777.h
  17. 2
      iguana/iguana_blocks.c
  18. 10
      iguana/iguana_bundles.c
  19. 10
      iguana/iguana_chains.c
  20. 8
      iguana/iguana_msg.c
  21. 50
      iguana/iguana_notary.c
  22. 107
      iguana/iguana_ramchain.c
  23. 6
      iguana/iguana_recv.c
  24. 3
      iguana/iguana_rpc.c
  25. 2
      iguana/iguana_secp.c
  26. 15
      iguana/iguana_sign.c
  27. 2
      iguana/iguana_spendvectors.c
  28. 9
      iguana/iguana_wallet.c
  29. 73
      iguana/m_notary
  30. 28
      iguana/m_test
  31. 35
      iguana/main.c
  32. 30
      iguana/tests/addnotarys_7776
  33. 2
      iguana/tests/decoderawtransaction
  34. 2
      iguana/tests/ratifyC_7776
  35. 278
      iguana/tests/ratifyX.json
  36. 2
      iguana/tests/ratify_7776
  37. 3
      iguana/tests/ratifytest
  38. 3
      iguana/tests/sign
  39. 4
      includes/iguana_funcs.h
  40. 2
      includes/iguana_structs.h

1
basilisk/basilisk_bitcoin.c

@ -565,6 +565,7 @@ char *iguana_utxoduplicates(struct supernet_info *myinfo,struct iguana_info *coi
free(rawtx);
if ( *completedp != 0 && sendflag != 0 )
{
printf("splitfunds signedtx.(%s)\n",signedtx);
iguana_sendrawtransaction(myinfo,coin,signedtx);
}
rawtx = signedtx;

4
crypto777/bitcoind_RPC.c

@ -202,9 +202,9 @@ try_again:
free(s.ptr);
return(0);
}
else if ( numretries >= 5 )
else if ( numretries >= 2 )
{
printf("Maximum number of retries exceeded!\n");
//printf("Maximum number of retries exceeded!\n");
free(s.ptr);
return(0);
}

1
datachain/datachain.c

@ -320,6 +320,7 @@ void datachain_update_spend(struct supernet_info *myinfo,int32_t ordered,struct
int64_t datachain_update(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,uint8_t rmd160[20],int64_t crypto777_payment,uint8_t type,int32_t height,uint64_t hdrsi_unspentind,int64_t value,uint32_t fileid,uint64_t scriptpos,int32_t scriptlen,bits256 txid,int32_t vout)
{
return(0);
if ( memcmp(rmd160,CRYPTO777_RMD160,20) == 0 )
{
crypto777_payment += value;

541
deprecated/obsolete.h

@ -19657,3 +19657,544 @@ len = 0;
pthread_mutex_unlock(&komodo_mutex);
if ( n >= 1000000 )
printf("komodo_paxtotal n.%d iterations?\n",n);*/
void dpow_sync(struct supernet_info *myinfo,int32_t forceflag,struct dpow_info *dp,struct dpow_block *bp,int8_t bestk,uint64_t refmask,int32_t myind,bits256 srchash,int32_t src_or_dest)
{
int8_t lastk; uint64_t mask;
if ( bestk < 0 )
mask = dpow_maskmin(refmask,bp,&lastk);
else
{
lastk = bestk;
mask = refmask;
}
//dpow_utxosync(myinfo,bp,mask,myind,srchash);
if ( forceflag || bp->notaries[myind].masks[lastk] == 0 )
{
//printf("dpow sync update signedtxgen\n");
dpow_signedtxgen(myinfo,dp,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,lastk,mask,myind,src_or_dest != 0 ? DPOW_SIGBTCCHANNEL : DPOW_SIGCHANNEL,src_or_dest,0);
}
}
/*if ( channel == DPOW_ENTRIESCHANNEL )
{
struct dpow_entry notaries[DPOW_MAXRELAYS]; uint8_t n; int8_t bestk; struct dpow_coinentry *ptr,*refptr;
rlen = 0;
bestk = data[rlen++];
n = data[rlen++];
rlen += iguana_rwbignum(0,&data[rlen],sizeof(hashmsg),hashmsg.bytes);
//printf("got ENTRIES bestk.%d (%d %llx) recv.%llx numnotaries.%d\n",bestk,bp->bestk,(long long)bp->bestmask,(long long)bp->recvmask,n);
if ( bits256_cmp(hashmsg,bp->hashmsg) == 0 )
{
memset(notaries,0,sizeof(notaries));
for (i=0; i<64; i++)
notaries[i].bestk = -1;
rlen += dpow_rwcoinentrys(0,&data[rlen],notaries,n,bestk);
//printf("matched hashmsg rlen.%d vs datalen.%d\n",rlen,datalen);
for (i=0; i<n; i++)
{
for (iter=0; iter<2; iter++)
{
ptr = iter != 0 ? &notaries[i].dest : &notaries[i].src;
refptr = iter != 0 ? &bp->notaries[i].dest : &bp->notaries[i].src;
if ( bits256_nonz(ptr->prev_hash) != 0 )
{
if ( bits256_nonz(refptr->prev_hash) == 0 )
{
printf(">>>>>>>>> %s got utxo.[%d] indirectly <<<<<<<<<<<\n",iter!=0?"dest":"src",i);
refptr->prev_hash = ptr->prev_hash;
refptr->prev_vout = ptr->prev_vout;
if ( iter == 1 && bits256_nonz(notaries[i].src.prev_hash) != 0 )
bp->recvmask |= (1LL << i);
}
}
if ( (bestk= notaries[i].bestk) >= 0 )
{
if ( ptr->siglens[bestk] > 0 && refptr->siglens[bestk] == 0 )
{
printf(">>>>>>>>>> got %s siglen.%d for [%d] indirectly bestk.%d <<<<<<<<<<\n",iter!=0?"dest":"src",ptr->siglens[bestk],i,bestk);
memcpy(refptr->sigs[bestk],ptr->sigs[bestk],ptr->siglens[bestk]);
refptr->siglens[bestk] = ptr->siglens[bestk];
if ( iter != 0 )
bp->destsigsmasks[bestk] |= (1LL << i);
else bp->srcsigsmasks[bestk] |= (1LL << i);
}
}
}
}
}
}
else if ( channel == DPOW_UTXOCHANNEL )
{
src_or_dest = 1;
coin = (src_or_dest != 0) ? bp->destcoin : bp->srccoin;
memset(&U,0,sizeof(U));
if ( dpow_rwutxobuf(0,data,&U,bp) < 0 )
{
printf("error from rwutxobuf\n");
return(0);
}
if ( bits256_cmp(U.hashmsg,bp->hashmsg) != 0 && bits256_nonz(bp->hashmsg) != 0 )
{
printf("unexpected mismatch hashmsg.%s vs %s\n",bits256_str(str,U.hashmsg),bits256_str(str2,bp->hashmsg));
return(0);
}
if ( (ep= dpow_notaryfind(myinfo,bp,height,&senderind,U.pubkey)) != 0 )
{
dpow_utxo2entry(bp,ep,&U);
if ( ((1LL << senderind) & bp->recvmask) == 0 )
{
dpow_utxosync(myinfo,dp,bp,0,myind,srchash);
bp->recvmask |= (1LL << senderind);
}
dpow_sync(myinfo,0,dp,bp,-1,ep->recvmask,myind,srchash,src_or_dest);
flag = 1;
}
//printf("bestk.%d %llx vs recv.%llx\n",bp->bestk,(long long)bp->bestmask,(long long)bp->recvmask);
if ( 0 && flag == 0 && bp != 0 )
printf("ep.%p sender.%d UTXO.%d hashmsg.(%s) txid.(%s) v%d %llx\n",ep,senderind,height,bits256_str(str,U.hashmsg),bits256_str(str2,src_or_dest!=0?U.desthash:U.srchash),src_or_dest!=0?U.destvout:U.srcvout,(long long)bp->recvmask);
}
else if ( channel == DPOW_SIGCHANNEL || channel == DPOW_SIGBTCCHANNEL )
{
if ( dpow_rwsigentry(0,data,&dsig) < 0 )
{
printf("rwsigentry error\n");
return(0);
}
//printf("got sig.%x (%d %d) <<<<<<<<<< from.%d (%d %llx) sigs.%llx\n",channel,channel == DPOW_SIGCHANNEL,channel == DPOW_SIGBTCCHANNEL,dsig.senderind,dsig.lastk,(long long)dsig.mask,(long long)(dsig.lastk>=0?bp->destsigsmasks[dsig.lastk]:0));
if ( channel == DPOW_SIGBTCCHANNEL )
{
src_or_dest = 1;
coin = bp->destcoin;
cp = &bp->notaries[dsig.senderind].dest;
//printf("gotsig %s channel.%x from %d bestk.%d %llx\n",coin->symbol,channel,dsig.senderind,dsig.lastk,(long long)dsig.mask);
}
else
{
src_or_dest = 0;
coin = bp->srccoin;
cp = &bp->notaries[dsig.senderind].src;
}
if ( dsig.senderind >= 0 && dsig.senderind < DPOW_MAXRELAYS )
{
if ( dsig.lastk < bp->numnotaries && dsig.senderind < bp->numnotaries && (ep= dpow_notaryfind(myinfo,bp,height,&senderind,dsig.senderpub)) != 0 )
{
vcalc_sha256(0,commit.bytes,dsig.beacon.bytes,sizeof(dsig.beacon));
if ( memcmp(dsig.senderpub,bp->notaries[dsig.senderind].pubkey,33) == 0 )
{
//if ( ep->masks[dsig.lastk] == 0 )
{
ep->masks[src_or_dest][dsig.lastk] = dsig.mask;
cp->siglens[dsig.lastk] = dsig.siglen;
memcpy(cp->sigs[dsig.lastk],dsig.sig,dsig.siglen);
ep->beacon = dsig.beacon;
if ( src_or_dest != 0 )
{
bp->destsigsmasks[dsig.lastk] |= (1LL << dsig.senderind);
if ( bp->bestk >= 0 && bp->bestk == dsig.lastk && (bp->bestmask & bp->destsigsmasks[dsig.lastk]) == bp->bestmask )
{
dpow_sigscheck(myinfo,dp,bp,DPOW_SIGBTCCHANNEL,myind,1);
}
}
else
{
bp->srcsigsmasks[dsig.lastk] |= (1LL << dsig.senderind);
if ( bp->bestk >= 0 && bp->bestk == dsig.lastk && (bp->bestmask & bp->srcsigsmasks[dsig.lastk]) == bp->bestmask )
{
dpow_sigscheck(myinfo,dp,bp,DPOW_SIGCHANNEL,myind,0);
}
}
//printf(" ht.%d (%d %llx) <<<<<<<< %s from.%d got lastk.%d %llx/%llx siglen.%d >>>>>>>>>\n",bp->height,bp->bestk,(long long)bp->bestmask,coin->symbol,dsig.senderind,dsig.lastk,(long long)dsig.mask,(long long)bp->destsigsmasks[dsig.lastk],dsig.siglen);
dpow_sync(myinfo,1,dp,bp,dsig.lastk,dsig.mask,myind,srchash,src_or_dest);
flag = 1;
}
} else printf("%s pubkey mismatch for senderind.%d %llx vs %llx\n",coin->symbol,dsig.senderind,*(long long *)dsig.senderpub,*(long long *)bp->notaries[dsig.senderind].pubkey);
} else printf("%s illegal lastk.%d or senderind.%d or senderpub.%llx\n",coin->symbol,dsig.lastk,dsig.senderind,*(long long *)dsig.senderpub);
} else printf("couldnt find senderind.%d height.%d channel.%x\n",dsig.senderind,height,channel);
//if ( 0 && bp != 0 )
// printf("%s SIG.%d sender.%d lastk.%d mask.%llx siglen.%d recv.%llx\n",coin->symbol,height,dsig.senderind,dsig.lastk,(long long)dsig.mask,dsig.siglen,(long long)bp->recvmask);
}
else*/
int32_t dpow_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint32_t txidchannel,bits256 srchash,int32_t myind)
{
struct dpow_entry *ep; int32_t i,k,len,src_or_dest,sendutxo = 0; uint8_t data[sizeof(struct dpow_entry)+2]; struct dpow_utxoentry U;
ep = &bp->notaries[myind];
if ( bp->state < 1000 )
{
src_or_dest = 1;
bp->bestmask = dpow_maskmin(bp->recvmask,bp,&bp->bestk);
if ( bp->bestk >= 0 )
{
sendutxo = 0;
for (i=0; i<bp->numnotaries; i++)
{
k = DPOW_MODIND(bp,i);
if ( k == myind )
continue;
if ( ((1LL << k) & bp->recvmask) != 0 && (bp->notaries[k].recvmask & (1LL << myind)) == 0 )
{
//printf("other notary.%d doesnt have our.%d utxo yet\n",k,myind);
sendutxo = 1;
break;
}
}
if ( ep->masks[src_or_dest][bp->bestk] == 0 )
{
//printf("dpow update signedtxgen\n");
dpow_signedtxgen(myinfo,dp,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,DPOW_SIGBTCCHANNEL,src_or_dest,0);
}
if ( bp->bestk >= 0 && (rand() % 10) == 0 )
dpow_sigsend(myinfo,dp,bp,myind,bp->bestk,bp->bestmask,srchash,DPOW_SIGBTCCHANNEL);
} else sendutxo = 1;
if ( sendutxo != 0 )
{
memset(&U,0,sizeof(U));
dpow_entry2utxo(&U,bp,&bp->notaries[myind]);
if ( (len= dpow_rwutxobuf(1,data,&U,bp)) > 0 )
dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,DPOW_UTXOCHANNEL,bp->height,data,len);
}
if ( bp->bestk >= 0 && ep->masks[src_or_dest][bp->bestk] == 0 )
{
//printf("dpow update2 signedtxgen\n");
dpow_signedtxgen(myinfo,dp,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,DPOW_SIGBTCCHANNEL,src_or_dest,0);
}
if ( bp->bestk >= 0 && (rand() % 10) == 0 )
{
dpow_sigsend(myinfo,dp,bp,myind,bp->bestk,bp->bestmask,srchash,DPOW_SIGBTCCHANNEL);
for (i=0; i<bp->numnotaries; i++)
if ( bp->notaries[i].bestk >= 0 && bp->notaries[i].bestk != bp->bestk && bitweight(bp->notaries[i].recvmask & bp->recvmask) >= 7 )
dpow_sigsend(myinfo,dp,bp,myind,bp->notaries[i].bestk,bp->recvmask,srchash,DPOW_SIGBTCCHANNEL);
}
}
else if ( bp->state != 0xffffffff )
{
src_or_dest = 0;
if ( bp->bestk >= 0 && ep->masks[src_or_dest][bp->bestk] == 0 )
{
//printf("dpow update src signedtxgen\n");
dpow_signedtxgen(myinfo,dp,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,DPOW_SIGCHANNEL,src_or_dest,0);
}
if ( bp->bestk >= 0 && (rand() % 10) == 0 )
dpow_sigsend(myinfo,dp,bp,myind,bp->bestk,bp->bestmask,srchash,DPOW_SIGCHANNEL);
}
if ( (rand() % 20) == 0 )
{
if ( bp->isratify != 0 )
{
uint64_t sigsmask,srcmask;
if ( bp->bestk < 0 )
sigsmask = srcmask = 0;
else sigsmask = bp->destsigsmasks[bp->bestk], srcmask = bp->srcsigsmasks[bp->bestk];
printf("notary[%d] %s numips.%d isratify.%d ht.%d FSM.%08x masks.%llx best.(%d %llx) sigsmask.%llx %llx src.%llx\n",myind,src_or_dest != 0 ? bp->destcoin->symbol : bp->srccoin->symbol,myinfo->numdpowipbits,bp->isratify,bp->height,bp->state,(long long)bp->recvmask,bp->bestk,(long long)bp->bestmask,(long long)sigsmask,(long long)(sigsmask & bp->bestmask),(long long)srcmask);
}
if ( bp->isratify != 0 )
{
bp->bestmask = dpow_maskmin(bp->recvmask,bp,&bp->bestk);
dpow_sendcoinentrys(myinfo,dp,bp);
if ( bp->bestk >= 0 )
{
//printf("dpow update ratify signedtxgen\n");
dpow_signedtxgen(myinfo,dp,(bp->state < 1000) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,bp->state < 1000 ? DPOW_SIGBTCCHANNEL : DPOW_SIGCHANNEL,bp->state < 1000,0);
}
printf("ht.%d numnotaries.%d BEST.%llx from RECV.%llx bestk.%d sigsmask.%llx missing.%llx\n",bp->height,bp->numnotaries,(long long)bp->bestmask,(long long)bp->recvmask,bp->bestk,bp->bestk>=0?(long long)bp->destsigsmasks[bp->bestk]:0,bp->bestk>=0?(long long)(bp->bestmask & ~bp->destsigsmasks[bp->bestk]):0);
if ( bp->height < DPOW_FIRSTRATIFY )
dp->blocks[bp->height] = bp;
}
}
if ( bp->state < 1000 && bp->bestk >= 0 && (bp->destsigsmasks[bp->bestk] & bp->bestmask) == bp->bestmask )
{
dpow_sigscheck(myinfo,dp,bp,myind,1);
}
else if ( bp->state != 0xffffffff && bp->bestk >= 0 && (bp->srcsigsmasks[bp->bestk] & bp->bestmask) == bp->bestmask )
{
dpow_sigscheck(myinfo,dp,bp,myind,0);
}
return(bp->state);
}
uint32_t dpow_statemachineiterate(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,struct dpow_block *bp,int32_t myind,int32_t src_or_dest)
{
int32_t j,incr; char *opret_symbol,coinaddr[64]; uint32_t channel,sigchannel,txidchannel; bits256 srchash,zero;
if ( 0 && bp->numnotaries > 8 )
incr = sqrt(bp->numnotaries) + 1;
else incr = 1;
memset(zero.bytes,0,sizeof(zero));
channel = DPOW_UTXOCHANNEL;
if ( bits256_nonz(bp->desttxid) == 0 )
{
sigchannel = DPOW_SIGBTCCHANNEL;
txidchannel = DPOW_BTCTXIDCHANNEL;
opret_symbol = "";
}
else
{
sigchannel = DPOW_SIGCHANNEL;
txidchannel = DPOW_TXIDCHANNEL;
opret_symbol = dp->symbol;
}
bitcoin_address(coinaddr,coin->chain->pubtype,dp->minerkey33,33);
if ( bits256_nonz(bp->hashmsg) == 0 && bp->height >= DPOW_FIRSTRATIFY )
{
printf("null hashmsg\n");
return(0);
}
for (j=0; j<sizeof(srchash); j++)
srchash.bytes[j] = dp->minerkey33[j+1];
bp->bestk = dpow_bestk(bp,&bp->bestmask);
if ( bp->state < 7 )
{
dpow_utxosync(myinfo,dp,bp,0,myind,srchash);
bp->state++;
}
else
{
dpow_update(myinfo,dp,bp,txidchannel,srchash,myind);
if ( bits256_nonz(bp->srctxid) != 0 )
bp->state = 0xffffffff;
}
return(bp->state);
}
/*int32_t dpow_voutratify(struct dpow_block *bp,uint8_t *serialized,int32_t m,uint8_t pubkeys[][33],int32_t numratified)
{
uint64_t satoshis; uint32_t locktime = 0; uint32_t numvouts; int32_t i,len = 0;
numvouts = numratified + 1;
len += iguana_rwvarint32(1,&serialized[len],&numvouts);
satoshis = DPOW_UTXOSIZE;
len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis);
serialized[len++] = 35;
serialized[len++] = 33;
decode_hex(&serialized[len],33,CRYPTO777_PUBSECPSTR), len += 33;
serialized[len++] = CHECKSIG;
satoshis = DPOW_MINOUTPUT;
for (i=0; i<numratified; i++)
{
len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis);
serialized[len++] = 35;
serialized[len++] = 33;
memcpy(&serialized[len],pubkeys[i],33), len += 33;
serialized[len++] = CHECKSIG;
}
len += iguana_rwnum(1,&serialized[len],sizeof(locktime),&locktime);
printf("numvouts.%d len.%d RATIFY vouts\n",numvouts,len);
return(len);
}*/
int32_t dpow_rwcoinentry(int32_t rwflag,uint8_t *serialized,struct dpow_coinentry *src,struct dpow_coinentry *dest,int8_t *bestkp)
{
int8_t bestk; struct dpow_coinentry *ptr; int32_t siglen,iter,len = 0;
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(src->prev_hash),src->prev_hash.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(src->prev_vout),(uint32_t *)&src->prev_vout);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(dest->prev_hash),dest->prev_hash.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(dest->prev_vout),(uint32_t *)&dest->prev_vout);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(*bestkp),(uint32_t *)bestkp);
if ( (bestk= *bestkp) >= 0 )
{
for (iter=0; iter<2; iter++)
{
ptr = (iter == 0) ? src : dest;
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->siglens[bestk]),(uint32_t *)&ptr->siglens[bestk]);
if ( (siglen= ptr->siglens[bestk]) > 0 )
{
if ( rwflag != 0 )
memcpy(&serialized[len],ptr->sigs[bestk],siglen);
else memcpy(ptr->sigs[bestk],&serialized[len],siglen);
len += siglen;
}
}
}
return(len);
}
int32_t dpow_rwcoinentrys(int32_t rwflag,uint8_t *serialized,struct dpow_entry notaries[DPOW_MAXRELAYS],uint8_t numnotaries,int8_t bestk)
{
int32_t i,len = 0;
for (i=0; i<numnotaries; i++)
{
if ( rwflag != 0 )
notaries[i].bestk = bestk;
len += dpow_rwcoinentry(rwflag,&serialized[len],&notaries[i].src,&notaries[i].dest,&notaries[i].bestk);
}
return(len);
}
int32_t dpow_sendcoinentrys(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp)
{
uint8_t data[sizeof(struct dpow_coinentry)*64 + 4096]; bits256 zero; int32_t len = 0;
memset(zero.bytes,0,sizeof(zero));
//printf("ht.%d >>>>>>>>>>>>> dpow_sendcoinentrys (%d %llx) <- %llx\n",bp->height,bp->bestk,(long long)bp->bestmask,(long long)bp->recvmask);
data[len++] = bp->bestk;
data[len++] = bp->numnotaries;
len += iguana_rwbignum(1,&data[len],sizeof(bp->hashmsg),bp->hashmsg.bytes);
len += dpow_rwcoinentrys(1,&data[len],bp->notaries,bp->numnotaries,bp->bestk);
dpow_send(myinfo,dp,bp,zero,bp->hashmsg,DPOW_ENTRIESCHANNEL,bp->height,data,len);
return(len);
}
int32_t dpow_rwutxobuf(int32_t rwflag,uint8_t *data,struct dpow_utxoentry *up,struct dpow_block *bp)
{
uint8_t numnotaries; uint64_t othermask; int32_t i,len = 0;
len += iguana_rwbignum(rwflag,&data[len],sizeof(up->hashmsg),up->hashmsg.bytes);
len += iguana_rwbignum(rwflag,&data[len],sizeof(up->srchash),up->srchash.bytes);
len += iguana_rwbignum(rwflag,&data[len],sizeof(up->desthash),up->desthash.bytes);
if ( bits256_nonz(up->srchash) == 0 || bits256_nonz(up->desthash) == 0 )
{
printf("dpow_rwutxobuf null src.%d or dest.%d\n",bits256_nonz(up->srchash),bits256_nonz(up->desthash));
return(-1);
}
len += iguana_rwbignum(rwflag,&data[len],sizeof(up->commit),up->commit.bytes);
len += iguana_rwnum(rwflag,&data[len],sizeof(up->recvmask),(uint8_t *)&up->recvmask);
len += iguana_rwnum(rwflag,&data[len],sizeof(up->height),(uint8_t *)&up->height);
len += iguana_rwnum(rwflag,&data[len],sizeof(up->srcvout),&up->srcvout);
len += iguana_rwnum(rwflag,&data[len],sizeof(up->destvout),&up->destvout);
len += iguana_rwnum(rwflag,&data[len],sizeof(up->bestk),&up->bestk);
if ( rwflag != 0 )
{
for (i=0; i<33; i++)
data[len++] = up->pubkey[i];
data[len++] = bp->numnotaries;
for (i=0; i<bp->numnotaries; i++)
len += iguana_rwnum(rwflag,&data[len],sizeof(*up->othermasks),(uint8_t *)&up->othermasks[(int32_t)i]);
}
else
{
for (i=0; i<33; i++)
up->pubkey[i] = data[len++];
numnotaries = data[len++];
if ( numnotaries <= bp->numnotaries )
{
for (i=0; i<numnotaries; i++)
{
len += iguana_rwnum(rwflag,&data[len],sizeof(othermask),(uint8_t *)&othermask);
bp->notaries[(int32_t)i].othermask |= othermask;
}
} else return(-1);
}
return(len);
}
/*void dpow_utxosync(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint64_t recvmask,int32_t myind,bits256 srchash)
{
uint32_t i,j,r; int32_t len; struct dpow_utxoentry U; uint8_t utxodata[sizeof(U)+2];
if ( (bp->recvmask ^ recvmask) != 0 )
{
if ( ((1LL << myind) & recvmask) == 0 )
{
i = myind;
//printf("utxosync bp->%llx != %llx, myind.%d\n",(long long)bp->recvmask,(long long)recvmask,myind);
}
else
{
r = (rand() % bp->numnotaries);
for (j=0; j<bp->numnotaries; j++)
{
i = DPOW_MODIND(bp,j+r);
if ( ((1LL << i) & bp->recvmask) != 0 && ((1LL << i) & recvmask) == 0 )
break;
}
//printf("utxosync bp->%llx != %llx, random pick.%d\n",(long long)bp->recvmask,(long long)recvmask,i);
}
memset(&U,0,sizeof(U));
dpow_entry2utxo(&U,bp,&bp->notaries[i]);
//char str[65],str2[65];
//printf("send.(%s %s)\n",bits256_str(str,bp->notaries[i].dest.prev_hash),bits256_str(str2,bp->notaries[i].src.prev_hash));
if ( (len= dpow_rwutxobuf(1,utxodata,&U,bp)) > 0 )
dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,DPOW_UTXOCHANNEL,bp->height,utxodata,len);
}
}*/
/*else if ( strcmp(dp->symbol,"KMD") == 0 )
{
bp->bestk = -1;
bp->bestmask = 0;
bp->height = ((dp->checkpoint.blockhash.height / 10) % (DPOW_FIRSTRATIFY/10)) * 10;
printf("new rotation ht.%d\n",bp->height);
dp->blocks[checkpoint.blockhash.height] = 0;
checkpoint.blockhash.height = dp->checkpoint.blockhash.height;
dp->blocks[checkpoint.blockhash.height] = bp;
}*/
/*if ( Minerids[height] >= -1 )
{
printf("cached[%d] -> %d\n",height,Minerids[height]);
return(Minerids[height]);
}
if ( depth < 1 )
{
if ( (pindex= chainActive[height]) != 0 )
{
depth++;
komodo_index2pubkey33(pubkey33,pindex,height);
komodo_chosennotary(&notaryid,height,pubkey33);
if ( notaryid >= -1 )
{
Minerids[height] = notaryid;
if ( Minerfp != 0 )
{
fseek(Minerfp,height,SEEK_SET);
fputc(Minerids[height],Minerfp);
fflush(Minerfp);
}
}
depth--;
return(notaryid);
}
}
return(-2);*/
if ( Minerids[height-i] == -2 )
{
Minerids[height-i] = komodo_minerid(height-i);
if ( Minerids[height - i] == -2 )
{
fprintf(stderr,"second -2 for Minerids[%d] current.%d\n",height-i,height);
return(-2);
}
}
if ( Minerids[height-i] == notaryid )
return(-1);
/*if ( i == 0 && j == 0 && komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 )
{
if ( height < sizeof(Minerids)/sizeof(*Minerids) )
{
if ( (Minerids[height]= nid) >= -1 )
{
if ( Minerfp != 0 )
{
fseek(Minerfp,height,SEEK_SET);
fputc(Minerids[height],Minerfp);
fflush(Minerfp);
}
}
}
}*/
uint8_t pubkeys[64][33];
if ( pindex->nHeight > 73673 && komodo_notaries(pubkeys,76000) == 35 )
{
static int32_t didinit;
if ( didinit == 0 )
{
if ( (pindex= chainActive[73673]) != 0 )
{
komodo_connectpindex(pindex);
}
didinit = 73673;
}
}
if ( i != 0 && notaryid >= 0 && notaryid < 64 && voutmask != 0 )
{
//komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0,0,0,0,0);
}
/*if ( (k= komodo_nutxofind(height,block.vtx[i].vin[j].prevout.hash,block.vtx[i].vin[j].prevout.n)) >= 0 )
signedmask |= (1LL << k);
else if ( signedmask != 0 )
printf("signedmask.%llx but ht.%d i.%d j.%d not found (%s %d)\n",(long long)signedmask,height,i,j,block.vtx[i].vin[j].prevout.hash.ToString().c_str(),block.vtx[i].vin[j].prevout.n);*/
/*memset(Minerids,0xfe,sizeof(Minerids));
if ( (Minerfp= fopen(fname2,"rb+")) == 0 )
{
if ( (Minerfp= fopen(fname2,"wb")) != 0 )
{
fwrite(Minerids,1,sizeof(Minerids),Minerfp);
fclose(Minerfp);
}
Minerfp = fopen(fname2,"rb+");
}
if ( Minerfp != 0 && fread(Minerids,1,sizeof(Minerids),Minerfp) != sizeof(Minerids) )
printf("read error Minerids\n");*/

2
gecko/gecko_blocks.c

@ -132,7 +132,7 @@ int32_t gecko_hwmset(struct supernet_info *myinfo,struct iguana_info *virt,struc
printf("no bundle for %s.%d\n",virt->symbol,block->height);
return(-1);
}
if ( iguana_ramchain_data(myinfo,virt,addr,txdata,txarray,block->RO.txn_count,data,datalen,bp,block,0) >= 0 )
if ( iguana_ramchain_data(myinfo,virt,addr,txdata,txarray,block->RO.txn_count,data,datalen,bp,block) >= 0 )
{
block->fpipbits = (uint32_t)addr->ipbits;
block->RO.recvlen = datalen;

2
iguana/coins/genREVS

@ -0,0 +1,2 @@
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"REVS.conf\",\"path\":\"${HOME#"/"}/.komodo/REVS\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"REVS\",\"name\":\"REVS\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"905c3498\",\"p2p\":10195,\"rpc\":10196,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}"

2
iguana/coins/revs_7776

@ -0,0 +1,2 @@
curl --url "http://127.0.0.1:7776" --data "{\"conf\":\"REVS.conf\",\"path\":\"${HOME#"/"}/.komodo/REVS\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"REVS\",\"name\":\"REVS\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"905c3498\",\"p2p\":10195,\"rpc\":10196,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}"

2
iguana/coins/zec

@ -1,3 +1,3 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"path\":\"${HOME#"/"}/.zcash\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":8,\"endpend\":8,\"services\":129,\"maxpeers\":32,\"newcoin\":\"ZEC\",\"name\":\"Zcash\",\"hasheaders\":0,\"useaddmultisig\":0,\"netmagic\":\"24e92764\",\"p2p\":8233,\"rpc\":8232,\"pubval\":184,\"p2shval\":189,\"wifval\":128,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"00040fe8ec8471911baa1db1266ea15dd06b4a8a5c453883c000b031973dce08\",\"protover\":170002,\"genesisblock\":\"040000000000000000000000000000000000000000000000000000000000000000000000db4d7a85b768123f1dff1d4c4cece70083b2d27e117b4ac2e31d087988a5eac4000000000000000000000000000000000000000000000000000000000000000090041358ffff071f5712000000000000000000000000000000000000000000000000000000000000fd4005000a889f00854b8665cd555f4656f68179d31ccadc1b1f7fb0952726313b16941da348284d67add4686121d4e3d930160c1348d8191c25f12b267a6a9c131b5031cbf8af1f79c9d513076a216ec87ed045fa966e01214ed83ca02dc1797270a454720d3206ac7d931a0a680c5c5e099057592570ca9bdf6058343958b31901fce1a15a4f38fd347750912e14004c73dfe588b903b6c03166582eeaf30529b14072a7b3079e3a684601b9b3024054201f7440b0ee9eb1a7120ff43f713735494aa27b1f8bab60d7f398bca14f6abb2adbf29b04099121438a7974b078a11635b594e9170f1086140b4173822dd697894483e1c6b4e8b8dcd5cb12ca4903bc61e108871d4d915a9093c18ac9b02b6716ce1013ca2c1174e319c1a570215bc9ab5f7564765f7be20524dc3fdf8aa356fd94d445e05ab165ad8bb4a0db096c097618c81098f91443c719416d39837af6de85015dca0de89462b1d8386758b2cf8a99e00953b308032ae44c35e05eb71842922eb69797f68813b59caf266cb6c213569ae3280505421a7e3a0a37fdf8e2ea354fc5422816655394a9454bac542a9298f176e211020d63dee6852c40de02267e2fc9d5e1ff2ad9309506f02a1a71a0501b16d0d36f70cdfd8de78116c0c506ee0b8ddfdeb561acadf31746b5a9dd32c21930884397fb1682164cb565cc14e089d66635a32618f7eb05fe05082b8a3fae620571660a6b89886eac53dec109d7cbb6930ca698a168f301a950be152da1be2b9e07516995e20baceebecb5579d7cdbc16d09f3a50cb3c7dffe33f26686d4ff3f8946ee6475e98cf7b3cf9062b6966e838f865ff3de5fb064a37a21da7bb8dfd2501a29e184f207caaba364f36f2329a77515dcb710e29ffbf73e2bbd773fab1f9a6b005567affff605c132e4e4dd69f36bd201005458cfbd2c658701eb2a700251cefd886b1e674ae816d3f719bac64be649c172ba27a4fd55947d95d53ba4cbc73de97b8af5ed4840b659370c556e7376457f51e5ebb66018849923db82c1c9a819f173cccdb8f3324b239609a300018d0fb094adf5bd7cbb3834c69e6d0b3798065c525b20f040e965e1a161af78ff7561cd874f5f1b75aa0bc77f720589e1b810f831eac5073e6dd46d00a2793f70f7427f0f798f2f53a67e615e65d356e66fe40609a958a05edb4c175bcc383ea0530e67ddbe479a898943c6e3074c6fcc252d6014de3a3d292b03f0d88d312fe221be7be7e3c59d07fa0f2f4029e364f1f355c5d01fa53770d0cd76d82bf7e60f6903bc1beb772e6fde4a70be51d9c7e03c8d6d8dfb361a234ba47c470fe630820bbd920715621b9fbedb49fcee165ead0875e6c2b1af16f50b5d6140cc981122fcbcf7c5a4e3772b3661b628e08380abc545957e59f634705b1bbde2f0b4e055a5ec5676d859be77e20962b645e051a880fddb0180b4555789e1f9344a436a84dc5579e2553f1e5fb0a599c137be36cabbed0319831fea3fddf94ddc7971e4bcf02cdc93294a9aab3e3b13e3b058235b4f4ec06ba4ceaa49d675b4ba80716f3bc6976b1fbf9c8bf1f3e3a4dc1cd83ef9cf816667fb94f1e923ff63fef072e6a19321e4812f96cb0ffa864da50ad74deb76917a336f31dce03ed5f0303aad5e6a83634f9fcc371096f8288b8f02ddded5ff1bb9d49331e4a84dbe1543164438fde9ad71dab024779dcdde0b6602b5ae0a6265c14b94edd83b37403f4b78fcd2ed555b596402c28ee81d87a909c4e8722b30c71ecdd861b05f61f8b1231795c76adba2fdefa451b283a5d527955b9f3de1b9828e7b2e74123dd47062ddcc09b05e7fa13cb2212a6fdbc65d7e852cec463ec6fd929f5b8483cf3052113b13dac91b69f49d1b7d1aec01c4a68e41ce157\",\"debug\":0}"
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"zcash.conf\",\"path\":\"${HOME#"/"}/.zcash\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":8,\"endpend\":8,\"services\":129,\"maxpeers\":32,\"newcoin\":\"ZEC\",\"name\":\"Zcash\",\"hasheaders\":0,\"useaddmultisig\":0,\"netmagic\":\"24e92764\",\"p2p\":8233,\"rpc\":8232,\"pubval\":184,\"p2shval\":189,\"wifval\":128,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"00040fe8ec8471911baa1db1266ea15dd06b4a8a5c453883c000b031973dce08\",\"protover\":170002,\"genesisblock\":\"040000000000000000000000000000000000000000000000000000000000000000000000db4d7a85b768123f1dff1d4c4cece70083b2d27e117b4ac2e31d087988a5eac4000000000000000000000000000000000000000000000000000000000000000090041358ffff071f5712000000000000000000000000000000000000000000000000000000000000fd4005000a889f00854b8665cd555f4656f68179d31ccadc1b1f7fb0952726313b16941da348284d67add4686121d4e3d930160c1348d8191c25f12b267a6a9c131b5031cbf8af1f79c9d513076a216ec87ed045fa966e01214ed83ca02dc1797270a454720d3206ac7d931a0a680c5c5e099057592570ca9bdf6058343958b31901fce1a15a4f38fd347750912e14004c73dfe588b903b6c03166582eeaf30529b14072a7b3079e3a684601b9b3024054201f7440b0ee9eb1a7120ff43f713735494aa27b1f8bab60d7f398bca14f6abb2adbf29b04099121438a7974b078a11635b594e9170f1086140b4173822dd697894483e1c6b4e8b8dcd5cb12ca4903bc61e108871d4d915a9093c18ac9b02b6716ce1013ca2c1174e319c1a570215bc9ab5f7564765f7be20524dc3fdf8aa356fd94d445e05ab165ad8bb4a0db096c097618c81098f91443c719416d39837af6de85015dca0de89462b1d8386758b2cf8a99e00953b308032ae44c35e05eb71842922eb69797f68813b59caf266cb6c213569ae3280505421a7e3a0a37fdf8e2ea354fc5422816655394a9454bac542a9298f176e211020d63dee6852c40de02267e2fc9d5e1ff2ad9309506f02a1a71a0501b16d0d36f70cdfd8de78116c0c506ee0b8ddfdeb561acadf31746b5a9dd32c21930884397fb1682164cb565cc14e089d66635a32618f7eb05fe05082b8a3fae620571660a6b89886eac53dec109d7cbb6930ca698a168f301a950be152da1be2b9e07516995e20baceebecb5579d7cdbc16d09f3a50cb3c7dffe33f26686d4ff3f8946ee6475e98cf7b3cf9062b6966e838f865ff3de5fb064a37a21da7bb8dfd2501a29e184f207caaba364f36f2329a77515dcb710e29ffbf73e2bbd773fab1f9a6b005567affff605c132e4e4dd69f36bd201005458cfbd2c658701eb2a700251cefd886b1e674ae816d3f719bac64be649c172ba27a4fd55947d95d53ba4cbc73de97b8af5ed4840b659370c556e7376457f51e5ebb66018849923db82c1c9a819f173cccdb8f3324b239609a300018d0fb094adf5bd7cbb3834c69e6d0b3798065c525b20f040e965e1a161af78ff7561cd874f5f1b75aa0bc77f720589e1b810f831eac5073e6dd46d00a2793f70f7427f0f798f2f53a67e615e65d356e66fe40609a958a05edb4c175bcc383ea0530e67ddbe479a898943c6e3074c6fcc252d6014de3a3d292b03f0d88d312fe221be7be7e3c59d07fa0f2f4029e364f1f355c5d01fa53770d0cd76d82bf7e60f6903bc1beb772e6fde4a70be51d9c7e03c8d6d8dfb361a234ba47c470fe630820bbd920715621b9fbedb49fcee165ead0875e6c2b1af16f50b5d6140cc981122fcbcf7c5a4e3772b3661b628e08380abc545957e59f634705b1bbde2f0b4e055a5ec5676d859be77e20962b645e051a880fddb0180b4555789e1f9344a436a84dc5579e2553f1e5fb0a599c137be36cabbed0319831fea3fddf94ddc7971e4bcf02cdc93294a9aab3e3b13e3b058235b4f4ec06ba4ceaa49d675b4ba80716f3bc6976b1fbf9c8bf1f3e3a4dc1cd83ef9cf816667fb94f1e923ff63fef072e6a19321e4812f96cb0ffa864da50ad74deb76917a336f31dce03ed5f0303aad5e6a83634f9fcc371096f8288b8f02ddded5ff1bb9d49331e4a84dbe1543164438fde9ad71dab024779dcdde0b6602b5ae0a6265c14b94edd83b37403f4b78fcd2ed555b596402c28ee81d87a909c4e8722b30c71ecdd861b05f61f8b1231795c76adba2fdefa451b283a5d527955b9f3de1b9828e7b2e74123dd47062ddcc09b05e7fa13cb2212a6fdbc65d7e852cec463ec6fd929f5b8483cf3052113b13dac91b69f49d1b7d1aec01c4a68e41ce157\",\"debug\":0}"

44
iguana/dPoW.h

@ -20,17 +20,17 @@
#define DPOW_CHECKPOINTFREQ 10
#define DPOW_MINSIGS 7
#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1)
//#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1)
#define DPOW_MODIND(bp,offset) (((((bp)->height / DPOW_CHECKPOINTFREQ) % (bp)->numnotaries) + (offset)) % (bp)->numnotaries)
#define DPOW_VERSION 0x0404
#define DPOW_VERSION 0x0757
#define DPOW_UTXOSIZE 10000
#define DPOW_MINOUTPUT 6000
#define DPOW_DURATION 300
#define DPOW_RATIFYDURATION (3600 * 24)
#define DPOW_ENTRIESCHANNEL ('e' | ('n' << 8) | ('t' << 16) | ('r' << 24))
#define DPOW_BTCENTRIESCHANNEL (~DPOW_ENTRIESCHANNEL)
#define DPOW_UTXOCHANNEL ('d' | ('P' << 8) | ('o' << 16) | ('W' << 24))
//#define DPOW_ENTRIESCHANNEL ('e' | ('n' << 8) | ('t' << 16) | ('r' << 24))
//#define DPOW_BTCENTRIESCHANNEL (~DPOW_ENTRIESCHANNEL)
//#define DPOW_UTXOCHANNEL ('d' | ('P' << 8) | ('o' << 16) | ('W' << 24))
#define DPOW_SIGCHANNEL ('s' | ('i' << 8) | ('g' << 16) | ('s' << 24))
#define DPOW_SIGBTCCHANNEL (~DPOW_SIGCHANNEL)
#define DPOW_TXIDCHANNEL ('t' | ('x' << 8) | ('i' << 16) | ('d' << 24))
@ -40,14 +40,15 @@
#define DPOW_FIFOSIZE 64
#define DPOW_MAXTX 8192
#define DPOW_THIRDPARTY_CONFIRMS 0
#define DPOW_KOMODOCONFIRMS 3
#define DPOW_KOMODOCONFIRMS 10
#define DPOW_BTCCONFIRMS 1
#define DPOW_MAXRELAYS 64
#define DPOW_MAXSIGLEN 128
struct dpow_coinentry
{
bits256 prev_hash;
uint8_t siglens[DPOW_MAXRELAYS],sigs[DPOW_MAXRELAYS][76];
uint8_t siglens[DPOW_MAXRELAYS],sigs[DPOW_MAXRELAYS][DPOW_MAXSIGLEN];
int32_t prev_vout;
};
@ -61,11 +62,12 @@ struct dpow_utxoentry
struct dpow_entry
{
bits256 commit,beacon;
uint64_t masks[2][DPOW_MAXRELAYS],recvmask,othermask;
int32_t height;
int8_t bestk;
uint8_t pubkey[33];
bits256 commit,beacon,ratifysrcutxo,ratifydestutxo;
uint64_t masks[2][DPOW_MAXRELAYS],recvmask,othermask,bestmask,ratifyrecvmask,ratifybestmask;
int32_t height; uint32_t pendingcrcs[2];
uint16_t ratifysrcvout,ratifydestvout;
int8_t bestk,ratifybestk;
uint8_t pubkey[33],ratifysigs[2][DPOW_MAXSIGLEN],ratifysiglens[2];
struct dpow_coinentry src,dest;
};
@ -74,7 +76,7 @@ struct dpow_sigentry
bits256 beacon;
uint64_t mask;
int32_t refcount;
uint8_t senderind,lastk,siglen,sig[76],senderpub[33];
uint8_t senderind,lastk,siglen,sig[DPOW_MAXSIGLEN],senderpub[33];
};
struct komodo_notaries
@ -96,14 +98,15 @@ struct dpow_block
bits256 hashmsg,desttxid,srctxid,beacon,commit;
struct iguana_info *srccoin,*destcoin; char *opret_symbol;
uint64_t destsigsmasks[DPOW_MAXRELAYS],srcsigsmasks[DPOW_MAXRELAYS];
uint64_t recvmask,bestmask;
uint64_t recvmask,bestmask,ratifybestmask,ratifyrecvmask,pendingbestmask,pendingratifybestmask,ratifysigmasks[2];
struct dpow_entry notaries[DPOW_MAXRELAYS];
uint32_t state,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2];
int32_t height,numnotaries,completed,minsigs,duration,numratified,isratify;
int8_t bestk;
uint32_t state,starttime,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2],lastepoch;
int32_t rawratifiedlens[2],height,numnotaries,numerrors,completed,minsigs,duration,numratified,isratify,require0,scores[DPOW_MAXRELAYS];
int8_t bestk,ratifybestk,pendingbestk,pendingratifybestk;
cJSON *ratified;
uint8_t ratified_pubkeys[DPOW_MAXRELAYS][33]; char handles[DPOW_MAXRELAYS][32];
char signedtx[32768];//,rawtx[32768];
uint8_t myind,ratified_pubkeys[DPOW_MAXRELAYS][33],ratifysigs[2][DPOW_MAXSIGLEN],ratifysiglens[2];
char handles[DPOW_MAXRELAYS][32];
char signedtx[32768]; uint8_t ratifyrawtx[2][32768]; uint32_t pendingcrcs[2];
};
struct pax_transaction
@ -123,9 +126,10 @@ struct dpow_info
struct dpow_hashheight approved[DPOW_FIFOSIZE],notarized[DPOW_FIFOSIZE];
bits256 srctx[DPOW_MAXTX],desttx[DPOW_MAXTX];
uint32_t SRCREALTIME,destupdated,srcconfirms,numdesttx,numsrctx,lastsplit,cancelratify,crcs[16];
int32_t maxblocks,SRCHEIGHT,SHORTFLAG;
int32_t lastheight,maxblocks,SRCHEIGHT,SHORTFLAG,ratifying;
struct pax_transaction *PAX;
portable_mutex_t mutex;
uint32_t ipbits[64],numipbits;
struct dpow_block **blocks;
};

469
iguana/dpow/dpow_fsm.c

@ -13,7 +13,7 @@
* *
******************************************************************************/
struct dpow_entry *dpow_notaryfind(struct supernet_info *myinfo,struct dpow_block *bp,int32_t *senderindp,uint8_t *senderpub)
struct dpow_entry *dpow_notaryfind(struct supernet_info *myinfo,struct dpow_block *bp,int32_t height,int32_t *senderindp,uint8_t *senderpub)
{
int32_t i;
*senderindp = -1;
@ -66,61 +66,10 @@ void dpow_entry2utxo(struct dpow_utxoentry *up,struct dpow_block *bp,struct dpow
up->destvout = ep->dest.prev_vout;
}
void dpow_utxosync(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint64_t recvmask,int32_t myind,bits256 srchash)
int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint8_t nn_senderind,uint32_t channel,uint32_t height,uint8_t *data,int32_t datalen)
{
uint32_t i,j,r; int32_t len; struct dpow_utxoentry U; uint8_t utxodata[sizeof(U)+2];
if ( (bp->recvmask ^ recvmask) != 0 )
{
if ( ((1LL << myind) & recvmask) == 0 )
{
i = myind;
//printf("utxosync bp->%llx != %llx, myind.%d\n",(long long)bp->recvmask,(long long)recvmask,myind);
}
else
{
r = (rand() % bp->numnotaries);
for (j=0; j<DPOW_M(bp); j++)
{
i = DPOW_MODIND(bp,j+r);
if ( ((1LL << i) & bp->recvmask) != 0 && ((1LL << i) & recvmask) == 0 )
break;
}
//printf("utxosync bp->%llx != %llx, random pick.%d\n",(long long)bp->recvmask,(long long)recvmask,i);
}
memset(&U,0,sizeof(U));
dpow_entry2utxo(&U,bp,&bp->notaries[i]);
//char str[65],str2[65];
//printf("send.(%s %s)\n",bits256_str(str,bp->notaries[i].dest.prev_hash),bits256_str(str2,bp->notaries[i].src.prev_hash));
if ( (len= dpow_rwutxobuf(1,utxodata,&U,bp)) > 0 )
dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,DPOW_UTXOCHANNEL,bp->height,utxodata,len);
}
}
void dpow_sync(struct supernet_info *myinfo,int32_t forceflag,struct dpow_info *dp,struct dpow_block *bp,int8_t bestk,uint64_t refmask,int32_t myind,bits256 srchash,uint32_t channel,int32_t src_or_dest)
{
int8_t lastk; uint64_t mask;
if ( bestk < 0 )
mask = dpow_maskmin(refmask,bp,&lastk);
else
{
lastk = bestk;
mask = refmask;
}
//dpow_utxosync(myinfo,bp,mask,myind,srchash);
if ( forceflag || bp->notaries[myind].masks[lastk] == 0 )
dpow_signedtxgen(myinfo,dp,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,lastk,mask,myind,src_or_dest != 0 ? DPOW_SIGBTCCHANNEL : DPOW_SIGCHANNEL,src_or_dest);
}
int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t channel,uint32_t height,uint8_t *data,int32_t datalen)
{
bits256 txid,commit,srchash,hashmsg; struct dpow_block *bp = 0; uint32_t flag = 0; int32_t src_or_dest,senderind,i,iter,rlen,myind = -1; char str[65],str2[65]; struct dpow_sigentry dsig; struct dpow_entry *ep; struct dpow_coinentry *cp; struct dpow_utxoentry U; struct iguana_info *coin;
if ( (bp= dpow_heightfind(myinfo,dp,height)) == 0 )
{
if ( 0 && (rand() % 100) == 0 && height > 0 )
printf("couldnt find height.%d | if you just started notary dapp this is normal\n",height);
return(-1);
}
dpow_notaryfind(myinfo,bp,&myind,dp->minerkey33);
int32_t i,src_or_dest,myind = -1; bits256 txid,srchash; struct iguana_info *coin; char str[65],str2[65];
dpow_notaryfind(myinfo,bp,height,&myind,dp->minerkey33);
if ( myind < 0 )
{
printf("couldnt find myind height.%d | this means your pubkey for this node is not registered and needs to be ratified by majority vote of all notaries\n",height);
@ -128,171 +77,37 @@ int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,uint3
}
for (i=0; i<32; i++)
srchash.bytes[i] = dp->minerkey33[i+1];
if ( channel == DPOW_ENTRIESCHANNEL )
{
struct dpow_entry notaries[DPOW_MAXRELAYS]; uint8_t n; int8_t bestk; struct dpow_coinentry *ptr,*refptr;
rlen = 0;
bestk = data[rlen++];
n = data[rlen++];
rlen += iguana_rwbignum(0,&data[rlen],sizeof(hashmsg),hashmsg.bytes);
//printf("got ENTRIES bestk.%d (%d %llx) recv.%llx numnotaries.%d\n",bestk,bp->bestk,(long long)bp->bestmask,(long long)bp->recvmask,n);
if ( bits256_cmp(hashmsg,bp->hashmsg) == 0 )
{
memset(notaries,0,sizeof(notaries));
for (i=0; i<64; i++)
notaries[i].bestk = -1;
rlen += dpow_rwcoinentrys(0,&data[rlen],notaries,n,bestk);
//printf("matched hashmsg rlen.%d vs datalen.%d\n",rlen,datalen);
for (i=0; i<n; i++)
{
for (iter=0; iter<2; iter++)
{
ptr = iter != 0 ? &notaries[i].dest : &notaries[i].src;
refptr = iter != 0 ? &bp->notaries[i].dest : &bp->notaries[i].src;
if ( bits256_nonz(ptr->prev_hash) != 0 )
{
if ( bits256_nonz(refptr->prev_hash) == 0 )
{
printf(">>>>>>>>> %s got utxo.[%d] indirectly <<<<<<<<<<<\n",iter!=0?"dest":"src",i);
refptr->prev_hash = ptr->prev_hash;
refptr->prev_vout = ptr->prev_vout;
if ( iter == 1 && bits256_nonz(notaries[i].src.prev_hash) != 0 )
bp->recvmask |= (1LL << i);
}
}
if ( (bestk= notaries[i].bestk) >= 0 )
{
if ( ptr->siglens[bestk] > 0 && refptr->siglens[bestk] == 0 )
{
printf(">>>>>>>>>> got %s siglen.%d for [%d] indirectly bestk.%d <<<<<<<<<<\n",iter!=0?"dest":"src",ptr->siglens[bestk],i,bestk);
memcpy(refptr->sigs[bestk],ptr->sigs[bestk],ptr->siglens[bestk]);
refptr->siglens[bestk] = ptr->siglens[bestk];
if ( iter != 0 )
bp->destsigsmasks[bestk] |= (1LL << i);
else bp->srcsigsmasks[bestk] |= (1LL << i);
}
}
}
}
}
}
else if ( channel == DPOW_UTXOCHANNEL )
{
src_or_dest = 1;
coin = (src_or_dest != 0) ? bp->destcoin : bp->srccoin;
memset(&U,0,sizeof(U));
if ( dpow_rwutxobuf(0,data,&U,bp) < 0 )
{
printf("error from rwutxobuf\n");
return(0);
}
if ( bits256_cmp(U.hashmsg,bp->hashmsg) != 0 && bits256_nonz(bp->hashmsg) != 0 )
{
printf("unexpected mismatch hashmsg.%s vs %s\n",bits256_str(str,U.hashmsg),bits256_str(str2,bp->hashmsg));
return(0);
}
if ( (ep= dpow_notaryfind(myinfo,bp,&senderind,U.pubkey)) != 0 )
{
dpow_utxo2entry(bp,ep,&U);
if ( ((1LL << senderind) & bp->recvmask) == 0 )
{
dpow_utxosync(myinfo,dp,bp,0,myind,srchash);
bp->recvmask |= (1LL << senderind);
}
dpow_sync(myinfo,1,dp,bp,-1,ep->recvmask,myind,srchash,channel,src_or_dest);
flag = 1;
}
//printf("bestk.%d %llx vs recv.%llx\n",bp->bestk,(long long)bp->bestmask,(long long)bp->recvmask);
if ( 0 && flag == 0 && bp != 0 )
printf("ep.%p sender.%d UTXO.%d hashmsg.(%s) txid.(%s) v%d %llx\n",ep,senderind,height,bits256_str(str,U.hashmsg),bits256_str(str2,src_or_dest!=0?U.desthash:U.srchash),src_or_dest!=0?U.destvout:U.srcvout,(long long)bp->recvmask);
}
else if ( channel == DPOW_SIGCHANNEL || channel == DPOW_SIGBTCCHANNEL )
{
if ( dpow_rwsigentry(0,data,&dsig) < 0 )
{
printf("rwsigentry error\n");
return(0);
}
//printf("got sig.%x (%d %d) <<<<<<<<<< from.%d (%d %llx) sigs.%llx\n",channel,channel == DPOW_SIGCHANNEL,channel == DPOW_SIGBTCCHANNEL,dsig.senderind,dsig.lastk,(long long)dsig.mask,(long long)(dsig.lastk>=0?bp->destsigsmasks[dsig.lastk]:0));
if ( channel == DPOW_SIGBTCCHANNEL )
{
src_or_dest = 1;
coin = bp->destcoin;
cp = &bp->notaries[dsig.senderind].dest;
//printf("gotsig %s channel.%x from %d bestk.%d %llx\n",coin->symbol,channel,dsig.senderind,dsig.lastk,(long long)dsig.mask);
}
else
{
src_or_dest = 0;
coin = bp->srccoin;
cp = &bp->notaries[dsig.senderind].src;
}
if ( dsig.senderind >= 0 && dsig.senderind < DPOW_MAXRELAYS )
{
if ( dsig.lastk < bp->numnotaries && dsig.senderind < bp->numnotaries && (ep= dpow_notaryfind(myinfo,bp,&senderind,dsig.senderpub)) != 0 )
{
vcalc_sha256(0,commit.bytes,dsig.beacon.bytes,sizeof(dsig.beacon));
if ( memcmp(dsig.senderpub,bp->notaries[dsig.senderind].pubkey,33) == 0 )
{
//if ( ep->masks[dsig.lastk] == 0 )
{
ep->masks[src_or_dest][dsig.lastk] = dsig.mask;
cp->siglens[dsig.lastk] = dsig.siglen;
memcpy(cp->sigs[dsig.lastk],dsig.sig,dsig.siglen);
ep->beacon = dsig.beacon;
if ( src_or_dest != 0 )
{
bp->destsigsmasks[dsig.lastk] |= (1LL << dsig.senderind);
if ( bp->bestk >= 0 && bp->bestk == dsig.lastk && (bp->bestmask & bp->destsigsmasks[dsig.lastk]) == bp->bestmask )
{
dpow_sigscheck(myinfo,dp,bp,DPOW_SIGBTCCHANNEL,myind,1);
}
}
else
{
bp->srcsigsmasks[dsig.lastk] |= (1LL << dsig.senderind);
if ( bp->bestk >= 0 && bp->bestk == dsig.lastk && (bp->bestmask & bp->srcsigsmasks[dsig.lastk]) == bp->bestmask )
{
dpow_sigscheck(myinfo,dp,bp,DPOW_SIGCHANNEL,myind,0);
}
}
//printf(" ht.%d (%d %llx) <<<<<<<< %s from.%d got lastk.%d %llx/%llx siglen.%d >>>>>>>>>\n",bp->height,bp->bestk,(long long)bp->bestmask,coin->symbol,dsig.senderind,dsig.lastk,(long long)dsig.mask,(long long)bp->destsigsmasks[dsig.lastk],dsig.siglen);
dpow_sync(myinfo,1,dp,bp,dsig.lastk,dsig.mask,myind,srchash,channel,src_or_dest);
flag = 1;
}
} else printf("%s pubkey mismatch for senderind.%d %llx vs %llx\n",coin->symbol,dsig.senderind,*(long long *)dsig.senderpub,*(long long *)bp->notaries[dsig.senderind].pubkey);
} else printf("%s illegal lastk.%d or senderind.%d or senderpub.%llx\n",coin->symbol,dsig.lastk,dsig.senderind,*(long long *)dsig.senderpub);
} else printf("couldnt find senderind.%d height.%d channel.%x\n",dsig.senderind,height,channel);
//if ( 0 && bp != 0 )
// printf("%s SIG.%d sender.%d lastk.%d mask.%llx siglen.%d recv.%llx\n",coin->symbol,height,dsig.senderind,dsig.lastk,(long long)dsig.mask,dsig.siglen,(long long)bp->recvmask);
}
else if ( channel == DPOW_TXIDCHANNEL || channel == DPOW_BTCTXIDCHANNEL )
if ( channel == DPOW_TXIDCHANNEL || channel == DPOW_BTCTXIDCHANNEL )
{
src_or_dest = (channel == DPOW_BTCTXIDCHANNEL);
coin = (src_or_dest != 0) ? bp->destcoin : bp->srccoin;
printf("handle txid channel.%x\n",channel);
//printf("bp.%p datalen.%d\n",bp,datalen);
for (i=0; i<32; i++)
srchash.bytes[i] = data[i];
txid = bits256_doublesha256(0,&data[32],datalen-32);
init_hexbytes_noT(bp->signedtx,&data[32],datalen-32);
printf("signedtx.(%s)\n",bp->signedtx);
if ( bits256_cmp(txid,srchash) == 0 )
{
printf("verify (%s) it is properly signed! set ht.%d signedtxid to %s\n",coin->symbol,height,bits256_str(str,txid));
//printf("verify (%s) it is properly signed! set ht.%d signedtxid to %s\n",coin->symbol,height,bits256_str(str,txid));
if ( src_or_dest != 0 )
{
bp->desttxid = txid;
bp->state = 1000;
dp->destupdated = 0;
dpow_signedtxgen(myinfo,dp,bp->srccoin,bp,bp->bestk,bp->bestmask,myind,DPOW_SIGCHANNEL,0);
//dpow_sigscheck(myinfo,dp,bp,DPOW_SIGCHANNEL,myind,0);
if ( bp->state < 1000 )
{
bp->desttxid = txid;
bp->state = 1000;
dp->destupdated = 0;
dpow_signedtxgen(myinfo,dp,bp->srccoin,bp,bp->bestk,bp->bestmask,myind,DPOW_SIGCHANNEL,0,bp->isratify);
//dpow_sigscheck(myinfo,dp,bp,DPOW_SIGCHANNEL,myind,0);
}
}
else
{
bp->srctxid = txid;
printf("set state COMPLETED\n");
bp->state = 0xffffffff;
if ( bp->state != 0xffffffff )
{
bp->srctxid = txid;
printf("set state elapsed %d COMPLETED %s.(%s) %s.(%s)\n",(int32_t)(time(NULL) - bp->starttime),dp->symbol,bits256_str(str,bp->desttxid),dp->dest,bits256_str(str2,txid));
bp->state = 0xffffffff;
}
}
}
else
@ -301,146 +116,28 @@ int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,uint3
printf("txidchannel txid %s mismatch %s (%s)\n",bits256_str(str,txid),bits256_str(str2,srchash),bp->signedtx);
bp->signedtx[0] = 0;
}
} else printf("unhandled channel.%x\n",channel);
} //else printf("unhandled channel.%x\n",channel);
return(0);
}
int32_t dpow_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint32_t txidchannel,bits256 srchash,int32_t myind)
{
struct dpow_entry *ep; int32_t i,k,len,src_or_dest,sendutxo = 0; uint8_t data[sizeof(struct dpow_entry)+2]; struct dpow_utxoentry U;
ep = &bp->notaries[myind];
if ( bp->state < 1000 )
{
src_or_dest = 1;
bp->bestmask = dpow_maskmin(bp->recvmask,bp,&bp->bestk);
if ( bp->bestk >= 0 )
{
sendutxo = 0;
for (i=0; i<bp->numnotaries; i++)
{
k = DPOW_MODIND(bp,i);
if ( k == myind )
continue;
if ( ((1LL << k) & bp->recvmask) != 0 && (bp->notaries[k].recvmask & (1LL << myind)) == 0 )
{
//printf("other notary.%d doesnt have our.%d utxo yet\n",k,myind);
sendutxo = 1;
break;
}
}
if ( ep->masks[src_or_dest][bp->bestk] == 0 )
dpow_signedtxgen(myinfo,dp,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,DPOW_SIGBTCCHANNEL,src_or_dest);
if ( bp->bestk >= 0 && (rand() % 10) == 0 )
dpow_sigsend(myinfo,dp,bp,myind,bp->bestk,bp->bestmask,srchash,DPOW_SIGBTCCHANNEL);
} else sendutxo = 1;
if ( sendutxo != 0 )
{
memset(&U,0,sizeof(U));
dpow_entry2utxo(&U,bp,&bp->notaries[myind]);
if ( (len= dpow_rwutxobuf(1,data,&U,bp)) > 0 )
dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,DPOW_UTXOCHANNEL,bp->height,data,len);
}
if ( bp->bestk >= 0 && ep->masks[src_or_dest][bp->bestk] == 0 )
dpow_signedtxgen(myinfo,dp,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,DPOW_SIGBTCCHANNEL,src_or_dest);
if ( bp->bestk >= 0 && (rand() % 10) == 0 )
{
dpow_sigsend(myinfo,dp,bp,myind,bp->bestk,bp->bestmask,srchash,DPOW_SIGBTCCHANNEL);
for (i=0; i<bp->numnotaries; i++)
if ( bp->notaries[i].bestk >= 0 && bp->notaries[i].bestk != bp->bestk && bitweight(bp->notaries[i].recvmask & bp->recvmask) >= 7 )
dpow_sigsend(myinfo,dp,bp,myind,bp->notaries[i].bestk,bp->recvmask,srchash,DPOW_SIGBTCCHANNEL);
}
}
else if ( bp->state != 0xffffffff )
{
src_or_dest = 0;
if ( bp->bestk >= 0 && ep->masks[src_or_dest][bp->bestk] == 0 )
dpow_signedtxgen(myinfo,dp,(src_or_dest != 0) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,DPOW_SIGCHANNEL,src_or_dest);
if ( bp->bestk >= 0 && (rand() % 10) == 0 )
dpow_sigsend(myinfo,dp,bp,myind,bp->bestk,bp->bestmask,srchash,DPOW_SIGCHANNEL);
}
if ( (rand() % 10) == 0 )
{
if ( bp->isratify != 0 )
{
uint64_t sigsmask,srcmask;
if ( bp->bestk < 0 )
sigsmask = srcmask = 0;
else sigsmask = bp->destsigsmasks[bp->bestk], srcmask = bp->srcsigsmasks[bp->bestk];
printf("[%d] %s isratify.%d ht.%d FSM.%08x masks.%llx best.(%d %llx) sigsmask.%llx %llx src.%llx\n",myind,src_or_dest != 0 ? bp->destcoin->symbol : bp->srccoin->symbol,bp->isratify,bp->height,bp->state,(long long)bp->recvmask,bp->bestk,(long long)bp->bestmask,(long long)sigsmask,(long long)(sigsmask & bp->bestmask),(long long)srcmask);
}
if ( bp->isratify != 0 )
{
bp->bestmask = dpow_maskmin(bp->recvmask,bp,&bp->bestk);
dpow_sendcoinentrys(myinfo,dp,bp);
if ( bp->bestk >= 0 )
dpow_signedtxgen(myinfo,dp,(bp->state < 1000) ? bp->destcoin : bp->srccoin,bp,bp->bestk,bp->bestmask,myind,bp->state < 1000 ? DPOW_SIGBTCCHANNEL : DPOW_SIGCHANNEL,bp->state < 1000);
printf("ht.%d numnotaries.%d BEST.%llx from RECV.%llx bestk.%d sigsmask.%llx missing.%llx\n",bp->height,bp->numnotaries,(long long)bp->bestmask,(long long)bp->recvmask,bp->bestk,bp->bestk>=0?(long long)bp->destsigsmasks[bp->bestk]:0,bp->bestk>=0?(long long)(bp->bestmask & ~bp->destsigsmasks[bp->bestk]):0);
if ( bp->height < DPOW_FIRSTRATIFY )
dp->blocks[bp->height] = bp;
}
}
if ( bp->state < 1000 && bp->bestk >= 0 && (bp->destsigsmasks[bp->bestk] & bp->bestmask) == bp->bestmask )
{
dpow_sigscheck(myinfo,dp,bp,DPOW_SIGBTCCHANNEL,myind,1);
}
else if ( bp->state != 0xffffffff && bp->bestk >= 0 && (bp->srcsigsmasks[bp->bestk] & bp->bestmask) == bp->bestmask )
{
dpow_sigscheck(myinfo,dp,bp,DPOW_SIGCHANNEL,myind,0);
}
return(bp->state);
}
uint32_t dpow_statemachineiterate(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,struct dpow_block *bp,int32_t myind,int32_t src_or_dest)
int32_t dpow_checkutxo(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,char *coinaddr)
{
int32_t j,incr; char *opret_symbol,coinaddr[64]; uint32_t channel,sigchannel,txidchannel; bits256 srchash,zero;
if ( 0 && bp->numnotaries > 8 )
incr = sqrt(bp->numnotaries) + 1;
else incr = 1;
memset(zero.bytes,0,sizeof(zero));
channel = DPOW_UTXOCHANNEL;
if ( bits256_nonz(bp->desttxid) == 0 )
int32_t haveutxo,completed,minutxo,n; bits256 signedtxid; cJSON *addresses; char *rawtx,*sendtx;
if ( strcmp("BTC",coin->symbol) == 0 )
{
sigchannel = DPOW_SIGBTCCHANNEL;
txidchannel = DPOW_BTCTXIDCHANNEL;
opret_symbol = "";
minutxo = 9;
n = 50;
}
else
{
sigchannel = DPOW_SIGCHANNEL;
txidchannel = DPOW_TXIDCHANNEL;
opret_symbol = dp->symbol;
}
bitcoin_address(coinaddr,coin->chain->pubtype,dp->minerkey33,33);
if ( bits256_nonz(bp->hashmsg) == 0 && bp->height >= DPOW_FIRSTRATIFY )
{
printf("null hashmsg\n");
return(0);
}
for (j=0; j<sizeof(srchash); j++)
srchash.bytes[j] = dp->minerkey33[j+1];
bp->bestk = dpow_bestk(bp,&bp->bestmask);
if ( bp->state < 7 )
{
dpow_utxosync(myinfo,dp,bp,0,myind,srchash);
bp->state++;
minutxo = 49;
n = 10;
}
else
{
dpow_update(myinfo,dp,bp,txidchannel,srchash,myind);
if ( bits256_nonz(bp->srctxid) != 0 )
bp->state = 0xffffffff;
}
return(bp->state);
}
int32_t dpow_checkutxo(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,char *coinaddr)
{
int32_t haveutxo,completed; bits256 signedtxid; cJSON *addresses; char *rawtx,*sendtx;
if ( (haveutxo= dpow_haveutxo(myinfo,coin,txidp,voutp,coinaddr)) <= 10 && time(NULL) > dp->lastsplit+bp->duration )
if ( (haveutxo= dpow_haveutxo(myinfo,coin,txidp,voutp,coinaddr)) <= minutxo && time(NULL) > dp->lastsplit+bp->duration )
{
addresses = cJSON_CreateArray();
jaddistr(addresses,coinaddr);
if ( (rawtx= iguana_utxoduplicates(myinfo,coin,dp->minerkey33,DPOW_UTXOSIZE,strcmp(coin->symbol,"BTC") == 0 ? 50 : 10,&completed,&signedtxid,0,addresses)) != 0 )
if ( (rawtx= iguana_utxoduplicates(myinfo,coin,dp->minerkey33,DPOW_UTXOSIZE,n,&completed,&signedtxid,0,addresses)) != 0 )
{
if ( (sendtx= dpow_sendrawtransaction(myinfo,coin,rawtx)) != 0 )
{
@ -475,6 +172,11 @@ void dpow_statemachinestart(void *ptr)
printf("statemachinestart %s->%s %s ht.%d minsigs.%d duration.%d start.%u\n",dp->symbol,dp->dest,bits256_str(str,checkpoint.blockhash.hash),checkpoint.blockhash.height,minsigs,duration,checkpoint.timestamp);
src = iguana_coinfind(dp->symbol);
dest = iguana_coinfind(dp->dest);
if ( src == 0 || dest == 0 )
{
printf("null coin ptr? (%s %p or %s %p)\n",dp->symbol,src,dp->dest,dest);
return;
}
if ( strcmp(src->symbol,"KMD") == 0 )
kmdheight = checkpoint.blockhash.height;
else if ( strcmp(dest->symbol,"KMD") == 0 )
@ -483,29 +185,37 @@ void dpow_statemachinestart(void *ptr)
{
bp = calloc(1,sizeof(*bp));
bp->minsigs = minsigs;
if ( (bp->duration= duration) == DPOW_RATIFYDURATION )
bp->isratify = 1;
bp->duration = duration;
bp->srccoin = src;
bp->destcoin = dest;
bp->opret_symbol = dp->symbol;
if ( jsonstr != 0 && (ratified= cJSON_Parse(jsonstr)) != 0 )
{
bp->isratify = 1;
if ( (numratified= cJSON_GetArraySize(ratified)) > 0 )
{
if ( numratified > 64 )
{
fprintf(stderr,"cant ratify more than 64 notaries ratified has %d\n",numratified);
return;
}
for (i=0; i<numratified; i++)
{
item = jitem(ratified,i);
hexstr = handle = 0;
if ( (hexstr= jstr(item,"pubkey")) != 0 && is_hexstr(hexstr,0) == 66 && (handle= jstr(item,"handle")) != 0 )
if ( (hexstr= jstr(item,"pubkey")) != 0 && is_hexstr(hexstr,0) == 66 )
{
decode_hex(bp->ratified_pubkeys[i],33,hexstr);
safecopy(bp->handles[i],handle,sizeof(bp->handles[i]));
if ( (handle= jstr(item,"handle")) != 0 )
safecopy(bp->handles[i],handle,sizeof(bp->handles[i]));
if ( i == 0 )
{
destprevtxid0 = jbits256(item,"destprevtxid0");
destprevvout0 = jint(item,"destprevvout0");
srcprevtxid0 = jbits256(item,"srcprevtxid0");
srcprevvout0 = jint(item,"srcprevvout0");
if ( bits256_nonz(destprevtxid0) != 0 && bits256_nonz(srcprevtxid0) != 0 )
bp->require0 = 1;
}
}
else
@ -538,14 +248,29 @@ void dpow_statemachinestart(void *ptr)
dp->blocks[checkpoint.blockhash.height - DPOW_FIRSTRATIFY] = 0;
}*/
}
if ( bp->isratify != 0 && dp->ratifying != 0 )
{
printf("new ratification starting dp->ratifying.%d\n",dp->ratifying);
dp->ratifying++;
while ( dp->ratifying > 1 )
sleep(3);
printf("other ratifications stopped\n");
}
if ( dp->ratifying != 0 && bp->isratify == 0 )
{
printf("skip notarization ht.%d when ratifying\n",bp->height);
free(ptr);
return;
}
dp->ratifying += bp->isratify;
bitcoin_address(srcaddr,src->chain->pubtype,dp->minerkey33,33);
bitcoin_address(destaddr,dest->chain->pubtype,dp->minerkey33,33);
if ( kmdheight >= 0 )
{
bp->numnotaries = komodo_notaries(pubkeys,kmdheight);
bp->numnotaries = komodo_notaries(src->symbol,pubkeys,strcmp("KMD",src->symbol) == 0 ? kmdheight : bp->height);
for (i=0; i<bp->numnotaries; i++)
{
//for (j=0; j<33; j++)
//int32_t j; for (j=0; j<33; j++)
// printf("%02x",pubkeys[i][j]);
//printf(" <= pubkey[%d]\n",i);
memcpy(bp->notaries[i].pubkey,pubkeys[i],33);
@ -562,6 +287,7 @@ void dpow_statemachinestart(void *ptr)
printf("%02x",dp->minerkey33[i]);
printf(" statemachinestart this node %s %s is not official notary numnotaries.%d\n",srcaddr,destaddr,bp->numnotaries);
free(ptr);
dp->ratifying -= bp->isratify;
return;
}
}
@ -569,6 +295,18 @@ void dpow_statemachinestart(void *ptr)
{
printf("statemachinestart no kmdheight.%d\n",kmdheight);
free(ptr);
dp->ratifying -= bp->isratify;
return;
}
if ( bp->isratify != 0 && memcmp(bp->notaries[0].pubkey,bp->ratified_pubkeys[0],33) != 0 )
{
for (i=0; i<33; i++)
printf("%02x",bp->notaries[0].pubkey[i]);
printf(" current vs ");
for (i=0; i<33; i++)
printf("%02x",bp->ratified_pubkeys[0][i]);
printf(" new, cant change notary0\n");
dp->ratifying -= bp->isratify;
return;
}
printf(" myind.%d myaddr.(%s %s)\n",myind,srcaddr,destaddr);
@ -578,6 +316,10 @@ void dpow_statemachinestart(void *ptr)
ep->dest.prev_vout = destprevvout0;
ep->src.prev_hash = srcprevtxid0;
ep->src.prev_vout = srcprevvout0;
bp->notaries[myind].ratifysrcutxo = srcprevtxid0;
bp->notaries[myind].ratifysrcvout = srcprevvout0;
bp->notaries[myind].ratifydestutxo = destprevtxid0;
bp->notaries[myind].ratifydestvout = destprevvout0;
printf("Use override utxo %s/v%d %s/v%d\n",bits256_str(str,destprevtxid0),destprevvout0,bits256_str(str2,srcprevtxid0),srcprevvout0);
}
else
@ -586,14 +328,23 @@ void dpow_statemachinestart(void *ptr)
{
printf("dont have %s %s utxo, please send funds\n",dp->dest,destaddr);
free(ptr);
dp->ratifying -= bp->isratify;
return;
}
if ( dpow_checkutxo(myinfo,dp,bp,bp->srccoin,&ep->src.prev_hash,&ep->src.prev_vout,srcaddr) < 0 )
{
printf("dont have %s %s utxo, please send funds\n",dp->symbol,srcaddr);
free(ptr);
dp->ratifying -= bp->isratify;
return;
}
if ( bp->isratify != 0 )
{
bp->notaries[myind].ratifysrcutxo = ep->src.prev_hash;
bp->notaries[myind].ratifysrcvout = ep->src.prev_vout;
bp->notaries[myind].ratifydestutxo = ep->dest.prev_hash;
bp->notaries[myind].ratifydestvout = ep->dest.prev_vout;
}
}
bp->recvmask |= (1LL << myind);
bp->notaries[myind].othermask |= (1LL << myind);
@ -601,22 +352,24 @@ void dpow_statemachinestart(void *ptr)
bp->height = checkpoint.blockhash.height;
bp->timestamp = checkpoint.timestamp;
bp->hashmsg = checkpoint.blockhash.hash;
bp->myind = myind;
while ( bp->isratify == 0 && dp->destupdated == 0 )
{
if ( dp->checkpoint.blockhash.height > checkpoint.blockhash.height )
{
printf("abort ht.%d due to new checkpoint.%d\n",checkpoint.blockhash.height,dp->checkpoint.blockhash.height);
dp->ratifying -= bp->isratify;
return;
}
sleep(1);
}
if ( bp->isratify == 0 || (starttime= checkpoint.timestamp) == 0 )
starttime = (uint32_t)time(NULL);
bp->starttime = starttime = (uint32_t)time(NULL);
printf("isratify.%d DPOW.%s statemachine checkpoint.%d %s start.%u\n",bp->isratify,src->symbol,checkpoint.blockhash.height,bits256_str(str,checkpoint.blockhash.hash),checkpoint.timestamp);
for (i=0; i<sizeof(srchash); i++)
srchash.bytes[i] = dp->minerkey33[i+1];
//printf("start utxosync start.%u %u\n",starttime,(uint32_t)time(NULL));
dpow_utxosync(myinfo,dp,bp,0,myind,srchash);
//dpow_utxosync(myinfo,dp,bp,0,myind,srchash);
//printf("done utxosync start.%u %u\n",starttime,(uint32_t)time(NULL));
while ( time(NULL) < starttime+bp->duration && src != 0 && dest != 0 && bp->state != 0xffffffff )
{
@ -628,28 +381,25 @@ void dpow_statemachinestart(void *ptr)
printf("abort ht.%d due to new checkpoint.%d\n",checkpoint.blockhash.height,dp->checkpoint.blockhash.height);
break;
}
else
}
if ( dp->ratifying > 1 )
{
printf("new ratification started. abort ht.%d\n",bp->height);
break;
}
if ( bp->isratify == 0 )
{
bits256 checkhash;
checkhash = dpow_getblockhash(myinfo,bp->srccoin,bp->height);
if ( bits256_cmp(checkhash,bp->hashmsg) != 0 )
{
bp->bestk = -1;
bp->bestmask = bp->recvmask = 0;
bp->height = ((dp->checkpoint.blockhash.height / 10) % (DPOW_FIRSTRATIFY/10)) * 10;
printf("new rotation ht.%d\n",bp->height);
dp->blocks[checkpoint.blockhash.height] = 0;
checkpoint.blockhash.height = dp->checkpoint.blockhash.height;
dp->blocks[checkpoint.blockhash.height] = bp;
/*for (i=0; i<64; i++)
{
bp->notaries[i].recvmask = 0;
bp->notaries[i].bestk = -1;
}
memset(bp->destsigsmasks,0,sizeof(bp->destsigsmasks));
memset(bp->notaries[myind].masks,0,sizeof(bp->notaries[myind].masks));*/
printf("%s ht.%d %s got reorged to %s, abort notarization\n",bp->srccoin->symbol,bp->height,bits256_str(str,bp->hashmsg),bits256_str(str2,checkhash));
bp->state = 0xffffffff;
}
}
if ( bp->state != 0xffffffff )
{
//printf("dp->ht.%d ht.%d DEST.%08x %s\n",dp->checkpoint.blockhash.height,checkpoint.blockhash.height,bp->state,bits256_str(str,srchash));
bp->state = dpow_statemachineiterate(myinfo,dp,dest,bp,myind,1);
dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,0,bp->height,(void *)"ping",0);
}
if ( 0 && dp->cancelratify != 0 && bp->isratify != 0 )
{
@ -657,8 +407,9 @@ void dpow_statemachinestart(void *ptr)
break;
}
}
printf("bestk.%d %llx sigs.%llx state machine ht.%d completed state.%x %s.%s %s.%s recvmask.%llx\n",bp->bestk,(long long)bp->bestmask,(long long)(bp->bestk>=0?bp->destsigsmasks[bp->bestk]:0),bp->height,bp->state,dp->dest,bits256_str(str,bp->desttxid),dp->symbol,bits256_str(str2,bp->srctxid),(long long)bp->recvmask);
printf("isratify.%d bestk.%d %llx sigs.%llx state machine ht.%d completed state.%x %s.%s %s.%s recvmask.%llx\n",bp->isratify,bp->bestk,(long long)bp->bestmask,(long long)(bp->bestk>=0?bp->destsigsmasks[bp->bestk]:0),bp->height,bp->state,dp->dest,bits256_str(str,bp->desttxid),dp->symbol,bits256_str(str2,bp->srctxid),(long long)bp->recvmask);
dp->lastrecvmask = bp->recvmask;
dp->ratifying -= bp->isratify;
free(ptr);
}

602
iguana/dpow/dpow_network.c

@ -16,20 +16,92 @@
#if ISNOTARYNODE
struct dpow_nanoutxo
{
bits256 srcutxo,destutxo;
uint64_t bestmask,recvmask;
uint32_t pendingcrcs[2];
uint16_t srcvout,destvout;
uint8_t sigs[2][DPOW_MAXSIGLEN],siglens[2],bestk,pad;
} PACKED;
struct dpow_nanomsghdr
{
bits256 srchash,desthash;
uint32_t channel,height,size,datalen,crc32;
struct dpow_nanoutxo ratify,notarize;
uint32_t channel,height,size,datalen,crc32,myipbits,numipbits,ipbits[64];
char symbol[16];
uint8_t version0,version1,packet[];
uint8_t senderind,version0,version1,packet[];
} PACKED;
uint64_t dpow_ratifybest(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp);
struct dpow_block *dpow_heightfind(struct supernet_info *myinfo,struct dpow_info *dp,int32_t height);
int32_t dpow_signedtxgen(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,struct dpow_block *bp,int8_t bestk,uint64_t bestmask,int32_t myind,uint32_t deprec,int32_t src_or_dest,int32_t useratified);
void dpow_sigscheck(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,int32_t myind,int32_t src_or_dest,int8_t bestk,uint64_t bestmask,uint8_t pubkeys[64][33],int32_t numratified);
char *nanomsg_tcpname(char *str,char *ipaddr)
{
sprintf(str,"tcp://%s:7775",ipaddr);
return(str);
}
static int _increasing_ipbits(const void *a,const void *b)
{
#define uint32_a (*(uint32_t *)a)
#define uint32_b (*(uint32_t *)b)
if ( uint32_b > uint32_a )
return(-1);
else if ( uint32_b < uint32_a )
return(1);
return(0);
#undef uint32_a
#undef uint32_b
}
int32_t dpow_addnotary(struct supernet_info *myinfo,struct dpow_info *dp,char *ipaddr)
{
char str[512]; uint32_t ipbits,*ptr; int32_t i,iter,n,retval = -1;
if ( myinfo->dpowsock >= 0 )
{
portable_mutex_lock(&myinfo->dpowmutex);
ipbits = (uint32_t)calc_ipbits(ipaddr);
for (iter=0; iter<2; iter++)
{
if ( iter == 0 )
{
n = myinfo->numdpowipbits;
ptr = myinfo->dpowipbits;
}
else
{
n = dp->numipbits;
ptr = dp->ipbits;
}
for (i=0; i<n; i++)
if ( ipbits == ptr[i] )
break;
if ( i == n && n < 64 )
{
ptr[n] = ipbits;
if ( iter == 0 && strcmp(ipaddr,myinfo->ipaddr) != 0 )
retval = nn_connect(myinfo->dpowsock,nanomsg_tcpname(str,ipaddr));
n++;
qsort(ptr,n,sizeof(uint32_t),_increasing_ipbits);
if ( iter == 0 )
myinfo->numdpowipbits = n;
else dp->numipbits = n;
//for (i=0; i<n; i++)
// printf("%08x ",ptr[i]);
//printf("addnotary.[%d] (%s) retval.%d (total %d %d) iter.%d\n",n,ipaddr,retval,myinfo->numdpowipbits,dp!=0?dp->numipbits:-1,iter);
}
if ( dp == 0 )
break;
}
portable_mutex_unlock(&myinfo->dpowmutex);
}
return(retval);
}
void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr)
{
char str[512]; int32_t timeout,retval;
@ -48,18 +120,15 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr)
}
timeout = 1000;
nn_setsockopt(myinfo->dpowsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
myinfo->dpowipbits[0] = (uint32_t)calc_ipbits(myinfo->ipaddr);
myinfo->numdpowipbits = 1;
}
if ( myinfo->dpowsock >= 0 && strcmp(ipaddr,myinfo->ipaddr) != 0 )
{
retval = nn_connect(myinfo->dpowsock,nanomsg_tcpname(str,ipaddr));
printf("addnotary (%s) retval.%d\n",ipaddr,retval);
}
dpow_addnotary(myinfo,0,ipaddr);
}
int32_t dpow_crc32find(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t crc32,uint32_t channel)
{
int32_t i,firstz = -1;
//return(0);
for (i=0; i<sizeof(dp->crcs)/sizeof(*dp->crcs); i++)
{
if ( dp->crcs[i] == crc32 )
@ -75,23 +144,338 @@ int32_t dpow_crc32find(struct supernet_info *myinfo,struct dpow_info *dp,uint32_
return(firstz);
}
void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isratify)
{
int32_t i;
if ( isratify != 0 )
{
np->srcutxo = bp->notaries[bp->myind].ratifysrcutxo;
np->srcvout = bp->notaries[bp->myind].ratifysrcvout;
np->destutxo = bp->notaries[bp->myind].ratifydestutxo;
np->destvout = bp->notaries[bp->myind].ratifydestvout;
np->bestmask = bp->ratifybestmask;
np->recvmask = bp->ratifyrecvmask;
//printf("send ratify best.(%d %llx) siglens.(%d %d)\n", bp->ratifybestk,(long long)bp->ratifybestmask,bp->ratifysiglens[0],bp->ratifysiglens[1]);
if ( (np->bestk= bp->ratifybestk) >= 0 )
{
for (i=0; i<2; i++)
{
if ( (np->siglens[i]= bp->ratifysiglens[i]) > 0 )
memcpy(np->sigs[i],bp->ratifysigs[i],np->siglens[i]);
}
}
}
else
{
np->srcutxo = bp->notaries[bp->myind].src.prev_hash;
np->srcvout = bp->notaries[bp->myind].src.prev_vout;
np->destutxo = bp->notaries[bp->myind].dest.prev_hash;
np->destvout = bp->notaries[bp->myind].dest.prev_vout;
np->bestmask = bp->bestmask;
np->recvmask = bp->recvmask;
if ( (np->bestk= bp->bestk) >= 0 )
{
if ( (np->siglens[0]= bp->notaries[bp->myind].src.siglens[bp->bestk]) > 0 )
memcpy(np->sigs[0],bp->notaries[bp->myind].src.sigs[bp->bestk],np->siglens[0]);
if ( (np->siglens[1]= bp->notaries[bp->myind].dest.siglens[bp->bestk]) > 0 )
memcpy(np->sigs[1],bp->notaries[bp->myind].dest.sigs[bp->bestk],np->siglens[1]);
}
}
}
void dpow_ratify_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint8_t senderind,int8_t bestk,uint64_t bestmask,uint64_t recvmask,bits256 srcutxo,uint16_t srcvout,bits256 destutxo,uint16_t destvout,uint8_t siglens[2],uint8_t sigs[2][DPOW_MAXSIGLEN],uint32_t pendingcrcs[2])
{
int8_t bestks[64]; int32_t counts[64],i,j,numcrcs=0,numdiff,besti,best,bestmatches = 0,matches = 0; uint64_t masks[64],matchesmask; uint32_t crcval=0; char srcaddr[64],destaddr[64];
//char str[65],str2[65];
//printf("senderind.%d num.%d %s %s\n",senderind,bp->numnotaries,bits256_str(str,srcutxo),bits256_str(str2,destutxo));
if ( bp->isratify != 0 && senderind >= 0 && senderind < bp->numnotaries && bits256_nonz(srcutxo) != 0 && bits256_nonz(destutxo) != 0 )
{
memset(masks,0,sizeof(masks));
memset(bestks,0xff,sizeof(bestks));
memset(counts,0,sizeof(counts));
for (i=0; i<2; i++)
bp->notaries[senderind].pendingcrcs[i] = pendingcrcs[i];
bp->notaries[senderind].ratifysrcutxo = srcutxo;
bp->notaries[senderind].ratifysrcvout = srcvout;
bp->notaries[senderind].ratifydestutxo = destutxo;
bp->notaries[senderind].ratifydestvout = destvout;
bp->notaries[senderind].ratifybestmask = bestmask;
bp->notaries[senderind].ratifyrecvmask = recvmask;
if ( (bp->notaries[senderind].ratifybestk= bestk) >= 0 )
{
for (i=0; i<2; i++)
{
if ( (bp->notaries[senderind].ratifysiglens[i]= siglens[i]) != 0 )
{
memcpy(bp->notaries[senderind].ratifysigs[i],sigs[i],siglens[i]);
if ( bestk == bp->pendingratifybestk && bestmask == bp->pendingratifybestmask )
{
if ( ((1LL << senderind) & bestmask) != 0 )
bp->ratifysigmasks[i] |= (1LL << senderind);
} else bp->ratifysigmasks[i] &= ~(1LL << senderind);
}
}
}
//printf("RECV from %d best.(%d %llx) sigs.(%d %d) %llx %llx\n",senderind,bestk,(long long)bestmask,siglens[0],siglens[1],(long long)bp->ratifysigmasks[0],(long long)bp->ratifysigmasks[1]);
bp->ratifyrecvmask = 0;//|= (1LL << senderind) | (1LL << bp->myind);
bp->ratifybestmask = 0;
bp->ratifybestk = -1;
for (numdiff=i=0; i<bp->numnotaries; i++)
{
if ( bits256_nonz(bp->notaries[i].ratifysrcutxo) != 0 && bits256_nonz(bp->notaries[i].ratifydestutxo) != 0 )
bp->ratifyrecvmask |= (1LL << i);
if ( bp->notaries[i].ratifybestk < 0 || bp->notaries[i].ratifybestmask == 0 )
continue;
if ( bp->require0 != 0 && (bp->notaries[i].ratifybestmask & 1) == 0 )
continue;
for (j=0; j<numdiff; j++)
if ( bp->notaries[i].ratifybestk == bestks[j] && bp->notaries[i].ratifybestmask == masks[j] )
{
counts[j]++;
break;
}
if ( j == numdiff && bp->notaries[i].ratifybestk >= 0 && bp->notaries[i].ratifybestmask != 0 )
{
masks[numdiff] = bp->notaries[i].ratifybestmask;
bestks[numdiff] = bp->notaries[i].ratifybestk;
counts[numdiff]++;
//printf("j.%d numdiff.%d (%d %llx).%d\n",j,numdiff,bp->notaries[i].ratifybestk,(long long)bp->notaries[i].ratifybestmask,counts[numdiff]);
numdiff++;
}
}
besti = -1, best = 0;
for (i=0; i<numdiff; i++)
{
//printf("(%d %llx).%d ",bestks[i],(long long)masks[i],counts[i]);
if ( counts[i] > best )
{
best = counts[i];
besti = i;
}
}
if ( besti >= 0 && bestks[besti] >= 0 && masks[besti] != 0 && (bp->ratifyrecvmask & masks[besti]) == masks[besti] )
bp->ratifybestmask = masks[besti], bp->ratifybestk = bestks[besti];
//printf("numdiff.%d besti.%d numbest.%d (%d %llx) vs (%d %llx)\n",numdiff,besti,best,besti>=0?bestks[besti]:-1,(long long)(besti>=0?masks[besti]:0),bestk,(long long)bestmask);
if ( bp->ratifybestmask == 0 || (time(NULL) / 100) != bp->lastepoch )
{
bp->ratifybestmask = dpow_ratifybest(bp->ratifyrecvmask,bp,&bp->ratifybestk);
if ( (time(NULL) / 100) != bp->lastepoch )
{
bp->lastepoch = (uint32_t)(time(NULL) / 100);
printf("epoch %u\n",bp->lastepoch % bp->numnotaries);
sleep(2 + (rand() % 7));
}
}
bp->notaries[bp->myind].ratifybestk = bp->ratifybestk;
bp->notaries[bp->myind].ratifybestmask = bp->ratifybestmask;
bp->notaries[bp->myind].ratifyrecvmask = bp->ratifyrecvmask;
if ( bp->ratifybestk >= 0 )
{
for (matchesmask=i=0; i<bp->numnotaries; i++)
{
if ( bp->ratifybestk >= 0 && bp->notaries[i].ratifybestk == bp->ratifybestk && bp->notaries[i].ratifybestmask == bp->ratifybestmask )
{
matches++;
if ( ((1LL << i) & bp->ratifybestmask) != 0 )
{
matchesmask |= (1LL << i);
bestmatches++;
}
}
}
crcval = 0;
numcrcs = 0;
for (i=0; i<bp->numnotaries; i++)
{
if ( ((1LL << i) & matchesmask) != 0 )
{
if ( numcrcs == 0 )
numcrcs++, crcval = bp->notaries[i].pendingcrcs[bp->state < 1000];
else if ( numcrcs > 0 && crcval == bp->notaries[i].pendingcrcs[bp->state < 1000] )
numcrcs++;
}
}
//printf("crcval.%x numcrcs.%d bestmatches.%d matchesmask.%llx\n",crcval,numcrcs,bestmatches,(long long)matchesmask);
if ( bestmatches >= bp->minsigs )
{
if ( bp->pendingratifybestk != bp->ratifybestk || bp->pendingratifybestmask != bp->ratifybestmask )
{
printf("new PENDING RATIFY BESTK (%d %llx)\n",bp->ratifybestk,(long long)bp->ratifybestmask);
bp->pendingratifybestk = bp->ratifybestk;
bp->pendingratifybestmask = bp->ratifybestmask;
memset(bp->notaries[bp->myind].ratifysigs,0,sizeof(bp->notaries[bp->myind].ratifysigs));
memset(bp->notaries[bp->myind].ratifysiglens,0,sizeof(bp->notaries[bp->myind].ratifysiglens));
memset(bp->ratifysigmasks,0,sizeof(bp->ratifysigmasks));
dpow_signedtxgen(myinfo,dp,bp->destcoin,bp,bp->ratifybestk,bp->ratifybestmask,bp->myind,DPOW_SIGBTCCHANNEL,1,1);
for (i=0; i<bp->numnotaries; i++)
{
if ( i != bp->myind )
{
memset(&bp->notaries[i].ratifysrcutxo,0,sizeof(bp->notaries[i].ratifysrcutxo));
memset(&bp->notaries[i].ratifydestutxo,0,sizeof(bp->notaries[i].ratifydestutxo));
bp->notaries[i].ratifybestmask = bp->notaries[i].ratifyrecvmask = 0;
}
else if ( bp->require0 == 0 )
{
bitcoin_address(srcaddr,bp->srccoin->chain->pubtype,dp->minerkey33,33);
bitcoin_address(destaddr,bp->destcoin->chain->pubtype,dp->minerkey33,33);
if ( dpow_checkutxo(myinfo,dp,bp,bp->destcoin,&bp->notaries[i].dest.prev_hash,&bp->notaries[i].dest.prev_vout,destaddr) < 0 )
{
printf("dont have %s %s utxo, please send funds\n",dp->dest,destaddr);
}
if ( dpow_checkutxo(myinfo,dp,bp,bp->srccoin,&bp->notaries[i].src.prev_hash,&bp->notaries[i].src.prev_vout,srcaddr) < 0 )
{
printf("dont have %s %s utxo, please send funds\n",dp->symbol,srcaddr);
}
}
}
}
if ( bp->ratifysigmasks[1] == bp->pendingratifybestmask ) // have all sigs
{
if ( bp->state < 1000 )
{
dpow_sigscheck(myinfo,dp,bp,bp->myind,1,bp->pendingratifybestk,bp->pendingratifybestmask,bp->ratified_pubkeys,bp->numratified);
}
if ( bp->ratifysigmasks[0] == bp->pendingratifybestmask ) // have all sigs
{
if ( bp->state != 0xffffffff )
dpow_sigscheck(myinfo,dp,bp,bp->myind,0,bp->pendingratifybestk,bp->pendingratifybestmask,bp->ratified_pubkeys,bp->numratified);
}
else if ( ((1LL << bp->myind) & bp->ratifybestmask) != 0 && (rand() % 100) == 0 )
{
dpow_signedtxgen(myinfo,dp,bp->srccoin,bp,bp->ratifybestk,bp->ratifybestmask,bp->myind,DPOW_SIGCHANNEL,0,1);
}
//else printf("ratify srcmask.%llx != bestmask.%llx\n",(long long)bp->ratifysigmasks[0],(long long)bp->bestmask);
}
else if ( ((1LL << bp->myind) & bp->ratifybestmask) != 0 && (rand() % 100) == 0 )
{
dpow_signedtxgen(myinfo,dp,bp->destcoin,bp,bp->ratifybestk,bp->ratifybestmask,bp->myind,DPOW_SIGBTCCHANNEL,1,1);
}
//else printf("ratify destmask.%llx != bestmask.%llx\n",(long long)bp->ratifysigmasks[1],(long long)bp->bestmask);
}
}
if ( (rand() % 100) == 0 )
printf("[%d] numips.%d %s RATIFY.%d matches.%d bestmatches.%d bestk.%d %llx recv.%llx %llx sigmasks.(%llx %llx) crcval.%x num.%d\n",bp->myind,dp->numipbits,dp->symbol,bp->minsigs,matches,bestmatches,bp->ratifybestk,(long long)bp->ratifybestmask,(long long)bp->ratifyrecvmask,(long long)matchesmask,(long long)bp->ratifysigmasks[1],(long long)bp->ratifysigmasks[0],crcval,numcrcs);
}
}
void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint8_t senderind,int8_t bestk,uint64_t bestmask,uint64_t recvmask,bits256 srcutxo,uint16_t srcvout,bits256 destutxo,uint16_t destvout,uint8_t siglens[2],uint8_t sigs[2][DPOW_MAXSIGLEN])
{
int32_t i,bestmatches = 0,matches = 0;
if ( bp->isratify == 0 && bp->state != 0xffffffff && senderind >= 0 && senderind < bp->numnotaries && bits256_nonz(srcutxo) != 0 && bits256_nonz(destutxo) != 0 )
{
bp->notaries[senderind].src.prev_hash = srcutxo;
bp->notaries[senderind].src.prev_vout = srcvout;
bp->notaries[senderind].dest.prev_hash = destutxo;
bp->notaries[senderind].dest.prev_vout = destvout;
bp->notaries[senderind].bestmask = bestmask;
bp->notaries[senderind].recvmask = recvmask;
if ( (bp->notaries[senderind].bestk= bestk) >= 0 )
{
if ( (bp->notaries[senderind].src.siglens[bestk]= siglens[0]) != 0 )
{
memcpy(bp->notaries[senderind].src.sigs[bestk],sigs[0],siglens[0]);
if ( bestk == bp->bestk && bestmask == bp->bestmask )
bp->srcsigsmasks[bestk] |= (1LL << senderind);
else bp->srcsigsmasks[bestk] &= ~(1LL << senderind);
}
if ( (bp->notaries[senderind].dest.siglens[bestk]= siglens[1]) != 0 )
{
memcpy(bp->notaries[senderind].dest.sigs[bestk],sigs[1],siglens[1]);
if ( bestk == bp->bestk && bestmask == bp->bestmask )
bp->destsigsmasks[bestk] |= (1LL << senderind);
else bp->destsigsmasks[bestk] &= ~(1LL << senderind);
}
}
bp->recvmask |= (1LL << senderind) | (1LL << bp->myind);
bp->bestmask = dpow_maskmin(bp->recvmask,bp,&bp->bestk);
bp->notaries[bp->myind].bestk = bp->bestk;
bp->notaries[bp->myind].bestmask = bp->bestmask;
bp->notaries[bp->myind].recvmask = bp->recvmask;
if ( bp->bestk >= 0 )
{
for (i=0; i<bp->numnotaries; i++)
{
if ( bp->bestk >= 0 && bp->notaries[i].bestk == bp->bestk && bp->notaries[i].bestmask == bp->bestmask )
{
matches++;
if ( ((1LL << i) & bp->bestmask) != 0 )
bestmatches++;
} // else printf("mismatch.%d (%d %llx) ",i,bp->notaries[i].bestk,(long long)bp->notaries[i].bestmask);
}
if ( bestmatches >= bp->minsigs )
{
if ( bp->pendingbestk != bp->bestk || bp->pendingbestmask != bp->bestmask )
{
//printf("new PENDING BESTK (%d %llx) state.%d\n",bp->bestk,(long long)bp->bestmask,bp->state);
bp->pendingbestk = bp->bestk;
bp->pendingbestmask = bp->bestmask;
dpow_signedtxgen(myinfo,dp,bp->destcoin,bp,bp->bestk,bp->bestmask,bp->myind,DPOW_SIGBTCCHANNEL,1,0);
}
if ( bp->destsigsmasks[bp->bestk] == bp->bestmask ) // have all sigs
{
if ( bp->state < 1000 )
dpow_sigscheck(myinfo,dp,bp,bp->myind,1,bp->bestk,bp->bestmask,0,0);
if ( bp->srcsigsmasks[bp->bestk] == bp->bestmask ) // have all sigs
{
if ( bp->state != 0xffffffff )
dpow_sigscheck(myinfo,dp,bp,bp->myind,0,bp->bestk,bp->bestmask,0,0);
} //else printf("srcmask.%llx != bestmask.%llx\n",(long long)bp->srcsigsmasks[bp->bestk],(long long)bp->bestmask);
} //else printf("destmask.%llx != bestmask.%llx\n",(long long)bp->destsigsmasks[bp->bestk],(long long)bp->bestmask);
}
}
if ( (rand() % 100) == 0 )
printf("[%d] ips.%d %s NOTARIZE.%d matches.%d bestmatches.%d bestk.%d %llx recv.%llx sigmasks.(%llx %llx) senderind.%d state.%x (%x %x %x)\n",bp->myind,dp->numipbits,dp->symbol,bp->minsigs,matches,bestmatches,bp->bestk,(long long)bp->bestmask,(long long)bp->recvmask,(long long)(bp->bestk>=0?bp->destsigsmasks[bp->bestk]:0),(long long)(bp->bestk>=0?bp->srcsigsmasks[bp->bestk]:0),senderind,bp->state,bp->hashmsg.uints[0],bp->desttxid.uints[0],bp->srctxid.uints[0]);
}
}
void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,struct dpow_nanoutxo *np,int32_t isratify,int8_t senderind)
{
if ( isratify != 0 )
{
dpow_ratify_update(myinfo,dp,bp,senderind,np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->pendingcrcs);
}
else
{
dpow_notarize_update(myinfo,dp,bp,senderind,np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs);
}
//dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask);
}
void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen)
{
struct dpow_nanomsghdr *np; int32_t size,sentbytes = 0; uint32_t crc32;
struct dpow_nanomsghdr *np; int32_t i,size,sentbytes = 0; uint32_t crc32;
crc32 = calc_crc32(0,data,datalen);
//if ( (firstz= dpow_crc32find(myinfo,crc32,channel)) >= 0 )
{
//dp->crcs[firstz] = crc32;
size = (int32_t)(sizeof(*np) + datalen);
np = calloc(1,size);
//printf("dpow_send.(%d) size.%d\n",datalen,size);
np = calloc(1,size); // endian dependent!
if ( (np->numipbits= dp->numipbits) == 0 )
{
dp->ipbits[0] = myinfo->myaddr.myipbits;
np->numipbits = dp->numipbits = 1;
}
np->senderind = bp->myind;
memcpy(np->ipbits,dp->ipbits,dp->numipbits * sizeof(*dp->ipbits));
//for (i=0; i<np->numipbits; i++)
// printf("%08x ",np->ipbits[i]);
//printf(" dpow_send.(%d) size.%d numipbits.%d myind.%d\n",datalen,size,np->numipbits,bp->myind);
if ( bp->isratify == 0 )
dpow_nanoutxoset(&np->notarize,bp,0);
else dpow_nanoutxoset(&np->ratify,bp,1);
np->size = size;
np->datalen = datalen;
np->crc32 = crc32;
np->srchash = srchash;
for (i=0; i<2; i++)
np->ratify.pendingcrcs[i] = bp->pendingcrcs[i];
for (i=0; i<32; i++)
np->srchash.bytes[i] = dp->minerkey33[i+1];
//np->srchash = srchash;
np->desthash = desthash;
np->channel = channel;
np->height = msgbits;
np->myipbits = myinfo->myaddr.myipbits;
strcpy(np->symbol,dp->symbol);
np->version0 = DPOW_VERSION & 0xff;
np->version1 = (DPOW_VERSION >> 8) & 0xff;
@ -102,15 +486,58 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo
}
}
void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *ipbits,int32_t numipbits,int32_t fromid,uint32_t senderipbits)
{
int32_t i,j,matched,missing,n; char ipaddr[64];
if ( numipbits >= 64 )
{
printf("dpow_ipbitsadd reject from.%d numipbits.%d\n",fromid,numipbits);
return;
}
n = dp->numipbits;
matched = missing = 0;
//for (i=0; i<numipbits; i++)
// printf("%08x ",ipbits[i]);
for (i=0; i<numipbits; i++)
{
for (j=0; j<n; j++)
if ( ipbits[i] == dp->ipbits[j] )
{
matched++;
ipbits[i] = 0;
break;
}
if ( j == n )
missing++;
}
if ( (numipbits == 1 || missing < matched || matched > 0) && missing > 0 )
{
for (i=0; i<numipbits; i++)
if ( ipbits[i] != 0 )
{
expand_ipbits(ipaddr,ipbits[i]);
//printf("ADD NOTARY.(%s) %08x\n",ipaddr,ipbits[i]);
dpow_addnotary(myinfo,dp,ipaddr);
}
} else if ( missing > 0 )
printf("IGNORE from.%d RECV numips.%d numipbits.%d matched.%d missing.%d\n",fromid,numipbits,n,matched,missing);
expand_ipbits(ipaddr,senderipbits);
dpow_addnotary(myinfo,dp,ipaddr);
expand_ipbits(ipaddr,myinfo->myaddr.myipbits);
dpow_addnotary(myinfo,dp,ipaddr);
//printf("recv numips.(%d %d)\n",myinfo->numdpowipbits,dp->numipbits);
}
void dpow_nanomsg_update(struct supernet_info *myinfo)
{
int32_t i,n=0,size,firstz = -1; uint32_t crc32; struct dpow_nanomsghdr *np; struct dpow_info *dp;
int32_t i,n=0,size,firstz = -1; uint32_t crc32; struct dpow_nanomsghdr *np; struct dpow_info *dp; struct dpow_block *bp;
while ( (size= nn_recv(myinfo->dpowsock,&np,NN_MSG,0)) >= 0 )
{
if ( size >= 0 )
{
if ( np->version0 == (DPOW_VERSION & 0xff) && np->version1 == ((DPOW_VERSION >> 8) & 0xff) )
{
//printf("v.%02x %02x datalen.%d size.%d %d vs %d\n",np->version0,np->version1,np->datalen,size,np->datalen,(int32_t)(size - sizeof(*np)));
if ( np->datalen == (size - sizeof(*np)) )
{
crc32 = calc_crc32(0,np->packet,np->datalen);
@ -123,15 +550,28 @@ void dpow_nanomsg_update(struct supernet_info *myinfo)
break;
}
}
if ( dp != 0 && crc32 == np->crc32 && (firstz= dpow_crc32find(myinfo,dp,crc32,np->channel)) >= 0 )
if ( dp != 0 && crc32 == np->crc32 )//&& (firstz= dpow_crc32find(myinfo,dp,crc32,np->channel)) >= 0 )
{
//char str[65]; printf("%s RECV ht.%d ch.%08x (%d) crc32.%08x:%08x datalen.%d:%d firstz.%d\n",bits256_str(str,np->srchash),np->height,np->channel,size,np->crc32,crc32,np->datalen,(int32_t)(size - sizeof(*np)),firstz);
if ( i == myinfo->numdpows )
printf("received nnpacket for (%s)\n",np->symbol);
else if ( dpow_datahandler(myinfo,dp,np->channel,np->height,np->packet,np->datalen) >= 0 )
dp->crcs[firstz] = crc32;
else
{
dpow_ipbitsadd(myinfo,dp,np->ipbits,np->numipbits,np->senderind,np->myipbits);
if ( (bp= dpow_heightfind(myinfo,dp,np->height)) != 0 && bp->state != 0xffffffff )
{
if ( np->senderind >= 0 && np->senderind < bp->numnotaries && memcmp(bp-> notaries[np->senderind].pubkey+1,np->srchash.bytes,32) == 0 )
{
if ( bp->isratify == 0 )
dpow_nanoutxoget(myinfo,dp,bp,&np->notarize,0,np->senderind);
else dpow_nanoutxoget(myinfo,dp,bp,&np->ratify,1,np->senderind);
dpow_datahandler(myinfo,dp,bp,np->senderind,np->channel,np->height,np->packet,np->datalen);
}
}
//dp->crcs[firstz] = crc32;
}
}
} else printf("np->datalen.%d %d (size %d - %ld)\n",np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np));
} //else printf("ignore np->datalen.%d %d (size %d - %ld)\n",np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np));
}
if ( np != 0 )
nn_freemsg(np);
@ -155,57 +595,6 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) { }
#endif
int32_t dpow_rwcoinentry(int32_t rwflag,uint8_t *serialized,struct dpow_coinentry *src,struct dpow_coinentry *dest,int8_t *bestkp)
{
int8_t bestk; struct dpow_coinentry *ptr; int32_t siglen,iter,len = 0;
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(src->prev_hash),src->prev_hash.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(src->prev_vout),(uint32_t *)&src->prev_vout);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(dest->prev_hash),dest->prev_hash.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(dest->prev_vout),(uint32_t *)&dest->prev_vout);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(*bestkp),(uint32_t *)bestkp);
if ( (bestk= *bestkp) >= 0 )
{
for (iter=0; iter<2; iter++)
{
ptr = (iter == 0) ? src : dest;
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->siglens[bestk]),(uint32_t *)&ptr->siglens[bestk]);
if ( (siglen= ptr->siglens[bestk]) > 0 )
{
if ( rwflag != 0 )
memcpy(&serialized[len],ptr->sigs[bestk],siglen);
else memcpy(ptr->sigs[bestk],&serialized[len],siglen);
len += siglen;
}
}
}
return(len);
}
int32_t dpow_rwcoinentrys(int32_t rwflag,uint8_t *serialized,struct dpow_entry notaries[DPOW_MAXRELAYS],uint8_t numnotaries,int8_t bestk)
{
int32_t i,len = 0;
for (i=0; i<numnotaries; i++)
{
if ( rwflag != 0 )
notaries[i].bestk = bestk;
len += dpow_rwcoinentry(rwflag,&serialized[len],&notaries[i].src,&notaries[i].dest,&notaries[i].bestk);
}
return(len);
}
int32_t dpow_sendcoinentrys(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp)
{
uint8_t data[sizeof(struct dpow_coinentry)*64 + 4096]; bits256 zero; int32_t len = 0;
memset(zero.bytes,0,sizeof(zero));
//printf("ht.%d >>>>>>>>>>>>> dpow_sendcoinentrys (%d %llx) <- %llx\n",bp->height,bp->bestk,(long long)bp->bestmask,(long long)bp->recvmask);
data[len++] = bp->bestk;
data[len++] = bp->numnotaries;
len += iguana_rwbignum(1,&data[len],sizeof(bp->hashmsg),bp->hashmsg.bytes);
len += dpow_rwcoinentrys(1,&data[len],bp->notaries,bp->numnotaries,bp->bestk);
dpow_send(myinfo,dp,bp,zero,bp->hashmsg,DPOW_ENTRIESCHANNEL,bp->height,data,len);
return(len);
}
int32_t dpow_opreturnscript(uint8_t *script,uint8_t *opret,int32_t opretlen)
{
int32_t offset = 0;
@ -230,36 +619,20 @@ int32_t dpow_opreturnscript(uint8_t *script,uint8_t *opret,int32_t opretlen)
int32_t dpow_rwopret(int32_t rwflag,uint8_t *opret,bits256 *hashmsg,int32_t *heightmsgp,char *src,struct dpow_block *bp,int32_t src_or_dest)
{
int32_t i,opretlen = 0; bits256 beacon,beacons[DPOW_MAXRELAYS];
int32_t i,opretlen = 0; //bits256 beacon,beacons[DPOW_MAXRELAYS];
opretlen += iguana_rwbignum(rwflag,&opret[opretlen],sizeof(*hashmsg),hashmsg->bytes);
opretlen += iguana_rwnum(rwflag,&opret[opretlen],sizeof(*heightmsgp),(uint32_t *)heightmsgp);
if ( src_or_dest == 0 )
{
//char str[65]; printf("src_or_dest.%d opreturn add %s\n",src_or_dest,bits256_str(str,bp->desttxid));
if ( bits256_nonz(bp->desttxid) == 0 )
return(-1);
opretlen += iguana_rwbignum(rwflag,&opret[opretlen],sizeof(bp->desttxid),bp->desttxid.bytes);
if ( rwflag != 0 )
{
if ( src != 0 )
{
for (i=0; src[i]!=0; i++)
opret[opretlen++] = src[i];
}
opret[opretlen++] = 0;
}
else
{
if ( src != 0 )
{
for (i=0; opret[opretlen]!=0; i++)
src[i] = opret[opretlen++];
src[i] = 0;
}
opretlen++;
printf("no desttxid\n");
return(-1);
}
opretlen += iguana_rwbignum(rwflag,&opret[opretlen],sizeof(bp->desttxid),bp->desttxid.bytes);
}
else if ( 0 )
/*else if ( 0 )
{
memset(beacons,0,sizeof(beacons));
for (i=0; i<bp->numnotaries; i++)
@ -269,50 +642,27 @@ int32_t dpow_rwopret(int32_t rwflag,uint8_t *opret,bits256 *hashmsg,int32_t *hei
}
vcalc_sha256(0,beacon.bytes,beacons[0].bytes,sizeof(*beacons) * bp->numnotaries);
opretlen += iguana_rwbignum(rwflag,&opret[opretlen],sizeof(beacon),beacon.bytes);
}
return(opretlen);
}
int32_t dpow_rwutxobuf(int32_t rwflag,uint8_t *data,struct dpow_utxoentry *up,struct dpow_block *bp)
{
uint8_t numnotaries; uint64_t othermask; int32_t i,len = 0;
len += iguana_rwbignum(rwflag,&data[len],sizeof(up->hashmsg),up->hashmsg.bytes);
len += iguana_rwbignum(rwflag,&data[len],sizeof(up->srchash),up->srchash.bytes);
len += iguana_rwbignum(rwflag,&data[len],sizeof(up->desthash),up->desthash.bytes);
if ( bits256_nonz(up->srchash) == 0 || bits256_nonz(up->desthash) == 0 )
{
printf("dpow_rwutxobuf null src.%d or dest.%d\n",bits256_nonz(up->srchash),bits256_nonz(up->desthash));
return(-1);
}
len += iguana_rwbignum(rwflag,&data[len],sizeof(up->commit),up->commit.bytes);
len += iguana_rwnum(rwflag,&data[len],sizeof(up->recvmask),(uint8_t *)&up->recvmask);
len += iguana_rwnum(rwflag,&data[len],sizeof(up->height),(uint8_t *)&up->height);
len += iguana_rwnum(rwflag,&data[len],sizeof(up->srcvout),&up->srcvout);
len += iguana_rwnum(rwflag,&data[len],sizeof(up->destvout),&up->destvout);
len += iguana_rwnum(rwflag,&data[len],sizeof(up->bestk),&up->bestk);
}*/
if ( rwflag != 0 )
{
for (i=0; i<33; i++)
data[len++] = up->pubkey[i];
data[len++] = bp->numnotaries;
for (i=0; i<bp->numnotaries; i++)
len += iguana_rwnum(rwflag,&data[len],sizeof(*up->othermasks),(uint8_t *)&up->othermasks[(int32_t)i]);
if ( src != 0 )
{
for (i=0; src[i]!=0; i++)
opret[opretlen++] = src[i];
}
opret[opretlen++] = 0;
}
else
{
for (i=0; i<33; i++)
up->pubkey[i] = data[len++];
numnotaries = data[len++];
if ( numnotaries <= bp->numnotaries )
if ( src != 0 )
{
for (i=0; i<numnotaries; i++)
{
len += iguana_rwnum(rwflag,&data[len],sizeof(othermask),(uint8_t *)&othermask);
bp->notaries[(int32_t)i].othermask |= othermask;
}
} else return(-1);
for (i=0; opret[opretlen]!=0; i++)
src[i] = opret[opretlen++];
src[i] = 0;
}
opretlen++;
}
return(len);
return(opretlen);
}
int32_t dpow_rwsigentry(int32_t rwflag,uint8_t *data,struct dpow_sigentry *dsig)

21
iguana/dpow/dpow_prices.c

@ -723,7 +723,7 @@ double PAX_calcspline(struct PAX_spline *spline,double *outputs,double *slopes,i
if ( (f[n]= splinevals[i]) != 0. && utc32[i] != 0 )
{
//printf("i%d.(%u %f) ",i,utc32[i],splinevals[i]);
printf("%f ",splinevals[i]);
//printf("%f ",splinevals[i]);
if ( n > 0 )
{
if ( (gaps[n-1]= utc32[i] - lastxval) < 0 )
@ -860,12 +860,12 @@ int32_t PAX_genspline(struct PAX_spline *spline,int32_t splineid,char *name,uint
{
if ( i < spline->num )
{
if ( refvals[i] != 0 && output[i * 24] != refvals[i] )
if ( 0 && refvals[i] != 0 && output[i * 24] != refvals[i] )
printf("{%.8f != %.8f}.%d ",output[i * 24],refvals[i],i);
spline->pricevals[i] = output[i * 24];
}
}
printf("spline.%s num.%d\n",name,spline->num);
//printf("spline.%s num.%d\n",name,spline->num);
return(spline->num);
}
@ -1269,12 +1269,11 @@ int32_t PAX_ecbparse(char *date,double *prices,char *url,int32_t basenum)
char *jsonstr,*relstr,*basestr,name[16]; int32_t count=0,i,relnum; cJSON *json,*ratesobj,*item; struct destbuf tmp;
if ( (jsonstr= issue_curl(url)) != 0 )
{
//if ( Debuglevel > 2 )
if ( Debuglevel > 2 )
printf("(%s)\n",jsonstr);
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
copy_cJSON(&tmp,jobj(json,"date")), safecopy(date,tmp.buf,64);
printf("tmpdate.(%s)\n",date);
if ( (basestr= jstr(json,"base")) != 0 && strcmp(basestr,CURRENCIES[basenum]) == 0 && (ratesobj= jobj(json,"rates")) != 0 && (item= ratesobj->child) != 0 )
{
while ( item != 0 )
@ -1329,7 +1328,7 @@ int32_t PAX_ecbprices(char *date,double *prices,int32_t year,int32_t month,int32
count += PAX_ecbparse(basenum == 0 ? date : tmpdate,prices,url,basenum);
if ( (basenum != 0 && strcmp(tmpdate,date) != 0) || (checkdate[0] != 0 && strcmp(checkdate,date) != 0) )
{
printf("date mismatch (%s) != (%s) or checkdate.(%s)\n",tmpdate,date,checkdate);
//printf("date mismatch (%s) != (%s) or checkdate.(%s)\n",tmpdate,date,checkdate);
return(-1);
}
}
@ -1364,7 +1363,7 @@ int32_t ecb_matrix(double basevals[MAX_CURRENCIES],double matrix[MAX_CURRENCIES]
loaded = 1;
else printf("fread error\n");
fclose(fp);
} else printf("ecb_matrix.(%s) load error fp.%p\n",fname,fp);
} //else printf("ecb_matrix.(%s) load error fp.%p\n",fname,fp);
datenum = conv_date(&seconds,date);
year = datenum / 10000, month = (datenum / 100) % 100, day = (datenum % 100);
if ( loaded == 0 )
@ -1378,7 +1377,7 @@ int32_t ecb_matrix(double basevals[MAX_CURRENCIES],double matrix[MAX_CURRENCIES]
loaded = 1;
fclose(fp);
}
} else printf("peggy_matrix error loading %d.%d.%d\n",year,month,day);
} //else printf("peggy_matrix error loading %d.%d.%d\n",year,month,day);
}
else
{
@ -1410,7 +1409,7 @@ int32_t ecb_matrix(double basevals[MAX_CURRENCIES],double matrix[MAX_CURRENCIES]
//"2000-01-03"
if ( (datenum= conv_date(&seconds,date)) < 0 )
return(-1);
printf("loaded.(%s) nonz.%d (%d %d %d) datenum.%d\n",date,n,year,month,day,datenum);
//printf("loaded.(%s) nonz.%d (%d %d %d) datenum.%d\n",date,n,year,month,day,datenum);
return(datenum);
}
@ -1771,7 +1770,7 @@ void PAX_genecbsplines(struct PAX_data *dp)
datenum = OS_conv_unixtime(&t,&seconds,(uint32_t)time(NULL)-(28-i+1)*24*3600);
expand_datenum(dp->edate,datenum);
timestamp = OS_conv_datenum(datenum,12,0,0);
printf("i.%d datenum.%d %s t%u\n",i,datenum,dp->edate,timestamp);
//printf("i.%d datenum.%d %s t%u\n",i,datenum,dp->edate,timestamp);
if ( (datenum= ecb_matrix(dp->basevals,dp->ecbmatrix,dp->edate)) > 0 )
{
utc32[numsamples] = timestamp;
@ -1795,7 +1794,7 @@ void PAX_genecbsplines(struct PAX_data *dp)
prices[j][numsamples+1] = prices[j][numsamples-1] + diff;
diff += prices[j][numsamples-1] - PAX_splineval(&dp->splines[j],utc32[numsamples-1] - 16*3600,1);
prices[j][numsamples+2] = prices[j][numsamples-1] + diff;
printf("%s splineval %f vs %f %f %f\n",CURRENCIES[j],prices[j][numsamples-1],prices[j][numsamples],prices[j][numsamples+1],prices[j][numsamples+2]);
//printf("%s splineval %f vs %f %f %f\n",CURRENCIES[j],prices[j][numsamples-1],prices[j][numsamples],prices[j][numsamples+1],prices[j][numsamples+2]);
PAX_genspline(&dp->splines[j],j,CURRENCIES[j],utc32,prices[j],numsamples+3,prices[j]);
}
}

82
iguana/dpow/dpow_rpc.c

@ -15,14 +15,14 @@
#define issue_curl(cmdstr) bitcoind_RPC(0,"curl",cmdstr,0,0,0)
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t kmdheight)
int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height)
{
int32_t i,num=-1; struct iguana_info *coin; char params[256],*retstr,*pubkeystr; cJSON *retjson,*item,*array;
if ( (coin= iguana_coinfind("KMD")) != 0 )
if ( (coin= iguana_coinfind(symbol)) != 0 )
{
if ( coin->FULLNODE < 0 )
{
sprintf(params,"[\"%d\"]",kmdheight);
sprintf(params,"[\"%d\"]",height);
if ( (retstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"notaries",params)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
@ -62,7 +62,7 @@ bits256 dpow_getbestblockhash(struct supernet_info *myinfo,struct iguana_info *c
return(coin->lastbesthash);
if ( (retstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getbestblockhash","")) != 0 )
{
if ( strcmp(coin->symbol,"USD") == 0 )
if ( 0 && strcmp(coin->symbol,"USD") == 0 )
printf("%s getbestblockhash.(%s)\n",coin->symbol,retstr);
if ( is_hexstr(retstr,0) == sizeof(blockhash)*2 )
decode_hex(blockhash.bytes,sizeof(blockhash),retstr);
@ -85,6 +85,36 @@ bits256 dpow_getbestblockhash(struct supernet_info *myinfo,struct iguana_info *c
return(blockhash);
}
bits256 dpow_getblockhash(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height)
{
char buf[128],*retstr=0; bits256 blockhash;
memset(blockhash.bytes,0,sizeof(blockhash));
if ( coin->FULLNODE < 0 )
{
sprintf(buf,"%d",height);
retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getblockhash",buf);
//printf("%s ht.%d -> getblockhash.(%s)\n",coin->symbol,height,retstr);
usleep(10000);
}
else if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 )
{
printf("test iguana mode getblockhash\n");
retstr = bitcoinrpc_getblockhash(myinfo,coin,0,0,height);
}
else
{
return(blockhash);
}
if ( retstr != 0 )
{
if ( strlen(retstr) == 64 )
decode_hex(blockhash.bytes,32,retstr);
free(retstr);
}
return(blockhash);
}
cJSON *dpow_getblock(struct supernet_info *myinfo,struct iguana_info *coin,bits256 blockhash)
{
char buf[128],str[65],*retstr=0; cJSON *json = 0;
@ -94,6 +124,7 @@ cJSON *dpow_getblock(struct supernet_info *myinfo,struct iguana_info *coin,bits2
retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getblock",buf);
if ( 0 && strcmp(coin->symbol,"USD") == 0 )
printf("%s getblock.(%s)\n",coin->symbol,retstr);
usleep(10000);
}
else if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 )
{
@ -111,6 +142,32 @@ cJSON *dpow_getblock(struct supernet_info *myinfo,struct iguana_info *coin,bits2
return(json);
}
cJSON *dpow_gettxout(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout)
{
char buf[128],str[65],*retstr=0; cJSON *json = 0;
sprintf(buf,"\"%s\", %d",bits256_str(str,txid),vout);
if ( coin->FULLNODE < 0 )
{
retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"gettxout",buf);
usleep(10000);
}
else if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 )
{
printf("need to test following call\n");
retstr = bitcoinrpc_gettxout(myinfo,coin,0,buf,txid,1,0); // untested
}
else
{
return(0);
}
if ( retstr != 0 )
{
json = cJSON_Parse(retstr);
free(retstr);
}
return(json);
}
char *dpow_decoderawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,char *rawtx)
{
char *retstr,*paramstr; cJSON *array;
@ -122,6 +179,7 @@ char *dpow_decoderawtransaction(struct supernet_info *myinfo,struct iguana_info
retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"decoderawtransaction",paramstr);
//printf("%s decoderawtransaction.(%s) <- (%s)\n",coin->symbol,retstr,paramstr);
free(paramstr);
usleep(10000);
}
else if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 )
{
@ -145,6 +203,7 @@ cJSON *dpow_gettransaction(struct supernet_info *myinfo,struct iguana_info *coin
retstr = dpow_decoderawtransaction(myinfo,coin,rawtx);
free(rawtx);
}
usleep(10000);
}
else if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 )
{
@ -195,9 +254,11 @@ char *dpow_signrawtransaction(struct supernet_info *myinfo,struct iguana_info *c
jaddistr(array,rawtx);
jaddi(array,jduplicate(vins));
paramstr = jprint(array,1);
//printf("signrawtransaction\n");
retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"signrawtransaction",paramstr);
//printf("%s signrawtransaction.(%s) params.(%s)\n",coin->symbol,retstr,paramstr);
free(paramstr);
usleep(10000);
return(retstr);
}
else if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 )
@ -233,6 +294,7 @@ char *dpow_signrawtransaction(struct supernet_info *myinfo,struct iguana_info *c
}
}
retstr = bitcoinrpc_signrawtransaction(myinfo,coin,0,0,rawtx,vins,privkeys,"ALL");
printf("call sign.(%s) vins.(%s) privs.(%s) -> (%s)\n",rawtx,jprint(vins,0),jprint(privkeys,0),retstr);
free_json(privkeys);
return(retstr);
}
@ -287,7 +349,7 @@ int32_t dpow_getchaintip(struct supernet_info *myinfo,bits256 *blockhashp,uint32
{
for (i=0; i<n&&i<maxtx; i++)
txs[i] = jbits256i(array,i);
//if ( 0 && strcmp(coin->symbol,"USD") == 0 )
if ( 0 && strcmp(coin->symbol,"USD") == 0 )
printf("dpow_getchaintip %s ht.%d time.%u numtx.%d\n",coin->symbol,height,*blocktimep,n);
*numtxp = n;
}
@ -316,7 +378,7 @@ int32_t dpow_vini_ismine(struct supernet_info *myinfo,struct dpow_info *dp,cJSON
int32_t dpow_haveutxo(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,char *coinaddr)
{
int32_t i,n,vout,haveutxo = 0; bits256 txid; cJSON *unspents,*item; uint64_t satoshis; char *str,*address; uint8_t script[35];
int32_t i,j,n,vout,haveutxo = 0; uint32_t r; bits256 txid; cJSON *unspents,*item; uint64_t satoshis; char *str,*address; uint8_t script[35];
memset(txidp,0,sizeof(*txidp));
*voutp = -1;
if ( (unspents= dpow_listunspent(myinfo,coin,coinaddr)) != 0 )
@ -332,8 +394,12 @@ int32_t dpow_haveutxo(struct supernet_info *myinfo,struct iguana_info *coin,bits
"confirmations" : 4282,
"spendable" : true
},*/
for (i=0; i<n; i++)
r = 0;
memcpy(&r,coin->symbol,3);
r = calc_crc32(0,(void *)&r,sizeof(r));
for (j=0; j<n; j++)
{
i = (r + j) % n;
item = jitem(unspents,i);
satoshis = SATOSHIDEN * jdouble(item,"amount");
if ( satoshis == DPOW_UTXOSIZE && (address= jstr(item,"address")) != 0 && strcmp(address,coinaddr) == 0 )
@ -813,7 +879,7 @@ int32_t dpow_issuer_iteration(struct dpow_info *dp,struct iguana_info *coin,int3
}
else
{
printf("error from %s\n",coin->symbol);
//printf("error from %s\n",coin->symbol);
sleep(3);
}
return(height);

367
iguana/dpow/dpow_tx.c

@ -13,18 +13,48 @@
* *
******************************************************************************/
#define DPOW_BLACKLIST -100000
void dpow_bestmask_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint8_t nn_senderind,int8_t nn_bestk,uint64_t nn_bestmask,uint64_t nn_recvmask)
{
int32_t startscore;
if ( nn_senderind < 0 || nn_senderind >= bp->numnotaries )
return;
bp->notaries[nn_senderind].bestk = nn_bestk;
bp->notaries[nn_senderind].bestmask = nn_bestmask;
bp->notaries[nn_senderind].recvmask = nn_recvmask;
startscore = bp->scores[nn_senderind];
if ( bp->bestk >= 0 )
{
if ( nn_bestk < 0 )
bp->scores[nn_senderind] -= 10;
else if ( nn_bestk != bp->bestk )
bp->scores[nn_senderind]--;
else if ( nn_bestmask != bp->bestmask )
bp->scores[nn_senderind]--;
else if ( bp->scores[nn_senderind] < 1 )
bp->scores[nn_senderind] = 1;
else bp->scores[nn_senderind]++;
if ( startscore > DPOW_BLACKLIST && bp->scores[nn_senderind] <= DPOW_BLACKLIST )
printf(">>>>>>>>>>>>> nn_senderind.%d %llx MIA, skip this node for now\n",nn_senderind,(long long)(1LL << nn_senderind));
}
}
uint64_t dpow_lastk_mask(struct dpow_block *bp,int8_t *lastkp)
{
int32_t j,m,k; uint64_t mask = 0;
int32_t j,m,k; uint64_t mask = bp->require0;
*lastkp = -1;
for (j=m=0; j<bp->numnotaries; j++)
m = bp->require0;
for (j=0; j<bp->numnotaries; j++)
{
k = DPOW_MODIND(bp,j);//((bp->height % bp->numnotaries) + j) % bp->numnotaries;
k = DPOW_MODIND(bp,j);
if ( (bp->require0 == 0 || k != 0) && bp->scores[k] < DPOW_BLACKLIST )
continue;
if ( bits256_nonz(bp->notaries[k].src.prev_hash) != 0 && bits256_nonz(bp->notaries[k].dest.prev_hash) != 0 )
{
bp->recvmask |= (1LL << k);
mask |= (1LL << k);
if ( ++m >= DPOW_M(bp) )
if ( ++m >= bp->minsigs )
{
*lastkp = k;
break;
@ -45,17 +75,45 @@ int32_t dpow_bestk(struct dpow_block *bp,uint64_t *maskp)
return(lastk);
}
uint64_t dpow_ratifybest(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp)
{
int32_t m,j,k; uint64_t bestmask,mask = bp->require0;
bestmask = 0;
*lastkp = -1;
for (m=j=0; j<bp->numnotaries; j++)
{
k = (j + ((uint32_t)time(NULL) / 100)) % bp->numnotaries;//DPOW_MODIND(bp,j);
if ( bp->require0 != 0 && k == 0 )
continue;
if ( bits256_nonz(bp->notaries[k].ratifysrcutxo) != 0 && bits256_nonz(bp->notaries[k].ratifydestutxo) != 0 )
{
mask |= (1LL << k);
if ( ++m == bp->minsigs-bp->require0 )
{
*lastkp = k;
bestmask = mask | bp->require0;
//printf("m.%d == minsigs.%d (%d %llx)\n",m,bp->minsigs,k,(long long)bestmask);
}
}
}
return(bestmask);
}
uint64_t dpow_maskmin(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp)
{
int32_t j,m,k; uint64_t bestmask,mask;
bestmask = mask = 0;
for (j=m=0; j<bp->numnotaries; j++)
int32_t j,m,k; uint64_t bestmask,mask = 0;//bp->require0;
bestmask = 0;
*lastkp = -1;
m = 0;//bp->require0;
for (j=0; j<bp->numnotaries; j++)
{
k = DPOW_MODIND(bp,j);
//if ( (bp->require0 == 0 || k != 0) && bp->scores[k] < DPOW_BLACKLIST )
// continue;
if ( bits256_nonz(bp->notaries[k].src.prev_hash) != 0 && bits256_nonz(bp->notaries[k].dest.prev_hash) != 0 )
{
mask |= (1LL << k);
if ( ++m == DPOW_M(bp) )
if ( ++m == bp->minsigs )
{
*lastkp = k;
bestmask = mask;
@ -105,50 +163,50 @@ struct dpow_block *dpow_heightfind(struct supernet_info *myinfo,struct dpow_info
return(bp);
}
int32_t dpow_voutratify(struct dpow_block *bp,uint8_t *serialized,int32_t m,uint8_t pubkeys[][33],int32_t numratified)
int32_t dpow_voutstandard(struct dpow_block *bp,uint8_t *serialized,int32_t m,int32_t src_or_dest,uint8_t pubkeys[][33],int32_t numratified)
{
uint64_t satoshis; uint32_t locktime = 0; uint32_t numvouts; int32_t i,len = 0;
numvouts = numratified + 1;
len += iguana_rwvarint32(1,&serialized[len],&numvouts);
satoshis = DPOW_UTXOSIZE;
len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis);
serialized[len++] = 35;
serialized[len++] = 33;
decode_hex(&serialized[len],33,CRYPTO777_PUBSECPSTR), len += 33;
serialized[len++] = CHECKSIG;
satoshis = DPOW_MINOUTPUT;
for (i=0; i<numratified; i++)
uint32_t locktime=0,numvouts; uint64_t satoshis,satoshisB; int32_t i,opretlen,len=0; uint8_t opret[1024],data[4096];
numvouts = 2;
if ( pubkeys == 0 || numratified <= 0 )
{
len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis);
serialized[len++] = 35;
serialized[len++] = 33;
memcpy(&serialized[len],pubkeys[i],33), len += 33;
serialized[len++] = CHECKSIG;
satoshis = DPOW_UTXOSIZE * m * .76;
if ( (satoshisB= DPOW_UTXOSIZE * m - 10000) < satoshis )
satoshis = satoshisB;
}
else
{
satoshis = DPOW_MINOUTPUT;
numvouts += numratified;
}
len += iguana_rwnum(1,&serialized[len],sizeof(locktime),&locktime);
return(len);
}
int32_t dpow_voutstandard(struct dpow_block *bp,uint8_t *serialized,int32_t m,int32_t src_or_dest)
{
uint32_t locktime=0,numvouts; uint64_t satoshis,satoshisB; int32_t opretlen,len=0; uint8_t opret[1024],data[4096];
numvouts = 2;
len += iguana_rwvarint32(1,&serialized[len],&numvouts);
satoshis = DPOW_UTXOSIZE * m * .76;
if ( (satoshisB= DPOW_UTXOSIZE * m - 10000) < satoshis )
satoshis = satoshisB;
len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis);
serialized[len++] = 35;
serialized[len++] = 33;
decode_hex(&serialized[len],33,CRYPTO777_PUBSECPSTR), len += 33;
serialized[len++] = CHECKSIG;
if ( pubkeys != 0 && numratified != 0 )
{
satoshis = DPOW_MINOUTPUT;
for (i=0; i<numratified; i++)
{
len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis);
serialized[len++] = 35;
serialized[len++] = 33;
memcpy(&serialized[len],pubkeys[i],33), len += 33;
serialized[len++] = CHECKSIG;
}
printf("numvouts.%d len.%d RATIFY vouts\n",numvouts,len);
}
satoshis = 0;
len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis);
if ( src_or_dest != 0 )
opretlen = dpow_rwopret(1,opret,&bp->hashmsg,&bp->height,0,bp,src_or_dest);
opretlen = dpow_rwopret(1,opret,&bp->hashmsg,&bp->height,bp->srccoin->symbol,bp,src_or_dest);
else opretlen = dpow_rwopret(1,opret,&bp->hashmsg,&bp->height,bp->srccoin->symbol,bp,src_or_dest);
if ( opretlen < 0 )
{
printf("negative opretlen src_or_dest.%d\n",src_or_dest);
return(-1);
}
opretlen = dpow_opreturnscript(data,opret,opretlen);
if ( opretlen < 0xfd )
serialized[len++] = opretlen;
@ -165,7 +223,7 @@ int32_t dpow_voutstandard(struct dpow_block *bp,uint8_t *serialized,int32_t m,in
bits256 dpow_notarytx(char *signedtx,int32_t *numsigsp,int32_t isPoS,struct dpow_block *bp,int8_t bestk,uint64_t bestmask,int32_t usesigs,int32_t src_or_dest,uint8_t pubkeys[][33],int32_t numratified)
{
uint32_t k,j,m,numsigs,version,sequenceid = 0xffffffff; bits256 zero; int32_t n,siglen,len; uint8_t serialized[32768]; struct dpow_entry *ep; struct dpow_coinentry *cp;
uint32_t k,m,numsigs,version,vout,sequenceid = 0xffffffff; bits256 zero; int32_t n,siglen,len; uint8_t serialized[32768],*sig; bits256 txid; struct dpow_entry *ep; struct dpow_coinentry *cp;
signedtx[0] = 0;
*numsigsp = 0;
memset(zero.bytes,0,sizeof(zero));
@ -174,84 +232,145 @@ bits256 dpow_notarytx(char *signedtx,int32_t *numsigsp,int32_t isPoS,struct dpow
len += iguana_rwnum(1,&serialized[len],sizeof(version),&version);
if ( isPoS != 0 )
len += iguana_rwnum(1,&serialized[len],sizeof(bp->timestamp),&bp->timestamp);
m = DPOW_M(bp);
m = bp->minsigs;
len += iguana_rwvarint32(1,&serialized[len],(uint32_t *)&m);
for (j=m=0; j<bp->numnotaries; j++)
for (k=m=0; k<bp->numnotaries; k++)
{
k = DPOW_MODIND(bp,j);
siglen = 0;
sig = 0;
if ( ((1LL << k) & bestmask) != 0 )
{
ep = &bp->notaries[k];
cp = (src_or_dest != 0) ? &bp->notaries[k].dest : &bp->notaries[k].src;
if ( bits256_nonz(cp->prev_hash) == 0 )
return(cp->prev_hash);
len += iguana_rwbignum(1,&serialized[len],sizeof(cp->prev_hash),cp->prev_hash.bytes);
len += iguana_rwnum(1,&serialized[len],sizeof(cp->prev_vout),&cp->prev_vout);
siglen = cp->siglens[bestk];
if ( usesigs != 0 )
if ( pubkeys != 0 && numratified > 0 )
{
if ( src_or_dest != 0 )
{
txid = bp->notaries[k].ratifydestutxo;
vout = bp->notaries[k].ratifydestvout;
}
else
{
txid = bp->notaries[k].ratifysrcutxo;
vout = bp->notaries[k].ratifysrcvout;
}
if ( bestk >= 0 )
{
siglen = bp->notaries[k].ratifysiglens[src_or_dest];
sig = bp->notaries[k].ratifysigs[src_or_dest];
}
//char str[65]; printf("j.%d k.%d m.%d vin.(%s) v%d siglen.%d\n",j,k,m,bits256_str(str,txid),vout,siglen);
}
else
{
ep = &bp->notaries[k];
cp = (src_or_dest != 0) ? &bp->notaries[k].dest : &bp->notaries[k].src;
if ( bits256_nonz(cp->prev_hash) == 0 )
{
printf("null prevhash k.%d m.%d src_or_dest.%d\n",k,m,src_or_dest);
return(zero);
}
txid = cp->prev_hash;
vout = cp->prev_vout;
if ( bestk >= 0 )
{
siglen = cp->siglens[bestk];
sig = cp->sigs[bestk];
}
}
len += iguana_rwbignum(1,&serialized[len],sizeof(txid),txid.bytes);
len += iguana_rwnum(1,&serialized[len],sizeof(vout),&vout);
if ( usesigs != 0 && bestk >= 0 )
{
len += iguana_rwvarint32(1,&serialized[len],(uint32_t *)&siglen);
if ( siglen > 0 && siglen <= sizeof(cp->sigs[bestk]) )
{
memcpy(&serialized[len],cp->sigs[bestk],siglen);
memcpy(&serialized[len],sig,siglen);
len += siglen;
numsigs++;
}
} else printf("Missing sig from k.%d\n",k);
} else serialized[len++] = 0;
len += iguana_rwnum(1,&serialized[len],sizeof(sequenceid),&sequenceid);
//printf("height.%d mod.%d VINI.%d <- i.%d j.%d\n",height,height % numnotaries,m,i,j);
m++;
if ( m == DPOW_M(bp) && k == bestk )
if ( m == bp->minsigs )//&& k == bestk )
break;
}
}
if ( pubkeys != 0 && numratified > 0 )
if ( (n= dpow_voutstandard(bp,&serialized[len],m,src_or_dest,pubkeys,numratified)) < 0 )
{
if ( (n= dpow_voutratify(bp,&serialized[len],m,pubkeys,numratified)) < 0 )
return(zero);
len += n;
}
else
{
if ( (n= dpow_voutstandard(bp,&serialized[len],m,src_or_dest)) < 0 )
return(zero);
len += n;
printf("error dpow_voutstandard m.%d src_or_dest.%d\n",m,src_or_dest);
return(zero);
}
len += n;
init_hexbytes_noT(signedtx,serialized,len);
//printf("notarytx.(%s) opretlen.%d\n",signedtx,opretlen);
*numsigsp = numsigs;
return(bits256_doublesha256(0,serialized,len));
}
cJSON *dpow_vins(struct iguana_info *coin,struct dpow_block *bp,int8_t bestk,uint64_t bestmask,int32_t usesigs,int32_t src_or_dest)
cJSON *dpow_vins(struct iguana_info *coin,struct dpow_block *bp,int8_t bestk,uint64_t bestmask,int32_t usesigs,int32_t src_or_dest,int32_t useratified)
{
int32_t k,j,m=0; uint8_t script[35]; char scriptstr[256]; cJSON *vins=0,*item; struct dpow_entry *ep; struct dpow_coinentry *cp;
int32_t k,m; bits256 txid; uint16_t vout; uint8_t script[35]; char scriptstr[256]; cJSON *vins=0,*item; struct dpow_entry *ep; struct dpow_coinentry *cp;
vins = cJSON_CreateArray();
for (j=0; j<bp->numnotaries; j++)
for (m=k=0; k<bp->numnotaries; k++)
{
k = DPOW_MODIND(bp,j);
if ( ((1LL << k) & bestmask) != 0 )
{
ep = &bp->notaries[k];
cp = (src_or_dest != 0) ? &bp->notaries[k].dest : &bp->notaries[k].src;
if ( bits256_nonz(cp->prev_hash) != 0 )
if ( useratified != 0 )
{
if ( src_or_dest != 0 )
{
txid = bp->notaries[k].ratifydestutxo;
vout = bp->notaries[k].ratifydestvout;
}
else
{
txid = bp->notaries[k].ratifysrcutxo;
vout = bp->notaries[k].ratifysrcvout;
}
}
else
{
cp = (src_or_dest != 0) ? &bp->notaries[k].dest : &bp->notaries[k].src;
txid = cp->prev_hash;
vout = cp->prev_vout;
}
if ( bits256_nonz(txid) != 0 )
{
item = cJSON_CreateObject();
jaddbits256(item,"txid",cp->prev_hash);
jaddnum(item,"vout",cp->prev_vout);
script[0] = 33;
memcpy(script+1,ep->pubkey,33);
script[34] = CHECKSIG;
init_hexbytes_noT(scriptstr,script,35);
jaddbits256(item,"txid",txid);
jaddnum(item,"vout",vout);
if ( k == 0 && bp->require0 != 0 )
{
script[0] = 0x76;
script[1] = 0xa9;
script[2] = 0x14;
calc_rmd160_sha256(&script[3],ep->pubkey,33); // 8ee61a3161993f4f7b7081259bf5f3322d65d3f8
script[23] = 0x88;
script[24] = 0xac;
init_hexbytes_noT(scriptstr,script,25);
/*int32_t z;
for (z=0; z<25; z++)
printf("%02x",script[z]);
printf(" <- script0\n");*/
}
else
{
script[0] = 33;
memcpy(script+1,ep->pubkey,33);
script[34] = CHECKSIG;
init_hexbytes_noT(scriptstr,script,35);
}
jaddstr(item,"scriptPubKey",scriptstr);
jaddi(vins,item);
//printf("height.%d mod.%d VINI.%d <- i.%d j.%d\n",height,height % numnotaries,m,i,j);
m++;
if ( m == DPOW_M(bp) && k == bestk )
if ( m == bp->minsigs )//&& k == bestk )
break;
}
else
{
printf("null txid slot k.%d m.%d minsigs.%d\n",k,m,bp->minsigs);
free_json(vins);
return(0);
}
@ -263,6 +382,8 @@ cJSON *dpow_vins(struct iguana_info *coin,struct dpow_block *bp,int8_t bestk,uin
void dpow_rawtxsign(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,struct dpow_block *bp,char *rawtx,cJSON *vins,int8_t bestk,uint64_t bestmask,int32_t myind,int32_t src_or_dest)
{
int32_t j,m=0,retval=-1; char *jsonstr,*signedtx,*rawtx2,*sigstr; cJSON *signobj,*sobj,*txobj2,*item,*vin; bits256 srchash; struct dpow_entry *ep; struct dpow_coinentry *cp;
if ( bestk < 0 )
return;
for (j=0; j<sizeof(srchash); j++)
srchash.bytes[j] = dp->minerkey33[j+1];
m = 0;
@ -307,30 +428,70 @@ void dpow_rawtxsign(struct supernet_info *myinfo,struct dpow_info *dp,struct igu
}
}
int32_t dpow_signedtxgen(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,struct dpow_block *bp,int8_t bestk,uint64_t bestmask,int32_t myind,uint32_t sigchannel,int32_t src_or_dest)
int32_t dpow_signedtxgen(struct supernet_info *myinfo,struct dpow_info *dp,struct iguana_info *coin,struct dpow_block *bp,int8_t bestk,uint64_t bestmask,int32_t myind,uint32_t deprec,int32_t src_or_dest,int32_t useratified)
{
int32_t j,numsigs,retval=-1; char rawtx[32768]; cJSON *vins; bits256 txid,srchash,zero; struct dpow_entry *ep;
//bestmask = dpow_maskmin(bestmask,bp,&bestk);
int32_t j,m,numsigs,len,siglen,retval=-1; uint32_t crcval; char rawtx[32768],*jsonstr,*rawtx2,*signedtx,*sigstr; cJSON *item,*sobj,*vins,*vin,*txobj2,*signobj; bits256 txid,srchash,zero; struct dpow_entry *ep;
ep = &bp->notaries[myind];
memset(&zero,0,sizeof(zero));
if ( bestk < 0 )
return(-1);
for (j=0; j<sizeof(srchash); j++)
srchash.bytes[j] = dp->minerkey33[j+1];
if ( (vins= dpow_vins(coin,bp,bestk,bestmask,1,src_or_dest)) != 0 )
if ( (vins= dpow_vins(coin,bp,bestk,bestmask,1,src_or_dest,useratified)) != 0 )
{
txid = dpow_notarytx(rawtx,&numsigs,coin->chain->isPoS,bp,bestk,bestmask,0,src_or_dest,bp->numratified!=0?bp->ratified_pubkeys:0,bp->numratified);
txid = dpow_notarytx(rawtx,&numsigs,coin->chain->isPoS,bp,bestk,bestmask,0,src_or_dest,bp->numratified!=0?bp->ratified_pubkeys:0,useratified*bp->numratified);
//char str[65]; printf("signedtxgen %s src_or_dest.%d (%d %llx) useratified.%d raw.(%s)\n",bits256_str(str,txid),src_or_dest,bestk,(long long)bestmask,useratified,rawtx);
if ( bits256_nonz(txid) != 0 && rawtx[0] != 0 ) // send tx to share utxo set
{
/*memset(&tmp,0,sizeof(tmp));
tmp.ulongs[1] = bestmask;
tmp.bytes[31] = bestk;
len = (int32_t)strlen(rawtx) >> 1;
decode_hex(txdata+32,len,rawtx);
for (j=0; j<sizeof(srchash); j++)
txdata[j] = tmp.bytes[j];
dpow_send(myinfo,bp,zero,bp->hashmsg,(bits256_nonz(bp->btctxid) == 0) ? DPOW_BTCTXIDCHANNEL : DPOW_TXIDCHANNEL,bp->height,txdata,len+32);*/
dpow_rawtxsign(myinfo,dp,coin,bp,rawtx,vins,bestk,bestmask,myind,src_or_dest);
if ( useratified != 0 )
{
len = (int32_t)strlen(rawtx) >> 1;
if ( len <= sizeof(bp->ratifyrawtx[0]) )
{
decode_hex(bp->ratifyrawtx[src_or_dest],len,rawtx), bp->rawratifiedlens[src_or_dest] = len;
crcval = calc_crc32(0,bp->ratifyrawtx[src_or_dest],bp->rawratifiedlens[src_or_dest]);
if ( crcval != bp->pendingcrcs[src_or_dest] )
{
printf("new crcval.[%d] %x != %x\n",src_or_dest,crcval,bp->pendingcrcs[src_or_dest]);
bp->pendingcrcs[src_or_dest] = crcval;
}
bp->notaries[bp->myind].pendingcrcs[src_or_dest] = bp->pendingcrcs[src_or_dest];
}
if ( (jsonstr= dpow_signrawtransaction(myinfo,coin,rawtx,vins)) != 0 )
{
if ( (signobj= cJSON_Parse(jsonstr)) != 0 )
{
if ( ((signedtx= jstr(signobj,"hex")) != 0 || (signedtx= jstr(signobj,"result")) != 0) && (rawtx2= dpow_decoderawtransaction(myinfo,coin,signedtx)) != 0 )
{
if ( (txobj2= cJSON_Parse(rawtx2)) != 0 )
{
if ( (vin= jarray(&m,txobj2,"vin")) != 0 )
{
for (j=0; j<m; j++)
{
item = jitem(vin,j);
if ( (sobj= jobj(item,"scriptSig")) != 0 && (sigstr= jstr(sobj,"hex")) != 0 && strlen(sigstr) > 32 )
{
siglen = (int32_t)strlen(sigstr) >> 1;
bp->ratifysiglens[src_or_dest] = siglen;
decode_hex(bp->ratifysigs[src_or_dest],siglen,sigstr);
bp->notaries[bp->myind].ratifysiglens[src_or_dest] = siglen;
memcpy(bp->notaries[bp->myind].ratifysigs[src_or_dest],bp->ratifysigs[src_or_dest],siglen);
bp->ratifysigmasks[src_or_dest] |= (1LL << bp->myind);
printf("RATIFYSIG[%d] <- set notaryid.%d siglen.%d (%s).%d\n",src_or_dest,bp->myind,bp->ratifysiglens[src_or_dest],sigstr,siglen);
break;
}
}
}
}
}
}
}
else
{
printf("signrawtransaction error vins.(%s) rawtx.(%s)\n",jprint(vins,0),rawtx);
}
} else dpow_rawtxsign(myinfo,dp,coin,bp,rawtx,vins,bestk,bestmask,myind,src_or_dest);
} else printf("signedtxgen zero txid or null rawtx\n");
free_json(vins);
}
@ -339,18 +500,18 @@ int32_t dpow_signedtxgen(struct supernet_info *myinfo,struct dpow_info *dp,struc
return(retval);
}
void dpow_sigscheck(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint32_t channel,int32_t myind,int32_t src_or_dest)
void dpow_sigscheck(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,int32_t myind,int32_t src_or_dest,int8_t bestk,uint64_t bestmask,uint8_t pubkeys[64][33],int32_t numratified)
{
bits256 txid,srchash,zero,signedtxid; struct iguana_info *coin; int32_t j,len,numsigs; char *retstr=0,str[65],str2[65]; uint8_t txdata[32768];
bits256 txid,srchash,zero,signedtxid; struct iguana_info *coin; int32_t j,len,numsigs; char *retstr=0,str[65],str2[65]; uint8_t txdata[32768]; uint32_t channel;
coin = (src_or_dest != 0) ? bp->destcoin : bp->srccoin;
memset(zero.bytes,0,sizeof(zero));
//printf("sigscheck myind.%d src_dest.%d state.%x\n",myind,src_or_dest,bp->state);
if ( bp->state != 0xffffffff && coin != 0 )
channel = (src_or_dest != 0) ? DPOW_SIGBTCCHANNEL : DPOW_SIGCHANNEL;
if ( bestk >= 0 && bp->state != 0xffffffff && coin != 0 )
{
signedtxid = dpow_notarytx(bp->signedtx,&numsigs,coin->chain->isPoS,bp,bp->bestk,bp->bestmask,1,src_or_dest,bp->numratified!=0?bp->ratified_pubkeys:0,bp->numratified);
printf("src_or_dest.%d bestk.%d %llx %s numsigs.%d signedtx.(%s)\n",src_or_dest,bp->bestk,(long long)bp->bestmask,bits256_str(str,signedtxid),numsigs,bp->signedtx);
signedtxid = dpow_notarytx(bp->signedtx,&numsigs,coin->chain->isPoS,bp,bestk,bestmask,1,src_or_dest,pubkeys,numratified);
//printf("src_or_dest.%d bestk.%d %llx %s numsigs.%d signedtx.(%s)\n",src_or_dest,bestk,(long long)bestmask,bits256_str(str,signedtxid),numsigs,bp->signedtx);
bp->state = 1;
if ( bits256_nonz(signedtxid) != 0 && numsigs == DPOW_M(bp) )
if ( bits256_nonz(signedtxid) != 0 && numsigs == bp->minsigs )
{
if ( (retstr= dpow_sendrawtransaction(myinfo,coin,bp->signedtx)) != 0 )
{
@ -363,22 +524,26 @@ void dpow_sigscheck(struct supernet_info *myinfo,struct dpow_info *dp,struct dpo
if ( src_or_dest != 0 )
{
bp->desttxid = txid;
dpow_signedtxgen(myinfo,dp,bp->srccoin,bp,bp->bestk,bp->bestmask,myind,DPOW_SIGCHANNEL,0);
}
else bp->srctxid = txid;
dpow_signedtxgen(myinfo,dp,bp->srccoin,bp,bestk,bestmask,myind,DPOW_SIGCHANNEL,0,numratified != 0);
} else bp->srctxid = txid;
len = (int32_t)strlen(bp->signedtx) >> 1;
decode_hex(txdata+32,len,bp->signedtx);
for (j=0; j<sizeof(srchash); j++)
txdata[j] = txid.bytes[j];
dpow_send(myinfo,dp,bp,txid,bp->hashmsg,(src_or_dest != 0) ? DPOW_BTCTXIDCHANNEL : DPOW_TXIDCHANNEL,bp->height,txdata,len+32);
printf("complete statemachine.%s ht.%d\n",coin->symbol,bp->height);
bp->state = src_or_dest != 0 ? 1000 : 0xffffffff;
printf("complete statemachine.%s ht.%d state.%d (%x %x)\n",coin->symbol,bp->height,bp->state,bp->hashmsg.uints[0],txid.uints[0]);
} else printf("sendtxid mismatch got %s instead of %s\n",bits256_str(str,txid),bits256_str(str2,signedtxid));
}
free(retstr);
retstr = 0;
}
}
else
{
printf("NULL return from sendrawtransaction. abort\n");
bp->state = 0xffffffff;
}
} else printf("numsigs.%d vs required.%d\n",numsigs,bp->minsigs);
}
}

2
iguana/iguana777.c

@ -450,7 +450,7 @@ void iguana_update_balances(struct supernet_info *myinfo,struct iguana_info *coi
max = coin->bundlescount;
if ( coin->bundles[max-1] == coin->current || coin->bundles[max-1] == 0 || (coin->bundles[max-1] != 0 && coin->bundles[max-1]->utxofinish <= 1) )
max--;
if ( coin->chain->zcash != 0 )
if ( 1 && coin->chain->zcash != 0 )
{
coin->spendvectorsaved = 0;
for (i=0; i<coin->bundlescount-1; i++)

2
iguana/iguana777.h

@ -103,7 +103,7 @@ struct supernet_info
void *PAXDATA;
struct liquidity_info linfos[64];
struct komodo_notaries NOTARY;
char seedipaddr[64];
char seedipaddr[64]; uint32_t dpowipbits[128]; int32_t numdpowipbits; portable_mutex_t dpowmutex;
// compatibility
bits256 pangea_category,instantdex_category;
uint8_t logs[256],exps[510];

2
iguana/iguana_blocks.c

@ -355,7 +355,7 @@ int32_t iguana_blockvalidate(struct supernet_info *myinfo,struct iguana_info *co
{
static uint32_t counter;
if ( (counter++ % 10000) == 9999 )
printf("iguana_blockvalidate: %s miscompare.%d (%s) vs (%s)\n",coin->symbol,counter,bits256_str(str,hash2),bits256_str(str2,block->RO.hash2));
printf("iguana_blockvalidate.%d: %s miscompare.%d (%s) vs (%s)\n",block->height,coin->symbol,counter,bits256_str(str,hash2),bits256_str(str2,block->RO.hash2));
//getchar();
}
return(-1);

10
iguana/iguana_bundles.c

@ -1035,16 +1035,16 @@ int64_t iguana_bundlecalcs(struct supernet_info *myinfo,struct iguana_info *coin
int32_t iguana_bundlefinalize(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,struct OS_memspace *mem,struct OS_memspace *memB)
{
int32_t i; struct iguana_bundle *tmpbp; //struct iguana_blockreq *breq;
int32_t i; struct iguana_bundle *tmpbp; struct iguana_blockreq *breq;
if ( coin->firstRTheight == 0 && iguana_bundleready(myinfo,coin,bp,0) == bp->n )
{
printf(">>>>>>>>>>>>>> EMIT.[%3d] %s | 1st.%-3d h.%-3d c.%-3d s.[%3d] maxB.%d NET.(h%d b%d) %u:%02u\n",bp->hdrsi,coin->symbol,coin->current!=0?coin->current->hdrsi:-1,coin->current!=0?coin->current->numhashes:-1,coin->current!=0?coin->current->numcached:-1,coin->current!=0?coin->current->numsaved:-1,coin->MAXBUNDLES,HDRnet,queue_size(&coin->priorityQ),(uint32_t)(time(NULL)-coin->startutc)/60,(uint32_t)(time(NULL)-coin->startutc)%60);
/*if ( queue_size(&coin->priorityQ) > 10000 )
if ( queue_size(&coin->priorityQ) > 10000 )
{
while ( (breq= queue_dequeue(&coin->priorityQ)) != 0 )
myfree(breq,sizeof(*breq));
//printf("cleared priorityQ\n");
}*/
}
if ( bp->emitfinish != 0 )
{
printf("already EMIT for bundle.%d\n",bp->hdrsi);
@ -1560,11 +1560,11 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
iguana_setmaxbundles(coin);
strcpy(coin->statusstr,str);
coin->estsize = estsize;
/*if ( queue_size(&coin->priorityQ) > 10000 )
if ( queue_size(&coin->priorityQ) > 10000 )
{
while ( (breq= queue_dequeue(&coin->priorityQ)) != 0 )
myfree(breq,sizeof(*breq));
//printf("cleared priorityQ\n");
}*/
}
}

10
iguana/iguana_chains.c

@ -309,8 +309,6 @@ void iguana_chainparms(struct supernet_info *myinfo,struct iguana_chain *chain,c
if ( jobj(argjson,"conf") == 0 )
conf[0] = 0;
else safecopy(conf,jstr(argjson,"conf"),sizeof(conf));
if ( conf[0] != 0 )
printf("PATH.(%s) CONF.(%s)\n",path!=0?path:"",conf);
safecopy(chain->name,jstr(argjson,"name"),sizeof(chain->name));
//chain->dust = j64bits(argjson,"dust");
if ( jobj(argjson,"txfee_satoshis") != 0 )
@ -318,12 +316,16 @@ void iguana_chainparms(struct supernet_info *myinfo,struct iguana_chain *chain,c
if ( chain->txfee == 0 )
chain->txfee = (uint64_t)(SATOSHIDEN * jdouble(argjson,"txfee"));
chain->use_addmultisig = juint(argjson,"useaddmultisig");
if ( (port= extract_userpass(chain->serverport,chain->userpass,chain->symbol,chain->userhome,path,conf)) != 0 )
chain->rpcport = port;
//if ( conf[0] != 0 )
printf("PATH.(%s) CONF.(%s)\n",path!=0?path:"",conf);
if ( juint(argjson,"p2p") != 0 )
chain->portp2p = juint(argjson,"p2p");
else chain->portp2p = juint(argjson,"portp2p");
if ( jstr(argjson,"rpchost") != 0 )
safecopy(chain->serverport,jstr(argjson,"rpchost"),sizeof(chain->serverport));
if ( jstr(argjson,"userpass") != 0 )
if ( jstr(argjson,"userpass") != 0 )
safecopy(chain->userpass,jstr(argjson,"userpass"),sizeof(chain->userpass));
chain->rpcport = juint(argjson,"rpcport");
if ( chain->rpcport == 0 && (chain->rpcport= juint(argjson,"rpc")) == 0 && strcmp(chain->symbol,"RELAY") != 0 )
@ -345,8 +347,6 @@ void iguana_chainparms(struct supernet_info *myinfo,struct iguana_chain *chain,c
else if ( strcmp("BTCD",chain->symbol) == 0 )
chain->rpcport = 14632;
}
if ( chain->serverport[0] == 0 && (port= extract_userpass(chain->serverport,chain->userpass,chain->symbol,chain->userhome,path,conf)) != 0 )
chain->rpcport = port;
chain->zcash = juint(argjson,"zcash");
chain->debug = juint(argjson,"debug");
chain->fixit = juint(argjson,"fixit");

8
iguana/iguana_msg.c

@ -603,6 +603,7 @@ int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgj
int32_t len = 0;
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->vpub_old),&msg->vpub_old);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->vpub_new),&msg->vpub_new);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->anchor),msg->anchor.bytes);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->nullifiers[0]),msg->nullifiers[0].bytes);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->nullifiers[1]),msg->nullifiers[1].bytes);
@ -658,10 +659,13 @@ int32_t iguana_rwtx(struct supernet_info *myinfo,uint8_t zcash,int32_t rwflag,st
return(-1);
}
}
//for (i=-3; i<7; i++)
// printf("%02x",serialized[len+i]);
//printf(" prev 3 bytes before tx_out\n");
len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_out);
if ( len + msg->tx_out*8 > maxsize )
{
printf("invalid tx_out.%d len.%d vs maxsize.%d\n",msg->tx_out,len,maxsize);
printf("invalidA tx_out.%d len.%d vs maxsize.%d\n",msg->tx_out,len,maxsize);
return(-1);
}
//printf("numvouts.%d ",msg->tx_out);
@ -673,7 +677,7 @@ int32_t iguana_rwtx(struct supernet_info *myinfo,uint8_t zcash,int32_t rwflag,st
len += n;
if ( n <= 0 || len > maxsize )
{
printf("invalid tx_out.%d len.%d vs maxsize.%d\n",msg->tx_out,len,maxsize);
printf("invalidB tx_out.%d len.%d vs maxsize.%d\n",msg->tx_out,len,maxsize);
return(-1);
}
}

50
iguana/iguana_notary.c

@ -22,7 +22,9 @@
#include "iguana777.h"
#include "notaries.h"
int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t channel,uint32_t height,uint8_t *data,int32_t datalen);
int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint8_t nn_senderind,uint32_t channel,uint32_t height,uint8_t *data,int32_t datalen);
uint64_t dpow_maskmin(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp);
int32_t dpow_checkutxo(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,char *coinaddr);
#include "dpow/dpow_network.c"
#include "dpow/dpow_rpc.c"
@ -58,7 +60,7 @@ void dpow_checkpointset(struct supernet_info *myinfo,struct dpow_checkpoint *che
void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t height,bits256 hash,uint32_t timestamp,uint32_t blocktime)
{
void **ptrs; char str[65]; struct dpow_checkpoint checkpoint; int32_t freq,minsigs;
void **ptrs; char str[65]; struct dpow_checkpoint checkpoint; int32_t freq,minsigs; uint8_t pubkeys[64][33];
dpow_checkpointset(myinfo,&dp->last,height,hash,timestamp,blocktime);
checkpoint = dp->srcfifo[dp->srcconfirms];
if ( strcmp("BTC",dp->dest) == 0 )
@ -69,9 +71,11 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he
else
{
freq = 1;
minsigs = 2;
minsigs = (komodo_notaries(dp->symbol,pubkeys,height) >> 1) + 1;
if ( minsigs > DPOW_MINSIGS )
minsigs = DPOW_MINSIGS;
}
printf("%s src ht.%d dest.%u nonz.%d %s\n",dp->symbol,height,dp->destupdated,bits256_nonz(checkpoint.blockhash.hash),bits256_str(str,dp->last.blockhash.hash));
printf("%s/%s src ht.%d dest.%u nonz.%d %s minsigs.%d\n",dp->symbol,dp->dest,checkpoint.blockhash.height,dp->destupdated,bits256_nonz(checkpoint.blockhash.hash),bits256_str(str,dp->last.blockhash.hash),minsigs);
dpow_fifoupdate(myinfo,dp->srcfifo,dp->last);
if ( bits256_nonz(checkpoint.blockhash.hash) != 0 && (checkpoint.blockhash.height % freq) == 0 )
{
@ -161,7 +165,9 @@ void iguana_dPoWupdate(struct supernet_info *myinfo,struct dpow_info *dp)
{
if ( strcmp(dp->dest,"KMD") == 0 )
dp->SRCHEIGHT = dpow_issuer_iteration(dp,src,dp->SRCHEIGHT,&dp->SRCREALTIME);
//printf("%s %s height.%d vs last.%d\n",dp->symbol,bits256_str(str,blockhash),height,dp->last.blockhash.height);
char str[65]; printf("%s %s height.%d vs last.%d\n",dp->symbol,bits256_str(str,blockhash),height,dp->last.blockhash.height);
if ( dp->lastheight == 0 )
dp->lastheight = height-1;
if ( height < dp->last.blockhash.height )
{
printf("iguana_dPoWupdate src.%s reorg detected %d vs %d approved.%d notarized.%d\n",dp->symbol,height,dp->last.blockhash.height,dp->approved[0].height,dp->notarized[0].height);
@ -169,8 +175,24 @@ void iguana_dPoWupdate(struct supernet_info *myinfo,struct dpow_info *dp)
{
if ( bits256_cmp(blockhash,dp->last.blockhash.hash) != 0 )
printf("UNEXPECTED ILLEGAL BLOCK in src chaintip\n");
} else dpow_srcupdate(myinfo,dp,height,blockhash,(uint32_t)time(NULL),blocktime);
} else dpow_srcupdate(myinfo,dp,height,blockhash,(uint32_t)time(NULL),blocktime);
}
else
{
while ( dp->lastheight <= height )
{
blockhash = dpow_getblockhash(myinfo,src,dp->lastheight);
dpow_srcupdate(myinfo,dp,dp->lastheight++,blockhash,(uint32_t)time(NULL),blocktime);
}
}
}
else
{
while ( dp->lastheight <= height )
{
blockhash = dpow_getblockhash(myinfo,src,dp->lastheight);
dpow_srcupdate(myinfo,dp,dp->lastheight++,blockhash,(uint32_t)time(NULL),blocktime);
}
}
} //else printf("error getchaintip for %s\n",dp->symbol);
} else printf("iguana_dPoWupdate missing src.(%s) %p or dest.(%s) %p\n",dp->symbol,src,dp->dest,dest);
}
@ -272,14 +294,14 @@ char *dpow_passthru(struct iguana_info *coin,char *function,char *hex)
TWO_STRINGS(zcash,passthru,function,hex)
{
if ( (coin= iguana_coinfind("ZEC")) != 0 || coin->chain->serverport[0] == 0 )
if ( (coin= iguana_coinfind("ZEC")) != 0 )
return(dpow_passthru(coin,function,hex));
else return(clonestr("{\"error\":\"ZEC not active, start in bitcoind mode\"}"));
}
TWO_STRINGS(komodo,passthru,function,hex)
{
if ( (coin= iguana_coinfind("KMD")) != 0 || coin->chain->serverport[0] == 0 )
if ( (coin= iguana_coinfind("KMD")) != 0 )
return(dpow_passthru(coin,function,hex));
else return(clonestr("{\"error\":\"KMD not active, start in bitcoind mode\"}"));
}
@ -372,14 +394,22 @@ ZERO_ARGS(dpow,cancelratify)
TWOINTS_AND_ARRAY(dpow,ratify,minsigs,timestamp,ratified)
{
void **ptrs; bits256 zero; struct dpow_checkpoint checkpoint;
void **ptrs; bits256 zero; int32_t i; char *source; struct dpow_checkpoint checkpoint;
if ( ratified == 0 )
return(clonestr("{\"error\":\"no ratified list for dpow ratify\"}"));
memset(zero.bytes,0,sizeof(zero));
dpow_checkpointset(myinfo,&checkpoint,0,zero,timestamp,timestamp);
ptrs = calloc(1,sizeof(void *)*5 + sizeof(struct dpow_checkpoint));
ptrs[0] = (void *)myinfo;
if ( (source= jstr(json,"source")) == 0 )
source = "KMD";
ptrs[1] = (void *)&myinfo->DPOWS[0];
for (i=0; i<myinfo->numdpows; i++)
if ( strcmp(myinfo->DPOWS[0].symbol,source) == 0 )
{
ptrs[1] = (void *)&myinfo->DPOWS[i];
break;
}
ptrs[2] = (void *)(long)minsigs;
ptrs[3] = (void *)DPOW_RATIFYDURATION;
ptrs[4] = (void *)jprint(ratified,0);

107
iguana/iguana_ramchain.c

@ -1030,13 +1030,10 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits
return(-1);
}
OS_compatible_path(fname);
/*static portable_mutex_t mutex; static int didinit;
if ( didinit == 0 )
{
portable_mutex_init(&mutex);
didinit = 1;
}
portable_mutex_lock(&mutex);*/
#ifdef __PNACL__
//static portable_mutex_t mutex;
//portable_mutex_lock(&mutex);
#endif
if ( (fp= fopen(fname,"wb")) == 0 )
printf("iguana_ramchain_save: couldnt create.(%s) errno.%d\n",fname,errno);
else if ( coin->peers != 0 )
@ -1060,7 +1057,9 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits
fclose(fp);
//sleep(3);
}
#ifdef __PNACL__
//portable_mutex_unlock(&mutex);
#endif
return(fpos);
}
@ -1322,8 +1321,6 @@ int32_t iguana_ramchain_extras(struct supernet_info *myinfo,struct iguana_info *
int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp)
{
int32_t iter; bits256 sha256; char str[65],fname[1024]; void *ptr; long filesize;
if ( ramchain->Xspendinds != 0 )
return(ramchain->numXspends);
for (iter=0; iter<2; iter++)
{
sprintf(fname,"%s/%s%s/spends/%s.%d",GLOBAL_DBDIR,iter==0?"ro/":"",coin->symbol,bits256_str(str,bp->hashes[0]),bp->bundleheight);
@ -1340,14 +1337,14 @@ int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramcha
bp->startutxo = bp->utxofinish = (uint32_t)time(NULL);
if ( bp->Xvalid == 0 )
{
if ( (rand() % 10) == 0 )
if ( 0 && (rand() % 10) == 0 )
printf("[%d] filesize %ld Xspendptr.%p %p num.%d\n",bp->hdrsi,filesize,ramchain->Xspendptr,ramchain->Xspendinds,ramchain->numXspends);
bp->Xvalid = 1;
}
//printf("mapped utxo vector[%d] from (%s)\n",ramchain->numXspends,fname);
return(ramchain->numXspends);
//int32_t i; for (i=0; i<ramchain->numXspends; i++)
// printf("(%d u%d) ",ramchain->Xspendinds[i].hdrsi,ramchain->Xspendinds[i].ind);
//printf("mapped utxo vector[%d] from (%s)\n",ramchain->numXspends,fname);
}
else
{
@ -1470,7 +1467,7 @@ struct iguana_ramchain *_iguana_ramchain_map(struct supernet_info *myinfo,struct
{
for (i=0; i<bp->n; i++)
{
iguana_blockzcopyRO(zcash,(void *)&zRO,0,B,i);
iguana_blockzcopyRO(0*zcash,(void *)&zRO,0,B,i);
if ( bp->blocks[i] == 0 && (bp->blocks[i]= iguana_blockhashset("mapchain",coin,-1,zRO.RO.hash2,1)) == 0 )
{
printf("Error getting blockptr\n");
@ -1480,7 +1477,7 @@ struct iguana_ramchain *_iguana_ramchain_map(struct supernet_info *myinfo,struct
{
bp->hashes[i] = zRO.RO.hash2;
//bp->blocks[i]->RO = zRO.RO;
iguana_blockzcopyRO(zcash,&bp->blocks[i]->RO,0,(void *)&zRO,0);
iguana_blockzcopyRO(0*zcash,&bp->blocks[i]->RO,0,(void *)&zRO,0);
}
/* if ( (bRO= iguana_blockzcopyRO(zcash,&bp->blocks[i]->RO,0,B,i)) != 0 )
{
@ -1498,7 +1495,7 @@ struct iguana_ramchain *_iguana_ramchain_map(struct supernet_info *myinfo,struct
return(0);
}
struct iguana_ramchain *iguana_ramchain_map(struct supernet_info *myinfo,struct iguana_info *coin,char *fname,struct iguana_bundle *bp,int32_t numblocks,struct iguana_ramchain *ramchain,struct OS_memspace *hashmem,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t bundlei,long fpos,int32_t allocextras,int32_t expanded,uint8_t zcash)
struct iguana_ramchain *iguana_ramchain_map(struct supernet_info *myinfo,struct iguana_info *coin,char *fname,struct iguana_bundle *bp,int32_t numblocks,struct iguana_ramchain *ramchain,struct OS_memspace *hashmem,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t bundlei,long fpos,int32_t allocextras,int32_t expanded)
{
struct iguana_ramchain *retptr;
#ifdef __PNACL__
@ -1506,7 +1503,7 @@ struct iguana_ramchain *iguana_ramchain_map(struct supernet_info *myinfo,struct
//portable_mutex_lock(&mutex);
#endif
ramchain->height = bp->bundleheight;
retptr = _iguana_ramchain_map(myinfo,coin,fname,bp,numblocks,ramchain,hashmem,ipbits,hash2,prevhash2,bundlei,fpos,allocextras,expanded,zcash);
retptr = _iguana_ramchain_map(myinfo,coin,fname,bp,numblocks,ramchain,hashmem,ipbits,hash2,prevhash2,bundlei,fpos,allocextras,expanded,coin->chain->zcash);
#ifdef __PNACL__
//portable_mutex_unlock(&mutex);
#endif
@ -1820,24 +1817,23 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info
return(0);
}
long iguana_ramchain_data(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,int32_t txn_count,uint8_t *data,int32_t recvlen,struct iguana_bundle *bp,struct iguana_block *block,uint8_t zcash)
long iguana_ramchain_data(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,int32_t txn_count,uint8_t *data,int32_t recvlen,struct iguana_bundle *bp,struct iguana_block *block)
{
int32_t verifyflag = 0;
RAMCHAIN_DECLARE; struct iguana_ramchain R,*mapchain,*ramchain = &addr->ramchain; struct iguana_msgtx *tx; char fname[1024]; uint8_t rmd160[20]; struct iguana_ramchaindata *rdata; int32_t i,j,fpos,pubkeysize,sigsize,hdrsi,subdir,firsti=1,err,flag,bundlei=-1; uint32_t scriptspace,stackspace; struct iguana_blockRO RO;
RAMCHAIN_DECLARE; struct iguana_ramchain R,*mapchain,*ramchain = &addr->ramchain; struct iguana_msgtx *tx; char fname[1024]; uint8_t rmd160[20]; struct iguana_ramchaindata *rdata; int32_t i,j,fpos,pubkeysize,sigsize,subdir,firsti=1,err,flag,bundlei; uint32_t scriptspace,stackspace; struct iguana_blockRO RO;
if ( block == 0 || bp == 0 || addr == 0 || (block != 0 && (bundlei= block->bundlei) < 0) )
{
//printf("iguana_ramchain_data: null ptr %p %p %p bundlei.%d\n",block,bp,addr,bundlei);
//printf("iguana_ramchain_data: null ptr %p %p %p\n",block,bp,addr);
return(-1);
}
#ifdef __PNACL__
//verifyflag = 1;
#endif
iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,0,origtxdata->zblock.RO.hash2,origtxdata->zblock.RO.prev_block,1,0);
sigsize = pubkeysize = 0;
scriptspace = 1;//iguana_scriptspaceraw(coin,&scriptsize,&sigsize,&pubkeysize,txarray,txn_count);
for (i=0; i<sizeof(addr->dirty)/sizeof(*addr->dirty); i++)
addr->dirty[i] = 0;
if ( iguana_ramchain_init(fname,ramchain,&addr->TXDATA,&addr->HASHMEM,1,txn_count,origtxdata->numunspents,origtxdata->numspends,0,0,(scriptspace+sigsize+pubkeysize)*1.1,0,1,zcash) == 0 )
if ( iguana_ramchain_init(fname,ramchain,&addr->TXDATA,&addr->HASHMEM,1,txn_count,origtxdata->numunspents,origtxdata->numspends,0,0,(scriptspace+sigsize+pubkeysize)*1.1,0,1,coin->chain->zcash) == 0 )
{
if ( block != 0 && block->fpipbits == 0 )
block->issued = block->RO.recvlen = 0, block->fpos = -1;
@ -1905,7 +1901,7 @@ long iguana_ramchain_data(struct supernet_info *myinfo,struct iguana_info *coin,
rdata->prevhash2 = origtxdata->zblock.RO.prev_block;
rdata->scriptspace = scriptspace = ramchain->H.scriptoffset;
rdata->stackspace = stackspace = ramchain->H.stacksize;
iguana_ramchain_setsize(fname,ramchain,rdata,1,zcash);
iguana_ramchain_setsize(fname,ramchain,rdata,1,coin->chain->zcash);
flag = 0;
if ( ramchain->H.txidind != rdata->numtxids || ramchain->H.unspentind != rdata->numunspents || ramchain->H.spendind != rdata->numspends )
{
@ -1921,17 +1917,21 @@ long iguana_ramchain_data(struct supernet_info *myinfo,struct iguana_info *coin,
{
if ( (err= iguana_ramchain_verify(coin,ramchain)) == 0 )
{
*B = RO;
iguana_blockzcopyRO(0*coin->chain->zcash,B,0,&RO,0);
rdata->scriptspace = ramchain->H.scriptoffset = scriptspace;
rdata->stackspace = ramchain->H.stacksize = stackspace;
if ( (fpos= (int32_t)iguana_ramchain_save(coin,RAMCHAIN_ARG,(uint32_t)addr->ipbits,RO.hash2,RO.prev_block,bundlei,0,zcash)) >= 0 )
if ( (fpos= (int32_t)iguana_ramchain_save(coin,RAMCHAIN_ARG,(uint32_t)addr->ipbits,RO.hash2,RO.prev_block,bundlei,0,coin->chain->zcash)) >= 0 )
{
origtxdata->datalen = (int32_t)rdata->allocsize;
//char str[65]; printf("saved.%s [%d:%d] fpos.%d datalen.%d\n",bits256_str(str,block->RO.hash2),bp->hdrsi,bundlei,fpos,origtxdata->datalen);
ramchain->H.ROflag = 0;
flag = 1;
if ( addr->dirty[0] != 0 && addr->voutsfp != 0 )
fflush(addr->voutsfp);
if ( addr->dirty[1] != 0 && addr->vinsfp != 0 )
fflush(addr->vinsfp);
memset(&R,0,sizeof(R));
if ( verifyflag != 0 && (mapchain= iguana_ramchain_map(myinfo,coin,fname,0,1,&R,&addr->HASHMEM,(uint32_t)addr->ipbits,RO.hash2,RO.prev_block,bundlei,fpos,0,0,zcash)) == 0 )
if ( verifyflag != 0 && (mapchain= iguana_ramchain_map(myinfo,coin,fname,0,1,&R,0,(uint32_t)addr->ipbits,RO.hash2,RO.prev_block,bundlei,fpos,1,0)) == 0 )
{
printf("delete unverified [%d:%d]\n",bp->hdrsi,bundlei);
iguana_ramchain_free(coin,&R,1);
@ -1946,7 +1946,7 @@ long iguana_ramchain_data(struct supernet_info *myinfo,struct iguana_info *coin,
}
if ( block != 0 && fpos >= 0 )
block->fpos = fpos, block->fpipbits = (uint32_t)addr->ipbits;
} //else printf("save error\n");
} else printf("save error\n");
}
else
{
@ -1955,13 +1955,6 @@ long iguana_ramchain_data(struct supernet_info *myinfo,struct iguana_info *coin,
}
}
}
if ( addr != 0 )
{
if ( addr->dirty[0] != 0 && addr->voutsfp != 0 )
fflush(addr->voutsfp);
if ( addr->dirty[1] != 0 && addr->vinsfp != 0 )
fflush(addr->vinsfp);
}
if ( fpos < 0 && block != 0 )
iguana_blockunmark(coin,block,bp,bundlei,1);
//fprintf(stderr,"finished with hdrsi.%d ht.%d scripts.%u:%u\n",bp->hdrsi,bp->bundleheight,ramchain->H.scriptoffset,rdata->scriptspace);
@ -2015,7 +2008,7 @@ void iguana_blockdelete(struct iguana_info *coin,bits256 hash2,int32_t i)
void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,struct iguana_bundle *bp,int32_t i,int32_t deletefile)
{
void *ptr; int32_t recvlen,height = -1; uint8_t zcash = 0;
void *ptr; int32_t recvlen,height = -1;
if ( 0 && bp != 0 )
printf("UNMARK.[%d:%d]\n",bp->hdrsi,i);
if ( block != 0 )
@ -2048,7 +2041,7 @@ void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,stru
{
printf("reduce %s HWM height from %d to %d\n",coin->symbol,coin->blocks.hwmchain.height,height);
if ( (block= iguana_blockfind("unmark",coin,iguana_blockhash(coin,height))) != 0 )
iguana_blockcopy(zcash,coin->chain->auxpow,coin,(struct iguana_block *)&coin->blocks.hwmchain,block);
iguana_blockcopy(coin->chain->zcash,coin->chain->auxpow,coin,(struct iguana_block *)&coin->blocks.hwmchain,block);
}
}
@ -2191,7 +2184,7 @@ void iguana_bundlemapfree(struct iguana_info *coin,struct OS_memspace *mem,struc
int32_t iguana_ramchain_expandedsave(struct supernet_info *myinfo,struct iguana_info *coin,RAMCHAIN_FUNC,struct iguana_ramchain *newchain,struct OS_memspace *hashmem,int32_t cmpflag,struct iguana_bundle *bp)
{
static const bits256 zero; uint8_t zcash = 0;
static const bits256 zero;
bits256 firsthash2; int32_t err,bundlei,hdrsi,numblocks,firsti,height,retval= -1; struct iguana_ramchain checkR,*mapchain; char fname[1024]; struct iguana_block *block; uint32_t scriptspace,scriptoffset,stacksize; uint8_t *destoffset,*srcoffset; struct iguana_ramchaindata *rdata;
if ( (rdata= ramchain->H.data) == 0 )
return(-1);
@ -2213,7 +2206,7 @@ int32_t iguana_ramchain_expandedsave(struct supernet_info *myinfo,struct iguana_
rdata->prevhash2 = block->RO.prev_block;
rdata->scriptspace = scriptoffset;
ramchain->H.stacksize = rdata->stackspace = stacksize;
iguana_ramchain_setsize(fname,ramchain,rdata,bp->n,zcash);
iguana_ramchain_setsize(fname,ramchain,rdata,bp->n,coin->chain->zcash);
//printf("Apresave T.%d U.%d S.%d P.%d X.%d -> size.%ld firsti.%d scriptoffset.%d stacksize.%d\n",rdata->numtxids,rdata->numunspents,rdata->numspends,rdata->numpkinds,rdata->numexternaltxids,(long)rdata->allocsize,firsti,ramchain->H.scriptoffset,ramchain->H.stacksize);
*newchain = *ramchain;
//memcpy(ramchain->roU2,ramchain->U2,sizeof(*ramchain->U2) * rdata->numunspents);
@ -2237,7 +2230,7 @@ int32_t iguana_ramchain_expandedsave(struct supernet_info *myinfo,struct iguana_
ramchain->H.scriptoffset = scriptoffset;
rdata->scriptspace = scriptoffset;
ramchain->H.stacksize = rdata->stackspace = stacksize;
if ( iguana_ramchain_save(coin,RAMCHAIN_ARG,0,firsthash2,zero,0,bp,zcash) < 0 )
if ( iguana_ramchain_save(coin,RAMCHAIN_ARG,0,firsthash2,zero,0,bp,coin->chain->zcash) < 0 )
{
printf("ERROR saving ramchain hdrsi.%d, deleting and will regenerate\n",hdrsi);
iguana_mempurge(hashmem);
@ -2252,7 +2245,7 @@ int32_t iguana_ramchain_expandedsave(struct supernet_info *myinfo,struct iguana_
bundlei = 0;
if ( cmpflag == 0 )
iguana_memreset(hashmem);
if ( (mapchain= iguana_ramchain_map(myinfo,coin,fname,bp,numblocks,&checkR,cmpflag==0?hashmem:0,0,firsthash2,zero,bundlei,0,0,1,zcash)) != 0 )
if ( (mapchain= iguana_ramchain_map(myinfo,coin,fname,bp,numblocks,&checkR,cmpflag==0?hashmem:0,0,firsthash2,zero,bundlei,0,0,1)) != 0 )
{
iguana_ramchain_link(mapchain,firsthash2,hdrsi,height,0,numblocks,firsti,1);
iguana_ramchain_extras(myinfo,coin,mapchain,hashmem,0);
@ -2284,13 +2277,13 @@ int32_t iguana_ramchain_expandedsave(struct supernet_info *myinfo,struct iguana_
struct iguana_ramchain *iguana_bundleload(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int32_t extraflag)
{
static const bits256 zero; uint8_t zcash = 0;
static const bits256 zero;
struct iguana_blockRO *B; struct iguana_txid *T; int32_t i,firsti = 1; char fname[512];
struct iguana_block *block,*prev,*prev2; struct iguana_ramchain *mapchain; struct iguana_ramchaindata *rdata; uint32_t firsttxidind;
if ( bp->emitfinish > 1 )
return(ramchain);
memset(ramchain,0,sizeof(*ramchain));
if ( (mapchain= iguana_ramchain_map(myinfo,coin,fname,bp,bp->n,ramchain,0,0,bp->hashes[0],zero,0,0,extraflag,1,zcash)) != 0 )
if ( (mapchain= iguana_ramchain_map(myinfo,coin,fname,bp,bp->n,ramchain,0,0,bp->hashes[0],zero,0,0,extraflag,1)) != 0 )
{
iguana_ramchain_link(mapchain,bp->hashes[0],bp->hdrsi,bp->bundleheight,0,bp->n,firsti,1);
//char str[65]; printf("%s bp.%d: T.%d U.%d S.%d P%d X.%d MAPPED %s %p\n",coin->symbol,bp->hdrsi,mapchain->H.data->numtxids,mapchain->H.data->numunspents,mapchain->H.data->numspends,mapchain->H.data->numpkinds,mapchain->H.data->numexternaltxids,mbstr(str,mapchain->H.data->allocsize),mapchain->H.data);
@ -2317,7 +2310,7 @@ struct iguana_ramchain *iguana_bundleload(struct supernet_info *myinfo,struct ig
block->hdrsi = bp->hdrsi;
block->bundlei = i;
block->fpipbits = (uint32_t)calc_ipbits("127.0.0.1");
iguana_blockzcopyRO(zcash,&block->RO,0,B,i);
iguana_blockzcopyRO(0*coin->chain->zcash,&block->RO,0,B,i);
//printf("%x ",(int32_t)B[i].hash2.ulongs[3]);
bp->blocks[i] = block;
bp->hashes[i] = block->RO.hash2;
@ -2363,7 +2356,7 @@ struct iguana_ramchain *iguana_bundleload(struct supernet_info *myinfo,struct ig
int64_t iguana_ramchainopen(struct supernet_info *myinfo,char *fname,struct iguana_info *coin,struct iguana_ramchain *ramchain,struct OS_memspace *mem,struct OS_memspace *hashmem,int32_t bundleheight,bits256 hash2)
{
RAMCHAIN_DECLARE; RAMCHAIN_ZEROES; uint8_t zcash = 0; int32_t i,numblocks = coin->chain->bundlesize; uint32_t numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata=0; int64_t hashsize,allocsize;
RAMCHAIN_DECLARE; RAMCHAIN_ZEROES; int32_t i,numblocks = coin->chain->bundlesize; uint32_t numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata=0; int64_t hashsize,allocsize;
//B = 0, Ux = 0, Sx = 0, P = 0, A = 0, X = 0, Kspace = TXbits = PKbits = 0, U = 0, S = 0, T = 0;
mem->alignflag = sizeof(uint32_t);
hashmem->alignflag = sizeof(uint32_t);
@ -2391,7 +2384,7 @@ int64_t iguana_ramchainopen(struct supernet_info *myinfo,char *fname,struct igua
//#endif
if ( mem->ptr == 0 )
{
while ( (allocsize= _iguana_rdata_action(fname,0,0,0,0,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,0,0,0,0,0,RAMCHAIN_ARG,numblocks,zcash)) > 2*1024LL*1024L*1024L )
while ( (allocsize= _iguana_rdata_action(fname,0,0,0,0,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,0,0,0,0,0,RAMCHAIN_ARG,numblocks,coin->chain->zcash)) > 2*1024LL*1024L*1024L )
{
numtxids *= .9;
numunspents *= .9;
@ -2408,7 +2401,7 @@ int64_t iguana_ramchainopen(struct supernet_info *myinfo,char *fname,struct igua
iguana_meminit(hashmem,coin->symbol,0,hashsize + 65536*3,0);
printf("%s hash meminit %lld\n",coin->symbol,(long long)hashmem->totalsize);
}
if ( iguana_ramchain_init(fname,ramchain,mem,hashmem,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,1,numblocks,zcash) > 0 )
if ( iguana_ramchain_init(fname,ramchain,mem,hashmem,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,1,numblocks,coin->chain->zcash) > 0 )
{
iguana_ramchain_link(ramchain,hash2,bundleheight/coin->chain->bundlesize,bundleheight,0,0,1,0);
ramchain->expanded = 1;
@ -2424,7 +2417,7 @@ int64_t iguana_ramchainopen(struct supernet_info *myinfo,char *fname,struct igua
int32_t iguana_mapchaininit(char *fname,struct iguana_info *coin,struct iguana_ramchain *mapchain,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block,void *ptr,long filesize)
{
int32_t firsti = 1; RAMCHAIN_DECLARE; uint8_t zcash = 0;
int32_t firsti = 1; RAMCHAIN_DECLARE;
memset(mapchain,0,sizeof(*mapchain));
mapchain->fileptr = ptr;
mapchain->filesize = filesize;
@ -2436,9 +2429,9 @@ int32_t iguana_mapchaininit(char *fname,struct iguana_info *coin,struct iguana_r
return(-1);
}
_iguana_ramchain_setptrs(MAPCHAIN_PTRS,mapchain->H.data);
if ( block->fpos+mapchain->H.data->allocsize > filesize || iguana_ramchain_size(fname,MAPCHAIN_ARG,1,mapchain->H.data->scriptspace,zcash) != mapchain->H.data->allocsize )
if ( block->fpos+mapchain->H.data->allocsize > filesize || iguana_ramchain_size(fname,MAPCHAIN_ARG,1,mapchain->H.data->scriptspace,coin->chain->zcash) != mapchain->H.data->allocsize )
{
printf("iguana_mapchaininit.%d ipbits.%x size mismatch %ld vs %ld vs filesize.%ld fpos.%ld bundlei.%d expanded.%d soff.%d\n",bp->bundleheight,block->fpipbits,(long)iguana_ramchain_size(fname,MAPCHAIN_ARG,1,mapchain->H.data->scriptspace,zcash),(long)mapchain->H.data->allocsize,(long)filesize,(long)block->fpos,bundlei,mapchain->expanded,mapchain->H.data->scriptspace);
printf("iguana_mapchaininit.%d ipbits.%x size mismatch %ld vs %ld vs filesize.%ld fpos.%ld bundlei.%d expanded.%d soff.%d\n",bp->bundleheight,block->fpipbits,(long)iguana_ramchain_size(fname,MAPCHAIN_ARG,1,mapchain->H.data->scriptspace,coin->chain->zcash),(long)mapchain->H.data->allocsize,(long)filesize,(long)block->fpos,bundlei,mapchain->expanded,mapchain->H.data->scriptspace);
//getchar();
return(-1);
}
@ -2456,7 +2449,7 @@ int32_t iguana_mapchaininit(char *fname,struct iguana_info *coin,struct iguana_r
// helper threads: NUM_HELPERS
int32_t iguana_bundlesaveHT(struct supernet_info *myinfo,struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,uint32_t starttime) // helper thread
{
static int depth; uint8_t zcash = 0;
static int depth;
RAMCHAIN_DESTDECLARE; RAMCHAIN_DECLARE; RAMCHAIN_ZEROES;
void **ptrs; long *filesizes; uint32_t *ipbits; char fname[1024];
struct iguana_ramchain *R,*mapchain,*dest,newchain; uint32_t fpipbits; bits256 prevhash2;
@ -2539,7 +2532,7 @@ int32_t iguana_bundlesaveHT(struct supernet_info *myinfo,struct iguana_info *coi
numexternaltxids = numspends;
//printf("E.%d depth.%d start bundle ramchain %d at %u started.%u lag.%d\n",coin->numemitted,depth,bp->bundleheight,now,starttime,now-starttime);
depth++;
if ( iguana_ramchain_alloc(fname,coin,dest,mem,&HASHMEM,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace+sigspace,bp->bundleheight+starti,bp_n,zcash) < 0 )
if ( iguana_ramchain_alloc(fname,coin,dest,mem,&HASHMEM,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace+sigspace,bp->bundleheight+starti,bp_n,coin->chain->zcash) < 0 )
{
printf("error iguana_ramchain_alloc for bundleheight.%d\n",bp->bundleheight);
iguana_bundlemapfree(coin,mem,&HASHMEM,ipbits,ptrs,filesizes,num,R,starti,endi);
@ -2568,7 +2561,7 @@ int32_t iguana_bundlesaveHT(struct supernet_info *myinfo,struct iguana_info *coi
iguana_blockunmark(coin,block,bp,i,1);
return(-1);
}
iguana_blockzcopyRO(zcash,destB,i,&block->RO,0);
iguana_blockzcopyRO(0*coin->chain->zcash,destB,i,&block->RO,0);
//destB[i] = block->RO;
} else printf("bundlesave error getting block (%d:%d) %p vs %p\n",bp->hdrsi,i,block,bp->blocks[i]);
}
@ -2583,9 +2576,9 @@ int32_t iguana_bundlesaveHT(struct supernet_info *myinfo,struct iguana_info *coi
{
iguana_blocksetcounters(coin,block,dest);
//coin->blocks.RO[bp->bundleheight+bundlei] = block->RO;
iguana_blockzcopyRO(zcash,destB,bundlei,&block->RO,0);
iguana_blockzcopyRO(0*coin->chain->zcash,destB,bundlei,&block->RO,0);
//destB[bundlei] = block->RO;
//fprintf(stderr,"T.(%d %d u%d).%d ",R[bundlei].H.data->numtxids,dest->H.txidind,R[bundlei].H.data->numunspents,bundlei);
//fprintf(stderr,"(%d %d).%d ",R[bundlei].H.data->numtxids,dest->H.txidind,bundlei);
if ( (err= iguana_ramchain_iterate(myinfo,coin,dest,&R[bundlei],bp,bundlei)) != 0 )
{
if ( (block= bp->blocks[bundlei]) != 0 )
@ -2615,7 +2608,7 @@ int32_t iguana_bundlesaveHT(struct supernet_info *myinfo,struct iguana_info *coi
memset(&newchain,0,sizeof(newchain));
if ( bundlei == endi+1 && iguana_ramchain_expandedsave(myinfo,coin,RAMCHAIN_DESTARG,&newchain,&HASHMEM,0,bp) == 0 )
{
//char str[65]; printf("d.%d ht.%d %s saved\n",depth,dest->height,mbstr(str,dest->H.data->allocsize));
//char str[65]; printf("d.%d ht.%d %s saved lag.%d elapsed.%ld\n",depth,dest->height,mbstr(str,dest->H.data->allocsize),now-starttime,time(NULL)-now);
retval = 0;
} else bp->generrs++;
iguana_bundlemapfree(coin,mem,&HASHMEM,ipbits,ptrs,filesizes,num,R,starti,endi);
@ -2664,7 +2657,7 @@ void iguana_mergefree(struct iguana_info *coin,struct OS_memspace *mem,struct ig
int32_t iguana_bundlemergeHT(struct supernet_info *myinfo,char *fname,struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,struct iguana_bundle *nextbp,uint32_t starttime)
{
static int32_t depth; static const bits256 zero; uint8_t zcash = 0;
static int32_t depth; static const bits256 zero;
RAMCHAIN_DESTDECLARE; struct OS_memspace HASHMEM,HASHMEMA,HASHMEMB;
uint32_t now = (uint32_t)time(NULL); char str[65],fnameA[1024],fnameB[1024];
struct iguana_ramchain _Achain,_Bchain,*A,*B,R,newchain,*dest = &R; int32_t err,retval = -1,firsti = 1;
@ -2675,11 +2668,11 @@ int32_t iguana_bundlemergeHT(struct supernet_info *myinfo,char *fname,struct igu
iguana_meminit(&HASHMEMB,"hashmemB",0,iguana_hashmemsize(nextbp->ramchain.H.txidind,nextbp->ramchain.H.unspentind,nextbp->ramchain.H.spendind,nextbp->ramchain.pkind,nextbp->ramchain.externalind,nextbp->ramchain.H.data->scriptspace) + IGUANA_MAXSCRIPTSIZE,0);
memset(&_Achain,0,sizeof(_Achain)); A = &_Achain;
memset(&_Bchain,0,sizeof(_Bchain)); B = &_Bchain;
if ( (A= iguana_ramchain_map(myinfo,coin,fnameA,bp,bp->ramchain.numblocks,A,&HASHMEMA,0,bp->hashes[0],zero,0,0,1,1,zcash)) != 0 )
if ( (A= iguana_ramchain_map(myinfo,coin,fnameA,bp,bp->ramchain.numblocks,A,&HASHMEMA,0,bp->hashes[0],zero,0,0,1,1)) != 0 )
{
iguana_ramchain_link(A,bp->hashes[0],bp->hdrsi,bp->bundleheight,0,bp->ramchain.numblocks,firsti,1);
}
if ( (B= iguana_ramchain_map(myinfo,coin,fnameB,bp,nextbp->ramchain.numblocks,B,&HASHMEMB,0,nextbp->hashes[0],zero,0,0,1,1,zcash)) != 0 )
if ( (B= iguana_ramchain_map(myinfo,coin,fnameB,bp,nextbp->ramchain.numblocks,B,&HASHMEMB,0,nextbp->hashes[0],zero,0,0,1,1)) != 0 )
{
iguana_ramchain_link(B,bp->hashes[0],nextbp->hdrsi,nextbp->bundleheight,0,nextbp->ramchain.numblocks,firsti,1);
}
@ -2691,7 +2684,7 @@ int32_t iguana_bundlemergeHT(struct supernet_info *myinfo,char *fname,struct igu
}
if ( A->H.data != 0 && B->H.data != 0 && B->height == A->height+A->numblocks )
{
if ( iguana_ramchain_alloc(fname,coin,dest,mem,&HASHMEM,(A->H.data->numtxids+B->H.data->numtxids),(A->H.data->numunspents+B->H.data->numunspents),(A->H.data->numspends+B->H.data->numspends),(A->H.data->numpkinds+B->H.data->numpkinds),(A->H.data->numexternaltxids+B->H.data->numexternaltxids),A->H.data->scriptspace,A->height,A->numblocks + B->numblocks,zcash) < 0 )
if ( iguana_ramchain_alloc(fname,coin,dest,mem,&HASHMEM,(A->H.data->numtxids+B->H.data->numtxids),(A->H.data->numunspents+B->H.data->numunspents),(A->H.data->numspends+B->H.data->numspends),(A->H.data->numpkinds+B->H.data->numpkinds),(A->H.data->numexternaltxids+B->H.data->numexternaltxids),A->H.data->scriptspace,A->height,A->numblocks + B->numblocks,coin->chain->zcash) < 0 )
{
printf("depth.%d ht.%d fsize.%s ERROR alloc lag.%d elapsed.%d\n",depth,dest->height,mbstr(str,dest->H.data->allocsize),now-starttime,(int32_t)(time(NULL)-now));
iguana_mergefree(coin,mem,A,B,&HASHMEM,&HASHMEMA,&HASHMEMB);

6
iguana/iguana_recv.c

@ -493,7 +493,7 @@ void iguana_oldgotblockM(struct supernet_info *myinfo,struct iguana_info *coin,s
addr->recvblocks += 1.;
addr->recvtotal += recvlen;
}
if ( speculative == 0 && iguana_ramchain_data(myinfo,coin,addr,origtxdata,txarray,origtxdata->zblock.RO.txn_count,data,recvlen,bp,block,0) >= 0 )
if ( speculative == 0 && iguana_ramchain_data(myinfo,coin,addr,origtxdata,txarray,origtxdata->zblock.RO.txn_count,data,recvlen,bp,block) >= 0 )
{
txdata->zblock.fpipbits = (uint32_t)addr->ipbits;
txdata->zblock.RO.recvlen = recvlen;
@ -851,7 +851,7 @@ void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,stru
didinit = 1;
}
portable_mutex_lock(&mutex);*/
if ( iguana_ramchain_data(myinfo,coin,addr,origtxdata,txarray,origtxdata->zblock.RO.txn_count,data,recvlen,bp,block,zcash) >= 0 )
if ( iguana_ramchain_data(myinfo,coin,addr,origtxdata,txarray,origtxdata->zblock.RO.txn_count,data,recvlen,bp,block) >= 0 )
{
txdata->zblock.fpipbits = (uint32_t)addr->ipbits;
txdata->zblock.RO.recvlen = recvlen;
@ -886,7 +886,7 @@ void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,stru
}
else if ( bp->queued == 0 && bp->startutxo == 0 )
{
iguana_bundleQ(myinfo,coin,bp,0);
iguana_bundleQ(myinfo,coin,bp,1000);
//printf("numsaved.%d [%d] %s\n",numsaved,bp->hdrsi,addr->ipaddr);
}
}

3
iguana/iguana_rpc.c

@ -1143,9 +1143,10 @@ void iguana_rpcloop(void *args)
}
memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits));
expand_ipbits(remoteaddr,ipbits);
//printf("RPC.(%s) %x\n",remoteaddr,ipbits);
if ( strcmp(WHITELIST_IPADDR,remoteaddr) == 0 || strncmp(remoteaddr,"127.0.0.",strlen("127.0.0.")) == 0 )
strcpy(remoteaddr,"127.0.0.1");
else printf("remote RPC request from (%s) %x\n",remoteaddr,ipbits);
memset(jsonbuf,0,IGUANA_MAXPACKETSIZE);
remains = (int32_t)(IGUANA_MAXPACKETSIZE - 1);
buf = jsonbuf;

2
iguana/iguana_secp.c

@ -39,7 +39,7 @@ int32_t bitcoin_pubkeylen(const uint8_t *pubkey)
return(65);
else
{
printf("illegal pubkey.[%02x] %llx\n",pubkey[0],*(long long *)pubkey);
//printf("illegal pubkey.[%02x] %llx\n",pubkey[0],*(long long *)pubkey);
return(-1);
}
}

15
iguana/iguana_sign.c

@ -22,8 +22,8 @@ int32_t iguana_vinparse(struct iguana_info *coin,int32_t rwflag,uint8_t *seriali
{
int32_t p2shlen,len = 0; uint32_t tmp;
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->prev_hash),msg->prev_hash.bytes);
//char str[65]; printf("prev_hash.(%s)\n",bits256_str(str,msg->prev_hash));
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->prev_vout),&msg->prev_vout);
//char str[65]; printf("prev_hash.(%s) v%d\n",bits256_str(str,msg->prev_hash),msg->prev_vout);
if ( rwflag == 1 )
{
tmp = msg->scriptlen + msg->userdatalen + msg->p2shlen;
@ -618,6 +618,9 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
return(-1);
}
}
//for (i=-3; i<7; i++)
// printf("%02x",serialized[len+i]);
//printf(" prev 3 bytes before tx_out rw.%d\n",rwflag);
len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_out);
if ( rwflag == 0 )
{
@ -643,7 +646,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
len += n;
if ( len > maxsize )
{
printf("invalid tx_out.%d len.%d vs maxsize.%d n.%d\n",msg->tx_out,len,maxsize,n);
printf("invalidC tx_out.%d of %d len.%d vs maxsize.%d n.%d\n",i,msg->tx_out,len,maxsize,n);
return(-1);
}
if ( voutarray != 0 )
@ -1411,8 +1414,8 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
decode_hex(serialized,len,rawtx);
if ( (txobj= bitcoin_hex2json(coin,height,&txid,msgtx,rawtx,extraspace,extralen,serialized4,vins,V->suppress_pubkeys)) != 0 )
{
//if ( vins != 0 )
// printf("vins.(%s)\n",jprint(vins,0));
if ( 0 && vins != 0 )
printf("txobj.(%s)\n",jprint(txobj,0));
if ( jobj(txobj,"error") != 0 )
{
printf("txobj.(%s)\n",jprint(txobj,0));
@ -1430,7 +1433,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
}
free(checkstr);
}
}
} else fprintf(stderr,"no txobj from bitcoin_hex2json\n");
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 )
{
memset(msgtx,0,sizeof(*msgtx));
@ -1470,7 +1473,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
} else printf("%s signed\n",bits256_str(str,*signedtxidp));
}
}
}
} else fprintf(stderr,"no inputs in vins.(%s)\n",vins!=0?jprint(vins,0):"null");
free(extraspace);
free(serialized), free(serialized2), free(serialized3), free(serialized4);
} else return(-1);

2
iguana/iguana_spendvectors.c

@ -1134,7 +1134,7 @@ int32_t iguana_bundlevalidate(struct supernet_info *myinfo,struct iguana_info *c
if ( coin->chain->zcash != 0 )
{
static uint32_t counter;
if ( counter++ < 3 )
if ( 0 && counter++ < 3 )
printf("need to process joinsplits before can validate.%s\n",coin->symbol);
bp->validated = (uint32_t)time(NULL);
forceflag = 1;

9
iguana/iguana_wallet.c

@ -164,6 +164,8 @@ struct iguana_waddress *iguana_waddressadd(struct supernet_info *myinfo,struct i
//if ( addwaddr->wifstr[0] != 0 )
strcpy(waddr->wifstr,addwaddr->wifstr);
memcpy(waddr->rmd160,rmd160,sizeof(waddr->rmd160));
if ( addwaddr->pubkey[0] == 0 )
bitcoin_pubkey33(myinfo->ctx,addwaddr->pubkey,addwaddr->privkey);
calc_rmd160_sha256(rmd160,addwaddr->pubkey,bitcoin_pubkeylen(addwaddr->pubkey));
if ( memcmp(rmd160,waddr->rmd160,sizeof(waddr->rmd160)) == 0 )
memcpy(waddr->pubkey,addwaddr->pubkey,sizeof(waddr->pubkey));
@ -669,6 +671,8 @@ uint8_t iguana_waddrvalidate(struct supernet_info *myinfo,struct iguana_info *co
memset(&waddr->privkey,0,sizeof(waddr->privkey));
}
}
if ( waddr->pubkey[0] == 0 )
bitcoin_pubkey33(myinfo->ctx,waddr->pubkey,waddr->privkey);
if ( bitcoin_pubkeylen(waddr->pubkey) > 0 )
{
errors[1]++;
@ -708,6 +712,8 @@ uint8_t iguana_waddrvalidate(struct supernet_info *myinfo,struct iguana_info *co
}
}
}
if ( waddr->pubkey[0] == 0 )
bitcoin_pubkey33(myinfo->ctx,waddr->pubkey,waddr->privkey);
if ( (plen= bitcoin_pubkeylen(waddr->pubkey)) > 0 )
{
calc_rmd160_sha256(rmd160,waddr->pubkey,plen);
@ -977,7 +983,7 @@ cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin
{
if ( (waddr= iguana_waddresssearch(myinfo,&wacct,&addresses[i * 64])) != 0 )
{
printf("%s ",waddr->wifstr);
//printf("%s ",waddr->wifstr);
jaddistr(privkeys,waddr->wifstr);
}
else printf("cant find waddr for %s\n",&addresses[i*64]);
@ -1127,6 +1133,7 @@ cJSON *iguana_getinfo(struct supernet_info *myinfo,struct iguana_info *coin)
jadd(retjson,"supernet",array);
jaddnum(retjson,"connections",coin->peers->numranked);
}
jaddnum(retjson,"RELAY",coin->FULLNODE);
jaddnum(retjson,"difficulty",coin->blocks.hwmchain.PoW);
jaddstr(retjson,"status",coin->statusstr);
jaddstr(retjson,"coin",coin->symbol);

73
iguana/m_notary

@ -17,44 +17,47 @@ sleep 4
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"SuperNET\",\"method\":\"myipaddr\",\"ipaddr\":\"$myip\"}"
sleep 3
tests/addnotarys_7776
./btc_7776
./kmd_7776
coins/btc_7776
coins/kmd_7776
#coins/revs_7776
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"$myip\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KMD\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"REVS\",\"pubkey\":\"$pubkey\"}"
sleep 7
./wp_7776
sleep 3
curl --url "http://127.0.0.1:7776" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}"
sleep 6
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EUR\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EUR\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"JPY\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GBP\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"AUD\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CAD\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHF\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NZD\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CNY\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RUB\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MXN\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BRL\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"INR\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HKD\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"TRY\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ZAR\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PLN\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NOK\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SEK\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DKK\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CZK\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HUF\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ILS\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KRW\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MYR\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PHP\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RON\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SGD\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"THB\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BGN\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"IDR\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HRK\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"JPY\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GBP\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"AUD\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CAD\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHF\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NZD\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CNY\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RUB\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MXN\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BRL\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"INR\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HKD\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"TRY\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ZAR\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PLN\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NOK\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SEK\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DKK\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CZK\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HUF\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ILS\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KRW\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MYR\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PHP\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RON\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SGD\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"THB\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BGN\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"IDR\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HRK\",\"pubkey\":\"$pubkey\"}"

28
iguana/m_test

@ -0,0 +1,28 @@
#!/bin/bash
pkill iguana
rm -f ../agents/iguana *.o
git pull
cd secp256k1; ./m_unix; cd ..
cd ../crypto777; ./m_LP; cd ../iguana
gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c -O2 -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c
gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c
gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lnanomsg -lcurl -lssl -lcrypto -lpthread -lz -lm
../agents/iguana notary & #> iguana.log 2> error.log &
myip=`curl -s4 checkip.amazonaws.com`
source pubkey.txt
coins/kmd_7776
coins/revs_7776
sleep 4
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"SuperNET\",\"method\":\"myipaddr\",\"ipaddr\":\"$myip\"}"
sleep 3
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"$myip\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"78.47.196.146\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"5.9.102.210\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"89.248.160.237\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"89.248.160.238\"}"
./wp_7776
curl --url "http://127.0.0.1:7776" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"REVS\",\"pubkey\":\"$pubkey\"}"

35
iguana/main.c

@ -1611,6 +1611,7 @@ void iguana_main(void *arg)
}
strcpy(myinfo->rpcsymbol,"BTCD");
iguana_urlinit(myinfo,ismainnet,usessl);
portable_mutex_init(&myinfo->dpowmutex);
if ( myinfo->IAMNOTARY == 0 )
{
#if LIQUIDITY_PROVIDER
@ -1636,6 +1637,40 @@ void iguana_main(void *arg)
#endif
}
} else basilisks_init(myinfo);
if ( 0 )
{
char *jsonstr = "[\"03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828\", \"02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344\", \"03750cf30d739cd7632f77c1c02812dd7a7181628b0558058d4755838117e05339\", \"0394f3529d2e8cc69ffa7a2b55f3761e7be978fa1896ef4c55dc9c275e77e5bf5e\", \"0243c1eeb3777af47187d542e5f8c84f0ac4b05cf5a7ad77faa8cb6d2d56db7823\", \"02bb298844175640a34e908ffdfa2839f77aba3d5edadefee16beb107826e00063\", \"02fa88e549b4b871498f892e527a5d57287916809f8cc3163f641d71c535e8df5a\", \"032f799e370f06476793a122fcd623db7804898fe5aef5572095cfee6353df34bf\", \"02c06fe5401faff4442ef87b7d1b56c2e5a214166615f9a2f2030c71b0cb067ae8\", \"038ac67ca49a8169bcc5de83fe020071095a2c3b2bc4d1c17386977329758956d5\"]";
int32_t i,n; char coinaddr[64]; uint8_t pubkey33[33]; double val = 0.1; cJSON *array;
if ( (array= cJSON_Parse(jsonstr)) != 0 )
{
n = cJSON_GetArraySize(array);
for (i=0; i<n; i++)
{
decode_hex(pubkey33,33,jstri(array,i));
bitcoin_address(coinaddr,60,pubkey33,33);
printf("./komodo-cli -ac_name=REVS sendtoaddress %s %f\n",coinaddr,val);
}
} else printf("couldnt parse.(%s)\n",jsonstr);
}
if ( 0 )
{
int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height);
char CURRENCIES[][8] = { "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", // major currencies
"CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK",
"REVS" };
uint8_t pubkeys[64][33]; char coinaddr[64]; int32_t i,j; double val = 0.01;
//n = komodo_notaries("KMD",pubkeys,0);
#include "notaries.h"
for (i=0; i<=32; i++)
{
for (j=0; j<sizeof(Notaries)/sizeof(*Notaries); j++)
{
decode_hex(pubkeys[j],33,Notaries[j][1]);
bitcoin_address(coinaddr,60,pubkeys[j],33);
printf("./komodo-cli -ac_name=%s sendtoaddress %s %f\n",CURRENCIES[i],coinaddr,val);
}
}
}
iguana_launchdaemons(myinfo);
}

30
iguana/tests/addnotarys_7776

@ -1,5 +1,4 @@
#!/bin/bash
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"5.9.102.210\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"78.47.196.146\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"149.56.29.163\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"191.235.80.138\"}"
@ -7,32 +6,3 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"ad
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"94.102.63.226\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"129.232.225.202\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"104.255.64.3\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"163.172.68.112\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"149.56.122.76\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"213.202.253.10\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"217.106.238.109\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"94.102.63.217\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"185.106.121.32\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"221.121.144.139\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"185.82.203.23\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"94.102.63.208\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"148.251.190.89\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"103.18.59.220\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"94.102.63.200\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"164.132.202.176\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"94.102.63.199\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"27.100.36.201\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"94.102.63.218\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"1.234.19.123\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"69.12.77.197\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"185.106.122.147\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"149.56.28.84\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"94.102.63.227\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"120.136.2.29\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"149.202.65.200\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"80.28.255.124\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"221.121.144.138\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"167.114.227.223\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"221.121.144.140\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"94.102.63.226\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"176.9.0.233\"}"

2
iguana/tests/decoderawtransaction

File diff suppressed because one or more lines are too long

2
iguana/tests/ratifyC_7776

File diff suppressed because one or more lines are too long

278
iguana/tests/ratifyX.json

@ -0,0 +1,278 @@
{
"agent": "dpow",
"method": "ratify",
"round": "finaltest",
"minsigs": 7,
"start": 1479400896,
"ratified": [
{
"handle": "testA",
"pubkey": "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828",
"destprevtxid0": "4f49bd22b44ae02f543359e98cea0e9d1f99060877ae220f26cb2f9bcd0a497f",
"destprevvout0": 1,
"srcprevtxid0": "d14260097cb69cebe52841c6ec8aecd68302d8cc100aa37213bf552cc26bed03",
"srcprevvout0": 1
},
{
"handle": "testB",
"pubkey": "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344"
},
{
"handle": "artik_AE",
"pubkey": "029acf1dcd9f5ff9c455f8bb717d4ae0c703e089d16cf8424619c491dff5994c90"
},
{
"handle": "artik_EU",
"pubkey": "03f54b2c24f82632e3cdebe4568ba0acf487a80f8a89779173cdb78f74514847ce"
},
{
"handle": "artik_NA",
"pubkey": "0224e31f93eff0cc30eaf0b2389fbc591085c0e122c4d11862c1729d090106c842"
},
{
"handle": "artik_SH",
"pubkey": "02bdd8840a34486f38305f311c0e2ae73e84046f6e9c3dd3571e32e58339d20937"
},
{
"handle": "badass_EU",
"pubkey": "0209d48554768dd8dada988b98aca23405057ac4b5b46838a9378b95c3e79b9b9e"
},
{
"handle": "badass_NA",
"pubkey": "02afa1a9f948e1634a29dc718d218e9d150c531cfa852843a1643a02184a63c1a7"
},
{
"handle": "badass_SH",
"pubkey": "026b49dd3923b78a592c1b475f208e23698d3f085c4c3b4906a59faf659fd9530b"
},
{
"handle": "crackers_EU",
"pubkey": "0340c66cf2c41c41efb420af57867baa765e8468c12aa996bfd816e1e07e410728"
},
{
"handle": "crackers_NA",
"pubkey": "029e1c01131974f4cd3f564cc0c00eb87a0f9721043fbc1ca60f9bd0a1f73f64a1"
},
{
"handle": "crackers_SH",
"pubkey": "02313d72f9a16055737e14cfc528dcd5d0ef094cfce23d0348fe974b6b1a32e5f0"
},
{
"handle": "durerus_EU",
"pubkey": "02bcbd287670bdca2c31e5d50130adb5dea1b53198f18abeec7211825f47485d57"
},
{
"handle": "etszombi_EU",
"pubkey": "0281b1ad28d238a2b217e0af123ce020b79e91b9b10ad65a7917216eda6fe64bf7"
},
{
"handle": "etszombi_NA",
"pubkey": "02757999e651200ac24ff808e5dc7762ba64da1b940c7b150980f636a3866d6de9"
},
{
"handle": "etszombii_AE",
"pubkey": "0252b6185bf8ea7efe8bbc345ddc8da87329149f30233088387abd716d4aa9e974"
},
{
"handle": "etszombii_SH",
"pubkey": "025d7a193c0757f7437fad3431f027e7b5ed6c925b77daba52a8755d24bf682dde"
},
{
"handle": "farl4web_EU",
"pubkey": "0300ecf9121cccf14cf9423e2adb5d98ce0c4e251721fa345dec2e03abeffbab3f"
},
{
"handle": "farl4web_SH",
"pubkey": "0396bb5ed3c57aa1221d7775ae0ff751e4c7dc9be220d0917fa8bbdf670586c030"
},
{
"handle": "fullmoon_AE",
"pubkey": "0204a908350b8142698fdb6fabefc97fe0e04f537adc7522ba7a1e8f3bec003d4a"
},
{
"handle": "fullmoon_NA",
"pubkey": "03e928cdb694cd3805a03e6f792ac0ba177c3261d98401e9a5450f512fdb89bd09"
},
{
"handle": "fullmoon_SH",
"pubkey": "0396699a1792207b39cd20629a51e0825e075d3a80f0237a95d4385ad2a12d88fb"
},
{
"handle": "grewal_AE",
"pubkey": "034e804867936874d2dcef56ab5696f5fba059db069eb4f5c2887c61e6c60638b1"
},
{
"handle": "grewal_NA",
"pubkey": "03adc0834c203d172bce814df7c7a5e13dc603105e6b0adabc942d0421aefd2132"
},
{
"handle": "grewal_SH",
"pubkey": "03212a73f5d38a675ee3cdc6e82542a96c38c3d1c79d25a1ed2e42fcf6a8be4e68"
},
{
"handle": "indenode_EU",
"pubkey": "0221387ff95c44cb52b86552e3ec118a3c311ca65b75bf807c6c07eaeb1be8303c"
},
{
"handle": "jeezy_EU",
"pubkey": "023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6"
},
{
"handle": "karasugoi_NA",
"pubkey": "02a348b03b9c1a8eac1b56f85c402b041c9bce918833f2ea16d13452309052a982"
},
{
"handle": "kashifali_EU",
"pubkey": "02b74e712998ca1e9580c8c0851f20f79563afd65a22d47d47e184d951bcc1e135"
},
{
"handle": "kolo_AE",
"pubkey": "03016d19344c45341e023b72f9fb6e6152fdcfe105f3b4f50b82a4790ff54e9dc6"
},
{
"handle": "kolo_EU",
"pubkey": "03f5c08dadffa0ffcafb8dd7ffc38c22887bd02702a6c9ac3440deddcf2837692b"
},
{
"handle": "kolo_NA",
"pubkey": "02e17c5f8c3c80f584ed343b8dcfa6d710dfef0889ec1e7728ce45ce559347c58c"
},
{
"handle": "kolo_SH",
"pubkey": "02aa24064500756d9b0959b44d5325f2391d8e95c6127e109184937152c384e185"
},
{
"handle": "locomb_EU",
"pubkey": "02ea030819f09586aa33fa57c1daf80782880e509c9bae87ef8fde1a08acf78599"
},
{
"handle": "metaphilibert_NA",
"pubkey": "02b714aa5833d7a76700c429d5542cea409826d3668ba9d75ec3407a607450563c"
},
{
"handle": "movecrypto_AE",
"pubkey": "022783d94518e4dc77cbdf1a97915b29f427d7bc15ea867900a76665d3112be6f3"
},
{
"handle": "movecrypto_EU",
"pubkey": "021ab53bc6cf2c46b8a5456759f9d608966eff87384c2b52c0ac4cc8dd51e9cc42"
},
{
"handle": "movecrypto_NA",
"pubkey": "02efb12f4d78f44b0542d1c60146738e4d5506d27ec98a469142c5c84b29de0a80"
},
{
"handle": "movecrypto_SH",
"pubkey": "031f9739a3ebd6037a967ce1582cde66e79ea9a0551c54731c59c6b80f635bc859"
},
{
"handle": "muros_AE",
"pubkey": "022d77402fd7179335da39479c829be73428b0ef33fb360a4de6890f37c2aa005e"
},
{
"handle": "muros_NA",
"pubkey": "0252b6185bf8ea7efe8bbc345ddc8da87329149f30233088387abd716d4aa9e974"
},
{
"handle": "nxtswe_EU",
"pubkey": "032fb104e5eaa704a38a52c126af8f67e870d70f82977e5b2f093d5c1c21ae5899"
},
{
"handle": "polycryptoblock_NA",
"pubkey": "02708dcda7c45fb54b78469673c2587bfdd126e381654819c4c23df0e00b679622"
},
{
"handle": "pondsea_AE",
"pubkey": "032e1c213787312099158f2d74a89e8240a991d162d4ce8017d8504d1d7004f735"
},
{
"handle": "pondsea_EU",
"pubkey": "0225aa6f6f19e543180b31153d9e6d55d41bc7ec2ba191fd29f19a2f973544e29d"
},
{
"handle": "pondsea_NA",
"pubkey": "031bcfdbb62268e2ff8dfffeb9ddff7fe95fca46778c77eebff9c3829dfa1bb411"
},
{
"handle": "pondsea_SH",
"pubkey": "02209073bc0943451498de57f802650311b1f12aa6deffcd893da198a544c04f36"
},
{
"handle": "popcornbag_EU",
"pubkey": "024d21c1fa55c454a71da7ca188ada8d530e2f2af5223af3c352f039f555b5178f"
},
{
"handle": "proto_EU",
"pubkey": "03681ffdf17c8f4f0008cefb7fa0779c5e888339cdf932f0974483787a4d6747c1"
},
{
"handle": "rnr_AE",
"pubkey": "02ffda5a0147e781308fe66a1774793eacd9b35829073746b217845cfe7577b7dc"
},
{
"handle": "rnr_EU",
"pubkey": "0287aa4b73988ba26cf6565d815786caf0d2c4af704d7883d163ee89cd9977edec"
},
{
"handle": "rnr_NA",
"pubkey": "03f381ba12b70fb3c5c790ca0131a200534d608c301ff8ccca93abe4cc3444ae5b"
},
{
"handle": "rnr_SH",
"pubkey": "037536fb9bdfed10251f71543fb42679e7c52308bcd12146b2568b9a818d8b8377"
},
{
"handle": "siggurd_NA",
"pubkey": "03f2a02e212604afeff85bedd15703a3e47a13650013e04609140a7b3109d08f77"
},
{
"handle": "supernet_AE",
"pubkey": "029d93ef78197dc93892d2a30e5a54865f41e0ca3ab7eb8e3dcbc59c8756b6e355"
},
{
"handle": "supernet_EU",
"pubkey": "02061c6278b91fd4ac5cab4401100ffa3b2d5a277e8f71db23401cc071b3665546"
},
{
"handle": "supernet_NA",
"pubkey": "033c073366152b6b01535e15dd966a3a8039169584d06e27d92a69889b720d44e1"
},
{
"handle": "titomane_AE",
"pubkey": "03cda6ca5c2d02db201488a54a548dbfc10533bdc275d5ea11928e8d6ab33c2185"
},
{
"handle": "titomane_EU",
"pubkey": "03517fcac101fed480ae4f2caf775560065957930d8c1facc83e30077e45bdd199"
},
{
"handle": "titomane_NA",
"pubkey": "0387046d9745414fb58a0fa3599078af5073e10347e4657ef7259a99cb4f10ad47"
},
{
"handle": "titomane_SH",
"pubkey": "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960"
},
{
"handle": "vanbreuk_EU",
"pubkey": "024f3cad7601d2399c131fd070e797d9cd8533868685ddbe515daa53c2e26004c3"
},
{
"handle": "xrobesx_NA",
"pubkey": "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1"
},
{
"handle": "yassin_EU",
"pubkey": "033fb7231bb66484081952890d9a03f91164fb27d392d9152ec41336b71b15fbd0"
},
{
"handle": "yassin_EU2",
"pubkey": "02468340f56b8efa09c0df2ae4c2e5d9360a77bb6bec136152ed235baecf7ebae6"
},
{
"handle": "yassin_SH",
"pubkey": "0334e6e1ec8285c4b85bd6dae67e17d67d1f20e7328efad17ce6fd24ae97cdd65e"
}
]
}

2
iguana/tests/ratify_7776

@ -1,2 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"dpow\",\"method\":\"ratify\",\"minsigs\":2,\"timestamp\":1476711523,\"ratified\":[{\"handle\":\"testA\",\"pubkey\":\"03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828\"}, {\"handle\":\"testB\",\"pubkey\":\"02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344\"}]}"
curl -s "http://komodonotary.com/notary.json" | curl "http://127.0.0.1:7776" -d @-

3
iguana/tests/ratifytest

@ -0,0 +1,3 @@
#!/bin/bash
#!/bin/bash
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"dpow\",\"method\":\"ratify\",\"source\":\"REVS\",\"minsigs\":8,\"start\":1479481719,\"ratified\":[{\"destprevtxid0\":\"b193f44182d6bcfb52374560ac792ac6fc299fe75401437a446256c26762d189\",\"destprevvout0\":1,\"srcprevtxid0\":\"cca08b14a3cd4c6359a5b0dbf899d8a855044ce8761c4d5581226ca645525cf3\",\"srcprevvout0\":8,\"pubkey\":\"03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828\"}, {\"pubkey\":\"02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344\"}, {\"pubkey\":\"03750cf30d739cd7632f77c1c02812dd7a7181628b0558058d4755838117e05339\"}, {\"pubkey\":\"0394f3529d2e8cc69ffa7a2b55f3761e7be978fa1896ef4c55dc9c275e77e5bf5e\"}, {\"pubkey\":\"0243c1eeb3777af47187d542e5f8c84f0ac4b05cf5a7ad77faa8cb6d2d56db7823\"}, {\"pubkey\":\"02bb298844175640a34e908ffdfa2839f77aba3d5edadefee16beb107826e00063\"}, {\"pubkey\":\"02fa88e549b4b871498f892e527a5d57287916809f8cc3163f641d71c535e8df5a\"}, {\"pubkey\":\"032f799e370f06476793a122fcd623db7804898fe5aef5572095cfee6353df34bf\"}, {\"pubkey\":\"02c06fe5401faff4442ef87b7d1b56c2e5a214166615f9a2f2030c71b0cb067ae8\"}, {\"pubkey\":\"038ac67ca49a8169bcc5de83fe020071095a2c3b2bc4d1c17386977329758956d5\"}]}"

3
iguana/tests/sign

@ -0,0 +1,3 @@
#!/bin/bash
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"method\":\"signrawtransaction\",\"params\":[\"0100000008571ec5afd602f294f3eb95adb83da8894399f9de1a72ed85afc913393afbf3f13000000000ffffffffa20dc04e8a4cc6c619f0857e5a24b527db7ab473a0cd051632a3429841c798680700000000ffffffffeb1bcb46fcbdf97d28be1350254d010d1581a0dc0b7115034b1a23d9f14d7b700400000000ffffffffce3cba6588e17a889264daf868582a46853313a4bff8e64bd048a259eb8f2f140700000000ffffffff54505b1507c71de8cdf6c58ad8c2c6864a48681de2326b60f3d3506f8464d33b0000000000ffffffffbcf7cc97c0e064ac8c3839f46bd6c884edb390625c4975f16864376417f1ce5c0700000000ffffffffc011a2d208bb03f88c9c13a9ebeb9041149d72d26121cf4378ced82df462c8ea0400000000fffffffffb1be8356069642320d9f9b4c4d10ce1ebad59f89b78310988ae5abd34a2253d0100000000ffffffff0c70170000000000002321020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9ac7017000000000000232103b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828ac7017000000000000232102ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344ac7017000000000000232103750cf30d739cd7632f77c1c02812dd7a7181628b0558058d4755838117e05339ac701700000000000023210394f3529d2e8cc69ffa7a2b55f3761e7be978fa1896ef4c55dc9c275e77e5bf5eac701700000000000023210243c1eeb3777af47187d542e5f8c84f0ac4b05cf5a7ad77faa8cb6d2d56db7823ac7017000000000000232102bb298844175640a34e908ffdfa2839f77aba3d5edadefee16beb107826e00063ac7017000000000000232102fa88e549b4b871498f892e527a5d57287916809f8cc3163f641d71c535e8df5aac70170000000000002321032f799e370f06476793a122fcd623db7804898fe5aef5572095cfee6353df34bfac7017000000000000232102c06fe5401faff4442ef87b7d1b56c2e5a214166615f9a2f2030c71b0cb067ae8ac70170000000000002321038ac67ca49a8169bcc5de83fe020071095a2c3b2bc4d1c17386977329758956d5ac00000000000000002b6a29000000000000000000000000000000000000000000000000000000000000000000000000524556530000000000\", [{\"txid\":\"6898c7419842a3321605cda073b47adb27b5245a7e85f019c6c64c8a4ec00da2\",\"vout\":7,\"scriptPubKey\":\"2103750cf30d739cd7632f77c1c02812dd7a7181628b0558058d4755838117e05339ac\"}, {\"txid\":\"707b4df1d9231a4b0315710bdca081150d014d255013be287df9bdfc46cb1beb\",\"vout\":4,\"scriptPubKey\":\"210394f3529d2e8cc69ffa7a2b55f3761e7be978fa1896ef4c55dc9c275e77e5bf5eac\"}, {\"txid\":\"142f8feb59a248d04be6f8bfa4133385462a5868f8da6492887ae18865ba3cce\",\"vout\":7,\"scriptPubKey\":\"210243c1eeb3777af47187d542e5f8c84f0ac4b05cf5a7ad77faa8cb6d2d56db7823ac\"}, {\"txid\":\"3bd364846f50d3f3606b32e21d68484a86c6c2d88ac5f6cde81dc707155b5054\",\"vout\":0,\"scriptPubKey\":\"2102bb298844175640a34e908ffdfa2839f77aba3d5edadefee16beb107826e00063ac\"}, {\"txid\":\"5ccef11764376468f175495c6290b3ed84c8d66bf439388cac64e0c097ccf7bc\",\"vout\":7,\"scriptPubKey\":\"2102fa88e549b4b871498f892e527a5d57287916809f8cc3163f641d71c535e8df5aac\"}, {\"txid\":\"eac862f42dd8ce7843cf2161d2729d144190ebeba9139c8cf803bb08d2a211c0\",\"vout\":4,\"scriptPubKey\":\"21032f799e370f06476793a122fcd623db7804898fe5aef5572095cfee6353df34bfac\"}, {\"txid\":\"3d25a234bd5aae880931789bf859adebe10cd1c4b4f9d9202364696035e81bfb\",\"vout\":1,\"scriptPubKey\":\"2102c06fe5401faff4442ef87b7d1b56c2e5a214166615f9a2f2030c71b0cb067ae8ac\"}] ]}"

4
includes/iguana_funcs.h

@ -64,7 +64,7 @@ void iguana_syncramchain(struct iguana_info *coin);
//int32_t iguana_validateramchain(struct iguana_info *coin,int64_t *netp,uint64_t *creditsp,uint64_t *debitsp,int32_t height,struct iguana_block *block,int32_t hwmheight,struct iguana_prevdep *lp);
int32_t iguana_calcrmd160(struct iguana_info *coin,char *asmstr,struct vin_info *vp,uint8_t *pk_script,int32_t pk_scriptlen,bits256 debugtxid,int32_t vout,uint32_t sequence);
uint32_t iguana_updatescript(struct iguana_info *coin,uint32_t blocknum,uint32_t txidind,uint32_t spendind,uint32_t unspentind,uint64_t value,uint8_t *script,int32_t scriptlen,uint32_t sequence);
void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *txdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t datalen,int32_t fromcache,uint8_t zcache);
void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen,int32_t fromcache,uint8_t zcash);
int32_t iguana_parseblock(struct iguana_info *coin,struct iguana_block *block,struct iguana_msgtx *tx,int32_t numtx);
uint32_t iguana_txidind(struct iguana_info *coin,uint32_t *firstvoutp,uint32_t *firstvinp,bits256 txid);
bits256 iguana_txidstr(struct iguana_info *coin,uint32_t *firstvoutp,uint32_t *firstvinp,char *txidstr,uint32_t txidind);
@ -193,7 +193,7 @@ struct iguana_txblock *iguana_peertxdata(struct iguana_info *coin,int32_t *bundl
int32_t iguana_peerfile_exists(struct iguana_info *coin,struct iguana_peer *addr,char *dirname,char *fname,bits256 hash2,bits256 prevhash2,int32_t numblocks);
struct iguana_ramchain *iguana_ramchainset(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_txblock *txdata);
void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA,struct iguana_peer *addr);
long iguana_ramchain_data(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,int32_t txn_count,uint8_t *data,int32_t recvlen,struct iguana_bundle *bp,struct iguana_block *block,uint8_t zcash);
long iguana_ramchain_data(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,int32_t txn_count,uint8_t *data,int32_t recvlen,struct iguana_bundle *bp,struct iguana_block *block);
int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blockp,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2);
struct iguana_block *iguana_bundleblockadd(struct iguana_info *coin,struct iguana_bundle **bpp,int32_t *bundleip,struct iguana_block *origblock);
int32_t iguana_chainextend(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *newblock);

2
includes/iguana_structs.h

@ -508,7 +508,7 @@ struct iguana_info
uint32_t utxoaddrlastcount,*utxoaddroffsets,lastunspentsupdate; uint8_t *utxoaddrtable; bits256 utxoaddrhash;
FILE *utxofp;
bits256 markedunspents[1024];
char seedipaddr[64];
char seedipaddr[64];
uint32_t lastbesthashtime; bits256 lastbesthash; int32_t lastbestheight;
struct iguana_block *RTblocks[65536]; uint8_t *RTrawdata[65536]; int32_t RTrecvlens[65536],RTnumtx[65536];
struct iguana_RTtxid *RTdataset; struct iguana_RTaddr *RTaddrs;

Loading…
Cancel
Save