From 69b9f767608df3090829a9405265845973c4099f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Sep 2016 04:20:46 -0300 Subject: [PATCH] fix for no spends in basilisk history API --- basilisk/basilisk_bitcoin.c | 56 ++++++++++++++++++------------------- iguana/iguana_unspents.c | 43 +--------------------------- 2 files changed, 28 insertions(+), 71 deletions(-) diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index 159e972c1..dae74758b 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -932,7 +932,7 @@ int32_t basilisk_unspentfind(struct supernet_info *myinfo,struct iguana_info *co struct basilisk_spend *basilisk_addspend(struct supernet_info *myinfo,char *symbol,bits256 txid,uint16_t vout,int32_t addflag) { - int32_t i; struct basilisk_spend *s; + int32_t i=0; struct basilisk_spend *s; // mutex if ( myinfo->numspends > 0 ) { @@ -947,9 +947,9 @@ struct basilisk_spend *basilisk_addspend(struct supernet_info *myinfo,char *symb } if ( addflag != 0 && i == myinfo->numspends ) { - printf("realloc spends.[%d] %p\n",myinfo->numspends,myinfo->spends); + //printf("realloc spends.[%d] %p\n",myinfo->numspends,myinfo->spends); myinfo->spends = realloc(myinfo->spends,sizeof(*myinfo->spends) * (myinfo->numspends+1)); - printf("allocated spends.[%d] %p\n",myinfo->numspends+1,myinfo->spends); + //printf("allocated spends.[%d] %p\n",myinfo->numspends+1,myinfo->spends); s = &myinfo->spends[myinfo->numspends++]; memset(s,0,sizeof(*s)); s->txid = txid; @@ -1015,7 +1015,6 @@ void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *co already_spent = spentheight; if ( (bu.spentheight= already_spent) != 0 ) bu.status = 1; - //printf("i.%d n.%d\n",i,n); if ( i == n ) { if ( i >= waddr->maxunspents ) @@ -1025,39 +1024,38 @@ void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *co //printf("allocate max.%d for %s\n",waddr->maxunspents,waddr->coinaddr); } waddr->numunspents++; - //printf("new unspent.%s %d script.%p [%d]\n",waddr->coinaddr,waddr->numunspents,bu.script,bu.spendlen); - } - waddr->unspents[i] = bu; - //PREVENT DOUBLE SPENDS!!! and use p2sh - if ( i == n && bu.spentheight != 0 && (dest= jobj(item,"dest")) != 0 ) - { - struct basilisk_spend *s; - //{"txid":"cd4fb72f871d481c534f15d7f639883958936d49e965f58276f0925798e762df","vin":1,"height":,"unspentheight":,"relays":2}}, - if ( (s= basilisk_addspend(myinfo,coin->symbol,bu.txid,bu.vout,1)) != 0 ) + //printf("new unspent.%s %d script.%p [%d] (%s)\n",waddr->coinaddr,waddr->numunspents,bu.script,bu.spendlen,jprint(item,0)); + if ( bu.spentheight != 0 && (dest= jobj(item,"dest")) != 0 ) { - s->spentfrom = jbits256(dest,"spentfrom"); - s->vini = jint(dest,"vin"); - s->height = bu.spentheight; - s->timestamp = juint(dest,"timestamp"); - s->unspentheight = bu.height; - s->relaymask = bu.relaymask; - ratio = jdouble(dest,"ratio"); - if ( (vouts= jobj(dest,"vouts")) != 0 && (m= cJSON_GetArraySize(vouts)) > 0 ) + struct basilisk_spend *s; + //{"txid":"cd4fb72f871d481c534f15d7f639883958936d49e965f58276f0925798e762df","vin":1,"height":,"unspentheight":,"relays":2}}, + if ( (s= basilisk_addspend(myinfo,coin->symbol,bu.txid,bu.vout,1)) != 0 ) { - for (j=0; jspentfrom = jbits256(dest,"spentfrom"); + s->vini = jint(dest,"vin"); + s->height = bu.spentheight; + s->timestamp = juint(dest,"timestamp"); + s->unspentheight = bu.height; + s->relaymask = bu.relaymask; + ratio = jdouble(dest,"ratio"); + if ( (vouts= jobj(dest,"vouts")) != 0 && (m= cJSON_GetArraySize(vouts)) > 0 ) { - vitem = jitem(vouts,j); - if ( (destaddr= jfieldname(vitem)) != 0 ) + for (j=0; jdestaddr,destaddr,sizeof(s->destaddr)); - s->ismine = (iguana_waddresssearch(myinfo,&wacct,destaddr) != 0); - s->value = jdouble(vitem,jfieldname(vitem)) * SATOSHIDEN; - //printf("(%s %.8f) ",s->destaddr,dstr(s->value)); + vitem = jitem(vouts,j); + if ( (destaddr= jfieldname(vitem)) != 0 ) + { + safecopy(s->destaddr,destaddr,sizeof(s->destaddr)); + s->ismine = (iguana_waddresssearch(myinfo,&wacct,destaddr) != 0); + s->value = jdouble(vitem,jfieldname(vitem)) * SATOSHIDEN; + //printf("(%s %.8f) ",s->destaddr,dstr(s->value)); + } } + //char str[65]; printf("SPEND dest.(%s) ratio %.8f (%s/v%d)\n",jprint(dest,0),ratio,bits256_str(str,s->txid),s->vini); } - //char str[65]; printf("SPEND dest.(%s) ratio %.8f (%s/v%d)\n",jprint(dest,0),ratio,bits256_str(str,s->txid),s->vini); } } + waddr->unspents[i] = bu; } } else printf("waddr.%p script.%p address.%p %s\n",waddr,script,address,address!=0?address:""); } diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index c53054607..88d252043 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -62,48 +62,6 @@ int32_t iguana_RTunspentind2txid(struct supernet_info *myinfo,struct iguana_info else break; } return(-1); - //{"txid":"e34686afc17ec37a8438f0c9a7e48f98d0c625c7917a59c2d7fa22b53d570115","vout":1,"address":"16jsjc1YvzDXqKf7PorMhTyK8ym3ra3uxm","scriptPubKey":"76a9143ef4734c1141725c095342095f6e0e7748b6c16588ac","amount":0.01000000,"timestamp":0,"height":419261,"confirmations":1729,"checkind":4497018,"account":"default","spendable":true,"spent":{"hdrsi":209,"pkind":2459804,"unspentind":4497018,"prevunspentind":0,"satoshis":"1000000","txidind":1726947,"vout":1,"type":2,"fileid":0,"scriptpos":0,"scriptlen":25},"spentheight":419713,"dest":{"spentfrom":"22651e62f248fe2e72053d650f177e4b246ee016605102a40419e603b2bbeac8","vin":0,"timestamp":0,"vouts":[{"1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu":0.00010000}, {"1GQHQ7vwVpGeir2kKrYATsLtrkUQSc7FGY":0.00980000}],"total":0.00990000,"ratio":1}} - /* cJSON *retarray,*item,*uitem,*sitem; char *retstr; int32_t i,n,retval = -1; - *voutp = *spentheightp = -1; - memset(txidp,0,sizeof(*txidp)); - if ( (retstr= bitcoinrpc_listunspent(myinfo,coin,0,0,0,0,0)) != 0 ) - { - if ( (retarray= cJSON_Parse(retstr)) != 0 ) - { - if ( (n= cJSON_GetArraySize(retarray)) > 0 ) - { - for (i=0; ibundles[spentheight/coin->chain->bundlesize]) != 0 && (rdata= bp->ramchain.H.data) != 0 )