diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index ba38ae0be..b32695947 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -956,7 +956,11 @@ HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr) return(clonestr("{\"error\":\"no result\"}")); } } else printf("no coin\n"); - return(basilisk_standardservice("BAL",myinfo,0,hash,vals,hexstr,1)); + if ( (retstr= basilisk_standardservice("BAL",myinfo,0,hash,vals,hexstr,1)) != 0 ) + { + basilisk_unspents_process(myinfo,coin,retstr); + } + return(retstr); } HASH_ARRAY_STRING(basilisk,history,hash,vals,hexstr) diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index bf0148744..18778ee6a 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -914,65 +914,91 @@ int32_t basilisk_unspentfind(struct supernet_info *myinfo,struct iguana_info *co return(-1); } -void basilisk_jsonmerge(cJSON *json,char *symbol,cJSON *array) +cJSON *basilisk_jsonmerge(char *symbol,cJSON *array) { - int32_t i,j,n,m; cJSON *jobj,*iobj,*dest; - if ( (dest= jarray(&m,json,symbol)) == 0 ) - dest = cJSON_CreateArray(); + int32_t i,j,n,m; cJSON *jobj,*iobj,*dest = cJSON_CreateArray(); if ( dest != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { - m = cJSON_GetArraySize(dest); for (i=0; i 0 ) { item = jitem(spends,0); - if ( (address= jstr(item,"address")) != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 ) + if ( (address= jstr(item,"address")) != 0 )//&& (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 ) { if ( myinfo->Cspends == 0 ) - { myinfo->Cspends = cJSON_CreateObject(); - jadd(myinfo->Cspends,coin->symbol,jduplicate(spends)); - } else basilisk_jsonmerge(myinfo->Cspends,coin->symbol,spends); + if ( jobj(myinfo->Cspends,coin->symbol) != 0 ) + jdelete(myinfo->Cspends,coin->symbol); + jadd(myinfo->Cspends,coin->symbol,basilisk_jsonmerge(coin->symbol,spends)); //printf("S.(%s)\n",jprint(waddr->Cspends,0)); } //printf("merge spends.(%s)\n",jprint(spends,0)); } - if ( (unspents= jarray(&n,json,"unspents")) != 0 ) + if ( (unspents= jarray(&n,json,"unspents")) != 0 && n > 0 ) { item = jitem(unspents,0); - if ( (address= jstr(item,"address")) != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 ) + if ( (address= jstr(item,"address")) != 0 )//&& (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 ) { if ( myinfo->Cunspents == 0 ) - { myinfo->Cunspents = cJSON_CreateObject(); - jadd(myinfo->Cunspents,coin->symbol,jduplicate(unspents)); - } else basilisk_jsonmerge(myinfo->Cunspents,coin->symbol,unspents); - printf("U.(%s)\n",jprint(myinfo->Cunspents,0)); + if ( jobj(myinfo->Cunspents,coin->symbol) != 0 ) + jdelete(myinfo->Cunspents,coin->symbol); + jadd(myinfo->Cunspents,coin->symbol,basilisk_jsonmerge(coin->symbol,unspents)); + //printf("U.(%s)\n",jprint(myinfo->Cunspents,0)); } //printf("merge unspents.(%s)\n",jprint(unspents,0)); } } +void basilisk_unspents_process(struct supernet_info *myinfo,struct iguana_info *coin,char *retstr) +{ + cJSON *retarray; int32_t i,n; + portable_mutex_lock(&myinfo->bu_mutex); + if ( myinfo->Cspends != 0 ) + free_json(myinfo->Cspends), myinfo->Cspends = 0; + if ( myinfo->Cunspents != 0 ) + free_json(myinfo->Cunspents), myinfo->Cunspents = 0; + if ( (retarray= cJSON_Parse(retstr)) != 0 ) + { + if ( is_cJSON_Array(retarray) != 0 ) + { + n = cJSON_GetArraySize(retarray); + for (i=0; ibu_mutex); +} + void basilisk_unspents_update(struct supernet_info *myinfo,struct iguana_info *coin) { - char *retstr; cJSON *vals; int32_t oldest,i,RTheight; cJSON *retarray; + char *retstr; cJSON *vals; int32_t oldest,i,RTheight; vals = cJSON_CreateObject(); for (i=oldest=0; irelay_RTheights[i]) != 0 && (oldest == 0 || RTheight < oldest) ) @@ -982,19 +1008,7 @@ void basilisk_unspents_update(struct supernet_info *myinfo,struct iguana_info *c jaddstr(vals,"coin",coin->symbol); if ( (retstr= basilisk_balances(myinfo,coin,0,0,GENESIS_PUBKEY,vals,"")) != 0 ) { - //printf("basilisk_balances.(%s)\n",retstr); - if ( (retarray= cJSON_Parse(retstr)) != 0 ) - { - portable_mutex_lock(&myinfo->bu_mutex); - iguana_wallet_Cclear(myinfo,coin->symbol); - if ( is_cJSON_Array(retarray) != 0 ) - { - for (i=0; ibu_mutex); - } + basilisk_unspents_process(myinfo,coin,retstr); free(retstr); } free_json(vals); diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 66ffdcb3d..5b4ca3986 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -941,11 +941,44 @@ uint64_t iguana_unspentavail(struct supernet_info *myinfo,struct iguana_info *co cJSON *iguana_RTlistunspent(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *argarray,int32_t minconf,int32_t maxconf,char *remoteaddr,int32_t includespends) { - int32_t numrmds,numunspents=0; uint8_t *rmdarray; cJSON *retjson = cJSON_CreateArray(); - rmdarray = iguana_rmdarray(myinfo,coin,&numrmds,argarray,0); - iguana_RTunspents(myinfo,coin,retjson,minconf,maxconf,rmdarray,numrmds,(1 << 30),0,&numunspents,remoteaddr,includespends); - if ( rmdarray != 0 ) - free(rmdarray); + int32_t i,j,m,n,numrmds,numunspents=0; char *coinaddr; uint8_t *rmdarray; cJSON *unspents,*item,*array,*retjson; + if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 ) + { + retjson = cJSON_CreateArray(); + rmdarray = iguana_rmdarray(myinfo,coin,&numrmds,argarray,0); + iguana_RTunspents(myinfo,coin,retjson,minconf,maxconf,rmdarray,numrmds,(1 << 30),0,&numunspents,remoteaddr,includespends); + if ( rmdarray != 0 ) + free(rmdarray); + } + else + { + portable_mutex_lock(&myinfo->bu_mutex); + if ( (unspents= myinfo->Cunspents) != 0 && (array= jobj(unspents,coin->symbol)) != 0 ) + unspents = jduplicate(array); + portable_mutex_unlock(&myinfo->bu_mutex); + retjson = cJSON_CreateArray(); + if ( unspents != 0 ) + { + if ( (n= cJSON_GetArraySize(unspents)) > 0 && (m= cJSON_GetArraySize(argarray)) > 0 ) + { + for (i=0; iwallet,subset,tmp) - { - HASH_ITER(hh,subset->waddr,waddr,tmp2) - { - if ( waddr->Cspends != 0 ) - free_json(waddr->Cspends), waddr->Cspends = 0; - if ( waddr->Cunspents != 0 ) - free_json(waddr->Cunspents), waddr->Cunspents = 0; - } - }*/ - portable_mutex_lock(&myinfo->bu_mutex); - if ( myinfo->Cspends != 0 ) - free_json(myinfo->Cspends); - if ( myinfo->Cunspents != 0 ) - free_json(myinfo->Cunspents); - portable_mutex_unlock(&myinfo->bu_mutex); -} - struct iguana_waddress *iguana_ismine(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,uint8_t addrtype,uint8_t pubkey[65],uint8_t rmd160[20]) { struct iguana_waccount *wacct; struct iguana_waddress *waddr = 0; @@ -936,10 +917,6 @@ void iguana_walletlock(struct supernet_info *myinfo,struct iguana_info *coin) memset(myinfo->myaddr.NXTADDR,0,sizeof(myinfo->myaddr.NXTADDR)); myinfo->myaddr.nxt64bits = 0; myinfo->expiration = 0; - portable_mutex_lock(&myinfo->bu_mutex); - if ( myinfo->spends != 0 ) - /*free(myinfo->spends),*/ myinfo->numspends = 0; - portable_mutex_unlock(&myinfo->bu_mutex); iguana_walletiterate(myinfo,coin,-2,0,0,0,0); } diff --git a/iguana/tests/listunspent b/iguana/tests/listunspent index 3cb17f9a9..4d650562d 100755 --- a/iguana/tests/listunspent +++ b/iguana/tests/listunspent @@ -1 +1 @@ -curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"listunspent\",\"params\":[1, 9999999, [\"RFMEYcxuBL8S7UPdUbzXunPtS4p82HRcKs\"]]}" +curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"listunspent\",\"params\":[1, 9999999, []]}" diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index a7a9a7527..4cd7b570e 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -245,7 +245,7 @@ int32_t blockhash_sha256(uint8_t *blockhashp,uint8_t *serialized,int32_t len); void iguana_nameset(char name[64],char *symbol,cJSON *json); cJSON *iguana_getinfo(struct supernet_info *myinfo,struct iguana_info *coin); void *basilisk_getinfo(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj); - +void basilisk_unspents_process(struct supernet_info *myinfo,struct iguana_info *coin,char *retstr); char *busdata_sync(uint32_t *noncep,char *jsonstr,char *broadcastmode,char *destNXTaddr); void peggy(); int32_t opreturns_init(uint32_t blocknum,uint32_t blocktimestamp,char *path); @@ -430,7 +430,7 @@ struct iguana_waddress *iguana_waddresssearch(struct supernet_info *myinfo,struc cJSON *iguana_RTlistunspent(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *argarray,int32_t minconf,int32_t maxconf,char *remoteaddr,int32_t includespends); void calc_shares(struct supernet_info *myinfo,uint8_t *shares,uint8_t *secret,int32_t size,int32_t width,int32_t M,int32_t N,uint8_t *sharenrs,uint8_t *space,int32_t spacesize); //struct basilisk_spend *basilisk_addspend(struct supernet_info *myinfo,char *symbol,bits256 txid,uint16_t vout,int32_t addflag); -void iguana_wallet_Cclear(struct supernet_info *myinfo,char *symbol); +//void iguana_wallet_Cclear(struct supernet_info *myinfo,char *symbol); int64_t _RTgettxout(struct iguana_info *coin,struct iguana_RTtxid **ptrp,int32_t *heightp,int32_t *scriptlenp,uint8_t *script,uint8_t *rmd160,char *coinaddr,bits256 txid,int32_t vout,int32_t mempool); int32_t _iguana_RTunspentfind(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,uint8_t *spendscript,struct iguana_outpoint outpt,int64_t value); int32_t basilisk_unspentfind(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,uint8_t *spendscript,struct iguana_outpoint outpt,int64_t value);