Browse Source

Test

etomic
jl777 8 years ago
parent
commit
6b8afc8099
  1. 4
      .gitignore
  2. 16
      basilisk/basilisk_swap.c
  3. 24
      iguana/exchanges/mm.c
  4. 4
      iguana/iguana_payments.c
  5. 47
      iguana/iguana_sign.c

4
.gitignore

@ -180,3 +180,7 @@ iguana/iguana777.o-0cc60f50
iguana/DB/SWAPS/667293271-3414303895 iguana/DB/SWAPS/667293271-3414303895
iguana/DB/SWAPS/667293271-3414303895.swap iguana/DB/SWAPS/667293271-3414303895.swap
iguana/DB/SWAPS/548227681-1452262678.swap
iguana/DB/SWAPS/548227681-1452262678

16
basilisk/basilisk_swap.c

@ -255,7 +255,7 @@ int32_t basilisk_numconfirms(struct supernet_info *myinfo,struct basilisk_swap *
{ {
cJSON *argjson,*valuearray=0; char *valstr; int32_t i,n,retval = -1; cJSON *argjson,*valuearray=0; char *valstr; int32_t i,n,retval = -1;
#ifdef BASILISK_DISABLEWAITTX #ifdef BASILISK_DISABLEWAITTX
return(10); return(100);
#endif #endif
argjson = cJSON_CreateObject(); argjson = cJSON_CreateObject();
jaddbits256(argjson,"txid",rawtx->I.actualtxid); jaddbits256(argjson,"txid",rawtx->I.actualtxid);
@ -319,7 +319,6 @@ bits256 basilisk_swap_broadcast(char *name,struct supernet_info *myinfo,struct b
int32_t _basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,uint32_t timestamp,uint32_t locktime,uint32_t sequenceid,struct basilisk_rawtx *dest,struct basilisk_rawtx *rawtx,bits256 privkey,bits256 *privkey2,uint8_t *userdata,int32_t userdatalen,int32_t ignore_cltverr) int32_t _basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,uint32_t timestamp,uint32_t locktime,uint32_t sequenceid,struct basilisk_rawtx *dest,struct basilisk_rawtx *rawtx,bits256 privkey,bits256 *privkey2,uint8_t *userdata,int32_t userdatalen,int32_t ignore_cltverr)
{ {
char *rawtxbytes=0,*signedtx=0,hexstr[999],wifstr[128]; cJSON *txobj,*vins,*item,*sobj,*privkeys; int32_t needsig=1,retval = -1; struct vin_info *V; char *rawtxbytes=0,*signedtx=0,hexstr[999],wifstr[128]; cJSON *txobj,*vins,*item,*sobj,*privkeys; int32_t needsig=1,retval = -1; struct vin_info *V;
V = calloc(16,sizeof(*V)); V = calloc(16,sizeof(*V));
V[0].signers[0].privkey = privkey; V[0].signers[0].privkey = privkey;
bitcoin_pubkey33(myinfo->ctx,V[0].signers[0].pubkey,privkey); bitcoin_pubkey33(myinfo->ctx,V[0].signers[0].pubkey,privkey);
@ -333,7 +332,7 @@ int32_t _basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,uint32_
bitcoin_priv2wif(wifstr,*privkey2,rawtx->coin->chain->wiftype); bitcoin_priv2wif(wifstr,*privkey2,rawtx->coin->chain->wiftype);
jaddistr(privkeys,wifstr); jaddistr(privkeys,wifstr);
V[0].N = V[0].M = 2; V[0].N = V[0].M = 2;
//char str[65]; printf("add second privkey.(%s) %s\n",jprint(privkeys,0),bits256_str(str,*privkey2)); char str[65]; printf("add second privkey.(%s) %s\n",jprint(privkeys,0),bits256_str(str,*privkey2));
} else V[0].N = V[0].M = 1; } else V[0].N = V[0].M = 1;
V[0].suppress_pubkeys = dest->I.suppress_pubkeys; V[0].suppress_pubkeys = dest->I.suppress_pubkeys;
V[0].ignore_cltverr = ignore_cltverr; V[0].ignore_cltverr = ignore_cltverr;
@ -352,6 +351,7 @@ int32_t _basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,uint32_
needsig = 0; needsig = 0;
#endif #endif
} }
printf("rawtx B\n");
if ( bits256_nonz(rawtx->I.actualtxid) != 0 ) if ( bits256_nonz(rawtx->I.actualtxid) != 0 )
jaddbits256(item,"txid",rawtx->I.actualtxid); jaddbits256(item,"txid",rawtx->I.actualtxid);
else jaddbits256(item,"txid",rawtx->I.signedtxid); else jaddbits256(item,"txid",rawtx->I.signedtxid);
@ -371,10 +371,11 @@ int32_t _basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,uint32_
jaddi(vins,item); jaddi(vins,item);
jdelete(txobj,"vin"); jdelete(txobj,"vin");
jadd(txobj,"vin",vins); jadd(txobj,"vin",vins);
//printf("basilisk_rawtx_sign locktime.%u/%u for %s spendscript.%s -> %s, suppress.%d\n",rawtx->locktime,dest->locktime,rawtx->name,hexstr,dest->name,dest->suppress_pubkeys); printf("basilisk_rawtx_sign locktime.%u/%u for %s spendscript.%s -> %s, suppress.%d\n",rawtx->I.locktime,dest->I.locktime,rawtx->name,hexstr,dest->name,dest->I.suppress_pubkeys);
txobj = bitcoin_txoutput(txobj,dest->spendscript,dest->I.spendlen,dest->I.amount); txobj = bitcoin_txoutput(txobj,dest->spendscript,dest->I.spendlen,dest->I.amount);
if ( (rawtxbytes= bitcoin_json2hex(myinfo,rawtx->coin,&dest->I.txid,txobj,V)) != 0 ) if ( (rawtxbytes= bitcoin_json2hex(myinfo,rawtx->coin,&dest->I.txid,txobj,V)) != 0 )
{ {
printf("rawtx.(%s) vins.%p\n",rawtxbytes,vins);
if ( needsig == 0 ) if ( needsig == 0 )
signedtx = rawtxbytes; signedtx = rawtxbytes;
if ( signedtx != 0 || (signedtx= iguana_signrawtx(myinfo,rawtx->coin,height,&dest->I.signedtxid,&dest->I.completed,vins,rawtxbytes,privkeys,V)) != 0 ) if ( signedtx != 0 || (signedtx= iguana_signrawtx(myinfo,rawtx->coin,height,&dest->I.signedtxid,&dest->I.completed,vins,rawtxbytes,privkeys,V)) != 0 )
@ -745,6 +746,7 @@ int32_t basilisk_alicepayment_spend(struct supernet_info *myinfo,struct basilisk
int32_t i,retval; int32_t i,retval;
printf("alicepayment_spend\n"); printf("alicepayment_spend\n");
swap->alicepayment.I.spendlen = basilisk_alicescript(swap->alicepayment.redeemscript,&swap->alicepayment.I.redeemlen,swap->alicepayment.spendscript,0,swap->alicepayment.I.destaddr,swap->alicecoin->chain->p2shtype,swap->I.pubAm,swap->I.pubBn); swap->alicepayment.I.spendlen = basilisk_alicescript(swap->alicepayment.redeemscript,&swap->alicepayment.I.redeemlen,swap->alicepayment.spendscript,0,swap->alicepayment.I.destaddr,swap->alicecoin->chain->p2shtype,swap->I.pubAm,swap->I.pubBn);
printf("alicepayment_spend len.%d\n",swap->alicepayment.I.spendlen);
if ( (retval= basilisk_rawtx_sign(myinfo,swap->alicecoin->longestchain,swap,dest,&swap->alicepayment,swap->I.privAm,&swap->I.privBn,0,0,1)) == 0 ) if ( (retval= basilisk_rawtx_sign(myinfo,swap->alicecoin->longestchain,swap,dest,&swap->alicepayment,swap->I.privAm,&swap->I.privBn,0,0,1)) == 0 )
{ {
for (i=0; i<dest->I.datalen; i++) for (i=0; i<dest->I.datalen; i++)
@ -1373,9 +1375,7 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,bits256 priv
else if ( optionduration > 0 ) else if ( optionduration > 0 )
swap->I.callduration += optionduration; swap->I.callduration += optionduration;
swap->I.bobsatoshis = swap->I.req.destamount; swap->I.bobsatoshis = swap->I.req.destamount;
swap->I.bobconfirms = (1*0 + sqrt(dstr(swap->I.bobsatoshis) * .1));
swap->I.alicesatoshis = swap->I.req.srcamount; swap->I.alicesatoshis = swap->I.req.srcamount;
swap->I.aliceconfirms = swap->I.bobconfirms * 3;
if ( (swap->I.bobinsurance= (swap->I.bobsatoshis / INSTANTDEX_INSURANCEDIV)) < 10000 ) if ( (swap->I.bobinsurance= (swap->I.bobsatoshis / INSTANTDEX_INSURANCEDIV)) < 10000 )
swap->I.bobinsurance = 10000; swap->I.bobinsurance = 10000;
if ( (swap->I.aliceinsurance= (swap->I.alicesatoshis / INSTANTDEX_INSURANCEDIV)) < 10000 ) if ( (swap->I.aliceinsurance= (swap->I.alicesatoshis / INSTANTDEX_INSURANCEDIV)) < 10000 )
@ -1414,6 +1414,8 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,bits256 priv
free(swap); free(swap);
return(0); return(0);
} }
swap->I.bobconfirms = (1*0 + sqrt(dstr(swap->I.bobsatoshis) * .1));
swap->I.aliceconfirms = swap->I.bobconfirms * 3;
if ( swap->I.bobconfirms == 0 ) if ( swap->I.bobconfirms == 0 )
swap->I.bobconfirms = swap->bobcoin->chain->minconfirms; swap->I.bobconfirms = swap->bobcoin->chain->minconfirms;
if ( swap->I.aliceconfirms == 0 ) if ( swap->I.aliceconfirms == 0 )
@ -1800,7 +1802,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
if ( basilisk_swapget(myinfo,swap,0x1000,data,maxlen,basilisk_verify_alicepaid) == 0 ) if ( basilisk_swapget(myinfo,swap,0x1000,data,maxlen,basilisk_verify_alicepaid) == 0 )
{ {
swap->I.statebits |= 0x1000; swap->I.statebits |= 0x1000;
printf("got alicepayment\n"); printf("got alicepayment aliceconfirms.%d\n",swap->I.aliceconfirms);
} }
} }
else if ( (swap->I.statebits & 0x2000) == 0 ) else if ( (swap->I.statebits & 0x2000) == 0 )

24
iguana/exchanges/mm.c

@ -22,6 +22,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include "OS_portable.h" #include "OS_portable.h"
#define MAX(a,b) ((a) > (b) ? (a) : (b))
struct mmpending_order struct mmpending_order
{ {
@ -501,15 +502,16 @@ int32_t marketmaker_spread(char *exchange,char *base,char *rel,double bid,double
jaddnum(vals,"ask",ask); jaddnum(vals,"ask",ask);
vol = bidvol > askvol ? askvol : bidvol; vol = bidvol > askvol ? askvol : bidvol;
jaddnum(vals,"maxvol",vol); jaddnum(vals,"maxvol",vol);
jaddnum(vals,"minvol",vol * 0.1); jaddnum(vals,"minvol",vol*0.1 > 100 ? 100 : vol * 0.1);
sprintf(url,"%s/?",IGUANA_URL); sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"tradebot\",\"method\":\"liquidity\",\"targetcoin\":\"%s\",\"vals\":%s}",base,jprint(vals,1)); sprintf(postdata,"{\"agent\":\"tradebot\",\"method\":\"liquidity\",\"targetcoin\":\"%s\",\"vals\":%s}",base,jprint(vals,1));
printf("(%s)\n",postdata);
if ( (retstr= bitcoind_RPC(0,"tradebot",url,0,"liqudity",postdata)) != 0 ) if ( (retstr= bitcoind_RPC(0,"tradebot",url,0,"liqudity",postdata)) != 0 )
{ {
//printf("(%s) -> (%s)\n",postdata,retstr); //printf("(%s) -> (%s)\n",postdata,retstr);
free(retstr); free(retstr);
} }
spread_ratio = (ask - bid) / (bid + ask); spread_ratio = .5 * ((ask - bid) / (bid + ask));
for (i=0; i<sizeof(CURRENCIES)/sizeof(*CURRENCIES); i++) for (i=0; i<sizeof(CURRENCIES)/sizeof(*CURRENCIES); i++)
{ {
if ( PAXPRICES[i] > SMALLVAL ) if ( PAXPRICES[i] > SMALLVAL )
@ -519,7 +521,7 @@ int32_t marketmaker_spread(char *exchange,char *base,char *rel,double bid,double
jaddnum(vals,"bid",PAXPRICES[i] * (1. - spread_ratio)); jaddnum(vals,"bid",PAXPRICES[i] * (1. - spread_ratio));
jaddnum(vals,"ask",PAXPRICES[i] * (1. + spread_ratio)); jaddnum(vals,"ask",PAXPRICES[i] * (1. + spread_ratio));
jaddnum(vals,"maxvol",vol * PAXPRICES[i]); jaddnum(vals,"maxvol",vol * PAXPRICES[i]);
jaddnum(vals,"minvol",vol * 0.1 * PAXPRICES[i]); jaddnum(vals,"minvol",MAX(1,(int32_t)(vol * 0.01 * PAXPRICES[i])));
sprintf(url,"%s/?",IGUANA_URL); sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"tradebot\",\"method\":\"liquidity\",\"targetcoin\":\"%s\",\"vals\":%s}","KMD",jprint(vals,1)); sprintf(postdata,"{\"agent\":\"tradebot\",\"method\":\"liquidity\",\"targetcoin\":\"%s\",\"vals\":%s}","KMD",jprint(vals,1));
if ( (retstr= bitcoind_RPC(0,"tradebot",url,0,"liqudity",postdata)) != 0 ) if ( (retstr= bitcoind_RPC(0,"tradebot",url,0,"liqudity",postdata)) != 0 )
@ -528,6 +530,7 @@ int32_t marketmaker_spread(char *exchange,char *base,char *rel,double bid,double
free(retstr); free(retstr);
} }
} }
break;
} }
} else printf("unsupported ask only for DEX %s/%s\n",base,rel); } else printf("unsupported ask only for DEX %s/%s\n",base,rel);
} }
@ -561,7 +564,7 @@ int32_t marketmaker_spread(char *exchange,char *base,char *rel,double bid,double
void marketmaker(double minask,double maxbid,char *baseaddr,char *reladdr,double start_BASE,double start_REL,double profitmargin,double maxexposure,double ratioincr,char *exchange,char *name,char *base,char *rel) void marketmaker(double minask,double maxbid,char *baseaddr,char *reladdr,double start_BASE,double start_REL,double profitmargin,double maxexposure,double ratioincr,char *exchange,char *name,char *base,char *rel)
{ {
static uint32_t counter; static uint32_t counter;
cJSON *fiatjson; double start_DEXbase,start_DEXrel,USD_average=0.,DEX_base = 0.,DEX_rel = 0.,balance_base=0.,balance_rel=0.,mmbid,mmask,usdprice=0.,CMC_average=0.,aveprice,incr,pendingbids,pendingasks,buyvol,sellvol,bidincr,askincr,filledprice,avebid=0.,aveask=0.,val,changes[3],highbid=0.,lowask=0.,theoretical = 0.; uint32_t lasttime = 0; cJSON *fiatjson; double bid,ask,start_DEXbase,start_DEXrel,USD_average=0.,DEX_base = 0.,DEX_rel = 0.,balance_base=0.,balance_rel=0.,mmbid,mmask,usdprice=0.,CMC_average=0.,aveprice,incr,pendingbids,pendingasks,buyvol,sellvol,bidincr,askincr,filledprice,avebid=0.,aveask=0.,val,changes[3],highbid=0.,lowask=0.,theoretical = 0.; uint32_t lasttime = 0;
incr = maxexposure * ratioincr; incr = maxexposure * ratioincr;
buyvol = sellvol = 0.; buyvol = sellvol = 0.;
start_DEXbase = dex_balance(base,baseaddr); start_DEXbase = dex_balance(base,baseaddr);
@ -636,8 +639,11 @@ void marketmaker(double minask,double maxbid,char *baseaddr,char *reladdr,double
mmask = 0.; mmask = 0.;
} }
marketmaker_volumeset(&bidincr,&askincr,incr,buyvol,pendingbids,sellvol,pendingasks,maxexposure); marketmaker_volumeset(&bidincr,&askincr,incr,buyvol,pendingbids,sellvol,pendingasks,maxexposure);
printf("AVE.(%.8f %.8f) hbla %.8f %.8f bid %.8f ask %.8f theory %.8f buys.(%.6f %.6f) sells.(%.6f %.6f) incr.(%.6f %.6f) balances.(%.8f + %.8f, %.8f + %.8f)\n",avebid,aveask,highbid,lowask,mmbid,mmask,theoretical,buyvol,pendingbids,sellvol,pendingasks,bidincr,askincr,balance_base,DEX_base,balance_rel,DEX_rel); printf("AVE.(%.8f %.8f) hbla %.8f %.8f bid %.8f ask %.8f theory %.8f buys.(%.6f %.6f) sells.(%.6f %.6f) incr.(%.6f %.6f) balances.(%.8f + %.8f, %.8f + %.8f) test %f\n",avebid,aveask,highbid,lowask,mmbid,mmask,theoretical,buyvol,pendingbids,sellvol,pendingasks,bidincr,askincr,balance_base,DEX_base,balance_rel,DEX_rel,(aveask - avebid)/aveprice);
marketmaker_spread("DEX",base,rel,avebid - profitmargin*aveprice,incr,aveask + profitmargin*aveprice,incr,profitmargin*aveprice*0.5); if ( (aveask - avebid)/aveprice > 4*profitmargin )
bid = highbid * (1 - 4*profitmargin), ask = lowask * (1 + 4*profitmargin);
else bid = avebid - profitmargin*aveprice, ask = avebid + profitmargin*aveprice;
marketmaker_spread("DEX",base,rel,bid,incr,ask,incr,profitmargin*aveprice*0.5);
if ( (pendingbids + buyvol) > (pendingasks + sellvol) ) if ( (pendingbids + buyvol) > (pendingasks + sellvol) )
{ {
bidincr *= (double)(pendingasks + sellvol) / ((pendingbids + buyvol) + (pendingasks + sellvol)); bidincr *= (double)(pendingasks + sellvol) / ((pendingbids + buyvol) + (pendingasks + sellvol));
@ -655,8 +661,8 @@ void marketmaker(double minask,double maxbid,char *baseaddr,char *reladdr,double
askincr = (int32_t)askincr + 0.777; askincr = (int32_t)askincr + 0.777;
} }
//printf("mmbid %.8f %.6f, mmask %.8f %.6f\n",mmbid,bidincr,mmask,askincr); //printf("mmbid %.8f %.6f, mmask %.8f %.6f\n",mmbid,bidincr,mmask,askincr);
marketmaker_spread(exchange,base,rel,mmbid,bidincr,mmask,askincr,profitmargin*aveprice*0.5); //marketmaker_spread(exchange,base,rel,mmbid,bidincr,mmask,askincr,profitmargin*aveprice*0.5);
sleep(60); sleep(6000);
} }
} }
} }
@ -707,7 +713,7 @@ int main(int argc, const char * argv[])
marketmaker(minask,maxbid,baseaddr,reladdr,start_base,start_rel,profitmargin,maxexposure,incrratio,exchange,name,base,rel); marketmaker(minask,maxbid,baseaddr,reladdr,start_base,start_rel,profitmargin,maxexposure,incrratio,exchange,name,base,rel);
} }
free_json(addrjson); free_json(addrjson);
} } else printf("ERROR parsing.(%s)\n",retstr);
free(retstr); free(retstr);
} }
free_json(retjson); free_json(retjson);

