Browse Source

Add ERC20 bob deposit/payment. Bob spends alice payment only when alicetomic not empty.

etomic
Artem Pikulin 7 years ago
parent
commit
753a1aac7e
  1. 33
      iguana/exchanges/LP_etomic.c
  2. 4
      iguana/exchanges/LP_remember.c

33
iguana/exchanges/LP_etomic.c

@ -144,10 +144,12 @@ char *LP_etomicbob_spends_alice_payment(struct LP_swap_remember *swap)
char *LP_etomicbob_sends_deposit(struct basilisk_swap *swap) char *LP_etomicbob_sends_deposit(struct basilisk_swap *swap)
{ {
BobSendsEthDepositInput input; BobSendsEthDepositInput input;
BobSendsErc20DepositInput input20;
BasicTxData txData; BasicTxData txData;
memset(&txData,0,sizeof(txData)); memset(&txData,0,sizeof(txData));
memset(&input,0,sizeof(input)); 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); uint8arrayToHex(input.depositId, swap->bobdeposit.I.actualtxid.bytes, 32);
strcpy(input.aliceAddress, swap->I.etomicdest); strcpy(input.aliceAddress, swap->I.etomicdest);
uint8arrayToHex(input.bobHash, swap->I.secretBn, 20); uint8arrayToHex(input.bobHash, swap->I.secretBn, 20);
@ -157,6 +159,19 @@ char *LP_etomicbob_sends_deposit(struct basilisk_swap *swap)
satoshisToWei(txData.amount, swap->bobdeposit.I.amount); satoshisToWei(txData.amount, swap->bobdeposit.I.amount);
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32);
return bobSendsEthDeposit(input, txData); 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);
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) char *LP_etomicbob_refunds_deposit(struct LP_swap_remember *swap)
@ -200,10 +215,13 @@ char *LP_etomicbob_refunds_deposit(struct LP_swap_remember *swap)
char *LP_etomicbob_sends_payment(struct basilisk_swap *swap) char *LP_etomicbob_sends_payment(struct basilisk_swap *swap)
{ {
BobSendsEthPaymentInput input; BobSendsEthPaymentInput input;
BobSendsErc20PaymentInput input20;
BasicTxData txData; BasicTxData txData;
memset(&txData,0,sizeof(txData)); memset(&txData,0,sizeof(txData));
memset(&input,0,sizeof(input)); memset(&input,0,sizeof(input));
memset(&input20,0,sizeof(input20));
if ( strcmp(swap->I.bobstr,"ETH") == 0 ) {
uint8arrayToHex(input.paymentId, swap->bobpayment.I.actualtxid.bytes, 32); uint8arrayToHex(input.paymentId, swap->bobpayment.I.actualtxid.bytes, 32);
strcpy(input.aliceAddress, swap->I.etomicdest); strcpy(input.aliceAddress, swap->I.etomicdest);
uint8arrayToHex(input.aliceHash, swap->I.secretAm, 20); uint8arrayToHex(input.aliceHash, swap->I.secretAm, 20);
@ -213,6 +231,19 @@ char *LP_etomicbob_sends_payment(struct basilisk_swap *swap)
satoshisToWei(txData.amount, swap->bobpayment.I.amount); satoshisToWei(txData.amount, swap->bobpayment.I.amount);
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32);
return bobSendsEthPayment(input, txData); 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) char *LP_etomicbob_reclaims_payment(struct LP_swap_remember *swap)

4
iguana/exchanges/LP_remember.c

@ -1304,10 +1304,12 @@ 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.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 )
{ {
//printf("bobspend.(%s)\n",rswap.txbytes[BASILISK_BOBSPEND]); if (rswap.alicetomic[0] != 0) {
char *bobSpendEthTx = LP_etomicbob_spends_alice_payment(&rswap); char *bobSpendEthTx = LP_etomicbob_spends_alice_payment(&rswap);
free(bobSpendEthTx); free(bobSpendEthTx);
} }
//printf("bobspend.(%s)\n",rswap.txbytes[BASILISK_BOBSPEND]);
}
} }
LP_txbytes_update("bobspend",rswap.alicecoin,rswap.txbytes[BASILISK_BOBSPEND],&rswap.txids[BASILISK_BOBSPEND],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_BOBSPEND]); LP_txbytes_update("bobspend",rswap.alicecoin,rswap.txbytes[BASILISK_BOBSPEND],&rswap.txids[BASILISK_BOBSPEND],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_BOBSPEND]);
} }

Loading…
Cancel
Save