diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 2b26bf466..b36dcd986 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -193,5 +193,7 @@ void kmd_bitcoinscan(); struct iguana_info *iguana_coinfind(char *symbol); cJSON *kmd_listtransactions(struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip); cJSON *kmd_listunspent(struct iguana_info *coin,char *coinaddr); +cJSON *kmd_listspent(struct iguana_info *coin,char *coinaddr); +cJSON *kmd_gettxin(struct iguana_info *coin,bits256 txid,int32_t vout); #endif diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index bc42a5dba..17db03c29 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -726,6 +726,20 @@ TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions2,symbol,address,count,skip) return(clonestr("{\"error\":\"listunspent2 null symbol, address or coin\"}")); } +HASH_AND_STRING_AND_INT(dex,gettxin,txid,symbol,vout) +{ + if ( symbol != 0 && (coin= iguana_coinfind(symbol)) != 0 ) + return(jprint(kmd_gettxin(coin,txid,vout),1)); + return(clonestr("{\"error\":\"listspent null symbol, address or coin\"}")); +} + +TWO_STRINGS(dex,listspent,symbol,address) +{ + if ( symbol != 0 && address != 0 && (coin= iguana_coinfind(symbol)) != 0 ) + return(jprint(kmd_listspent(coin,address),1)); + return(clonestr("{\"error\":\"listspent null symbol, address or coin\"}")); +} + #include "../includes/iguana_apiundefs.h" diff --git a/iguana/kmd_lookup.h b/iguana/kmd_lookup.h index 5c71aea1c..60d2984bf 100755 --- a/iguana/kmd_lookup.h +++ b/iguana/kmd_lookup.h @@ -310,23 +310,44 @@ cJSON *kmd_gettxin(struct iguana_info *coin,bits256 txid,int32_t vout) return(cJSON_Parse("{\"error\":\"txid not found\"}")); } -cJSON *kmd_listunspent(struct iguana_info *coin,char *coinaddr) +cJSON *kmd_listaddress(struct iguana_info *coin,char *coinaddr,int32_t mode) { - struct kmd_addresshh *addr; struct kmd_transactionhh *ptr,*spent; uint8_t type_rmd160[21]; int32_t i,height; cJSON *array = cJSON_CreateArray(); + struct kmd_addresshh *addr; struct kmd_transactionhh *ptr,*spent,*prev=0; uint8_t type_rmd160[21]; int32_t i,height; cJSON *array = cJSON_CreateArray(); if ( (height= kmd_height(coin)) > coin->kmd_height+3 ) return(cJSON_Parse("[]")); bitcoin_addr2rmd160(&type_rmd160[0],&type_rmd160[1],coinaddr); if ( (addr= _kmd_address(coin,type_rmd160)) != 0 && (ptr= addr->prev) != 0 && ptr->tx != 0 ) { - for (i=0; inumvouts; i++) + while ( ptr != 0 ) { - if ( memcmp(ptr->tx->vouts[i].type_rmd160,type_rmd160,21) == 0 && (spent= ptr->ptrs[(i<<1)+1]) == 0 ) - jaddi(array,kmd_unspentjson(ptr->tx,i)); + prev = 0; + for (i=0; inumvouts; i++) + { + if ( memcmp(ptr->tx->vouts[i].type_rmd160,type_rmd160,21) == 0 ) + { + spent = ptr->ptrs[(i<<1) + 1]; + if ( (mode == 0 && spent == 0) || (mode == 1 && spent != 0) ) + jaddi(array,kmd_unspentjson(ptr->tx,i)); + if ( ptr->ptrs[i<<1] != 0 ) + prev = ptr->ptrs[i<<1]; + } + } + ptr = prev; } } return(array); } +cJSON *kmd_listunspent(struct iguana_info *coin,char *coinaddr) +{ + return(kmd_listaddress(coin,coinaddr,0)); +} + +cJSON *kmd_listspent(struct iguana_info *coin,char *coinaddr) +{ + return(kmd_listaddress(coin,coinaddr,1)); +} + char *kmd_bitcoinblockhashstr(char *coinstr,char *serverport,char *userpass,int32_t height) { char numstr[128],*blockhashstr=0; bits256 hash2; struct iguana_info *coin; @@ -387,7 +408,6 @@ int32_t _kmd_bitcoinscan(struct iguana_info *coin) while ( loadheight < height ) { flag = 0; - printf("load ht.%d\n",loadheight); if ( (blockjson= kmd_blockjson(&h,coin->symbol,coin->chain->serverport,coin->chain->userpass,0,loadheight)) != 0 ) { if ( (txids= jarray(&numtxids,blockjson,"tx")) != 0 ) @@ -420,7 +440,7 @@ int32_t _kmd_bitcoinscan(struct iguana_info *coin) if ( (sobj= jobj(vout,"scriptPubKey")) != 0 && (addresses= jarray(&n,sobj,"addresses")) != 0 ) { kmd_transactionvout(coin,ptr,i,jdouble(vout,"value")*SATOSHIDEN,type_rmd160,zero,-1); - } + } else flag++; } for (i=0; ikmd_height = loadheight++; - if ( flag == 0 || num > 100 ) + if ( flag != 0 || num > 100 ) break; + coin->kmd_height = loadheight++; } return(num); } diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 8b475475d..20386be5b 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -44,6 +44,8 @@ TWO_STRINGS(dex,kvsearch,symbol,key); THREE_STRINGS_AND_THREE_INTS(dex,kvupdate,symbol,key,value,flags,unused,unusedb); TWO_STRINGS(dex,listunspent2,symbol,address); TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions2,symbol,address,count,skip); +HASH_AND_STRING_AND_INT(dex,gettxin,txid,symbol,vout); +TWO_STRINGS(dex,listspent,symbol,address); TWO_STRINGS(zcash,passthru,function,hex); TWO_STRINGS(komodo,passthru,function,hex);