4
iguana/iguana_payments.c

@ -274,7 +274,7 @@ char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,int
memset(&msgtx,0,sizeof(msgtx)); memset(&msgtx,0,sizeof(msgtx));
if ( V == 0 ) if ( V == 0 )
V = calloc(numinputs,sizeof(*V)), flagV = 1; V = calloc(numinputs,sizeof(*V)), flagV = 1;
//printf("SIGN.(%s) priv.(%s) %llx %llx\n",jprint(vins,0),jprint(privkeys,0),(long long)V->signers[0].privkey.txid,(long long)V->signers[1].privkey.txid); //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);
if ( V != 0 ) if ( V != 0 )
{ {
if ( iguana_signrawtransaction(myinfo,coin,height,&msgtx,&signedtx,signedtxidp,V,numinputs,rawtx,vins,privkeys) > 0 ) if ( iguana_signrawtransaction(myinfo,coin,height,&msgtx,&signedtx,signedtxidp,V,numinputs,rawtx,vins,privkeys) > 0 )
@ -289,7 +289,7 @@ char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,int
if ( flag != 0 ) if ( flag != 0 )
free_json(privkeys); free_json(privkeys);
} }
//char str[65]; printf("completed.%d %s signed.(%s)\n",*completedp,bits256_str(str,*signedtxidp),signedtx!=0?signedtx:""); char str[65]; printf("completed.%d %s signed.(%s)\n",*completedp,bits256_str(str,*signedtxidp),signedtx!=0?signedtx:"");
return(signedtx); return(signedtx);
} }

