Browse Source

Test

etomic
jl777 7 years ago
parent
commit
c0f72c6d01
  1. 2
      iguana/exchanges/LP_include.h
  2. 10
      iguana/exchanges/LP_remember.c
  3. 62
      iguana/exchanges/LP_transaction.c

2
iguana/exchanges/LP_include.h

@ -276,7 +276,7 @@ struct LP_swap_remember
uint32_t finishtime,tradeid,requestid,quoteid,plocktime,dlocktime,expiration,state,otherstate;
int32_t iambob,finishedflag,origfinishedflag,Predeemlen,Dredeemlen,sentflags[sizeof(txnames)/sizeof(*txnames)];
uint8_t secretAm[20],secretAm256[32],secretBn[20],secretBn256[32],Predeemscript[1024],Dredeemscript[1024],pubkey33[33],other33[33];
char Agui[65],Bgui[65],gui[65],src[65],dest[65],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[65],bobcoin[65],*txbytes[sizeof(txnames)/sizeof(*txnames)];
char Agui[65],Bgui[65],gui[65],src[65],dest[65],bobtomic[128],alicetomic[128],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[65],bobcoin[65],*txbytes[sizeof(txnames)/sizeof(*txnames)];
};
struct LP_outpoint

10
iguana/exchanges/LP_remember.c

@ -66,7 +66,11 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx
fprintf(fp,",\"expiration\":%u",swap->I.expiration);
fprintf(fp,",\"iambob\":%d",swap->I.iambob);
fprintf(fp,",\"bobcoin\":\"%s\"",swap->I.bobstr);
if ( swap->I.bobtomic[0] != 0 )
fprintf(fp,",\"bobtomic\":\"%s\"",swap->I.bobtomic);
fprintf(fp,",\"alicecoin\":\"%s\"",swap->I.alicestr);
if ( swap->I.alicetomic[0] != 0 )
fprintf(fp,",\"alicetomic\":\"%s\"",swap->I.alicetomic);
fprintf(fp,",\"lock\":%u",locktime);
fprintf(fp,",\"amount\":%.8f",dstr(rawtx->I.amount));
if ( bits256_nonz(triggertxid) != 0 )
@ -502,9 +506,13 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap)
jaddstr(item,"Agui",rswap->Agui);
jaddstr(item,"gui",rswap->gui);
jaddstr(item,"bob",rswap->src);
if ( rswap->bobtomic[0] != 0 )
jaddstr(item,"bobtomic",rswap->bobtomic);
jaddnum(item,"srcamount",dstr(rswap->srcamount));
jaddnum(item,"bobtxfee",dstr(rswap->Btxfee));
jaddstr(item,"alice",rswap->dest);
if ( rswap->alicetomic[0] != 0 )
jaddstr(item,"alicetomic",rswap->alicetomic);
jaddnum(item,"destamount",dstr(rswap->destamount));
jaddnum(item,"alicetxfee",dstr(rswap->Atxfee));
jadd64bits(item,"aliceid",rswap->aliceid);
@ -552,6 +560,8 @@ int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t
safecopy(rswap->Bgui,jstr(item,"Bgui"),sizeof(rswap->Bgui));
safecopy(rswap->Agui,jstr(item,"Agui"),sizeof(rswap->Agui));
safecopy(rswap->gui,jstr(item,"gui"),sizeof(rswap->gui));
safecopy(rswap->bobtomic,jstr(item,"bobtomic"),sizeof(rswap->bobtomic));
safecopy(rswap->alicetomic,jstr(item,"alicetomic"),sizeof(rswap->alicetomic));
rswap->tradeid = juint(item,"tradeid");
rswap->aliceid = j64bits(item,"aliceid");
if ( (secretstr= jstr(item,"secretAm")) != 0 && strlen(secretstr) == 40 )

62
iguana/exchanges/LP_transaction.c

