From 40ffb653942419305cfa95eeb71441faed3773d4 Mon Sep 17 00:00:00 2001 From: laruh Date: Mon, 17 Jun 2024 14:24:14 +0700 Subject: [PATCH] review: rename validate_state fnc, use extend plus chain in etomic_swap_v2_id fnc --- mm2src/coins/eth.rs | 9 ++++++--- mm2src/coins/eth/nft_swap_v2/mod.rs | 8 ++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index db539429e8..40a05f02f4 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -805,9 +805,12 @@ impl EthCoinImpl { let mut input = Vec::with_capacity(funding_timelock_bytes.len() + payment_timelock_bytes.len() + secret_hash.len()); - input.extend_from_slice(&funding_timelock_bytes); - input.extend_from_slice(&payment_timelock_bytes); - input.extend_from_slice(secret_hash); + input.extend( + funding_timelock_bytes + .iter() + .chain(payment_timelock_bytes.iter()) + .chain(secret_hash.iter()), + ); sha256(&input).to_vec() } diff --git a/mm2src/coins/eth/nft_swap_v2/mod.rs b/mm2src/coins/eth/nft_swap_v2/mod.rs index c60c5304d4..74976662ec 100644 --- a/mm2src/coins/eth/nft_swap_v2/mod.rs +++ b/mm2src/coins/eth/nft_swap_v2/mod.rs @@ -336,7 +336,7 @@ impl EthCoin { htlc_params: Vec, state: U256, ) -> Result, PrepareTxDataError> { - validate_state(args.maker_payment_tx, state, MakerPaymentStateV2::PaymentSent as u8)?; + validate_payment_state(args.maker_payment_tx, state, MakerPaymentStateV2::PaymentSent as u8)?; let spend_func = match args.contract_type { ContractType::Erc1155 => NFT_MAKER_SWAP_V2.function("spendErc1155MakerPayment")?, @@ -367,7 +367,7 @@ impl EthCoin { htlc_params: Vec, state: U256, ) -> Result, PrepareTxDataError> { - validate_state(args.maker_payment_tx, state, MakerPaymentStateV2::PaymentSent as u8)?; + validate_payment_state(args.maker_payment_tx, state, MakerPaymentStateV2::PaymentSent as u8)?; let refund_func = match args.contract_type { ContractType::Erc1155 => NFT_MAKER_SWAP_V2.function("refundErc1155MakerPaymentTimelock")?, @@ -398,7 +398,7 @@ impl EthCoin { htlc_params: Vec, state: U256, ) -> Result, PrepareTxDataError> { - validate_state(args.maker_payment_tx, state, MakerPaymentStateV2::PaymentSent as u8)?; + validate_payment_state(args.maker_payment_tx, state, MakerPaymentStateV2::PaymentSent as u8)?; let refund_func = match args.contract_type { ContractType::Erc1155 => NFT_MAKER_SWAP_V2.function("refundErc1155MakerPaymentSecret")?, @@ -656,7 +656,7 @@ fn erc721_transfer_with_data<'a>() -> Result<&'a ethabi::Function, Erc721Functio Ok(function) } -fn validate_state(tx: &SignedEthTx, state: U256, expected_state: u8) -> Result<(), PrepareTxDataError> { +fn validate_payment_state(tx: &SignedEthTx, state: U256, expected_state: u8) -> Result<(), PrepareTxDataError> { if state != U256::from(expected_state) { return Err(PrepareTxDataError::Internal(ERRL!( "Payment {:?} state is not {}, got {}",