diff --git a/basilisk/basilisk_swap.c b/basilisk/basilisk_swap.c index 98cb6d749..a83daa697 100755 --- a/basilisk/basilisk_swap.c +++ b/basilisk/basilisk_swap.c @@ -195,6 +195,8 @@ int32_t basilisk_rawtx_spend(struct supernet_info *myinfo,struct basilisk_swap * char str[65]; printf("add second privkey.(%s) %s\n",jprint(privkeys,0),bits256_str(str,*privkey2)); } else V.N = V.M = 1; V.suppress_pubkeys = dest->suppress_pubkeys; + if ( dest->redeemlen != 0 ) + memcpy(V.p2shscript,dest->redeemscript,dest->redeemlen), V.p2shlen = dest->redeemlen; if ( userdata != 0 && userdatalen > 0 ) { memcpy(V.userdata,userdata,userdatalen); diff --git a/deprecated/obsolete.h b/deprecated/obsolete.h index e0d721098..3dad750bc 100755 --- a/deprecated/obsolete.h +++ b/deprecated/obsolete.h @@ -18503,5 +18503,46 @@ len = 0; } return(n); }*/ + + continue; + for (i=bp->hdrsi; i>=0; i--) + { + if ( (bp= coin->bundles[i]) != 0 ) + { + ramchain = 0; + if ( iguana_pkhashfind(coin,&ramchain,&deposits,&lastunspentind,&p,rmd160,i,i) != 0 && (rdata= ramchain->H.data) != 0 ) + { + spent = 0; + deposits = 0; + unspentind = lastunspentind; + U = RAMCHAIN_PTR(rdata,Uoffset); + T = RAMCHAIN_PTR(rdata,Toffset); + while ( unspentind > 0 ) + { + if ( iguana_spentflag(myinfo,coin,&RTspend,&spentheight,ramchain,i,unspentind,lastheight,0,1<<31,U[unspentind].value) == 0 ) + deposits += U[unspentind].value; + else spent += U[unspentind].value; + unspentind = U[unspentind].prevunspentind; + } + weights[pkind] += (deposits - spent); + /*if ( (A2= ramchain->A2) != 0 && p.pkind > 0 && p.pkind < rdata->numpkinds && (U2= ramchain->Uextras) != 0 ) + { + T = RAMCHAIN_PTR(rdata,Toffset); + U = RAMCHAIN_PTR(rdata,Uoffset); + unspentind = A2[p.pkind].lastunspentind; + while ( unspentind > 0 ) + { + uheight = iguana_uheight(coin,ramchain->height,T,rdata->numtxids,&U[unspentind]); + if ( uheight < lastheight ) + spent += U[unspentind].value; + unspentind = U2[unspentind].prevunspentind; + } + weights[pkind] -= spent; + } else printf("PoS.[%d] rdata.%p or A2.%p error [%d] pkind.%d\n",pkind,rdata,A2,i,p.pkind);*/ + if ( weights[pkind] != 0 ) + printf("wt %.8f P.%d -> [%d] pkind.%d deposits %.8f spent %.8f\n",dstr(weights[pkind]),pkind,i,p.pkind,dstr(deposits),dstr(spent)); + } + } + #endif #endif diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 283e3ea92..fe1c920a7 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -732,7 +732,16 @@ void iguana_coinloop(void *arg) //if ( coin->longestchain+10000 > coin->blocks.maxbits ) // iguana_recvalloc(coin,coin->longestchain + 100000); if ( coin->RELAYNODE != 0 || coin->VALIDATENODE != 0 || coin->MAXPEERS == 1 ) + { flag += iguana_processrecv(myinfo,coin); + if ( coin->RTheight > 0 && coin->RTheight > coin->chain->bundlesize ) + { + int32_t hdrsi,nonz,errs; struct iguana_pkhash *refP; struct iguana_bundle *bp; + hdrsi = (coin->RTheight / coin->chain->bundlesize) - 1; + if ( (bp= coin->bundles[hdrsi]) != 0 && bp->weights == 0 ) + bp->weights = iguana_PoS_weights(myinfo,coin,&refP,&bp->supply,&bp->numweights,&nonz,&errs,bp->bundleheight); + } + } iguana_jsonQ(); } coin->idletime = (uint32_t)time(NULL); diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index ce76ac80e..8b71fe3d0 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -373,7 +373,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i //iguana_blast(coin,addr); } } - copyflag = 0;//(coin->enableCACHE != 0) && (strcmp(coin->symbol,"BTC") != 0); + copyflag = (coin->enableCACHE != 0) && (strcmp(coin->symbol,"BTC") != 0); bp = 0, bundlei = -2; bp = iguana_bundlefind(coin,&bp,&bundlei,origtxdata->zblock.RO.hash2); if ( bp != 0 && bundlei >= 0 && bundlei < bp->n ) diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 2a833f714..2a5342303 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -382,85 +382,6 @@ int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *c return(num); } -int64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *supplyp,int32_t *numacctsp,int32_t *nonzp,int32_t *errsp,int32_t lastheight) -{ - int64_t deposits,RTspend,total,supply,spent,*weights=0; uint32_t lastunspentind,unspentind,pkind; int32_t spentheight,i,neg,nonz,num=0; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; struct iguana_ramchaindata *rdata; struct iguana_pkhash *refP,p; struct iguana_unspent *U; struct iguana_txid *T; uint8_t rmd160[20]; char coinaddr[64]; //struct iguana_account *A2; struct iguana_utxo *U2; - *supplyp = 0; - *numacctsp = *nonzp = 0; - *errsp = 1; - if ( (bp= coin->bundles[lastheight / coin->chain->bundlesize]) == 0 ) - return(0); - if ( (rdata= bp->ramchain.H.data) == 0 ) - return(0); - refP = RAMCHAIN_PTR(rdata,Poffset); - if ( (num= rdata->numpkinds) > 0 ) - { - weights = calloc(num,sizeof(*weights)); - for (pkind=1; pkindchain->pubtype,rmd160,sizeof(rmd160)); - //printf("PKIND.%d %s\n",pkind,coinaddr); - for (i=bp->hdrsi; i>=0; i--) - { - if ( (bp= coin->bundles[i]) != 0 ) - { - ramchain = 0; - if ( iguana_pkhashfind(coin,&ramchain,&deposits,&lastunspentind,&p,rmd160,i,i) != 0 && (rdata= ramchain->H.data) != 0 ) - { - spent = 0; - deposits = 0; - unspentind = lastunspentind; - U = RAMCHAIN_PTR(rdata,Uoffset); - T = RAMCHAIN_PTR(rdata,Toffset); - while ( unspentind > 0 ) - { - if ( iguana_spentflag(myinfo,coin,&RTspend,&spentheight,ramchain,i,unspentind,lastheight,0,1<<31,U[unspentind].value) == 0 ) - deposits += U[unspentind].value; - else spent += U[unspentind].value; - unspentind = U[unspentind].prevunspentind; - } - weights[pkind] += (deposits - spent); - /*if ( (A2= ramchain->A2) != 0 && p.pkind > 0 && p.pkind < rdata->numpkinds && (U2= ramchain->Uextras) != 0 ) - { - T = RAMCHAIN_PTR(rdata,Toffset); - U = RAMCHAIN_PTR(rdata,Uoffset); - unspentind = A2[p.pkind].lastunspentind; - while ( unspentind > 0 ) - { - uheight = iguana_uheight(coin,ramchain->height,T,rdata->numtxids,&U[unspentind]); - if ( uheight < lastheight ) - spent += U[unspentind].value; - unspentind = U2[unspentind].prevunspentind; - } - weights[pkind] -= spent; - } else printf("PoS.[%d] rdata.%p or A2.%p error [%d] pkind.%d\n",pkind,rdata,A2,i,p.pkind);*/ - if ( weights[pkind] != 0 ) - printf("wt %.8f P.%d -> [%d] pkind.%d deposits %.8f spent %.8f\n",dstr(weights[pkind]),pkind,i,p.pkind,dstr(deposits),dstr(spent)); - } - } - } - } - } - nonz = neg = 0; - supply = 0; - for (pkind=1; pkindchain->bundlesize,num,nonz,neg,dstr(supply)); - return(weights); -} - int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int64_t *spentp,int64_t *unspents,int32_t *nump,struct iguana_ramchain *ramchain,struct iguana_pkhash *p,uint32_t lastunspentind,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t hdrsi,int32_t lastheight,int32_t minconf,int32_t maxconf,char *remoteaddr) { struct iguana_unspent *U; struct iguana_utxo *U2; int32_t max,uheight,spentheight; uint32_t pkind=0,unspentind; int64_t spent = 0,checkval,deposits = 0; struct iguana_txid *T; struct iguana_account *A2; struct iguana_ramchaindata *rdata = 0; int64_t RTspend = 0; //struct iguana_spend *S; @@ -526,7 +447,7 @@ int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *co } unspentind = U2[unspentind].prevunspentind; } - if ( llabs(spent - checkval - RTspend) > SMALLVAL ) + if ( 0 && llabs(spent - checkval - RTspend) > SMALLVAL ) printf("spend %s: [%d] deposits %.8f spent %.8f check %.8f (%.8f) vs A2[%u] %.8f\n",lastheight==IGUANA_MAXHEIGHT?"checkerr":"",hdrsi,dstr(deposits),dstr(spent),dstr(checkval)+dstr(RTspend),dstr(*spentp),pkind,dstr(A2[pkind].total)); } (*spentp) = spent; @@ -650,17 +571,118 @@ uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,i { bitcoin_addr2rmd160(&addrtypes[j],&rmdarray[20 * j],coinaddr); init_hexbytes_noT(rmdstr,&rmdarray[20 * j],20); - printf("(%s %s) ",coinaddr,rmdstr); + //printf("(%s %s) ",coinaddr,rmdstr); j++; } } - printf("rmdarray[%d]\n",n); + //printf("rmdarray[%d]\n",n); } if ( flag != 0 ) free_json(array); return(rmdarray); } +int64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_pkhash **Ptrp,int64_t *supplyp,int32_t *numacctsp,int32_t *nonzp,int32_t *errsp,int32_t lastheight) +{ + int64_t balance,total,supply,*weights=0; uint32_t pkind; int32_t numrmds,minconf,neg,numunspents,nonz,num=0; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; struct iguana_pkhash *refP; uint8_t rmd160[20],*rmdarray; cJSON *array; char coinaddr[64]; //struct iguana_account *A2; struct iguana_utxo *U2; + *supplyp = 0; + *numacctsp = *nonzp = 0; + *errsp = 1; + (*Ptrp) = 0; + if ( (bp= coin->bundles[lastheight / coin->chain->bundlesize]) == 0 || bp == coin->current ) + return(0); + if ( (rdata= bp->ramchain.H.data) == 0 ) + return(0); + (*Ptrp) = refP = RAMCHAIN_PTR(rdata,Poffset); + if ( (num= rdata->numpkinds) > 0 ) + { + weights = calloc(num,sizeof(*weights)); + minconf = coin->blocks.hwmchain.height - lastheight; + for (pkind=1; pkindchain->pubtype,rmd160,sizeof(rmd160)); + jaddistr(array,coinaddr); + //bitcoin_address(coinaddr,coin->chain->p2shtype,rmd160,sizeof(rmd160)); + //jaddistr(array,coinaddr); + if ( (rmdarray= iguana_rmdarray(myinfo,coin,&numrmds,array,0)) != 0 ) + { + numunspents = 0; + balance = iguana_unspents(myinfo,coin,0,minconf,(1 << 30),rmdarray,numrmds,lastheight,0,&numunspents,0); + free(rmdarray); + weights[pkind] += balance; + if ( weights[pkind] != balance ) + printf("PKIND.%d %s %.8f += %.8f\n",pkind,coinaddr,dstr(weights[pkind]),dstr(balance)); + } + free_json(array); + } + } + nonz = neg = 0; + supply = 0; + for (pkind=1; pkindchain->bundlesize,num,nonz,neg,dstr(supply)); + return(weights); +} + +bits256 iguana_staker_hash2(bits256 refhash2,uint8_t *refrmd160,uint8_t *rmd160,int64_t weight) +{ + bits256 hash2; + vcalc_sha256cat(hash2.bytes,refhash2.bytes,sizeof(refhash2),rmd160,20); + return(mpz_div64(hash2,weight)); +} + +int _cmp_hashes(const void *a,const void *b) +{ +#define hasha (*(bits256 *)a) +#define hashb (*(bits256 *)b) + return(bits256_cmp(hasha,hashb)); +#undef hasha +#undef hashb +} + +int32_t iguana_staker_sort(struct iguana_info *coin,bits256 *hash2p,uint8_t *refrmd160,struct iguana_pkhash *refP,int64_t *weights,int32_t numweights,bits256 *sortbuf) +{ + int32_t i,j,n = 0; bits256 ind,refhash2 = *hash2p; + memset(sortbuf,0,sizeof(*sortbuf) * 2 * numweights); + for (i=0; i 0 ) + { + memset(&ind,0,sizeof(ind)); + for (j=0; j<20; j++) + ind.bytes[j] = refP[i].rmd160[j]; + ind.ulongs[3] = weights[i]; + ind.uints[5] = i; + sortbuf[n << 1] = iguana_staker_hash2(refhash2,refrmd160,ind.bytes,weights[i]); + sortbuf[(n << 1) + 1] = ind; + n++; + } + } + if ( n > 0 ) + qsort(sortbuf,n,sizeof(*sortbuf)*2,_cmp_hashes); + vcalc_sha256cat(hash2p->bytes,refhash2.bytes,sizeof(refhash2),sortbuf[1].bytes,20); + memcpy(refrmd160,sortbuf[1].bytes,20); + { + char str[65],coinaddr[64]; + bitcoin_address(coinaddr,coin->chain->pubtype,refrmd160,20); + printf("winner.%s %.8f: %s\n",coinaddr,dstr(sortbuf[1].ulongs[3]),bits256_str(str,sortbuf[0])); + } + return((int32_t)sortbuf[1].uints[5]); +} + int32_t iguana_unspent_check(struct supernet_info *myinfo,struct iguana_info *coin,uint16_t hdrsi,uint32_t unspentind) { bits256 txid; int32_t vout,spentheight; diff --git a/iguana/mini-gmp.c b/iguana/mini-gmp.c index 37a361b97..4b330f255 100644 --- a/iguana/mini-gmp.c +++ b/iguana/mini-gmp.c @@ -4439,3 +4439,15 @@ bits256 mpz_muldivcmp(bits256 oldval,int32_t mulval,int32_t divval,bits256 targe return(newval); } +bits256 mpz_div64(bits256 hash,uint64_t divval) +{ + mpz_t bn; bits256 newval; + mpz_init(bn); + mpz_from_bits256(bn,hash); + mpz_tdiv_qr_ui(bn,NULL,bn,divval); + newval = mpz_to_bits256(bn); + //char *bits256_str(char *,bits256); + //char str[65],str2[65]; printf("%s div.%lld -> %s size.%d\n",bits256_str(str,hash),(long long)divval,bits256_str(str2,newval),bn->_mp_size); + mpz_clear(bn); + return(newval); +} diff --git a/iguana/ramchain_api.c b/iguana/ramchain_api.c index eeea84b15..ee3fbbfc1 100755 --- a/iguana/ramchain_api.c +++ b/iguana/ramchain_api.c @@ -186,13 +186,13 @@ STRING_AND_INT(iguana,bundleaddresses,activecoin,height) STRING_AND_INT(iguana,PoSweights,activecoin,height) { - struct iguana_info *ptr; int32_t num,nonz,errs,bundleheight; int64_t *weights,supply; cJSON *retjson; + struct iguana_info *ptr; int32_t num,nonz,errs,bundleheight; struct iguana_pkhash *refP; int64_t *weights,supply; cJSON *retjson; if ( (ptr= iguana_coinfind(activecoin)) != 0 ) { - for (bundleheight=coin->chain->bundlesize; bundleheightchain->bundlesize) + //for (bundleheight=coin->chain->bundlesize; bundleheightchain->bundlesize) { - //bundleheight = (height / coin->chain->bundlesize) * coin->chain->bundlesize; - if ( (weights= iguana_PoS_weights(myinfo,ptr,&supply,&num,&nonz,&errs,bundleheight)) != 0 ) + bundleheight = (height / ptr->chain->bundlesize) * ptr->chain->bundlesize; + if ( (weights= iguana_PoS_weights(myinfo,ptr,&refP,&supply,&num,&nonz,&errs,bundleheight)) != 0 ) { retjson = cJSON_CreateObject(); jaddstr(retjson,"result",errs == 0 ? "success" : "error"); @@ -202,13 +202,45 @@ STRING_AND_INT(iguana,PoSweights,activecoin,height) jaddnum(retjson,"errors",errs); jaddnum(retjson,"supply",dstr(supply)); free(weights); - //return(jprint(retjson,1)); + return(jprint(retjson,1)); } else return(clonestr("{\"error\":\"iguana_PoS_weights returned null\"}")); } } return(clonestr("{\"error\":\"activecoin is not active\"}")); } +STRING_ARG(iguana,stakers,activecoin) +{ + struct iguana_info *ptr; int32_t i,datalen,pkind,hdrsi; bits256 hash2; struct iguana_bundle *bp; cJSON *retjson,*array; struct iguana_pkhash *refP; struct iguana_ramchaindata *rdata; char coinaddr[64]; uint8_t refrmd160[20]; bits256 *sortbuf; + if ( (ptr= iguana_coinfind(activecoin)) != 0 && ptr->RTheight > ptr->chain->bundlesize ) + { + hdrsi = (ptr->RTheight / ptr->chain->bundlesize) - 1; + if ( (bp= ptr->bundles[hdrsi]) != 0 && bp->weights != 0 && (rdata= bp->ramchain.H.data) != 0 && bp->weights != 0 ) + { + sortbuf = calloc(bp->numweights,2 * sizeof(*sortbuf)); + for (i=datalen=0; inumweights; i++) + datalen += iguana_rwnum(1,&((uint8_t *)sortbuf)[datalen],sizeof(bp->weights[i]),(void *)&bp->weights[i]); + hash2 = bits256_doublesha256(0,(uint8_t *)sortbuf,datalen); + refP = RAMCHAIN_PTR(rdata,Poffset); + retjson = cJSON_CreateObject(); + array = cJSON_CreateArray(); + memset(refrmd160,0,sizeof(refrmd160)); + for (i=0; ichain->bundlesize; i++) + { + if ( (pkind= iguana_staker_sort(ptr,&hash2,refrmd160,refP,bp->weights,bp->numweights,sortbuf)) > 0 ) + { + bitcoin_address(coinaddr,ptr->chain->pubtype,refP[pkind].rmd160,sizeof(refP[pkind].rmd160)); + jaddistr(array,coinaddr); + } else jaddistr(array,"error"); + } + jaddstr(retjson,"result","success"); + jadd(retjson,"stakers",array); + return(jprint(retjson,1)); + } else return(clonestr("{\"error\":\"iguana_stakers needs PoSweights and weights\"}")); + } + return(clonestr("{\"error\":\"activecoin is not active\"}")); +} + STRING_AND_INT(iguana,bundlehashes,activecoin,height) { struct iguana_info *ptr; struct iguana_bundle *bp; int32_t i,hdrsi; cJSON *retjson,*array; struct iguana_ramchaindata *rdata; diff --git a/iguana/tests/PoS b/iguana/tests/PoS index 8435b6c88..f3ee99728 100755 --- a/iguana/tests/PoS +++ b/iguana/tests/PoS @@ -1 +1,7 @@ -curl --url "http://127.0.0.1:7778" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"PoSweights\",\"activecoin\":\"BTCD\",\"height\":1200000}" +curl --url "http://127.0.0.1:7778" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"PoSweights\",\"activecoin\":\"BTCD\",\"height\":1192000}" +curl --url "http://127.0.0.1:7778" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"PoSweights\",\"activecoin\":\"BTCD\",\"height\":1192500}" +curl --url "http://127.0.0.1:7778" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"PoSweights\",\"activecoin\":\"BTCD\",\"height\":1193000}" +curl --url "http://127.0.0.1:7778" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"PoSweights\",\"activecoin\":\"BTCD\",\"height\":1193500}" +curl --url "http://127.0.0.1:7778" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"PoSweights\",\"activecoin\":\"BTCD\",\"height\":1194000}" +curl --url "http://127.0.0.1:7778" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"PoSweights\",\"activecoin\":\"BTCD\",\"height\":1194500}" +curl --url "http://127.0.0.1:7778" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"PoSweights\",\"activecoin\":\"BTCD\",\"height\":1195000}" diff --git a/iguana/tests/decoderawtransaction b/iguana/tests/decoderawtransaction index 94b277fae..f6a65e6a9 100755 --- a/iguana/tests/decoderawtransaction +++ b/iguana/tests/decoderawtransaction @@ -1 +1 @@ -curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"method\":\"decoderawtransaction\",\"params\":[\"0100000001afa83a8601f8d86da02823fb39fac4e19f7fcdde276d7c529df94a6fe4067f6a000000008d483045022100f968fcbd1638f0004fa51ef75be60aeb300e0870c72bb85dcc99a6b097d155e30220436884335112fd84dc9837c7d979fc4a5d1220de584d987a799d8a349782ddd7012102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afd204bdc874215f9a5d9793a7b7d36e3960d02d9f969a8d427e9845bc97a48ea41ad00ffffffff015dbc0300000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000\"]}" +curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"decoderawtransaction\",\"params\":[\"01000000e85b8b5701e70119429220c29716cfeec766bfc6dd558d6384f1440f036438be69e4a59af1010000006b483045022100d0c9a4a7fb75a89be15605bf2fcea9988bd15f6df1a6035a7833a2640c60a4590220587539a52310d5a345be0b03b74c7a08b0db0bf390881ded9ae2d680d70ca45501210383497d04e1fb49335215952e02986294762291cd5abde651301f172600fa2924ffffffff028096980000000000475221021249448c9bc1b141ccce56de5b906f502eeca18587c26070610f0fda747b773b210373b708aad6d23c26f109a6281d012d30ca9dfa86acb2c7e5cf2289e588e88c2052ae40084e05000000001976a91421e112f4211cbc612bc5f3de86acf0017b88b67d88ac00000000\"]}" diff --git a/iguana/tests/gettransaction b/iguana/tests/gettransaction index 769c1299e..a03d7fd7a 100755 --- a/iguana/tests/gettransaction +++ b/iguana/tests/gettransaction @@ -1,2 +1,2 @@ -curl --url "http://127.0.0.1:7778" --data "{\"method\":\"gettransaction\",\"coin\":\"BTCD\",\"params\":[\"9825a57222b1f8d2e0072e547865c84d29cd356c0d9078b9cdcd52cf3b320378\"]}" +curl --url "http://127.0.0.1:7778" --data "{\"method\":\"gettransaction\",\"coin\":\"BTCD\",\"params\":[\"f19aa5e469be3864030f44f184638d55ddc6bf66c7eecf1697c22092421901e7\"]}" diff --git a/iguana/tests/request b/iguana/tests/request index de17631b8..91fbcc83b 100755 --- a/iguana/tests/request +++ b/iguana/tests/request @@ -1,2 +1,2 @@ -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"BTCD\",\"amount\":1,\"dest\":\"BTC\",\"minprice\":0.0025}}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"BTCD\",\"amount\":0.1,\"dest\":\"BTC\",\"minprice\":0.0025}}" diff --git a/iguana/tests/stakers b/iguana/tests/stakers new file mode 100755 index 000000000..bf6c5f5f9 --- /dev/null +++ b/iguana/tests/stakers @@ -0,0 +1 @@ +curl --url "http://127.0.0.1:7778" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"stakers\",\"activecoin\":\"BTCD\"}" diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index ca10270ef..a31d8b543 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -142,6 +142,7 @@ P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount STRING_AND_INT(iguana,bundleaddresses,activecoin,height); STRING_AND_INT(iguana,bundlehashes,activecoin,height); STRING_AND_INT(iguana,PoSweights,activecoin,height); +STRING_ARG(iguana,stakers,activecoin); //TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,minaccept,base,rel,minprice,basevolume); //TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,maxaccept,base,rel,maxprice,basevolume); diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index c29deef3e..cd44cc654 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -542,7 +542,9 @@ void iguana_RTspendvectors(struct supernet_info *myinfo,struct iguana_info *coin double instantdex_avehbla(struct supernet_info *myinfo,double retvals[4],char *base,char *rel,double basevolume); int32_t bitcoin_revealsecret160(uint8_t *script,int32_t n,uint8_t secret160[20]); int64_t iguana_lockval(int32_t finalized,int64_t locktime); -int64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *supplyp,int32_t *numacctsp,int32_t *nonzp,int32_t *errsp,int32_t lastheight); +int64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_pkhash **Ptrp,int64_t *supplyp,int32_t *numacctsp,int32_t *nonzp,int32_t *errsp,int32_t lastheight); +int32_t iguana_staker_sort(struct iguana_info *coin,bits256 *hash2p,uint8_t *refrmd160,struct iguana_pkhash *refP,int64_t *weights,int32_t numweights,bits256 *sortbuf); +bits256 mpz_div64(bits256 hash,uint64_t divval); // ------------------------------------------------------[ Preparation ]---- // Initialise a gfshare context for producing shares diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index 6bd874dc1..20c7ce0c9 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -349,6 +349,7 @@ struct iguana_bundle bits256 prevbundlehash2,hashes[IGUANA_MAXBUNDLESIZE+1],nextbundlehash2,allhash,*speculative,validatehash; struct iguana_ramchain ramchain; uint8_t red,green,blue; struct iguana_spendvector *tmpspends; int32_t numtmpspends; + int64_t *weights,supply; int32_t numweights; }; struct iguana_bundlereq