From 893e6c32dcb72fc1f430debe3c0ea44ed0f6d198 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Sep 2016 05:00:30 -0300 Subject: [PATCH] test --- basilisk/basilisk.c | 15 ++-- iguana/iguana_spendvectors.c | 2 +- iguana/iguana_unspents.c | 139 ++++++++++++++++++----------------- 3 files changed, 83 insertions(+), 73 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 05c173745..8f5c8f64d 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -870,14 +870,17 @@ void basilisks_loop(void *arg) basilisk_ping_send(myinfo,btcd); } } - HASH_ITER(hh,myinfo->allcoins,coin,tmpcoin) + if ( myinfo->expiration != 0 ) { - if ( time(NULL) > coin->lastunspentsupdate+10 ) + HASH_ITER(hh,myinfo->allcoins,coin,tmpcoin) { - //printf(">>>>>>>>>>>>> update %s\n",coin->symbol); - basilisk_unspents_update(myinfo,coin); - coin->lastunspentsupdate = (uint32_t)time(NULL); - //printf(">>>>>>>>>>>>> update %s finished\n",coin->symbol); + if ( myinfo->Cunspents == 0 || time(NULL) > coin->lastunspentsupdate+60 ) + { + //printf(">>>>>>>>>>>>> update %s\n",coin->symbol); + basilisk_unspents_update(myinfo,coin); + coin->lastunspentsupdate = (uint32_t)time(NULL); + //printf(">>>>>>>>>>>>> update %s finished\n",coin->symbol); + } } } if ( RELAYID < 0 && myinfo->expiration != 0 ) diff --git a/iguana/iguana_spendvectors.c b/iguana/iguana_spendvectors.c index 76b4cf2f3..6f3f0cb10 100755 --- a/iguana/iguana_spendvectors.c +++ b/iguana/iguana_spendvectors.c @@ -679,7 +679,7 @@ int32_t iguana_volatilesinit(struct supernet_info *myinfo,struct iguana_info *co fprintf(stderr,"."); if ( filecrc == 0 ) { - fprintf(stderr,"balancehash add [%d]\n",bp->hdrsi); + //fprintf(stderr,"balancehash add [%d]\n",bp->hdrsi); vupdate_sha256(balancehash.bytes,&vstate,(void *)Aptr,sizeof(*Aptr) * numpkinds); vupdate_sha256(balancehash.bytes,&vstate,(void *)Uptr,sizeof(*Uptr) * numunspents); vupdate_sha256(allbundles.bytes,&bstate,(void *)bp->hashes,sizeof(bp->hashes[0]) * bp->n); diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 5b4ca3986..202e37061 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -653,7 +653,7 @@ int64_t iguana_RTunspents(struct supernet_info *myinfo,struct iguana_info *coin, uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numrmdsp,cJSON *array,int32_t firsti) { - int32_t i,n,flag=0,j=0; char *coinaddr,rmdstr[41]; uint8_t *addrtypes,*rmdarray = 0; + int32_t i,n,flag=0,k,j=0; char *coinaddr,rmdstr[41]; uint8_t addrtype,*addrtypes,*rmdarray = 0; *numrmdsp = 0; if ( array == 0 || cJSON_GetArraySize(array) == 0 ) array = iguana_getaddressesbyaccount(myinfo,coin,"*"); @@ -666,9 +666,19 @@ uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,i { if ( (coinaddr= jstr(jitem(array,i),0)) != 0 ) { + //printf("(%s %s) ",coinaddr,rmdstr); + if ( iguana_addressvalidate(coin,&addrtype,coinaddr) < 0 ) + { + printf("i.%d illegal coinaddr.(%s) longest.%d\n",i,coinaddr,coin->longestchain); + continue; + } bitcoin_addr2rmd160(&addrtypes[j],&rmdarray[20 * j],coinaddr); + for (k=0; k<20; k++) + if ( rmdarray[20 * j + k] != 0 ) + break; + if ( k == 20 ) + continue; init_hexbytes_noT(rmdstr,&rmdarray[20 * j],20); - //printf("(%s %s) ",coinaddr,rmdstr); j++; } } @@ -807,10 +817,20 @@ int32_t iguana_RTunspent_check(struct supernet_info *myinfo,struct iguana_info * int32_t iguana_RTaddr_unspents(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *sump,struct iguana_outpoint *unspents,int32_t max,char *coinaddr,char *remoteaddr,int32_t lastheight,int32_t includespent) { - int32_t n,k,numunspents,minconf = 0; uint64_t total; uint8_t rmd160[20],pubkey[65],addrtype; + int32_t n,j,k,numunspents,minconf = 0; uint64_t total; uint8_t rmd160[20],pubkey[65],addrtype; total = 0; n = numunspents = 0; + if ( iguana_addressvalidate(coin,&addrtype,coinaddr) < 0 ) + { + printf("illegal coinaddr.(%s) minconf.%d longest.%d diff.%d\n",coinaddr,minconf,coin->longestchain,coin->blocks.hwmchain.height - minconf); + return(0); + } bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); + for (j=0; j<20; j++) + if ( rmd160[j] != 0 ) + break; + if ( j == 20 ) + return(0); iguana_RTpkhasharray(myinfo,coin,0,minconf,coin->longestchain,&total,0,coin->bundlescount,rmd160,coinaddr,pubkey,lastheight,unspents,&n,max-1000,remoteaddr,includespent); numunspents = n; for (k=0; ktxfee; - for (i=numunspents=0; ilongestchain,coin->blocks.hwmchain.height - minconf); - continue; - } - bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); - for (j=0; j<20; j++) - if ( rmd160[j] != 0 ) - break; - if ( j == 20 ) - continue; - if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 ) - { - numunspents += iguana_RTaddr_unspents(myinfo,coin,&sum,&unspents[numunspents],max-numunspents,coinaddr,remoteaddr,1<<30,0); - } - else - { - portable_mutex_lock(&myinfo->bu_mutex); - //if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 ) - { - if ( myinfo->Cunspents != 0 && (array= jobj(myinfo->Cunspents,coin->symbol)) != 0 ) - { - if ( (n= cJSON_GetArraySize(array)) > 0 ) - { - for (i=0; ibu_mutex); - } - if ( numunspents > max || sum > required ) - break; - //printf("n.%d max.%d total %.8f\n",n,max,dstr(total)); - } - } - *totalp = sum; - printf("numunspents.%d sum %.8f\n",numunspents,dstr(sum)); - return(numunspents); -} - int32_t iguana_RTuvaltxid(struct supernet_info *myinfo,bits256 *txidp,struct iguana_info *coin,struct iguana_outpoint outpt) { struct iguana_bundle *bp; struct iguana_unspent *U,*u; struct iguana_txid *T; struct iguana_ramchain *ramchain; struct iguana_ramchaindata *rdata; struct iguana_RTunspent *unspent; struct iguana_RTtxid *parent; @@ -992,6 +949,56 @@ cJSON *iguana_RTlistunspent(struct supernet_info *myinfo,struct iguana_info *coi return(retjson); } +int32_t iguana_RTunspentslists(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *totalp,struct iguana_outpoint *unspents,int32_t max,uint64_t required,int32_t minconf,cJSON *addresses,char *remoteaddr) +{ + uint64_t sum = 0; int32_t i,n,numunspents,numaddrs; uint8_t pubkey[65]; char *coinaddr; struct iguana_outpoint outpt; cJSON *array,*item; //struct iguana_waddress *waddr; struct iguana_waccount *wacct; + *totalp = 0; + numunspents = 0; + if ( (numaddrs= cJSON_GetArraySize(addresses)) == 0 ) + { + printf("null addresses.(%s)\n",jprint(addresses,0)); + return(0); + } + memset(pubkey,0,sizeof(pubkey)); + //remains = required * 1.1 + coin->txfee; + if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 ) + { + for (i=numunspents=0; i 0 ) + { + for (i=0; i max || sum > required ) + break; + } + } + free_json(array); + } + } + *totalp = sum; + printf("numunspents.%d max.%d sum %.8f required %.8f\n",numunspents,max,dstr(sum),dstr(required)); + return(numunspents); +} + #define UTXOADDR_ITEMSIZE 32 #define iguana_utxotable_numinds(ind) (((ind) == 0xffff) ? coin->utxoaddrlastcount : (coin->utxoaddroffsets[(ind) + 1] - coin->utxoaddroffsets[ind]))