diff --git a/iguana/iguana_realtime.c b/iguana/iguana_realtime.c index db14480ba..c750edca8 100755 --- a/iguana/iguana_realtime.c +++ b/iguana/iguana_realtime.c @@ -649,7 +649,7 @@ void iguana_RTunspent(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struc void iguana_RTspend(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_RTtxid *RTptr,struct iguana_block *block,int64_t polarity,uint8_t *script,int32_t scriptlen,bits256 txid,int32_t vini,bits256 prev_hash,int32_t prev_vout) { struct iguana_RTspend *spend; struct iguana_RTtxid *spentRTptr; struct iguana_RTunspent *unspent=0; char str[65],str2[65],coinaddr[64]; uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; uint32_t unspentind; int32_t spendlen,height; uint64_t value; struct iguana_outpoint spentpt; - printf("RTspend %s vini.%d spend.(%s/v%d) %lld\n",bits256_str(str,txid),vini,bits256_str(str2,prev_hash),prev_vout,(long long)polarity); + //printf("RTspend %s vini.%d spend.(%s/v%d) %lld\n",bits256_str(str,txid),vini,bits256_str(str2,prev_hash),prev_vout,(long long)polarity); if ( vini == 0 && bits256_nonz(prev_hash) == 0 && prev_vout < 0 ) return; //fprintf(stderr,"-"); @@ -695,11 +695,13 @@ void iguana_RTspend(struct supernet_info *myinfo,struct iguana_info *coin,struct { int32_t spentheight,lockedflag,RTspentflag; bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); - //printf("found unspentind (%s %.8f).%d spendlen.%d\n",coinaddr,dstr(value),addrtype,spendlen); unspent = iguana_RTunspent_create(rmd160,value,spendscript,spendlen>0?spendlen:0,0,prev_vout); memset(&spentpt,0,sizeof(spentpt)); spentpt.unspentind = unspentind; spentpt.hdrsi = height / coin->chain->bundlesize; + spentpt.value = value; + if ( strcmp(coinaddr,"RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z") == 0 ) + printf("spend old from ht.%d (%s %.8f).%d spendlen.%d\n",RTptr->height,coinaddr,dstr(value),addrtype,spendlen); iguana_RTutxofunc(coin,&spentheight,&lockedflag,spentpt,&RTspentflag,0,RTptr->height); } } diff --git a/iguana/iguana_rpc.c b/iguana/iguana_rpc.c index 2d30cf1c9..404f098e9 100755 --- a/iguana/iguana_rpc.c +++ b/iguana/iguana_rpc.c @@ -1107,7 +1107,7 @@ void iguana_rpcloop(void *args) sock = accept(bindsock,(struct sockaddr *)&cli_addr,&clilen); if ( sock < 0 ) { - //printf("iguana_rpcloop ERROR on accept usock.%d\n",sock); + //printf("iguana_rpcloop ERROR on accept usock.%d errno %d %s\n",sock,errno,strerror(errno)); continue; } memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits)); diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index a05e7901d..89051efdc 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -402,7 +402,7 @@ int32_t iguana_RTscanunspents(struct supernet_info *myinfo,struct iguana_info *c { if ( unspent->spend == 0 ) { - spentheight = unspent->height; + spentheight = 0; memset(&outpt,0,sizeof(outpt)); memset(&txid,0,sizeof(txid)); if ( (parent= unspent->parent) != 0 ) diff --git a/iguana/iguana_volatiles.c b/iguana/iguana_volatiles.c index d03e592e6..6bc35fa92 100755 --- a/iguana/iguana_volatiles.c +++ b/iguana/iguana_volatiles.c @@ -162,14 +162,16 @@ int32_t iguana_RTutxofunc(struct iguana_info *coin,int32_t *fromheightp,int32_t if ( (rdata= ramchain->H.data) == 0 ) return(1); val = ((uint64_t)spentpt.hdrsi << 32) | spentpt.unspentind; - if ( (utxo.fromheight= fromheight) != 0 ) - utxo.spentflag = 1; + if ( fromheight != 0 ) + utxo.fromheight = fromheight, utxo.spentflag = 1; if ( spentpt.unspentind > 0 && spentpt.unspentind < rdata->numunspents ) { if ( ramchain->Uextras != 0 ) { utxo = ramchain->Uextras[spentpt.unspentind]; - if ( lockflag != 0 ) + if ( fromheight != 0 ) + utxo.fromheight = fromheight, utxo.spentflag = 1; + if ( lockflag != 0 || fromheight != 0 ) { if ( (hhutxo= iguana_hhutxofind(coin,val)) == 0 ) { @@ -178,13 +180,20 @@ int32_t iguana_RTutxofunc(struct iguana_info *coin,int32_t *fromheightp,int32_t hhutxo->u = utxo; HASH_ADD_KEYPTR(hh,coin->utxotable,&hhutxo->uval,sizeof(hhutxo->uval),hhutxo); } - printf("iguana_utxofind: need to change to new RT lock method\n"); + //printf("iguana_utxofind: need to change to new RT lock method\n"); } } if ( ramchain->Uextras == 0 || utxo.spentflag == 0 ) { if ( (hhutxo= iguana_hhutxofind(coin,val)) != 0 ) + { utxo = hhutxo->u; + if ( fromheight != 0 ) + { + utxo.fromheight = fromheight, utxo.spentflag = 1; + hhutxo->u = utxo; + } + } //printf("iguana_utxofind: need to change to new RT method\n"); } } @@ -207,7 +216,7 @@ int32_t iguana_RTutxofunc(struct iguana_info *coin,int32_t *fromheightp,int32_t int32_t iguana_RTspentflag(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *RTspendp,int32_t *spentheightp,struct iguana_ramchain *ramchain,struct iguana_outpoint spentpt,int32_t height,int32_t minconf,int32_t maxconf,uint64_t amount) { - uint32_t numunspents; int32_t RTspentflag,spentflag,lockedflag,fromheight; uint64_t confs;//,RTspend = 0; + uint32_t numunspents; int32_t RTspentflag,spentflag,lockedflag,fromheight=0; uint64_t confs;//,RTspend = 0; struct iguana_ramchaindata *rdata; struct iguana_RTunspent *unspent; *spentheightp = -1; if ( coin->disableUTXO != 0 ) @@ -219,6 +228,7 @@ int32_t iguana_RTspentflag(struct supernet_info *myinfo,struct iguana_info *coin { if ( (unspent= spentpt.ptr) != 0 ) { + *spentheightp = unspent->fromheight; if ( unspent->spend != 0 ) { *RTspendp += (amount == 0) ? coin->txfee : amount; diff --git a/iguana/ramchain_api.c b/iguana/ramchain_api.c index 5db58b16d..fc78ca067 100755 --- a/iguana/ramchain_api.c +++ b/iguana/ramchain_api.c @@ -51,7 +51,7 @@ TWO_STRINGS_AND_TWO_DOUBLES(iguana,balance,activecoin,address,lastheightd,mincon P = calloc(coin->bundlescount,sizeof(*P)); array = cJSON_CreateArray(); //printf("Start %s balance.(%s) height.%d\n",coin->symbol,address,lastheight); - if ( lastheight == 0 ) + if ( lastheight <= 0 ) lastheight = IGUANA_MAXHEIGHT; iguana_RTpkhasharray(myinfo,coin,array,minconf,maxconf,&total,P,coin->bundlescount,rmd160,address,pubkey33,lastheight,0,0,0,remoteaddr,1); free(P); diff --git a/iguana/tests/backupwallet b/iguana/tests/backupwallet index 8b0222eb7..32645108d 100755 --- a/iguana/tests/backupwallet +++ b/iguana/tests/backupwallet @@ -1 +1 @@ -curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"method\":\"backupwallet\",\"params\":[\"testwallet\"]}" +curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"backupwallet\",\"params\":[\"testwallet\"]}" diff --git a/iguana/tests/decoderawtransaction b/iguana/tests/decoderawtransaction index f52a76c07..c5c8564da 100755 --- a/iguana/tests/decoderawtransaction +++ b/iguana/tests/decoderawtransaction @@ -1 +1 @@ -curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"decoderawtransaction\",\"params\":[\"010000004831cd5701af9e98186fa255729e89a0c7670ff1d9b99ae2bd10b6cc31f55864dd99a2ca00010000006a473044022057cd04e3948a8b92cab4524e2a78ae7ff470d00d654a6c36086d07ca8afa65dd022074c7eb31998b204725d4b2ce6f756a477e5e27d59285479b7c9c8dfd095eca8a012102743d2afdb88ede68fb5938e961b1f41c2b6267b3286516543eb4e4ab87ad0d0affffffff02c0d40100000000001976a9145da2ae69885741a6946e01ad8aa8b5312eed856088ac6059e50b000000001976a9142f4c0f91fc06ac228c120aee41741d0d3909683288ac00000000\", 1]}" +curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"decoderawtransaction\",\"params\":[\"01000000be1fce570100bb9d831c71b011f7f931ed4c6cb8251a95c13828ed5fc0ba96670bacec918001000000fd0000ffffffff02bcf60100000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac04a8e405000000001976a914c210f6711e98fe9971757ede2b2dcb0507f3f25e88ac00000000\", 1]}"