Browse Source

basilisk refresh

etomic
jl777 8 years ago
parent
commit
e30ebf232b
  1. 82
      basilisk/basilisk.c
  2. 2
      iguana/tests/dexgetO
  3. 2
      iguana/tests/refresh
  4. 1
      includes/iguana_apideclares.h

82
basilisk/basilisk.c

@ -1070,4 +1070,86 @@ INT_ARG(iguana,paxfiats,mask)
komodo_assetcoins(1,mask);
return(clonestr("{\"result\":\"success\"}"));
}
int32_t utxocmp(cJSON *utxo,cJSON *utxo2)
{
bits256 txid,txid2; int32_t vout=-1,vout2=-1;
//printf("cmp (%s) vs (%s)\n",jprint(utxo,0),jprint(utxo2,0));
txid = jbits256(utxo,"txid");
vout = jint(utxo,"vout");
txid2 = jbits256(utxo2,"txid");
vout2 = jint(utxo2,"vout");
if ( bits256_cmp(txid,txid2) == 0 && vout == vout2 )
return(0);
else return(-1);
}
TWO_STRINGS(basilisk,refresh,symbol,address)
{
cJSON *array=0,*array2=0,*array3,*item,*item2; char *retstr; int32_t i,j,n,m,vout; bits256 txid;
if ( symbol != 0 && iguana_isnotarychain(symbol) >= 0 && address != 0 && address[0] != 0 )
{
if ( (retstr= _dex_listunspent(myinfo,symbol,address)) != 0 )
{
array = cJSON_Parse(retstr);
free(retstr);
}
if ( (retstr= _dex_listunspent2(myinfo,symbol,address)) != 0 )
{
if ( array == 0 )
array = cJSON_Parse(retstr);
else array2 = cJSON_Parse(retstr);
free(retstr);
}
if ( array != 0 && array2 != 0 ) // merge
{
m = cJSON_GetArraySize(array2);
array3 = jduplicate(array);
n = cJSON_GetArraySize(array3);
//printf("MERGE %s and %s\n",jprint(array,0),jprint(array2,0));
for (j=0; j<m; j++)
{
item2 = jitem(array2,j);
for (i=0; i<n; i++)
if ( utxocmp(jitem(array,i),item2) == 0 )
break;
if ( i == n )
{
printf("FOUND NEW %s\n",jprint(item2,0));
jaddi(array3,jduplicate(item2));
}
}
free_json(array);
free_json(array2), array2 = 0;
array = array3, array3 = 0;
}
if ( array != 0 ) // gettxout
{
n = cJSON_GetArraySize(array);
array3 = cJSON_CreateArray();
for (i=0; i<n; i++)
{
item = jitem(array,i);
txid = jbits256(item,"txid");
vout = jint(item,"vout");
if ( (retstr= _dex_gettxout(myinfo,symbol,txid,vout)) != 0 )
{
if ( (item2= cJSON_Parse(retstr)) != 0 )
{
if ( jdouble(item2,"value") > 0 )
{
//printf("%s, ",jprint(item2,0));
jaddi(array3,item2);
}
else free_json(item2);
}
free(retstr);
}
}
free_json(array);
return(jprint(array3,1));
} else return(clonestr("[]"));
}
return(clonestr("{\"error\":\"invalid coin or address specified\"}"));
}
#include "../includes/iguana_apiundefs.h"

2
iguana/tests/dexgetO

@ -1,2 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"gettxout\",\"vout\":0,\"txid\":\"cad09f4c3e23ef4cde4980cc0e2b296943f22cbaac183a30f86f49f7eccfedfd\",\"symbol\":\"BTC\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"gettxout\",\"vout\":1,\"txid\":\"fa3321ed55e8e96ba7221e9cc4bc54b735616649abcc9734bb73f505ee712884\",\"symbol\":\"KMD\"}"

2
iguana/tests/refresh

@ -0,0 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"refresh\",\"symbol\":\"KMD\",\"address\":\"RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc\",\"timeout\":600000}"

1
includes/iguana_apideclares.h

@ -76,6 +76,7 @@ INT_ARG(basilisk,paxfiats,mask);
HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr);
TWO_STRINGS(basilisk,refresh,symbol,address);
HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr);

Loading…
Cancel
Save