jl777 8 years ago
parent
commit
5a202da84b
  1. 5
      basilisk/basilisk.h
  2. 199
      basilisk/basilisk_swap.c
  3. 3
      iguana/exchanges/bitcoin.h
  4. 24
      iguana/iguana_realtime.c
  5. 14
      iguana/iguana_scripts.c
  6. 4
      iguana/swaps/iguana_BTCswap.c
  7. 7
      includes/iguana_funcs.h

5
basilisk/basilisk.h

@ -65,14 +65,15 @@ struct basilisk_swap
int32_t bobconfirms,aliceconfirms,iambob,reclaimed;
uint64_t alicesatoshis,bobsatoshis,bobinsurance,aliceinsurance;
bits256 privkeys[INSTANTDEX_DECKSIZE],myprivs[2],mypubs[2],otherpubs[2],pubA0,pubA1,pubB0,pubB1,privAm,pubAm,privBn,pubBn;
uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2];
bits256 myprivs[2],mypubs[2],otherpubs[2],pubA0,pubA1,pubB0,pubB1,privAm,pubAm,privBn,pubBn;
uint32_t crcs_mypub[2],crcs_mychoosei[2],crcs_myprivs[2],crcs_mypriv[2];
int32_t choosei,otherchoosei,cutverified,otherverifiedcut,numpubs,havestate,otherhavestate;
uint8_t secretAm[20],secretBn[20];
uint8_t secretAm256[32],secretBn256[32];
struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim;
bits256 privkeys[INSTANTDEX_DECKSIZE];
uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2];
uint8_t verifybuf[65536];
};

199
basilisk/basilisk_swap.c

