Skip to content

Commit

Permalink
review: consts for TAKER/MAKER state indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
laruh committed Nov 1, 2024
1 parent da12b97 commit 2b81855
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
11 changes: 10 additions & 1 deletion mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ use web3::types::TransactionId;
const ETH_MAKER_PAYMENT: &str = "ethMakerPayment";
const ERC20_MAKER_PAYMENT: &str = "erc20MakerPayment";

/// state index for `MakerPayment` structure from `EtomicSwapMakerV2.sol`
///
/// struct MakerPayment {
/// bytes20 paymentHash;
/// uint32 paymentLockTime;
/// MakerPaymentState state;
/// }
const MAKER_PAYMENT_STATE_INDX: usize = 2;

struct MakerPaymentArgs {
taker_address: Address,
taker_secret_hash: [u8; 32],
Expand Down Expand Up @@ -127,7 +136,7 @@ impl EthCoin {
Token::FixedBytes(swap_id.clone()),
&MAKER_SWAP_V2,
EthPaymentType::MakerPayments,
2,
MAKER_PAYMENT_STATE_INDX,
)
.await?;

Expand Down
20 changes: 15 additions & 5 deletions mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ const ETH_TAKER_PAYMENT: &str = "ethTakerPayment";
const ERC20_TAKER_PAYMENT: &str = "erc20TakerPayment";
const TAKER_PAYMENT_APPROVE: &str = "takerPaymentApprove";

/// state index for `TakerPayment` structure from `EtomicSwapTakerV2.sol`
///
/// struct TakerPayment {
/// bytes20 paymentHash;
/// uint32 preApproveLockTime;
/// uint32 paymentLockTime;
/// TakerPaymentState state;
/// }
const TAKER_PAYMENT_STATE_INDX: usize = 3;

struct TakerFundingArgs {
dex_fee: U256,
payment_amount: U256,
Expand Down Expand Up @@ -147,7 +157,7 @@ impl EthCoin {
Token::FixedBytes(swap_id.clone()),
&TAKER_SWAP_V2,
EthPaymentType::TakerPayments,
3,
TAKER_PAYMENT_STATE_INDX,
)
.await?;

Expand Down Expand Up @@ -220,7 +230,7 @@ impl EthCoin {
decoded[0].clone(),
&TAKER_SWAP_V2,
EthPaymentType::TakerPayments,
3,
TAKER_PAYMENT_STATE_INDX,
)
.await
);
Expand Down Expand Up @@ -371,7 +381,7 @@ impl EthCoin {
decoded[0].clone(), // id from takerPaymentApprove
&TAKER_SWAP_V2,
EthPaymentType::TakerPayments,
3,
TAKER_PAYMENT_STATE_INDX,
)
.await
.map_err(|e| SearchForFundingSpendErr::Internal(ERRL!("{}", e)))?;
Expand Down Expand Up @@ -403,7 +413,7 @@ impl EthCoin {
decoded[0].clone(),
&TAKER_SWAP_V2,
EthPaymentType::TakerPayments,
3,
TAKER_PAYMENT_STATE_INDX,
)
.await
);
Expand Down Expand Up @@ -446,7 +456,7 @@ impl EthCoin {
decoded[0].clone(), // id from spendTakerPayment
&TAKER_SWAP_V2,
EthPaymentType::TakerPayments,
3,
TAKER_PAYMENT_STATE_INDX,
)
.await?;
if taker_status == U256::from(TakerPaymentStateV2::MakerSpent as u8) {
Expand Down

0 comments on commit 2b81855

Please sign in to comment.