Browse Source

Update Bob smart contract integration.

patch-3
Artem Pikulin 7 years ago
parent
commit
d6ed0f2d52
  1. 12
      iguana/exchanges/LP_etomic.c
  2. 48
      iguana/exchanges/etomicswap/etomiclib.cpp
  3. 10
      iguana/exchanges/etomicswap/etomiclib.h

12
iguana/exchanges/LP_etomic.c

@ -278,6 +278,7 @@ char *LP_etomicbob_sends_deposit(struct basilisk_swap *swap)
uint8arrayToHex(input.depositId, swap->bobdeposit.I.actualtxid.bytes, 32);
strcpy(input.aliceAddress, swap->I.etomicdest);
uint8arrayToHex(input.bobHash, swap->I.secretBn, 20);
input.lockTime = swap->bobdeposit.I.locktime;
strcpy(txData.from, swap->I.etomicsrc);
strcpy(txData.to, ETOMIC_BOBCONTRACT);
@ -290,6 +291,7 @@ char *LP_etomicbob_sends_deposit(struct basilisk_swap *swap)
uint8arrayToHex(input20.bobHash, swap->I.secretBn, 20);
satoshisToWei(input20.amount, swap->bobdeposit.I.amount);
strcpy(input20.tokenAddress, swap->I.bobtomic);
input20.lockTime = swap->bobdeposit.I.locktime;
strcpy(txData.from, swap->I.etomicsrc);
strcpy(txData.to, ETOMIC_BOBCONTRACT);
@ -346,6 +348,7 @@ uint8_t LP_etomic_verify_bob_deposit(struct basilisk_swap *swap, char *txId)
uint8arrayToHex(input.depositId, swap->bobdeposit.I.actualtxid.bytes, 32);
strcpy(input.aliceAddress, swap->I.etomicdest);
uint8arrayToHex(input.bobHash, swap->I.secretBn, 20);
input.lockTime = swap->bobdeposit.I.locktime;
return verifyBobEthDepositData(input, data.input);
} else {
@ -354,6 +357,7 @@ uint8_t LP_etomic_verify_bob_deposit(struct basilisk_swap *swap, char *txId)
uint8arrayToHex(input20.bobHash, swap->I.secretBn, 20);
satoshisToWei(input20.amount, swap->bobdeposit.I.amount);
strcpy(input20.tokenAddress, swap->I.bobtomic);
input20.lockTime = swap->bobdeposit.I.locktime;
return verifyBobErc20DepositData(input20, data.input);
}
@ -382,7 +386,6 @@ char *LP_etomicbob_refunds_deposit(struct LP_swap_remember *swap)
}
uint8arrayToHex(input.depositId, swap->txids[BASILISK_BOBDEPOSIT].bytes, 32);
strcpy(input.aliceAddress, swap->etomicdest);
sprintf(input.aliceCanClaimAfter, "%" PRIu64, receipt.blockNumber + 960);
bits256 invertedSecret;
int32_t i;
@ -418,6 +421,7 @@ char *LP_etomicbob_sends_payment(struct basilisk_swap *swap)
uint8arrayToHex(input.paymentId, swap->bobpayment.I.actualtxid.bytes, 32);
strcpy(input.aliceAddress, swap->I.etomicdest);
uint8arrayToHex(input.aliceHash, swap->I.secretAm, 20);
input.lockTime = swap->bobpayment.I.locktime;
strcpy(txData.from, swap->I.etomicsrc);
strcpy(txData.to, ETOMIC_BOBCONTRACT);
@ -430,6 +434,7 @@ char *LP_etomicbob_sends_payment(struct basilisk_swap *swap)
uint8arrayToHex(input20.aliceHash, swap->I.secretAm, 20);
satoshisToWei(input20.amount, swap->bobpayment.I.amount);
strcpy(input20.tokenAddress, swap->I.bobtomic);
input20.lockTime = swap->bobpayment.I.locktime;
strcpy(txData.from, swap->I.etomicsrc);
strcpy(txData.to, ETOMIC_BOBCONTRACT);
@ -485,6 +490,7 @@ uint8_t LP_etomic_verify_bob_payment(struct basilisk_swap *swap, char *txId)
uint8arrayToHex(input.paymentId, swap->bobpayment.I.actualtxid.bytes, 32);
strcpy(input.aliceAddress, swap->I.etomicdest);
uint8arrayToHex(input.aliceHash, swap->I.secretAm, 20);
input.lockTime = swap->bobpayment.I.locktime;
return verifyBobEthPaymentData(input, data.input);
} else {
@ -493,6 +499,7 @@ uint8_t LP_etomic_verify_bob_payment(struct basilisk_swap *swap, char *txId)
uint8arrayToHex(input20.aliceHash, swap->I.secretAm, 20);
satoshisToWei(input20.amount, swap->bobpayment.I.amount);
strcpy(input20.tokenAddress, swap->I.bobtomic);
input20.lockTime = swap->bobpayment.I.locktime;
return verifyBobErc20PaymentData(input20, data.input);
}
@ -521,7 +528,6 @@ char *LP_etomicbob_reclaims_payment(struct LP_swap_remember *swap)
}
uint8arrayToHex(input.paymentId, swap->txids[BASILISK_BOBPAYMENT].bytes, 32);
strcpy(input.aliceAddress, swap->etomicdest);
sprintf(input.bobCanClaimAfter, "%" PRIu64, receipt.blockNumber + 480);
uint8arrayToHex(input.aliceHash, swap->secretAm, 20);
if (swap->bobtomic[0] != 0) {
@ -561,7 +567,6 @@ char *LP_etomicalice_spends_bob_payment(struct LP_swap_remember *swap)
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);
@ -608,7 +613,6 @@ char *LP_etomicalice_claims_bob_deposit(struct LP_swap_remember *swap)
uint8arrayToHex(input.depositId, swap->txids[BASILISK_BOBDEPOSIT].bytes, 32);
satoshisToWei(input.amount, swap->values[BASILISK_BOBDEPOSIT]);
sprintf(input.aliceCanClaimAfter, "%" PRIu64, receipt.blockNumber + 960);
if (swap->bobtomic[0] != 0) {
strcpy(input.tokenAddress, swap->bobtomic);

48
iguana/exchanges/etomicswap/etomiclib.cpp

@ -206,13 +206,15 @@ char* bobSpendsAlicePayment(BobSpendsAlicePaymentInput input, BasicTxData txData
std::stringstream bobSendsEthDepositData(BobSendsEthDepositInput input)
{
u256 lockTime = input.lockTime;
std::stringstream ss;
ss << "0xc2c5143f"
ss << "0xdd23795f"
<< toHex(jsToBytes(input.depositId))
<< "000000000000000000000000"
<< toHex(jsToAddress(input.aliceAddress))
<< toHex(jsToBytes(input.bobHash))
<< "000000000000000000000000";
<< "000000000000000000000000"
<< toHex(toBigEndian(lockTime));
return ss;
}
@ -241,11 +243,12 @@ std::stringstream bobSendsErc20DepositData(BobSendsErc20DepositInput input)
{
uint8_t decimals = getErc20Decimals(input.tokenAddress);
u256 amount = jsToU256(input.amount);
u256 lockTime = input.lockTime;
if (decimals < 18) {
amount /= boost::multiprecision::pow(u256(10), 18 - decimals);
}
std::stringstream ss;
ss << "0xce8bbe4b"
ss << "0x5d567259"
<< toHex(jsToBytes(input.depositId))
<< toHex(toBigEndian(amount))
<< "000000000000000000000000"
@ -253,7 +256,8 @@ std::stringstream bobSendsErc20DepositData(BobSendsErc20DepositInput input)
<< toHex(jsToBytes(input.bobHash))
<< "000000000000000000000000"
<< "000000000000000000000000"
<< toHex(jsToAddress(input.tokenAddress));
<< toHex(jsToAddress(input.tokenAddress))
<< toHex(toBigEndian(lockTime));
return ss;
}
@ -290,17 +294,14 @@ char* bobRefundsDeposit(BobRefundsDepositInput input, BasicTxData txData)
amount /= boost::multiprecision::pow(u256(10), 18 - decimals);
}
}
ss << "0x1dbe6508"
ss << "0x1f7a72f7"
<< toHex(jsToBytes(input.depositId))
<< toHex(toBigEndian(amount))
<< toHex(toBigEndian(jsToU256(input.aliceCanClaimAfter)))
<< toHex(jsToBytes(input.bobSecret))
<< "000000000000000000000000"
<< toHex(jsToAddress(input.aliceAddress))
<< "000000000000000000000000"
<< toHex(tokenAddress)
<< "00000000000000000000000000000000000000000000000000000000000000c0"
<< "0000000000000000000000000000000000000000000000000000000000000020"
<< toHex(jsToBytes(input.bobSecret));
<< toHex(tokenAddress);
tx.data = jsToBytes(ss.str());
char* rawTx = signTx(tx, txData.secretKey);
char* result = sendRawTxWaitConfirm(rawTx);
@ -320,10 +321,9 @@ char* aliceClaimsBobDeposit(AliceClaimsBobDepositInput input, BasicTxData txData
amount /= boost::multiprecision::pow(u256(10), 18 - decimals);
}
}
ss << "0x960173b5"
ss << "0x4b915a68"
<< toHex(jsToBytes(input.depositId))
<< toHex(toBigEndian(amount))
<< toHex(toBigEndian(jsToU256(input.aliceCanClaimAfter)))
<< "000000000000000000000000"
<< toHex(jsToAddress(input.bobAddress))
<< "000000000000000000000000"
@ -339,13 +339,15 @@ char* aliceClaimsBobDeposit(AliceClaimsBobDepositInput input, BasicTxData txData
std::stringstream bobSendsEthPaymentData(BobSendsEthPaymentInput input)
{
u256 lockTime = input.lockTime;
std::stringstream ss;
ss << "0xcf36fe8e"
ss << "0x5ab30d95"
<< toHex(jsToBytes(input.paymentId))
<< "000000000000000000000000"
<< toHex(jsToAddress(input.aliceAddress))
<< toHex(jsToBytes(input.aliceHash))
<< "000000000000000000000000";
<< "000000000000000000000000"
<< toHex(toBigEndian(lockTime));
return ss;
}
@ -374,11 +376,12 @@ std::stringstream bobSendsErc20PaymentData(BobSendsErc20PaymentInput input)
{
uint8_t decimals = getErc20Decimals(input.tokenAddress);
u256 amount = jsToU256(input.amount);
u256 lockTime = input.lockTime;
if (decimals < 18) {
amount /= boost::multiprecision::pow(u256(10), 18 - decimals);
}
std::stringstream ss;
ss << "0x34f64dfd"
ss << "0xb8a15b1d"
<< toHex(jsToBytes(input.paymentId))
<< toHex(toBigEndian(amount))
<< "000000000000000000000000"
@ -386,7 +389,8 @@ std::stringstream bobSendsErc20PaymentData(BobSendsErc20PaymentInput input)
<< toHex(jsToBytes(input.aliceHash))
<< "000000000000000000000000"
<< "000000000000000000000000"
<< toHex(jsToAddress(input.tokenAddress));
<< toHex(jsToAddress(input.tokenAddress))
<< toHex(toBigEndian(lockTime));
return ss;
}
@ -423,10 +427,9 @@ char* bobReclaimsBobPayment(BobReclaimsBobPaymentInput input, BasicTxData txData
amount /= boost::multiprecision::pow(u256(10), 18 - decimals);
}
}
ss << "0xb7cc2312"
ss << "0xe45ef4ad"
<< toHex(jsToBytes(input.paymentId))
<< toHex(toBigEndian(amount))
<< toHex(toBigEndian(jsToU256(input.bobCanClaimAfter)))
<< "000000000000000000000000"
<< toHex(jsToAddress(input.aliceAddress))
<< "000000000000000000000000"
@ -452,17 +455,14 @@ char* aliceSpendsBobPayment(AliceSpendsBobPaymentInput input, BasicTxData txData
amount /= boost::multiprecision::pow(u256(10), 18 - decimals);
}
}
ss << "0x97004255"
ss << "0x113ee583"
<< toHex(jsToBytes(input.paymentId))
<< toHex(toBigEndian(amount))
<< toHex(toBigEndian(jsToU256(input.bobCanClaimAfter)))
<< toHex(jsToBytes(input.aliceSecret))
<< "000000000000000000000000"
<< toHex(jsToAddress(input.bobAddress))
<< "000000000000000000000000"
<< toHex(tokenAddress)
<< "00000000000000000000000000000000000000000000000000000000000000c0"
<< "0000000000000000000000000000000000000000000000000000000000000020"
<< toHex(jsToBytes(input.aliceSecret));
<< toHex(tokenAddress);
tx.data = jsToBytes(ss.str());
char* rawTx = signTx(tx, txData.secretKey);
char* result = sendRawTxWaitConfirm(rawTx);

