Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
90111f0553
  1. 55
      basilisk/basilisk.c
  2. 2
      basilisk/basilisk.h
  3. 68
      basilisk/basilisk_bitcoin.c
  4. 2
      basilisk/basilisk_ether.c
  5. 2
      basilisk/basilisk_lisk.c
  6. 2
      basilisk/basilisk_nxt.c
  7. 2
      basilisk/basilisk_waves.c
  8. 2
      iguana/iguana777.h

55
basilisk/basilisk.c

@ -15,7 +15,7 @@
#include "../iguana/iguana777.h"
char *basilisk_finish(struct basilisk_item *ptr,cJSON **argjsonp,int32_t besti)
char *basilisk_finish(struct basilisk_item *ptr,int32_t besti)
{
int32_t i; char *retstr = 0;
for (i=0; i<ptr->numresults; i++)
@ -24,17 +24,9 @@ char *basilisk_finish(struct basilisk_item *ptr,cJSON **argjsonp,int32_t besti)
{
if ( ptr->results[i] != 0 )
free(ptr->results[i]);
if ( ptr->resultargs[i] != 0 )
free_json(ptr->resultargs[i]);
}
else
{
retstr = ptr->results[i];
if ( argjsonp != 0 )
*argjsonp = jduplicate(ptr->resultargs[i]);
}
else retstr = ptr->results[i];
ptr->results[i] = 0;
ptr->resultargs[i] = 0;
}
ptr->finished = (uint32_t)time(NULL);
return(retstr);
@ -60,26 +52,20 @@ cJSON *basilisk_json(struct supernet_info *myinfo,cJSON *hexjson,uint32_t basili
return(retjson);
}
cJSON *basilisk_resultsjson(struct supernet_info *myinfo,char *symbol,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,char *retstr,cJSON *args)
cJSON *basilisk_resultsjson(struct supernet_info *myinfo,char *symbol,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,char *retstr)
{
cJSON *hexjson,*retjson;
if ( remoteaddr != 0 && remoteaddr[0] != 0 )
cJSON *hexjson=0,*retjson=0;
if ( (hexjson= cJSON_Parse(retstr)) != 0 )
{
hexjson = cJSON_CreateObject();
jaddstr(hexjson,"agent","basilisk");
jaddstr(hexjson,"method","result");
jaddstr(hexjson,"hexmsg",retstr);
if ( args != 0 )
jadd(hexjson,"args",jduplicate(args));
retjson = basilisk_json(myinfo,hexjson,basilisktag,timeoutmillis);
free_json(hexjson);
}
else // local request
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",retstr);
if ( args != 0 )
jadd(retjson,"args",jduplicate(args));
if ( remoteaddr != 0 && remoteaddr[0] != 0 )
{
jaddstr(hexjson,"agent","basilisk");
jaddstr(hexjson,"method","result");
retjson = basilisk_json(myinfo,hexjson,basilisktag,timeoutmillis);
free_json(hexjson);
}
else // local request
retjson = hexjson;
}
return(retjson);
}
@ -178,16 +164,16 @@ void basilisk_functions(struct iguana_info *coin)
char *basilisk_issuecmd(basilisk_func func,struct supernet_info *myinfo,char *remoteaddr,uint32_t basilisktag,char *symbol,int32_t timeoutmillis,cJSON *vals)
{
struct iguana_info *coin; char *retstr=0; cJSON *retjson,*args = 0;
struct iguana_info *coin; char *retstr=0; cJSON *retjson;
if ( basilisktag == 0 )
OS_randombytes((uint8_t *)&basilisktag,sizeof(basilisktag));
if ( (coin= iguana_coinfind(symbol)) != 0 )
{
if ( func != 0 )
{
if ( (retstr= (*func)(myinfo,coin,remoteaddr,basilisktag,timeoutmillis,&args,vals)) != 0 )
if ( (retstr= (*func)(myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 )
{
retjson = basilisk_resultsjson(myinfo,symbol,remoteaddr,basilisktag,timeoutmillis,retstr,args);
retjson = basilisk_resultsjson(myinfo,symbol,remoteaddr,basilisktag,timeoutmillis,retstr);
free(retstr);
retstr = jprint(retjson,1);
}
@ -270,11 +256,9 @@ ARRAY_OBJ_INT(basilisk,result,args,vals,basilisktag)
struct basilisk_item *ptr; char *hexmsg=0;
if ( vals != 0 && (hexmsg= jstr(vals,"hexmsg")) != 0 )
{
ptr = calloc(1,sizeof(*ptr) + strlen(hexmsg) + 1);
ptr = calloc(1,sizeof(*ptr));
ptr->results[0] = clonestr(hexmsg);
ptr->basilisktag = basilisktag;
if ( args != 0 )
ptr->resultargs[0] = jduplicate(args);
ptr->numresults = 1;
//printf("Q results hexmsg.(%s) args.(%s)\n",hexmsg,jprint(args,0));
queue_enqueue("resultsQ",&myinfo->basilisks.resultsQ,&ptr->DL,0);
@ -350,7 +334,7 @@ char *basilisk_hexmsg(struct supernet_info *myinfo,struct category_info *cat,voi
if ( strcmp(method,"result") == 0 )
{
//printf("got rawtx.(%s)\n",jstr(valsobj,"hexmsg"));
return(basilisk_result(myinfo,coin,json,remoteaddr,jobj(json,"args"),valsobj,basilisktag));
return(basilisk_result(myinfo,coin,json,remoteaddr,jobj(json,"vals"),valsobj,basilisktag));
}
}
}
@ -387,7 +371,6 @@ void basilisks_loop(void *arg)
if ( (n= pending->numresults) < sizeof(pending->results)/sizeof(*pending->results) )
{
pending->results[n] = ptr->results[0];
pending->resultargs[n] = ptr->resultargs[0];
pending->numresults++;
}
}

2
basilisk/basilisk.h

@ -28,7 +28,7 @@ struct basilisk_item
{
struct queueitem DL; UT_hash_handle hh;
uint32_t submit,finished,basilisktag,numresults,numexact;
char *results[BASILISK_MAXFANOUT]; cJSON *resultargs[BASILISK_MAXFANOUT];
char *results[BASILISK_MAXFANOUT];
};
struct basilisk_info

68
basilisk/basilisk_bitcoin.c

@ -310,9 +310,8 @@ int32_t basilisk_bitcoinavail(struct iguana_info *coin)
else return(0);
}
char *basilisk_bitcoinbalances(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON **argsp,cJSON *vals)
char *basilisk_bitcoinbalances(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *vals)
{
*argsp = 0;
/* cJSON *array=0,*result,*item,*retjson,*hexjson; int32_t i,n,besti=-1; char *coinaddr,*balancestr=0,*retstr=0; int64_t total=0,amount,most=0; struct basilisk_item *ptr;
array = cJSON_CreateArray();
if ( coin != 0 && basilisk_bitcoinavail(coin) != 0 )
@ -391,10 +390,9 @@ char *basilisk_valuestr(struct iguana_info *coin,char *coinaddr,uint64_t value,i
return(jprint(retjson,1));
}
char *basilisk_bitcoinvalue(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON **argsp,cJSON *vals)
char *basilisk_bitcoinvalue(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *vals)
{
int32_t i,height,vout; char *coinaddr,*retstr=0; struct basilisk_value *v; cJSON *hexjson; uint64_t value = 0; struct basilisk_item *ptr; bits256 txid;
*argsp = 0;
int32_t i,height,vout; char *coinaddr,*retstr=0; struct basilisk_value *v; cJSON *hexjson,*resultarg; uint64_t value = 0; struct basilisk_item *ptr; bits256 txid;
txid = jbits256(vals,"txid");
vout = jint(vals,"vout");
coinaddr = jstr(vals,"address");
@ -428,15 +426,15 @@ char *basilisk_bitcoinvalue(struct supernet_info *myinfo,struct iguana_info *coi
if ( (ptr= basilisk_issue(myinfo,hexjson,timeoutmillis,0,1,basilisktag)) != 0 )
{
v = &myinfo->basilisks.values[myinfo->basilisks.numvalues++];
if ( ptr->resultargs[0] != 0 )
if ( (resultarg= cJSON_Parse(ptr->results[0])) != 0 )
{
safecopy(v->coinaddr,jstr(ptr->resultargs[0],"address"),sizeof(v->coinaddr));
v->value = j64bits(ptr->resultargs[0],"value");
v->txid = jbits256(ptr->resultargs[0],"txid");
v->vout = jint(ptr->resultargs[0],"vout");
v->height = jint(ptr->resultargs[0],"height");
safecopy(v->coinaddr,jstr(resultarg,"address"),sizeof(v->coinaddr));
v->value = j64bits(resultarg,"value");
v->txid = jbits256(resultarg,"txid");
v->vout = jint(resultarg,"vout");
v->height = jint(resultarg,"height");
}
basilisk_finish(ptr,argsp,-1);
basilisk_finish(ptr,-1);
retstr = basilisk_valuestr(coin,v->coinaddr,v->value,v->height,txid,vout);
}
free_json(hexjson);
@ -444,11 +442,17 @@ char *basilisk_bitcoinvalue(struct supernet_info *myinfo,struct iguana_info *coi
return(retstr);
}
int64_t basilisk_bitcointxcost(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t locktime,int64_t satoshis,int64_t txfee,cJSON *addresses,char *spendscriptstr,char *changeaddr,char *rawtx,cJSON *vins)
int64_t basilisk_bitcointxcost(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t locktime,int64_t satoshis,int64_t txfee,cJSON *addresses,char *spendscriptstr,char *changeaddr,char *resultstr)
{
cJSON *txobj,*vouts,*vin,*sobj,*addrs,*vretjson,*argvals,*args; int64_t value,change=0,outputsum=0,inputsum=0,spentsatoshis=0,cost = -1; int32_t i,j,m,numaddrs,vout,spendlen,n; struct iguana_msgtx msgtx; uint8_t extraspace[8192],script[IGUANA_MAXSCRIPTSIZE],asmtype; struct vin_info V; char *scriptstr,str[65],*vret; bits256 txid;
cJSON *txobj,*vouts,*vin,*sobj,*addrs,*vretjson,*vins,*argvals,*resultsobj; int64_t value,change=0,outputsum=0,inputsum=0,spentsatoshis=0,cost = -1; int32_t i,j,m,numaddrs,vout,spendlen,n; struct iguana_msgtx msgtx; uint8_t extraspace[8192],script[IGUANA_MAXSCRIPTSIZE],asmtype; struct vin_info V; char *scriptstr,str[65],*vret,*rawtx; bits256 txid;
if ( coin != 0 )
{
if ( (resultsobj= cJSON_Parse(resultstr)) == 0 || (vins= jobj(resultsobj,"vins")) != 0 || (rawtx= jstr(resultsobj,"rawtx")) != 0 )
{
if ( resultsobj != 0 )
free_json(resultsobj);
return(0);
}
spendlen = (int32_t)strlen(spendscriptstr) >> 1;
decode_hex(script,spendlen,spendscriptstr);
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,rawtx,extraspace,sizeof(extraspace))) != 0 )
@ -459,7 +463,7 @@ int64_t basilisk_bitcointxcost(struct supernet_info *myinfo,struct iguana_info *
printf("locktime mismatch %u != %u\n",juint(txobj,"locktime"),locktime);
return(-1);
}
else if ( jobj(txobj,"error") == 0 && vins != 0 && cJSON_GetArraySize(vins) == msgtx.tx_in )
else if ( jobj(txobj,"error") == 0 && cJSON_GetArraySize(vins) == msgtx.tx_in )
{
numaddrs = cJSON_GetArraySize(addresses);
for (i=0; i<msgtx.tx_in; i++)
@ -476,8 +480,7 @@ int64_t basilisk_bitcointxcost(struct supernet_info *myinfo,struct iguana_info *
argvals = cJSON_CreateObject();
txid = jbits256(argvals,"txid");
vout = jint(argvals,"vout");
args = 0;
if ( (vret= basilisk_bitcoinvalue(myinfo,coin,remoteaddr,0,10000,&args,argvals)) != 0 )
if ( (vret= basilisk_bitcoinvalue(myinfo,coin,remoteaddr,0,10000,argvals)) != 0 )
{
if ( (vretjson= cJSON_Parse(vret)) != 0 )
{
@ -505,9 +508,8 @@ int64_t basilisk_bitcointxcost(struct supernet_info *myinfo,struct iguana_info *
free_json(txobj);
return(-1);
}
free_json(argvals);
if ( args != 0 )
free_json(args);
if ( argvals != 0 )
free_json(argvals);
} else printf("cant find spend info.(%s)\n",jprint(vin,0));
}
if ( (vouts= jarray(&n,txobj,"vout")) != 0 && n == msgtx.tx_out )
@ -552,10 +554,10 @@ int64_t basilisk_bitcointxcost(struct supernet_info *myinfo,struct iguana_info *
return(cost);
}
char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON **vinsp,cJSON *valsobj)
char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj)
{
uint8_t buf[IGUANA_MAXSCRIPTSIZE]; int32_t i,minconf,spendlen,besti=-1; cJSON *hexjson,*addresses,*txobj = 0; uint32_t locktime; char *spendscriptstr,*changeaddr,*retstr=0,*rawtx = 0; int64_t amount,txfee,cost,bestcost=-1; struct basilisk_item *ptr;
*vinsp = 0;
uint8_t buf[IGUANA_MAXSCRIPTSIZE]; int32_t i,minconf,spendlen,besti=-1; cJSON *hexjson,*resultobj,*vins,*addresses,*txobj = 0; uint32_t locktime; char *spendscriptstr,*changeaddr,*retstr=0,*rawtx = 0; int64_t amount,txfee,cost,bestcost=-1; struct basilisk_item *ptr;
vins = 0;
changeaddr = jstr(valsobj,"changeaddr");
spendscriptstr = jstr(valsobj,"spendscript");
amount = j64bits(valsobj,"amount");
@ -578,31 +580,33 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
decode_hex(buf,spendlen,spendscriptstr);
bitcoin_txoutput(coin,txobj,buf,spendlen,amount);
printf("call calcrawtx\n");
rawtx = iguana_calcrawtx(myinfo,coin,vinsp,txobj,amount,changeaddr,txfee,addresses,minconf);
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf);
printf("back calcrawtx\n");
} else printf("error creating txobj\n");
} //else rawtx = bitcoin_calcrawtx(myinfo,coin,vinsp,satoshis,spendscriptstr,changeaddr,txfee,addresses,minconf,locktime);
if ( rawtx != 0 )
{
if ( *vinsp != 0 )
if ( vins != 0 )
{
free_json(txobj);
return(jprint(basilisk_resultsjson(myinfo,coin->symbol,remoteaddr,basilisktag,timeoutmillis,rawtx,*vinsp),1));
resultobj = cJSON_CreateObject();
jaddstr(resultobj,"rawtx",rawtx), free(rawtx);
jadd(resultobj,"vins",vins);
retstr = jprint(basilisk_resultsjson(myinfo,coin->symbol,remoteaddr,basilisktag,timeoutmillis,jprint(resultobj,1)),1);
return(retstr);
} else free(rawtx);
}
}
if ( txobj != 0 )
free_json(txobj), txobj = 0;
if ( *vinsp != 0 )
free_json(*vinsp), *vinsp = 0;
if ( vins != 0 )
free_json(vins), vins = 0;
if ( addresses != 0 )
{
hexjson = cJSON_CreateObject();
jaddstr(hexjson,"agent","basilisk");
jaddstr(hexjson,"method","rawtx");
jaddstr(hexjson,"activecoin",coin->symbol);
if ( valsobj != 0 )
jadd(hexjson,"vals",jduplicate(valsobj));
if ( (ptr= basilisk_issue(myinfo,hexjson,timeoutmillis,0,1,basilisktag)) != 0 )
{
for (i=0; i<ptr->numresults; i++)
@ -611,7 +615,7 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
continue;
if ( retstr != 0 && strcmp(ptr->results[i],retstr) == 0 )
ptr->numexact++;
if ( (cost= basilisk_bitcointxcost(myinfo,coin,remoteaddr,locktime,amount,txfee,addresses,spendscriptstr,changeaddr,ptr->results[i],ptr->resultargs[i])) >= 0 && (bestcost == 0 || cost < bestcost) )
if ( (cost= basilisk_bitcointxcost(myinfo,coin,remoteaddr,locktime,amount,txfee,addresses,spendscriptstr,changeaddr,ptr->results[i])) >= 0 && (bestcost == 0 || cost < bestcost) )
{
if ( retstr != 0 )
ptr->numexact = 0;
@ -620,7 +624,7 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
besti = i;
}
}
retstr = basilisk_finish(ptr,vinsp,besti);
retstr = basilisk_finish(ptr,besti);
}
free_json(hexjson);
}

2
basilisk/basilisk_ether.c

@ -34,7 +34,7 @@ char *basilisk_etherrawtx(struct supernet_info *myinfo,struct iguana_info *coin,
jaddstr(hexjson,"agent","basilisk");
jaddstr(hexjson,"method","rawtx");
if ( (ptr= basilisk_issue(myinfo,hexjson,timeoutmillis,0,1,basilisktag)) != 0 )
retstr = basilisk_finish(ptr,vinsp,0);
retstr = basilisk_finish(ptr,0);
free_json(hexjson);
}
return(retstr);

2
basilisk/basilisk_lisk.c

@ -34,7 +34,7 @@ char *basilisk_liskrawtx(struct supernet_info *myinfo,struct iguana_info *coin,c
jaddstr(hexjson,"agent","basilisk");
jaddstr(hexjson,"method","rawtx");
if ( (ptr= basilisk_issue(myinfo,hexjson,timeoutmillis,0,1,basilisktag)) != 0 )
retstr = basilisk_finish(ptr,vinsp,0);
retstr = basilisk_finish(ptr,0);
free_json(hexjson);
}
return(retstr);

2
basilisk/basilisk_nxt.c

@ -34,7 +34,7 @@ char *basilisk_nxtrawtx(struct supernet_info *myinfo,struct iguana_info *coin,ch
jaddstr(hexjson,"agent","basilisk");
jaddstr(hexjson,"method","rawtx");
if ( (ptr= basilisk_issue(myinfo,hexjson,timeoutmillis,0,1,basilisktag)) != 0 )
retstr = basilisk_finish(ptr,vinsp,0);
retstr = basilisk_finish(ptr,0);
free_json(hexjson);
}
return(retstr);

2
basilisk/basilisk_waves.c

@ -34,7 +34,7 @@ char *basilisk_wavesrawtx(struct supernet_info *myinfo,struct iguana_info *coin,
jaddstr(hexjson,"agent","basilisk");
jaddstr(hexjson,"method","rawtx");
if ( (ptr= basilisk_issue(myinfo,hexjson,timeoutmillis,0,1,basilisktag)) != 0 )
retstr = basilisk_finish(ptr,vinsp,0);
retstr = basilisk_finish(ptr,0);
free_json(hexjson);
}
return(retstr);

2
iguana/iguana777.h

@ -495,7 +495,7 @@ struct hhbits256 { UT_hash_handle hh; bits256 txid; int32_t height; uint16_t fir
struct iguana_monitorinfo { bits256 txid; int32_t numreported; uint8_t peerbits[IGUANA_MAXPEERS >> 3]; };
typedef char *(*basilisk_func)(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON **argsp,cJSON *vals);
typedef char *(*basilisk_func)(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *vals);
struct iguana_info
{

Loading…
Cancel
Save