From 3b972344b00e1bf4367e4d4fa69d5359f0063532 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Apr 2016 01:40:16 -0500 Subject: [PATCH] getreceivedbyaddress RPC --- iguana/iguana_unspents.c | 9 ++++++--- iguana/iguana_wallet.c | 26 ++++++++++++++++++-------- iguana/tests/getreceivedbyaddress | 1 + includes/iguana_apideclares.h | 2 +- 4 files changed, 26 insertions(+), 12 deletions(-) create mode 100755 iguana/tests/getreceivedbyaddress diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index aa0d6d69f..a66f42247 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -2634,14 +2634,17 @@ STRING_ARG(iguana,initfastfind,activecoin) } else return(clonestr("{\"error\":\"no coin to initialize\"}")); } -TWOSTRINGS_AND_INT(iguana,balance,activecoin,address,lastheight) +TWO_STRINGS_AND_TWO_DOUBLES(iguana,balance,activecoin,address,lastheightd,minconfd) { - int32_t minconf=1,maxconf=SATOSHIDEN; int64_t total; uint8_t rmd160[20],pubkey33[33],addrtype; + int32_t lastheight,minconf,maxconf=SATOSHIDEN; int64_t total; uint8_t rmd160[20],pubkey33[33],addrtype; struct iguana_pkhash *P; cJSON *array,*retjson = cJSON_CreateObject(); if ( activecoin != 0 && activecoin[0] != 0 ) coin = iguana_coinfind(activecoin); if ( coin != 0 ) { + if ( (minconf= minconfd) <= 0 ) + minconf = 1; + lastheight = lastheightd; jaddstr(retjson,"address",address); if ( bitcoin_validaddress(coin,address) < 0 ) { @@ -2672,7 +2675,7 @@ TWOSTRINGS_AND_INT(iguana,balance,activecoin,address,lastheight) int64_t iguana_addressreceived(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,cJSON *txids,cJSON *vouts,char *coinaddr,int32_t minconf) { int64_t balance = 0; cJSON *unspentsjson,*balancejson,*item; int32_t i,n; char *balancestr; - if ( (balancestr= iguana_balance(IGUANA_CALLARGS,coin->symbol,coinaddr,-1)) != 0 ) + if ( (balancestr= iguana_balance(IGUANA_CALLARGS,coin->symbol,coinaddr,-1,minconf)) != 0 ) { if ( (balancejson= cJSON_Parse(balancestr)) != 0 ) { diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index b2a31c0c2..89cf6cb2d 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -1226,7 +1226,7 @@ STRING_AND_THREEINTS(bitcoinrpc,listtransactions,account,count,skip,includewatch { vouts = cJSON_CreateArray(); txids = cJSON_CreateArray(); - iguana_addressreceived(myinfo,coin,json,remoteaddr,txids,vouts,coinaddr,1); + iguana_addressreceived(myinfo,coin,0,remoteaddr,txids,vouts,coinaddr,1); if ( (m= cJSON_GetArraySize(txids)) > 0 ) { for (j=0; jcoinaddr); txids = cJSON_CreateArray(); vouts = cJSON_CreateArray(); - jaddnum(item,"amount",dstr(iguana_addressreceived(myinfo,coin,json,remoteaddr,txids,vouts,waddr->coinaddr,minconf))); + jaddnum(item,"amount",dstr(iguana_addressreceived(myinfo,coin,0,remoteaddr,txids,vouts,waddr->coinaddr,minconf))); jadd(item,"txids",txids); jadd(item,"vouts",vouts); jaddi(array,item); @@ -1316,6 +1316,22 @@ THREE_INTS(bitcoinrpc,listreceivedbyaddress,minconf,includeempty,flag) return(jprint(retjson,1)); } +STRING_AND_INT(bitcoinrpc,getreceivedbyaddress,address,minconf) +{ + char *balancestr; cJSON *balancejson,*retjson = cJSON_CreateObject(); + if ( (balancestr= iguana_balance(IGUANA_CALLARGS,coin->symbol,address,-1,minconf)) != 0 ) + { + if ( (balancejson= cJSON_Parse(balancestr)) != 0 ) + { + jaddnum(retjson,"result",dstr(jdouble(balancejson,"balance"))); + free_json(balancejson); + } + } + if ( jobj(retjson,"result") == 0 ) + jaddstr(retjson,"error","couldnt get received by address"); + return(jprint(retjson,1)); +} + TWO_INTS(bitcoinrpc,listaccounts,minconf,includewatchonly) { cJSON *retjson,*array; int64_t balance; struct iguana_waccount *wacct,*tmp; @@ -1338,12 +1354,6 @@ HASH_AND_TWOINTS(bitcoinrpc,listsinceblock,blockhash,target,flag) return(jprint(retjson,1)); } -STRING_AND_INT(bitcoinrpc,getreceivedbyaddress,address,minconf) -{ - cJSON *retjson = cJSON_CreateObject(); - return(jprint(retjson,1)); -} - INT_ARRAY_STRING(bitcoinrpc,createmultisig,M,pubkeys,ignore) { cJSON *retjson,*pkjson,*addresses; uint8_t script[2048],p2sh_rmd160[20]; char pubkeystr[256],msigaddr[64],*pkstr,scriptstr[sizeof(script)*2+1]; struct vin_info V; int32_t i,plen,len,n = cJSON_GetArraySize(pubkeys); diff --git a/iguana/tests/getreceivedbyaddress b/iguana/tests/getreceivedbyaddress new file mode 100755 index 000000000..675193ac3 --- /dev/null +++ b/iguana/tests/getreceivedbyaddress @@ -0,0 +1 @@ +curl --url "http://127.0.0.1:7778" --data "{\"method\":\"getreceivedbyaddress\",\"params\":[\"17outUgtsnLkguDuXm14tcQ7dMbdD8KZGK\"]}" diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 2dfbc2664..8e95baeee 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -97,7 +97,7 @@ TWO_STRINGS(iguana,persistent,activecoin,ipaddr); TWO_STRINGS(iguana,removenode,activecoin,ipaddr); TWO_STRINGS(iguana,oneshot,activecoin,ipaddr); TWO_STRINGS(iguana,nodestatus,activecoin,ipaddr); -TWOSTRINGS_AND_INT(iguana,balance,activecoin,address,height); +TWO_STRINGS_AND_TWO_DOUBLES(iguana,balance,activecoin,address,heightd,minconfd); P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount,destaddress2,destamount2,M,N,pubA,wifA,pubB,wifB,pubC,wifC); STRING_AND_INT(iguana,bundleaddresses,activecoin,height); STRING_AND_INT(iguana,bundlehashes,activecoin,height);