Browse Source

Test

etomic
jl777 7 years ago
parent
commit
af841e56e0
  1. 8
      iguana/exchanges/LP_commands.c
  2. 32
      iguana/exchanges/LP_scan.c

8
iguana/exchanges/LP_commands.c

@ -120,7 +120,7 @@ getprices(base, rel)\n\
sendmessage(base=coin, rel="", pubkey=zero, <argjson method2>)\n\
getmessages(firsti=0, num=100)\n\
clearmessages(firsti=0, num=100)\n\
trust(pubkey, trust)\n\
snapshot(coin, height)\n\
\"}"));
base = jstr(argjson,"base");
@ -246,6 +246,12 @@ trust(pubkey, trust)\n\
ptr->inactive = (uint32_t)time(NULL);
return(jprint(LP_coinsjson(0),1));
}
else if ( strcmp(method,"snapshot") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
ptr->inactive = (uint32_t)time(NULL);
return(jprint(LP_snapshot(ptr,juint(argjson,"height")),1));
}
if ( LP_isdisabled(coin,0) != 0 )
return(clonestr("{\"error\":\"coin is disabled\"}"));
if ( strcmp(method,"inventory") == 0 )

32
iguana/exchanges/LP_scan.c

@ -18,6 +18,7 @@
// marketmaker
//
struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid)
{
struct LP_transaction *tx;
@ -199,6 +200,37 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height)
else return(-1);
}
cJSON *LP_snapshot(struct iguana_info *coin,int32_t height)
{
struct LP_transaction *tx,*tmp; int32_t i,ht; uint64_t balance=0; cJSON *retjson,*array;
for (ht=1; ht<height; ht++)
if ( LP_blockinit(coin,ht) < 0 )
{
printf("error loading block.%d of %d\n",ht,height);
return(0);
}
portable_mutex_lock(&coin->txmutex);
HASH_ITER(hh,coin->transactions,tx,tmp)
{
if ( tx->height < height )
{
for (i=0; i<tx->numvouts; i++)
{
if ( (ht=tx->outpoints[i].spendheight) > 0 && ht < height )
continue;
balance += tx->outpoints[i].value;
}
}
}
portable_mutex_unlock(&coin->txmutex);
printf("%s balance %.8f at height.%d\n",coin->symbol,dstr(balance),height);
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
jadd(retjson,"balances",array);
jaddnum(retjson,"total",dstr(balance));
return(retjson);
}
int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout)
{
char destaddr[64]; uint64_t value,interest = 0; struct iguana_info *coin;

Loading…
Cancel
Save