From af841e56e0f1b7ef1c4571728d3716d6c016c2af Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Aug 2017 01:11:19 +0200 Subject: [PATCH] Test --- iguana/exchanges/LP_commands.c | 8 +++++++- iguana/exchanges/LP_scan.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 7af18862c..36706a094 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -120,7 +120,7 @@ getprices(base, rel)\n\ sendmessage(base=coin, rel="", pubkey=zero, )\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 ) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 045d4092e..539570913 100644 --- a/iguana/exchanges/LP_scan.c +++ b/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; httxmutex); + HASH_ITER(hh,coin->transactions,tx,tmp) + { + if ( tx->height < height ) + { + for (i=0; inumvouts; 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;