Skip to content

Commit

Permalink
review: rename validate_state fnc, use extend plus chain in etomic_sw…
Browse files Browse the repository at this point in the history
…ap_v2_id fnc
  • Loading branch information
laruh committed Jun 17, 2024
1 parent e636da1 commit 40ffb65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
8 changes: 4 additions & 4 deletions mm2src/coins/eth/nft_swap_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl EthCoin {
htlc_params: Vec<Token>,
state: U256,
) -> Result<Vec<u8>, 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")?,
Expand Down Expand Up @@ -367,7 +367,7 @@ impl EthCoin {
htlc_params: Vec<Token>,
state: U256,
) -> Result<Vec<u8>, 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")?,
Expand Down Expand Up @@ -398,7 +398,7 @@ impl EthCoin {
htlc_params: Vec<Token>,
state: U256,
) -> Result<Vec<u8>, 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")?,
Expand Down Expand Up @@ -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 {}",
Expand Down

0 comments on commit 40ffb65

Please sign in to comment.