Browse Source

Merge pull request #298 from jl777/dev

Dev
win-cross
jl777 8 years ago
committed by GitHub
parent
commit
2eebec0b39
  1. 1
      basilisk/basilisk.c
  2. 19
      basilisk/basilisk_bitcoin.c
  3. 105
      basilisk/basilisk_swap.c
  4. 1
      iguana/iguana_exchanges.c
  5. 30
      iguana/iguana_json.c
  6. 1
      iguana/iguana_notary.c
  7. 7
      iguana/iguana_payments.c
  8. 37
      iguana/iguana_sign.c
  9. 1
      iguana/iguana_tradebots.c
  10. 3
      iguana/iguana_unspents.c
  11. 1
      iguana/iguana_wallet.c
  12. 1
      iguana/main.c
  13. 1
      iguana/ramchain_api.c
  14. 4
      includes/iguana_apideclares.h
  15. 31
      includes/iguana_apideclares2.h

1
basilisk/basilisk.c

@ -953,6 +953,7 @@ void basilisks_init(struct supernet_info *myinfo)
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
TWO_STRINGS(tradebot,gensvm,base,rel)
{

19
basilisk/basilisk_bitcoin.c

@ -758,9 +758,14 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
if ( (amount= j64bits(valsobj,"satoshis")) == 0 )
amount = jdouble(valsobj,"value") * SATOSHIDEN;
if ( (txfee= j64bits(valsobj,"txfee")) == 0 )
{
//if ( strcmp(coin->symbol,"BTC") != 0 )
{
txfee = coin->chain->txfee;
if ( txfee == 0 )
txfee = 10000;
if ( txfee < 50000 )
txfee = 50000;
}
}
spendscriptstr = jstr(valsobj,"spendscript");
minconf = juint(valsobj,"minconf");
locktime = jint(valsobj,"locktime");
@ -797,14 +802,16 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
oplen = 0;
} else oplen = datachain_opreturnscript(coin,buf,opreturn,oplen);
}
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf,oplen!=0?buf:0,oplen+offset,burnamount,remoteaddr,V,0);
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf,oplen!=0?buf:0,oplen+offset,burnamount,remoteaddr,V,1);
if ( txfee == 0 )
{
txfee = iguana_esttxfee(myinfo,coin,rawtx,0,vins != 0 ? cJSON_GetArraySize(vins): 0);
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf,oplen!=0?buf:0,oplen+offset,burnamount,remoteaddr,V,0);
printf("new txfee %.8f\n",dstr(txfee));
if ( vins != 0 )
free_json(vins), vins = 0;
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf,oplen!=0?buf:0,oplen+offset,burnamount,remoteaddr,V,1);
printf("new txfee %.8f (%s)\n",dstr(txfee),rawtx);
}
printf("generated.(%s) vins.(%s)\n",rawtx!=0?rawtx:"",vins!=0?jprint(vins,0):"");
//printf("generated.(%s) vins.(%s)\n",rawtx!=0?rawtx:"",vins!=0?jprint(vins,0):"");
}
if ( rawtx != 0 )
{

105
basilisk/basilisk_swap.c

@ -481,7 +481,7 @@ int32_t basilisk_rawtx_return(struct supernet_info *myinfo,int32_t height,struct
rawtx->I.datalen = (int32_t)strlen(signedtx) >> 1;
//rawtx->txbytes = calloc(1,rawtx->I.datalen);
decode_hex(rawtx->txbytes,rawtx->I.datalen,signedtx);
printf("%s SIGNEDTX.(%s)\n",rawtx->name,signedtx);
//printf("%s SIGNEDTX.(%s)\n",rawtx->name,signedtx);
free(signedtx);
retval = 0;
} else printf("error signrawtx\n"); //do a very short timeout so it finishes via local poll
@ -490,7 +490,7 @@ int32_t basilisk_rawtx_return(struct supernet_info *myinfo,int32_t height,struct
return(retval);
}
int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,uint32_t swapstarted,uint8_t *pubkey33,int32_t iambob,int32_t lockinputs,struct basilisk_rawtx *rawtx,uint32_t locktime,uint8_t *script,int32_t scriptlen,int64_t txfee,int32_t minconf,int32_t delay)
int32_t _basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,uint32_t swapstarted,uint8_t *pubkey33,int32_t iambob,int32_t lockinputs,struct basilisk_rawtx *rawtx,uint32_t locktime,uint8_t *script,int32_t scriptlen,int64_t txfee,int32_t minconf,int32_t delay)
{
char *retstr,*jsonstr,scriptstr[1024],coinaddr[64]; uint32_t basilisktag; int32_t flag,i,n,retval = -1; cJSON *addresses,*valsobj,*retarray=0; struct vin_info *V;
//bitcoin_address(coinaddr,rawtx->coin->chain->pubtype,myinfo->persistent_pubkey33,33);
@ -499,8 +499,6 @@ int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,uint32_t swaps
bitcoin_address(rawtx->coin->changeaddr,rawtx->coin->chain->pubtype,pubkey33,33);
printf("set change address.(%s)\n",rawtx->coin->changeaddr);
}
//if ( strcmp(rawtx->coin->symbol,"BTC") == 0 )
// txfee = 0;
init_hexbytes_noT(scriptstr,script,scriptlen);
basilisktag = (uint32_t)rand();
valsobj = cJSON_CreateObject();
@ -558,6 +556,24 @@ int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,uint32_t swaps
return(retval);
}
int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,uint32_t swapstarted,uint8_t *pubkey33,int32_t iambob,int32_t lockinputs,struct basilisk_rawtx *rawtx,uint32_t locktime,uint8_t *script,int32_t scriptlen,int64_t txfee,int32_t minconf,int32_t delay)
{
int32_t retval,len; uint64_t newtxfee; struct iguana_info *coin;
if ( (coin= rawtx->coin) == 0 || strcmp(coin->symbol,"BTC") != 0 )
return(_basilisk_rawtx_gen(str,myinfo,swapstarted,pubkey33,iambob,lockinputs,rawtx,locktime,script,scriptlen,txfee,minconf,delay));
retval = _basilisk_rawtx_gen(str,myinfo,swapstarted,pubkey33,iambob,0,rawtx,locktime,script,scriptlen,txfee,minconf,delay);
len = rawtx->I.datalen;
if ( coin->estimatedfee == 0 )
coin->estimatedfee = iguana_getestimatedfee(myinfo,coin);
newtxfee = coin->estimatedfee * len;
if ( newtxfee > txfee )
{
retval = _basilisk_rawtx_gen(str,myinfo,swapstarted,pubkey33,iambob,lockinputs,rawtx,locktime,script,scriptlen,newtxfee,minconf,delay);
printf("txfee %.8f -> newtxfee %.8f\n",dstr(txfee),dstr(newtxfee));
}
return(retval);
}
struct basilisk_rawtx *basilisk_swapdata_rawtx(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen,struct basilisk_rawtx *rawtx)
{
if ( rawtx->I.datalen != 0 && rawtx->I.datalen <= maxlen )
@ -582,7 +598,7 @@ int32_t basilisk_verify_otherfee(struct supernet_info *myinfo,void *ptr,uint8_t
int32_t basilisk_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *recvbuf,int32_t recvlen,int32_t suppress_pubkeys)
{
int32_t datalen=0,retval=-1,hexlen,n; uint8_t *data; cJSON *txobj,*skey,*vouts,*vout; char *hexstr;
int32_t datalen=0,retval=-1,hexlen,n; uint8_t *data; cJSON *txobj,*skey,*vouts,*vout; char *hexstr; bits256 txid;
datalen = recvbuf[0];
datalen += (int32_t)recvbuf[1] << 8;
if ( datalen > 65536 )
@ -609,6 +625,10 @@ int32_t basilisk_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,str
printf("%s rawtx data compare error, len %d vs %d <<<<<<<<<< warning\n",rawtx->name,rawtx->I.datalen,datalen);
return(-1);
}
txid = bits256_doublesha256(0,data,datalen);
char str[65]; printf("rawtx.%s txid %s\n",rawtx->name,bits256_str(str,txid));
if ( bits256_cmp(txid,rawtx->I.actualtxid) != 0 && bits256_nonz(rawtx->I.actualtxid) == 0 )
rawtx->I.actualtxid = txid;
if ( (txobj= bitcoin_data2json(rawtx->coin,height,&rawtx->I.signedtxid,&rawtx->msgtx,rawtx->extraspace,sizeof(rawtx->extraspace),data,datalen,0,suppress_pubkeys)) != 0 )
{
rawtx->I.actualtxid = rawtx->I.signedtxid;
@ -728,7 +748,7 @@ int32_t basilisk_verify_bobpaid(struct supernet_info *myinfo,void *ptr,uint8_t *
for (i=0; i<32; i++)
revAm.bytes[i] = swap->I.privAm.bytes[31-i];
len = basilisk_swapuserdata(userdata,revAm,0,swap->I.myprivs[0],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen);
char str[65],str2[65]; printf("bobpaid.(%s) (%s)\n",bits256_str(str,swap->I.privAm),bits256_str(str2,swap->I.myprivs[0]));
char str[65],str2[65]; printf("bobpaid privAm.(%s) myprivs[0].(%s)\n",bits256_str(str,swap->I.privAm),bits256_str(str2,swap->I.myprivs[0]));
if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->longestchain,swap,&swap->alicespend,&swap->bobpayment,swap->I.myprivs[0],0,userdata,len,1)) == 0 )
{
for (i=0; i<swap->bobpayment.I.datalen; i++)
@ -1323,8 +1343,8 @@ void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx *
rawtx->coin = coin;
strcpy(rawtx->I.coinstr,coin->symbol);
rawtx->I.numconfirms = numconfirms;
if ( (rawtx->I.amount= satoshis) < 10000 )
rawtx->I.amount = 10000;
if ( (rawtx->I.amount= satoshis) < 50000 )
rawtx->I.amount = 50000;
rawtx->I.vintype = vintype; // 0 -> std, 2 -> 2of2, 3 -> spend bobpayment, 4 -> spend bobdeposit
rawtx->I.vouttype = vouttype; // 0 -> fee, 1 -> std, 2 -> 2of2, 3 -> bobpayment, 4 -> bobdeposit
if ( rawtx->I.vouttype == 0 )
@ -1380,7 +1400,7 @@ int32_t bitcoin_coinptrs(bits256 pubkey,struct iguana_info **bobcoinp,struct igu
void basilisk_swap_saveupdate(struct supernet_info *myinfo,struct basilisk_swap *swap)
{
FILE *fp; char fname[512];
sprintf(fname,"%s/SWAPS/%u-%u.swap",GLOBAL_DBDIR,swap->I.req.requestid,swap->I.req.quoteid);
sprintf(fname,"%s/SWAPS/%u-%u.swap",GLOBAL_DBDIR,swap->I.req.requestid,swap->I.req.quoteid), OS_compatible_path(fname);
if ( 0 && (fp= fopen(fname,"wb")) != 0 )
{
fwrite(&swap->I,1,sizeof(swap->I),fp);
@ -1425,7 +1445,7 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,bits256 priv
FILE *fp; char fname[512]; uint8_t *alicepub33=0,*bobpub33=0; int32_t jumblrflag,x = -1;
if ( reinit != 0 )
{
sprintf(fname,"%s/SWAPS/%u-%u.swap",GLOBAL_DBDIR,swap->I.req.requestid,swap->I.req.quoteid);
sprintf(fname,"%s/SWAPS/%u-%u.swap",GLOBAL_DBDIR,swap->I.req.requestid,swap->I.req.quoteid), OS_compatible_path(fname);
printf("reinit.(%s)\n",fname);
if ( (fp= fopen(fname,"rb")) != 0 )
{
@ -1463,10 +1483,10 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,bits256 priv
swap->I.callduration += optionduration;
swap->I.bobsatoshis = swap->I.req.destamount;
swap->I.alicesatoshis = swap->I.req.srcamount;
if ( (swap->I.bobinsurance= (swap->I.bobsatoshis / INSTANTDEX_INSURANCEDIV)) < 10000 )
swap->I.bobinsurance = 10000;
if ( (swap->I.aliceinsurance= (swap->I.alicesatoshis / INSTANTDEX_INSURANCEDIV)) < 10000 )
swap->I.aliceinsurance = 10000;
if ( (swap->I.bobinsurance= (swap->I.bobsatoshis / INSTANTDEX_INSURANCEDIV)) < 50000 )
swap->I.bobinsurance = 50000;
if ( (swap->I.aliceinsurance= (swap->I.alicesatoshis / INSTANTDEX_INSURANCEDIV)) < 50000 )
swap->I.aliceinsurance = 50000;
strcpy(swap->I.bobstr,swap->I.req.dest);
strcpy(swap->I.alicestr,swap->I.req.src);
swap->I.started = (uint32_t)time(NULL);
@ -1699,9 +1719,31 @@ int32_t basilisk_verify_privkeys(struct supernet_info *myinfo,void *ptr,uint8_t
return(errs);
}
void basilisk_dontforget(struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,int32_t locktime,bits256 triggertxid)
{
char fname[512],str[65]; FILE *fp; int32_t i;
sprintf(fname,"%s/SWAPS/%u-%u.%s",GLOBAL_DBDIR,swap->I.req.requestid,swap->I.req.quoteid,rawtx->name), OS_compatible_path(fname);
if ( (fp= fopen(fname,"wb")) != 0 )
{
fprintf(fp,"{\"name\":\"%s\",\"coin\":\"%s\"",rawtx->name,rawtx->coin->symbol);
if ( rawtx->I.datalen > 0 )
{
fprintf(fp,",\"tx\":\"");
for (i=0; i<rawtx->I.datalen; i++)
fprintf(fp,"%02x",rawtx->txbytes[i]);
fprintf(fp,"\",\"txid\":\"%s\"",bits256_str(str,bits256_doublesha256(0,rawtx->txbytes,rawtx->I.datalen)));
}
fprintf(fp,",\"lock\":%u",locktime);
if ( bits256_nonz(triggertxid) != 0 )
fprintf(fp,",\"trigger\":\"%s\"",bits256_str(str,triggertxid));
fprintf(fp,"}\n");
fclose(fp);
}
}
uint32_t basilisk_swapdata_rawtxsend(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t maxlen,struct basilisk_rawtx *rawtx,uint32_t nextbits,int32_t suppress_swapsend)
{
uint8_t sendbuf[32768]; int32_t sendlen;
uint8_t sendbuf[32768]; int32_t sendlen; bits256 triggertxid;
if ( basilisk_swapdata_rawtx(myinfo,swap,data,maxlen,rawtx) != 0 )
{
if ( bits256_nonz(rawtx->I.signedtxid) != 0 && bits256_nonz(rawtx->I.actualtxid) == 0 )
@ -1722,6 +1764,35 @@ uint32_t basilisk_swapdata_rawtxsend(struct supernet_info *myinfo,struct basilis
memcpy(&sendbuf[sendlen],rawtx->redeemscript,rawtx->I.redeemlen);
sendlen += rawtx->I.redeemlen;
}
memset(triggertxid.bytes,0,sizeof(triggertxid));
if ( swap->I.iambob != 0 )
{
if ( rawtx == &swap->bobdeposit )
{
basilisk_dontforget(myinfo,swap,&swap->bobdeposit,0,triggertxid);
basilisk_dontforget(myinfo,swap,&swap->bobrefund,0,triggertxid);
}
else if ( rawtx == &swap->bobpayment )
{
basilisk_dontforget(myinfo,swap,&swap->bobpayment,0,triggertxid);
basilisk_dontforget(myinfo,swap,&swap->bobreclaim,swap->bobpayment.I.locktime,triggertxid);
}
else if ( rawtx == &swap->bobspend )
basilisk_dontforget(myinfo,swap,&swap->bobspend,0,triggertxid);
}
else
{
if ( rawtx == &swap->alicepayment )
{
basilisk_dontforget(myinfo,swap,&swap->alicepayment,0,triggertxid);
}
else if ( rawtx == &swap->alicespend )
{
basilisk_dontforget(myinfo,swap,&swap->alicespend,0,triggertxid);
//basilisk_alicepayment_spend(myinfo,swap,&swap->alicereclaim);
basilisk_dontforget(myinfo,swap,&swap->alicereclaim,0,swap->bobrefund.I.actualtxid);
}
}
//printf("sendlen.%d datalen.%d redeemlen.%d\n",sendlen,rawtx->datalen,rawtx->redeemlen);
if ( suppress_swapsend == 0 )
return(basilisk_swapsend(myinfo,swap,msgbits,sendbuf,sendlen,nextbits,rawtx->I.crcs));
@ -1926,7 +1997,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
{
if ( basilisk_swapget(myinfo,swap,0x40000,data,maxlen,basilisk_verify_privi) == 0 || basilisk_privAm_extract(myinfo,swap) == 0 ) // divulges privAm
{
printf("got privi spend alicepayment, dont divulge privBn until bobspend propagated\n");
//printf("got privi spend alicepayment, dont divulge privBn until bobspend propagated\n");
basilisk_alicepayment_spend(myinfo,swap,&swap->bobspend);
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobspend,0x40000,1) == 0 )
printf("Bob error spending alice payment\n");
@ -2284,7 +2355,7 @@ void basilisk_swaploop(void *_swap)
else
{
retval = 0;
for (i=0; i<swap->alicepayment.I.spendlen; i++)
for (i=0; i<swap->alicepayment.I.datalen; i++)
printf("%02x",swap->alicepayment.txbytes[i]);
printf(" ALICE PAYMENT created\n");
iguana_unspents_mark(myinfo,swap->alicecoin,swap->alicepayment.vins);

1
iguana/iguana_exchanges.c

@ -1176,6 +1176,7 @@ cJSON *iguana_pricesarray(struct supernet_info *myinfo,char *exchange,char *base
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
THREE_STRINGS_AND_THREE_INTS(InstantDEX,orderbook,exchange,base,rel,depth,allfields,ignore)
{

30
iguana/iguana_json.c

@ -86,7 +86,6 @@ cJSON *SuperNET_helpjson()
cJSON *array=0,*json,*agents;
json = cJSON_CreateObject();
agents = cJSON_CreateArray();
#ifndef WIN32
#define IGUANA_ARGS json,array,agents
#define IGUANA_HELP0(agent,name) array = helpjson(IGUANA_ARGS,#agent,#name,0)
#define IGUANA_HELP_S(agent,name,str) array = helpjson(IGUANA_ARGS,#agent,#name,helparray(cJSON_CreateArray(),helpitem(#str,"string")))
@ -195,7 +194,6 @@ cJSON *SuperNET_helpjson()
#undef IGUANA_ARGS
#undef _IGUANA_APIDEC_H_
#include "../includes/iguana_apiundefs.h"
#endif
if ( array != 0 )
jadd(json,"API",array);
@ -498,6 +496,14 @@ char *SuperNET_htmlstr(char *fname,char *htmlstr,int32_t maxsize,char *agentstr)
return(OS_filestr(&filesize,"index7778.html"));
}
#ifdef WIN32
/**
* workaround for MSVS compiler bug -
* instead of going on if-else-if block split the if-else-if into two function
*/
char *SuperNET_parser2(struct supernet_info *myinfo, char *agentstr, char *method, cJSON *json, char *remoteaddr);
#endif
char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,cJSON *json,char *remoteaddr)
{
char *coinstr; struct iguana_info *coin = 0;
@ -614,13 +620,31 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,c
#define STRING_ARRAY_OBJ_STRING IGUANA_DISPATCH_SAOS
#include "../includes/iguana_apideclares.h"
#ifdef WIN32
return SuperNET_parser2(myinfo, agentstr, method, json, remoteaddr);
#else
#undef IGUANA_ARGS
#undef _IGUANA_APIDEC_H_
#include "../includes/iguana_apiundefs.h"
char errstr[512];
sprintf(errstr,"{\"error\":\"unsupported call\",\"agent\":\"%s\",\"method\":\"%s\"}",agentstr,method);
return(clonestr(errstr));
#endif
}
#ifdef WIN32
char *SuperNET_parser2(struct supernet_info *myinfo, char *agentstr, char *method, cJSON *json, char *remoteaddr) {
char *coinstr; struct iguana_info *coin = 0;
if (remoteaddr != 0 && (remoteaddr[0] == 0 || strcmp(remoteaddr, "127.0.0.1") == 0))
remoteaddr = 0;
#include "../includes/iguana_apideclares2.h"
#undef IGUANA_ARGS
#undef _IGUANA_APIDEC_H_
#include "../includes/iguana_apiundefs.h"
char errstr[512];
sprintf(errstr, "{\"error\":\"unsupported call\",\"agent\":\"%s\",\"method\":\"%s\"}", agentstr, method);
return(clonestr(errstr));
}
#endif

1
iguana/iguana_notary.c

@ -224,6 +224,7 @@ void dpow_addresses()
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
TWO_STRINGS(iguana,dpow,symbol,pubkey)
{

7
iguana/iguana_payments.c

@ -175,7 +175,7 @@ int32_t iguana_RTbestunspent(struct supernet_info *myinfo,struct iguana_info *co
}
if ( iguana_RTunspent_check(myinfo,coin,unspents[i]) != 0 )
{
//printf("(%d u%d) %.8f already used\n",unspents[i].hdrsi,unspents[i].unspentind,dstr(atx_value));
printf("(%d u%d) %.8f already used\n",unspents[i].hdrsi,unspents[i].unspentind,dstr(atx_value));
continue;
}
if ( maxmode == 0 )
@ -274,7 +274,7 @@ char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,int
memset(&msgtx,0,sizeof(msgtx));
if ( V == 0 )
V = calloc(numinputs,sizeof(*V)), flagV = 1;
//printf("SIGN.(%s) priv.(%s) %llx %llx V.%p\n",jprint(vins,0),jprint(privkeys,0),(long long)V->signers[0].privkey.txid,(long long)V->signers[1].privkey.txid,V);
//printf("SIGN.(%s) priv.(%s) %llx %llx (%s)\n",jprint(vins,0),jprint(privkeys,0),(long long)V->signers[0].privkey.txid,(long long)V->signers[1].privkey.txid,vins!=0?jprint(vins,0):"no vins");
if ( V != 0 )
{
if ( iguana_signrawtransaction(myinfo,coin,height,&msgtx,&signedtx,signedtxidp,V,numinputs,rawtx,vins,privkeys) > 0 )
@ -459,7 +459,7 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS
free(unspents);
return(0);
}*/
printf("avail %.8f satoshis %.8f, txfee %.8f burnamount %.8f vin0.scriptlen %d\n",dstr(avail),dstr(satoshis),dstr(txfee),dstr(burnamount),unspents[0].spendlen);
printf("avail %.8f satoshis %.8f, txfee %.8f burnamount %.8f vin0.scriptlen %d num.%d\n",dstr(avail),dstr(satoshis),dstr(txfee),dstr(burnamount),unspents[0].spendlen,num);
if ( txobj != 0 && avail >= satoshis+txfee )
{
if ( (vins= iguana_RTinputsjson(myinfo,coin,&total,satoshis + txfee,unspents,num,maxmode)) != 0 )
@ -700,6 +700,7 @@ char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
STRING_AND_INT(bitcoinrpc,sendrawtransaction,rawtx,allowhighfees)
{

37
iguana/iguana_sign.c

@ -568,6 +568,22 @@ void iguana_vinobjset(struct iguana_msgvin *vin,cJSON *item,uint8_t *spendscript
}
}
int32_t iguana_vinarray_check(cJSON *vinarray,bits256 txid)
{
bits256 array_txid; cJSON *item; int32_t i,n = cJSON_GetArraySize(vinarray);
for (i=0; i<n; i++)
{
item = jitem(vinarray,i);
array_txid = jbits256(item,"txid");
if ( bits256_cmp(array_txid,txid) == 0 )
{
printf("vinarray.[%d] duplicate\n",i);
return(i);
}
}
return(-1);
}
int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins,int32_t suppress_pubkeys)
{
int32_t i,n,len = 0,extraused=0; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid;
@ -657,7 +673,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
jaddi(voutarray,iguana_voutjson(coin,&msg->vouts[i],i,*txidp));
}
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time);
//printf("lock_time.%08x len.%d\n",msg->lock_time,len);
//printf("lock_time.%08x len.%d\n",msg->lock_time,len);
if ( strcmp(coin->symbol,"VPN") == 0 )
{
uint16_t ddosflag = 0;
@ -688,13 +704,16 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
iguana_vinobjset(&msg->vins[i],jitem(vins,i),spendscript,sizeof(spendscript));
sigtxid = bitcoin_sigtxid(coin,height,sigser,maxsize*2,msg,i,msg->vins[i].spendscript,msg->vins[i].spendlen,SIGHASH_ALL,vpnstr,suppress_pubkeys);
//printf("after vini.%d vinscript.%p spendscript.%p spendlen.%d (%s)\n",i,msg->vins[i].vinscript,msg->vins[i].spendscript,msg->vins[i].spendlen,jprint(jitem(vins,i),0));
if ( iguana_vinarray_check(vinarray,msg->vins[i].prev_hash) < 0 )
jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid));
if ( msg->vins[i].spendscript == spendscript )
msg->vins[i].spendscript = 0;
} else jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid));
} else if ( iguana_vinarray_check(vinarray,msg->vins[i].prev_hash) < 0 )
jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid));
}
free(sigser);
jadd(json,"vin",vinarray);
msg->tx_in = cJSON_GetArraySize(vinarray);
jaddnum(json,"numvins",msg->tx_in);
}
if ( voutarray != 0 )
@ -833,6 +852,7 @@ cJSON *bitcoin_data2json(struct iguana_info *coin,int32_t height,bits256 *txidp,
jaddstr(txobj,"error","couldnt decode transaction");
jaddstr(txobj,"coin",coin->symbol);
}
//printf("msgtx.(%s)\n",jprint(txobj,0));
if ( n != len )
{
int32_t i;
@ -1361,14 +1381,14 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
//printf("call hex2json.(%s) vins.(%s)\n",rawtx,jprint(vins,0));
if ( (txobj= bitcoin_hex2json(coin,height,&txid,msgtx,rawtx,extraspace,extralen,serialized4,vins,V->suppress_pubkeys)) != 0 )
{
//printf("back from bitcoin_hex2json\n");
//printf("back from bitcoin_hex2json (%s)\n",jprint(vins,0));
} else fprintf(stderr,"no txobj from bitcoin_hex2json\n");
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 )
{
//printf("numinputs.%d msgtx.%d\n",numinputs,msgtx->tx_in);
memset(msgtx,0,sizeof(*msgtx));
if ( iguana_rwmsgtx(coin,height,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,65536,vins,V->suppress_pubkeys) > 0 && numinputs == msgtx->tx_in )
{
//printf("back rwmsgtx vins.%p\n",msgtx->vins);
memset(pubkeys,0,sizeof(pubkeys));
memset(privkeys,0,sizeof(privkeys));
if ( (n= cJSON_GetArraySize(privkeysjson)) > 0 )
@ -1430,7 +1450,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
for (z=0; z<33; z++)
V[i].signers[j].pubkey[z] = pubkeys[k][z];
}
printf("%s -> V[%d].signer.[%d] <- privkey.%d\n",mvin.signers[j].coinaddr,i,j,k);
//printf("%s -> V[%d].signer.[%d] <- privkey.%d\n",mvin.signers[j].coinaddr,i,j,k);
break;
}
}
@ -1453,16 +1473,17 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
}
}
finalized = iguana_vininfo_create(myinfo,coin,serialized2,maxsize,msgtx,vins,numinputs,V);
//printf("finalized.%d\n",finalized);
if ( (complete= bitcoin_verifyvins(coin,height,signedtxidp,&signedtx,msgtx,serialized3,maxsize,V,SIGHASH_ALL,1,V->suppress_pubkeys)) > 0 && signedtx != 0 )
{
int32_t tmp; char str[65];
if ( (tmp= iguana_interpreter(coin,0,iguana_lockval(finalized,jint(txobj,"locktime")),V,numinputs)) < 0 )
{
//printf("iguana_interpreter %d error.(%s)\n",tmp,signedtx);
printf("iguana_interpreter %d error.(%s)\n",tmp,signedtx);
complete = 0;
} else printf("%s signed\n",bits256_str(str,*signedtxidp));
}
}
} else printf("complete.%d\n",complete);
} else printf("rwmsgtx error\n");
} else fprintf(stderr,"no inputs in vins.(%s)\n",vins!=0?jprint(vins,0):"null");
free(extraspace);
free(serialized), free(serialized2), free(serialized3), free(serialized4);

