Browse Source

test

etomic
jl777 8 years ago
parent
commit
0b5923903e
  1. 15
      iguana/iguana_notary.c
  2. 47
      iguana/kmd_lookup.h
  3. 2
      iguana/tests/dexgetbalance
  4. 2
      iguana/tests/dexgettxin
  5. 2
      iguana/tests/dexlistspent
  6. 1
      includes/iguana_apideclares.h

15
iguana/iguana_notary.c

@ -710,7 +710,7 @@ TWO_STRINGS(dex,listunspent2,symbol,address)
if ( (retjson= kmd_listunspent(coin,address)) != 0 ) if ( (retjson= kmd_listunspent(coin,address)) != 0 )
return(jprint(retjson,1)); 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) 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 ) if ( (retjson= kmd_listtransactions(coin,address,count,skip)) != 0 )
return(jprint(retjson,1)); 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) HASH_AND_STRING_AND_INT(dex,gettxin,txid,symbol,vout)
{ {
if ( symbol != 0 && (coin= iguana_coinfind(symbol)) != 0 ) if ( symbol != 0 && (coin= iguana_coinfind(symbol)) != 0 )
return(jprint(kmd_gettxin(coin,txid,vout),1)); 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) TWO_STRINGS(dex,listspent,symbol,address)
{ {
if ( symbol != 0 && address != 0 && (coin= iguana_coinfind(symbol)) != 0 ) if ( symbol != 0 && address != 0 && (coin= iguana_coinfind(symbol)) != 0 )
return(jprint(kmd_listspent(coin,address),1)); 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" #include "../includes/iguana_apiundefs.h"

47
iguana/kmd_lookup.h

@ -348,6 +348,36 @@ cJSON *kmd_listspent(struct iguana_info *coin,char *coinaddr)
return(kmd_listaddress(coin,coinaddr,1)); 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; i<n; i++)
{
item = jarray(array,i);
if ( (value= jdouble(item,"amount")*SATOSHIDEN) != 0 || (value= jdouble(item,"value")*SATOSHIDEN) != 0 )
{
if ( iter == 0 )
unspent += value;
else spent += value;
}
}
}
}
}
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddnum(retjson,"unspents",dstr(unspent));
jaddnum(retjson,"spents",dstr(spent));
jaddnum(retjson,"balance",dstr(unspent - spent));
return(retjson);
}
char *kmd_bitcoinblockhashstr(char *coinstr,char *serverport,char *userpass,int32_t height) char *kmd_bitcoinblockhashstr(char *coinstr,char *serverport,char *userpass,int32_t height)
{ {
char numstr[128],*blockhashstr=0; bits256 hash2; struct iguana_info *coin; char numstr[128],*blockhashstr=0; bits256 hash2; struct iguana_info *coin;
@ -415,17 +445,20 @@ int32_t _kmd_bitcoinscan(struct iguana_info *coin)
for (i=0; i<numtxids; i++) for (i=0; i<numtxids; i++)
{ {
memset(&zero,0,sizeof(zero)); memset(&zero,0,sizeof(zero));
sprintf(params,"[\"%s\", 1]",bits256_str(str,jbits256(jitem(txids,i),0))); txid = jbits256(jitem(txids,i),0);
if ( kmd_transaction(coin,txid) != 0 )
{
printf("already have txid.%s\n",bits256_str(str,txid));
continue;
}
sprintf(params,"[\"%s\", 1]",bits256_str(str,txid));
if ( (curlstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getrawtransaction",params)) != 0 ) if ( (curlstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getrawtransaction",params)) != 0 )
{ {
if ( (txjson= cJSON_Parse(curlstr)) != 0 ) if ( (txjson= cJSON_Parse(curlstr)) != 0 )
{ {
txid = jbits256(txjson,"txid"); if ( bits256_cmp(txid,jbits256(txjson,"txid")) != 0 )
if ( kmd_transaction(coin,txid) != 0 )
{ {
printf("already have txid.%s\n",bits256_str(str,txid)); printf("txid mismatch error ht.%d i.%d\n",loadheight,i);
free_json(txjson);
free(curlstr);
continue; continue;
} }
vouts = jarray(&numvouts,txjson,"vout"); vouts = jarray(&numvouts,txjson,"vout");
@ -464,7 +497,7 @@ int32_t _kmd_bitcoinscan(struct iguana_info *coin)
} }
free_json(blockjson); free_json(blockjson);
} }
if ( flag != 0 || num > 100 ) if ( flag != 0 || num > 1000 )
break; break;
coin->kmd_height = loadheight++; coin->kmd_height = loadheight++;
} }

2
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\"}"

2
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\"}"

2
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\"}"

1
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); TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions2,symbol,address,count,skip);
HASH_AND_STRING_AND_INT(dex,gettxin,txid,symbol,vout); HASH_AND_STRING_AND_INT(dex,gettxin,txid,symbol,vout);
TWO_STRINGS(dex,listspent,symbol,address); TWO_STRINGS(dex,listspent,symbol,address);
TWO_STRINGS(dex,getbalance,symbol,address);
TWO_STRINGS(zcash,passthru,function,hex); TWO_STRINGS(zcash,passthru,function,hex);
TWO_STRINGS(komodo,passthru,function,hex); TWO_STRINGS(komodo,passthru,function,hex);

Loading…
Cancel
Save