From df3d39c1ab4017ff8498a4028bc66b551b0c9c3f Mon Sep 17 00:00:00 2001 From: shamardy <39480341+shamardy@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:26:56 +0300 Subject: [PATCH] refactor(SwapOps): make all methods async (#2251) --- mm2src/coins/eth.rs | 144 ++++++------ mm2src/coins/eth/eth_tests.rs | 18 +- mm2src/coins/lightning.rs | 56 +++-- mm2src/coins/lp_coins.rs | 21 +- mm2src/coins/qrc20.rs | 120 +++++----- mm2src/coins/qrc20/qrc20_tests.rs | 12 +- mm2src/coins/siacoin.rs | 26 ++- mm2src/coins/tendermint/tendermint_coin.rs | 55 ++--- mm2src/coins/tendermint/tendermint_token.rs | 88 ++++---- mm2src/coins/test_coin.rs | 20 +- mm2src/coins/utxo/bch.rs | 50 +++-- mm2src/coins/utxo/qtum.rs | 50 +++-- mm2src/coins/utxo/slp.rs | 105 +++++---- mm2src/coins/utxo/utxo_standard.rs | 50 +++-- mm2src/coins/utxo/utxo_tests.rs | 10 +- mm2src/coins/z_coin.rs | 211 +++++++++--------- mm2src/coins/z_coin/z_coin_native_tests.rs | 16 +- mm2src/mm2_main/src/lp_swap/maker_swap.rs | 41 ++-- mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs | 1 - mm2src/mm2_main/src/lp_swap/swap_watcher.rs | 1 - mm2src/mm2_main/src/lp_swap/taker_swap.rs | 70 +++--- mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 1 - .../tests/docker_tests/docker_tests_inner.rs | 4 +- .../tests/docker_tests/qrc20_tests.rs | 20 +- .../tests/docker_tests/swap_watcher_tests.rs | 30 +-- 25 files changed, 645 insertions(+), 575 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 5fc048af7a..068c750d37 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -1105,16 +1105,21 @@ impl Deref for EthCoin { #[async_trait] impl SwapOps for EthCoin { - fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, _uuid: &[u8], _expire_at: u64) -> TransactionFut { - let address = try_tx_fus!(addr_from_raw_pubkey(fee_addr)); - - Box::new( - self.send_to_address( - address, - try_tx_fus!(wei_from_big_decimal(&dex_fee.fee_amount().into(), self.decimals)), - ) - .map(TransactionEnum::from), + async fn send_taker_fee( + &self, + fee_addr: &[u8], + dex_fee: DexFee, + _uuid: &[u8], + _expire_at: u64, + ) -> TransactionResult { + let address = try_tx_s!(addr_from_raw_pubkey(fee_addr)); + self.send_to_address( + address, + try_tx_s!(wei_from_big_decimal(&dex_fee.fee_amount().into(), self.decimals)), ) + .map(TransactionEnum::from) + .compat() + .await } async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { @@ -1124,11 +1129,11 @@ impl SwapOps for EthCoin { .map(TransactionEnum::from) } - fn send_taker_payment(&self, taker_payment: SendPaymentArgs) -> TransactionFut { - Box::new( - self.send_hash_time_locked_payment(taker_payment) - .map(TransactionEnum::from), - ) + async fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { + self.send_hash_time_locked_payment(taker_payment_args) + .map(TransactionEnum::from) + .compat() + .await } async fn send_maker_spends_taker_payment( @@ -1161,10 +1166,15 @@ impl SwapOps for EthCoin { .map(TransactionEnum::from) } - fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentFut<()> { + async fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentResult<()> { let tx = match validate_fee_args.fee_tx { TransactionEnum::SignedEthTx(t) => t.clone(), - _ => panic!(), + fee_tx => { + return MmError::err(ValidatePaymentError::InternalError(format!( + "Invalid fee tx type. fee tx: {:?}", + fee_tx + ))) + }, }; validate_fee_impl(self.clone(), EthValidateFeeArgs { fee_tx_hash: &tx.tx_hash(), @@ -1174,6 +1184,8 @@ impl SwapOps for EthCoin { min_block_number: validate_fee_args.min_block_number, uuid: validate_fee_args.uuid, }) + .compat() + .await } #[inline] @@ -1186,70 +1198,62 @@ impl SwapOps for EthCoin { self.validate_payment(input).compat().await } - fn check_if_my_payment_sent( + async fn check_if_my_payment_sent( &self, - if_my_payment_sent_args: CheckIfMyPaymentSentArgs, - ) -> Box, Error = String> + Send> { - let id = self.etomic_swap_id( - try_fus!(if_my_payment_sent_args.time_lock.try_into()), - if_my_payment_sent_args.secret_hash, - ); - let swap_contract_address = try_fus!(if_my_payment_sent_args.swap_contract_address.try_to_address()); - let selfi = self.clone(); + if_my_payment_sent_args: CheckIfMyPaymentSentArgs<'_>, + ) -> Result, String> { + let time_lock = if_my_payment_sent_args + .time_lock + .try_into() + .map_err(|e: TryFromIntError| e.to_string())?; + let id = self.etomic_swap_id(time_lock, if_my_payment_sent_args.secret_hash); + let swap_contract_address = if_my_payment_sent_args.swap_contract_address.try_to_address()?; let from_block = if_my_payment_sent_args.search_from_block; - let fut = async move { - let status = try_s!( - selfi - .payment_status(swap_contract_address, Token::FixedBytes(id.clone())) - .compat() - .await - ); + let status = self + .payment_status(swap_contract_address, Token::FixedBytes(id.clone())) + .compat() + .await?; - if status == U256::from(PaymentState::Uninitialized as u8) { - return Ok(None); - }; + if status == U256::from(PaymentState::Uninitialized as u8) { + return Ok(None); + }; - let mut current_block = try_s!(selfi.current_block().compat().await); - if current_block < from_block { - current_block = from_block; - } + let mut current_block = self.current_block().compat().await?; + if current_block < from_block { + current_block = from_block; + } - let mut from_block = from_block; + let mut from_block = from_block; - loop { - let to_block = current_block.min(from_block + selfi.logs_block_range); + loop { + let to_block = current_block.min(from_block + self.logs_block_range); - let events = try_s!( - selfi - .payment_sent_events(swap_contract_address, from_block, to_block) - .compat() - .await - ); + let events = self + .payment_sent_events(swap_contract_address, from_block, to_block) + .compat() + .await?; - let found = events.iter().find(|event| &event.data.0[..32] == id.as_slice()); + let found = events.iter().find(|event| &event.data.0[..32] == id.as_slice()); - match found { - Some(event) => { - let transaction = try_s!( - selfi - .transaction(TransactionId::Hash(event.transaction_hash.unwrap())) - .await - ); - match transaction { - Some(t) => break Ok(Some(try_s!(signed_tx_from_web3_tx(t)).into())), - None => break Ok(None), - } - }, - None => { - if to_block >= current_block { - break Ok(None); - } - from_block = to_block; - }, - } + match found { + Some(event) => { + let transaction = try_s!( + self.transaction(TransactionId::Hash(event.transaction_hash.unwrap())) + .await + ); + match transaction { + Some(t) => break Ok(Some(try_s!(signed_tx_from_web3_tx(t)).into())), + None => break Ok(None), + } + }, + None => { + if to_block >= current_block { + break Ok(None); + } + from_block = to_block; + }, } - }; - Box::new(fut.boxed().compat()) + } } async fn search_for_swap_tx_spend_my( diff --git a/mm2src/coins/eth/eth_tests.rs b/mm2src/coins/eth/eth_tests.rs index 03705ff4ca..c7f1e51d13 100644 --- a/mm2src/coins/eth/eth_tests.rs +++ b/mm2src/coins/eth/eth_tests.rs @@ -591,9 +591,7 @@ fn validate_dex_fee_invalid_sender_eth() { min_block_number: 0, uuid: &[], }; - let error = block_on_f01(coin.validate_fee(validate_fee_args)) - .unwrap_err() - .into_inner(); + let error = block_on(coin.validate_fee(validate_fee_args)).unwrap_err().into_inner(); match error { ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("was sent from wrong address")), _ => panic!("Expected `WrongPaymentTx` wrong sender address, found {:?}", error), @@ -629,9 +627,7 @@ fn validate_dex_fee_invalid_sender_erc() { min_block_number: 0, uuid: &[], }; - let error = block_on_f01(coin.validate_fee(validate_fee_args)) - .unwrap_err() - .into_inner(); + let error = block_on(coin.validate_fee(validate_fee_args)).unwrap_err().into_inner(); match error { ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("was sent from wrong address")), _ => panic!("Expected `WrongPaymentTx` wrong sender address, found {:?}", error), @@ -671,9 +667,7 @@ fn validate_dex_fee_eth_confirmed_before_min_block() { min_block_number: 11784793, uuid: &[], }; - let error = block_on_f01(coin.validate_fee(validate_fee_args)) - .unwrap_err() - .into_inner(); + let error = block_on(coin.validate_fee(validate_fee_args)).unwrap_err().into_inner(); match error { ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("confirmed before min_block")), _ => panic!("Expected `WrongPaymentTx` early confirmation, found {:?}", error), @@ -712,9 +706,7 @@ fn validate_dex_fee_erc_confirmed_before_min_block() { min_block_number: 11823975, uuid: &[], }; - let error = block_on_f01(coin.validate_fee(validate_fee_args)) - .unwrap_err() - .into_inner(); + let error = block_on(coin.validate_fee(validate_fee_args)).unwrap_err().into_inner(); match error { ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("confirmed before min_block")), _ => panic!("Expected `WrongPaymentTx` early confirmation, found {:?}", error), @@ -838,7 +830,7 @@ fn polygon_check_if_my_payment_sent() { amount: &BigDecimal::default(), payment_instructions: &None, }; - let my_payment = block_on_f01(coin.check_if_my_payment_sent(if_my_payment_sent_args)) + let my_payment = block_on(coin.check_if_my_payment_sent(if_my_payment_sent_args)) .unwrap() .unwrap(); let expected_hash = BytesJson::from("69a20008cea0c15ee483b5bbdff942752634aa072dfd2ff715fe87eec302de11"); diff --git a/mm2src/coins/lightning.rs b/mm2src/coins/lightning.rs index 14478a670c..ce97c96cb3 100644 --- a/mm2src/coins/lightning.rs +++ b/mm2src/coins/lightning.rs @@ -610,9 +610,14 @@ impl LightningCoin { #[async_trait] impl SwapOps for LightningCoin { // Todo: This uses dummy data for now for the sake of swap P.O.C., this should be implemented probably after agreeing on how fees will work for lightning - fn send_taker_fee(&self, _fee_addr: &[u8], _dex_fee: DexFee, _uuid: &[u8], _expire_at: u64) -> TransactionFut { - let fut = async move { Ok(TransactionEnum::LightningPayment(PaymentHash([1; 32]))) }; - Box::new(fut.boxed().compat()) + async fn send_taker_fee( + &self, + _fee_addr: &[u8], + _dex_fee: DexFee, + _uuid: &[u8], + _expire_at: u64, + ) -> TransactionResult { + Ok(TransactionEnum::LightningPayment(PaymentHash([1; 32]))) } async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { @@ -626,23 +631,19 @@ impl SwapOps for LightningCoin { Ok(payment.payment_hash.into()) } - fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionFut { + async fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { let invoice = match taker_payment_args.payment_instructions.clone() { Some(PaymentInstructions::Lightning(invoice)) => invoice, - _ => try_tx_fus!(ERR!("Invalid instructions, ligntning invoice is expected")), + _ => try_tx_s!(ERR!("Invalid instructions, ligntning invoice is expected")), }; let max_total_cltv_expiry_delta = self .estimate_blocks_from_duration(taker_payment_args.time_lock_duration) .try_into() .expect("max_total_cltv_expiry_delta shouldn't exceed u32::MAX"); - let coin = self.clone(); - let fut = async move { - // Todo: The path/s used is already logged when PaymentPathSuccessful/PaymentPathFailed events are fired, it might be better to save it to the DB and retrieve it with the payment info. - let payment = try_tx_s!(coin.pay_invoice(invoice, Some(max_total_cltv_expiry_delta)).await); - Ok(payment.payment_hash.into()) - }; - Box::new(fut.boxed().compat()) + // Todo: The path/s used is already logged when PaymentPathSuccessful/PaymentPathFailed events are fired, it might be better to save it to the DB and retrieve it with the payment info. + let payment = try_tx_s!(self.pay_invoice(invoice, Some(max_total_cltv_expiry_delta)).await); + Ok(payment.payment_hash.into()) } #[inline] @@ -680,9 +681,7 @@ impl SwapOps for LightningCoin { } // Todo: This validates the dummy fee for now for the sake of swap P.O.C., this should be implemented probably after agreeing on how fees will work for lightning - fn validate_fee(&self, _validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentFut<()> { - Box::new(futures01::future::ok(())) - } + async fn validate_fee(&self, _validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentResult<()> { Ok(()) } #[inline] async fn validate_maker_payment(&self, input: ValidatePaymentInput) -> ValidatePaymentResult<()> { @@ -694,29 +693,26 @@ impl SwapOps for LightningCoin { self.validate_swap_payment(input).compat().await } - fn check_if_my_payment_sent( + async fn check_if_my_payment_sent( &self, if_my_payment_sent_args: CheckIfMyPaymentSentArgs<'_>, - ) -> Box, Error = String> + Send> { + ) -> Result, String> { let invoice = match if_my_payment_sent_args.payment_instructions.clone() { Some(PaymentInstructions::Lightning(invoice)) => invoice, - _ => try_f!(ERR!("Invalid instructions, ligntning invoice is expected")), + _ => return ERR!("Invalid instructions, ligntning invoice is expected"), }; let payment_hash = PaymentHash((invoice.payment_hash()).into_inner()); let payment_hex = hex::encode(payment_hash.0); - let coin = self.clone(); - let fut = async move { - match coin.db.get_payment_from_db(payment_hash).await { - Ok(maybe_payment) => Ok(maybe_payment.map(|p| p.payment_hash.into())), - Err(e) => ERR!( - "Unable to check if payment {} is in db or not error: {}", - payment_hex, - e - ), - } - }; - Box::new(fut.boxed().compat()) + + match self.db.get_payment_from_db(payment_hash).await { + Ok(maybe_payment) => Ok(maybe_payment.map(|p| p.payment_hash.into())), + Err(e) => ERR!( + "Unable to check if payment {} is in db or not error: {}", + payment_hex, + e + ), + } } // Todo: need to also check on-chain spending diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 89740441a7..fb2b2c07ec 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1069,11 +1069,11 @@ pub enum WatcherRewardError { /// Swap operations (mostly based on the Hash/Time locked transactions implemented by coin wallets). #[async_trait] pub trait SwapOps { - fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, uuid: &[u8], expire_at: u64) -> TransactionFut; + async fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, uuid: &[u8], expire_at: u64) -> TransactionResult; async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult; - fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionFut; + async fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionResult; async fn send_maker_spends_taker_payment( &self, @@ -1089,16 +1089,16 @@ pub trait SwapOps { async fn send_maker_refunds_payment(&self, maker_refunds_payment_args: RefundPaymentArgs<'_>) -> TransactionResult; - fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentFut<()>; + async fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentResult<()>; async fn validate_maker_payment(&self, input: ValidatePaymentInput) -> ValidatePaymentResult<()>; async fn validate_taker_payment(&self, input: ValidatePaymentInput) -> ValidatePaymentResult<()>; - fn check_if_my_payment_sent( + async fn check_if_my_payment_sent( &self, if_my_payment_sent_args: CheckIfMyPaymentSentArgs<'_>, - ) -> Box, Error = String> + Send>; + ) -> Result, String>; async fn search_for_swap_tx_spend_my( &self, @@ -1122,14 +1122,13 @@ pub trait SwapOps { /// Whether the refund transaction can be sent now /// For example: there are no additional conditions for ETH, but for some UTXO coins we should wait for /// locktime < MTP - fn can_refund_htlc(&self, locktime: u64) -> Box + Send + '_> { + async fn can_refund_htlc(&self, locktime: u64) -> Result { let now = now_sec(); - let result = if now > locktime { - CanRefundHtlc::CanRefundNow + if now > locktime { + Ok(CanRefundHtlc::CanRefundNow) } else { - CanRefundHtlc::HaveToWait(locktime - now + 1) - }; - Box::new(futures01::future::ok(result)) + Ok(CanRefundHtlc::HaveToWait(locktime - now + 1)) + } } /// Whether the swap payment is refunded automatically or not when the locktime expires, or the other side fails the HTLC. diff --git a/mm2src/coins/qrc20.rs b/mm2src/coins/qrc20.rs index 6ffadb1d4e..3f86b78539 100644 --- a/mm2src/coins/qrc20.rs +++ b/mm2src/coins/qrc20.rs @@ -56,6 +56,7 @@ use serde_json::{self as json, Value as Json}; use serialization::{deserialize, serialize, CoinVariant}; use std::collections::{HashMap, HashSet}; use std::convert::TryInto; +use std::num::TryFromIntError; use std::ops::{Deref, Neg}; #[cfg(not(target_arch = "wasm32"))] use std::path::PathBuf; use std::str::FromStr; @@ -758,17 +759,18 @@ impl UtxoCommonOps for Qrc20Coin { #[async_trait] impl SwapOps for Qrc20Coin { - fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, _uuid: &[u8], _expire_at: u64) -> TransactionFut { - let to_address = try_tx_fus!(self.contract_address_from_raw_pubkey(fee_addr)); - let amount = try_tx_fus!(wei_from_big_decimal(&dex_fee.fee_amount().into(), self.utxo.decimals)); + async fn send_taker_fee( + &self, + fee_addr: &[u8], + dex_fee: DexFee, + _uuid: &[u8], + _expire_at: u64, + ) -> TransactionResult { + let to_address = try_tx_s!(self.contract_address_from_raw_pubkey(fee_addr)); + let amount = try_tx_s!(wei_from_big_decimal(&dex_fee.fee_amount().into(), self.utxo.decimals)); let transfer_output = - try_tx_fus!(self.transfer_output(to_address, amount, QRC20_GAS_LIMIT_DEFAULT, QRC20_GAS_PRICE_DEFAULT)); - let outputs = vec![transfer_output]; - - let selfi = self.clone(); - let fut = async move { selfi.send_contract_calls(outputs).await }; - - Box::new(fut.boxed().compat()) + try_tx_s!(self.transfer_output(to_address, amount, QRC20_GAS_LIMIT_DEFAULT, QRC20_GAS_PRICE_DEFAULT)); + self.send_contract_calls(vec![transfer_output]).await } async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { @@ -784,21 +786,15 @@ impl SwapOps for Qrc20Coin { } #[inline] - fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs) -> TransactionFut { - let time_lock = try_tx_fus!(taker_payment_args.time_lock.try_into()); - let maker_addr = try_tx_fus!(self.contract_address_from_raw_pubkey(taker_payment_args.other_pubkey)); + async fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { + let time_lock = try_tx_s!(taker_payment_args.time_lock.try_into()); + let maker_addr = try_tx_s!(self.contract_address_from_raw_pubkey(taker_payment_args.other_pubkey)); let id = qrc20_swap_id(time_lock, taker_payment_args.secret_hash); - let value = try_tx_fus!(wei_from_big_decimal(&taker_payment_args.amount, self.utxo.decimals)); + let value = try_tx_s!(wei_from_big_decimal(&taker_payment_args.amount, self.utxo.decimals)); let secret_hash = Vec::from(taker_payment_args.secret_hash); - let swap_contract_address = try_tx_fus!(taker_payment_args.swap_contract_address.try_to_address()); - - let selfi = self.clone(); - let fut = async move { - selfi - .send_hash_time_locked_payment(id, value, time_lock, secret_hash, maker_addr, swap_contract_address) - .await - }; - Box::new(fut.boxed().compat()) + let swap_contract_address = try_tx_s!(taker_payment_args.swap_contract_address.try_to_address()); + self.send_hash_time_locked_payment(id, value, time_lock, secret_hash, maker_addr, swap_contract_address) + .await } #[inline] @@ -850,39 +846,36 @@ impl SwapOps for Qrc20Coin { } #[inline] - fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentFut<()> { - let fee_tx = validate_fee_args.fee_tx; - let min_block_number = validate_fee_args.min_block_number; - let fee_tx = match fee_tx { + async fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentResult<()> { + let fee_tx = match validate_fee_args.fee_tx { TransactionEnum::UtxoTx(tx) => tx, - _ => panic!("Unexpected TransactionEnum"), + fee_tx => { + return MmError::err(ValidatePaymentError::InternalError(format!( + "Invalid fee tx type. fee tx: {:?}", + fee_tx + ))) + }, }; let fee_tx_hash = fee_tx.hash().reversed().into(); - let inputs_signed_by_pub = try_f!(check_all_utxo_inputs_signed_by_pub( - fee_tx, - validate_fee_args.expected_sender - )); + let inputs_signed_by_pub = check_all_utxo_inputs_signed_by_pub(fee_tx, validate_fee_args.expected_sender)?; if !inputs_signed_by_pub { - return Box::new(futures01::future::err( - ValidatePaymentError::WrongPaymentTx("The dex fee was sent from wrong address".to_string()).into(), + return MmError::err(ValidatePaymentError::WrongPaymentTx( + "The dex fee was sent from wrong address".to_string(), )); } - let fee_addr = try_f!(self + let fee_addr = self .contract_address_from_raw_pubkey(validate_fee_args.fee_addr) - .map_to_mm(ValidatePaymentError::WrongPaymentTx)); - let expected_value = try_f!(wei_from_big_decimal( - &validate_fee_args.dex_fee.fee_amount().into(), - self.utxo.decimals - )); - - let selfi = self.clone(); - let fut = async move { - selfi - .validate_fee_impl(fee_tx_hash, fee_addr, expected_value, min_block_number) - .await - .map_to_mm(ValidatePaymentError::WrongPaymentTx) - }; - Box::new(fut.boxed().compat()) + .map_to_mm(ValidatePaymentError::WrongPaymentTx)?; + let expected_value = wei_from_big_decimal(&validate_fee_args.dex_fee.fee_amount().into(), self.utxo.decimals)?; + + self.validate_fee_impl( + fee_tx_hash, + fee_addr, + expected_value, + validate_fee_args.min_block_number, + ) + .await + .map_to_mm(ValidatePaymentError::WrongPaymentTx) } #[inline] @@ -938,24 +931,23 @@ impl SwapOps for Qrc20Coin { } #[inline] - fn check_if_my_payment_sent( + async fn check_if_my_payment_sent( &self, if_my_payment_sent_args: CheckIfMyPaymentSentArgs<'_>, - ) -> Box, Error = String> + Send> { - let search_from_block = if_my_payment_sent_args.search_from_block; - let swap_id = qrc20_swap_id( - try_fus!(if_my_payment_sent_args.time_lock.try_into()), - if_my_payment_sent_args.secret_hash, - ); - let swap_contract_address = try_fus!(if_my_payment_sent_args.swap_contract_address.try_to_address()); + ) -> Result, String> { + let time_lock = if_my_payment_sent_args + .time_lock + .try_into() + .map_err(|e: TryFromIntError| e.to_string())?; + let swap_id = qrc20_swap_id(time_lock, if_my_payment_sent_args.secret_hash); + let swap_contract_address = if_my_payment_sent_args.swap_contract_address.try_to_address()?; - let selfi = self.clone(); - let fut = async move { - selfi - .check_if_my_payment_sent_impl(swap_contract_address, swap_id, search_from_block) - .await - }; - Box::new(fut.boxed().compat()) + self.check_if_my_payment_sent_impl( + swap_contract_address, + swap_id, + if_my_payment_sent_args.search_from_block, + ) + .await } #[inline] diff --git a/mm2src/coins/qrc20/qrc20_tests.rs b/mm2src/coins/qrc20/qrc20_tests.rs index d77afa2f9b..930f078c53 100644 --- a/mm2src/coins/qrc20/qrc20_tests.rs +++ b/mm2src/coins/qrc20/qrc20_tests.rs @@ -336,7 +336,7 @@ fn test_validate_fee() { let amount = BigDecimal::from_str("0.01").unwrap(); - let result = block_on_f01(coin.validate_fee(ValidateFeeArgs { + let result = block_on(coin.validate_fee(ValidateFeeArgs { fee_tx: &tx, expected_sender: &sender_pub, fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY, @@ -347,7 +347,7 @@ fn test_validate_fee() { assert!(result.is_ok()); let fee_addr_dif = hex::decode("03bc2c7ba671bae4a6fc835244c9762b41647b9827d4780a89a949b984a8ddcc05").unwrap(); - let err = block_on_f01(coin.validate_fee(ValidateFeeArgs { + let err = block_on(coin.validate_fee(ValidateFeeArgs { fee_tx: &tx, expected_sender: &sender_pub, fee_addr: &fee_addr_dif, @@ -363,7 +363,7 @@ fn test_validate_fee() { _ => panic!("Expected `WrongPaymentTx` wrong receiver address, found {:?}", err), } - let err = block_on_f01(coin.validate_fee(ValidateFeeArgs { + let err = block_on(coin.validate_fee(ValidateFeeArgs { fee_tx: &tx, expected_sender: &DEX_FEE_ADDR_RAW_PUBKEY, fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY, @@ -379,7 +379,7 @@ fn test_validate_fee() { _ => panic!("Expected `WrongPaymentTx` wrong sender address, found {:?}", err), } - let err = block_on_f01(coin.validate_fee(ValidateFeeArgs { + let err = block_on(coin.validate_fee(ValidateFeeArgs { fee_tx: &tx, expected_sender: &sender_pub, fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY, @@ -396,7 +396,7 @@ fn test_validate_fee() { } let amount_dif = BigDecimal::from_str("0.02").unwrap(); - let err = block_on_f01(coin.validate_fee(ValidateFeeArgs { + let err = block_on(coin.validate_fee(ValidateFeeArgs { fee_tx: &tx, expected_sender: &sender_pub, fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY, @@ -417,7 +417,7 @@ fn test_validate_fee() { // QTUM tx "8a51f0ffd45f34974de50f07c5bf2f0949da4e88433f8f75191953a442cf9310" let tx = TransactionEnum::UtxoTx("020000000113640281c9332caeddd02a8dd0d784809e1ad87bda3c972d89d5ae41f5494b85010000006a47304402207c5c904a93310b8672f4ecdbab356b65dd869a426e92f1064a567be7ccfc61ff02203e4173b9467127f7de4682513a21efb5980e66dbed4da91dff46534b8e77c7ef012102baefe72b3591de2070c0da3853226b00f082d72daa417688b61cb18c1d543d1afeffffff020001b2c4000000001976a9149e032d4b0090a11dc40fe6c47601499a35d55fbb88acbc4dd20c2f0000001976a9144208fa7be80dcf972f767194ad365950495064a488ac76e70800".into()); let sender_pub = hex::decode("02baefe72b3591de2070c0da3853226b00f082d72daa417688b61cb18c1d543d1a").unwrap(); - let err = block_on_f01(coin.validate_fee(ValidateFeeArgs { + let err = block_on(coin.validate_fee(ValidateFeeArgs { fee_tx: &tx, expected_sender: &sender_pub, fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY, diff --git a/mm2src/coins/siacoin.rs b/mm2src/coins/siacoin.rs index 84af0346fc..1bd8ef6c2d 100644 --- a/mm2src/coins/siacoin.rs +++ b/mm2src/coins/siacoin.rs @@ -399,7 +399,13 @@ impl MarketCoinOps for SiaCoin { #[async_trait] impl SwapOps for SiaCoin { - fn send_taker_fee(&self, _fee_addr: &[u8], _dex_fee: DexFee, _uuid: &[u8], _expire_at: u64) -> TransactionFut { + async fn send_taker_fee( + &self, + _fee_addr: &[u8], + _dex_fee: DexFee, + _uuid: &[u8], + _expire_at: u64, + ) -> TransactionResult { unimplemented!() } @@ -407,7 +413,9 @@ impl SwapOps for SiaCoin { unimplemented!() } - fn send_taker_payment(&self, _taker_payment_args: SendPaymentArgs) -> TransactionFut { unimplemented!() } + async fn send_taker_payment(&self, _taker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { + unimplemented!() + } async fn send_maker_spends_taker_payment( &self, @@ -437,7 +445,9 @@ impl SwapOps for SiaCoin { unimplemented!() } - fn validate_fee(&self, _validate_fee_args: ValidateFeeArgs) -> ValidatePaymentFut<()> { unimplemented!() } + async fn validate_fee(&self, _validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentResult<()> { + unimplemented!() + } async fn validate_maker_payment(&self, _input: ValidatePaymentInput) -> ValidatePaymentResult<()> { unimplemented!() @@ -447,10 +457,10 @@ impl SwapOps for SiaCoin { unimplemented!() } - fn check_if_my_payment_sent( + async fn check_if_my_payment_sent( &self, - _if_my_payment_sent_args: CheckIfMyPaymentSentArgs, - ) -> Box, Error = String> + Send> { + _if_my_payment_sent_args: CheckIfMyPaymentSentArgs<'_>, + ) -> Result, String> { unimplemented!() } @@ -496,9 +506,7 @@ impl SwapOps for SiaCoin { fn derive_htlc_pubkey(&self, _swap_unique_data: &[u8]) -> Vec { unimplemented!() } - fn can_refund_htlc(&self, _locktime: u64) -> Box + Send + '_> { - unimplemented!() - } + async fn can_refund_htlc(&self, _locktime: u64) -> Result { unimplemented!() } fn validate_other_pubkey(&self, _raw_pubkey: &[u8]) -> MmResult<(), ValidateOtherPubKeyErr> { unimplemented!() } diff --git a/mm2src/coins/tendermint/tendermint_coin.rs b/mm2src/coins/tendermint/tendermint_coin.rs index 1871ccacb4..2fc712c4aa 100644 --- a/mm2src/coins/tendermint/tendermint_coin.rs +++ b/mm2src/coins/tendermint/tendermint_coin.rs @@ -2691,7 +2691,7 @@ impl MarketCoinOps for TendermintCoin { #[async_trait] #[allow(unused_variables)] impl SwapOps for TendermintCoin { - fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, uuid: &[u8], expire_at: u64) -> TransactionFut { + async fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, uuid: &[u8], expire_at: u64) -> TransactionResult { self.send_taker_fee_for_denom( fee_addr, dex_fee.fee_amount().into(), @@ -2700,6 +2700,8 @@ impl SwapOps for TendermintCoin { uuid, expire_at, ) + .compat() + .await } async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { @@ -2715,7 +2717,7 @@ impl SwapOps for TendermintCoin { .await } - fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs) -> TransactionFut { + async fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { self.send_htlc_for_denom( taker_payment_args.time_lock_duration, taker_payment_args.other_pubkey, @@ -2724,6 +2726,8 @@ impl SwapOps for TendermintCoin { self.denom.clone(), self.decimals, ) + .compat() + .await } async fn send_maker_spends_taker_payment( @@ -2860,7 +2864,7 @@ impl SwapOps for TendermintCoin { )) } - fn validate_fee(&self, validate_fee_args: ValidateFeeArgs) -> ValidatePaymentFut<()> { + async fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentResult<()> { self.validate_fee_for_denom( validate_fee_args.fee_tx, validate_fee_args.expected_sender, @@ -2870,6 +2874,8 @@ impl SwapOps for TendermintCoin { validate_fee_args.uuid, self.denom.to_string(), ) + .compat() + .await } async fn validate_maker_payment(&self, input: ValidatePaymentInput) -> ValidatePaymentResult<()> { @@ -2882,10 +2888,10 @@ impl SwapOps for TendermintCoin { .await } - fn check_if_my_payment_sent( + async fn check_if_my_payment_sent( &self, - if_my_payment_sent_args: CheckIfMyPaymentSentArgs, - ) -> Box, Error = String> + Send> { + if_my_payment_sent_args: CheckIfMyPaymentSentArgs<'_>, + ) -> Result, String> { self.check_if_my_payment_sent_for_denom( self.decimals, self.denom.clone(), @@ -2893,6 +2899,8 @@ impl SwapOps for TendermintCoin { if_my_payment_sent_args.secret_hash, if_my_payment_sent_args.amount, ) + .compat() + .await } async fn search_for_swap_tx_spend_my( @@ -3315,7 +3323,7 @@ fn parse_expected_sequence_number(e: &str) -> MmResult> END HTLC CREATION - let htlc_spent = block_on( - coin.check_if_my_payment_sent(CheckIfMyPaymentSentArgs { - time_lock: 0, - other_pub: IRIS_TESTNET_HTLC_PAIR2_PUB_KEY, - secret_hash: sha256(&sec).as_slice(), - search_from_block: current_block, - swap_contract_address: &None, - swap_unique_data: &[], - amount: &amount_dec, - payment_instructions: &None, - }) - .compat(), - ) + let htlc_spent = block_on(coin.check_if_my_payment_sent(CheckIfMyPaymentSentArgs { + time_lock: 0, + other_pub: IRIS_TESTNET_HTLC_PAIR2_PUB_KEY, + secret_hash: sha256(&sec).as_slice(), + search_from_block: current_block, + swap_contract_address: &None, + swap_unique_data: &[], + amount: &amount_dec, + payment_instructions: &None, + })) .unwrap(); assert!(htlc_spent.is_some()); @@ -3693,7 +3698,7 @@ pub mod tendermint_coin_tests { }); let invalid_amount: MmNumber = 1.into(); - let error = block_on_f01(coin.validate_fee(ValidateFeeArgs { + let error = block_on(coin.validate_fee(ValidateFeeArgs { fee_tx: &create_htlc_tx, expected_sender: &[], fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY, @@ -3725,7 +3730,7 @@ pub mod tendermint_coin_tests { data: TxRaw::decode(random_transfer_tx_bytes.as_slice()).unwrap(), }); - let error = block_on_f01(coin.validate_fee(ValidateFeeArgs { + let error = block_on(coin.validate_fee(ValidateFeeArgs { fee_tx: &random_transfer_tx, expected_sender: &[], fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY, @@ -3756,7 +3761,7 @@ pub mod tendermint_coin_tests { data: TxRaw::decode(dex_fee_tx.encode_to_vec().as_slice()).unwrap(), }); - let error = block_on_f01(coin.validate_fee(ValidateFeeArgs { + let error = block_on(coin.validate_fee(ValidateFeeArgs { fee_tx: &dex_fee_tx, expected_sender: &[], fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY, @@ -3774,7 +3779,7 @@ pub mod tendermint_coin_tests { let valid_amount: BigDecimal = "0.0001".parse().unwrap(); // valid amount but invalid sender - let error = block_on_f01(coin.validate_fee(ValidateFeeArgs { + let error = block_on(coin.validate_fee(ValidateFeeArgs { fee_tx: &dex_fee_tx, expected_sender: &DEX_FEE_ADDR_RAW_PUBKEY, fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY, @@ -3791,7 +3796,7 @@ pub mod tendermint_coin_tests { } // invalid memo - let error = block_on_f01(coin.validate_fee(ValidateFeeArgs { + let error = block_on(coin.validate_fee(ValidateFeeArgs { fee_tx: &dex_fee_tx, expected_sender: &pubkey, fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY, diff --git a/mm2src/coins/tendermint/tendermint_token.rs b/mm2src/coins/tendermint/tendermint_token.rs index 1115065cdf..a2df5bc117 100644 --- a/mm2src/coins/tendermint/tendermint_token.rs +++ b/mm2src/coins/tendermint/tendermint_token.rs @@ -104,15 +104,18 @@ impl TendermintToken { #[async_trait] #[allow(unused_variables)] impl SwapOps for TendermintToken { - fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, uuid: &[u8], expire_at: u64) -> TransactionFut { - self.platform_coin.send_taker_fee_for_denom( - fee_addr, - dex_fee.fee_amount().into(), - self.denom.clone(), - self.decimals, - uuid, - expire_at, - ) + async fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, uuid: &[u8], expire_at: u64) -> TransactionResult { + self.platform_coin + .send_taker_fee_for_denom( + fee_addr, + dex_fee.fee_amount().into(), + self.denom.clone(), + self.decimals, + uuid, + expire_at, + ) + .compat() + .await } async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { @@ -129,15 +132,18 @@ impl SwapOps for TendermintToken { .await } - fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs) -> TransactionFut { - self.platform_coin.send_htlc_for_denom( - taker_payment_args.time_lock_duration, - taker_payment_args.other_pubkey, - taker_payment_args.secret_hash, - taker_payment_args.amount, - self.denom.clone(), - self.decimals, - ) + async fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { + self.platform_coin + .send_htlc_for_denom( + taker_payment_args.time_lock_duration, + taker_payment_args.other_pubkey, + taker_payment_args.secret_hash, + taker_payment_args.amount, + self.denom.clone(), + self.decimals, + ) + .compat() + .await } async fn send_maker_spends_taker_payment( @@ -170,16 +176,19 @@ impl SwapOps for TendermintToken { )) } - fn validate_fee(&self, validate_fee_args: ValidateFeeArgs) -> ValidatePaymentFut<()> { - self.platform_coin.validate_fee_for_denom( - validate_fee_args.fee_tx, - validate_fee_args.expected_sender, - validate_fee_args.fee_addr, - &validate_fee_args.dex_fee.fee_amount().into(), - self.decimals, - validate_fee_args.uuid, - self.denom.to_string(), - ) + async fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentResult<()> { + self.platform_coin + .validate_fee_for_denom( + validate_fee_args.fee_tx, + validate_fee_args.expected_sender, + validate_fee_args.fee_addr, + &validate_fee_args.dex_fee.fee_amount().into(), + self.decimals, + validate_fee_args.uuid, + self.denom.to_string(), + ) + .compat() + .await } async fn validate_maker_payment(&self, input: ValidatePaymentInput) -> ValidatePaymentResult<()> { @@ -194,17 +203,20 @@ impl SwapOps for TendermintToken { .await } - fn check_if_my_payment_sent( + async fn check_if_my_payment_sent( &self, - if_my_payment_sent_args: CheckIfMyPaymentSentArgs, - ) -> Box, Error = String> + Send> { - self.platform_coin.check_if_my_payment_sent_for_denom( - self.decimals, - self.denom.clone(), - if_my_payment_sent_args.other_pub, - if_my_payment_sent_args.secret_hash, - if_my_payment_sent_args.amount, - ) + if_my_payment_sent_args: CheckIfMyPaymentSentArgs<'_>, + ) -> Result, String> { + self.platform_coin + .check_if_my_payment_sent_for_denom( + self.decimals, + self.denom.clone(), + if_my_payment_sent_args.other_pub, + if_my_payment_sent_args.secret_hash, + if_my_payment_sent_args.amount, + ) + .compat() + .await } async fn search_for_swap_tx_spend_my( diff --git a/mm2src/coins/test_coin.rs b/mm2src/coins/test_coin.rs index 541be9e4d2..8f1dd0a508 100644 --- a/mm2src/coins/test_coin.rs +++ b/mm2src/coins/test_coin.rs @@ -114,7 +114,7 @@ impl MarketCoinOps for TestCoin { #[async_trait] #[mockable] impl SwapOps for TestCoin { - fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, uuid: &[u8], _expire_at: u64) -> TransactionFut { + async fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, uuid: &[u8], expire_at: u64) -> TransactionResult { unimplemented!() } @@ -122,7 +122,9 @@ impl SwapOps for TestCoin { unimplemented!() } - fn send_taker_payment(&self, _taker_payment_args: SendPaymentArgs) -> TransactionFut { unimplemented!() } + async fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { + unimplemented!() + } async fn send_maker_spends_taker_payment( &self, @@ -152,7 +154,9 @@ impl SwapOps for TestCoin { unimplemented!() } - fn validate_fee(&self, _validate_fee_args: ValidateFeeArgs) -> ValidatePaymentFut<()> { unimplemented!() } + async fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentResult<()> { + unimplemented!() + } async fn validate_maker_payment(&self, _input: ValidatePaymentInput) -> ValidatePaymentResult<()> { unimplemented!() @@ -162,10 +166,10 @@ impl SwapOps for TestCoin { unimplemented!() } - fn check_if_my_payment_sent( + async fn check_if_my_payment_sent( &self, - _if_my_payment_sent_args: CheckIfMyPaymentSentArgs, - ) -> Box, Error = String> + Send> { + if_my_payment_sent_args: CheckIfMyPaymentSentArgs<'_>, + ) -> Result, String> { unimplemented!() } @@ -211,9 +215,7 @@ impl SwapOps for TestCoin { fn derive_htlc_pubkey(&self, _swap_unique_data: &[u8]) -> Vec { unimplemented!() } - fn can_refund_htlc(&self, locktime: u64) -> Box + Send + '_> { - unimplemented!() - } + async fn can_refund_htlc(&self, locktime: u64) -> Result { unimplemented!() } fn validate_other_pubkey(&self, raw_pubkey: &[u8]) -> MmResult<(), ValidateOtherPubKeyErr> { unimplemented!() } diff --git a/mm2src/coins/utxo/bch.rs b/mm2src/coins/utxo/bch.rs index c2d1d5b62b..5ef27ae662 100644 --- a/mm2src/coins/utxo/bch.rs +++ b/mm2src/coins/utxo/bch.rs @@ -870,8 +870,16 @@ impl UtxoCommonOps for BchCoin { #[async_trait] impl SwapOps for BchCoin { #[inline] - fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, _uuid: &[u8], _expire_at: u64) -> TransactionFut { + async fn send_taker_fee( + &self, + fee_addr: &[u8], + dex_fee: DexFee, + _uuid: &[u8], + _expire_at: u64, + ) -> TransactionResult { utxo_common::send_taker_fee(self.clone(), fee_addr, dex_fee) + .compat() + .await } #[inline] @@ -882,8 +890,10 @@ impl SwapOps for BchCoin { } #[inline] - fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs) -> TransactionFut { + async fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { utxo_common::send_taker_payment(self.clone(), taker_payment_args) + .compat() + .await } #[inline] @@ -912,10 +922,15 @@ impl SwapOps for BchCoin { utxo_common::send_maker_refunds_payment(self.clone(), maker_refunds_payment_args).await } - fn validate_fee(&self, validate_fee_args: ValidateFeeArgs) -> ValidatePaymentFut<()> { + async fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentResult<()> { let tx = match validate_fee_args.fee_tx { TransactionEnum::UtxoTx(tx) => tx.clone(), - _ => panic!(), + fee_tx => { + return MmError::err(ValidatePaymentError::InternalError(format!( + "Invalid fee tx type. fee tx: {:?}", + fee_tx + ))) + }, }; utxo_common::validate_fee( self.clone(), @@ -926,6 +941,8 @@ impl SwapOps for BchCoin { validate_fee_args.min_block_number, validate_fee_args.fee_addr, ) + .compat() + .await } #[inline] @@ -939,17 +956,23 @@ impl SwapOps for BchCoin { } #[inline] - fn check_if_my_payment_sent( + async fn check_if_my_payment_sent( &self, - if_my_payment_sent_args: CheckIfMyPaymentSentArgs, - ) -> Box, Error = String> + Send> { + if_my_payment_sent_args: CheckIfMyPaymentSentArgs<'_>, + ) -> Result, String> { + let time_lock = if_my_payment_sent_args + .time_lock + .try_into() + .map_err(|e: TryFromIntError| e.to_string())?; utxo_common::check_if_my_payment_sent( self.clone(), - try_fus!(if_my_payment_sent_args.time_lock.try_into()), + time_lock, if_my_payment_sent_args.other_pub, if_my_payment_sent_args.secret_hash, if_my_payment_sent_args.swap_unique_data, ) + .compat() + .await } #[inline] @@ -992,13 +1015,10 @@ impl SwapOps for BchCoin { } #[inline] - fn can_refund_htlc(&self, locktime: u64) -> Box + Send + '_> { - Box::new( - utxo_common::can_refund_htlc(self, locktime) - .boxed() - .map_err(|e| ERRL!("{}", e)) - .compat(), - ) + async fn can_refund_htlc(&self, locktime: u64) -> Result { + utxo_common::can_refund_htlc(self, locktime) + .await + .map_err(|e| ERRL!("{}", e)) } #[inline] diff --git a/mm2src/coins/utxo/qtum.rs b/mm2src/coins/utxo/qtum.rs index 682b2a9ff0..8dd554bb53 100644 --- a/mm2src/coins/utxo/qtum.rs +++ b/mm2src/coins/utxo/qtum.rs @@ -510,8 +510,16 @@ impl UtxoStandardOps for QtumCoin { #[async_trait] impl SwapOps for QtumCoin { #[inline] - fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, _uuid: &[u8], _expire_at: u64) -> TransactionFut { + async fn send_taker_fee( + &self, + fee_addr: &[u8], + dex_fee: DexFee, + _uuid: &[u8], + _expire_at: u64, + ) -> TransactionResult { utxo_common::send_taker_fee(self.clone(), fee_addr, dex_fee) + .compat() + .await } #[inline] @@ -522,8 +530,10 @@ impl SwapOps for QtumCoin { } #[inline] - fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs) -> TransactionFut { + async fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { utxo_common::send_taker_payment(self.clone(), taker_payment_args) + .compat() + .await } #[inline] @@ -552,10 +562,15 @@ impl SwapOps for QtumCoin { utxo_common::send_maker_refunds_payment(self.clone(), maker_refunds_payment_args).await } - fn validate_fee(&self, validate_fee_args: ValidateFeeArgs) -> ValidatePaymentFut<()> { + async fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentResult<()> { let tx = match validate_fee_args.fee_tx { TransactionEnum::UtxoTx(tx) => tx.clone(), - _ => panic!(), + fee_tx => { + return MmError::err(ValidatePaymentError::InternalError(format!( + "Invalid fee tx type. fee tx: {:?}", + fee_tx + ))) + }, }; utxo_common::validate_fee( self.clone(), @@ -566,6 +581,8 @@ impl SwapOps for QtumCoin { validate_fee_args.min_block_number, validate_fee_args.fee_addr, ) + .compat() + .await } #[inline] @@ -579,17 +596,23 @@ impl SwapOps for QtumCoin { } #[inline] - fn check_if_my_payment_sent( + async fn check_if_my_payment_sent( &self, - if_my_payment_sent_args: CheckIfMyPaymentSentArgs, - ) -> Box, Error = String> + Send> { + if_my_payment_sent_args: CheckIfMyPaymentSentArgs<'_>, + ) -> Result, String> { + let time_lock = if_my_payment_sent_args + .time_lock + .try_into() + .map_err(|e: TryFromIntError| e.to_string())?; utxo_common::check_if_my_payment_sent( self.clone(), - try_fus!(if_my_payment_sent_args.time_lock.try_into()), + time_lock, if_my_payment_sent_args.other_pub, if_my_payment_sent_args.secret_hash, if_my_payment_sent_args.swap_unique_data, ) + .compat() + .await } #[inline] @@ -632,13 +655,10 @@ impl SwapOps for QtumCoin { } #[inline] - fn can_refund_htlc(&self, locktime: u64) -> Box + Send + '_> { - Box::new( - utxo_common::can_refund_htlc(self, locktime) - .boxed() - .map_err(|e| ERRL!("{}", e)) - .compat(), - ) + async fn can_refund_htlc(&self, locktime: u64) -> Result { + utxo_common::can_refund_htlc(self, locktime) + .await + .map_err(|e| ERRL!("{}", e)) } #[inline] diff --git a/mm2src/coins/utxo/slp.rs b/mm2src/coins/utxo/slp.rs index bce9902319..b1e7f1ef4c 100644 --- a/mm2src/coins/utxo/slp.rs +++ b/mm2src/coins/utxo/slp.rs @@ -55,6 +55,7 @@ use serde_json::Value as Json; use serialization::{deserialize, serialize, Deserializable, Error as SerError, Reader}; use serialization_derive::Deserializable; use std::convert::TryInto; +use std::num::TryFromIntError; use std::sync::atomic::{AtomicU64, Ordering as AtomicOrdering}; use std::sync::Arc; use utxo_signer::with_key_pair::{p2pkh_spend, p2sh_spend, sign_tx, UtxoSignWithKeyPairError}; @@ -1216,26 +1217,29 @@ impl MarketCoinOps for SlpToken { #[async_trait] impl SwapOps for SlpToken { - fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, _uuid: &[u8], _expire_at: u64) -> TransactionFut { - let coin = self.clone(); - let fee_pubkey = try_tx_fus!(Public::from_slice(fee_addr)); + async fn send_taker_fee( + &self, + fee_addr: &[u8], + dex_fee: DexFee, + _uuid: &[u8], + _expire_at: u64, + ) -> TransactionResult { + let fee_pubkey = try_tx_s!(Public::from_slice(fee_addr)); let script_pubkey = ScriptBuilder::build_p2pkh(&fee_pubkey.address_hash().into()).into(); - let amount = try_tx_fus!(dex_fee.fee_uamount(self.decimals())); + let amount = try_tx_s!(dex_fee.fee_uamount(self.decimals())); + let slp_out = SlpOutput { amount, script_pubkey }; + let (preimage, recently_spent) = try_tx_s!(self.generate_slp_tx_preimage(vec![slp_out]).await); - let fut = async move { - let slp_out = SlpOutput { amount, script_pubkey }; - let (preimage, recently_spent) = try_tx_s!(coin.generate_slp_tx_preimage(vec![slp_out]).await); - generate_and_send_tx( - &coin, - preimage.available_bch_inputs, - Some(preimage.slp_inputs.into_iter().map(|slp| slp.bch_unspent).collect()), - FeePolicy::SendExact, - recently_spent, - preimage.outputs, - ) - .await - }; - Box::new(fut.boxed().compat().map(|tx| tx.into())) + generate_and_send_tx( + self, + preimage.available_bch_inputs, + Some(preimage.slp_inputs.into_iter().map(|slp| slp.bch_unspent).collect()), + FeePolicy::SendExact, + recently_spent, + preimage.outputs, + ) + .await + .map(|tx| tx.into()) } async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { @@ -1252,23 +1256,17 @@ impl SwapOps for SlpToken { Ok(tx.into()) } - fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs) -> TransactionFut { - let maker_pub = try_tx_fus!(Public::from_slice(taker_payment_args.other_pubkey)); - let amount = try_tx_fus!(sat_from_big_decimal(&taker_payment_args.amount, self.decimals())); + async fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { + let maker_pub = try_tx_s!(Public::from_slice(taker_payment_args.other_pubkey)); + let amount = try_tx_s!(sat_from_big_decimal(&taker_payment_args.amount, self.decimals())); let secret_hash = taker_payment_args.secret_hash.to_owned(); let taker_htlc_keypair = self.derive_htlc_key_pair(taker_payment_args.swap_unique_data); - let time_lock = try_tx_fus!(taker_payment_args.time_lock.try_into()); + let time_lock = try_tx_s!(taker_payment_args.time_lock.try_into()); - let coin = self.clone(); - let fut = async move { - let tx = try_tx_s!( - coin.send_htlc(taker_htlc_keypair.public(), &maker_pub, time_lock, &secret_hash, amount) - .await - ); - Ok(tx.into()) - }; - Box::new(fut.boxed().compat()) + self.send_htlc(taker_htlc_keypair.public(), &maker_pub, time_lock, &secret_hash, amount) + .await + .map(|tx| tx.into()) } async fn send_maker_spends_taker_payment( @@ -1339,24 +1337,27 @@ impl SwapOps for SlpToken { Ok(tx.into()) } - fn validate_fee(&self, validate_fee_args: ValidateFeeArgs) -> ValidatePaymentFut<()> { + async fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentResult<()> { let tx = match validate_fee_args.fee_tx { TransactionEnum::UtxoTx(tx) => tx.clone(), - _ => panic!(), + fee_tx => { + return MmError::err(ValidatePaymentError::InternalError(format!( + "Invalid fee tx type. fee tx: {:?}", + fee_tx + ))) + }, }; - let coin = self.clone(); - let expected_sender = validate_fee_args.expected_sender.to_owned(); - let fee_addr = validate_fee_args.fee_addr.to_owned(); - let amount = validate_fee_args.dex_fee.fee_amount(); - let min_block_number = validate_fee_args.min_block_number; - let fut = async move { - coin.validate_dex_fee(tx, &expected_sender, &fee_addr, amount.into(), min_block_number) - .await - .map_err(|e| MmError::new(ValidatePaymentError::WrongPaymentTx(e.into_inner().to_string())))?; - Ok(()) - }; - Box::new(fut.boxed().compat()) + let amount = validate_fee_args.dex_fee.fee_amount(); + self.validate_dex_fee( + tx, + validate_fee_args.expected_sender, + validate_fee_args.fee_addr, + amount.into(), + validate_fee_args.min_block_number, + ) + .await + .map_err(|e| MmError::new(ValidatePaymentError::WrongPaymentTx(e.into_inner().to_string()))) } async fn validate_maker_payment(&self, input: ValidatePaymentInput) -> ValidatePaymentResult<()> { @@ -1368,17 +1369,23 @@ impl SwapOps for SlpToken { } #[inline] - fn check_if_my_payment_sent( + async fn check_if_my_payment_sent( &self, - if_my_payment_sent_args: CheckIfMyPaymentSentArgs, - ) -> Box, Error = String> + Send> { + if_my_payment_sent_args: CheckIfMyPaymentSentArgs<'_>, + ) -> Result, String> { + let time_lock = if_my_payment_sent_args + .time_lock + .try_into() + .map_err(|e: TryFromIntError| e.to_string())?; utxo_common::check_if_my_payment_sent( self.platform_coin.clone(), - try_fus!(if_my_payment_sent_args.time_lock.try_into()), + time_lock, if_my_payment_sent_args.other_pub, if_my_payment_sent_args.secret_hash, if_my_payment_sent_args.swap_unique_data, ) + .compat() + .await } #[inline] diff --git a/mm2src/coins/utxo/utxo_standard.rs b/mm2src/coins/utxo/utxo_standard.rs index a8627e86d9..e2c2a7b740 100644 --- a/mm2src/coins/utxo/utxo_standard.rs +++ b/mm2src/coins/utxo/utxo_standard.rs @@ -302,8 +302,16 @@ impl UtxoStandardOps for UtxoStandardCoin { #[async_trait] impl SwapOps for UtxoStandardCoin { #[inline] - fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, _uuid: &[u8], _expire_at: u64) -> TransactionFut { + async fn send_taker_fee( + &self, + fee_addr: &[u8], + dex_fee: DexFee, + _uuid: &[u8], + _expire_at: u64, + ) -> TransactionResult { utxo_common::send_taker_fee(self.clone(), fee_addr, dex_fee) + .compat() + .await } #[inline] @@ -314,8 +322,10 @@ impl SwapOps for UtxoStandardCoin { } #[inline] - fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs) -> TransactionFut { + async fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { utxo_common::send_taker_payment(self.clone(), taker_payment_args) + .compat() + .await } #[inline] @@ -344,10 +354,15 @@ impl SwapOps for UtxoStandardCoin { utxo_common::send_maker_refunds_payment(self.clone(), maker_refunds_payment_args).await } - fn validate_fee(&self, validate_fee_args: ValidateFeeArgs) -> ValidatePaymentFut<()> { + async fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentResult<()> { let tx = match validate_fee_args.fee_tx { TransactionEnum::UtxoTx(tx) => tx.clone(), - _ => panic!(), + fee_tx => { + return MmError::err(ValidatePaymentError::InternalError(format!( + "Invalid fee tx type. fee tx: {:?}", + fee_tx + ))) + }, }; utxo_common::validate_fee( self.clone(), @@ -358,6 +373,8 @@ impl SwapOps for UtxoStandardCoin { validate_fee_args.min_block_number, validate_fee_args.fee_addr, ) + .compat() + .await } #[inline] @@ -371,17 +388,23 @@ impl SwapOps for UtxoStandardCoin { } #[inline] - fn check_if_my_payment_sent( + async fn check_if_my_payment_sent( &self, - if_my_payment_sent_args: CheckIfMyPaymentSentArgs, - ) -> Box, Error = String> + Send> { + if_my_payment_sent_args: CheckIfMyPaymentSentArgs<'_>, + ) -> Result, String> { + let time_lock = if_my_payment_sent_args + .time_lock + .try_into() + .map_err(|e: TryFromIntError| e.to_string())?; utxo_common::check_if_my_payment_sent( self.clone(), - try_fus!(if_my_payment_sent_args.time_lock.try_into()), + time_lock, if_my_payment_sent_args.other_pub, if_my_payment_sent_args.secret_hash, if_my_payment_sent_args.swap_unique_data, ) + .compat() + .await } #[inline] @@ -416,13 +439,10 @@ impl SwapOps for UtxoStandardCoin { } #[inline] - fn can_refund_htlc(&self, locktime: u64) -> Box + Send + '_> { - Box::new( - utxo_common::can_refund_htlc(self, locktime) - .boxed() - .map_err(|e| ERRL!("{}", e)) - .compat(), - ) + async fn can_refund_htlc(&self, locktime: u64) -> Result { + utxo_common::can_refund_htlc(self, locktime) + .await + .map_err(|e| ERRL!("{}", e)) } fn is_auto_refundable(&self) -> bool { false } diff --git a/mm2src/coins/utxo/utxo_tests.rs b/mm2src/coins/utxo/utxo_tests.rs index 9456361c64..991fff2ebe 100644 --- a/mm2src/coins/utxo/utxo_tests.rs +++ b/mm2src/coins/utxo/utxo_tests.rs @@ -2660,9 +2660,7 @@ fn test_validate_fee_wrong_sender() { min_block_number: 0, uuid: &[], }; - let error = block_on_f01(coin.validate_fee(validate_fee_args)) - .unwrap_err() - .into_inner(); + let error = block_on(coin.validate_fee(validate_fee_args)).unwrap_err().into_inner(); log!("error: {:?}", error); match error { ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains(INVALID_SENDER_ERR_LOG)), @@ -2687,9 +2685,7 @@ fn test_validate_fee_min_block() { min_block_number: 278455, uuid: &[], }; - let error = block_on_f01(coin.validate_fee(validate_fee_args)) - .unwrap_err() - .into_inner(); + let error = block_on(coin.validate_fee(validate_fee_args)).unwrap_err().into_inner(); match error { ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("confirmed before min_block")), _ => panic!("Expected `WrongPaymentTx` early confirmation, found {:?}", error), @@ -2718,7 +2714,7 @@ fn test_validate_fee_bch_70_bytes_signature() { min_block_number: 0, uuid: &[], }; - block_on_f01(coin.validate_fee(validate_fee_args)).unwrap(); + block_on(coin.validate_fee(validate_fee_args)).unwrap(); } #[test] diff --git a/mm2src/coins/z_coin.rs b/mm2src/coins/z_coin.rs index 348676e548..390619ce8b 100644 --- a/mm2src/coins/z_coin.rs +++ b/mm2src/coins/z_coin.rs @@ -70,6 +70,7 @@ use serialization::CoinVariant; use std::collections::{HashMap, HashSet}; use std::convert::TryInto; use std::iter; +use std::num::TryFromIntError; use std::path::PathBuf; use std::sync::Arc; pub use z_coin_errors::*; @@ -1200,14 +1201,16 @@ impl MarketCoinOps for ZCoin { #[async_trait] impl SwapOps for ZCoin { - fn send_taker_fee(&self, _fee_addr: &[u8], dex_fee: DexFee, uuid: &[u8], _expire_at: u64) -> TransactionFut { - let selfi = self.clone(); + async fn send_taker_fee( + &self, + _fee_addr: &[u8], + dex_fee: DexFee, + uuid: &[u8], + _expire_at: u64, + ) -> TransactionResult { let uuid = uuid.to_owned(); - let fut = async move { - let tx = try_tx_s!(z_send_dex_fee(&selfi, dex_fee.fee_amount().into(), &uuid).await); - Ok(tx.into()) - }; - Box::new(fut.boxed().compat()) + let tx = try_tx_s!(z_send_dex_fee(self, dex_fee.fee_amount().into(), &uuid).await); + Ok(tx.into()) } async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { @@ -1230,28 +1233,24 @@ impl SwapOps for ZCoin { Ok(utxo_tx.into()) } - fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionFut { - let selfi = self.clone(); + async fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionResult { let taker_keypair = self.derive_htlc_key_pair(taker_payment_args.swap_unique_data); - let maker_pub = try_tx_fus!(Public::from_slice(taker_payment_args.other_pubkey)); + let maker_pub = try_tx_s!(Public::from_slice(taker_payment_args.other_pubkey)); let secret_hash = taker_payment_args.secret_hash.to_vec(); - let time_lock = try_tx_fus!(taker_payment_args.time_lock.try_into()); + let time_lock = try_tx_s!(taker_payment_args.time_lock.try_into()); let amount = taker_payment_args.amount; - let fut = async move { - let utxo_tx = try_tx_s!( - z_send_htlc( - &selfi, - time_lock, - taker_keypair.public(), - &maker_pub, - &secret_hash, - amount - ) - .await - ); - Ok(utxo_tx.into()) - }; - Box::new(fut.boxed().compat()) + let utxo_tx = try_tx_s!( + z_send_htlc( + self, + time_lock, + taker_keypair.public(), + &maker_pub, + &secret_hash, + amount + ) + .await + ); + Ok(utxo_tx.into()) } async fn send_maker_spends_taker_payment( @@ -1365,90 +1364,88 @@ impl SwapOps for ZCoin { Ok(tx.into()) } - fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentFut<()> { + async fn validate_fee(&self, validate_fee_args: ValidateFeeArgs<'_>) -> ValidatePaymentResult<()> { let z_tx = match validate_fee_args.fee_tx { TransactionEnum::ZTransaction(t) => t.clone(), - _ => panic!("Unexpected tx {:?}", validate_fee_args.fee_tx), + fee_tx => { + return MmError::err(ValidatePaymentError::InternalError(format!( + "Invalid fee tx type. fee tx: {:?}", + fee_tx + ))) + }, }; - let amount_sat = try_f!(validate_fee_args.dex_fee.fee_uamount(self.utxo_arc.decimals)); + let amount_sat = validate_fee_args.dex_fee.fee_uamount(self.utxo_arc.decimals)?; let expected_memo = MemoBytes::from_bytes(validate_fee_args.uuid).expect("Uuid length < 512"); - let min_block_number = validate_fee_args.min_block_number; - let coin = self.clone(); - let fut = async move { - let tx_hash = H256::from(z_tx.txid().0).reversed(); - let tx_from_rpc = coin - .utxo_rpc_client() - .get_verbose_transaction(&tx_hash.into()) - .compat() - .await - .map_err(|e| MmError::new(ValidatePaymentError::InvalidRpcResponse(e.into_inner().to_string())))?; - - let mut encoded = Vec::with_capacity(1024); - z_tx.write(&mut encoded).expect("Writing should not fail"); - if encoded != tx_from_rpc.hex.0 { - return MmError::err(ValidatePaymentError::WrongPaymentTx(format!( - "Encoded transaction {:?} does not match the tx {:?} from RPC", - encoded, tx_from_rpc - ))); - } + let tx_hash = H256::from(z_tx.txid().0).reversed(); + let tx_from_rpc = self + .utxo_rpc_client() + .get_verbose_transaction(&tx_hash.into()) + .compat() + .await + .map_err(|e| MmError::new(ValidatePaymentError::InvalidRpcResponse(e.into_inner().to_string())))?; + + let mut encoded = Vec::with_capacity(1024); + z_tx.write(&mut encoded).expect("Writing should not fail"); + if encoded != tx_from_rpc.hex.0 { + return MmError::err(ValidatePaymentError::WrongPaymentTx(format!( + "Encoded transaction {:?} does not match the tx {:?} from RPC", + encoded, tx_from_rpc + ))); + } - let block_height = match tx_from_rpc.height { - Some(h) => { - if h < min_block_number { - return MmError::err(ValidatePaymentError::WrongPaymentTx(format!( - "Dex fee tx {:?} confirmed before min block {}", - z_tx, min_block_number - ))); - } else { - BlockHeight::from_u32(h as u32) - } - }, - None => H0, - }; - - for shielded_out in z_tx.shielded_outputs.iter() { - if let Some((note, address, memo)) = - try_sapling_output_recovery(coin.consensus_params_ref(), block_height, &DEX_FEE_OVK, shielded_out) - { - if address != coin.z_fields.dex_fee_addr { - let encoded = - encode_payment_address(z_mainnet_constants::HRP_SAPLING_PAYMENT_ADDRESS, &address); - let expected = encode_payment_address( - z_mainnet_constants::HRP_SAPLING_PAYMENT_ADDRESS, - &coin.z_fields.dex_fee_addr, - ); - return MmError::err(ValidatePaymentError::WrongPaymentTx(format!( - "Dex fee was sent to the invalid address {}, expected {}", - encoded, expected - ))); - } - - if note.value != amount_sat { - return MmError::err(ValidatePaymentError::WrongPaymentTx(format!( - "Dex fee has invalid amount {}, expected {}", - note.value, amount_sat - ))); - } - - if memo != expected_memo { - return MmError::err(ValidatePaymentError::WrongPaymentTx(format!( - "Dex fee has invalid memo {:?}, expected {:?}", - memo, expected_memo - ))); - } - - return Ok(()); + let block_height = match tx_from_rpc.height { + Some(h) => { + if h < validate_fee_args.min_block_number { + return MmError::err(ValidatePaymentError::WrongPaymentTx(format!( + "Dex fee tx {:?} confirmed before min block {}", + z_tx, validate_fee_args.min_block_number + ))); + } else { + BlockHeight::from_u32(h as u32) } - } - - MmError::err(ValidatePaymentError::WrongPaymentTx(format!( - "The dex fee tx {:?} has no shielded outputs or outputs decryption failed", - z_tx - ))) + }, + None => H0, }; - Box::new(fut.boxed().compat()) + for shielded_out in z_tx.shielded_outputs.iter() { + if let Some((note, address, memo)) = + try_sapling_output_recovery(self.consensus_params_ref(), block_height, &DEX_FEE_OVK, shielded_out) + { + if address != self.z_fields.dex_fee_addr { + let encoded = encode_payment_address(z_mainnet_constants::HRP_SAPLING_PAYMENT_ADDRESS, &address); + let expected = encode_payment_address( + z_mainnet_constants::HRP_SAPLING_PAYMENT_ADDRESS, + &self.z_fields.dex_fee_addr, + ); + return MmError::err(ValidatePaymentError::WrongPaymentTx(format!( + "Dex fee was sent to the invalid address {}, expected {}", + encoded, expected + ))); + } + + if note.value != amount_sat { + return MmError::err(ValidatePaymentError::WrongPaymentTx(format!( + "Dex fee has invalid amount {}, expected {}", + note.value, amount_sat + ))); + } + + if memo != expected_memo { + return MmError::err(ValidatePaymentError::WrongPaymentTx(format!( + "Dex fee has invalid memo {:?}, expected {:?}", + memo, expected_memo + ))); + } + + return Ok(()); + } + } + + MmError::err(ValidatePaymentError::WrongPaymentTx(format!( + "The dex fee tx {:?} has no shielded outputs or outputs decryption failed", + z_tx + ))) } #[inline] @@ -1462,17 +1459,23 @@ impl SwapOps for ZCoin { } #[inline] - fn check_if_my_payment_sent( + async fn check_if_my_payment_sent( &self, if_my_payment_sent_args: CheckIfMyPaymentSentArgs<'_>, - ) -> Box, Error = String> + Send> { + ) -> Result, String> { + let time_lock = if_my_payment_sent_args + .time_lock + .try_into() + .map_err(|e: TryFromIntError| e.to_string())?; utxo_common::check_if_my_payment_sent( self.clone(), - try_fus!(if_my_payment_sent_args.time_lock.try_into()), + time_lock, if_my_payment_sent_args.other_pub, if_my_payment_sent_args.secret_hash, if_my_payment_sent_args.swap_unique_data, ) + .compat() + .await } #[inline] diff --git a/mm2src/coins/z_coin/z_coin_native_tests.rs b/mm2src/coins/z_coin/z_coin_native_tests.rs index 713eb7c930..f554d7c5d3 100644 --- a/mm2src/coins/z_coin/z_coin_native_tests.rs +++ b/mm2src/coins/z_coin/z_coin_native_tests.rs @@ -1,5 +1,5 @@ use bitcrypto::dhash160; -use common::{block_on, block_on_f01, now_sec}; +use common::{block_on, now_sec}; use mm2_core::mm_ctx::MmCtxBuilder; use mm2_test_helpers::for_tests::zombie_conf; use std::path::PathBuf; @@ -233,9 +233,7 @@ fn zombie_coin_validate_dex_fee() { uuid: &[1; 16], }; // Invalid amount should return an error - let err = block_on_f01(coin.validate_fee(validate_fee_args)) - .unwrap_err() - .into_inner(); + let err = block_on(coin.validate_fee(validate_fee_args)).unwrap_err().into_inner(); match err { ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("Dex fee has invalid amount")), _ => panic!("Expected `WrongPaymentTx`: {:?}", err), @@ -250,9 +248,7 @@ fn zombie_coin_validate_dex_fee() { min_block_number: 12000, uuid: &[2; 16], }; - let err = block_on_f01(coin.validate_fee(validate_fee_args)) - .unwrap_err() - .into_inner(); + let err = block_on(coin.validate_fee(validate_fee_args)).unwrap_err().into_inner(); match err { ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("Dex fee has invalid memo")), _ => panic!("Expected `WrongPaymentTx`: {:?}", err), @@ -267,9 +263,7 @@ fn zombie_coin_validate_dex_fee() { min_block_number: 14000, uuid: &[1; 16], }; - let err = block_on_f01(coin.validate_fee(validate_fee_args)) - .unwrap_err() - .into_inner(); + let err = block_on(coin.validate_fee(validate_fee_args)).unwrap_err().into_inner(); match err { ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("confirmed before min block")), _ => panic!("Expected `WrongPaymentTx`: {:?}", err), @@ -284,7 +278,7 @@ fn zombie_coin_validate_dex_fee() { min_block_number: 12000, uuid: &[1; 16], }; - block_on_f01(coin.validate_fee(validate_fee_args)).unwrap(); + block_on(coin.validate_fee(validate_fee_args)).unwrap(); } fn default_zcoin_activation_params() -> ZcoinActivationParams { diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap.rs b/mm2src/mm2_main/src/lp_swap/maker_swap.rs index 7f6982df3a..f9a729e537 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap.rs @@ -767,7 +767,6 @@ impl MakerSwap { min_block_number: taker_coin_start_block, uuid: self.uuid.as_bytes(), }) - .compat() .await { Ok(_) => break, @@ -809,19 +808,16 @@ impl MakerSwap { let maker_coin_swap_contract_address = self.r().data.maker_coin_swap_contract_address.clone(); let unique_data = self.unique_swap_data(); let payment_instructions = self.r().payment_instructions.clone(); - let transaction_f = self - .maker_coin - .check_if_my_payment_sent(CheckIfMyPaymentSentArgs { - time_lock: maker_payment_lock, - other_pub: &*other_maker_coin_htlc_pub, - secret_hash: secret_hash.as_slice(), - search_from_block: self.r().data.maker_coin_start_block, - swap_contract_address: &maker_coin_swap_contract_address, - swap_unique_data: &unique_data, - amount: &self.maker_amount, - payment_instructions: &payment_instructions, - }) - .compat(); + let transaction_f = self.maker_coin.check_if_my_payment_sent(CheckIfMyPaymentSentArgs { + time_lock: maker_payment_lock, + other_pub: &*other_maker_coin_htlc_pub, + secret_hash: secret_hash.as_slice(), + search_from_block: self.r().data.maker_coin_start_block, + swap_contract_address: &maker_coin_swap_contract_address, + swap_unique_data: &unique_data, + amount: &self.maker_amount, + payment_instructions: &payment_instructions, + }); let wait_maker_payment_until = wait_for_maker_payment_conf_until(self.r().data.started_at, lock_duration); let watcher_reward = if self.r().watcher_reward { @@ -1217,7 +1213,7 @@ impl MakerSwap { } loop { - match self.maker_coin.can_refund_htlc(locktime).compat().await { + match self.maker_coin.can_refund_htlc(locktime).await { Ok(CanRefundHtlc::CanRefundNow) => break, Ok(CanRefundHtlc::HaveToWait(to_sleep)) => Timer::sleep(to_sleep as f64).await, Err(e) => { @@ -1487,7 +1483,6 @@ impl MakerSwap { amount: &self.maker_amount, payment_instructions: &payment_instructions, }) - .compat() .await ); match maybe_maker_payment { @@ -1530,7 +1525,7 @@ impl MakerSwap { return ERR!("Maker payment will be refunded automatically!"); } - let can_refund_htlc = try_s!(self.maker_coin.can_refund_htlc(maker_payment_lock).compat().await); + let can_refund_htlc = try_s!(self.maker_coin.can_refund_htlc(maker_payment_lock).await); if let CanRefundHtlc::HaveToWait(seconds_to_wait) = can_refund_htlc { return ERR!("Too early to refund, wait until {}", wait_until_sec(seconds_to_wait)); } @@ -2401,12 +2396,12 @@ mod maker_swap_tests { TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); TestCoin::swap_contract_address.mock_safe(|_| MockResult::Return(None)); TestCoin::can_refund_htlc - .mock_safe(|_, _| MockResult::Return(Box::new(futures01::future::ok(CanRefundHtlc::CanRefundNow)))); + .mock_safe(|_, _| MockResult::Return(Box::pin(futures::future::ok(CanRefundHtlc::CanRefundNow)))); static mut MY_PAYMENT_SENT_CALLED: bool = false; TestCoin::check_if_my_payment_sent.mock_safe(|_, _| { unsafe { MY_PAYMENT_SENT_CALLED = true }; - MockResult::Return(Box::new(futures01::future::ok(Some(eth_tx_for_test().into())))) + MockResult::Return(Box::pin(futures::future::ok(Some(eth_tx_for_test().into())))) }); static mut MAKER_REFUND_CALLED: bool = false; @@ -2441,7 +2436,7 @@ mod maker_swap_tests { TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); TestCoin::swap_contract_address.mock_safe(|_| MockResult::Return(None)); TestCoin::can_refund_htlc - .mock_safe(|_, _| MockResult::Return(Box::new(futures01::future::ok(CanRefundHtlc::CanRefundNow)))); + .mock_safe(|_, _| MockResult::Return(Box::pin(futures::future::ok(CanRefundHtlc::CanRefundNow)))); static mut MAKER_REFUND_CALLED: bool = false; TestCoin::send_maker_refunds_payment.mock_safe(|_, _| { @@ -2536,10 +2531,10 @@ mod maker_swap_tests { static mut MY_PAYMENT_SENT_CALLED: bool = false; TestCoin::check_if_my_payment_sent.mock_safe(|_, _| { unsafe { MY_PAYMENT_SENT_CALLED = true }; - MockResult::Return(Box::new(futures01::future::ok(Some(eth_tx_for_test().into())))) + MockResult::Return(Box::pin(futures::future::ok(Some(eth_tx_for_test().into())))) }); TestCoin::can_refund_htlc - .mock_safe(|_, _| MockResult::Return(Box::new(futures01::future::ok(CanRefundHtlc::HaveToWait(1000))))); + .mock_safe(|_, _| MockResult::Return(Box::pin(futures::future::ok(CanRefundHtlc::HaveToWait(1000))))); TestCoin::search_for_swap_tx_spend_my .mock_safe(|_, _| MockResult::Return(Box::pin(futures::future::ready(Ok(None))))); let maker_coin = MmCoinEnum::Test(TestCoin::default()); @@ -2565,7 +2560,7 @@ mod maker_swap_tests { static mut MY_PAYMENT_SENT_CALLED: bool = false; TestCoin::check_if_my_payment_sent.mock_safe(|_, _| { unsafe { MY_PAYMENT_SENT_CALLED = true }; - MockResult::Return(Box::new(futures01::future::ok(None))) + MockResult::Return(Box::pin(futures::future::ok(None))) }); let maker_coin = MmCoinEnum::Test(TestCoin::default()); let taker_coin = MmCoinEnum::Test(TestCoin::default()); diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index 6029bd61b2..2a5fd662ac 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -1483,7 +1483,6 @@ impl break, diff --git a/mm2src/mm2_main/src/lp_swap/swap_watcher.rs b/mm2src/mm2_main/src/lp_swap/swap_watcher.rs index 0cc4c9e633..16e3712f16 100644 --- a/mm2src/mm2_main/src/lp_swap/swap_watcher.rs +++ b/mm2src/mm2_main/src/lp_swap/swap_watcher.rs @@ -445,7 +445,6 @@ impl State for RefundTakerPayment { match watcher_ctx .taker_coin .can_refund_htlc(watcher_ctx.taker_locktime()) - .compat() .await { Ok(CanRefundHtlc::CanRefundNow) => break, diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap.rs b/mm2src/mm2_main/src/lp_swap/taker_swap.rs index 3bedf837e4..4fe453c457 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap.rs @@ -1307,7 +1307,6 @@ impl TakerSwap { let fee_tx = self .taker_coin .send_taker_fee(&DEX_FEE_ADDR_RAW_PUBKEY, fee_amount, self.uuid.as_bytes(), expire_at) - .compat() .await; let transaction = match fee_tx { Ok(t) => t, @@ -1523,20 +1522,26 @@ impl TakerSwap { ])); } + let taker_payment_lock = self.r().data.taker_payment_lock; + let other_taker_coin_htlc_pub = self.r().other_taker_coin_htlc_pub; + let secret_hash = self.r().secret_hash.clone(); + let taker_coin_swap_contract_address = self.r().data.taker_coin_swap_contract_address.clone(); let unique_data = self.unique_swap_data(); + let taker_amount_decimal = self.taker_amount.to_decimal(); + let payment_instructions = self.r().payment_instructions.clone(); let f = self.taker_coin.check_if_my_payment_sent(CheckIfMyPaymentSentArgs { - time_lock: self.r().data.taker_payment_lock, - other_pub: self.r().other_taker_coin_htlc_pub.as_slice(), - secret_hash: &self.r().secret_hash.0, + time_lock: taker_payment_lock, + other_pub: other_taker_coin_htlc_pub.as_slice(), + secret_hash: &secret_hash.0, search_from_block: self.r().data.taker_coin_start_block, - swap_contract_address: &self.r().data.taker_coin_swap_contract_address, + swap_contract_address: &taker_coin_swap_contract_address, swap_unique_data: &unique_data, - amount: &self.taker_amount.to_decimal(), - payment_instructions: &self.r().payment_instructions, + amount: &taker_amount_decimal, + payment_instructions: &payment_instructions, }); let reward_amount = self.r().reward_amount.clone(); - let wait_until = self.r().data.taker_payment_lock; + let wait_until = taker_payment_lock; let watcher_reward = if self.r().watcher_reward { match self .taker_coin @@ -1562,28 +1567,32 @@ impl TakerSwap { None }; - let transaction = match f.compat().await { + let transaction = match f.await { Ok(res) => match res { Some(tx) => tx, None => { let time_lock = match std::env::var("USE_TEST_LOCKTIME") { Ok(_) => self.r().data.started_at, - Err(_) => self.r().data.taker_payment_lock, + Err(_) => taker_payment_lock, }; - let payment_fut = self.taker_coin.send_taker_payment(SendPaymentArgs { - time_lock_duration: self.r().data.lock_duration, - time_lock, - other_pubkey: &*self.r().other_taker_coin_htlc_pub, - secret_hash: &self.r().secret_hash.0, - amount: self.taker_amount.to_decimal(), - swap_contract_address: &self.r().data.taker_coin_swap_contract_address, - swap_unique_data: &unique_data, - payment_instructions: &self.r().payment_instructions, - watcher_reward, - wait_for_confirmation_until: self.r().data.taker_payment_lock, - }); + let lock_duration = self.r().data.lock_duration; + let payment = self + .taker_coin + .send_taker_payment(SendPaymentArgs { + time_lock_duration: lock_duration, + time_lock, + other_pubkey: &*other_taker_coin_htlc_pub, + secret_hash: &secret_hash.0, + amount: taker_amount_decimal, + swap_contract_address: &taker_coin_swap_contract_address, + swap_unique_data: &unique_data, + payment_instructions: &payment_instructions, + watcher_reward, + wait_for_confirmation_until: taker_payment_lock, + }) + .await; - match payment_fut.compat().await { + match payment { Ok(t) => t, Err(err) => { return Ok((Some(TakerSwapCommand::Finish), vec![ @@ -1932,7 +1941,7 @@ impl TakerSwap { } loop { - match self.taker_coin.can_refund_htlc(locktime).compat().await { + match self.taker_coin.can_refund_htlc(locktime).await { Ok(CanRefundHtlc::CanRefundNow) => break, Ok(CanRefundHtlc::HaveToWait(to_sleep)) => Timer::sleep(to_sleep as f64).await, Err(e) => { @@ -2192,7 +2201,6 @@ impl TakerSwap { amount: &self.taker_amount.to_decimal(), payment_instructions: &payment_instructions, }) - .compat() .await ); match maybe_sent { @@ -2319,7 +2327,7 @@ impl TakerSwap { return ERR!("Taker payment will be refunded automatically!"); } - let can_refund = try_s!(self.taker_coin.can_refund_htlc(taker_payment_lock).compat().await); + let can_refund = try_s!(self.taker_coin.can_refund_htlc(taker_payment_lock).await); if let CanRefundHtlc::HaveToWait(seconds_to_wait) = can_refund { return ERR!("Too early to refund, wait until {}", wait_until_sec(seconds_to_wait)); } @@ -2809,12 +2817,12 @@ mod taker_swap_tests { TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); TestCoin::swap_contract_address.mock_safe(|_| MockResult::Return(None)); TestCoin::can_refund_htlc - .mock_safe(|_, _| MockResult::Return(Box::new(futures01::future::ok(CanRefundHtlc::CanRefundNow)))); + .mock_safe(|_, _| MockResult::Return(Box::pin(futures::future::ok(CanRefundHtlc::CanRefundNow)))); static mut MY_PAYMENT_SENT_CALLED: bool = false; TestCoin::check_if_my_payment_sent.mock_safe(|_, _| { unsafe { MY_PAYMENT_SENT_CALLED = true }; - MockResult::Return(Box::new(futures01::future::ok(Some(eth_tx_for_test().into())))) + MockResult::Return(Box::pin(futures::future::ok(Some(eth_tx_for_test().into())))) }); static mut TX_SPEND_CALLED: bool = false; @@ -2863,7 +2871,7 @@ mod taker_swap_tests { static mut MY_PAYMENT_SENT_CALLED: bool = false; TestCoin::check_if_my_payment_sent.mock_safe(|_, _| { unsafe { MY_PAYMENT_SENT_CALLED = true }; - MockResult::Return(Box::new(futures01::future::ok(Some(eth_tx_for_test().into())))) + MockResult::Return(Box::pin(futures::future::ok(Some(eth_tx_for_test().into())))) }); static mut SEARCH_TX_SPEND_CALLED: bool = false; @@ -2912,7 +2920,7 @@ mod taker_swap_tests { TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); TestCoin::swap_contract_address.mock_safe(|_| MockResult::Return(None)); TestCoin::can_refund_htlc - .mock_safe(|_, _| MockResult::Return(Box::new(futures01::future::ok(CanRefundHtlc::CanRefundNow)))); + .mock_safe(|_, _| MockResult::Return(Box::pin(futures::future::ok(CanRefundHtlc::CanRefundNow)))); static mut SEARCH_TX_SPEND_CALLED: bool = false; TestCoin::search_for_swap_tx_spend_my.mock_safe(|_, _| { @@ -2955,7 +2963,7 @@ mod taker_swap_tests { TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); TestCoin::swap_contract_address.mock_safe(|_| MockResult::Return(None)); TestCoin::can_refund_htlc - .mock_safe(|_, _| MockResult::Return(Box::new(futures01::future::ok(CanRefundHtlc::HaveToWait(1000))))); + .mock_safe(|_, _| MockResult::Return(Box::pin(futures::future::ok(CanRefundHtlc::HaveToWait(1000))))); static mut SEARCH_TX_SPEND_CALLED: bool = false; TestCoin::search_for_swap_tx_spend_my.mock_safe(|_, _| { diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs index edeafa57b6..224ce38090 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs @@ -1883,7 +1883,6 @@ impl break, diff --git a/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs b/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs index c80fbd665b..d89b456874 100644 --- a/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs +++ b/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs @@ -50,7 +50,7 @@ fn test_search_for_swap_tx_spend_native_was_refunded_taker() { watcher_reward: None, wait_for_confirmation_until: 0, }; - let tx = block_on_f01(coin.send_taker_payment(taker_payment_args)).unwrap(); + let tx = block_on(coin.send_taker_payment(taker_payment_args)).unwrap(); let confirm_payment_input = ConfirmPaymentInput { payment_tx: tx.tx_hex(), @@ -208,7 +208,7 @@ fn test_search_for_taker_swap_tx_spend_native_was_spent_by_maker() { watcher_reward: None, wait_for_confirmation_until: 0, }; - let tx = block_on_f01(coin.send_taker_payment(taker_payment_args)).unwrap(); + let tx = block_on(coin.send_taker_payment(taker_payment_args)).unwrap(); let confirm_payment_input = ConfirmPaymentInput { payment_tx: tx.tx_hex(), diff --git a/mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs b/mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs index 0b6213920e..352b383941 100644 --- a/mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs @@ -275,7 +275,7 @@ fn test_maker_spends_taker_payment() { watcher_reward: None, wait_for_confirmation_until: 0, }; - let payment = block_on_f01(taker_coin.send_taker_payment(taker_payment_args)).unwrap(); + let payment = block_on(taker_coin.send_taker_payment(taker_payment_args)).unwrap(); let payment_tx_hash = payment.tx_hash_as_bytes(); let payment_tx_hex = payment.tx_hex(); log!("Taker payment: {:?}", payment_tx_hash); @@ -432,7 +432,7 @@ fn test_taker_refunds_payment() { watcher_reward: None, wait_for_confirmation_until: 0, }; - let payment = block_on_f01(coin.send_taker_payment(taker_payment_args)).unwrap(); + let payment = block_on(coin.send_taker_payment(taker_payment_args)).unwrap(); let payment_tx_hash = payment.tx_hash_as_bytes(); let payment_tx_hex = payment.tx_hex(); log!("Taker payment: {:?}", payment_tx_hash); @@ -530,7 +530,7 @@ fn test_check_if_my_payment_sent() { amount: &amount, payment_instructions: &None, }; - let found = block_on_f01(coin.check_if_my_payment_sent(if_my_payment_sent_args)).unwrap(); + let found = block_on(coin.check_if_my_payment_sent(if_my_payment_sent_args)).unwrap(); assert_eq!(found, Some(payment)); } @@ -1073,7 +1073,7 @@ fn test_get_max_taker_vol_and_trade_with_dynamic_trade_fee(coin: QtumCoin, priv_ let dex_fee = dex_fee_amount("QTUM", "MYCOIN", &expected_max_taker_vol, &qtum_min_tx_amount); let _taker_fee_tx = - block_on_f01(coin.send_taker_fee(&DEX_FEE_ADDR_RAW_PUBKEY, dex_fee, &[], timelock)).expect("!send_taker_fee"); + block_on(coin.send_taker_fee(&DEX_FEE_ADDR_RAW_PUBKEY, dex_fee, &[], timelock)).expect("!send_taker_fee"); let taker_payment_args = SendPaymentArgs { time_lock_duration: 0, time_lock: timelock, @@ -1087,7 +1087,7 @@ fn test_get_max_taker_vol_and_trade_with_dynamic_trade_fee(coin: QtumCoin, priv_ wait_for_confirmation_until: 0, }; - let _taker_payment_tx = block_on_f01(coin.send_taker_payment(taker_payment_args)).expect("!send_taker_payment"); + let _taker_payment_tx = block_on(coin.send_taker_payment(taker_payment_args)).expect("!send_taker_payment"); let my_balance = block_on_f01(coin.my_spendable_balance()).expect("!my_balance"); assert_eq!( @@ -1551,7 +1551,7 @@ fn test_search_for_segwit_swap_tx_spend_native_was_refunded_taker() { watcher_reward: None, wait_for_confirmation_until: 0, }; - let tx = block_on_f01(coin.send_taker_payment(taker_payment)).unwrap(); + let tx = block_on(coin.send_taker_payment(taker_payment)).unwrap(); let confirm_payment_input = ConfirmPaymentInput { payment_tx: tx.tx_hex(), @@ -1705,7 +1705,7 @@ fn test_send_taker_fee_qtum() { generate_segwit_qtum_coin_with_random_privkey("QTUM", BigDecimal::try_from(0.5).unwrap(), Some(0)); let amount = BigDecimal::from_str("0.01").unwrap(); - let tx = block_on_f01(coin.send_taker_fee( + let tx = block_on(coin.send_taker_fee( &DEX_FEE_ADDR_RAW_PUBKEY, DexFee::Standard(amount.clone().into()), &[], @@ -1714,7 +1714,7 @@ fn test_send_taker_fee_qtum() { .expect("!send_taker_fee"); assert!(matches!(tx, TransactionEnum::UtxoTx(_)), "Expected UtxoTx"); - block_on_f01(coin.validate_fee(ValidateFeeArgs { + block_on(coin.validate_fee(ValidateFeeArgs { fee_tx: &tx, expected_sender: coin.my_public_key().unwrap(), fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY, @@ -1734,7 +1734,7 @@ fn test_send_taker_fee_qrc20() { ); let amount = BigDecimal::from_str("0.01").unwrap(); - let tx = block_on_f01(coin.send_taker_fee( + let tx = block_on(coin.send_taker_fee( &DEX_FEE_ADDR_RAW_PUBKEY, DexFee::Standard(amount.clone().into()), &[], @@ -1743,7 +1743,7 @@ fn test_send_taker_fee_qrc20() { .expect("!send_taker_fee"); assert!(matches!(tx, TransactionEnum::UtxoTx(_)), "Expected UtxoTx"); - block_on_f01(coin.validate_fee(ValidateFeeArgs { + block_on(coin.validate_fee(ValidateFeeArgs { fee_tx: &tx, expected_sender: coin.my_public_key().unwrap(), fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY, diff --git a/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs b/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs index 83de612a31..f960932be6 100644 --- a/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs @@ -1209,7 +1209,7 @@ fn test_watcher_validate_taker_fee_utxo() { let taker_amount = MmNumber::from((10, 1)); let fee_amount = dex_fee_amount_from_taker_coin(&taker_coin, maker_coin.ticker(), &taker_amount); - let taker_fee = block_on_f01(taker_coin.send_taker_fee( + let taker_fee = block_on(taker_coin.send_taker_fee( &DEX_FEE_ADDR_RAW_PUBKEY, fee_amount, Uuid::new_v4().as_bytes(), @@ -1323,7 +1323,7 @@ fn test_watcher_validate_taker_fee_eth() { let taker_amount = MmNumber::from((1, 1)); let fee_amount = dex_fee_amount_from_taker_coin(&taker_coin, "ETH", &taker_amount); - let taker_fee = block_on_f01(taker_coin.send_taker_fee( + let taker_fee = block_on(taker_coin.send_taker_fee( &DEX_FEE_ADDR_RAW_PUBKEY, fee_amount, Uuid::new_v4().as_bytes(), @@ -1420,7 +1420,7 @@ fn test_watcher_validate_taker_fee_erc20() { let taker_amount = MmNumber::from((1, 1)); let fee_amount = dex_fee_amount_from_taker_coin(&taker_coin, "ETH", &taker_amount); - let taker_fee = block_on_f01(taker_coin.send_taker_fee( + let taker_fee = block_on(taker_coin.send_taker_fee( &DEX_FEE_ADDR_RAW_PUBKEY, fee_amount, Uuid::new_v4().as_bytes(), @@ -1521,7 +1521,7 @@ fn test_watcher_validate_taker_payment_utxo() { let secret_hash = dhash160(&generate_secret().unwrap()); - let taker_payment = block_on_f01(taker_coin.send_taker_payment(SendPaymentArgs { + let taker_payment = block_on(taker_coin.send_taker_payment(SendPaymentArgs { time_lock_duration, time_lock, other_pubkey: maker_pubkey, @@ -1616,7 +1616,7 @@ fn test_watcher_validate_taker_payment_utxo() { ), } - let taker_payment_wrong_secret = block_on_f01(taker_coin.send_taker_payment(SendPaymentArgs { + let taker_payment_wrong_secret = block_on(taker_coin.send_taker_payment(SendPaymentArgs { time_lock_duration, time_lock, other_pubkey: maker_pubkey, @@ -1729,7 +1729,7 @@ fn test_watcher_validate_taker_payment_eth() { .unwrap(), ); - let taker_payment = block_on_f01(taker_coin.send_taker_payment(SendPaymentArgs { + let taker_payment = block_on(taker_coin.send_taker_payment(SendPaymentArgs { time_lock_duration, time_lock, other_pubkey: maker_pub, @@ -1793,7 +1793,7 @@ fn test_watcher_validate_taker_payment_eth() { ), } - let taker_payment_wrong_contract = block_on_f01(taker_coin.send_taker_payment(SendPaymentArgs { + let taker_payment_wrong_contract = block_on(taker_coin.send_taker_payment(SendPaymentArgs { time_lock_duration, time_lock, other_pubkey: maker_pub, @@ -1861,7 +1861,7 @@ fn test_watcher_validate_taker_payment_eth() { ), } - let taker_payment_wrong_secret = block_on_f01(taker_coin.send_taker_payment(SendPaymentArgs { + let taker_payment_wrong_secret = block_on(taker_coin.send_taker_payment(SendPaymentArgs { time_lock_duration, time_lock, other_pubkey: maker_pub, @@ -1965,7 +1965,7 @@ fn test_watcher_validate_taker_payment_erc20() { .unwrap(), ); - let taker_payment = block_on_f01(taker_coin.send_taker_payment(SendPaymentArgs { + let taker_payment = block_on(taker_coin.send_taker_payment(SendPaymentArgs { time_lock_duration, time_lock, other_pubkey: maker_pub, @@ -2026,7 +2026,7 @@ fn test_watcher_validate_taker_payment_erc20() { ), } - let taker_payment_wrong_contract = block_on_f01(taker_coin.send_taker_payment(SendPaymentArgs { + let taker_payment_wrong_contract = block_on(taker_coin.send_taker_payment(SendPaymentArgs { time_lock_duration, time_lock, other_pubkey: maker_pub, @@ -2090,7 +2090,7 @@ fn test_watcher_validate_taker_payment_erc20() { ), } - let taker_payment_wrong_secret = block_on_f01(taker_coin.send_taker_payment(SendPaymentArgs { + let taker_payment_wrong_secret = block_on(taker_coin.send_taker_payment(SendPaymentArgs { time_lock_duration, time_lock, other_pubkey: maker_pub, @@ -2175,7 +2175,7 @@ fn test_taker_validates_taker_payment_refund_utxo() { let secret_hash = dhash160(&generate_secret().unwrap()); - let taker_payment = block_on_f01(taker_coin.send_taker_payment(SendPaymentArgs { + let taker_payment = block_on(taker_coin.send_taker_payment(SendPaymentArgs { time_lock_duration, time_lock, other_pubkey: maker_pubkey, @@ -2264,7 +2264,7 @@ fn test_taker_validates_taker_payment_refund_eth() { )) .unwrap(); - let taker_payment = block_on_f01(taker_coin.send_taker_payment(SendPaymentArgs { + let taker_payment = block_on(taker_coin.send_taker_payment(SendPaymentArgs { time_lock_duration, time_lock, other_pubkey: maker_pub, @@ -2565,7 +2565,7 @@ fn test_taker_validates_taker_payment_refund_erc20() { .unwrap(), ); - let taker_payment = block_on_f01(taker_coin.send_taker_payment(SendPaymentArgs { + let taker_payment = block_on(taker_coin.send_taker_payment(SendPaymentArgs { time_lock_duration, time_lock, other_pubkey: maker_pub, @@ -3164,7 +3164,7 @@ fn test_send_taker_payment_refund_preimage_utxo() { watcher_reward: None, wait_for_confirmation_until: 0, }; - let tx = block_on_f01(coin.send_taker_payment(taker_payment_args)).unwrap(); + let tx = block_on(coin.send_taker_payment(taker_payment_args)).unwrap(); let confirm_payment_input = ConfirmPaymentInput { payment_tx: tx.tx_hex(),