|
@ -310,9 +310,8 @@ int32_t basilisk_bitcoinavail(struct iguana_info *coin) |
|
|
else return(0); |
|
|
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;
|
|
|
/* 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(); |
|
|
array = cJSON_CreateArray(); |
|
|
if ( coin != 0 && basilisk_bitcoinavail(coin) != 0 ) |
|
|
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)); |
|
|
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; |
|
|
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; |
|
|
*argsp = 0; |
|
|
|
|
|
txid = jbits256(vals,"txid"); |
|
|
txid = jbits256(vals,"txid"); |
|
|
vout = jint(vals,"vout"); |
|
|
vout = jint(vals,"vout"); |
|
|
coinaddr = jstr(vals,"address"); |
|
|
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 ) |
|
|
if ( (ptr= basilisk_issue(myinfo,hexjson,timeoutmillis,0,1,basilisktag)) != 0 ) |
|
|
{ |
|
|
{ |
|
|
v = &myinfo->basilisks.values[myinfo->basilisks.numvalues++]; |
|
|
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)); |
|
|
safecopy(v->coinaddr,jstr(resultarg,"address"),sizeof(v->coinaddr)); |
|
|
v->value = j64bits(ptr->resultargs[0],"value"); |
|
|
v->value = j64bits(resultarg,"value"); |
|
|
v->txid = jbits256(ptr->resultargs[0],"txid"); |
|
|
v->txid = jbits256(resultarg,"txid"); |
|
|
v->vout = jint(ptr->resultargs[0],"vout"); |
|
|
v->vout = jint(resultarg,"vout"); |
|
|
v->height = jint(ptr->resultargs[0],"height"); |
|
|
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); |
|
|
retstr = basilisk_valuestr(coin,v->coinaddr,v->value,v->height,txid,vout); |
|
|
} |
|
|
} |
|
|
free_json(hexjson); |
|
|
free_json(hexjson); |
|
@ -444,11 +442,17 @@ char *basilisk_bitcoinvalue(struct supernet_info *myinfo,struct iguana_info *coi |
|
|
return(retstr); |
|
|
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 ( 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; |
|
|
spendlen = (int32_t)strlen(spendscriptstr) >> 1; |
|
|
decode_hex(script,spendlen,spendscriptstr); |
|
|
decode_hex(script,spendlen,spendscriptstr); |
|
|
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,rawtx,extraspace,sizeof(extraspace))) != 0 ) |
|
|
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); |
|
|
printf("locktime mismatch %u != %u\n",juint(txobj,"locktime"),locktime); |
|
|
return(-1); |
|
|
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); |
|
|
numaddrs = cJSON_GetArraySize(addresses); |
|
|
for (i=0; i<msgtx.tx_in; i++) |
|
|
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(); |
|
|
argvals = cJSON_CreateObject(); |
|
|
txid = jbits256(argvals,"txid"); |
|
|
txid = jbits256(argvals,"txid"); |
|
|
vout = jint(argvals,"vout"); |
|
|
vout = jint(argvals,"vout"); |
|
|
args = 0; |
|
|
if ( (vret= basilisk_bitcoinvalue(myinfo,coin,remoteaddr,0,10000,argvals)) != 0 ) |
|
|
if ( (vret= basilisk_bitcoinvalue(myinfo,coin,remoteaddr,0,10000,&args,argvals)) != 0 ) |
|
|
|
|
|
{ |
|
|
{ |
|
|
if ( (vretjson= cJSON_Parse(vret)) != 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); |
|
|
free_json(txobj); |
|
|
return(-1); |
|
|
return(-1); |
|
|
} |
|
|
} |
|
|
|
|
|
if ( argvals != 0 ) |
|
|
free_json(argvals); |
|
|
free_json(argvals); |
|
|
if ( args != 0 ) |
|
|
|
|
|
free_json(args); |
|
|
|
|
|
} else printf("cant find spend info.(%s)\n",jprint(vin,0)); |
|
|
} else printf("cant find spend info.(%s)\n",jprint(vin,0)); |
|
|
} |
|
|
} |
|
|
if ( (vouts= jarray(&n,txobj,"vout")) != 0 && n == msgtx.tx_out ) |
|
|
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); |
|
|
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; |
|
|
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; |
|
|
*vinsp = 0; |
|
|
vins = 0; |
|
|
changeaddr = jstr(valsobj,"changeaddr"); |
|
|
changeaddr = jstr(valsobj,"changeaddr"); |
|
|
spendscriptstr = jstr(valsobj,"spendscript"); |
|
|
spendscriptstr = jstr(valsobj,"spendscript"); |
|
|
amount = j64bits(valsobj,"amount"); |
|
|
amount = j64bits(valsobj,"amount"); |
|
@ -578,31 +580,33 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi |
|
|
decode_hex(buf,spendlen,spendscriptstr); |
|
|
decode_hex(buf,spendlen,spendscriptstr); |
|
|
bitcoin_txoutput(coin,txobj,buf,spendlen,amount); |
|
|
bitcoin_txoutput(coin,txobj,buf,spendlen,amount); |
|
|
printf("call calcrawtx\n"); |
|
|
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"); |
|
|
printf("back calcrawtx\n"); |
|
|
} else printf("error creating txobj\n"); |
|
|
} else printf("error creating txobj\n"); |
|
|
} //else rawtx = bitcoin_calcrawtx(myinfo,coin,vinsp,satoshis,spendscriptstr,changeaddr,txfee,addresses,minconf,locktime);
|
|
|
} //else rawtx = bitcoin_calcrawtx(myinfo,coin,vinsp,satoshis,spendscriptstr,changeaddr,txfee,addresses,minconf,locktime);
|
|
|
if ( rawtx != 0 ) |
|
|
if ( rawtx != 0 ) |
|
|
{ |
|
|
{ |
|
|
if ( *vinsp != 0 ) |
|
|
if ( vins != 0 ) |
|
|
{ |
|
|
{ |
|
|
free_json(txobj); |
|
|
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); |
|
|
} else free(rawtx); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if ( txobj != 0 ) |
|
|
if ( txobj != 0 ) |
|
|
free_json(txobj), txobj = 0; |
|
|
free_json(txobj), txobj = 0; |
|
|
if ( *vinsp != 0 ) |
|
|
if ( vins != 0 ) |
|
|
free_json(*vinsp), *vinsp = 0; |
|
|
free_json(vins), vins = 0; |
|
|
if ( addresses != 0 ) |
|
|
if ( addresses != 0 ) |
|
|
{ |
|
|
{ |
|
|
hexjson = cJSON_CreateObject(); |
|
|
hexjson = cJSON_CreateObject(); |
|
|
jaddstr(hexjson,"agent","basilisk"); |
|
|
jaddstr(hexjson,"agent","basilisk"); |
|
|
jaddstr(hexjson,"method","rawtx"); |
|
|
jaddstr(hexjson,"method","rawtx"); |
|
|
jaddstr(hexjson,"activecoin",coin->symbol); |
|
|
jaddstr(hexjson,"activecoin",coin->symbol); |
|
|
if ( valsobj != 0 ) |
|
|
|
|
|
jadd(hexjson,"vals",jduplicate(valsobj)); |
|
|
|
|
|
if ( (ptr= basilisk_issue(myinfo,hexjson,timeoutmillis,0,1,basilisktag)) != 0 ) |
|
|
if ( (ptr= basilisk_issue(myinfo,hexjson,timeoutmillis,0,1,basilisktag)) != 0 ) |
|
|
{ |
|
|
{ |
|
|
for (i=0; i<ptr->numresults; i++) |
|
|
for (i=0; i<ptr->numresults; i++) |
|
@ -611,7 +615,7 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi |
|
|
continue; |
|
|
continue; |
|
|
if ( retstr != 0 && strcmp(ptr->results[i],retstr) == 0 ) |
|
|
if ( retstr != 0 && strcmp(ptr->results[i],retstr) == 0 ) |
|
|
ptr->numexact++; |
|
|
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 ) |
|
|
if ( retstr != 0 ) |
|
|
ptr->numexact = 0; |
|
|
ptr->numexact = 0; |
|
@ -620,7 +624,7 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi |
|
|
besti = i; |
|
|
besti = i; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
retstr = basilisk_finish(ptr,vinsp,besti); |
|
|
retstr = basilisk_finish(ptr,besti); |
|
|
} |
|
|
} |
|
|
free_json(hexjson); |
|
|
free_json(hexjson); |
|
|
} |
|
|
} |
|
|