Browse Source

Test

etomic
jl777 8 years ago
parent
commit
0f2a167e8d
  1. 33
      basilisk/basilisk_swap.c

33
basilisk/basilisk_swap.c

@ -13,7 +13,8 @@
* *
******************************************************************************/
/*use external privkey to sign
/*
resume handling: list of tx broadcast, tx pending + required items, reconnect state machine or have statemachine assume off by one or state/otherstate specific handling
make sure to broadcast deposit before claiming refund, or to just skip it if neither is done
*/
@ -1434,7 +1435,7 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,bits256 priv
swap->I.bobconfirms = swap->bobcoin->chain->minconfirms;
if ( swap->I.aliceconfirms == 0 )
swap->I.aliceconfirms = swap->alicecoin->chain->minconfirms;
jumblrflag = bits256_cmp(privkey,myinfo->persistent_priv) != 0;
jumblrflag = (bits256_cmp(pubkey25519,myinfo->jumblr_pubkey) == 0 || bits256_cmp(pubkey25519,myinfo->jumblr_depositkey) == 0);
if ( swap->I.iambob != 0 )
{
basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,swap->bobcoin,0,0,swap->I.bobsatoshis/INSTANTDEX_DECKSIZE,0,0,jumblrflag);
@ -1623,7 +1624,7 @@ int32_t basilisk_verify_privkeys(struct supernet_info *myinfo,void *ptr,uint8_t
return(errs);
}
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)
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;
if ( basilisk_swapdata_rawtx(myinfo,swap,data,maxlen,rawtx) != 0 )
@ -1647,7 +1648,9 @@ uint32_t basilisk_swapdata_rawtxsend(struct supernet_info *myinfo,struct basilis
sendlen += rawtx->I.redeemlen;
}
//printf("sendlen.%d datalen.%d redeemlen.%d\n",sendlen,rawtx->datalen,rawtx->redeemlen);
return(basilisk_swapsend(myinfo,swap,msgbits,sendbuf,sendlen,nextbits,rawtx->I.crcs));
if ( suppress_swapsend == 0 )
return(basilisk_swapsend(myinfo,swap,msgbits,sendbuf,sendlen,nextbits,rawtx->I.crcs));
else return(0);
}
}
return(nextbits);
@ -1797,7 +1800,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits);
basilisk_sendstate(myinfo,swap,data,maxlen);
if ( (swap->I.otherstatebits & 0x80) == 0 )
basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40);
basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40,0);
}
while ( retval == 0 && time(NULL) < swap->I.expiration ) // both sides have setup required data and paid txfee
{
@ -1811,7 +1814,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
if ( (swap->I.statebits & 0x100) == 0 )
{
printf("send bobdeposit\n");
swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x200,data,maxlen,&swap->bobdeposit,0x100);
swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x200,data,maxlen,&swap->bobdeposit,0x100,0);
}
// [BLOCKING: altfound] make sure altpayment is confirmed and send payment
else if ( (swap->I.statebits & 0x1000) == 0 )
@ -1835,7 +1838,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
{
basilisk_bobscripts_set(myinfo,swap,0,1);
printf("send bobpayment\n");
swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000);
swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0);
}
// [BLOCKING: privM] Bob waits for privAm either from Alice or alice blockchain
else if ( (swap->I.statebits & 0x40000) == 0 )
@ -1844,7 +1847,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
{
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) == 0 )
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobspend,0x40000,1) == 0 )
printf("Bob error spending alice payment\n");
else
{
@ -1867,7 +1870,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
// submit reclaim of payment
printf("bob reclaims bobpayment\n");
swap->I.statebits |= (0x40000 | 0x80000);
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobreclaim,0) == 0 )
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobreclaim,0,0) == 0 )
printf("Bob error reclaiming own payment after alice timed out\n");
else
{
@ -1911,7 +1914,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
else if ( (swap->I.statebits & 0x800) == 0 )
{
printf("send alicepayment\n");
swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x1000,data,maxlen,&swap->alicepayment,0x800);
swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x1000,data,maxlen,&swap->alicepayment,0x800,0);
}
// [BLOCKING: payfound] make sure payment is confrmed and send in spend or see bob's reclaim and claim
else if ( (swap->I.statebits & 0x8000) == 0 )
@ -1935,7 +1938,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
else if ( (swap->I.statebits & 0x20000) == 0 )
{
printf("alicespend bobpayment\n");
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicespend,0x20000) != 0 && basilisk_numconfirms(myinfo,swap,&swap->alicespend) > 0 )
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicespend,0x20000,0) != 0 && basilisk_numconfirms(myinfo,swap,&swap->alicespend) > 0 )
{
for (j=datalen=0; j<32; j++)
data[datalen++] = swap->I.privAm.bytes[j];
@ -1955,7 +1958,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
if ( swap->bobdeposit.I.locktime != 0 && time(NULL) > swap->bobdeposit.I.locktime )
{
printf("Alice claims deposit\n");
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->aliceclaim,0) == 0 )
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->aliceclaim,0,0) == 0 )
printf("Alice couldnt claim deposit\n");
else
{
@ -1967,7 +1970,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
{
printf("Alice reclaims her payment\n");
swap->I.statebits |= 0x40000000;
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicereclaim,0x40000000) == 0 )
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicereclaim,0x40000000,0) == 0 )
printf("Alice error sending alicereclaim\n");
else
{
@ -2228,7 +2231,7 @@ void basilisk_swaploop(void *_swap)
if ( basilisk_rawtx_gen("myfee",myinfo,swap->I.started,swap->persistent_pubkey33,swap->I.iambob,1,&swap->myfee,0,swap->myfee.spendscript,swap->myfee.I.spendlen,swap->myfee.coin->chain->txfee,1,0) == 0 )
{
printf("done generate fee\n");
swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40);
swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40,0);
iguana_unspents_mark(myinfo,swap->I.iambob!=0?swap->bobcoin:swap->alicecoin,swap->myfee.vins);
basilisk_txlog(myinfo,swap,&swap->myfee,-1);
for (i=0; i<swap->myfee.I.spendlen; i++)
@ -2260,7 +2263,7 @@ void basilisk_swaploop(void *_swap)
{
printf("BOB reclaims refund\n");
basilisk_bobdeposit_refund(myinfo,swap,0);
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobrefund,0x40000000) == 0 ) // use secretBn
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobrefund,0x40000000,0) == 0 ) // use secretBn
{
printf("Bob submit error getting refund of deposit\n");
}

Loading…
Cancel
Save