diff --git a/iguana/dPoW.h b/iguana/dPoW.h index b36dcd986..013407cf3 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -175,9 +175,12 @@ char *_dex_getblockhash(struct supernet_info *myinfo,char *symbol,int32_t height char *_dex_getbestblockhash(struct supernet_info *myinfo,char *symbol); char *_dex_sendrawtransaction(struct supernet_info *myinfo,char *symbol,char *signedtx); char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout); +char *_dex_gettxin(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout); char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address); char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *address); char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address); +char *_dex_listspent(struct supernet_info *myinfo,char *symbol,char *address); +char *_dex_getbalance(struct supernet_info *myinfo,char *symbol,char *address); char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *coinaddr,int32_t count,int32_t skip); char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol); int32_t _dex_getheight(struct supernet_info *myinfo,char *symbol); @@ -190,10 +193,16 @@ cJSON *dpow_checkaddress(struct supernet_info *myinfo,struct iguana_info *coin,c void dex_channelsend(struct supernet_info *myinfo,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen); void kmd_bitcoinscan(); +cJSON *kmd_getbalance(struct iguana_info *coin,char *coinaddr); 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); +cJSON *dpow_listspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr); +cJSON *dpow_getbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr); +cJSON *dpow_gettxin(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout); + + #endif diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index a0903c9c8..2a5ed4b1e 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -476,6 +476,14 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d retstr = jprint(retjson,1); } } + else if ( dexreq.func == 'x' ) + { + if ( (retjson= dpow_gettxin(myinfo,coin,dexreq.hash,dexreq.shortarg)) != 0 ) + { + dpow_randipbits(myinfo,coin,retjson); + retstr = jprint(retjson,1); + } + } else if ( dexreq.func == 'H' ) { hash2 = dpow_getblockhash(myinfo,coin,dexreq.intarg); @@ -491,6 +499,14 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d retstr = jprint(retjson,1); } } + else if ( dexreq.func == 'b' ) + { + if ( (retjson= dpow_getbalance(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 ) + { + dpow_randipbits(myinfo,coin,retjson); + retstr = jprint(retjson,1); + } + } else if ( dexreq.func == 'I' ) { if ( (retjson= dpow_getinfo(myinfo,coin)) != 0 ) @@ -527,6 +543,14 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d retstr = jprint(retjson,1); } } + else if ( dexreq.func == 's' ) + { + if ( (retjson= dpow_listspent(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 ) + { + dpow_randipbits(myinfo,coin,retjson); + retstr = jprint(retjson,1); + } + } else if ( dexreq.func == 'P' ) { hash2 = dpow_getbestblockhash(myinfo,coin); @@ -764,6 +788,18 @@ char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32 return(_dex_sendrequest(myinfo,&dexreq,3,"value")); } +char *_dex_gettxin(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout) +{ + struct dex_request dexreq; + //char str[65]; printf("gettxout(%s %s %d)\n",symbol,bits256_str(str,txid),vout); + memset(&dexreq,0,sizeof(dexreq)); + safecopy(dexreq.name,symbol,sizeof(dexreq.name)); + dexreq.hash = txid; + dexreq.shortarg = vout; + dexreq.func = 'x'; + return(_dex_sendrequest(myinfo,&dexreq,3,"value")); +} + char *_dex_kvupdate(struct supernet_info *myinfo,char *symbol,char *key,char *value,int32_t flags) { struct dex_request dexreq; char keyvalue[IGUANA_MAXSCRIPTSIZE]; int32_t keylen,valuesize; @@ -918,7 +954,33 @@ char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address) struct dex_request dexreq; char *retstr; memset(&dexreq,0,sizeof(dexreq)); safecopy(dexreq.name,symbol,sizeof(dexreq.name)); - dexreq.func = 'U'; + dexreq.func = 's'; + if ( (retstr= _dex_sendrequeststr(myinfo,&dexreq,address,0,1,"")) != 0 ) + { + //printf("UNSPENTS.(%s)\n",retstr); + } + return(_dex_arrayreturn(retstr)); +} + +char *_dex_listspent(struct supernet_info *myinfo,char *symbol,char *address) +{ + struct dex_request dexreq; char *retstr; + memset(&dexreq,0,sizeof(dexreq)); + safecopy(dexreq.name,symbol,sizeof(dexreq.name)); + dexreq.func = 's'; + if ( (retstr= _dex_sendrequeststr(myinfo,&dexreq,address,0,1,"")) != 0 ) + { + //printf("UNSPENTS.(%s)\n",retstr); + } + return(_dex_arrayreturn(retstr)); +} + +char *_dex_getbalance(struct supernet_info *myinfo,char *symbol,char *address) +{ + struct dex_request dexreq; char *retstr; + memset(&dexreq,0,sizeof(dexreq)); + safecopy(dexreq.name,symbol,sizeof(dexreq.name)); + dexreq.func = 'b'; if ( (retstr= _dex_sendrequeststr(myinfo,&dexreq,address,0,1,"")) != 0 ) { //printf("UNSPENTS.(%s)\n",retstr); diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index ea148965b..9cb3057e7 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -405,6 +405,36 @@ cJSON *dpow_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,ch return(json); } +cJSON *dpow_listspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr) +{ + if ( myinfo->IAMNOTARY != 0 ) + return(kmd_listspent(coin,coinaddr)); + else + { + return(0); + } +} + +cJSON *dpow_getbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr) +{ + if ( myinfo->IAMNOTARY != 0 ) + return(kmd_getbalance(coin,coinaddr)); + else + { + return(0); + } +} + +cJSON *dpow_gettxin(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout) +{ + if ( myinfo->IAMNOTARY != 0 ) + return(kmd_gettxin(coin,txid,vout)); + else + { + return(0); + } +} + cJSON *dpow_listtransactions(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip) { char buf[128],*retstr; cJSON *json = 0; diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index f96419c6b..d26473e85 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -728,23 +728,32 @@ TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions2,symbol,address,count,skip) 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\":\"dex listspent null symbol, address or coin\"}")); + if ( myinfo->IAMNOTARY != 0 ) + { + if ( symbol != 0 && (coin= iguana_coinfind(symbol)) != 0 ) + return(jprint(kmd_gettxin(coin,txid,vout),1)); + return(clonestr("{\"error\":\"dex listspent null symbol, address or coin\"}")); + } else return(_dex_gettxin(myinfo,symbol,txid,vout)); } 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\":\"dex listspent null symbol, address or coin\"}")); + if ( myinfo->IAMNOTARY != 0 ) + { + if ( symbol != 0 && address != 0 && (coin= iguana_coinfind(symbol)) != 0 ) + return(jprint(kmd_listspent(coin,address),1)); + return(clonestr("{\"error\":\"dex listspent null symbol, address or coin\"}")); + } else return(_dex_listspent(myinfo,symbol,address)); } TWO_STRINGS(dex,getbalance,symbol,address) { - if ( symbol != 0 && address != 0 && (coin= iguana_coinfind(symbol)) != 0 ) - return(jprint(kmd_getbalance(coin,address),1)); - return(clonestr("{\"error\":\"dex getbalance null symbol, address or coin\"}")); + if ( myinfo->IAMNOTARY != 0 ) + { + if ( symbol != 0 && address != 0 && (coin= iguana_coinfind(symbol)) != 0 ) + return(jprint(kmd_getbalance(coin,address),1)); + return(clonestr("{\"error\":\"dex getbalance null symbol, address or coin\"}")); + } else return(_dex_getbalance(myinfo,symbol,address)); } #include "../includes/iguana_apiundefs.h" diff --git a/iguana/tests/dexgetbalance b/iguana/tests/dexgetbalance index bf11e3524..d0f90e62b 100755 --- a/iguana/tests/dexgetbalance +++ b/iguana/tests/dexgetbalance @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listbalance\",\"address\":\"RU58D7nNLXwD29hgC2MPgtAF458gGxnPYS\",\"symbol\":\"KMD\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"getbalance\",\"address\":\"RU58D7nNLXwD29hgC2MPgtAF458gGxnPYS\",\"symbol\":\"KMD\"}"