@ -1867,8 +1867,9 @@ int32_t basilisk_swapuserdata(uint8_t *userdata,bits256 privkey,int32_t ifpath,b
int32_t basilisk_bobpayment_reclaim(struct basilisk_swap *swap,int32_t delay)
{
static bits256 zero;
uint8_t userdata[512]; int32_t retval,len = 0; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 )
uint8_t userdata[512]; char bobstr[65],bobtomic[128]; int32_t retval,len = 0; struct iguana_info *coin;
LP_etomicsymbol(bobstr,bobtomic,bobstr);
if ( (coin= LP_coinfind(bobstr)) != 0 )
{
//printf("basilisk_bobpayment_reclaim\n");
len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[1],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen);
@ -1882,14 +1883,15 @@ int32_t basilisk_bobpayment_reclaim(struct basilisk_swap *swap,int32_t delay)
//basilisk_txlog(swap,&swap->bobreclaim,delay);
return(retval);
}
} else printf("basilisk_bobpayment_reclaim cant find (%s)\n",swap->I.bobstr);
} else printf("basilisk_bobpayment_reclaim cant find (%s)\n",bobstr);
return(-1);
}
int32_t basilisk_bobdeposit_refund(struct basilisk_swap *swap,int32_t delay)
{
uint8_t userdata[512]; int32_t i,retval,len = 0; char str[65]; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 )
uint8_t userdata[512]; int32_t i,retval,len = 0; char str[65],bobstr[65],bobtomic[128]; struct iguana_info *coin;
LP_etomicsymbol(bobstr,bobtomic,swap->I.bobstr);
if ( (coin= LP_coinfind(bobstr)) != 0 )
{
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);
@ -1902,7 +1904,7 @@ int32_t basilisk_bobdeposit_refund(struct basilisk_swap *swap,int32_t delay)
//basilisk_txlog(swap,&swap->bobrefund,delay);
return(retval);
}
} else printf("basilisk_bobdeposit_refund cant find (%s)\n",swap->I.bobstr);
} else printf("basilisk_bobdeposit_refund cant find (%s)\n",bobstr);
return(-1);
}
@ -1928,8 +1930,9 @@ void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,u
int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,int32_t genflag)
{
char coinaddr[64],checkaddr[64]; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 )
char coinaddr[64],checkaddr[64],bobstr[65],bobtomic[128]; struct iguana_info *coin;
LP_etomicsymbol(bobstr,bobtomic,swap->I.bobstr);
if ( (coin= LP_coinfind(bobstr)) != 0 )
{
bitcoin_address(coin->symbol,coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20);
if ( genflag != 0 && swap->I.iambob == 0 )
@ -2005,7 +2008,7 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i
}
}
}
} else printf("bobscripts set cant find (%s)\n",swap->I.bobstr);
} else printf("bobscripts set cant find (%s)\n",bobstr);
return(0);
}
@ -2053,8 +2056,9 @@ void basilisk_alicepayment(struct basilisk_swap *swap,struct iguana_info *coin,s
int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{
char coinaddr[64]; int32_t retval = -1; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 )
char coinaddr[64],alicestr[65],alicetomic[128]; int32_t retval = -1; struct iguana_info *coin;
LP_etomicsymbol(alicestr,alicetomic,swap->I.alicestr);
if ( (coin= LP_coinfind(alicestr)) != 0 )
{
if ( swap->alicepayment.I.datalen == 0 )
basilisk_alicepayment(swap,coin,&swap->alicepayment,swap->I.pubAm,swap->I.pubBn);
@ -2099,14 +2103,16 @@ int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *d
//printf("fee sent\n");
return(0);
}
} else printf("basilisk alicetx cant find (%s)\n",swap->I.alicestr);
} else printf("basilisk alicetx cant find (%s)\n",alicestr);
return(-1);
}
int32_t LP_verify_otherfee(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{
int32_t diff; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.iambob != 0 ? swap->I.alicestr : swap->I.bobstr)) != 0 )
int32_t diff; char bobstr[65],bobtomic[128],alicestr[65],alicetomic[128]; struct iguana_info *coin;
LP_etomicsymbol(bobstr,bobtomic,swap->I.bobstr);
LP_etomicsymbol(alicestr,alicetomic,swap->I.alicestr);
if ( (coin= LP_coinfind(swap->I.iambob != 0 ? alicestr : bobstr)) != 0 )
{
if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->otherfee,0,data,datalen,0) == 0 )
{
@ -2130,8 +2136,9 @@ int32_t LP_verify_otherfee(struct basilisk_swap *swap,uint8_t *data,int32_t data
int32_t LP_verify_alicespend(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{
struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 )
struct iguana_info *coin; char alicestr[65],alicetomic[128];
LP_etomicsymbol(alicestr,alicetomic,swap->I.alicestr);
if ( (coin= LP_coinfind(alicestr)) != 0 )
{
if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->alicespend,0,data,datalen,0) == 0 )
{
@ -2142,7 +2149,7 @@ int32_t LP_verify_alicespend(struct basilisk_swap *swap,uint8_t *data,int32_t da
return(0);
}
}
} else printf("verify alicespend cant find (%s)\n",swap->I.alicestr);
} else printf("verify alicespend cant find (%s)\n",alicestr);
return(-1);
}
@ -2156,8 +2163,9 @@ int32_t LP_verify_alicespend(struct basilisk_swap *swap,uint8_t *data,int32_t da
int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{
static bits256 zero;
uint8_t userdata[512]; int32_t retval=-1,len = 0; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 )
uint8_t userdata[512]; char bobstr[65],bobtomic[128]; int32_t retval=-1,len = 0; struct iguana_info *coin;
LP_etomicsymbol(bobstr,bobtomic,swap->I.bobstr);
if ( (coin= LP_coinfind(bobstr)) != 0 )
{
if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->bobdeposit,0,data,datalen,0) == 0 )
{
@ -2196,15 +2204,16 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da
return(LP_waitmempool(coin->symbol,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,60));
} else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->aliceclaim.I.suppress_pubkeys,swap->bobdeposit.I.destaddr);
}
} else printf("verify bob depositcant find bob coin (%s)\n",swap->I.bobstr);
} else printf("verify bob depositcant find bob coin (%s)\n",bobstr);
printf("error with bobdeposit\n");
return(retval);
}
int32_t LP_verify_alicepayment(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{
struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 )
struct iguana_info *coin; char alicestr[65],alicetomic[128];
LP_etomicsymbol(alicestr,alicetomic,swap->I.alicestr);
if ( (coin= LP_coinfind(alicestr)) != 0 )
{
if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->alicepayment,0,data,datalen,0) == 0 )
{
@ -2220,15 +2229,16 @@ int32_t LP_verify_alicepayment(struct basilisk_swap *swap,uint8_t *data,int32_t
//LP_importaddress(coin->symbol,swap->alicepayment.p2shaddr);
return(0);
}
} else printf("verify alicepayment couldnt find coin.(%s)\n",swap->I.alicestr);
} else printf("verify alicepayment couldnt find coin.(%s)\n",alicestr);
printf("error validating alicepayment\n");
return(-1);
}
int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{
uint8_t userdata[512]; int32_t i,retval=-1,len = 0; bits256 revAm; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 )
uint8_t userdata[512]; char bobstr[65],bobtomic[128]; int32_t i,retval=-1,len = 0; bits256 revAm; struct iguana_info *coin;
LP_etomicsymbol(bobstr,bobtomic,swap->I.bobstr);
if ( (coin= LP_coinfind(bobstr)) != 0 )
{
memset(revAm.bytes,0,sizeof(revAm));
if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->bobpayment,0,data,datalen,0) == 0 )
@ -2268,7 +2278,7 @@ int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t da
return(LP_waitmempool(coin->symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,60));
} else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->alicespend.I.suppress_pubkeys,swap->bobpayment.I.destaddr);
}
} else printf("verify bobpayment cant find (%s)\n",swap->I.bobstr);
} else printf("verify bobpayment cant find (%s)\n",bobstr);
printf("error validating bobpayment\n");
return(-1);
}

Loading…
Cancel
Save