47
iguana/iguana_sign.c

@ -581,7 +581,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
sigser = calloc(1,maxsize*2); sigser = calloc(1,maxsize*2);
//printf("json.%p array.%p sigser.%p\n",json,vinarray,sigser); //printf("json.%p array.%p sigser.%p\n",json,vinarray,sigser);
} }
//printf("version.%d\n",msg->version); printf("version.%d\n",msg->version);
if ( coin->chain->isPoS != 0 ) if ( coin->chain->isPoS != 0 )
{ {
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->timestamp),&msg->timestamp); len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->timestamp),&msg->timestamp);
@ -606,7 +606,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
} }
for (i=0; i<msg->tx_in; i++) for (i=0; i<msg->tx_in; i++)
{ {
//printf("vin.%d starts offset.%d\n",i,len); printf("vin.%d starts offset.%d\n",i,len);
if ( vins != 0 && jitem(vins,i) != 0 ) if ( vins != 0 && jitem(vins,i) != 0 )
iguana_vinobjset(&msg->vins[i],jitem(vins,i),spendscript,sizeof(spendscript)); iguana_vinobjset(&msg->vins[i],jitem(vins,i),spendscript,sizeof(spendscript));
if ( (n= iguana_vinparse(coin,rwflag,&serialized[len],&msg->vins[i])) < 0 ) if ( (n= iguana_vinparse(coin,rwflag,&serialized[len],&msg->vins[i])) < 0 )
@ -614,7 +614,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
//printf("serialized vin.[%02x %02x %02x]\n",serialized[len],serialized[len+1],serialized[len+2]); //printf("serialized vin.[%02x %02x %02x]\n",serialized[len],serialized[len+1],serialized[len+2]);
if ( msg->vins[i].spendscript == spendscript ) if ( msg->vins[i].spendscript == spendscript )
msg->vins[i].spendscript = 0; msg->vins[i].spendscript = 0;
//printf("vin.%d n.%d len.%d\n",i,n,len); printf("vin.%d n.%d len.%d\n",i,n,len);
len += n; len += n;
if ( len > maxsize ) if ( len > maxsize )
{ {
@ -624,7 +624,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
} }
//for (i=-3; i<7; i++) //for (i=-3; i<7; i++)
// printf("%02x",serialized[len+i]); // printf("%02x",serialized[len+i]);
//printf(" prev 3 bytes before tx_out rw.%d\n",rwflag); printf(" prev 3 bytes before tx_out rw.%d\n",rwflag);
len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_out); len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_out);
if ( rwflag == 0 ) if ( rwflag == 0 )
{ {
@ -644,7 +644,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
} }
for (i=0; i<msg->tx_out; i++) for (i=0; i<msg->tx_out; i++)
{ {
//printf("rwflag.%d vout.%d starts %d\n",rwflag,i,len); printf("rwflag.%d vout.%d starts %d\n",rwflag,i,len);
if ( (n= iguana_voutparse(rwflag,&serialized[len],&msg->vouts[i])) < 0 ) if ( (n= iguana_voutparse(rwflag,&serialized[len],&msg->vouts[i])) < 0 )
return(-1); return(-1);
len += n; len += n;
@ -657,7 +657,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)); jaddi(voutarray,iguana_voutjson(coin,&msg->vouts[i],i,*txidp));
} }
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time); 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 ) if ( strcmp(coin->symbol,"VPN") == 0 )
{ {
uint16_t ddosflag = 0; uint16_t ddosflag = 0;
@ -687,7 +687,7 @@ 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)); 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); 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)); 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));
jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid)); jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid));
if ( msg->vins[i].spendscript == spendscript ) if ( msg->vins[i].spendscript == spendscript )
msg->vins[i].spendscript = 0; msg->vins[i].spendscript = 0;
@ -708,7 +708,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
jaddnum(json,"locktime",msg->lock_time); jaddnum(json,"locktime",msg->lock_time);
jaddnum(json,"size",len); jaddnum(json,"size",len);
jaddbits256(json,"txid",*txidp); jaddbits256(json,"txid",*txidp);
//printf("TX.(%s) %p\n",jprint(json,0),json); printf("TX.(%s) %p\n",jprint(json,0),json);
} }
msg->allocsize = len; msg->allocsize = len;
return(len); return(len);
@ -825,6 +825,7 @@ cJSON *bitcoin_data2json(struct iguana_info *coin,int32_t height,bits256 *txidp,
memset(msgtx,0,sizeof(M)); memset(msgtx,0,sizeof(M));
vpnstr[0] = 0; vpnstr[0] = 0;
memset(txidp,0,sizeof(*txidp)); memset(txidp,0,sizeof(*txidp));
printf("call rwmsgtx\n");
if ( (n= iguana_rwmsgtx(coin,height,0,txobj,serialized,len,msgtx,txidp,vpnstr,extraspace,extralen,vins,suppress_pubkeys)) <= 0 ) if ( (n= iguana_rwmsgtx(coin,height,0,txobj,serialized,len,msgtx,txidp,vpnstr,extraspace,extralen,vins,suppress_pubkeys)) <= 0 )
{ {
printf("errortxobj.(%s)\n",jprint(txobj,0)); printf("errortxobj.(%s)\n",jprint(txobj,0));
@ -852,7 +853,9 @@ cJSON *bitcoin_hex2json(struct iguana_info *coin,int32_t height,bits256 *txidp,s
if ( (serialized= origserialized) == 0 ) if ( (serialized= origserialized) == 0 )
serialized = calloc(1,len+4096); serialized = calloc(1,len+4096);
decode_hex(serialized,len,txbytes); decode_hex(serialized,len,txbytes);
printf("call data2json\n");
txobj = bitcoin_data2json(coin,height,txidp,msgtx,extraspace,extralen,serialized,len,vins,suppress_pubkeys); txobj = bitcoin_data2json(coin,height,txidp,msgtx,extraspace,extralen,serialized,len,vins,suppress_pubkeys);
printf("back data2json %p\n",txobj);
if ( serialized != origserialized ) if ( serialized != origserialized )
free(serialized); free(serialized);
return(txobj); return(txobj);
@ -1420,33 +1423,18 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
extraspace = malloc(extralen); extraspace = malloc(extralen);
memset(msgtx,0,sizeof(*msgtx)); memset(msgtx,0,sizeof(*msgtx));
decode_hex(serialized,len,rawtx); decode_hex(serialized,len,rawtx);
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 ) if ( (txobj= bitcoin_hex2json(coin,height,&txid,msgtx,rawtx,extraspace,extralen,serialized4,vins,V->suppress_pubkeys)) != 0 )
{ {
if ( (0) && vins != 0 ) printf("back from bitcoin_hex2json\n");
printf("txobj.(%s)\n",jprint(txobj,0));
if ( jobj(txobj,"error") != 0 )
{
printf("txobj.(%s)\n",jprint(txobj,0));
}
if ( (0) && (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,V)) != 0 ) // no guarantee of identical regen
{
if ( strcmp(rawtx,checkstr) != 0 )
{
printf("RAW.(%s) ->\nNEW.(%s)\n",rawtx,checkstr);
//free_json(txobj);
//free(checkstr);
//free(serialized), free(serialized2), free(serialized3), free(serialized4);
//free(extraspace);
//return(-2);
}
free(checkstr);
}
} else fprintf(stderr,"no txobj from bitcoin_hex2json\n"); } else fprintf(stderr,"no txobj from bitcoin_hex2json\n");
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 ) if ( (numinputs= cJSON_GetArraySize(vins)) > 0 )
{ {
memset(msgtx,0,sizeof(*msgtx)); memset(msgtx,0,sizeof(*msgtx));
printf("call rwmsgtx vin0.scriptlen %d\n",msgtx->vins[0].scriptlen);
if ( iguana_rwmsgtx(coin,height,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,65536,vins,V->suppress_pubkeys) > 0 && numinputs == msgtx->tx_in ) 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\n");
memset(pubkeys,0,sizeof(pubkeys)); memset(pubkeys,0,sizeof(pubkeys));
memset(privkeys,0,sizeof(privkeys)); memset(privkeys,0,sizeof(privkeys));
if ( (n= cJSON_GetArraySize(privkeysjson)) > 0 ) if ( (n= cJSON_GetArraySize(privkeysjson)) > 0 )
@ -1463,6 +1451,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
iguana_ensure_privkey(myinfo,coin,privkey); iguana_ensure_privkey(myinfo,coin,privkey);
} }
} }
printf("after privkeys tx_in.%d\n",msgtx->tx_in);
for (i=0; i<msgtx->tx_in; i++) for (i=0; i<msgtx->tx_in; i++)
{ {
if ( msgtx->vins[i].p2shlen != 0 ) if ( msgtx->vins[i].p2shlen != 0 )
@ -1473,6 +1462,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
sigsize = 0; sigsize = 0;
flag = (msgtx->vins[i].vinscript[0] == 0); flag = (msgtx->vins[i].vinscript[0] == 0);
type = bitcoin_scriptget(coin,&hashtype,&sigsize,&pubkeysize,&userdata,&userdatalen,&mainvin,msgtx->vins[i].vinscript+flag,msgtx->vins[i].scriptlen-flag,0); type = bitcoin_scriptget(coin,&hashtype,&sigsize,&pubkeysize,&userdata,&userdatalen,&mainvin,msgtx->vins[i].vinscript+flag,msgtx->vins[i].scriptlen-flag,0);
printf("i.%d flag.%d type.%d scriptlen.%d\n",i,flag,type,msgtx->vins[i].scriptlen);
if ( flag != 0 && pubkeysize == 33 ) // jl777: need to generalize this if ( flag != 0 && pubkeysize == 33 ) // jl777: need to generalize this
{ {
for (k=0; k<sigsize; k++) for (k=0; k<sigsize; k++)
@ -1484,7 +1474,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
//for (j=0; j<msgtx->vins[i].p2shlen; j++) //for (j=0; j<msgtx->vins[i].p2shlen; j++)
// printf("%02x",msgtx->vins[i].redeemscript[j]); // printf("%02x",msgtx->vins[i].redeemscript[j]);
bitcoin_address(coinaddr,coin->chain->p2shtype,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen); bitcoin_address(coinaddr,coin->chain->p2shtype,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen);
type = iguana_calcrmd160(coin,0,&mvin,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen,zero,0,01); type = iguana_calcrmd160(coin,0,&mvin,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen,zero,0,0);
for (j=0; j<mvin.N; j++) for (j=0; j<mvin.N; j++)
{ {
if ( V->suppress_pubkeys == 0 ) if ( V->suppress_pubkeys == 0 )
@ -1520,6 +1510,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
printf("type.%d p2sh.[%d] -> %s M.%d N.%d\n",type,i,mvin.coinaddr,mvin.M,mvin.N); printf("type.%d p2sh.[%d] -> %s M.%d N.%d\n",type,i,mvin.coinaddr,mvin.M,mvin.N);
} }
} }
printf("tail end\n");
if ( i < V->N ) if ( i < V->N )
V->signers[i].privkey = privkey; V->signers[i].privkey = privkey;
if ( i < numinputs ) if ( i < numinputs )

Loading…
Cancel
Save