1
iguana/iguana_tradebots.c

@ -221,6 +221,7 @@ char *tradebot_control(struct supernet_info *myinfo,char *exchangestr,char *boti
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
HASH_ARRAY_STRING(tradebot,liquidity,hash,vals,targetcoin)
{

3
iguana/iguana_unspents.c

@ -913,7 +913,7 @@ void iguana_unspents_mark(struct supernet_info *myinfo,struct iguana_info *coin,
{
if ( firstslot >= 0 )
{
//printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,txid),vout);
printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,txid),vout);
coin->markedunspents[firstslot] = txid;
coin->markedunspents[firstslot].ushorts[15] = vout;
if ( (0) && coin->utxofp == 0 )
@ -1799,6 +1799,7 @@ void iguana_utxoaddrs_purge(struct iguana_info *coin)
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
STRING_AND_INT(iguana,snapshot,symbol,height)
{

1
iguana/iguana_wallet.c

@ -995,6 +995,7 @@ cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
int64_t iguana_addressreceived(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,cJSON *txids,cJSON *vouts,cJSON *unspents,cJSON *spends,char *coinaddr,int32_t minconf,int32_t firstheight)
{

1
iguana/main.c

@ -1026,6 +1026,7 @@ void SuperNET_parsepeers(struct supernet_info *myinfo,cJSON *array,int32_t n,int
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
STRING_ARG(iguana,initfastfind,activecoin)
{

1
iguana/ramchain_api.c

@ -18,6 +18,7 @@
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
STRING_ARG(iguana,peers,activecoin)

4
includes/iguana_apideclares.h

@ -335,6 +335,8 @@ STRING_ARG(hash,base64_decode,message);
STRING_ARG(hash,rmd160_sha256,message);
STRING_ARG(hash,sha256_sha256,message);
#ifndef WIN32
STRING_ARG(hash,sha224,message);
STRING_ARG(hash,sha256,message);
STRING_ARG(hash,sha384,message);
@ -366,3 +368,5 @@ TWO_STRINGS(hmac,tiger192_3,message,passphrase);
TWO_STRINGS(hmac,whirlpool,message,passphrase);
#endif
#endif

31
includes/iguana_apideclares2.h

@ -0,0 +1,31 @@
#ifdef WIN32
STRING_ARG(hash, sha224, message);
STRING_ARG(hash, sha256, message);
STRING_ARG(hash, sha384, message);
STRING_ARG(hash, sha512, message);
STRING_ARG(hash, rmd128, message);
STRING_ARG(hash, rmd160, message);
STRING_ARG(hash, rmd256, message);
STRING_ARG(hash, rmd320, message);
STRING_ARG(hash, sha1, message);
STRING_ARG(hash, md2, message);
STRING_ARG(hash, md4, message);
STRING_ARG(hash, md5, message);
STRING_ARG(hash, tiger192_3, message);
STRING_ARG(hash, whirlpool, message);
TWO_STRINGS(hmac, sha224, message, passphrase);
TWO_STRINGS(hmac, sha256, message, passphrase);
TWO_STRINGS(hmac, sha384, message, passphrase);
TWO_STRINGS(hmac, sha512, message, passphrase);
TWO_STRINGS(hmac, rmd128, message, passphrase);
TWO_STRINGS(hmac, rmd160, message, passphrase);
TWO_STRINGS(hmac, rmd256, message, passphrase);
TWO_STRINGS(hmac, rmd320, message, passphrase);
TWO_STRINGS(hmac, sha1, message, passphrase);
TWO_STRINGS(hmac, md2, message, passphrase);
TWO_STRINGS(hmac, md4, message, passphrase);
TWO_STRINGS(hmac, md5, message, passphrase);
TWO_STRINGS(hmac, tiger192_3, message, passphrase);
TWO_STRINGS(hmac, whirlpool, message, passphrase);
#endif
Loading…
Cancel
Save