@ -53,7 +53,24 @@
Alice timeout event is triggered if INSTANTDEX_LOCKTIME elapses from the start of a FSM instance. Bob timeout event is triggered after INSTANTDEX_LOCKTIME*2
*/
//auto create utxo
/*
Bob sends bobdeposit and waits for alicepayment to confirm before sending bobpayment
Alice waits for bobdeposit to confirm and sends alicepayment
Alice spends bobpayment immediately divulging privAm
Bob spends alicepayment immediately after getting privAm and divulges privBn
Bob will spend bobdeposit after end of trade or INSTANTDEX_LOCKTIME, divulging privBn
Alice spends alicepayment as soon as privBn is seen
Bob will spend bobpayment after INSTANTDEX_LOCKTIME
Alice spends bobdeposit in 2*INSTANTDEX_LOCKTIME
*/
void basilisk_txlog(struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,int32_t delay)
{
// save in append only for backstop reclaiming
}
void revcalc_rmd160_sha256(uint8_t rmd160[20],bits256 revhash)
{
@ -66,6 +83,18 @@ void revcalc_rmd160_sha256(uint8_t rmd160[20],bits256 revhash)
#define SCRIPT_OP_IF 0x63
#define SCRIPT_OP_ELSE 0x67
#define SCRIPT_OP_ENDIF 0x68
#define DISABLE_CHECKSIG
bits256 basilisk_revealkey(bits256 privkey,bits256 pubkey)
{
bits256 reveal;
#ifdef DISABLE_CHECKSIG
vcalc_sha256(0,reveal.bytes,privkey.bytes,sizeof(privkey));
#else
reveal = pubkey;
#endif
return(reveal);
}
int32_t basilisk_bobscript(uint8_t *rmd160,uint8_t *redeemscript,int32_t *redeemlenp,uint8_t *script,int32_t n,uint32_t *locktimep,int32_t *secretstartp,struct basilisk_swap *swap,int32_t depositflag)
{
@ -74,23 +103,19 @@ int32_t basilisk_bobscript(uint8_t *rmd160,uint8_t *redeemscript,int32_t *redeem
if ( depositflag != 0 )
{
*locktimep += INSTANTDEX_LOCKTIME;
cltvpub = swap->pubA0;
destpub = swap->pubB0;
pubkeyA[0] = 0x02, cltvpub = swap->pubA0;
pubkeyB[0] = 0x03, destpub = swap->pubB0;
privkey = swap->privBn;
secret160 = swap->secretBn;
secret256 = swap->secretBn256;
pubkeyA[0] = 0x02;
pubkeyB[0] = 0x03;
}
else
{
cltvpub = swap->pubB1;
destpub = swap->pubA0;
pubkeyA[0] = 0x03, cltvpub = swap->pubB1;
pubkeyB[0] = 0x02, destpub = swap->pubA0;
privkey = swap->privAm;
secret160 = swap->secretAm;
secret256 = swap->secretAm256;
pubkeyA[0] = 0x03;
pubkeyB[0] = 0x02;
}
for (i=0; i<32; i++)
printf("%02x",secret256[i]);
@ -106,7 +131,11 @@ int32_t basilisk_bobscript(uint8_t *rmd160,uint8_t *redeemscript,int32_t *redeem
memcpy(pubkeyB+1,destpub.bytes,sizeof(destpub));
redeemscript[n++] = SCRIPT_OP_IF;
n = bitcoin_checklocktimeverify(redeemscript,n,*locktimep);
#ifdef DISABLE_CHECKSIG
n = bitcoin_secret256spend(redeemscript,n,cltvpub);
#else
n = bitcoin_pubkeyspend(redeemscript,n,pubkeyA);
#endif
redeemscript[n++] = SCRIPT_OP_ELSE;
if ( secretstartp != 0 )
*secretstartp = n + 2;
@ -124,7 +153,7 @@ int32_t basilisk_bobscript(uint8_t *rmd160,uint8_t *redeemscript,int32_t *redeem
else printf("secret160 matches neither\n");
memcpy(secret160,bufB,20);
}
n = bitcoin_revealsecret160(redeemscript,n,secret160);
n = bitcoin_secret160verify(redeemscript,n,secret160);
}
else
{
@ -133,7 +162,11 @@ int32_t basilisk_bobscript(uint8_t *rmd160,uint8_t *redeemscript,int32_t *redeem
memcpy(&redeemscript[n],secret256,0x20), n += 0x20;
redeemscript[n++] = 0x88; //SCRIPT_OP_EQUALVERIFY;
}
#ifdef DISABLE_CHECKSIG
n = bitcoin_secret256spend(redeemscript,n,destpub);
#else
n = bitcoin_pubkeyspend(redeemscript,n,pubkeyB);
#endif
redeemscript[n++] = SCRIPT_OP_ENDIF;
*redeemlenp = n;
calc_rmd160_sha256(rmd160,redeemscript,n);
@ -311,14 +344,15 @@ struct basilisk_rawtx *basilisk_swapdata_rawtx(struct supernet_info *myinfo,stru
int32_t basilisk_verify_otherfee(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)
{
struct basilisk_swap *swap = ptr;
// add verification
// add verification and broadcast
swap->otherfee.txbytes = calloc(1,datalen);
memcpy(swap->otherfee.txbytes,data,datalen);
swap->otherfee.actualtxid = swap->otherfee.signedtxid = bits256_doublesha256(0,data,datalen);
basilisk_txlog(myinfo,swap,&swap->otherfee,-1);
return(0);
}
int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *data,int32_t datalen,int32_t suppress_pubkeys)
int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *data,int32_t datalen,int32_t suppress_pubkeys)
{
int32_t retval=-1,hexlen,n; cJSON *txobj,*skey,*vouts,*vout; char *hexstr;
if ( rawtx->txbytes == 0 )
@ -336,7 +370,7 @@ int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,int32_t height,s
printf("%02x",rawtx->txbytes[i]);
printf(" <- rawtx\n");
printf("%s rawtx data compare error, len %d vs %d <<<<<<<<<< warning\n",rawtx->name,rawtx->datalen,datalen);
//return(-1);
return(-1);
}
if ( (txobj= bitcoin_data2json(rawtx->coin,height,&rawtx->signedtxid,&rawtx->msgtx,rawtx->extraspace,sizeof(rawtx->extraspace),data,datalen,0,suppress_pubkeys)) != 0 )
{
@ -352,6 +386,7 @@ int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,int32_t height,s
{
decode_hex(rawtx->spendscript,hexlen,hexstr);
rawtx->spendlen = hexlen;
basilisk_txlog(myinfo,swap,rawtx,-1); // bobdeposit, bobpayment or alicepayment
retval = 0;
}
} else printf("%s ERROR.(%s)\n",rawtx->name,jprint(txobj,0));
@ -391,19 +426,23 @@ int32_t basilisk_swapuserdata(uint8_t *userdata,int32_t pushpriv,bits256 privkey
int32_t basilisk_verify_bobdeposit(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)
{
uint8_t userdata[512]; int32_t len = 0; struct basilisk_swap *swap = ptr;
if ( basilisk_rawtx_spendscript(myinfo,swap->bobcoin->blocks.hwmchain.height,&swap->bobdeposit,0,data,datalen,0) == 0 )
uint8_t userdata[512]; int32_t retval,len = 0; struct basilisk_swap *swap = ptr;
if ( basilisk_rawtx_spendscript(myinfo,swap,swap->bobcoin->blocks.hwmchain.height,&swap->bobdeposit,0,data,datalen,0) == 0 )
{
userdata[len++] = 0x51;
return(basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->aliceclaim,&swap->bobdeposit,swap->myprivs[0],0,userdata,len));
if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->aliceclaim,&swap->bobdeposit,swap->myprivs[0],0,userdata,len)) == 0 )
{
basilisk_txlog(myinfo,swap,&swap->aliceclaim,INSTANTDEX_LOCKTIME*2);
return(retval);
}
}
printf("error with bobdeposit\n");
return(-1);
}
int32_t basilisk_bobdeposit_refund(struct supernet_info *myinfo,struct basilisk_swap *swap)
int32_t basilisk_bobdeposit_refund(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t delay)
{
uint8_t userdata[512],revrmd160[20],testpub[33]; int32_t len = 0;
uint8_t userdata[512],revrmd160[20],testpub[33]; int32_t retval,len = 0;
len = basilisk_swapuserdata(userdata,1,swap->privBn,0x03,swap->pubB0,0,1);
int32_t i; for (i=0; i<len; i++)
printf("%02x",userdata[i]);
@ -416,7 +455,12 @@ int32_t basilisk_bobdeposit_refund(struct supernet_info *myinfo,struct basilisk_
if ( memcmp(swap->pubB0.bytes,testpub+1,32) == 0 )
printf("VERIFIED priv -> pub\n");
else printf("ERROR priv -> pub\n");
return(basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->bobrefund,&swap->bobdeposit,swap->myprivs[0],0,userdata,len));
if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->bobrefund,&swap->bobdeposit,swap->myprivs[0],0,userdata,len)) == 0 )
{
basilisk_txlog(myinfo,swap,&swap->bobrefund,delay);
return(retval);
}
return(-1);
}
/*Bob paytx:
@ -426,52 +470,56 @@ int32_t basilisk_bobdeposit_refund(struct supernet_info *myinfo,struct basilisk_
OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <alice_pubA0> OP_CHECKSIG
OP_ENDIF*/
int32_t basilisk_bobpayment_reclaim(struct supernet_info *myinfo,struct basilisk_swap *swap)
int32_t basilisk_bobpayment_reclaim(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t delay)
{
uint8_t userdata[512]; int32_t len = 0;
uint8_t userdata[512]; int32_t retval,len = 0;
printf("basilisk_bobpayment_reclaim\n");
userdata[len++] = 0x51;
return(basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->bobreclaim,&swap->bobpayment,swap->myprivs[1],0,userdata,len));
if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->bobreclaim,&swap->bobpayment,swap->myprivs[1],0,userdata,len)) == 0 )
{
basilisk_txlog(myinfo,swap,&swap->bobreclaim,delay);
return(retval);
}
return(-1);
}
int32_t basilisk_verify_bobpaid(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)
{
uint8_t userdata[512]; int32_t len = 0; struct basilisk_swap *swap = ptr;
if ( basilisk_rawtx_spendscript(myinfo,swap->bobcoin->blocks.hwmchain.height,&swap->bobpayment,0,data,datalen,0) == 0 )
uint8_t userdata[512]; int32_t retval,len = 0; struct basilisk_swap *swap = ptr;
if ( basilisk_rawtx_spendscript(myinfo,swap,swap->bobcoin->blocks.hwmchain.height,&swap->bobpayment,0,data,datalen,0) == 0 )
{
len = basilisk_swapuserdata(userdata,1,swap->privAm,0x02,swap->pubA0,0,1);
char str[65]; printf("bobpaid.(%s)\n",bits256_str(str,swap->privAm));
return(basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->alicespend,&swap->bobpayment,swap->myprivs[0],0,userdata,len));
} else return(-1);
if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->alicespend,&swap->bobpayment,swap->myprivs[0],0,userdata,len)) == 0 )
{
basilisk_txlog(myinfo,swap,&swap->alicespend,-1);
return(retval);
}
}
return(-1);
}
int32_t basilisk_alicepayment_spend(struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *dest)
{
int32_t retval;
//printf("alicepayment_spend\n");
swap->alicepayment.spendlen = basilisk_alicescript(swap->alicepayment.redeemscript,&swap->alicepayment.redeemlen,swap->alicepayment.spendscript,0,swap->alicepayment.destaddr,swap->alicecoin->chain->p2shtype,swap->pubAm,swap->pubBn);
return(basilisk_rawtx_sign(myinfo,swap->alicecoin->blocks.hwmchain.height,swap,dest,&swap->alicepayment,swap->privAm,&swap->privBn,0,0));
if ( (retval= basilisk_rawtx_sign(myinfo,swap->alicecoin->blocks.hwmchain.height,swap,dest,&swap->alicepayment,swap->privAm,&swap->privBn,0,0)) == 0 )
{
basilisk_txlog(myinfo,swap,dest,0); // bobspend or alicereclaim
return(retval);
}
return(-1);
}
int32_t basilisk_verify_alicepaid(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)
{
struct basilisk_swap *swap = ptr;
if ( basilisk_rawtx_spendscript(myinfo,swap->alicecoin->blocks.hwmchain.height,&swap->alicepayment,0,data,datalen,0) == 0 )
if ( basilisk_rawtx_spendscript(myinfo,swap,swap->alicecoin->blocks.hwmchain.height,&swap->alicepayment,0,data,datalen,0) == 0 )
return(0);
else return(-1);
}
int32_t basilisk_privAm_extract(struct supernet_info *myinfo,struct basilisk_swap *swap)
{
// need to scan blockchain for alicespend of bobpayment
// search for swap->bobpayment.actualtxid in spends
if ( bits256_nonz(swap->privAm) != 0 && swap->bobspend.txbytes == 0 )
{
char str[65]; printf("have privAm.%s\n",bits256_str(str,swap->privAm));
return(basilisk_alicepayment_spend(myinfo,swap,&swap->bobspend));
}
return(-1);
}
int32_t basilisk_verify_pubpair(int32_t *wrongfirstbytep,struct basilisk_swap *swap,int32_t ind,uint8_t pub0,bits256 pubi,uint64_t txid)
{
if ( pub0 != (swap->iambob ^ 1) + 0x02 )
@ -644,6 +692,7 @@ void basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swap *
{
printf("GENERATED BOB PAYMENT\n");
iguana_unspents_mark(myinfo,swap->bobcoin,swap->bobpayment.vins);
basilisk_bobpayment_reclaim(myinfo,swap,INSTANTDEX_LOCKTIME);
break;
}
}
@ -800,10 +849,33 @@ uint32_t basilisk_swapsend(struct supernet_info *myinfo,struct basilisk_swap *sw
return(0);
}
int32_t basilisk_priviextract(struct supernet_info *myinfo,struct iguana_info *coin,char *name,bits256 *destp,uint8_t secret160[20],bits256 srctxid,int32_t srcvout)
{
bits256 txid,privkey; char str[65]; int32_t i,vini,scriptlen; uint8_t rmd160[20],scriptsig[IGUANA_MAXSCRIPTSIZE];
if ( (vini= iguana_vinifind(myinfo,coin,&txid,srctxid,srcvout)) >= 0 )
{
if ( (scriptlen= iguana_scriptsigextract(myinfo,coin,scriptsig,sizeof(scriptsig),txid,vini)) > 0 )
{
for (i=0; i<32; i++)
privkey.bytes[i] = scriptsig[scriptlen - 33 + i];
revcalc_rmd160_sha256(rmd160,privkey);
if ( memcmp(secret160,rmd160,sizeof(rmd160)) == sizeof(rmd160) )
{
*destp = privkey;
printf("found %s (%s)\n",name,bits256_str(str,privkey));
return(0);
}
}
}
return(-1);
}
int32_t basilisk_privBn_extract(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{
// need to scan blockchain for bobrefund
// search for swap->bobrefund.actualtxid in spends
if ( basilisk_priviextract(myinfo,swap->bobcoin,"privBn",&swap->privBn,swap->secretBn,swap->bobrefund.actualtxid,0) == 0 )
{
}
if ( basilisk_swapget(myinfo,swap,0x40000000,data,maxlen,basilisk_verify_privi) == 0 )
{
if ( bits256_nonz(swap->privBn) != 0 && swap->alicereclaim.txbytes == 0 )
@ -814,7 +886,20 @@ int32_t basilisk_privBn_extract(struct supernet_info *myinfo,struct basilisk_swa
}
return(-1);
}
// end of coin protocol dependent
int32_t basilisk_privAm_extract(struct supernet_info *myinfo,struct basilisk_swap *swap)
{
if ( basilisk_priviextract(myinfo,swap->bobcoin,"privAm",&swap->privAm,swap->secretAm,swap->bobpayment.actualtxid,0) == 0 )
{
}
if ( bits256_nonz(swap->privAm) != 0 && swap->bobspend.txbytes == 0 )
{
char str[65]; printf("have privAm.%s\n",bits256_str(str,swap->privAm));
return(basilisk_alicepayment_spend(myinfo,swap,&swap->bobspend));
}
return(-1);
}
bits256 instantdex_derivekeypair(struct supernet_info *myinfo,bits256 *newprivp,uint8_t pubkey[33],bits256 privkey,bits256 orderhash)
{
@ -826,7 +911,7 @@ bits256 instantdex_derivekeypair(struct supernet_info *myinfo,bits256 *newprivp,
int32_t instantdex_pubkeyargs(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t numpubs,bits256 privkey,bits256 hash,int32_t firstbyte)
{
char buf[3]; int32_t i,n,m,len=0; bits256 pubi; uint64_t txid; uint8_t secret160[20],pubkey[33];
char buf[3]; int32_t i,n,m,len=0; bits256 pubi,reveal; uint64_t txid; uint8_t secret160[20],pubkey[33];
sprintf(buf,"%c0",'A' - 0x02 + firstbyte);
if ( numpubs > 2 )
{
@ -846,19 +931,20 @@ int32_t instantdex_pubkeyargs(struct supernet_info *myinfo,struct basilisk_swap
{
swap->myprivs[n] = privkey;
memcpy(swap->mypubs[n].bytes,pubkey+1,sizeof(bits256));
reveal = basilisk_revealkey(privkey,swap->mypubs[n]);
if ( swap->iambob != 0 )
{
if ( n == 0 )
swap->pubB0 = swap->mypubs[n];
swap->pubB0 = reveal;
else if ( n == 1 )
swap->pubB1 = swap->mypubs[n];
swap->pubB1 = reveal;
}
else if ( swap->iambob == 0 )
{
if ( n == 0 )
swap->pubA0 = swap->mypubs[n];
swap->pubA0 = reveal;
else if ( n == 1 )
swap->pubA1 = swap->mypubs[n];
swap->pubA1 = reveal;
}
}
}
@ -1416,15 +1502,10 @@ void basilisk_swaploop(void *_swap)
retval = 0;
printf("GENERATED BOB DEPOSIT\n");
iguana_unspents_mark(myinfo,swap->bobcoin,swap->bobdeposit.vins);
basilisk_bobdeposit_refund(myinfo,swap,INSTANTDEX_LOCKTIME);
break;
}
}
basilisk_bobscripts_set(myinfo,swap,0);
/*if ( basilisk_bobpayment_reclaim(myinfo,swap) < 0 || basilisk_bobdeposit_refund(myinfo,swap) < 0 )
{
printf("error bob reclaiming\n");
retval = -3;
}*/
}
else
{
@ -1442,6 +1523,7 @@ void basilisk_swaploop(void *_swap)
retval = 0;
printf("ALICE PAYMENT created\n");
iguana_unspents_mark(myinfo,swap->alicecoin,swap->alicepayment.vins);
basilisk_txlog(myinfo,swap,&swap->alicepayment,-1);
break;
}
}
@ -1450,6 +1532,7 @@ void basilisk_swaploop(void *_swap)
{
swap->statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40);
iguana_unspents_mark(myinfo,swap->iambob!=0?swap->bobcoin:swap->alicecoin,swap->myfee.vins);
basilisk_txlog(myinfo,swap,&swap->myfee,-1);
}
else
{
@ -1457,6 +1540,7 @@ void basilisk_swaploop(void *_swap)
retval = -6;
}
}
basilisk_txlog(myinfo,swap,0,-1);
}
while ( retval == 0 && time(NULL) < swap->expiration )
{
@ -1596,6 +1680,7 @@ void basilisk_swaploop(void *_swap)
if ( basilisk_swapget(myinfo,swap,0x8000,data,maxlen,basilisk_verify_bobpaid) == 0 )
{
printf("got bobpayment\n");
basilisk_swap_balancingtrade(myinfo,swap,0);
// verify payment and submit, set confirmed height
swap->statebits |= 0x8000;
}
@ -1611,14 +1696,12 @@ void basilisk_swaploop(void *_swap)
else if ( (swap->statebits & 0x20000) == 0 )
{
printf("alicespend bobpayment\n");
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicespend,0x20000) != 0 )
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicespend,0x20000) != 0 && basilisk_numconfirms(myinfo,&swap->alicespend) > 0 )
{
// maybe wait for alicespend to be confirmed
for (j=datalen=0; j<32; j++)
data[datalen++] = swap->privAm.bytes[j];
printf("send privAm\n");
swap->statebits |= basilisk_swapsend(myinfo,swap,0x40000,data,datalen,0x20000,swap->crcs_mypriv);
basilisk_swap_balancingtrade(myinfo,swap,0);
}
}
else if ( (swap->statebits & 0x40000) == 0 )
@ -1657,7 +1740,7 @@ void basilisk_swaploop(void *_swap)
if ( swap->iambob != 0 )//&& bits256_nonz(swap->bobdeposit.txid) != 0 )
{
printf("BOB reclaims refund\n");
basilisk_bobdeposit_refund(myinfo,swap);
basilisk_bobdeposit_refund(myinfo,swap,0);
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobrefund,0x40000000) == 0 ) // use secretBn
{
printf("Bob submit error getting refund of deposit\n");

3
iguana/exchanges/bitcoin.h

@ -33,7 +33,9 @@
#define SCRIPT_OP_ENDIF 0x68
#define SCRIPT_OP_DROP 0x75
#define SCRIPT_OP_EQUALVERIFY 0x88
#define SCRIPT_OP_SHA256 0xa8
#define SCRIPT_OP_HASH160 0xa9
#define SCRIPT_OP_EQUAL 0x87
#define SCRIPT_OP_CHECKSIG 0xac
#define SCRIPT_OP_CHECKMULTISIG 0xae
@ -49,7 +51,6 @@ int32_t bitcoin_MofNspendscript(uint8_t p2sh_rmd160[20],uint8_t *script,int32_t
int32_t bitcoin_pubkeyspend(uint8_t *script,int32_t n,uint8_t pubkey[66]);
int32_t bitcoin_p2shspend(uint8_t *script,int32_t n,uint8_t rmd160[20]);
int32_t bitcoin_revealsecret160(uint8_t *script,int32_t n,uint8_t secret160[20]);
int32_t bitcoin_standardspend(uint8_t *script,int32_t n,uint8_t rmd160[20]);
int32_t bitcoin_pubkeylen(const uint8_t *pubkey);

24
iguana/iguana_realtime.c

@ -543,6 +543,30 @@ char *iguana_txidcategory(struct supernet_info *myinfo,struct iguana_info *coin,
} else return("unknown");
}
int32_t iguana_scriptsigextract(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *script,int32_t maxsize,bits256 txid,int32_t vini)
{
return(-1);
}
int32_t iguana_vinifind(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *spentfrom,bits256 txid,int32_t vout)
{
int32_t vini = -1; //char *txbytes; char str[65]; cJSON *txobj;
memset(spentfrom,0,sizeof(*spentfrom));
/*if ( (txbytes= iguana_txbytes(myinfo,swap->bobcoin,txid)) != 0 )
{
if ( (txobj= iguana_hex2json(myinfo,swap->bobcoin,txbytes)) != 0 )
{
if ( (vins= jarray(&n,txobj,"vins")) != 0 && vini < n )
{
} else printf("iguana_vinifind no vins.%p or illegal vini.%d vs n.%d\n",txobj,vini,n);
free_json(txobj);
} else printf("iguana_vinifind couldnt parse %s.(%s)\n",swap->bobcoin->symbol,txbytes);
free(txbytes);
} else printf("iguana_vinifind cant get txbytes for %s.(%s)\n",swap->bobcoin->symbol,bits256_str(str,txid));*/
return(vini);
}
void iguana_RTunmap(uint8_t *ptr,uint32_t len)
{
OS_releasemap(&ptr[-2*sizeof(len)],len+2*sizeof(len));

14
iguana/iguana_scripts.c

@ -34,7 +34,7 @@ int32_t bitcoin_p2shspend(uint8_t *script,int32_t n,uint8_t rmd160[20])
return(n);
}
int32_t bitcoin_revealsecret160(uint8_t *script,int32_t n,uint8_t secret160[20])
int32_t bitcoin_secret160verify(uint8_t *script,int32_t n,uint8_t secret160[20])
{
script[n++] = SCRIPT_OP_HASH160;
script[n++] = 0x14;
@ -44,6 +44,16 @@ int32_t bitcoin_revealsecret160(uint8_t *script,int32_t n,uint8_t secret160[20])
return(n);
}
int32_t bitcoin_secret256spend(uint8_t *script,int32_t n,bits256 secret)
{
script[n++] = SCRIPT_OP_SHA256;
script[n++] = 0x20;
memcpy(&script[n],secret.bytes,0x20);
n += 0x14;
script[n++] = SCRIPT_OP_EQUAL;
return(n);
}
// OP_DUP OP_HASH160 <hash of pubkey> OP_EQUALVERIFY OP_CHECKSIG
int32_t bitcoin_standardspend(uint8_t *script,int32_t n,uint8_t rmd160[20])
{
@ -168,7 +178,7 @@ int32_t bitcoin_cltvscript(uint8_t p2shtype,char *ps2h_coinaddr,uint8_t p2sh_rmd
n = bitcoin_checklocktimeverify(script,n,locktime);
n = bitcoin_standardspend(script,n,rmd160A);
script[n++] = SCRIPT_OP_ELSE;
n = bitcoin_revealsecret160(script,n,secret160);
n = bitcoin_secret160verify(script,n,secret160);
n = bitcoin_standardspend(script,n,rmd160B);
script[n++] = SCRIPT_OP_ENDIF;
calc_rmd160_sha256(p2sh_rmd160,script,n);

4
iguana/swaps/iguana_BTCswap.c

@ -90,7 +90,7 @@ int32_t instantdex_bobscript(uint8_t *script,int32_t n,uint32_t *locktimep,int32
script[n++] = SCRIPT_OP_ELSE;
if ( secretstartp != 0 )
*secretstartp = n + 2;
n = bitcoin_revealsecret160(script,n,secret160);
n = bitcoin_secret160verify(script,n,secret160);
n = bitcoin_pubkeyspend(script,n,pubkeyB);
script[n++] = SCRIPT_OP_ENDIF;
return(n);
@ -1227,7 +1227,7 @@ char *instantdex_bailintx(struct iguana_info *coin,bits256 *txidp,struct bitcoin
bitcoin_txoutput(coin,txobj,scriptv0,scriptv0len,spend->satoshis);
if ( isbob != 0 )
{
scriptv1len = bitcoin_revealsecret160(scriptv1,0,x);
scriptv1len = bitcoin_secret160verify(scriptv1,0,x);
scriptv1len = bitcoin_pubkeyspend(scriptv1,scriptv1len,pubkey);
} else scriptv1len = bitcoin_p2shspend(scriptv1,0,x);
bitcoin_txoutput(coin,txobj,scriptv1,scriptv1len,spend->txfee);

7
includes/iguana_funcs.h

@ -420,6 +420,9 @@ int32_t iguana_addressvalidate(struct iguana_info *coin,uint8_t *addrtypep,char
int32_t bitcoin_sign(void *ctx,char *symbol,uint8_t *sig,bits256 txhash2,bits256 privkey,int32_t recoverflag);
void revcalc_rmd160_sha256(uint8_t rmd160[20],bits256 revhash);
struct iguana_utxo iguana_utxofind(struct iguana_info *coin,struct iguana_outpoint spentpt,int32_t *RTspendflagp,int32_t lockflag);
int32_t iguana_vinifind(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *spentfrom,bits256 txid,int32_t vout);
int32_t iguana_scriptsigextract(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *script,int32_t maxsize,bits256 txid,int32_t vini);
bits256 iguana_str2priv(struct supernet_info *myinfo,struct iguana_info *coin,char *str);
int32_t iguana_RTspentflag(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *RTspendp,int32_t *spentheightp,struct iguana_ramchain *ramchain,struct iguana_outpoint spentpt,int32_t height,int32_t minconf,int32_t maxconf,uint64_t amount);
int32_t iguana_voutscript(struct iguana_info *coin,struct iguana_bundle *bp,uint8_t *scriptspace,char *asmstr,struct iguana_unspent *u,struct iguana_pkhash *p,int32_t txi);
@ -524,6 +527,8 @@ void *iguana_blockzcopyRO(uint8_t zcash,struct iguana_blockRO *dest,int32_t dest
void iguana_blockzcopy(uint8_t zcash,struct iguana_block *dest,struct iguana_block *src);
int32_t iguana_blocksizecheck(char *debugstr,uint8_t zcash,struct iguana_block *block);
void basilisk_miner(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,int32_t maxmillis,char *mineraddr);
int32_t bitcoin_secret160verify(uint8_t *script,int32_t n,uint8_t secret160[20]);
int32_t bitcoin_secret256spend(uint8_t *script,int32_t n,bits256 secret);
int32_t bitcoin_pubkeyspend(uint8_t *script,int32_t n,uint8_t pubkey[66]);
int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,struct iguana_peer *addr,char *blockstr,bits256 hash2,int32_t height);
struct supernet_info *SuperNET_MYINFO(char *passphrase);
@ -579,7 +584,7 @@ void iguana_update_balances(struct supernet_info *myinfo,struct iguana_info *coi
void iguana_RTspendvectors(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp);
int64_t iguana_RTbalance(struct iguana_info *coin,char *coinaddr);
double instantdex_avehbla(struct supernet_info *myinfo,double retvals[4],char *base,char *rel,double basevolume);
int32_t bitcoin_revealsecret160(uint8_t *script,int32_t n,uint8_t secret160[20]);
int32_t bitcoin_secret160verify(uint8_t *script,int32_t n,uint8_t secret160[20]);
int64_t iguana_lockval(int32_t finalized,int64_t locktime);
uint64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_pkhash **Ptrp,uint64_t *supplyp,int32_t *numacctsp,int32_t *nonzp,int32_t *errsp,int32_t lastheight);
int32_t iguana_staker_sort(struct iguana_info *coin,bits256 *hash2p,uint8_t *refrmd160,struct iguana_pkhash *refP,uint64_t *weights,int32_t numweights,bits256 *sortbuf);

Loading…
Cancel
Save