Browse Source

Test

etomic
jl777 8 years ago
parent
commit
176d8553a5
  1. 7
      iguana/exchanges/LP_commands.c
  2. 110
      iguana/exchanges/LP_scan.c
  3. 2
      iguana/exchanges/snapshot

7
iguana/exchanges/LP_commands.c

@ -121,6 +121,7 @@ sendmessage(base=coin, rel="", pubkey=zero, <argjson method2>)\n\
getmessages(firsti=0, num=100)\n\
clearmessages(firsti=0, num=100)\n\
snapshot(coin, height)\n\
dividends(coin, height, <args>)\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 )

110
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; i<n; i++)
{
flag = 0;
item = jitem(array,i);
if ( (child= item->child) != 0 )
{
value = (uint64_t)(child->valuedouble * SATOSHIDEN);
if ( (field= get_cJSON_fieldname(child)) != 0 )
{
for (j=0; j<numexcluded; j++)
if ( strcmp(field,jstri(exclude,j)) == 0 )
{
flag = 1;
break;
}
}
//printf("(%s %s %.8f) ",jprint(item,0),field,dstr(value));
if ( iter == 0 )
{
if ( flag != 0 )
excluded += value;
else total += value;
}
else
{
if ( flag == 0 )
{
val = ratio * value;
if ( val > 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;

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

Loading…
Cancel
Save