From 753a1aac7ef3b710dada76261eee1f608679d623 Mon Sep 17 00:00:00 2001 From: Artem Pikulin Date: Thu, 15 Feb 2018 16:15:44 +0700 Subject: [PATCH] Add ERC20 bob deposit/payment. Bob spends alice payment only when alicetomic not empty. --- iguana/exchanges/LP_etomic.c | 63 +++++++++++++++++++++++++--------- iguana/exchanges/LP_remember.c | 6 ++-- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/iguana/exchanges/LP_etomic.c b/iguana/exchanges/LP_etomic.c index 4d68227ea..e9f153da3 100644 --- a/iguana/exchanges/LP_etomic.c +++ b/iguana/exchanges/LP_etomic.c @@ -144,19 +144,34 @@ char *LP_etomicbob_spends_alice_payment(struct LP_swap_remember *swap) char *LP_etomicbob_sends_deposit(struct basilisk_swap *swap) { BobSendsEthDepositInput input; + BobSendsErc20DepositInput input20; BasicTxData txData; memset(&txData,0,sizeof(txData)); memset(&input,0,sizeof(input)); + memset(&input20,0,sizeof(input20)); + if ( strcmp(swap->I.bobstr,"ETH") == 0 ) { + uint8arrayToHex(input.depositId, swap->bobdeposit.I.actualtxid.bytes, 32); + strcpy(input.aliceAddress, swap->I.etomicdest); + uint8arrayToHex(input.bobHash, swap->I.secretBn, 20); - uint8arrayToHex(input.depositId, swap->bobdeposit.I.actualtxid.bytes, 32); - strcpy(input.aliceAddress, swap->I.etomicdest); - uint8arrayToHex(input.bobHash, swap->I.secretBn, 20); + strcpy(txData.from, swap->I.etomicsrc); + strcpy(txData.to, ETOMIC_BOBCONTRACT); + satoshisToWei(txData.amount, swap->bobdeposit.I.amount); + uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); + return bobSendsEthDeposit(input, txData); + } else { + uint8arrayToHex(input20.depositId, swap->bobdeposit.I.actualtxid.bytes, 32); + strcpy(input20.aliceAddress, swap->I.etomicdest); + uint8arrayToHex(input20.bobHash, swap->I.secretBn, 20); + satoshisToWei(input20.amount, swap->bobdeposit.I.amount); + strcpy(input20.tokenAddress, swap->I.bobtomic); - strcpy(txData.from, swap->I.etomicsrc); - strcpy(txData.to, ETOMIC_BOBCONTRACT); - satoshisToWei(txData.amount, swap->bobdeposit.I.amount); - uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); - return bobSendsEthDeposit(input, txData); + strcpy(txData.from, swap->I.etomicsrc); + strcpy(txData.to, ETOMIC_BOBCONTRACT); + strcpy(txData.amount, "0"); + uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); + return bobSendsErc20Deposit(input20, txData); + } } char *LP_etomicbob_refunds_deposit(struct LP_swap_remember *swap) @@ -200,19 +215,35 @@ char *LP_etomicbob_refunds_deposit(struct LP_swap_remember *swap) char *LP_etomicbob_sends_payment(struct basilisk_swap *swap) { BobSendsEthPaymentInput input; + BobSendsErc20PaymentInput input20; BasicTxData txData; memset(&txData,0,sizeof(txData)); memset(&input,0,sizeof(input)); + memset(&input20,0,sizeof(input20)); - uint8arrayToHex(input.paymentId, swap->bobpayment.I.actualtxid.bytes, 32); - strcpy(input.aliceAddress, swap->I.etomicdest); - uint8arrayToHex(input.aliceHash, swap->I.secretAm, 20); + if ( strcmp(swap->I.bobstr,"ETH") == 0 ) { + uint8arrayToHex(input.paymentId, swap->bobpayment.I.actualtxid.bytes, 32); + strcpy(input.aliceAddress, swap->I.etomicdest); + uint8arrayToHex(input.aliceHash, swap->I.secretAm, 20); - strcpy(txData.from, swap->I.etomicsrc); - strcpy(txData.to, ETOMIC_BOBCONTRACT); - satoshisToWei(txData.amount, swap->bobpayment.I.amount); - uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); - return bobSendsEthPayment(input, txData); + strcpy(txData.from, swap->I.etomicsrc); + strcpy(txData.to, ETOMIC_BOBCONTRACT); + satoshisToWei(txData.amount, swap->bobpayment.I.amount); + uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); + return bobSendsEthPayment(input, txData); + } else { + uint8arrayToHex(input20.paymentId, swap->bobpayment.I.actualtxid.bytes, 32); + strcpy(input20.aliceAddress, swap->I.etomicdest); + uint8arrayToHex(input20.aliceHash, swap->I.secretAm, 20); + satoshisToWei(input20.amount, swap->bobpayment.I.amount); + strcpy(input20.tokenAddress, swap->I.bobtomic); + + strcpy(txData.from, swap->I.etomicsrc); + strcpy(txData.to, ETOMIC_BOBCONTRACT); + strcpy(txData.amount, "0"); + uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); + return bobSendsErc20Payment(input20, txData); + } } char *LP_etomicbob_reclaims_payment(struct LP_swap_remember *swap) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 0525ec4a1..6c459971f 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1304,9 +1304,11 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti { if ( (rswap.txbytes[BASILISK_BOBSPEND]= basilisk_swap_Aspend("bobspend",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_BOBSPEND],rswap.alicepaymentaddr,alice->zcash)) != 0 ) { + if (rswap.alicetomic[0] != 0) { + char *bobSpendEthTx = LP_etomicbob_spends_alice_payment(&rswap); + free(bobSpendEthTx); + } //printf("bobspend.(%s)\n",rswap.txbytes[BASILISK_BOBSPEND]); - char *bobSpendEthTx = LP_etomicbob_spends_alice_payment(&rswap); - free(bobSpendEthTx); } } LP_txbytes_update("bobspend",rswap.alicecoin,rswap.txbytes[BASILISK_BOBSPEND],&rswap.txids[BASILISK_BOBSPEND],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_BOBSPEND]);