Browse Source

Send ETH payments and deposits inside sendrawtx.

etomic
Artem Pikulin 7 years ago
parent
commit
00c6897902
  1. 17
      iguana/exchanges/LP_etomic.c
  2. 2
      iguana/exchanges/LP_remember.c
  3. 37
      iguana/exchanges/LP_swap.c

17
iguana/exchanges/LP_etomic.c

@ -206,9 +206,11 @@ char *LP_etomicalice_spends_bob_payment(struct LP_swap_remember *swap)
memset(&txData,0,sizeof(txData));
memset(&input,0,sizeof(input));
EthTxReceipt receipt = getEthTxReceipt(swap->bobDepositEthTx);
uint8arrayToHex(input.paymentId, swap->txids[BASILISK_BOBPAYMENT].bytes, 32);
satoshisToWei(input.amount, swap->values[BASILISK_BOBPAYMENT]);
sprintf(input.bobCanClaimAfter, "%" PRIu64, receipt.blockNumber + 480);
if (swap->bobtomic[0] != 0) {
strcpy(input.tokenAddress, swap->bobtomic);
@ -230,6 +232,21 @@ char *LP_etomicalice_spends_bob_payment(struct LP_swap_remember *swap)
return aliceSpendsBobPayment(input, txData);
}
char *sendEthTx(struct basilisk_swap *swap, struct basilisk_rawtx *rawtx)
{
if (rawtx == &swap->alicepayment && swap->I.alicetomic[0] != 0) {
return LP_etomicalice_send_payment(swap);
} else if (rawtx == &swap->bobdeposit && swap->I.bobtomic[0] != 0) {
return LP_etomicbob_sends_deposit(swap);
} else if (rawtx == &swap->bobpayment && swap->I.bobtomic[0] != 0) {
return LP_etomicbob_sends_payment(swap);
} else {
char *result = malloc(66);
strcpy(result, "0x0000000000000000000000000000000000000000000000000000000000000000");
return result;
}
}
int32_t LP_etomic_priv2addr(char *coinaddr,bits256 privkey)
{
char str[65],*addrstr;

2
iguana/exchanges/LP_remember.c

@ -1207,7 +1207,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
rev.bytes[j] = rswap.myprivs[0].bytes[31 - j];
if ( (rswap.txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"alicespend",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_ALICESPEND],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 )
{
//printf("alicespend.(%s)\n",rswap.txbytes[BASILISK_ALICESPEND]);
LP_etomicalice_spends_bob_payment(&rswap);
}
}
LP_txbytes_update("alicespend",rswap.bobcoin,rswap.txbytes[BASILISK_ALICESPEND],&rswap.txids[BASILISK_ALICESPEND],&rswap.paymentspent,&rswap.sentflags[BASILISK_ALICESPEND]);

37
iguana/exchanges/LP_swap.c

@ -697,6 +697,11 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3
}
if ( bits256_nonz(rawtx->I.actualtxid) != 0 && msgbits != 0 )
{
if (swap->I.bobtomic[0] != 0 || swap->I.alicetomic[0] != 0) {
char *ethTxId = sendEthTx(swap, rawtx);
strcpy(rawtx->I.ethTxid, ethTxId);
free(ethTxId);
}
sendlen = 0;
sendbuf[sendlen++] = rawtx->I.datalen & 0xff;
sendbuf[sendlen++] = (rawtx->I.datalen >> 8) & 0xff;
@ -822,21 +827,8 @@ void LP_bobloop(void *_swap)
printf("error waiting for alicefee\n");
}
if ( error == 0 )
{
if (swap->I.bobtomic[0] != 0)
{
char *depositTx = LP_etomicbob_sends_deposit(swap);
strcpy(swap->bobdeposit.I.ethTxid, depositTx);
free(depositTx);
}
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x200,data,maxlen,&swap->bobdeposit,0x100,0) != 0 )
{
}
else
{
if ( error == 0 ) {
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x200,data,maxlen,&swap->bobdeposit,0x100,0) == 0 ) {
error = 1;
printf("error sending bobdeposit\n");
}
@ -917,20 +909,12 @@ void LP_aliceloop(void *_swap)
{
LP_swapsfp_update(&swap->I.req);
LP_swap_critical = (uint32_t)time(NULL);
if ( swap->I.alicetomic[0] != 0 )
{
}
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x80,data,maxlen,&swap->myfee,0x40,0) == 0 )
printf("error sending alicefee\n");
else if ( LP_waitfor(swap->N.pair,swap,1800,LP_verify_bobdeposit) < 0 )
printf("error waiting for bobdeposit\n");
else
{
if ( swap->I.alicetomic[0] != 0 )
{
// artem: do stuff alice needs to do after bobdeposit comes in
}
m = swap->I.bobconfirms;
while ( (n= LP_numconfirms(bobstr,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,1)) < m )
{
@ -938,13 +922,6 @@ void LP_aliceloop(void *_swap)
char str[65];printf("%d wait for bobdeposit %s numconfs.%d %s %s\n",n,swap->bobdeposit.I.destaddr,m,bobstr,bits256_str(str,swap->bobdeposit.I.signedtxid));
sleep(10);
}
if ( swap->I.alicetomic[0] != 0 ) {
char *paymentEthTx = LP_etomicalice_send_payment(swap);
if (paymentEthTx[0] != 0) {
strcpy(swap->alicepayment.I.ethTxid, paymentEthTx);
}
free(paymentEthTx);
}
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x1000,data,maxlen,&swap->alicepayment,0x800,0) == 0 )
printf("error sending alicepayment\n");
else

Loading…
Cancel
Save