From 0b5923903e6c7879c5b0ed56e0ae38a84f3e8dd6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Feb 2017 10:35:37 +0200 Subject: [PATCH] test --- iguana/iguana_notary.c | 15 ++++++++--- iguana/kmd_lookup.h | 49 +++++++++++++++++++++++++++++------ iguana/tests/dexgetbalance | 2 ++ iguana/tests/dexgettxin | 2 ++ iguana/tests/dexlistspent | 2 ++ includes/iguana_apideclares.h | 1 + 6 files changed, 59 insertions(+), 12 deletions(-) create mode 100755 iguana/tests/dexgetbalance create mode 100755 iguana/tests/dexgettxin create mode 100755 iguana/tests/dexlistspent diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index 17db03c29..f96419c6b 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -710,7 +710,7 @@ TWO_STRINGS(dex,listunspent2,symbol,address) if ( (retjson= kmd_listunspent(coin,address)) != 0 ) return(jprint(retjson,1)); } - return(clonestr("{\"error\":\"listunspent2 null symbol, address or coin\"}")); + return(clonestr("{\"error\":\"dex listunspent2 null symbol, address or coin\"}")); } TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions2,symbol,address,count,skip) @@ -723,21 +723,28 @@ TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions2,symbol,address,count,skip) if ( (retjson= kmd_listtransactions(coin,address,count,skip)) != 0 ) return(jprint(retjson,1)); } - return(clonestr("{\"error\":\"listunspent2 null symbol, address or coin\"}")); + return(clonestr("{\"error\":\"dex 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\"}")); + return(clonestr("{\"error\":\"dex 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\"}")); + return(clonestr("{\"error\":\"dex listspent null symbol, address or coin\"}")); +} + +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\"}")); } #include "../includes/iguana_apiundefs.h" diff --git a/iguana/kmd_lookup.h b/iguana/kmd_lookup.h index 60d2984bf..38770e51c 100755 --- a/iguana/kmd_lookup.h +++ b/iguana/kmd_lookup.h @@ -348,6 +348,36 @@ cJSON *kmd_listspent(struct iguana_info *coin,char *coinaddr) return(kmd_listaddress(coin,coinaddr,1)); } +cJSON *kmd_getbalance(struct iguana_info *coin,char *coinaddr) +{ + cJSON *array,*retjson; int32_t iter; uint64_t spent=0,unspent=0,value; + for (iter=0; iter<2; iter++) + { + if ( (array= kmd_listaddress(coin,coinaddr,iter)) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; isymbol,coin->chain->serverport,coin->chain->userpass,"getrawtransaction",params)) != 0 ) { if ( (txjson= cJSON_Parse(curlstr)) != 0 ) { - txid = jbits256(txjson,"txid"); - if ( kmd_transaction(coin,txid) != 0 ) + if ( bits256_cmp(txid,jbits256(txjson,"txid")) != 0 ) { - printf("already have txid.%s\n",bits256_str(str,txid)); - free_json(txjson); - free(curlstr); + printf("txid mismatch error ht.%d i.%d\n",loadheight,i); continue; } - vouts = jarray(&numvouts,txjson,"vout"); + vouts = jarray(&numvouts,txjson,"vout"); vins = jarray(&numvins,txjson,"vin"); if ( (tx= kmd_transactionalloc(txid,loadheight,jint(txjson,"blocktime"),numvouts)) != 0 ) { @@ -464,7 +497,7 @@ int32_t _kmd_bitcoinscan(struct iguana_info *coin) } free_json(blockjson); } - if ( flag != 0 || num > 100 ) + if ( flag != 0 || num > 1000 ) break; coin->kmd_height = loadheight++; } diff --git a/iguana/tests/dexgetbalance b/iguana/tests/dexgetbalance new file mode 100755 index 000000000..bf11e3524 --- /dev/null +++ b/iguana/tests/dexgetbalance @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listbalance\",\"address\":\"RU58D7nNLXwD29hgC2MPgtAF458gGxnPYS\",\"symbol\":\"KMD\"}" diff --git a/iguana/tests/dexgettxin b/iguana/tests/dexgettxin new file mode 100755 index 000000000..70abbb1db --- /dev/null +++ b/iguana/tests/dexgettxin @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"gettxin\",\"vout\":0,\"txid\":\"cad09f4c3e23ef4cde4980cc0e2b296943f22cbaac183a30f86f49f7eccfedfd\",\"symbol\":\"KMD\"}" diff --git a/iguana/tests/dexlistspent b/iguana/tests/dexlistspent new file mode 100755 index 000000000..9b2a2c3d9 --- /dev/null +++ b/iguana/tests/dexlistspent @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listspent\",\"address\":\"RU58D7nNLXwD29hgC2MPgtAF458gGxnPYS\",\"symbol\":\"KMD\"}" diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 20386be5b..1be32ab77 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -46,6 +46,7 @@ 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(dex,getbalance,symbol,address); TWO_STRINGS(zcash,passthru,function,hex); TWO_STRINGS(komodo,passthru,function,hex);