Skip to content

Commit

Permalink
review: create separate Refund Args structures for Timelock and Secre…
Browse files Browse the repository at this point in the history
…t functions
  • Loading branch information
laruh committed Nov 1, 2024
1 parent 2b81855 commit 72ed306
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
22 changes: 14 additions & 8 deletions mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,24 @@ struct MakerValidationArgs<'a> {
payment_time_lock: u64,
}

struct MakerRefundArgs {
struct MakerRefundTimelockArgs {
payment_amount: U256,
taker_address: Address,
taker_secret: [u8; 32],
taker_secret_hash: [u8; 32],
maker_secret_hash: [u8; 32],
payment_time_lock: u64,
token_address: Address,
}

struct MakerRefundSecretArgs {
payment_amount: U256,
taker_address: Address,
taker_secret: [u8; 32],
maker_secret_hash: [u8; 32],
payment_time_lock: u64,
token_address: Address,
}

impl EthCoin {
pub(crate) async fn send_maker_payment_v2_impl(
&self,
Expand Down Expand Up @@ -216,10 +224,9 @@ impl EthCoin {
};
let args = {
let taker_address = public_to_address(&Public::from_slice(args.taker_pub));
MakerRefundArgs {
MakerRefundTimelockArgs {
payment_amount,
taker_address,
taker_secret: [0u8; 32],
taker_secret_hash: try_tx_s!(taker_secret_hash.try_into()),
maker_secret_hash: try_tx_s!(maker_secret_hash.try_into()),
payment_time_lock: args.time_lock,
Expand Down Expand Up @@ -261,11 +268,10 @@ impl EthCoin {
let payment_amount = try_tx_s!(wei_from_big_decimal(&args.amount, self.decimals));
let args = {
let taker_address = public_to_address(args.taker_pub);
MakerRefundArgs {
MakerRefundSecretArgs {
payment_amount,
taker_address,
taker_secret,
taker_secret_hash: [0u8; 32],
maker_secret_hash,
payment_time_lock: args.time_lock,
token_address,
Expand Down Expand Up @@ -348,7 +354,7 @@ impl EthCoin {
/// Prepares data for EtomicSwapMakerV2 contract [refundMakerPaymentTimelock](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapMakerV2.sol#L144) method
async fn prepare_refund_maker_payment_timelock_data(
&self,
args: MakerRefundArgs,
args: MakerRefundTimelockArgs,
) -> Result<Vec<u8>, PrepareTxDataError> {
let function = MAKER_SWAP_V2.function("refundMakerPaymentTimelock")?;
let id = self.etomic_swap_id_v2(args.payment_time_lock, &args.maker_secret_hash);
Expand All @@ -366,7 +372,7 @@ impl EthCoin {
/// Prepares data for EtomicSwapMakerV2 contract [refundMakerPaymentSecret](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapMakerV2.sol#L190) method
async fn prepare_refund_maker_payment_secret_data(
&self,
args: MakerRefundArgs,
args: MakerRefundSecretArgs,
) -> Result<Vec<u8>, PrepareTxDataError> {
let function = MAKER_SWAP_V2.function("refundMakerPaymentSecret")?;
let id = self.etomic_swap_id_v2(args.payment_time_lock, &args.maker_secret_hash);
Expand Down
23 changes: 15 additions & 8 deletions mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,26 @@ struct TakerFundingArgs {
payment_time_lock: u64,
}

struct TakerRefundArgs {
struct TakerRefundTimelockArgs {
dex_fee: U256,
payment_amount: U256,
maker_address: Address,
taker_secret: [u8; 32],
taker_secret_hash: [u8; 32],
maker_secret_hash: [u8; 32],
payment_time_lock: u64,
token_address: Address,
}

struct TakerRefundSecretArgs {
dex_fee: U256,
payment_amount: U256,
maker_address: Address,
taker_secret: [u8; 32],
maker_secret_hash: [u8; 32],
payment_time_lock: u64,
token_address: Address,
}

struct TakerValidationArgs<'a> {
swap_id: Vec<u8>,
amount: U256,
Expand Down Expand Up @@ -291,11 +300,10 @@ impl EthCoin {
},
};

let args = TakerRefundArgs {
let args = TakerRefundTimelockArgs {
dex_fee,
payment_amount,
maker_address,
taker_secret: [0u8; 32],
taker_secret_hash: try_tx_s!(taker_secret_hash.try_into()),
maker_secret_hash: try_tx_s!(maker_secret_hash.try_into()),
payment_time_lock: args.time_lock,
Expand Down Expand Up @@ -343,12 +351,11 @@ impl EthCoin {
));
let maker_address = public_to_address(args.maker_pubkey);

let refund_args = TakerRefundArgs {
let refund_args = TakerRefundSecretArgs {
dex_fee,
payment_amount,
maker_address,
taker_secret,
taker_secret_hash: [0u8; 32],
maker_secret_hash,
payment_time_lock: args.payment_time_lock,
token_address,
Expand Down Expand Up @@ -511,7 +518,7 @@ impl EthCoin {
/// Prepares data for EtomicSwapTakerV2 contract [refundTakerPaymentTimelock](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapTakerV2.sol#L208) method
async fn prepare_taker_refund_payment_timelock_data(
&self,
args: TakerRefundArgs,
args: TakerRefundTimelockArgs,
) -> Result<Vec<u8>, PrepareTxDataError> {
let function = TAKER_SWAP_V2.function("refundTakerPaymentTimelock")?;
let id = self.etomic_swap_id_v2(args.payment_time_lock, &args.maker_secret_hash);
Expand All @@ -530,7 +537,7 @@ impl EthCoin {
/// Prepares data for EtomicSwapTakerV2 contract [refundTakerPaymentSecret](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapTakerV2.sol#L267) method
async fn prepare_taker_refund_payment_secret_data(
&self,
args: &TakerRefundArgs,
args: &TakerRefundSecretArgs,
) -> Result<Vec<u8>, PrepareTxDataError> {
let function = TAKER_SWAP_V2.function("refundTakerPaymentSecret")?;
let id = self.etomic_swap_id_v2(args.payment_time_lock, &args.maker_secret_hash);
Expand Down

0 comments on commit 72ed306

Please sign in to comment.