|
|
@ -454,7 +454,7 @@ bits256 iguana_str2priv(char *str) |
|
|
|
return(privkey); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t iguana_vininfo_create(uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msgtx,cJSON *vins,int32_t numinputs,struct vin_info *V) |
|
|
|
int32_t iguana_vininfo_create(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msgtx,cJSON *vins,int32_t numinputs,struct vin_info *V) |
|
|
|
{ |
|
|
|
int32_t i,plen,finalized = 1,len = 0; struct vin_info *vp; //struct iguana_waccount *wacct; struct iguana_waddress *waddr; uint32_t sigsize,pubkeysize,p2shsize,userdatalen;
|
|
|
|
msgtx->tx_in = numinputs; |
|
|
@ -486,9 +486,9 @@ int32_t iguana_vininfo_create(uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uin |
|
|
|
{ |
|
|
|
memcpy(vp->spendscript,msgtx->vins[i].spendscript,msgtx->vins[i].spendlen); |
|
|
|
vp->spendlen = msgtx->vins[i].spendlen; |
|
|
|
_iguana_calcrmd160(pubtype,p2shtype,vp); |
|
|
|
_iguana_calcrmd160(taddr,pubtype,p2shtype,vp); |
|
|
|
if ( (plen= bitcoin_pubkeylen(vp->signers[0].pubkey)) > 0 ) |
|
|
|
bitcoin_address(vp->coinaddr,pubtype,vp->signers[0].pubkey,plen); |
|
|
|
bitcoin_address(vp->coinaddr,taddr,pubtype,vp->signers[0].pubkey,plen); |
|
|
|
} |
|
|
|
if ( vp->M == 0 && vp->N == 0 ) |
|
|
|
vp->M = vp->N = 1; |
|
|
@ -506,7 +506,7 @@ int32_t iguana_vininfo_create(uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uin |
|
|
|
return(finalized); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t bitcoin_verifyvins(void *ctx,char *symbol,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,bits256 *signedtxidp,char **signedtx,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxlen,struct vin_info *V,uint32_t sighash,int32_t signtx,int32_t suppress_pubkeys) |
|
|
|
int32_t bitcoin_verifyvins(void *ctx,char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,bits256 *signedtxidp,char **signedtx,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxlen,struct vin_info *V,uint32_t sighash,int32_t signtx,int32_t suppress_pubkeys) |
|
|
|
{ |
|
|
|
bits256 sigtxid; uint8_t *sig,*script; struct vin_info *vp; char vpnstr[64]; int32_t scriptlen,complete=0,j,vini=0,flag=0,siglen,numvouts,numsigs; |
|
|
|
numvouts = msgtx->tx_out; |
|
|
@ -528,7 +528,7 @@ int32_t bitcoin_verifyvins(void *ctx,char *symbol,uint8_t pubtype,uint8_t p2shty |
|
|
|
script = msgtx->vins[vini].spendscript; |
|
|
|
scriptlen = msgtx->vins[vini].spendlen; |
|
|
|
} |
|
|
|
sigtxid = bitcoin_sigtxid(pubtype,p2shtype,isPoS,height,serialized,maxlen,msgtx,vini,script,scriptlen,sighash,vpnstr,suppress_pubkeys); |
|
|
|
sigtxid = bitcoin_sigtxid(taddr,pubtype,p2shtype,isPoS,height,serialized,maxlen,msgtx,vini,script,scriptlen,sighash,vpnstr,suppress_pubkeys); |
|
|
|
if ( bits256_nonz(sigtxid) != 0 ) |
|
|
|
{ |
|
|
|
vp = &V[vini]; |
|
|
@ -584,7 +584,7 @@ int32_t bitcoin_verifyvins(void *ctx,char *symbol,uint8_t pubtype,uint8_t p2shty |
|
|
|
} |
|
|
|
iguana_msgtx_Vset(serialized,maxlen,msgtx,V); |
|
|
|
cJSON *txobj = cJSON_CreateObject(); |
|
|
|
*signedtx = iguana_rawtxbytes(pubtype,p2shtype,isPoS,height,txobj,msgtx,suppress_pubkeys); |
|
|
|
*signedtx = iguana_rawtxbytes(taddr,pubtype,p2shtype,isPoS,height,txobj,msgtx,suppress_pubkeys); |
|
|
|
//printf("SIGNEDTX.(%s)\n",jprint(txobj,1));
|
|
|
|
*signedtxidp = msgtx->txid; |
|
|
|
return(complete); |
|
|
@ -598,7 +598,7 @@ int64_t iguana_lockval(int32_t finalized,int64_t locktime) |
|
|
|
return(lockval); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson) |
|
|
|
int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson) |
|
|
|
{ |
|
|
|
uint8_t *serialized,*serialized2,*serialized3,*serialized4,*extraspace,pubkeys[64][33]; int32_t finalized,i,len,n,z,plen,maxsize,complete = 0,extralen = 65536; char *privkeystr,*signedtx = 0; bits256 privkeys[64],privkey,txid; cJSON *item; cJSON *txobj = 0; |
|
|
|
maxsize = 1000000; |
|
|
@ -613,7 +613,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t pubtype,uint8_t |
|
|
|
memset(msgtx,0,sizeof(*msgtx)); |
|
|
|
decode_hex(serialized,len,rawtx); |
|
|
|
// printf("call hex2json.(%s) vins.(%s)\n",rawtx,jprint(vins,0));
|
|
|
|
if ( (txobj= bitcoin_hex2json(pubtype,p2shtype,isPoS,height,&txid,msgtx,rawtx,extraspace,extralen,serialized4,vins,V->suppress_pubkeys)) != 0 ) |
|
|
|
if ( (txobj= bitcoin_hex2json(taddr,pubtype,p2shtype,isPoS,height,&txid,msgtx,rawtx,extraspace,extralen,serialized4,vins,V->suppress_pubkeys)) != 0 ) |
|
|
|
{ |
|
|
|
//printf("back from bitcoin_hex2json (%s)\n",jprint(vins,0));
|
|
|
|
} else fprintf(stderr,"no txobj from bitcoin_hex2json\n"); |
|
|
@ -621,7 +621,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t pubtype,uint8_t |
|
|
|
{ |
|
|
|
//printf("numinputs.%d msgtx.%d\n",numinputs,msgtx->tx_in);
|
|
|
|
memset(msgtx,0,sizeof(*msgtx)); |
|
|
|
if ( iguana_rwmsgtx(pubtype,p2shtype,isPoS,height,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,65536,vins,V->suppress_pubkeys) > 0 && numinputs == msgtx->tx_in ) |
|
|
|
if ( iguana_rwmsgtx(taddr,pubtype,p2shtype,isPoS,height,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,65536,vins,V->suppress_pubkeys) > 0 && numinputs == msgtx->tx_in ) |
|
|
|
{ |
|
|
|
memset(pubkeys,0,sizeof(pubkeys)); |
|
|
|
memset(privkeys,0,sizeof(privkeys)); |
|
|
@ -649,14 +649,14 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t pubtype,uint8_t |
|
|
|
coinaddr[0] = 0; |
|
|
|
sigsize = 0; |
|
|
|
flag = (msgtx->vins[i].vinscript[0] == 0); |
|
|
|
type = bitcoin_scriptget(pubtype,p2shtype,&hashtype,&sigsize,&pubkeysize,&userdata,&userdatalen,&mainvin,msgtx->vins[i].vinscript+flag,msgtx->vins[i].scriptlen-flag,0); |
|
|
|
type = bitcoin_scriptget(taddr,pubtype,p2shtype,&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 ( msgtx->vins[i].redeemscript != 0 ) |
|
|
|
{ |
|
|
|
//for (j=0; j<msgtx->vins[i].p2shlen; j++)
|
|
|
|
// printf("%02x",msgtx->vins[i].redeemscript[j]);
|
|
|
|
bitcoin_address(coinaddr,p2shtype,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen); |
|
|
|
type = iguana_calcrmd160(pubtype,p2shtype,0,&mvin,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen,zero,0,0); |
|
|
|
bitcoin_address(coinaddr,taddr,p2shtype,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen); |
|
|
|
type = iguana_calcrmd160(taddr,pubtype,p2shtype,0,&mvin,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen,zero,0,0); |
|
|
|
for (j=0; j<mvin.N; j++) |
|
|
|
{ |
|
|
|
if ( V->suppress_pubkeys == 0 ) |
|
|
@ -706,9 +706,9 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t pubtype,uint8_t |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
finalized = iguana_vininfo_create(pubtype,p2shtype,isPoS,serialized2,maxsize,msgtx,vins,numinputs,V); |
|
|
|
finalized = iguana_vininfo_create(taddr,pubtype,p2shtype,isPoS,serialized2,maxsize,msgtx,vins,numinputs,V); |
|
|
|
//printf("finalized.%d ignore_cltverr.%d suppress.%d\n",finalized,V[0].ignore_cltverr,V[0].suppress_pubkeys);
|
|
|
|
if ( (complete= bitcoin_verifyvins(ctx,symbol,pubtype,p2shtype,isPoS,height,signedtxidp,&signedtx,msgtx,serialized3,maxsize,V,SIGHASH_ALL,1,V->suppress_pubkeys)) > 0 && signedtx != 0 ) |
|
|
|
if ( (complete= bitcoin_verifyvins(ctx,symbol,taddr,pubtype,p2shtype,isPoS,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(ctx,cJSON_CreateArray(),iguana_lockval(finalized,jint(txobj,"locktime")),V,numinputs)) < 0 ) |
|
|
@ -728,7 +728,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t pubtype,uint8_t |
|
|
|
return(complete); |
|
|
|
} |
|
|
|
|
|
|
|
char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,char *symbol,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,void *ctx,bits256 privkey,bits256 *privkey2p,uint8_t *redeemscript,int32_t redeemlen,uint8_t *userdata,int32_t userdatalen,bits256 utxotxid,int32_t vout,char *destaddr,uint8_t *pubkey33,int32_t finalseqid,uint32_t expiration,int64_t *destamountp,uint64_t satoshis,char *changeaddr,char *vinaddr,int32_t suppress_pubkeys) |
|
|
|
char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,void *ctx,bits256 privkey,bits256 *privkey2p,uint8_t *redeemscript,int32_t redeemlen,uint8_t *userdata,int32_t userdatalen,bits256 utxotxid,int32_t vout,char *destaddr,uint8_t *pubkey33,int32_t finalseqid,uint32_t expiration,int64_t *destamountp,uint64_t satoshis,char *changeaddr,char *vinaddr,int32_t suppress_pubkeys) |
|
|
|
{ |
|
|
|
char *rawtxbytes=0,*signedtx=0,tmpaddr[64],hexstr[999],wifstr[128],txdestaddr[64],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*item,*privkeys; int32_t completed,spendlen,ignore_cltverr=1; struct vin_info V[2]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value,change = 0; struct iguana_msgtx msgtx; |
|
|
|
*destamountp = 0; |
|
|
@ -789,14 +789,14 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch |
|
|
|
} |
|
|
|
jaddbits256(item,"txid",utxotxid); |
|
|
|
jaddnum(item,"vout",vout); |
|
|
|
bitcoin_address(tmpaddr,pubtype,pubkey33,33); |
|
|
|
bitcoin_addr2rmd160(&addrtype,rmd160,tmpaddr); |
|
|
|
bitcoin_address(tmpaddr,taddr,pubtype,pubkey33,33); |
|
|
|
bitcoin_addr2rmd160(taddr,&addrtype,rmd160,tmpaddr); |
|
|
|
if ( redeemlen != 0 ) |
|
|
|
{ |
|
|
|
init_hexbytes_noT(hexstr,redeemscript,redeemlen); |
|
|
|
jaddstr(item,"redeemScript",hexstr); |
|
|
|
if ( vinaddr != 0 ) |
|
|
|
bitcoin_addr2rmd160(&addrtype,rmd160,vinaddr); |
|
|
|
bitcoin_addr2rmd160(taddr,&addrtype,rmd160,vinaddr); |
|
|
|
spendlen = bitcoin_p2shspend(spendscript,0,rmd160); |
|
|
|
//printf("P2SH path.%s\n",vinaddr!=0?vinaddr:0);
|
|
|
|
} else spendlen = bitcoin_standardspend(spendscript,0,rmd160); |
|
|
@ -810,9 +810,9 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch |
|
|
|
if ( destaddr == 0 ) |
|
|
|
{ |
|
|
|
destaddr = _destaddr; |
|
|
|
bitcoin_address(destaddr,pubtype,pubkey33,33); |
|
|
|
bitcoin_address(destaddr,taddr,pubtype,pubkey33,33); |
|
|
|
} |
|
|
|
bitcoin_addr2rmd160(&addrtype,rmd160,destaddr); |
|
|
|
bitcoin_addr2rmd160(taddr,&addrtype,rmd160,destaddr); |
|
|
|
if ( addrtype == p2shtype ) |
|
|
|
spendlen = bitcoin_p2shspend(spendscript,0,rmd160); |
|
|
|
else spendlen = bitcoin_standardspend(spendscript,0,rmd160); |
|
|
@ -826,7 +826,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch |
|
|
|
if ( change != 0 ) |
|
|
|
{ |
|
|
|
int32_t changelen; uint8_t changescript[1024],changetype,changermd160[20]; |
|
|
|
bitcoin_addr2rmd160(&changetype,changermd160,changeaddr); |
|
|
|
bitcoin_addr2rmd160(taddr,&changetype,changermd160,changeaddr); |
|
|
|
changelen = bitcoin_standardspend(changescript,0,changermd160); |
|
|
|
txobj = bitcoin_txoutput(txobj,changescript,changelen,change); |
|
|
|
} |
|
|
@ -836,7 +836,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch |
|
|
|
completed = 0; |
|
|
|
memset(signedtxidp,0,sizeof(*signedtxidp)); |
|
|
|
//printf("locktime.%u sequenceid.%x rawtx.(%s) vins.(%s)\n",locktime,sequenceid,rawtxbytes,jprint(vins,0));
|
|
|
|
if ( (completed= iguana_signrawtransaction(ctx,symbol,pubtype,p2shtype,isPoS,1000000,&msgtx,&signedtx,signedtxidp,V,1,rawtxbytes,vins,privkeys)) < 0 ) |
|
|
|
if ( (completed= iguana_signrawtransaction(ctx,symbol,taddr,pubtype,p2shtype,isPoS,1000000,&msgtx,&signedtx,signedtxidp,V,1,rawtxbytes,vins,privkeys)) < 0 ) |
|
|
|
//if ( (signedtx= LP_signrawtx(symbol,signedtxidp,&completed,vins,rawtxbytes,privkeys,V)) == 0 )
|
|
|
|
printf("couldnt sign transaction.%s %s\n",name,bits256_str(str,*signedtxidp)); |
|
|
|
else if ( completed == 0 ) |
|
|
@ -862,12 +862,12 @@ int32_t basilisk_rawtx_gen(void *ctx,char *str,uint32_t swapstarted,uint8_t *pub |
|
|
|
if ( changermd160 != 0 ) |
|
|
|
{ |
|
|
|
changeaddr = _changeaddr; |
|
|
|
bitcoin_address(changeaddr,coin->pubtype,changermd160,20); |
|
|
|
bitcoin_address(changeaddr,coin->taddr,coin->pubtype,changermd160,20); |
|
|
|
//printf("changeaddr.(%s) vs destaddr.(%s)\n",changeaddr,rawtx->I.destaddr);
|
|
|
|
} |
|
|
|
for (iter=0; iter<2; iter++) |
|
|
|
{ |
|
|
|
if ( (signedtx= basilisk_swap_bobtxspend(&rawtx->I.signedtxid,iter == 0 ? txfee : newtxfee,str,coin->symbol,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,ctx,privkey,0,0,0,0,0,rawtx->utxotxid,rawtx->utxovout,rawtx->I.destaddr,pubkey33,1,0,&destamount,rawtx->I.amount,changeaddr,vinaddr,rawtx->I.suppress_pubkeys)) != 0 ) |
|
|
|
if ( (signedtx= basilisk_swap_bobtxspend(&rawtx->I.signedtxid,iter == 0 ? txfee : newtxfee,str,coin->symbol,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,ctx,privkey,0,0,0,0,0,rawtx->utxotxid,rawtx->utxovout,rawtx->I.destaddr,pubkey33,1,0,&destamount,rawtx->I.amount,changeaddr,vinaddr,rawtx->I.suppress_pubkeys)) != 0 ) |
|
|
|
{ |
|
|
|
rawtx->I.datalen = (int32_t)strlen(signedtx) >> 1; |
|
|
|
if ( rawtx->I.datalen <= sizeof(rawtx->txbytes) ) |
|
|
@ -891,7 +891,7 @@ int32_t basilisk_rawtx_gen(void *ctx,char *str,uint32_t swapstarted,uint8_t *pub |
|
|
|
return(retval); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t basilisk_rawtx_sign(char *symbol,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,struct basilisk_swap *swap,struct basilisk_rawtx *dest,struct basilisk_rawtx *rawtx,bits256 privkey,bits256 *privkey2,uint8_t *userdata,int32_t userdatalen,int32_t ignore_cltverr,uint8_t *changermd160,char *vinaddr) |
|
|
|
int32_t basilisk_rawtx_sign(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,struct basilisk_swap *swap,struct basilisk_rawtx *dest,struct basilisk_rawtx *rawtx,bits256 privkey,bits256 *privkey2,uint8_t *userdata,int32_t userdatalen,int32_t ignore_cltverr,uint8_t *changermd160,char *vinaddr) |
|
|
|
{ |
|
|
|
char *signedtx,*changeaddr = 0,_changeaddr[64]; int64_t txfee,newtxfee=0,destamount; uint32_t timestamp,locktime=0,sequenceid = 0xffffffff; int32_t iter,retval = -1; double estimatedrate; |
|
|
|
//char str2[65]; printf("%s rawtxsign.(%s/v%d)\n",dest->name,bits256_str(str2,dest->utxotxid),dest->utxovout);
|
|
|
@ -904,12 +904,12 @@ int32_t basilisk_rawtx_sign(char *symbol,uint8_t pubtype,uint8_t p2shtype,uint8_ |
|
|
|
if ( changermd160 != 0 ) |
|
|
|
{ |
|
|
|
changeaddr = _changeaddr; |
|
|
|
bitcoin_address(changeaddr,pubtype,changermd160,20); |
|
|
|
bitcoin_address(changeaddr,taddr,pubtype,changermd160,20); |
|
|
|
//printf("changeaddr.(%s)\n",changeaddr);
|
|
|
|
} |
|
|
|
for (iter=0; iter<2; iter++) |
|
|
|
{ |
|
|
|
if ( (signedtx= basilisk_swap_bobtxspend(&dest->I.signedtxid,iter == 0 ? txfee : newtxfee,rawtx->name,symbol,pubtype,p2shtype,isPoS,wiftype,swap->ctx,privkey,privkey2,rawtx->redeemscript,rawtx->I.redeemlen,userdata,userdatalen,dest->utxotxid,dest->utxovout,dest->I.destaddr,rawtx->I.pubkey33,1,0,&destamount,rawtx->I.amount,changeaddr,vinaddr,dest->I.suppress_pubkeys)) != 0 ) |
|
|
|
if ( (signedtx= basilisk_swap_bobtxspend(&dest->I.signedtxid,iter == 0 ? txfee : newtxfee,rawtx->name,symbol,taddr,pubtype,p2shtype,isPoS,wiftype,swap->ctx,privkey,privkey2,rawtx->redeemscript,rawtx->I.redeemlen,userdata,userdatalen,dest->utxotxid,dest->utxovout,dest->I.destaddr,rawtx->I.pubkey33,1,0,&destamount,rawtx->I.amount,changeaddr,vinaddr,dest->I.suppress_pubkeys)) != 0 ) |
|
|
|
{ |
|
|
|
dest->I.datalen = (int32_t)strlen(signedtx) >> 1; |
|
|
|
if ( dest->I.datalen <= sizeof(dest->txbytes) ) |
|
|
@ -929,7 +929,7 @@ int32_t basilisk_rawtx_sign(char *symbol,uint8_t pubtype,uint8_t p2shtype,uint8_ |
|
|
|
//return(_basilisk_rawtx_sign(symbol,pubtype,p2shtype,isPoS,wiftype,swap,timestamp,locktime,sequenceid,dest,rawtx,privkey,privkey2,userdata,userdatalen,ignore_cltverr));
|
|
|
|
} |
|
|
|
|
|
|
|
int32_t basilisk_alicescript(uint8_t *redeemscript,int32_t *redeemlenp,uint8_t *script,int32_t n,char *msigaddr,uint8_t altps2h,bits256 pubAm,bits256 pubBn) |
|
|
|
int32_t basilisk_alicescript(uint8_t *redeemscript,int32_t *redeemlenp,uint8_t *script,int32_t n,char *msigaddr,uint8_t taddr,uint8_t altps2h,bits256 pubAm,bits256 pubBn) |
|
|
|
{ |
|
|
|
uint8_t p2sh160[20]; struct vin_info V; |
|
|
|
memset(&V,0,sizeof(V)); |
|
|
@ -937,7 +937,7 @@ int32_t basilisk_alicescript(uint8_t *redeemscript,int32_t *redeemlenp,uint8_t * |
|
|
|
memcpy(&V.signers[1].pubkey[1],pubBn.bytes,sizeof(pubBn)), V.signers[1].pubkey[0] = 0x03; |
|
|
|
V.M = V.N = 2; |
|
|
|
*redeemlenp = bitcoin_MofNspendscript(p2sh160,redeemscript,n,&V); |
|
|
|
bitcoin_address(msigaddr,altps2h,p2sh160,sizeof(p2sh160)); |
|
|
|
bitcoin_address(msigaddr,taddr,altps2h,p2sh160,sizeof(p2sh160)); |
|
|
|
n = bitcoin_p2shspend(script,0,p2sh160); |
|
|
|
//for (i=0; i<*redeemlenp; i++)
|
|
|
|
// printf("%02x",redeemscript[i]);
|
|
|
@ -945,7 +945,7 @@ int32_t basilisk_alicescript(uint8_t *redeemscript,int32_t *redeemlenp,uint8_t * |
|
|
|
return(n); |
|
|
|
} |
|
|
|
|
|
|
|
char *basilisk_swap_Aspend(char *name,char *symbol,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,void *ctx,bits256 privAm,bits256 privBn,bits256 utxotxid,int32_t vout,uint8_t pubkey33[33],uint32_t expiration,int64_t *destamountp,char *vinaddr) |
|
|
|
char *basilisk_swap_Aspend(char *name,char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,void *ctx,bits256 privAm,bits256 privBn,bits256 utxotxid,int32_t vout,uint8_t pubkey33[33],uint32_t expiration,int64_t *destamountp,char *vinaddr) |
|
|
|
{ |
|
|
|
char msigaddr[64],*signedtx = 0; int32_t spendlen,redeemlen; uint8_t tmp33[33],redeemscript[512],spendscript[128]; bits256 pubAm,pubBn,signedtxid; uint64_t txfee; |
|
|
|
if ( bits256_nonz(privAm) != 0 && bits256_nonz(privBn) != 0 ) |
|
|
@ -955,7 +955,7 @@ char *basilisk_swap_Aspend(char *name,char *symbol,uint8_t pubtype,uint8_t p2sht |
|
|
|
//char str[65];
|
|
|
|
//printf("pubAm.(%s)\n",bits256_str(str,pubAm));
|
|
|
|
//printf("pubBn.(%s)\n",bits256_str(str,pubBn));
|
|
|
|
spendlen = basilisk_alicescript(redeemscript,&redeemlen,spendscript,0,msigaddr,p2shtype,pubAm,pubBn); |
|
|
|
spendlen = basilisk_alicescript(redeemscript,&redeemlen,spendscript,0,msigaddr,taddr,p2shtype,pubAm,pubBn); |
|
|
|
//char str[65]; printf("%s utxo.(%s) redeemlen.%d spendlen.%d\n",msigaddr,bits256_str(str,utxotxid),redeemlen,spendlen);
|
|
|
|
/*rev = privAm;
|
|
|
|
for (i=0; i<32; i++) |
|
|
@ -964,7 +964,7 @@ char *basilisk_swap_Aspend(char *name,char *symbol,uint8_t pubtype,uint8_t p2sht |
|
|
|
for (i=0; i<32; i++) |
|
|
|
privBn.bytes[i] = rev.bytes[31 - i];*/ |
|
|
|
txfee = LP_txfee(symbol); |
|
|
|
signedtx = basilisk_swap_bobtxspend(&signedtxid,txfee,name,symbol,pubtype,p2shtype,isPoS,wiftype,ctx,privAm,&privBn,redeemscript,redeemlen,0,0,utxotxid,vout,0,pubkey33,1,expiration,destamountp,0,0,vinaddr,1); |
|
|
|
signedtx = basilisk_swap_bobtxspend(&signedtxid,txfee,name,symbol,taddr,pubtype,p2shtype,isPoS,wiftype,ctx,privAm,&privBn,redeemscript,redeemlen,0,0,utxotxid,vout,0,pubkey33,1,expiration,destamountp,0,0,vinaddr,1); |
|
|
|
} |
|
|
|
return(signedtx); |
|
|
|
} |
|
|
@ -1322,7 +1322,7 @@ int32_t basilisk_bobpayment_reclaim(struct basilisk_swap *swap,int32_t delay) |
|
|
|
len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[1],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); |
|
|
|
memcpy(swap->I.userdata_bobreclaim,userdata,len); |
|
|
|
swap->I.userdata_bobreclaimlen = len; |
|
|
|
if ( (retval= basilisk_rawtx_sign(swap->bobcoin.symbol,swap->bobcoin.pubtype,swap->bobcoin.p2shtype,swap->bobcoin.isPoS,swap->bobcoin.wiftype,swap,&swap->bobreclaim,&swap->bobpayment,swap->I.myprivs[1],0,userdata,len,1,swap->changermd160,swap->bobpayment.I.destaddr)) == 0 ) |
|
|
|
if ( (retval= basilisk_rawtx_sign(swap->bobcoin.symbol,swap->bobcoin.taddr,swap->bobcoin.pubtype,swap->bobcoin.p2shtype,swap->bobcoin.isPoS,swap->bobcoin.wiftype,swap,&swap->bobreclaim,&swap->bobpayment,swap->I.myprivs[1],0,userdata,len,1,swap->changermd160,swap->bobpayment.I.destaddr)) == 0 ) |
|
|
|
{ |
|
|
|
//for (i=0; i<swap->bobreclaim.I.datalen; i++)
|
|
|
|
// printf("%02x",swap->bobreclaim.txbytes[i]);
|
|
|
@ -1339,7 +1339,7 @@ int32_t basilisk_bobdeposit_refund(struct basilisk_swap *swap,int32_t delay) |
|
|
|
len = basilisk_swapuserdata(userdata,swap->I.privBn,0,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); |
|
|
|
memcpy(swap->I.userdata_bobrefund,userdata,len); |
|
|
|
swap->I.userdata_bobrefundlen = len; |
|
|
|
if ( (retval= basilisk_rawtx_sign(swap->bobcoin.symbol,swap->bobcoin.pubtype,swap->bobcoin.p2shtype,swap->bobcoin.isPoS,swap->bobcoin.wiftype,swap,&swap->bobrefund,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,0,swap->changermd160,swap->bobdeposit.I.destaddr)) == 0 ) |
|
|
|
if ( (retval= basilisk_rawtx_sign(swap->bobcoin.symbol,swap->bobcoin.taddr,swap->bobcoin.pubtype,swap->bobcoin.p2shtype,swap->bobcoin.isPoS,swap->bobcoin.wiftype,swap,&swap->bobrefund,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,0,swap->changermd160,swap->bobdeposit.I.destaddr)) == 0 ) |
|
|
|
{ |
|
|
|
for (i=0; i<swap->bobrefund.I.datalen; i++) |
|
|
|
printf("%02x",swap->bobrefund.txbytes[i]); |
|
|
@ -1353,13 +1353,13 @@ int32_t basilisk_bobdeposit_refund(struct basilisk_swap *swap,int32_t delay) |
|
|
|
int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,int32_t genflag) |
|
|
|
{ |
|
|
|
int32_t j; char coinaddr[64]; |
|
|
|
bitcoin_address(coinaddr,swap->bobcoin.pubtype,swap->changermd160,20); |
|
|
|
bitcoin_address(coinaddr,swap->bobcoin.taddr,swap->bobcoin.pubtype,swap->changermd160,20); |
|
|
|
if ( genflag != 0 && swap->I.iambob == 0 ) |
|
|
|
printf("basilisk_bobscripts_set WARNING: alice generating BOB tx\n"); |
|
|
|
if ( depositflag == 0 ) |
|
|
|
{ |
|
|
|
swap->bobpayment.I.spendlen = basilisk_bobscript(swap->bobpayment.I.rmd160,swap->bobpayment.redeemscript,&swap->bobpayment.I.redeemlen,swap->bobpayment.spendscript,0,&swap->bobpayment.I.locktime,&swap->bobpayment.I.secretstart,&swap->I,0); |
|
|
|
bitcoin_address(swap->bobpayment.p2shaddr,swap->bobcoin.p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); |
|
|
|
bitcoin_address(swap->bobpayment.p2shaddr,swap->bobcoin.taddr,swap->bobcoin.p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); |
|
|
|
strcpy(swap->bobpayment.I.destaddr,swap->bobpayment.p2shaddr); |
|
|
|
//LP_importaddress(swap->bobcoin.symbol,swap->bobpayment.I.destaddr);
|
|
|
|
//int32_t i; for (i=0; i<swap->bobpayment.I.redeemlen; i++)
|
|
|
@ -1391,7 +1391,7 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i |
|
|
|
else |
|
|
|
{ |
|
|
|
swap->bobdeposit.I.spendlen = basilisk_bobscript(swap->bobdeposit.I.rmd160,swap->bobdeposit.redeemscript,&swap->bobdeposit.I.redeemlen,swap->bobdeposit.spendscript,0,&swap->bobdeposit.I.locktime,&swap->bobdeposit.I.secretstart,&swap->I,1); |
|
|
|
bitcoin_address(swap->bobdeposit.p2shaddr,swap->bobcoin.p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); |
|
|
|
bitcoin_address(swap->bobdeposit.p2shaddr,swap->bobcoin.taddr,swap->bobcoin.p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); |
|
|
|
strcpy(swap->bobdeposit.I.destaddr,swap->bobdeposit.p2shaddr); |
|
|
|
//LP_importaddress(swap->bobcoin.symbol,swap->bobdeposit.I.destaddr);
|
|
|
|
//int32_t i; for (i=0; i<swap->bobdeposit.I.redeemlen; i++)
|
|
|
@ -1424,7 +1424,7 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i |
|
|
|
void LP_swap_coinaddr(struct basilisk_swap *swap,struct iguana_info *coin,char *coinaddr,uint8_t *data,int32_t datalen) |
|
|
|
{ |
|
|
|
cJSON *txobj,*vouts,*vout,*addresses,*item,*skey; uint8_t extraspace[8192]; bits256 signedtxid; struct iguana_msgtx msgtx; char *addr; int32_t n,m,suppress_pubkeys = 0; |
|
|
|
if ( (txobj= bitcoin_data2json(coin->pubtype,coin->p2shtype,coin->isPoS,coin->longestchain,&signedtxid,&msgtx,extraspace,sizeof(extraspace),data,datalen,0,suppress_pubkeys)) != 0 ) |
|
|
|
if ( (txobj= bitcoin_data2json(coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->longestchain,&signedtxid,&msgtx,extraspace,sizeof(extraspace),data,datalen,0,suppress_pubkeys)) != 0 ) |
|
|
|
{ |
|
|
|
//char str[65]; printf("got txid.%s (%s)\n",bits256_str(str,signedtxid),jprint(txobj,0));
|
|
|
|
if ( (vouts= jarray(&n,txobj,"vout")) != 0 && n > 0 ) |
|
|
@ -1480,14 +1480,14 @@ int32_t basilisk_alicepayment_spend(struct basilisk_swap *swap,struct basilisk_r |
|
|
|
void basilisk_alicepayment(struct basilisk_swap *swap,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn) |
|
|
|
{ |
|
|
|
char coinaddr[64]; |
|
|
|
alicepayment->I.spendlen = basilisk_alicescript(alicepayment->redeemscript,&alicepayment->I.redeemlen,alicepayment->spendscript,0,alicepayment->I.destaddr,coin->p2shtype,pubAm,pubBn); |
|
|
|
alicepayment->I.spendlen = basilisk_alicescript(alicepayment->redeemscript,&alicepayment->I.redeemlen,alicepayment->spendscript,0,alicepayment->I.destaddr,coin->taddr,coin->p2shtype,pubAm,pubBn); |
|
|
|
/*for (i=0; i<33; i++)
|
|
|
|
printf("%02x",swap->persistent_pubkey33[i]); |
|
|
|
printf(" pubkey33, "); |
|
|
|
for (i=0; i<20; i++) |
|
|
|
printf("%02x",swap->changermd160[i]); |
|
|
|
printf(" rmd160, ");*/ |
|
|
|
bitcoin_address(coinaddr,coin->pubtype,swap->changermd160,20); |
|
|
|
bitcoin_address(coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20); |
|
|
|
//printf("%s suppress.%d fee.%d\n",coinaddr,alicepayment->I.suppress_pubkeys,swap->myfee.I.suppress_pubkeys);
|
|
|
|
basilisk_rawtx_gen(swap->ctx,"alicepayment",swap->I.started,swap->persistent_pubkey33,0,1,alicepayment,alicepayment->I.locktime,alicepayment->spendscript,alicepayment->I.spendlen,coin->txfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr); |
|
|
|
} |
|
|
@ -1501,7 +1501,7 @@ int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *d |
|
|
|
printf("error alice generating payment.%d\n",swap->alicepayment.I.spendlen); |
|
|
|
else |
|
|
|
{ |
|
|
|
bitcoin_address(swap->alicepayment.I.destaddr,swap->alicecoin.p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen); |
|
|
|
bitcoin_address(swap->alicepayment.I.destaddr,swap->alicecoin.taddr,swap->alicecoin.p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen); |
|
|
|
//LP_importaddress(swap->alicecoin.symbol,swap->alicepayment.I.destaddr);
|
|
|
|
strcpy(swap->alicepayment.p2shaddr,swap->alicepayment.I.destaddr); |
|
|
|
retval = 0; |
|
|
@ -1515,7 +1515,7 @@ int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *d |
|
|
|
if ( swap->myfee.I.datalen == 0 ) |
|
|
|
{ |
|
|
|
printf("generate fee\n"); |
|
|
|
bitcoin_address(coinaddr,swap->alicecoin.pubtype,swap->changermd160,20); |
|
|
|
bitcoin_address(coinaddr,swap->alicecoin.taddr,swap->alicecoin.pubtype,swap->changermd160,20); |
|
|
|
if ( basilisk_rawtx_gen(swap->ctx,"myfee",swap->I.started,swap->persistent_pubkey33,swap->I.iambob,1,&swap->myfee,0,swap->myfee.spendscript,swap->myfee.I.spendlen,swap->myfee.coin->txfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr) == 0 ) |
|
|
|
{ |
|
|
|
printf("rawtxsend\n"); |
|
|
@ -1567,7 +1567,7 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da |
|
|
|
len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); |
|
|
|
memcpy(swap->I.userdata_aliceclaim,userdata,len); |
|
|
|
swap->I.userdata_aliceclaimlen = len; |
|
|
|
bitcoin_address(swap->bobdeposit.p2shaddr,swap->bobcoin.p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); |
|
|
|
bitcoin_address(swap->bobdeposit.p2shaddr,swap->bobcoin.taddr,swap->bobcoin.p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); |
|
|
|
strcpy(swap->bobdeposit.I.destaddr,swap->bobdeposit.p2shaddr); |
|
|
|
//LP_importaddress(swap->bobcoin.symbol,swap->bobdeposit.I.destaddr);
|
|
|
|
/*for (i=0; i<swap->bobdeposit.I.datalen; i++)
|
|
|
@ -1579,9 +1579,9 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da |
|
|
|
memcpy(swap->aliceclaim.redeemscript,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); |
|
|
|
swap->aliceclaim.I.redeemlen = swap->bobdeposit.I.redeemlen; |
|
|
|
memcpy(swap->aliceclaim.I.pubkey33,swap->persistent_pubkey33,33); |
|
|
|
bitcoin_address(swap->aliceclaim.I.destaddr,swap->alicecoin.pubtype,swap->persistent_pubkey33,33); |
|
|
|
bitcoin_address(swap->aliceclaim.I.destaddr,swap->alicecoin.taddr,swap->alicecoin.pubtype,swap->persistent_pubkey33,33); |
|
|
|
retval = 0; |
|
|
|
if ( (retval= basilisk_rawtx_sign(swap->bobcoin.symbol,swap->bobcoin.pubtype,swap->bobcoin.p2shtype,swap->bobcoin.isPoS,swap->bobcoin.wiftype,swap,&swap->aliceclaim,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->bobdeposit.I.destaddr)) == 0 ) |
|
|
|
if ( (retval= basilisk_rawtx_sign(swap->bobcoin.symbol,swap->bobcoin.taddr,swap->bobcoin.pubtype,swap->bobcoin.p2shtype,swap->bobcoin.isPoS,swap->bobcoin.wiftype,swap,&swap->aliceclaim,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->bobdeposit.I.destaddr)) == 0 ) |
|
|
|
{ |
|
|
|
/*for (i=0; i<swap->bobdeposit.I.datalen; i++)
|
|
|
|
printf("%02x",swap->bobdeposit.txbytes[i]); |
|
|
@ -1603,7 +1603,7 @@ int32_t LP_verify_alicepayment(struct basilisk_swap *swap,uint8_t *data,int32_t |
|
|
|
{ |
|
|
|
swap->bobspend.utxovout = 0; |
|
|
|
swap->bobspend.utxotxid = swap->alicepayment.I.signedtxid = LP_broadcast_tx(swap->alicepayment.name,swap->alicecoin.symbol,swap->alicepayment.txbytes,swap->alicepayment.I.datalen); |
|
|
|
bitcoin_address(swap->alicepayment.p2shaddr,swap->alicecoin.p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen); |
|
|
|
bitcoin_address(swap->alicepayment.p2shaddr,swap->alicecoin.taddr,swap->alicecoin.p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen); |
|
|
|
strcpy(swap->alicepayment.I.destaddr,swap->alicepayment.p2shaddr); |
|
|
|
if ( bits256_nonz(swap->alicepayment.I.signedtxid) != 0 ) |
|
|
|
swap->aliceunconf = 1; |
|
|
@ -1631,7 +1631,7 @@ int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t da |
|
|
|
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); |
|
|
|
bitcoin_address(swap->bobpayment.p2shaddr,swap->bobcoin.p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); |
|
|
|
bitcoin_address(swap->bobpayment.p2shaddr,swap->bobcoin.taddr,swap->bobcoin.p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); |
|
|
|
strcpy(swap->bobpayment.I.destaddr,swap->bobpayment.p2shaddr); |
|
|
|
//LP_importaddress(swap->bobcoin.symbol,swap->bobpayment.I.destaddr);
|
|
|
|
/*for (i=0; i<swap->bobpayment.I.datalen; i++)
|
|
|
@ -1644,9 +1644,9 @@ int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t da |
|
|
|
swap->I.userdata_alicespendlen = len; |
|
|
|
retval = 0; |
|
|
|
memcpy(swap->alicespend.I.pubkey33,swap->persistent_pubkey33,33); |
|
|
|
bitcoin_address(swap->alicespend.I.destaddr,swap->bobcoin.pubtype,swap->persistent_pubkey33,33); |
|
|
|
bitcoin_address(swap->alicespend.I.destaddr,swap->bobcoin.taddr,swap->bobcoin.pubtype,swap->persistent_pubkey33,33); |
|
|
|
//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(swap->bobcoin.symbol,swap->bobcoin.pubtype,swap->bobcoin.p2shtype,swap->bobcoin.isPoS,swap->bobcoin.wiftype,swap,&swap->alicespend,&swap->bobpayment,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->alicepayment.I.destaddr)) == 0 ) |
|
|
|
if ( (retval= basilisk_rawtx_sign(swap->bobcoin.symbol,swap->bobcoin.taddr,swap->bobcoin.pubtype,swap->bobcoin.p2shtype,swap->bobcoin.isPoS,swap->bobcoin.wiftype,swap,&swap->alicespend,&swap->bobpayment,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->alicepayment.I.destaddr)) == 0 ) |
|
|
|
{ |
|
|
|
/*for (i=0; i<swap->bobpayment.I.datalen; i++)
|
|
|
|
printf("%02x",swap->bobpayment.txbytes[i]); |
|
|
|