10
iguana/exchanges/etomicswap/etomiclib.h

@ -9,7 +9,7 @@ extern "C" {
#ifdef ETOMIC_TESTNET
#define ETOMIC_ALICECONTRACT "0xe1d4236c5774d35dc47dcc2e5e0ccfc463a3289c"
#define ETOMIC_BOBCONTRACT "0x9387fd3a016bb0205e4e131dde886b9d2bc000a2"
#define ETOMIC_BOBCONTRACT "0x2a8e4f9ae69c86e277602c6802085febc4bd5986"
#else
#define ETOMIC_ALICECONTRACT "0x9bc5418ceded51db08467fc4b62f32c5d9ebda55"
#define ETOMIC_BOBCONTRACT "0xb1ad803ea4f57401639c123000c75f5b66e4d123"
@ -63,6 +63,7 @@ typedef struct {
char depositId[70];
char aliceAddress[65];
char bobHash[65];
uint64_t lockTime;
} BobSendsEthDepositInput;
typedef struct {
@ -71,6 +72,7 @@ typedef struct {
char tokenAddress[65];
char aliceAddress[65];
char bobHash[65];
uint64_t lockTime;
} BobSendsErc20DepositInput;
typedef struct {
@ -79,7 +81,6 @@ typedef struct {
char tokenAddress[65];
char aliceAddress[65];
char bobSecret[70];
char aliceCanClaimAfter[100];
} BobRefundsDepositInput;
typedef struct {
@ -88,13 +89,13 @@ typedef struct {
char tokenAddress[65];
char bobAddress[65];
char bobHash[65];
char aliceCanClaimAfter[100];
} AliceClaimsBobDepositInput;
typedef struct {
char paymentId[70];
char aliceAddress[65];
char aliceHash[65];
uint64_t lockTime;
} BobSendsEthPaymentInput;
typedef struct {
@ -103,6 +104,7 @@ typedef struct {
char tokenAddress[65];
char aliceAddress[65];
char aliceHash[65];
uint64_t lockTime;
} BobSendsErc20PaymentInput;
typedef struct {
@ -111,7 +113,6 @@ typedef struct {
char tokenAddress[65];
char aliceAddress[65];
char aliceHash[65];
char bobCanClaimAfter[100];
} BobReclaimsBobPaymentInput;
typedef struct {
@ -120,7 +121,6 @@ typedef struct {
char tokenAddress[65];
char aliceSecret[70];
char bobAddress[65];
char bobCanClaimAfter[100];
} AliceSpendsBobPaymentInput;
typedef struct {

Loading…
Cancel
Save