From 176d8553a5210c25487b2ec4a174264d774c4b51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Aug 2017 21:03:13 +0200 Subject: [PATCH] Test --- iguana/exchanges/LP_commands.c | 7 +++ iguana/exchanges/LP_scan.c | 110 +++++++++++++++++++++++++++++++-- iguana/exchanges/snapshot | 2 +- 3 files changed, 114 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 13b8d9741..f50c73ab5 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -121,6 +121,7 @@ sendmessage(base=coin, rel="", pubkey=zero, )\n\ getmessages(firsti=0, num=100)\n\ clearmessages(firsti=0, num=100)\n\ snapshot(coin, height)\n\ +dividends(coin, height, )\n\ \"}")); base = jstr(argjson,"base"); @@ -252,6 +253,12 @@ snapshot(coin, height)\n\ return(jprint(LP_snapshot(ptr,juint(argjson,"height")),1)); else return(clonestr("{\"error\":\"cant find coind\"}")); } + else if ( strcmp(method,"dividends") == 0 ) + { + if ( (ptr= LP_coinsearch(coin)) != 0 ) + return(LP_dividends(ptr,juint(argjson,"height"),argjson)); + else return(clonestr("{\"error\":\"cant find coind\"}")); + } 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 4c7af64f5..33afec441 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -309,11 +309,11 @@ cJSON *LP_snapshot(struct iguana_info *coin,int32_t height) { if ( (ht=tx->outpoints[i].spendheight) > 0 && ht < height ) continue; - if ( (ap= _LP_address(coin,tx->outpoints[i].coinaddr)) != 0 ) + if ( tx->outpoints[i].coinaddr[0] != 0 && (ap= _LP_address(coin,tx->outpoints[i].coinaddr)) != 0 ) { balance += tx->outpoints[i].value; ap->balance += tx->outpoints[i].value; - printf("%s/%s %.8f %.8f\n",tx->outpoints[i].coinaddr,ap->coinaddr,dstr(tx->outpoints[i].value),dstr(ap->balance)); + //printf("(%s/%s) %.8f %.8f\n",tx->outpoints[i].coinaddr,ap->coinaddr,dstr(tx->outpoints[i].value),dstr(ap->balance)); } else noaddr_balance += tx->outpoints[i].value; } } @@ -327,8 +327,7 @@ cJSON *LP_snapshot(struct iguana_info *coin,int32_t height) if ( ap->balance != 0 ) { item = cJSON_CreateArray(); - jaddistr(item,ap->coinaddr); - jaddinum(item,dstr(ap->balance)); + jaddnum(item,ap->coinaddr,dstr(ap->balance)); jaddi(array,item); n++; } @@ -340,6 +339,109 @@ cJSON *LP_snapshot(struct iguana_info *coin,int32_t height) return(retjson); } +char *LP_dividends(struct iguana_info *coin,int32_t height,cJSON *argjson) +{ + cJSON *array,*retjson,*item,*child,*exclude=0; int32_t i,j,n,execflag=0,flag,iter,numexcluded=0; char buf[1024],*field,*prefix="",*suffix=""; uint64_t dustsum=0,excluded=0,total=0,dividend=0,value,val,emit=0,dust=0; double ratio = 1.; + if ( (retjson= LP_snapshot(coin,height)) != 0 ) + { + //printf("SNAPSHOT.(%s)\n",retstr); + if ( (array= jarray(&n,retjson,"balances")) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) != 0 ) + { + if ( argjson != 0 ) + { + exclude = jarray(&numexcluded,argjson,"exclude"); + dust = (uint64_t)(jdouble(argjson,"dust") * SATOSHIDEN); + dividend = (uint64_t)(jdouble(argjson,"dividend") * SATOSHIDEN); + if ( jstr(argjson,"prefix") != 0 ) + prefix = jstr(argjson,"prefix"); + if ( jstr(argjson,"suffix") != 0 ) + suffix = jstr(argjson,"suffix"); + execflag = jint(argjson,"system"); + } + for (iter=0; iter<2; iter++) + { + for (i=0; ichild) != 0 ) + { + value = (uint64_t)(child->valuedouble * SATOSHIDEN); + if ( (field= get_cJSON_fieldname(child)) != 0 ) + { + for (j=0; j dust ) + { + sprintf(buf,"%s %s %.8f %s",prefix,field,dstr(val),suffix); + if ( execflag != 0 ) + { + if ( system(buf) != 0 ) + printf("error system.(%s)\n",buf); + } + else printf("%s\n",buf); + emit += val; + } else dustsum += val; + } + } + } + } + if ( iter == 0 ) + { + if ( total > 0 ) + { + if ( dividend == 0 ) + dividend = total; + ratio = (double)dividend / total; + } else break; + } + } + } + free_json(array); + } + free_json(retjson); + retjson = cJSON_CreateObject(); + jaddstr(retjson,"coin",coin->symbol); + jaddnum(retjson,"height",height); + jaddnum(retjson,"total",dstr(total)); + jaddnum(retjson,"excluded",dstr(excluded)); + if ( dust != 0 ) + jaddnum(retjson,"dust",dstr(dust)); + if ( dustsum != 0 ) + jaddnum(retjson,"dustsum",dstr(dustsum)); + jaddnum(retjson,"dividend",dstr(dividend)); + jaddnum(retjson,"dividends",dstr(emit)); + jaddnum(retjson,"ratio",ratio); + if ( execflag != 0 ) + jaddnum(retjson,"system",execflag); + if ( prefix[0] != 0 ) + jaddstr(retjson,"prefix",prefix); + if ( suffix[0] != 0 ) + jaddstr(retjson,"suffix",suffix); + return(jprint(retjson,1)); + } + return(clonestr("{\"error\":\"symbol not found\"}")); +} + int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) { char destaddr[64]; uint64_t value,interest = 0; struct iguana_info *coin; diff --git a/iguana/exchanges/snapshot b/iguana/exchanges/snapshot index 4e88851fd..2b875af59 100755 --- a/iguana/exchanges/snapshot +++ b/iguana/exchanges/snapshot @@ -1,2 +1,2 @@ source userpass -curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"snapshot\",\"coin\":\"KMD\",\"height\":2000}" +curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"snapshot\",\"coin\":\"KMD\",\"height\":$1}"