Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
b94acc246c
  1. 148
      basilisk/basilisk.c
  2. 2
      basilisk/basilisk.h
  3. 140
      basilisk/basilisk_bitcoin.c
  4. 36
      deprecated/obsolete.h
  5. 6
      iguana/iguana777.h
  6. 23
      iguana/iguana_payments.c
  7. 12
      iguana/swaps/iguana_BTCswap.c
  8. 6
      includes/iguana_apideclares.h

148
basilisk/basilisk.c

@ -60,6 +60,30 @@ cJSON *basilisk_json(struct supernet_info *myinfo,cJSON *hexjson,uint32_t basili
return(retjson); return(retjson);
} }
cJSON *basilisk_resultsjson(struct supernet_info *myinfo,char *symbol,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,char *retstr,cJSON *args)
{
cJSON *hexjson,*retjson;
if ( remoteaddr != 0 && remoteaddr[0] != 0 )
{
hexjson = cJSON_CreateObject();
jaddstr(hexjson,"agent","basilisk");
jaddstr(hexjson,"method","result");
jaddstr(hexjson,"hexmsg",retstr);
if ( args != 0 )
jadd(hexjson,"args",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",args);
}
return(retjson);
}
#include "basilisk_bitcoin.c" #include "basilisk_bitcoin.c"
#include "basilisk_nxt.c" #include "basilisk_nxt.c"
#include "basilisk_ether.c" #include "basilisk_ether.c"
@ -152,40 +176,24 @@ void basilisk_functions(struct iguana_info *coin)
} }
} }
char *basilisk_issuerawtx(struct supernet_info *myinfo,char *remoteaddr,uint32_t basilisktag,char *symbol,cJSON **vinsp,uint32_t locktime,uint64_t satoshis,char *spendscriptstr,char *changeaddr,int64_t txfee,int32_t minconf,cJSON *addresses,int32_t timeout) 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 *rawtx=0; struct iguana_info *coin; char *retstr=0; cJSON *retjson,*args = 0;
*vinsp = 0; if ( basilisktag == 0 )
OS_randombytes((uint8_t *)&basilisktag,sizeof(basilisktag));
if ( (coin= iguana_coinfind(symbol)) != 0 ) if ( (coin= iguana_coinfind(symbol)) != 0 )
{ {
if ( coin->basilisk_rawtx != 0 ) if ( func != 0 )
rawtx = (*coin->basilisk_rawtx)(myinfo,coin,remoteaddr,basilisktag,vinsp,locktime,satoshis,changeaddr,txfee,addresses,minconf,spendscriptstr,timeout);
}
return(rawtx);
}
int64_t basilisk_issuebalances(struct supernet_info *myinfo,char *remoteaddr,int32_t basilisktag,char *symbol,cJSON **argsp,int32_t lastheight,int32_t minconf,cJSON *addresses,int32_t timeout)
{ {
struct iguana_info *coin; int64_t balance = 0; if ( (retstr= (*func)(myinfo,coin,remoteaddr,basilisktag,timeoutmillis,&args,vals)) != 0 )
*argsp = 0;
if ( (coin= iguana_coinfind(symbol)) != 0 )
{ {
if ( coin->basilisk_balances != 0 ) retjson = basilisk_resultsjson(myinfo,symbol,remoteaddr,basilisktag,timeoutmillis,retstr,args);
balance = (*coin->basilisk_balances)(myinfo,coin,remoteaddr,basilisktag,argsp,lastheight,minconf,addresses,timeout); free(retstr);
retstr = jprint(retjson,1);
} }
return(balance);
} }
int64_t basilisk_issuevalue(struct supernet_info *myinfo,char *remoteaddr,int32_t basilisktag,char *symbol,cJSON **argsp,bits256 txid,int16_t vout,char *coinaddr,int32_t timeout)
{
struct iguana_info *coin; int64_t value = 0;
*argsp = 0;
if ( (coin= iguana_coinfind(symbol)) != 0 )
{
if ( coin->basilisk_value != 0 )
value = (*coin->basilisk_value)(myinfo,coin,remoteaddr,basilisktag,txid,vout,coinaddr,timeout);
} }
return(value); return(retstr);
} }
#include "../includes/iguana_apidefs.h" #include "../includes/iguana_apidefs.h"
@ -224,11 +232,14 @@ xxx
} else */return(clonestr("{\"error\":\"invalid request for inactive coin\"}")); } else */return(clonestr("{\"error\":\"invalid request for inactive coin\"}"));
} }
STRING_ARRAY_OBJ_STRING(basilisk,rawtx,changeaddr,addresses,vals,spendscriptstr) INT_ARRAY_STRING(basilisk,rawtx,basilisktag,vals,activecoin)
{ {
cJSON *argjson=0,*retjson,*hexjson; char *rawtx=0,*symbol=0; int64_t txfee,satoshis; uint32_t locktime,minconf,basilisktag; int32_t timeout,i,n; cJSON *addresses=0; char *changeaddr,*spendscriptstr; int32_t i,n,timeoutmillis;
//printf("RAWTX changeaddr.%s (%s) remote.(%s)\n",changeaddr==0?"":changeaddr,jprint(json,0),remoteaddr); changeaddr = jstr(vals,"changeaddr");
if ( addresses == 0 || (n= cJSON_GetArraySize(addresses)) <= 0 || changeaddr == 0 || changeaddr[0] == 0 ) spendscriptstr = jstr(vals,"spendscript");
addresses = jarray(&n,vals,"addresses");
timeoutmillis = jint(vals,"timeout");
if ( addresses == 0 || changeaddr == 0 || changeaddr[0] == 0 )
return(clonestr("{\"error\":\"invalid addresses[] or changeaddr\"}")); return(clonestr("{\"error\":\"invalid addresses[] or changeaddr\"}"));
else else
{ {
@ -236,43 +247,22 @@ STRING_ARRAY_OBJ_STRING(basilisk,rawtx,changeaddr,addresses,vals,spendscriptstr)
if ( strcmp(jstri(addresses,i),changeaddr) == 0 ) if ( strcmp(jstri(addresses,i),changeaddr) == 0 )
return(clonestr("{\"error\":\"changeaddr cant be in addresses[]\"}")); return(clonestr("{\"error\":\"changeaddr cant be in addresses[]\"}"));
} }
retjson = cJSON_CreateObject(); if ( spendscriptstr != 0 && spendscriptstr[0] != 0 && activecoin != 0 && activecoin[0] != 0 )
if ( spendscriptstr != 0 && spendscriptstr[0] != 0 && (symbol= jstr(vals,"coin")) != 0 )
{
minconf = juint(vals,"minconf");
locktime = juint(vals,"locktime");
if ( jobj(json,"timeout") != 0 )
timeout = jint(json,"timeout");
else timeout = jint(vals,"timeout");
satoshis = j64bits(vals,"amount");
txfee = j64bits(vals,"txfee");
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
OS_randombytes((uint8_t *)&basilisktag,sizeof(basilisktag));
if ( (rawtx= basilisk_issuerawtx(myinfo,remoteaddr,basilisktag,symbol,&argjson,locktime,satoshis,spendscriptstr,changeaddr,txfee,minconf,addresses,timeout)) != 0 )
{
//printf("return rawtx.(%s) remote.%p symbol.%s\n",rawtx,remoteaddr,symbol);
if ( remoteaddr != 0 && remoteaddr[0] != 0 && (coin= iguana_coinfind(symbol)) != 0 )
{ {
hexjson = cJSON_CreateObject(); return(basilisk_issuecmd(coin->basilisk_rawtx,myinfo,remoteaddr,basilisktag,activecoin,timeoutmillis,vals));
jaddstr(hexjson,"rawtx",rawtx);
jaddstr(hexjson,"agent","basilisk");
jaddstr(hexjson,"method","result");
jaddstr(hexjson,"hexmsg",rawtx);
if ( argjson != 0 )
jadd(hexjson,"args",argjson);
retjson = basilisk_json(myinfo,hexjson,basilisktag,timeout);
free_json(hexjson);
} }
else return(clonestr("{\"error\":\"missing activecoin or spendscript\"}"));
{
jaddstr(retjson,"result",rawtx);
if ( argjson != 0 )
jadd(retjson,"args",argjson);
} }
free(rawtx);
} else jaddstr(retjson,"error","couldnt create rawtx"); INT_ARRAY_STRING(basilisk,value,basilisktag,vals,activecoin)
{
int32_t timeoutmillis;
if ( activecoin != 0 && activecoin[0] != 0 && vals != 0 )
{
timeoutmillis = jint(vals,"timeout");
return(basilisk_issuecmd(coin->basilisk_value,myinfo,remoteaddr,basilisktag,activecoin,timeoutmillis,vals));
} }
return(jprint(retjson,1)); return(clonestr("{\"error\":\"missing activecoin\"}"));
} }
ARRAY_OBJ_INT(basilisk,result,args,vals,basilisktag) ARRAY_OBJ_INT(basilisk,result,args,vals,basilisktag)
@ -298,14 +288,16 @@ ARRAY_OBJ_INT(basilisk,result,args,vals,basilisktag)
char *basilisk_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void *ptr,int32_t len,char *remoteaddr) char *basilisk_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void *ptr,int32_t len,char *remoteaddr)
{ {
char *method="",*agent="",*retstr = 0; int32_t i,j; cJSON *vins,*json,*valsobj; struct iguana_info *coin=0; struct iguana_peer *addr; char *method="",*agent="",*retstr = 0; int32_t i,j,timeoutmillis; cJSON *array,*json,*valsobj; struct iguana_info *coin=0; struct iguana_peer *addr; uint32_t basilisktag;
array = 0;
if ( (json= cJSON_Parse(ptr)) != 0 ) if ( (json= cJSON_Parse(ptr)) != 0 )
{ {
printf("basilisk.(%s)\n",jprint(json,0)); printf("basilisk.(%s)\n",jprint(json,0));
agent = jstr(json,"agent"); agent = jstr(json,"agent");
method = jstr(json,"method"); method = jstr(json,"method");
valsobj = jobj(json,"vals"); timeoutmillis = jint(json,"timeout");
if ( strcmp(agent,"basilisk") == 0 ) basilisktag = juint(json,"basilisktag");
if ( strcmp(agent,"basilisk") == 0 && (valsobj= jobj(json,"vals")) != 0 )
{ {
if ( valsobj != 0 && jobj(valsobj,"coin") != 0 ) if ( valsobj != 0 && jobj(valsobj,"coin") != 0 )
coin = iguana_coinfind(jstr(valsobj,"coin")); coin = iguana_coinfind(jstr(valsobj,"coin"));
@ -315,21 +307,17 @@ char *basilisk_hexmsg(struct supernet_info *myinfo,struct category_info *cat,voi
{ {
if ( coin->RELAYNODE != 0 || coin->VALIDATENODE != 0 ) if ( coin->RELAYNODE != 0 || coin->VALIDATENODE != 0 )
{ {
if ( valsobj != 0 && strcmp(method,"rawtx") == 0 ) if ( strcmp(method,"rawtx") == 0 )
{ {
uint64_t amount = j64bits(valsobj,"amount"); retstr = basilisk_issuecmd(coin->basilisk_rawtx,myinfo,remoteaddr,basilisktag,coin->symbol,timeoutmillis,valsobj);
uint64_t txfee = j64bits(valsobj,"txfee");
int32_t minconf = juint(valsobj,"minconf");
int32_t timeout = juint(valsobj,"timeout");
uint32_t locktime = juint(valsobj,"locktime");
uint32_t basilisktag = juint(valsobj,"basilisktag");
if ( txfee == 0 )
txfee = coin->chain->txfee;
retstr = basilisk_issuerawtx(myinfo,remoteaddr,basilisktag,coin->symbol,&vins,locktime,amount,jstr(json,"spendscriptstr"),jstr(json,"changeaddr"),txfee,minconf,jobj(json,"addresses"),timeout);
} }
else if ( strcmp(method,"balances") == 0 ) else if ( strcmp(method,"balances") == 0 )
{ {
retstr = basilisk_balances(myinfo,coin,json,remoteaddr,juint(json,"lastheight"),jobj(json,"addresses"),jstr(json,"activecoin")); retstr = basilisk_issuecmd(coin->basilisk_balances,myinfo,remoteaddr,basilisktag,coin->symbol,timeoutmillis,valsobj);
}
else if ( strcmp(method,"value") == 0 )
{
retstr = basilisk_issuecmd(coin->basilisk_value,myinfo,remoteaddr,basilisktag,coin->symbol,timeoutmillis,valsobj);
} }
if ( retstr == 0 ) if ( retstr == 0 )
return(0); return(0);
@ -360,9 +348,7 @@ char *basilisk_hexmsg(struct supernet_info *myinfo,struct category_info *cat,voi
if ( strcmp(method,"result") == 0 ) if ( strcmp(method,"result") == 0 )
{ {
//printf("got rawtx.(%s)\n",jstr(valsobj,"hexmsg")); //printf("got rawtx.(%s)\n",jstr(valsobj,"hexmsg"));
if ( jstr(valsobj,"coin") != 0 ) return(basilisk_result(myinfo,coin,json,remoteaddr,jobj(json,"args"),valsobj,basilisktag));
coin = iguana_coinfind(jstr(valsobj,"coin"));
return(basilisk_result(myinfo,coin,json,remoteaddr,jobj(json,"args"),valsobj,juint(json,"basilisktag")));
} }
} }
} }

2
basilisk/basilisk.h

@ -22,7 +22,7 @@
#define BASILISK_MINFANOUT 8 #define BASILISK_MINFANOUT 8
#define BASILISK_MAXFANOUT 64 #define BASILISK_MAXFANOUT 64
struct basilisk_value { bits256 txid; int64_t value; int16_t vout; char coinaddr[64]; }; struct basilisk_value { bits256 txid; int64_t value; int32_t height; int16_t vout; char coinaddr[64]; };
struct basilisk_item struct basilisk_item
{ {

140
basilisk/basilisk_bitcoin.c

@ -310,9 +310,9 @@ int32_t basilisk_bitcoinavail(struct iguana_info *coin)
else return(0); else return(0);
} }
int64_t basilisk_bitcoinbalances(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,cJSON **arrayp,int32_t lastheight,int32_t minconf,cJSON *addresses,int32_t timeoutmillis) char *basilisk_bitcoinbalances(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON **argsp,cJSON *vals)
{ {
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 )
{ {
@ -375,65 +375,91 @@ int64_t basilisk_bitcoinbalances(struct supernet_info *myinfo,struct iguana_info
free_json(hexjson); free_json(hexjson);
} }
*arrayp = array; *arrayp = array;
return(most); return(most);*/
return(0);
}
char *basilisk_valuestr(struct iguana_info *coin,char *coinaddr,uint64_t value,int32_t height,bits256 txid,int16_t vout)
{
cJSON *retjson = cJSON_CreateObject();
jaddnum(retjson,"result",dstr(value));
jadd64bits(retjson,"value",value);
jaddnum(retjson,"height",height);
jaddbits256(retjson,"txid",txid);
jaddnum(retjson,"vout",vout);
return(jprint(retjson,1));
} }
int64_t basilisk_bitcoinvalue(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,bits256 txid,int32_t vout,char *coinaddr,int32_t timeoutmillis) char *basilisk_bitcoinvalue(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON **argsp,cJSON *vals)
{ {
int32_t i,height; struct basilisk_value *v; cJSON *hexjson; uint64_t value = 0; struct basilisk_item *ptr; 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;
if ( coin != 0 && basilisk_bitcoinavail(coin) != 0 ) *argsp = 0;
txid = jbits256(vals,"txid");
vout = jint(vals,"vout");
coinaddr = jstr(vals,"address");
if ( coin != 0 && basilisk_bitcoinavail(coin) != 0 && coinaddr != 0 && coinaddr[0] != 0 )
{ {
if ( coin->VALIDATENODE != 0 || coin->RELAYNODE != 0 ) if ( coin->VALIDATENODE != 0 || coin->RELAYNODE != 0 )
{ {
printf("local check\n");
if ( iguana_unspentindfind(coin,coinaddr,0,0,&value,&height,txid,vout,coin->bundlescount) > 0 ) if ( iguana_unspentindfind(coin,coinaddr,0,0,&value,&height,txid,vout,coin->bundlescount) > 0 )
return(value); return(basilisk_valuestr(coin,coinaddr,value,height,txid,vout));
} //else return(bitcoin_value(coin,txid,vout,coinaddr)); } //else return(bitcoin_value(coin,txid,vout,coinaddr));
printf("have local, but lite node\n");
} }
else else
{ {
printf("Scan basilisks values\n");
if ( (v= myinfo->basilisks.values) != 0 ) if ( (v= myinfo->basilisks.values) != 0 )
{ {
for (i=0; i<myinfo->basilisks.numvalues; i++,v++) for (i=0; i<myinfo->basilisks.numvalues; i++,v++)
{ {
if ( v->vout == vout && bits256_cmp(txid,v->txid) == 0 && strcmp(v->coinaddr,coinaddr) == 0 ) if ( v->vout == vout && bits256_cmp(txid,v->txid) == 0 && strcmp(v->coinaddr,coinaddr) == 0 )
return(v->value); return(basilisk_valuestr(coin,v->coinaddr,v->value,v->height,txid,vout));
} }
} }
hexjson = cJSON_CreateObject(); hexjson = cJSON_CreateObject();
jaddnum(hexjson,"basilisktag",basilisktag); jaddnum(hexjson,"basilisktag",basilisktag);
jaddstr(hexjson,"address",coinaddr);
jaddbits256(hexjson,"txid",txid);
jaddnum(hexjson,"vout",vout);
jaddstr(hexjson,"agent","basilisk"); jaddstr(hexjson,"agent","basilisk");
jaddstr(hexjson,"method","value"); jaddstr(hexjson,"method","value");
if ( vals != 0 )
jadd(hexjson,"vals",vals);
printf("issue.(%s)\n",jprint(hexjson,0));
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++];
strcpy(v->coinaddr,coinaddr); if ( ptr->resultargs[0] != 0 )
v->value = value; {
v->txid = txid; 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");
}
basilisk_finish(ptr,argsp,-1);
retstr = basilisk_valuestr(coin,v->coinaddr,v->value,v->height,txid,vout);
} }
free_json(hexjson); free_json(hexjson);
} }
return(value); 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 *rawtx,cJSON *vins)
{ {
cJSON *txobj,*vouts,*vin,*sobj,*addrs; int64_t change=0,outputsum=0,inputsum=0,spentsatoshis=0,cost = -1; int32_t i,j,m,numaddrs,spendlen,n; struct iguana_msgtx msgtx; uint8_t extraspace[8192],script[IGUANA_MAXSCRIPTSIZE],asmtype; struct vin_info V; char *scriptstr,str[65]; bits256 txid; 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;
if ( coin != 0 ) if ( coin != 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 )
{ {
//printf("GOTTX.(%s)\n",jprint(txobj,0)); printf("GOT VINS.(%s)\n",jprint(vins,0));
if ( juint(txobj,"locktime") != locktime ) if ( juint(txobj,"locktime") != locktime )
{ {
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= jarray(&n,txobj,"vin")) != 0 && cJSON_GetArraySize(vins) == msgtx.tx_in ) else if ( jobj(txobj,"error") == 0 && vins != 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++)
@ -445,19 +471,33 @@ int64_t basilisk_bitcointxcost(struct supernet_info *myinfo,struct iguana_info *
V.spendlen = (int32_t)strlen(scriptstr) >> 1; V.spendlen = (int32_t)strlen(scriptstr) >> 1;
decode_hex(V.spendscript,V.spendlen,scriptstr); decode_hex(V.spendscript,V.spendlen,scriptstr);
asmtype = _iguana_calcrmd160(coin,&V); asmtype = _iguana_calcrmd160(coin,&V);
if ( basilisk_bitcoinvalue(myinfo,coin,remoteaddr,0,msgtx.vins[i].prev_hash,msgtx.vins[i].prev_vout,V.coinaddr,10000) == V.amount ) //if ( asmtype == IGUANA_SCRIPT_76A988AC || asmtype == IGUANA_SCRIPT_AC || asmtype == IGUANA_SCRIPT_76AC || asmtype == IGUANA_SCRIPT_P2SH )
bitcoin_address(V.coinaddr,coin->chain->pubtype,V.rmd160,20);
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 ( (vretjson= cJSON_Parse(vret)) != 0 )
{
if ( (value= j64bits(vretjson,"value")) != 0 )
{ {
inputsum += V.amount; inputsum += value;
for (j=0; j<numaddrs; j++) for (j=0; j<numaddrs; j++)
if ( strcmp(jstri(addresses,j),V.coinaddr) == 0 ) if ( strcmp(jstri(addresses,j),V.coinaddr) == 0 )
break; break;
if ( j == numaddrs ) if ( j == numaddrs )
{ {
printf("spend of invalid input address.(%s)\n",V.coinaddr); printf("spend of invalid input address.(%s) (%s).%d\n",V.coinaddr,scriptstr,asmtype);
free_json(txobj); free_json(txobj);
return(-1); return(-1);
} }
printf("Valid spend %.8f to %s\n",dstr(V.amount),V.coinaddr); printf("Valid spend %.8f to %s\n",dstr(value),V.coinaddr);
}
free_json(vretjson);
}
free(vret);
} }
else else
{ {
@ -465,6 +505,9 @@ int64_t basilisk_bitcointxcost(struct supernet_info *myinfo,struct iguana_info *
free_json(txobj); free_json(txobj);
return(-1); return(-1);
} }
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 )
@ -509,12 +552,20 @@ 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,cJSON **vinsp,uint32_t locktime,uint64_t satoshis,char *changeaddr,uint64_t txfee,cJSON *addresses,int32_t minconf,char *spendscriptstr,int32_t timeoutmillis) char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON **vinsp,cJSON *valsobj)
{ {
uint8_t buf[IGUANA_MAXSCRIPTSIZE]; int32_t i,spendlen,besti=-1; cJSON *hexjson,*retjson,*valsobj,*txobj = 0; char *retstr=0,*rawtx = 0; int64_t cost,bestcost=-1; struct basilisk_item *ptr; 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; changeaddr = jstr(valsobj,"changeaddr");
if ( basilisktag == 0 ) spendscriptstr = jstr(valsobj,"spendscript");
basilisktag = rand(); amount = j64bits(valsobj,"amount");
txfee = j64bits(valsobj,"txfee");
minconf = juint(valsobj,"minconf");
locktime = juint(valsobj,"locktime");
addresses = jobj(valsobj,"addresses");
if ( (txfee= j64bits(valsobj,"txfee")) == 0 )
txfee = 10000;
if ( changeaddr == 0 || changeaddr[0] == 0 || spendscriptstr == 0 || spendscriptstr[0] == 0 || amount == 0 || addresses == 0 )
return(clonestr("{\"error\":\"invalid changeaddr or spendscript or addresses\"}"));
if ( coin != 0 && basilisk_bitcoinavail(coin) != 0 ) if ( coin != 0 && basilisk_bitcoinavail(coin) != 0 )
{ {
if ( coin->VALIDATENODE != 0 || coin->RELAYNODE != 0 ) if ( coin->VALIDATENODE != 0 || coin->RELAYNODE != 0 )
@ -525,8 +576,8 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
{ {
spendlen = (int32_t)strlen(spendscriptstr) >> 1; spendlen = (int32_t)strlen(spendscriptstr) >> 1;
decode_hex(buf,spendlen,spendscriptstr); decode_hex(buf,spendlen,spendscriptstr);
bitcoin_txoutput(coin,txobj,buf,spendlen,satoshis); bitcoin_txoutput(coin,txobj,buf,spendlen,amount);
rawtx = iguana_calcrawtx(myinfo,coin,vinsp,txobj,satoshis,changeaddr,txfee,addresses,minconf); rawtx = iguana_calcrawtx(myinfo,coin,vinsp,txobj,amount,changeaddr,txfee,addresses,minconf);
} 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 )
@ -534,18 +585,7 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
if ( *vinsp != 0 ) if ( *vinsp != 0 )
{ {
free_json(txobj); free_json(txobj);
hexjson = cJSON_CreateObject(); return(jprint(basilisk_resultsjson(myinfo,coin->symbol,remoteaddr,basilisktag,timeoutmillis,rawtx,*vinsp),1));
valsobj = cJSON_CreateObject();
jaddstr(hexjson,"agent","basilisk");
jaddstr(hexjson,"method","result");
jaddstr(valsobj,"hexmsg",rawtx);
jaddstr(valsobj,"coin",coin->symbol);
jadd(hexjson,"vals",valsobj);
jadd(hexjson,"args",*vinsp);
retjson = basilisk_json(myinfo,hexjson,basilisktag,timeoutmillis);
free(rawtx);
free_json(hexjson);
return(jprint(retjson,1));
} else free(rawtx); } else free(rawtx);
} }
} }
@ -553,20 +593,12 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
free_json(txobj); free_json(txobj);
if ( addresses != 0 ) if ( addresses != 0 )
{ {
valsobj = cJSON_CreateObject();
jaddnum(valsobj,"basilisktag",basilisktag);
jaddstr(valsobj,"coin",coin->symbol);
jadd64bits(valsobj,"amount",satoshis);
jadd64bits(valsobj,"txfee",txfee);
jaddnum(valsobj,"minconf",minconf);
jaddnum(valsobj,"locktime",locktime);
hexjson = cJSON_CreateObject(); hexjson = cJSON_CreateObject();
jaddstr(hexjson,"changeaddr",changeaddr); jaddnum(hexjson,"basilisktag",basilisktag);
jaddstr(hexjson,"spendscriptstr",spendscriptstr);
jadd(hexjson,"addresses",jduplicate(addresses));
jadd(hexjson,"vals",valsobj);
jaddstr(hexjson,"agent","basilisk"); jaddstr(hexjson,"agent","basilisk");
jaddstr(hexjson,"method","rawtx"); jaddstr(hexjson,"method","rawtx");
if ( valsobj != 0 )
jadd(hexjson,"vals",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++)
@ -575,7 +607,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,satoshis,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],ptr->resultargs[i])) >= 0 && (bestcost == 0 || cost < bestcost) )
{ {
if ( retstr != 0 ) if ( retstr != 0 )
ptr->numexact = 0; ptr->numexact = 0;

36
deprecated/obsolete.h

@ -17022,6 +17022,42 @@ len = 0;
instantdex_addevent(s,*n,"BOB_idle","BTCoffer","poll","BTC_waitdeck"); // send deck + Chose instantdex_addevent(s,*n,"BOB_idle","BTCoffer","poll","BTC_waitdeck"); // send deck + Chose
instantdex_addevent(s,*n,"ALICE_idle","BTCoffer","poll","BTC_waitdeck");*/ instantdex_addevent(s,*n,"ALICE_idle","BTCoffer","poll","BTC_waitdeck");*/
char *basilisk_issuebalances(struct supernet_info *myinfo,char *remoteaddr,int32_t basilisktag,char *symbol,int32_t lastheight,int32_t minconf,cJSON *addresses,int32_t timeoutmillis)
{
struct iguana_info *coin; char *retstr = 0; cJSON *retjson,*args = 0;
if ( (coin= iguana_coinfind(symbol)) != 0 )
{
if ( coin->basilisk_balances != 0 )
{
if ( (retstr= (*coin->basilisk_balances)(myinfo,coin,remoteaddr,basilisktag,&args,lastheight,minconf,addresses,timeoutmillis)) != 0 )
{
retjson = basilisk_resultsjson(myinfo,symbol,remoteaddr,basilisktag,timeoutmillis,retstr,args);
free(retstr);
retstr = jprint(retjson,1);
}
}
}
return(retstr);
}
char *basilisk_issuevalue(struct supernet_info *myinfo,char *remoteaddr,uint32_t basilisktag,char *symbol,bits256 txid,int16_t vout,char *coinaddr,int32_t timeoutmillis)
{
struct iguana_info *coin; char *retstr = 0; cJSON *retjson,*args = 0;
if ( (coin= iguana_coinfind(symbol)) != 0 )
{
if ( coin->basilisk_value != 0 )
{
if ( (retstr= (*coin->basilisk_value)(myinfo,coin,remoteaddr,basilisktag,&args,txid,vout,coinaddr,timeoutmillis)) != 0 )
{
retjson = basilisk_resultsjson(myinfo,symbol,remoteaddr,basilisktag,timeoutmillis,retstr,args);
free(retstr);
retstr = jprint(retjson,1);
}
}
}
return(retstr);
}
#endif #endif
#endif #endif

6
iguana/iguana777.h

@ -495,13 +495,13 @@ 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]; }; 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);
struct iguana_info struct iguana_info
{ {
char name[64],symbol[8],protocol,statusstr[512],scriptsfname[2][512]; char name[64],symbol[8],protocol,statusstr[512],scriptsfname[2][512];
struct iguana_peers peers; struct iguana_peer internaladdr; struct iguana_peers peers; struct iguana_peer internaladdr;
char *(*basilisk_rawtx)(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,cJSON **vinsp,uint32_t locktime,uint64_t satoshis,char *changeaddr,uint64_t txfee,cJSON *addresses,int32_t minconf,char *spendscriptstr,int32_t timeoutmillis); basilisk_func basilisk_rawtx,basilisk_balances,basilisk_value;
int64_t (*basilisk_balances)(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,cJSON **arrayp,int32_t lastheight,int32_t minconf,cJSON *addresses,int32_t timeoutmillis);
int64_t (*basilisk_value)(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,bits256 txid,int32_t vout,char *coinaddr,int32_t timeoutmillis);
uint32_t fastfind; FILE *fastfps[0x100]; uint8_t *fast[0x100]; int32_t *fasttables[0x100]; long fastsizes[0x100]; uint32_t fastfind; FILE *fastfps[0x100]; uint8_t *fast[0x100]; int32_t *fasttables[0x100]; long fastsizes[0x100];
uint64_t instance_nonce,myservices,totalsize,totalrecv,totalpackets,sleeptime; uint64_t instance_nonce,myservices,totalsize,totalrecv,totalpackets,sleeptime;

23
iguana/iguana_payments.c

@ -382,7 +382,7 @@ void iguana_unspentslock(struct supernet_info *myinfo,struct iguana_info *coin,c
char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *coinaddr,uint64_t satoshis,uint64_t txfee,char *comment,char *comment2,int32_t minconf,char *account) char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *coinaddr,uint64_t satoshis,uint64_t txfee,char *comment,char *comment2,int32_t minconf,char *account)
{ {
uint8_t addrtype,spendscript[1024],rmd160[20]; int32_t completed; char spendscriptstr[4096],*rawtx=0,*signedtx = 0; bits256 signedtxid,senttxid; cJSON *retjson,*vins,*addresses; uint32_t spendlen,locktime = 0; struct iguana_waddress *waddr; uint8_t addrtype,spendscript[1024],rmd160[20]; int32_t completed; char *retstr,spendscriptstr[4096],*rawtx=0,*signedtx = 0; bits256 signedtxid,senttxid; cJSON *retjson,*vins,*addresses,*valsobj; uint32_t spendlen,locktime = 0; struct iguana_waddress *waddr; uint32_t basilisktag;
//sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to] <amount> is a real and is rounded to 8 decimal places. Returns the transaction ID <txid> if successful. Y //sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to] <amount> is a real and is rounded to 8 decimal places. Returns the transaction ID <txid> if successful. Y
addresses = iguana_getaddressesbyaccount(myinfo,coin,account); addresses = iguana_getaddressesbyaccount(myinfo,coin,account);
if ( coin->changeaddr[0] == 0 ) if ( coin->changeaddr[0] == 0 )
@ -398,7 +398,22 @@ char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
spendlen = bitcoin_standardspend(spendscript,0,rmd160); spendlen = bitcoin_standardspend(spendscript,0,rmd160);
init_hexbytes_noT(spendscriptstr,spendscript,spendlen); init_hexbytes_noT(spendscriptstr,spendscript,spendlen);
if ( (rawtx= basilisk_issuerawtx(myinfo,remoteaddr,0,coin->symbol,&vins,locktime,satoshis,spendscriptstr,coin->changeaddr,txfee,minconf,addresses,0)) != 0 ) basilisktag = (uint32_t)rand();
valsobj = cJSON_CreateObject();
jadd(valsobj,"addresses",addresses);
jaddstr(valsobj,"coin",coin->symbol);
jaddstr(valsobj,"changeaddr",coin->changeaddr);
jadd64bits(valsobj,"amount",satoshis);
jadd64bits(valsobj,"txfee",txfee);
jaddnum(valsobj,"minconf",minconf);
jaddnum(valsobj,"basilisktag",basilisktag);
jaddnum(valsobj,"locktime",locktime);
jaddnum(valsobj,"timeout",30000);
if ( (retstr= basilisk_rawtx(myinfo,coin,0,0,basilisktag,valsobj,coin->symbol)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (rawtx= jstr(retjson,"result")) != 0 && (vins= jobj(retjson,"vins")) != 0 )
{ {
if ( (signedtx= iguana_signrawtx(myinfo,coin,&signedtxid,&completed,vins,rawtx,0)) != 0 ) if ( (signedtx= iguana_signrawtx(myinfo,coin,&signedtxid,&completed,vins,rawtx,0)) != 0 )
{ {
@ -425,6 +440,10 @@ char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *
free(rawtx); free(rawtx);
return(clonestr("{\"error\":\"couldnt sign rawtx\"}")); return(clonestr("{\"error\":\"couldnt sign rawtx\"}"));
} }
}
free_json(retjson);
}
free(retstr);
} else return(clonestr("{\"error\":\"couldnt create rawtx\"}")); } else return(clonestr("{\"error\":\"couldnt create rawtx\"}"));
} }
return(clonestr("{\"error\":\"need address and amount\"}")); return(clonestr("{\"error\":\"need address and amount\"}"));

12
iguana/swaps/iguana_BTCswap.c

@ -170,7 +170,7 @@ void iguana_addinputs(struct iguana_info *coin,struct bitcoin_spend *spend,cJSON
struct bitcoin_statetx *instantdex_signtx(char *str,struct supernet_info *myinfo,struct iguana_info *coin,uint32_t locktime,char *scriptstr,int64_t satoshis,int64_t txfee,int32_t minconf,int32_t myside) struct bitcoin_statetx *instantdex_signtx(char *str,struct supernet_info *myinfo,struct iguana_info *coin,uint32_t locktime,char *scriptstr,int64_t satoshis,int64_t txfee,int32_t minconf,int32_t myside)
{ {
struct iguana_waddress *waddr; struct iguana_waccount *wacct; struct bitcoin_statetx *tx=0; uint8_t pubkey33[33]; char coinaddr[64],wifstr[64]; char *rawtx,*signedtx,*retstr; bits256 signedtxid; uint32_t basilisktag; int32_t flag,completed; cJSON *valsobj,*vins,*retjson=0,*privkey,*argjson,*addresses; struct iguana_waddress *waddr; struct iguana_waccount *wacct; struct bitcoin_statetx *tx=0; uint8_t pubkey33[33]; char coinaddr[64],wifstr[64]; char *rawtx,*signedtx,*retstr; bits256 signedtxid; uint32_t basilisktag; int32_t flag,completed; cJSON *valsobj,*vins,*retjson=0,*privkey,*addresses;
if ( (waddr= iguana_getaccountaddress(myinfo,coin,0,0,coin->changeaddr,"change")) == 0 ) if ( (waddr= iguana_getaccountaddress(myinfo,coin,0,0,coin->changeaddr,"change")) == 0 )
{ {
printf("no change addr error\n"); printf("no change addr error\n");
@ -188,18 +188,19 @@ struct bitcoin_statetx *instantdex_signtx(char *str,struct supernet_info *myinfo
bitcoin_priv2wif(wifstr,waddr->privkey,coin->chain->wiftype); bitcoin_priv2wif(wifstr,waddr->privkey,coin->chain->wiftype);
jaddistr(privkey,waddr->wifstr); jaddistr(privkey,waddr->wifstr);
} }
basilisktag = (uint32_t)rand();
jaddistr(addresses,coinaddr); jaddistr(addresses,coinaddr);
valsobj = cJSON_CreateObject(); valsobj = cJSON_CreateObject();
jadd(valsobj,"addresses",addresses);
jaddstr(valsobj,"coin",coin->symbol); jaddstr(valsobj,"coin",coin->symbol);
jaddstr(valsobj,"changeaddr",coin->changeaddr);
jadd64bits(valsobj,"amount",satoshis); jadd64bits(valsobj,"amount",satoshis);
jadd64bits(valsobj,"txfee",txfee); jadd64bits(valsobj,"txfee",txfee);
jaddnum(valsobj,"minconf",minconf); jaddnum(valsobj,"minconf",minconf);
basilisktag = (uint32_t)rand();
jaddnum(valsobj,"basilisktag",basilisktag); jaddnum(valsobj,"basilisktag",basilisktag);
jaddnum(valsobj,"locktime",locktime); jaddnum(valsobj,"locktime",locktime);
argjson = cJSON_CreateObject(); jaddnum(valsobj,"timeout",30000);
jaddnum(argjson,"timeout",30000); if ( (retstr= basilisk_rawtx(myinfo,coin,0,0,basilisktag,valsobj,coin->symbol)) != 0 )
if ( (retstr= basilisk_rawtx(myinfo,coin,argjson,0,coin->changeaddr,addresses,valsobj,scriptstr)) != 0 )
{ {
printf("%s got.(%s)\n",str,retstr); printf("%s got.(%s)\n",str,retstr);
flag = 0; flag = 0;
@ -232,7 +233,6 @@ struct bitcoin_statetx *instantdex_signtx(char *str,struct supernet_info *myinfo
free(retstr); free(retstr);
} else printf("error creating %s feetx\n",myside != 0 ? "BOB" : "ALICE"); } else printf("error creating %s feetx\n",myside != 0 ? "BOB" : "ALICE");
free_json(addresses); free_json(addresses);
free_json(argjson);
return(tx); return(tx);
} }

6
includes/iguana_apideclares.h

@ -14,9 +14,9 @@
******************************************************************************/ ******************************************************************************/
INT_ARRAY_STRING(basilisk,balances,lastheight,addresses,activecoin); INT_ARRAY_STRING(basilisk,balances,basilisktag,vals,activecoin);//lastheight,addresses,activecoin);
STRING_ARRAY_OBJ_STRING(basilisk,rawtx,changeaddr,addresses,vals,spendscriptstr); INT_ARRAY_STRING(basilisk,rawtx,basilisktag,vals,activecoin);//changeaddr,addresses,vals,spendscriptstr);
//INT_ARRAY_STRING(basilisk,result,basilisktag,args,hexmsg); INT_ARRAY_STRING(basilisk,value,basilisktag,vals,activecoin);
ARRAY_OBJ_INT(basilisk,result,args,vals,basilisktag); ARRAY_OBJ_INT(basilisk,result,args,vals,basilisktag);
ZERO_ARGS(bitcoinrpc,getinfo); ZERO_ARGS(bitcoinrpc,getinfo);

Loading…
Cancel
Save