diff --git a/CHANGELOG.md b/CHANGELOG.md index 55fe9d77bd..b0bd0f2b76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ - Get rid of unnecessary / old dependencies: `crossterm`, `crossterm_winapi`, `mio 0.7.13`, `miow`, `ntapi`, `signal-hook`, `signal-hook-mio` in [#1710](https://github.com/KomodoPlatform/atomicDEX-API/pull/1710) - A bug that caused EVM swap payments validation to fail because the tx was not available yet in the RPC node when calling `eth_getTransactionByHash` was fixed in [#1716](https://github.com/KomodoPlatform/atomicDEX-API/pull/1716). `eth_getTransactionByHash` in now retried in `wait_for_confirmations` until tx is found in the RPC node, this makes sure that the transaction is returned from `eth_getTransactionByHash` later when validating. - `OperationFailure::Other` error was expanded. New error variants were matched with `HwRpcError`, so error type will be `HwError`, not `InternalError` [#1719](https://github.com/KomodoPlatform/atomicDEX-API/pull/1719) +- RPC calls for evm chains was reduced in `wait_for_confirmations` function in [#1724](https://github.com/KomodoPlatform/atomicDEX-API/pull/1724) +- A possible endless loop in evm `wait_for_htlc_tx_spend` was fixed in [#1724](https://github.com/KomodoPlatform/atomicDEX-API/pull/1724) ## v1.0.0-beta - 2023-03-08 diff --git a/mm2src/coins/coin_errors.rs b/mm2src/coins/coin_errors.rs index a296f68adb..648e3428b4 100644 --- a/mm2src/coins/coin_errors.rs +++ b/mm2src/coins/coin_errors.rs @@ -60,7 +60,9 @@ impl From for ValidatePaymentError { match e { Web3RpcError::Transport(tr) => ValidatePaymentError::Transport(tr), Web3RpcError::InvalidResponse(resp) => ValidatePaymentError::InvalidRpcResponse(resp), - Web3RpcError::Internal(internal) => ValidatePaymentError::InternalError(internal), + Web3RpcError::Internal(internal) | Web3RpcError::Timeout(internal) => { + ValidatePaymentError::InternalError(internal) + }, } } } diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index ddb940e331..0db1807086 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -75,22 +75,22 @@ cfg_wasm32! { } use super::{coin_conf, AsyncMutex, BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, CoinFutSpawner, - CoinProtocol, CoinTransportMetrics, CoinsContext, EthValidateFeeArgs, FeeApproxStage, FoundSwapTxSpend, - HistorySyncState, IguanaPrivKey, MakerSwapTakerCoin, MarketCoinOps, MmCoin, MyAddressError, - NegotiateSwapContractAddrErr, NumConversError, NumConversResult, PaymentInstructions, - PaymentInstructionsErr, PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, RawTransactionError, - RawTransactionFut, RawTransactionRequest, RawTransactionRes, RawTransactionResult, RefundError, - RefundPaymentArgs, RefundResult, RpcClientType, RpcTransportEventHandler, RpcTransportEventHandlerShared, - SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureError, - SignatureResult, SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, TradeFee, TradePreimageError, - TradePreimageFut, TradePreimageResult, TradePreimageValue, Transaction, TransactionDetails, - TransactionEnum, TransactionErr, TransactionFut, TxMarshalingErr, UnexpectedDerivationMethod, - ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, ValidateOtherPubKeyErr, - ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, VerificationError, VerificationResult, - WatcherOps, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, - WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest, WithdrawResult, EARLY_CONFIRMATION_ERR_LOG, - INSUFFICIENT_WATCHER_REWARD_ERR_LOG, INVALID_CONTRACT_ADDRESS_ERR_LOG, INVALID_PAYMENT_STATE_ERR_LOG, - INVALID_RECEIVER_ERR_LOG, INVALID_SENDER_ERR_LOG, INVALID_SWAP_ID_ERR_LOG}; + CoinProtocol, CoinTransportMetrics, CoinsContext, ConfirmPaymentInput, EthValidateFeeArgs, FeeApproxStage, + FoundSwapTxSpend, HistorySyncState, IguanaPrivKey, MakerSwapTakerCoin, MarketCoinOps, MmCoin, + MyAddressError, MyWalletAddress, NegotiateSwapContractAddrErr, NumConversError, NumConversResult, + PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, + RawTransactionError, RawTransactionFut, RawTransactionRequest, RawTransactionRes, RawTransactionResult, + RefundError, RefundPaymentArgs, RefundResult, RpcClientType, RpcTransportEventHandler, + RpcTransportEventHandlerShared, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, + SendPaymentArgs, SignatureError, SignatureResult, SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, TradeFee, + TradePreimageError, TradePreimageFut, TradePreimageResult, TradePreimageValue, Transaction, + TransactionDetails, TransactionEnum, TransactionErr, TransactionFut, TxMarshalingErr, + UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, + ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, VerificationError, + VerificationResult, WatcherOps, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, + WatcherValidateTakerFeeInput, WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest, WithdrawResult, + EARLY_CONFIRMATION_ERR_LOG, INSUFFICIENT_WATCHER_REWARD_ERR_LOG, INVALID_CONTRACT_ADDRESS_ERR_LOG, + INVALID_PAYMENT_STATE_ERR_LOG, INVALID_RECEIVER_ERR_LOG, INVALID_SENDER_ERR_LOG, INVALID_SWAP_ID_ERR_LOG}; pub use rlp; #[cfg(test)] mod eth_tests; @@ -100,7 +100,6 @@ mod web3_transport; #[path = "eth/v2_activation.rs"] pub mod v2_activation; #[cfg(feature = "enable-nft-integration")] use crate::nft::WithdrawNftResult; -use crate::MyWalletAddress; #[cfg(feature = "enable-nft-integration")] use crate::{lp_coinfind_or_err, MmCoinEnum, TransactionType}; use v2_activation::{build_address_and_priv_key_policy, EthActivationV2Error}; @@ -197,6 +196,8 @@ pub enum Web3RpcError { Transport(String), #[display(fmt = "Invalid response: {}", _0)] InvalidResponse(String), + #[display(fmt = "Timeout: {}", _0)] + Timeout(String), #[display(fmt = "Internal: {}", _0)] Internal(String), } @@ -238,7 +239,9 @@ impl From for RawTransactionError { fn from(e: Web3RpcError) -> Self { match e { Web3RpcError::Transport(tr) | Web3RpcError::InvalidResponse(tr) => RawTransactionError::Transport(tr), - Web3RpcError::Internal(internal) => RawTransactionError::InternalError(internal), + Web3RpcError::Internal(internal) | Web3RpcError::Timeout(internal) => { + RawTransactionError::InternalError(internal) + }, } } } @@ -277,7 +280,9 @@ impl From for WithdrawError { fn from(e: Web3RpcError) -> Self { match e { Web3RpcError::Transport(err) | Web3RpcError::InvalidResponse(err) => WithdrawError::Transport(err), - Web3RpcError::Internal(internal) => WithdrawError::InternalError(internal), + Web3RpcError::Internal(internal) | Web3RpcError::Timeout(internal) => { + WithdrawError::InternalError(internal) + }, } } } @@ -290,7 +295,9 @@ impl From for TradePreimageError { fn from(e: Web3RpcError) -> Self { match e { Web3RpcError::Transport(err) | Web3RpcError::InvalidResponse(err) => TradePreimageError::Transport(err), - Web3RpcError::Internal(internal) => TradePreimageError::InternalError(internal), + Web3RpcError::Internal(internal) | Web3RpcError::Timeout(internal) => { + TradePreimageError::InternalError(internal) + }, } } } @@ -319,7 +326,7 @@ impl From for BalanceError { fn from(e: Web3RpcError) -> Self { match e { Web3RpcError::Transport(tr) | Web3RpcError::InvalidResponse(tr) => BalanceError::Transport(tr), - Web3RpcError::Internal(internal) => BalanceError::Internal(internal), + Web3RpcError::Internal(internal) | Web3RpcError::Timeout(internal) => BalanceError::Internal(internal), } } } @@ -1726,114 +1733,90 @@ impl MarketCoinOps for EthCoin { ) } - fn wait_for_confirmations( - &self, - tx: &[u8], - confirmations: u64, - _requires_nota: bool, - wait_until: u64, - check_every: u64, - ) -> Box + Send> { + fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box + Send> { + macro_rules! update_status_with_error { + ($status: ident, $error: ident) => { + match $error.get_inner() { + Web3RpcError::Timeout(_) => $status.append(" Timed out."), + _ => $status.append(" Failed."), + } + }; + } + let ctx = try_fus!(MmArc::from_weak(&self.ctx).ok_or("No context")); let mut status = ctx.log.status_handle(); status.status(&[&self.ticker], "Waiting for confirmations…"); - status.deadline(wait_until * 1000); + status.deadline(input.wait_until * 1000); - let unsigned: UnverifiedTransaction = try_fus!(rlp::decode(tx)); + let unsigned: UnverifiedTransaction = try_fus!(rlp::decode(&input.payment_tx)); let tx = try_fus!(SignedEthTx::new(unsigned)); + let tx_hash = tx.hash(); - let required_confirms = U64::from(confirmations); + let required_confirms = U64::from(input.confirmations); + let check_every = input.check_every as f64; let selfi = self.clone(); let fut = async move { loop { - if status.ms2deadline().unwrap() < 0 { - status.append(" Timed out."); - return ERR!( - "Waited too long until {} for transaction {:?} confirmation ", - wait_until, - tx - ); - } - - let web3_receipt = match selfi.web3.eth().transaction_receipt(tx.hash()).await { - Ok(r) => r, + // Wait for one confirmation and return the transaction confirmation block number + let confirmed_at = match selfi + .transaction_confirmed_at(tx_hash, input.wait_until, check_every) + .compat() + .await + { + Ok(c) => c, Err(e) => { - error!( - "Error {:?} getting the {} transaction {:?}, retrying in 15 seconds", - e, - selfi.ticker(), - tx.tx_hash() - ); - Timer::sleep(check_every as f64).await; - continue; + update_status_with_error!(status, e); + return Err(e.to_string()); }, }; - if let Some(receipt) = web3_receipt { - if receipt.status != Some(1.into()) { - status.append(" Failed."); - return ERR!( - "Tx receipt {:?} status of {} tx {:?} is failed", - receipt, - selfi.ticker(), - tx.tx_hash() - ); - } - if let Some(confirmed_at) = receipt.block_number { - let current_block = match selfi.web3.eth().block_number().await { - Ok(b) => b, - Err(e) => { - error!( - "Error {:?} getting the {} block number retrying in 15 seconds", - e, - selfi.ticker() - ); - Timer::sleep(check_every as f64).await; - continue; - }, - }; - // checking if the current block is above the confirmed_at block prediction for pos chain to prevent overflow - if current_block >= confirmed_at && current_block - confirmed_at + 1 >= required_confirms { - loop { - if status.ms2deadline().unwrap() < 0 { - status.append(" Timed out."); - return ERR!( - "Waited too long until {} for transaction {:?} confirmation ", - wait_until, - tx - ); - } - - // Make sure that the transaction is returned by eth_getTransactionByHash too so that swaps don't fail at payment validation - // https://github.com/KomodoPlatform/atomicDEX-API/issues/1630#issuecomment-1401736168 - match selfi.web3.eth().transaction(TransactionId::Hash(tx.hash)).await { - Ok(Some(_)) => { - status.append(" Confirmed."); - return Ok(()); - }, - Ok(None) => error!( - "Didn't find tx: {:02x} for coin: {} on RPC node using eth_getTransactionByHash. Retrying in {} seconds", - tx.hash, - selfi.ticker(), - check_every - ), - Err(e) => error!( - "Error {} calling eth_getTransactionByHash for coin: {}, tx: {:02x}. Retrying in {} seconds", - e, - selfi.ticker(), - tx.hash, - check_every - ), - } - - Timer::sleep(check_every as f64).await; - } + // checking that confirmed_at is greater than zero to prevent overflow. + // untrusted RPC nodes might send a zero value to cause overflow if we didn't do this check. + // required_confirms should always be more than 0 anyways but we should keep this check nonetheless. + if confirmed_at <= U64::from(0) { + error!( + "confirmed_at: {}, for payment tx: {:02x}, for coin:{} should be greater than zero!", + confirmed_at, + tx_hash, + selfi.ticker() + ); + Timer::sleep(check_every).await; + continue; + } + + // Wait for a block that achieves the required confirmations + let confirmation_block_number = confirmed_at + required_confirms - 1; + if let Err(e) = selfi + .wait_for_block(confirmation_block_number, input.wait_until, check_every) + .compat() + .await + { + update_status_with_error!(status, e); + return Err(e.to_string()); + } + + // Make sure that there was no chain reorganization that led to transaction confirmation block to be changed + match selfi + .transaction_confirmed_at(tx_hash, input.wait_until, check_every) + .compat() + .await + { + Ok(conf) => { + if conf == confirmed_at { + status.append(" Confirmed."); + break Ok(()); } - } + }, + Err(e) => { + update_status_with_error!(status, e); + return Err(e.to_string()); + }, } - Timer::sleep(check_every as f64).await; + + Timer::sleep(check_every).await; } }; + Box::new(fut.boxed().compat()) } @@ -1881,6 +1864,14 @@ impl MarketCoinOps for EthCoin { let fut = async move { loop { + if now_ms() / 1000 > wait_until { + return TX_PLAIN_ERR!( + "Waited too long until {} for transaction {:?} to be spent ", + wait_until, + tx, + ); + } + let current_block = match selfi.current_block().compat().await { Ok(b) => b, Err(e) => { @@ -1925,15 +1916,7 @@ impl MarketCoinOps for EthCoin { } } - if now_ms() / 1000 > wait_until { - return TX_PLAIN_ERR!( - "Waited too long until {} for transaction {:?} to be spent ", - wait_until, - tx, - ); - } Timer::sleep(5.).await; - continue; } }; Box::new(fut.boxed().compat()) @@ -3563,7 +3546,7 @@ impl EthCoin { let fut = async move { loop { if now_ms() / 1000 > wait_until { - return MmError::err(Web3RpcError::Internal(ERRL!( + return MmError::err(Web3RpcError::Timeout(ERRL!( "Waited too long until {} for allowance to be updated to at least {}", wait_until, required_allowance @@ -4062,6 +4045,88 @@ impl EthCoin { ); Ok(None) } + + fn transaction_confirmed_at(&self, payment_hash: H256, wait_until: u64, check_every: f64) -> Web3RpcFut { + let selfi = self.clone(); + let fut = async move { + loop { + if now_ms() / 1000 > wait_until { + return MmError::err(Web3RpcError::Timeout(ERRL!( + "Waited too long until {} for payment tx: {:02x}, for coin:{}, to be confirmed!", + wait_until, + payment_hash, + selfi.ticker() + ))); + } + + let web3_receipt = match selfi.web3.eth().transaction_receipt(payment_hash).await { + Ok(r) => r, + Err(e) => { + error!( + "Error {:?} getting the {} transaction {:?}, retrying in 15 seconds", + e, + selfi.ticker(), + payment_hash + ); + Timer::sleep(check_every).await; + continue; + }, + }; + + if let Some(receipt) = web3_receipt { + if receipt.status != Some(1.into()) { + return MmError::err(Web3RpcError::Internal(ERRL!( + "Tx receipt {:?} status of {} tx {:?} is failed", + receipt, + selfi.ticker(), + payment_hash + ))); + } + + if let Some(confirmed_at) = receipt.block_number { + break Ok(confirmed_at); + } + } + + Timer::sleep(check_every).await; + } + }; + Box::new(fut.boxed().compat()) + } + + fn wait_for_block(&self, block_number: U64, wait_until: u64, check_every: f64) -> Web3RpcFut<()> { + let selfi = self.clone(); + let fut = async move { + loop { + if now_ms() / 1000 > wait_until { + return MmError::err(Web3RpcError::Timeout(ERRL!( + "Waited too long until {} for block number: {:02x} to appear on-chain, for coin:{}", + wait_until, + block_number, + selfi.ticker() + ))); + } + + match selfi.web3.eth().block_number().await { + Ok(current_block) => { + if current_block >= block_number { + break Ok(()); + } + }, + Err(e) => { + error!( + "Error {:?} getting the {} block number retrying in 15 seconds", + e, + selfi.ticker() + ); + }, + }; + + Timer::sleep(check_every).await; + } + }; + Box::new(fut.boxed().compat()) + } } #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] diff --git a/mm2src/coins/lightning.rs b/mm2src/coins/lightning.rs index a134d0bc53..f5ca99c625 100644 --- a/mm2src/coins/lightning.rs +++ b/mm2src/coins/lightning.rs @@ -15,17 +15,17 @@ use crate::lightning::ln_utils::{filter_channels, pay_invoice_with_max_total_clt use crate::utxo::rpc_clients::UtxoRpcClientEnum; use crate::utxo::utxo_common::{big_decimal_from_sat, big_decimal_from_sat_unsigned}; use crate::utxo::{sat_from_big_decimal, utxo_common, BlockchainNetwork}; -use crate::{BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, CoinFutSpawner, FeeApproxStage, FoundSwapTxSpend, - HistorySyncState, MakerSwapTakerCoin, MarketCoinOps, MmCoin, NegotiateSwapContractAddrErr, - PaymentInstructions, PaymentInstructionsErr, RawTransactionError, RawTransactionFut, - RawTransactionRequest, RefundError, RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, - SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureError, SignatureResult, SpendPaymentArgs, - SwapOps, TakerSwapMakerCoin, TradeFee, TradePreimageFut, TradePreimageResult, TradePreimageValue, - Transaction, TransactionEnum, TransactionErr, TransactionFut, TxMarshalingErr, UnexpectedDerivationMethod, - UtxoStandardCoin, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, ValidateOtherPubKeyErr, - ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, VerificationError, VerificationResult, - WatcherOps, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, - WithdrawError, WithdrawFut, WithdrawRequest}; +use crate::{BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, CoinFutSpawner, ConfirmPaymentInput, FeeApproxStage, + FoundSwapTxSpend, HistorySyncState, MakerSwapTakerCoin, MarketCoinOps, MmCoin, + NegotiateSwapContractAddrErr, PaymentInstructions, PaymentInstructionsErr, RawTransactionError, + RawTransactionFut, RawTransactionRequest, RefundError, RefundPaymentArgs, RefundResult, + SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureError, + SignatureResult, SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, TradeFee, TradePreimageFut, + TradePreimageResult, TradePreimageValue, Transaction, TransactionEnum, TransactionErr, TransactionFut, + TxMarshalingErr, UnexpectedDerivationMethod, UtxoStandardCoin, ValidateAddressResult, ValidateFeeArgs, + ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, + ValidatePaymentInput, VerificationError, VerificationResult, WatcherOps, WatcherSearchForSwapTxSpendInput, + WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WithdrawError, WithdrawFut, WithdrawRequest}; use async_trait::async_trait; use bitcoin::bech32::ToBase32; use bitcoin::hashes::Hash; @@ -1071,24 +1071,17 @@ impl MarketCoinOps for LightningCoin { // Todo: Add waiting for confirmations logic for the case of if the channel is closed and the htlc can be claimed on-chain // Todo: The above is postponed and might not be needed after this issue is resolved https://github.com/lightningdevkit/rust-lightning/issues/2017 - fn wait_for_confirmations( - &self, - tx: &[u8], - _confirmations: u64, - _requires_nota: bool, - wait_until: u64, - check_every: u64, - ) -> Box + Send> { - let payment_hash = try_f!(payment_hash_from_slice(tx).map_err(|e| e.to_string())); + fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box + Send> { + let payment_hash = try_f!(payment_hash_from_slice(&input.payment_tx).map_err(|e| e.to_string())); let payment_hex = hex::encode(payment_hash.0); let coin = self.clone(); let fut = async move { loop { - if now_ms() / 1000 > wait_until { + if now_ms() / 1000 > input.wait_until { return ERR!( "Waited too long until {} for payment {} to be received", - wait_until, + input.wait_until, payment_hex ); } @@ -1124,7 +1117,7 @@ impl MarketCoinOps for LightningCoin { // note: When sleeping for only 1 second the test_send_payment_and_swaps unit test took 20 seconds to complete instead of 37 seconds when WAIT_CONFIRM_INTERVAL (15 seconds) is used // Todo: In next sprints, should add a mutex for lightning swap payments to avoid overloading the shared db connection with requests when the sleep time is reduced and multiple swaps are ran together // Todo: The aim is to make lightning swap payments as fast as possible. Running swap payments statuses should be loaded from db on restarts in this case. - Timer::sleep(check_every as f64).await; + Timer::sleep(input.check_every as f64).await; } }; Box::new(fut.boxed().compat()) diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index da239d3550..f4dbd94905 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -543,6 +543,15 @@ pub enum ValidateOtherPubKeyErr { InvalidPubKey(String), } +#[derive(Clone, Debug)] +pub struct ConfirmPaymentInput { + pub payment_tx: Vec, + pub confirmations: u64, + pub requires_nota: bool, + pub wait_until: u64, + pub check_every: u64, +} + #[derive(Clone, Debug)] pub struct WatcherValidateTakerFeeInput { pub taker_fee_hash: Vec, @@ -941,14 +950,7 @@ pub trait MarketCoinOps { /// Receives raw transaction bytes as input and returns tx hash in hexadecimal format fn send_raw_tx_bytes(&self, tx: &[u8]) -> Box + Send>; - fn wait_for_confirmations( - &self, - tx: &[u8], - confirmations: u64, - requires_nota: bool, - wait_until: u64, - check_every: u64, - ) -> Box + Send>; + fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box + Send>; fn wait_for_htlc_tx_spend( &self, diff --git a/mm2src/coins/qrc20.rs b/mm2src/coins/qrc20.rs index e8bf41228a..54219400cf 100644 --- a/mm2src/coins/qrc20.rs +++ b/mm2src/coins/qrc20.rs @@ -15,9 +15,9 @@ use crate::utxo::{qtum, ActualTxFee, AdditionalTxData, AddrFromStrError, Broadca GetUtxoListOps, HistoryUtxoTx, HistoryUtxoTxMap, MatureUnspentList, RecentlySpentOutPointsGuard, UtxoActivationParams, UtxoAddressFormat, UtxoCoinFields, UtxoCommonOps, UtxoFromLegacyReqErr, UtxoTx, UtxoTxBroadcastOps, UtxoTxGenerationOps, VerboseTransactionFrom, UTXO_LOCK}; -use crate::{BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, CoinFutSpawner, FeeApproxStage, - FoundSwapTxSpend, HistorySyncState, IguanaPrivKey, MakerSwapTakerCoin, MarketCoinOps, MmCoin, - NegotiateSwapContractAddrErr, PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, +use crate::{BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, CoinFutSpawner, ConfirmPaymentInput, + FeeApproxStage, FoundSwapTxSpend, HistorySyncState, IguanaPrivKey, MakerSwapTakerCoin, MarketCoinOps, + MmCoin, NegotiateSwapContractAddrErr, PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, RawTransactionFut, RawTransactionRequest, RefundError, RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureResult, SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, TradeFee, TradePreimageError, @@ -1220,19 +1220,18 @@ impl MarketCoinOps for Qrc20Coin { utxo_common::send_raw_tx_bytes(&self.utxo, tx) } - fn wait_for_confirmations( - &self, - tx: &[u8], - confirmations: u64, - requires_nota: bool, - wait_until: u64, - check_every: u64, - ) -> Box + Send> { - let tx: UtxoTx = try_fus!(deserialize(tx).map_err(|e| ERRL!("{:?}", e))); + fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box + Send> { + let tx: UtxoTx = try_fus!(deserialize(input.payment_tx.as_slice()).map_err(|e| ERRL!("{:?}", e))); let selfi = self.clone(); let fut = async move { selfi - .wait_for_confirmations_and_check_result(tx, confirmations, requires_nota, wait_until, check_every) + .wait_for_confirmations_and_check_result( + tx, + input.confirmations, + input.requires_nota, + input.wait_until, + input.check_every, + ) .await }; Box::new(fut.boxed().compat()) diff --git a/mm2src/coins/qrc20/qrc20_tests.rs b/mm2src/coins/qrc20/qrc20_tests.rs index 7354b5a103..f662f55ad3 100644 --- a/mm2src/coins/qrc20/qrc20_tests.rs +++ b/mm2src/coins/qrc20/qrc20_tests.rs @@ -260,27 +260,40 @@ fn test_wait_for_confirmations_excepted() { let requires_nota = false; let wait_until = (now_ms() / 1000) + 1; // the transaction is mined already let check_every = 1; - coin.wait_for_confirmations(&payment_tx, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx, + confirmations, + requires_nota, + wait_until, + check_every, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); // tx_hash: ed53b97deb2ad76974c972cb084f6ba63bd9f16c91c4a39106a20c6d14599b2a // `erc20Payment` contract call excepted let payment_tx = hex::decode("01000000014c1411bac38ca25a2816342b019df81f503e1db75b25c6da618b08484dc2ff49010000006b483045022100da3e90fbcc45a94573c28213b36dc616630e3adfa42a7f16bdf917e8a76b954502206ad0830bb16e5c25466903ae7f749e291586726f1497ae9fc2e709c1b6cd1857012103693bff1b39e8b5a306810023c29b95397eb395530b106b1820ea235fd81d9ce9ffffffff040000000000000000625403a08601012844095ea7b3000000000000000000000000ba8b71f3544b93e2f681f996da519a98ace0107a000000000000000000000000000000000000000000000000000000000000000014d362e096e873eb7907e205fadc6175c6fec7bc44c20000000000000000625403a08601012844095ea7b3000000000000000000000000ba8b71f3544b93e2f681f996da519a98ace0107a000000000000000000000000000000000000000000000000000000000000000a14d362e096e873eb7907e205fadc6175c6fec7bc44c20000000000000000e35403a0860101284cc49b415b2a0a1a8b4af2762154115ced87e2424b3cb940c0181cc3c850523702f1ec298fef0000000000000000000000000000000000000000000000000000000000000064000000000000000000000000d362e096e873eb7907e205fadc6175c6fec7bc44000000000000000000000000783cf0be521101942da509846ea476e683aad8324b6b2e5444c2639cc0fb7bcea5afba3f3cdce239000000000000000000000000000000000000000000000000000000000000000000000000000000005fa0fffb14ba8b71f3544b93e2f681f996da519a98ace0107ac2493d4a03000000001976a9149e032d4b0090a11dc40fe6c47601499a35d55fbb88acae2ea15f").unwrap(); - let error = coin - .wait_for_confirmations(&payment_tx, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap_err(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx, + confirmations, + requires_nota, + wait_until, + check_every, + }; + let error = coin.wait_for_confirmations(confirm_payment_input).wait().unwrap_err(); log!("error: {:?}", error); assert!(error.contains("Contract call failed with an error: Revert")); // tx_hash: aa992c028c07e239dbd2ff32bf67251f026929c644b4d02a469e351cb44abab7 // `receiverSpend` contract call excepted let payment_tx = hex::decode("0100000007077ccb377a68fd6079503f856df4e553e337015f8419cd0f2a949c31db175df7050000006a473044022058097f54be31ae5af197f72e4410b33b22f29fad5b1a1cefb30ee45b3b3477dc02205c1098850fa2f2c1929c27af6261f83abce7682eb769f909dd09e9be5e0bd469012102aa32922f4b05cbc7384dd85b86021c98e4102f5da3df48bc516aa76f8119559affffffffc191895a431db3dccbf4f9d4b8cd8301124343e66275194ad734a77ffe56b95e030000006a4730440220491fed7954c6f43acc7226c337bb16ac71b38df50f55a819441d9b2b9e4a04b502201f95be6941b6619c0ca246e15adb090b82cd908f7c85108a1dcc02eafb7cc725012102aa32922f4b05cbc7384dd85b86021c98e4102f5da3df48bc516aa76f8119559afffffffff678de174fb81d3820df43a2c29945b08df4fb080deb8088ef11b3711c0fe8df020000006a473044022071d9c0ec57ab23360a4f73d0edfc2f67614b56f6d2e54387b39c3de1fa894c7d022030ea65d157784ff68cae9c9acb0dd626205073f478003b1cb1d0d581dcb27b1c012102aa32922f4b05cbc7384dd85b86021c98e4102f5da3df48bc516aa76f8119559affffffffe1ef8740ce51ed3172efea91a5e559b5fe63dc6fede8a9037ad47fbc38560b51040000006a47304402203f056dff0be1f24ed96c72904c9aac3ac964913d0c3228bfab3fa4bef7f22c060220658a121bf8f29d86c18ec1aee4460f363c0704d2f05cc9d7923e978e917f48ca012102aa32922f4b05cbc7384dd85b86021c98e4102f5da3df48bc516aa76f8119559affffffffe825dea61113bbd67dd35cbc9d88890ac222f55bf0201a7f9fb96592e0614d4d080000006b483045022100bb10f195c57c1eed9de3d9d9726484f839e25d83deb54cf2142df37099df6a8d02202a025182caaa5348350b410ee783180e9ce3ccac5e361eb50b162311e9d803f1012102aa32922f4b05cbc7384dd85b86021c98e4102f5da3df48bc516aa76f8119559affffffffe1ef8740ce51ed3172efea91a5e559b5fe63dc6fede8a9037ad47fbc38560b51060000006a47304402205550e0b4e1425f2f7a8645c6fd408ba0603cca5ca408202729041f5eab0b0cd202205c98fc8e91a37960d38f0104e81d3d48f737c4000ef45e2372c84d857455da34012102aa32922f4b05cbc7384dd85b86021c98e4102f5da3df48bc516aa76f8119559affffffffe825dea61113bbd67dd35cbc9d88890ac222f55bf0201a7f9fb96592e0614d4d060000006b483045022100b0d21cbb5d94b4995d9cb81e7440849dbe645416bca6d51bb5450e10753523220220299f105d573cdb785233699b5a9be8f907d9821a74cfd91fb72911a4a6e1bdb8012102aa32922f4b05cbc7384dd85b86021c98e4102f5da3df48bc516aa76f8119559affffffff020000000000000000c35403a0860101284ca402ed292be8b1d4904e8f1924bd7a2eb4d8085214c17af3d8d7574b2740a86b6296d343c00000000000000000000000000000000000000000000000000000000005f5e10028fcc0c5f6d9619d3c1f90af51e891d62333eb748c568f7da2a7734240d37d38000000000000000000000000d362e096e873eb7907e205fadc6175c6fec7bc44000000000000000000000000d020b63f5a989776516bdc04d426ba118130c00214ba8b71f3544b93e2f681f996da519a98ace0107ac270630800000000001976a914fb7dad7ce97deecf50a4573a2bd7639c79bdc08588aca64aaa5f").unwrap(); - let error = coin - .wait_for_confirmations(&payment_tx, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap_err(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx, + confirmations, + requires_nota, + wait_until, + check_every, + }; + let error = coin.wait_for_confirmations(confirm_payment_input).wait().unwrap_err(); log!("error: {:?}", error); assert!(error.contains("Contract call failed with an error: Revert")); } diff --git a/mm2src/coins/solana.rs b/mm2src/coins/solana.rs index 2443f31276..0da80b5968 100644 --- a/mm2src/coins/solana.rs +++ b/mm2src/coins/solana.rs @@ -2,16 +2,17 @@ use super::{CoinBalance, HistorySyncState, MarketCoinOps, MmCoin, SwapOps, Trade use crate::coin_errors::MyAddressError; use crate::solana::solana_common::{lamports_to_sol, PrepareTransferData, SufficientBalanceError}; use crate::solana::spl::SplTokenInfo; -use crate::{BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinFutSpawner, FeeApproxStage, FoundSwapTxSpend, - MakerSwapTakerCoin, NegotiateSwapContractAddrErr, PaymentInstructions, PaymentInstructionsErr, - PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, RawTransactionFut, RawTransactionRequest, RefundError, - RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, - SendPaymentArgs, SignatureResult, SpendPaymentArgs, TakerSwapMakerCoin, TradePreimageFut, - TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionFut, TransactionType, - TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, - ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, - ValidatePaymentInput, VerificationResult, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, - WatcherValidateTakerFeeInput, WithdrawError, WithdrawFut, WithdrawRequest, WithdrawResult}; +use crate::{BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinFutSpawner, ConfirmPaymentInput, FeeApproxStage, + FoundSwapTxSpend, MakerSwapTakerCoin, NegotiateSwapContractAddrErr, PaymentInstructions, + PaymentInstructionsErr, PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, RawTransactionFut, + RawTransactionRequest, RefundError, RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, + SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureResult, SpendPaymentArgs, + TakerSwapMakerCoin, TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionDetails, + TransactionFut, TransactionType, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, + ValidateFeeArgs, ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, + ValidatePaymentFut, ValidatePaymentInput, VerificationResult, WatcherSearchForSwapTxSpendInput, + WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WithdrawError, WithdrawFut, WithdrawRequest, + WithdrawResult}; use async_trait::async_trait; use base58::ToBase58; use bincode::{deserialize, serialize}; @@ -441,14 +442,7 @@ impl MarketCoinOps for SolanaCoin { Box::new(fut.boxed().compat()) } - fn wait_for_confirmations( - &self, - _tx: &[u8], - _confirmations: u64, - _requires_nota: bool, - _wait_until: u64, - _check_every: u64, - ) -> Box + Send> { + fn wait_for_confirmations(&self, _input: ConfirmPaymentInput) -> Box + Send> { unimplemented!() } diff --git a/mm2src/coins/solana/spl.rs b/mm2src/coins/solana/spl.rs index d23cb2301f..8aa917aed0 100644 --- a/mm2src/coins/solana/spl.rs +++ b/mm2src/coins/solana/spl.rs @@ -2,11 +2,11 @@ use super::{CoinBalance, HistorySyncState, MarketCoinOps, MmCoin, SwapOps, Trade use crate::coin_errors::MyAddressError; use crate::solana::solana_common::{ui_amount_to_amount, PrepareTransferData, SufficientBalanceError}; use crate::solana::{solana_common, AccountError, SolanaCommonOps, SolanaFeeDetails}; -use crate::{BalanceFut, CheckIfMyPaymentSentArgs, CoinFutSpawner, FeeApproxStage, FoundSwapTxSpend, - MakerSwapTakerCoin, NegotiateSwapContractAddrErr, PaymentInstructions, PaymentInstructionsErr, - RawTransactionFut, RawTransactionRequest, RefundError, RefundPaymentArgs, RefundResult, - SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureResult, - SolanaCoin, SpendPaymentArgs, TakerSwapMakerCoin, TradePreimageFut, TradePreimageResult, +use crate::{BalanceFut, CheckIfMyPaymentSentArgs, CoinFutSpawner, ConfirmPaymentInput, FeeApproxStage, + FoundSwapTxSpend, MakerSwapTakerCoin, NegotiateSwapContractAddrErr, PaymentInstructions, + PaymentInstructionsErr, RawTransactionFut, RawTransactionRequest, RefundError, RefundPaymentArgs, + RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, + SignatureResult, SolanaCoin, SpendPaymentArgs, TakerSwapMakerCoin, TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionFut, TransactionType, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, @@ -265,14 +265,7 @@ impl MarketCoinOps for SplToken { self.platform_coin.send_raw_tx_bytes(tx) } - fn wait_for_confirmations( - &self, - _tx: &[u8], - _confirmations: u64, - _requires_nota: bool, - _wait_until: u64, - _check_every: u64, - ) -> Box + Send> { + fn wait_for_confirmations(&self, _input: ConfirmPaymentInput) -> Box + Send> { unimplemented!() } diff --git a/mm2src/coins/tendermint/tendermint_coin.rs b/mm2src/coins/tendermint/tendermint_coin.rs index 4eb75fdf23..eabffcf897 100644 --- a/mm2src/coins/tendermint/tendermint_coin.rs +++ b/mm2src/coins/tendermint/tendermint_coin.rs @@ -14,14 +14,14 @@ use crate::tendermint::ibc::IBC_OUT_SOURCE_PORT; use crate::utxo::sat_from_big_decimal; use crate::utxo::utxo_common::big_decimal_from_sat; use crate::{big_decimal_from_sat_unsigned, BalanceError, BalanceFut, BigDecimal, CheckIfMyPaymentSentArgs, - CoinBalance, CoinFutSpawner, FeeApproxStage, FoundSwapTxSpend, HistorySyncState, MakerSwapTakerCoin, - MarketCoinOps, MmCoin, NegotiateSwapContractAddrErr, PaymentInstructions, PaymentInstructionsErr, - PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, RawTransactionError, RawTransactionFut, - RawTransactionRequest, RawTransactionRes, RefundError, RefundPaymentArgs, RefundResult, RpcCommonOps, - SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureError, - SignatureResult, SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, TradeFee, TradePreimageError, - TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionEnum, - TransactionErr, TransactionFut, TransactionType, TxFeeDetails, TxMarshalingErr, + CoinBalance, CoinFutSpawner, ConfirmPaymentInput, FeeApproxStage, FoundSwapTxSpend, HistorySyncState, + MakerSwapTakerCoin, MarketCoinOps, MmCoin, NegotiateSwapContractAddrErr, PaymentInstructions, + PaymentInstructionsErr, PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, RawTransactionError, + RawTransactionFut, RawTransactionRequest, RawTransactionRes, RefundError, RefundPaymentArgs, RefundResult, + RpcCommonOps, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, + SignatureError, SignatureResult, SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, TradeFee, + TradePreimageError, TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionDetails, + TransactionEnum, TransactionErr, TransactionFut, TransactionType, TxFeeDetails, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentFut, ValidatePaymentInput, VerificationError, VerificationResult, WatcherOps, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, @@ -2127,26 +2127,19 @@ impl MarketCoinOps for TendermintCoin { Box::new(fut.boxed().compat()) } - fn wait_for_confirmations( - &self, - tx_bytes: &[u8], - _confirmations: u64, - _requires_nota: bool, - wait_until: u64, - check_every: u64, - ) -> Box + Send> { + fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box + Send> { // Sanity check - let _: TxRaw = try_fus!(Message::decode(tx_bytes)); + let _: TxRaw = try_fus!(Message::decode(input.payment_tx.as_slice())); - let tx_hash = hex::encode_upper(sha256(tx_bytes)); + let tx_hash = hex::encode_upper(sha256(&input.payment_tx)); let coin = self.clone(); let fut = async move { loop { - if now_ms() / 1000 > wait_until { + if now_ms() / 1000 > input.wait_until { return ERR!( "Waited too long until {} for payment {} to be received", - wait_until, + input.wait_until, tx_hash.clone() ); } @@ -2163,7 +2156,7 @@ impl MarketCoinOps for TendermintCoin { }; }; - Timer::sleep(check_every as f64).await; + Timer::sleep(input.check_every as f64).await; } }; @@ -3449,11 +3442,14 @@ pub mod tendermint_coin_tests { .unwrap() .encode_to_vec(); - block_on( - coin.wait_for_confirmations(&tx_bytes, 0, false, wait_until(), CHECK_INTERVAL) - .compat(), - ) - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx_bytes, + confirmations: 0, + requires_nota: false, + wait_until: wait_until(), + check_every: CHECK_INTERVAL, + }; + block_on(coin.wait_for_confirmations(confirm_payment_input).compat()).unwrap(); } for failed_tx_hash in FAILED_TX_HASH_SAMPLES { @@ -3461,11 +3457,14 @@ pub mod tendermint_coin_tests { .unwrap() .encode_to_vec(); - block_on( - coin.wait_for_confirmations(&tx_bytes, 0, false, wait_until(), CHECK_INTERVAL) - .compat(), - ) - .unwrap_err(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx_bytes, + confirmations: 0, + requires_nota: false, + wait_until: wait_until(), + check_every: CHECK_INTERVAL, + }; + block_on(coin.wait_for_confirmations(confirm_payment_input).compat()).unwrap_err(); } } } diff --git a/mm2src/coins/tendermint/tendermint_token.rs b/mm2src/coins/tendermint/tendermint_token.rs index 2107c6a42a..54dc2dbc28 100644 --- a/mm2src/coins/tendermint/tendermint_token.rs +++ b/mm2src/coins/tendermint/tendermint_token.rs @@ -7,17 +7,17 @@ use super::{TendermintCoin, TendermintFeeDetails, GAS_LIMIT_DEFAULT, MIN_TX_SATO use crate::rpc_command::tendermint::IBCWithdrawRequest; use crate::utxo::utxo_common::big_decimal_from_sat; use crate::{big_decimal_from_sat_unsigned, utxo::sat_from_big_decimal, BalanceFut, BigDecimal, - CheckIfMyPaymentSentArgs, CoinBalance, CoinFutSpawner, FeeApproxStage, FoundSwapTxSpend, HistorySyncState, - MakerSwapTakerCoin, MarketCoinOps, MmCoin, MyAddressError, NegotiateSwapContractAddrErr, - PaymentInstructions, PaymentInstructionsErr, RawTransactionFut, RawTransactionRequest, RefundError, - RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, - SendPaymentArgs, SignatureResult, SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, TradeFee, - TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionEnum, - TransactionErr, TransactionFut, TransactionType, TxFeeDetails, TxMarshalingErr, - UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, - ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, - VerificationResult, WatcherOps, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, - WatcherValidateTakerFeeInput, WithdrawError, WithdrawFut, WithdrawRequest}; + CheckIfMyPaymentSentArgs, CoinBalance, CoinFutSpawner, ConfirmPaymentInput, FeeApproxStage, + FoundSwapTxSpend, HistorySyncState, MakerSwapTakerCoin, MarketCoinOps, MmCoin, MyAddressError, + NegotiateSwapContractAddrErr, PaymentInstructions, PaymentInstructionsErr, RawTransactionFut, + RawTransactionRequest, RefundError, RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, + SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureResult, SpendPaymentArgs, SwapOps, + TakerSwapMakerCoin, TradeFee, TradePreimageFut, TradePreimageResult, TradePreimageValue, + TransactionDetails, TransactionEnum, TransactionErr, TransactionFut, TransactionType, TxFeeDetails, + TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, + ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, + ValidatePaymentInput, VerificationResult, WatcherOps, WatcherSearchForSwapTxSpendInput, + WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WithdrawError, WithdrawFut, WithdrawRequest}; use async_trait::async_trait; use bitcrypto::sha256; use common::executor::abortable_queue::AbortableQueue; @@ -522,16 +522,8 @@ impl MarketCoinOps for TendermintToken { self.platform_coin.send_raw_tx_bytes(tx) } - fn wait_for_confirmations( - &self, - tx: &[u8], - confirmations: u64, - requires_nota: bool, - wait_until: u64, - check_every: u64, - ) -> Box + Send> { - self.platform_coin - .wait_for_confirmations(tx, confirmations, requires_nota, wait_until, check_every) + fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box + Send> { + self.platform_coin.wait_for_confirmations(input) } fn wait_for_htlc_tx_spend( diff --git a/mm2src/coins/test_coin.rs b/mm2src/coins/test_coin.rs index 7e3cb9e0eb..01e4dda0cc 100644 --- a/mm2src/coins/test_coin.rs +++ b/mm2src/coins/test_coin.rs @@ -3,8 +3,8 @@ use super::{CoinBalance, HistorySyncState, MarketCoinOps, MmCoin, RawTransactionFut, RawTransactionRequest, SwapOps, TradeFee, TransactionEnum, TransactionFut}; use crate::{coin_errors::MyAddressError, BalanceFut, CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinFutSpawner, - FeeApproxStage, FoundSwapTxSpend, MakerSwapTakerCoin, NegotiateSwapContractAddrErr, PaymentInstructions, - PaymentInstructionsErr, RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, + ConfirmPaymentInput, FeeApproxStage, FoundSwapTxSpend, MakerSwapTakerCoin, NegotiateSwapContractAddrErr, + PaymentInstructions, PaymentInstructionsErr, RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureResult, SpendPaymentArgs, TakerSwapMakerCoin, TradePreimageFut, TradePreimageResult, TradePreimageValue, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, @@ -64,14 +64,7 @@ impl MarketCoinOps for TestCoin { fn send_raw_tx_bytes(&self, tx: &[u8]) -> Box + Send> { unimplemented!() } - fn wait_for_confirmations( - &self, - tx: &[u8], - confirmations: u64, - requires_nota: bool, - wait_until: u64, - check_every: u64, - ) -> Box + Send> { + fn wait_for_confirmations(&self, _input: ConfirmPaymentInput) -> Box + Send> { unimplemented!() } diff --git a/mm2src/coins/utxo/bch.rs b/mm2src/coins/utxo/bch.rs index 5758f269bd..896600d0a3 100644 --- a/mm2src/coins/utxo/bch.rs +++ b/mm2src/coins/utxo/bch.rs @@ -10,15 +10,15 @@ use crate::utxo::utxo_common::big_decimal_from_sat_unsigned; use crate::utxo::utxo_tx_history_v2::{UtxoMyAddressesHistoryError, UtxoTxDetailsError, UtxoTxDetailsParams, UtxoTxHistoryOps}; use crate::{BlockHeightAndTime, CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinProtocol, - CoinWithDerivationMethod, IguanaPrivKey, MakerSwapTakerCoin, NegotiateSwapContractAddrErr, - PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, RawTransactionFut, RawTransactionRequest, - RefundError, RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, - SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureResult, SpendPaymentArgs, SwapOps, - TakerSwapMakerCoin, TradePreimageValue, TransactionFut, TransactionType, TxFeeDetails, TxMarshalingErr, - UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, - ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, - VerificationResult, WatcherOps, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, - WatcherValidateTakerFeeInput, WithdrawFut}; + CoinWithDerivationMethod, ConfirmPaymentInput, IguanaPrivKey, MakerSwapTakerCoin, + NegotiateSwapContractAddrErr, PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, + RawTransactionFut, RawTransactionRequest, RefundError, RefundPaymentArgs, RefundResult, + SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureResult, + SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, TradePreimageValue, TransactionFut, TransactionType, + TxFeeDetails, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, + ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, + ValidatePaymentInput, VerificationResult, WatcherOps, WatcherSearchForSwapTxSpendInput, + WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WithdrawFut}; use common::executor::{AbortableSystem, AbortedError}; use common::log::warn; use derive_more::Display; @@ -1147,22 +1147,8 @@ impl MarketCoinOps for BchCoin { utxo_common::send_raw_tx_bytes(&self.utxo_arc, tx) } - fn wait_for_confirmations( - &self, - tx: &[u8], - confirmations: u64, - requires_nota: bool, - wait_until: u64, - check_every: u64, - ) -> Box + Send> { - utxo_common::wait_for_confirmations( - &self.utxo_arc, - tx, - confirmations, - requires_nota, - wait_until, - check_every, - ) + fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box + Send> { + utxo_common::wait_for_confirmations(&self.utxo_arc, input) } fn wait_for_htlc_tx_spend( diff --git a/mm2src/coins/utxo/qtum.rs b/mm2src/coins/utxo/qtum.rs index 657ecd56b9..8fa047cfa1 100644 --- a/mm2src/coins/utxo/qtum.rs +++ b/mm2src/coins/utxo/qtum.rs @@ -24,15 +24,16 @@ use crate::utxo::utxo_builder::{BlockHeaderUtxoArcOps, MergeUtxoArcOps, UtxoCoin UtxoFieldsWithHardwareWalletBuilder, UtxoFieldsWithIguanaSecretBuilder}; use crate::utxo::utxo_tx_history_v2::{UtxoMyAddressesHistoryError, UtxoTxDetailsError, UtxoTxDetailsParams, UtxoTxHistoryOps}; -use crate::{eth, CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinWithDerivationMethod, DelegationError, - DelegationFut, GetWithdrawSenderAddress, IguanaPrivKey, MakerSwapTakerCoin, NegotiateSwapContractAddrErr, - PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, RefundError, RefundPaymentArgs, - RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, - SignatureResult, SpendPaymentArgs, StakingInfosFut, SwapOps, TakerSwapMakerCoin, TradePreimageValue, - TransactionFut, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, - ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, - ValidatePaymentInput, VerificationResult, WatcherOps, WatcherSearchForSwapTxSpendInput, - WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WithdrawFut, WithdrawSenderAddress}; +use crate::{eth, CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinWithDerivationMethod, ConfirmPaymentInput, + DelegationError, DelegationFut, GetWithdrawSenderAddress, IguanaPrivKey, MakerSwapTakerCoin, + NegotiateSwapContractAddrErr, PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, + RefundError, RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, + SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureResult, SpendPaymentArgs, StakingInfosFut, + SwapOps, TakerSwapMakerCoin, TradePreimageValue, TransactionFut, TxMarshalingErr, + UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, + ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, + VerificationResult, WatcherOps, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, + WatcherValidateTakerFeeInput, WithdrawFut, WithdrawSenderAddress}; use common::executor::{AbortableSystem, AbortedError}; use crypto::Bip44Chain; use ethereum_types::H160; @@ -831,22 +832,8 @@ impl MarketCoinOps for QtumCoin { utxo_common::send_raw_tx_bytes(&self.utxo_arc, tx) } - fn wait_for_confirmations( - &self, - tx: &[u8], - confirmations: u64, - requires_nota: bool, - wait_until: u64, - check_every: u64, - ) -> Box + Send> { - utxo_common::wait_for_confirmations( - &self.utxo_arc, - tx, - confirmations, - requires_nota, - wait_until, - check_every, - ) + fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box + Send> { + utxo_common::wait_for_confirmations(&self.utxo_arc, input) } fn wait_for_htlc_tx_spend( diff --git a/mm2src/coins/utxo/slp.rs b/mm2src/coins/utxo/slp.rs index 8beef7c130..ef2903c280 100644 --- a/mm2src/coins/utxo/slp.rs +++ b/mm2src/coins/utxo/slp.rs @@ -13,17 +13,18 @@ use crate::utxo::utxo_common::{self, big_decimal_from_sat_unsigned, payment_scri use crate::utxo::{generate_and_send_tx, sat_from_big_decimal, ActualTxFee, AdditionalTxData, BroadcastTxErr, FeePolicy, GenerateTxError, RecentlySpentOutPointsGuard, UtxoCoinConf, UtxoCoinFields, UtxoCommonOps, UtxoTx, UtxoTxBroadcastOps, UtxoTxGenerationOps}; -use crate::{BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, CoinFutSpawner, FeeApproxStage, FoundSwapTxSpend, - HistorySyncState, MakerSwapTakerCoin, MarketCoinOps, MmCoin, NegotiateSwapContractAddrErr, - NumConversError, PaymentInstructions, PaymentInstructionsErr, PrivKeyPolicyNotAllowed, RawTransactionFut, - RawTransactionRequest, RefundError, RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, - SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureResult, SpendPaymentArgs, SwapOps, - TakerSwapMakerCoin, TradeFee, TradePreimageError, TradePreimageFut, TradePreimageResult, - TradePreimageValue, TransactionDetails, TransactionEnum, TransactionErr, TransactionFut, TxFeeDetails, - TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, - ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentInput, VerificationError, - VerificationResult, WatcherOps, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, - WatcherValidateTakerFeeInput, WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest}; +use crate::{BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, CoinFutSpawner, ConfirmPaymentInput, FeeApproxStage, + FoundSwapTxSpend, HistorySyncState, MakerSwapTakerCoin, MarketCoinOps, MmCoin, + NegotiateSwapContractAddrErr, NumConversError, PaymentInstructions, PaymentInstructionsErr, + PrivKeyPolicyNotAllowed, RawTransactionFut, RawTransactionRequest, RefundError, RefundPaymentArgs, + RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, + SignatureResult, SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, TradeFee, TradePreimageError, + TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionEnum, + TransactionErr, TransactionFut, TxFeeDetails, TxMarshalingErr, UnexpectedDerivationMethod, + ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, ValidateOtherPubKeyErr, + ValidatePaymentInput, VerificationError, VerificationResult, WatcherOps, WatcherSearchForSwapTxSpendInput, + WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WithdrawError, WithdrawFee, WithdrawFut, + WithdrawRequest}; use async_trait::async_trait; use bitcrypto::dhash160; use chain::constants::SEQUENCE_FINAL; @@ -1154,16 +1155,8 @@ impl MarketCoinOps for SlpToken { Box::new(fut.boxed().compat()) } - fn wait_for_confirmations( - &self, - tx: &[u8], - confirmations: u64, - requires_nota: bool, - wait_until: u64, - check_every: u64, - ) -> Box + Send> { - self.platform_coin - .wait_for_confirmations(tx, confirmations, requires_nota, wait_until, check_every) + fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box + Send> { + self.platform_coin.wait_for_confirmations(input) } fn wait_for_htlc_tx_spend( diff --git a/mm2src/coins/utxo/utxo_common.rs b/mm2src/coins/utxo/utxo_common.rs index 1323a2a349..5709002ec2 100644 --- a/mm2src/coins/utxo/utxo_common.rs +++ b/mm2src/coins/utxo/utxo_common.rs @@ -12,8 +12,8 @@ use crate::utxo::rpc_clients::{electrum_script_hash, BlockHashOrHeight, UnspentI use crate::utxo::spv::SimplePaymentVerification; use crate::utxo::tx_cache::TxCacheResult; use crate::utxo::utxo_withdraw::{InitUtxoWithdraw, StandardUtxoWithdraw, UtxoWithdraw}; -use crate::{CanRefundHtlc, CoinBalance, CoinWithDerivationMethod, GetWithdrawSenderAddress, HDAccountAddressId, - RawTransactionError, RawTransactionRequest, RawTransactionRes, RefundPaymentArgs, +use crate::{CanRefundHtlc, CoinBalance, CoinWithDerivationMethod, ConfirmPaymentInput, GetWithdrawSenderAddress, + HDAccountAddressId, RawTransactionError, RawTransactionRequest, RawTransactionRes, RefundPaymentArgs, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureError, SignatureResult, SpendPaymentArgs, SwapOps, TradePreimageValue, TransactionFut, TxFeeDetails, TxMarshalingErr, ValidateAddressResult, ValidateOtherPubKeyErr, ValidatePaymentFut, ValidatePaymentInput, @@ -2323,21 +2323,17 @@ pub fn send_raw_tx_bytes( pub fn wait_for_confirmations( coin: &UtxoCoinFields, - tx: &[u8], - confirmations: u64, - requires_nota: bool, - wait_until: u64, - check_every: u64, + input: ConfirmPaymentInput, ) -> Box + Send> { - let mut tx: UtxoTx = try_fus!(deserialize(tx).map_err(|e| ERRL!("{:?}", e))); + let mut tx: UtxoTx = try_fus!(deserialize(input.payment_tx.as_slice()).map_err(|e| ERRL!("{:?}", e))); tx.tx_hash_algo = coin.tx_hash_algo; coin.rpc_client.wait_for_confirmations( tx.hash().reversed().into(), tx.expiry_height, - confirmations as u32, - requires_nota, - wait_until, - check_every, + input.confirmations as u32, + input.requires_nota, + input.wait_until, + input.check_every, ) } diff --git a/mm2src/coins/utxo/utxo_standard.rs b/mm2src/coins/utxo/utxo_standard.rs index b3f5168b0c..b21b2fda80 100644 --- a/mm2src/coins/utxo/utxo_standard.rs +++ b/mm2src/coins/utxo/utxo_standard.rs @@ -22,12 +22,12 @@ use crate::tx_history_storage::{GetTxHistoryFilters, WalletId}; use crate::utxo::utxo_builder::{UtxoArcBuilder, UtxoCoinBuilder}; use crate::utxo::utxo_tx_history_v2::{UtxoMyAddressesHistoryError, UtxoTxDetailsError, UtxoTxDetailsParams, UtxoTxHistoryOps}; -use crate::{CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinWithDerivationMethod, GetWithdrawSenderAddress, - IguanaPrivKey, MakerSwapTakerCoin, NegotiateSwapContractAddrErr, PaymentInstructions, - PaymentInstructionsErr, PrivKeyBuildPolicy, RefundError, RefundPaymentArgs, RefundResult, - SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignatureResult, - SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, TradePreimageValue, TransactionFut, TxMarshalingErr, - ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, ValidateOtherPubKeyErr, +use crate::{CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinWithDerivationMethod, ConfirmPaymentInput, + GetWithdrawSenderAddress, IguanaPrivKey, MakerSwapTakerCoin, NegotiateSwapContractAddrErr, + PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, RefundError, RefundPaymentArgs, + RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, + SignatureResult, SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, TradePreimageValue, TransactionFut, + TxMarshalingErr, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, VerificationResult, WatcherOps, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WithdrawFut, WithdrawSenderAddress}; @@ -596,22 +596,8 @@ impl MarketCoinOps for UtxoStandardCoin { utxo_common::send_raw_tx_bytes(&self.utxo_arc, tx) } - fn wait_for_confirmations( - &self, - tx: &[u8], - confirmations: u64, - requires_nota: bool, - wait_until: u64, - check_every: u64, - ) -> Box + Send> { - utxo_common::wait_for_confirmations( - &self.utxo_arc, - tx, - confirmations, - requires_nota, - wait_until, - check_every, - ) + fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box + Send> { + utxo_common::wait_for_confirmations(&self.utxo_arc, input) } fn wait_for_htlc_tx_spend( diff --git a/mm2src/coins/utxo/utxo_tests.rs b/mm2src/coins/utxo/utxo_tests.rs index ae54d5fd57..bd2a901dcd 100644 --- a/mm2src/coins/utxo/utxo_tests.rs +++ b/mm2src/coins/utxo/utxo_tests.rs @@ -28,10 +28,10 @@ use crate::utxo::utxo_common_tests::{self, utxo_coin_fields_for_test, utxo_coin_ use crate::utxo::utxo_standard::{utxo_standard_coin_with_priv_key, UtxoStandardCoin}; use crate::utxo::utxo_tx_history_v2::{UtxoTxDetailsParams, UtxoTxHistoryOps}; #[cfg(not(target_arch = "wasm32"))] use crate::WithdrawFee; -use crate::INVALID_SENDER_ERR_LOG; use crate::{BlockHeightAndTime, CoinBalance, IguanaPrivKey, PrivKeyBuildPolicy, SearchForSwapTxSpendInput, SpendPaymentArgs, StakingInfosDetails, SwapOps, TradePreimageValue, TxFeeDetails, TxMarshalingErr, ValidateFeeArgs}; +use crate::{ConfirmPaymentInput, INVALID_SENDER_ERR_LOG}; use chain::{BlockHeader, BlockHeaderBits, OutPoint}; use common::executor::Timer; use common::{block_on, now_ms, OrdRange, PagingOptionsEnum, DEX_FEE_ADDR_RAW_PUBKEY}; @@ -4135,11 +4135,14 @@ fn test_for_non_existent_tx_hex_utxo_electrum() { ); // bad transaction hex let tx = hex::decode("0400008085202f8902bf17bf7d1daace52e08f732a6b8771743ca4b1cb765a187e72fd091a0aabfd52000000006a47304402203eaaa3c4da101240f80f9c5e9de716a22b1ec6d66080de6a0cca32011cd77223022040d9082b6242d6acf9a1a8e658779e1c655d708379862f235e8ba7b8ca4e69c6012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffffff023ca13c0e9e085dd13f481f193e8a3e8fd609020936e98b5587342d994f4d020000006b483045022100c0ba56adb8de923975052312467347d83238bd8d480ce66e8b709a7997373994022048507bcac921fdb2302fa5224ce86e41b7efc1a2e20ae63aa738dfa99b7be826012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffff0300e1f5050000000017a9141ee6d4c38a3c078eab87ad1a5e4b00f21259b10d87000000000000000016611400000000000000000000000000000000000000001b94d736000000001976a91405aab5342166f8594baf17a7d9bef5d56744332788ac2d08e35e000000000000000000000000000000").unwrap(); - let actual = coin - .wait_for_confirmations(&tx, 1, false, timeout, 1) - .wait() - .err() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx, + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + let actual = coin.wait_for_confirmations(confirm_payment_input).wait().err().unwrap(); assert!(actual.contains( "Tx d342ff9da528a2e262bddf2b6f9a27d1beb7aeb03f0fc8d9eac2987266447e44 was not found on chain after 10 tries" )); diff --git a/mm2src/coins/z_coin.rs b/mm2src/coins/z_coin.rs index 7d19ae13ee..416b6292c1 100644 --- a/mm2src/coins/z_coin.rs +++ b/mm2src/coins/z_coin.rs @@ -13,8 +13,8 @@ use crate::utxo::{sat_from_big_decimal, utxo_common, ActualTxFee, AdditionalTxDa RecentlySpentOutPointsGuard, UtxoActivationParams, UtxoAddressFormat, UtxoArc, UtxoCoinFields, UtxoCommonOps, UtxoFeeDetails, UtxoRpcMode, UtxoTxBroadcastOps, UtxoTxGenerationOps, VerboseTransactionFrom}; -use crate::{BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, CoinFutSpawner, FeeApproxStage, - FoundSwapTxSpend, HistorySyncState, MakerSwapTakerCoin, MarketCoinOps, MmCoin, +use crate::{BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, CoinFutSpawner, ConfirmPaymentInput, + FeeApproxStage, FoundSwapTxSpend, HistorySyncState, MakerSwapTakerCoin, MarketCoinOps, MmCoin, NegotiateSwapContractAddrErr, NumConversError, PaymentInstructions, PaymentInstructionsErr, PrivKeyActivationPolicy, PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, RawTransactionFut, RawTransactionRequest, RefundError, RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, @@ -1047,15 +1047,8 @@ impl MarketCoinOps for ZCoin { Box::new(fut.boxed().compat()) } - fn wait_for_confirmations( - &self, - tx: &[u8], - confirmations: u64, - requires_nota: bool, - wait_until: u64, - check_every: u64, - ) -> Box + Send> { - utxo_common::wait_for_confirmations(self.as_ref(), tx, confirmations, requires_nota, wait_until, check_every) + fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box + Send> { + utxo_common::wait_for_confirmations(self.as_ref(), input) } fn wait_for_htlc_tx_spend( diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap.rs b/mm2src/mm2_main/src/lp_swap/maker_swap.rs index 0cd8affc40..ae1d8e7af2 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap.rs @@ -16,8 +16,8 @@ use crate::mm2::lp_ordermatch::{MakerOrderBuilder, OrderConfirmationsSettings}; use crate::mm2::lp_price::fetch_swap_coins_price; use crate::mm2::lp_swap::{broadcast_swap_message, min_watcher_reward, taker_payment_spend_duration, watcher_reward_amount}; -use coins::{CanRefundHtlc, CheckIfMyPaymentSentArgs, FeeApproxStage, FoundSwapTxSpend, MmCoinEnum, - PaymentInstructions, PaymentInstructionsErr, RefundPaymentArgs, SearchForSwapTxSpendInput, +use coins::{CanRefundHtlc, CheckIfMyPaymentSentArgs, ConfirmPaymentInput, FeeApproxStage, FoundSwapTxSpend, + MmCoinEnum, PaymentInstructions, PaymentInstructionsErr, RefundPaymentArgs, SearchForSwapTxSpendInput, SendPaymentArgs, SpendPaymentArgs, TradeFee, TradePreimageValue, TransactionEnum, ValidateFeeArgs, ValidatePaymentInput}; use common::log::{debug, error, info, warn}; @@ -893,13 +893,15 @@ impl MakerSwap { let maker_payment_wait_confirm = wait_for_maker_payment_conf_until(self.r().data.started_at, self.r().data.lock_duration); - let f = self.maker_coin.wait_for_confirmations( - &self.r().maker_payment.clone().unwrap().tx_hex, - self.r().data.maker_payment_confirmations, - self.r().data.maker_payment_requires_nota.unwrap_or(false), - maker_payment_wait_confirm, - WAIT_CONFIRM_INTERVAL, - ); + let confirm_maker_payment_input = ConfirmPaymentInput { + payment_tx: self.r().maker_payment.clone().unwrap().tx_hex.0, + confirmations: self.r().data.maker_payment_confirmations, + requires_nota: self.r().data.maker_payment_requires_nota.unwrap_or(false), + wait_until: maker_payment_wait_confirm, + check_every: WAIT_CONFIRM_INTERVAL, + }; + + let f = self.maker_coin.wait_for_confirmations(confirm_maker_payment_input); if let Err(err) = f.compat().await { return Ok((Some(MakerSwapCommand::PrepareForMakerPaymentRefund), vec![ MakerSwapEvent::MakerPaymentWaitConfirmFailed( @@ -963,16 +965,18 @@ impl MakerSwap { async fn validate_taker_payment(&self) -> Result<(Option, Vec), String> { let wait_taker_payment = taker_payment_spend_deadline(self.r().data.started_at, self.r().data.lock_duration); let confirmations = self.r().data.taker_payment_confirmations; + let taker_coin_swap_contract_address = self.r().data.taker_coin_swap_contract_address.clone(); + let confirm_taker_payment_input = ConfirmPaymentInput { + payment_tx: self.r().taker_payment.clone().unwrap().tx_hex.0, + confirmations, + requires_nota: self.r().data.taker_payment_requires_nota.unwrap_or(false), + wait_until: wait_taker_payment, + check_every: WAIT_CONFIRM_INTERVAL, + }; let wait_f = self .taker_coin - .wait_for_confirmations( - &self.r().taker_payment.clone().unwrap().tx_hex, - confirmations, - self.r().data.taker_payment_requires_nota.unwrap_or(false), - wait_taker_payment, - WAIT_CONFIRM_INTERVAL, - ) + .wait_for_confirmations(confirm_taker_payment_input) .compat(); if let Err(err) = wait_f.await { return Ok((Some(MakerSwapCommand::PrepareForMakerPaymentRefund), vec![ @@ -1007,7 +1011,7 @@ impl MakerSwap { unique_swap_data: self.unique_swap_data(), secret_hash: self.secret_hash(), amount: self.taker_amount.clone(), - swap_contract_address: self.r().data.taker_coin_swap_contract_address.clone(), + swap_contract_address: taker_coin_swap_contract_address, try_spv_proof_until: wait_taker_payment, confirmations, min_watcher_reward, @@ -1110,13 +1114,14 @@ impl MakerSwap { // we should wait for only one confirmation to make sure our spend transaction is not failed let confirmations = std::cmp::min(1, self.r().data.taker_payment_confirmations); let requires_nota = false; - let wait_fut = self.taker_coin.wait_for_confirmations( - &self.r().taker_payment_spend.clone().unwrap().tx_hex, + let confirm_taker_payment_input = ConfirmPaymentInput { + payment_tx: self.r().taker_payment.clone().unwrap().tx_hex.0, confirmations, requires_nota, - self.wait_refund_until(), - WAIT_CONFIRM_INTERVAL, - ); + wait_until: self.wait_refund_until(), + check_every: WAIT_CONFIRM_INTERVAL, + }; + let wait_fut = self.taker_coin.wait_for_confirmations(confirm_taker_payment_input); if let Err(err) = wait_fut.compat().await { return Ok((Some(MakerSwapCommand::PrepareForMakerPaymentRefund), vec![ MakerSwapEvent::TakerPaymentSpendConfirmFailed( diff --git a/mm2src/mm2_main/src/lp_swap/swap_watcher.rs b/mm2src/mm2_main/src/lp_swap/swap_watcher.rs index 09b42f2863..7441a4a855 100644 --- a/mm2src/mm2_main/src/lp_swap/swap_watcher.rs +++ b/mm2src/mm2_main/src/lp_swap/swap_watcher.rs @@ -2,8 +2,9 @@ use super::{broadcast_p2p_tx_msg, get_payment_locktime, lp_coinfind, min_watcher tx_helper_topic, H256Json, SwapsContext, WAIT_CONFIRM_INTERVAL}; use crate::mm2::MmError; use async_trait::async_trait; -use coins::{CanRefundHtlc, FoundSwapTxSpend, MmCoinEnum, RefundPaymentArgs, SendMakerPaymentSpendPreimageInput, - WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, WatcherValidateTakerFeeInput}; +use coins::{CanRefundHtlc, ConfirmPaymentInput, FoundSwapTxSpend, MmCoinEnum, RefundPaymentArgs, + SendMakerPaymentSpendPreimageInput, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, + WatcherValidateTakerFeeInput}; use common::executor::{AbortSettings, SpawnAbortable, Timer}; use common::log::{debug, error, info}; use common::state_machine::prelude::*; @@ -216,16 +217,17 @@ impl State for ValidateTakerPayment { }; let confirmations = min(watcher_ctx.data.taker_payment_confirmations, TAKER_SWAP_CONFIRMATIONS); + let confirm_taker_payment_input = ConfirmPaymentInput { + payment_tx: taker_payment_hex.clone(), + confirmations, + requires_nota: watcher_ctx.data.taker_payment_requires_nota.unwrap_or(false), + wait_until: taker_payment_spend_deadline, + check_every: WAIT_CONFIRM_INTERVAL, + }; let wait_fut = watcher_ctx .taker_coin - .wait_for_confirmations( - &taker_payment_hex, - confirmations, - watcher_ctx.data.taker_payment_requires_nota.unwrap_or(false), - taker_payment_spend_deadline, - WAIT_CONFIRM_INTERVAL, - ) + .wait_for_confirmations(confirm_taker_payment_input) .compat(); if let Err(err) = wait_fut.await { return Self::change_state(Stopped::from_reason(StopReason::Error( diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap.rs b/mm2src/mm2_main/src/lp_swap/taker_swap.rs index f2bc7e0cb6..1a41f1128b 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap.rs @@ -15,9 +15,10 @@ use crate::mm2::lp_ordermatch::{MatchBy, OrderConfirmationsSettings, TakerAction use crate::mm2::lp_price::fetch_swap_coins_price; use crate::mm2::lp_swap::{broadcast_p2p_tx_msg, min_watcher_reward, tx_helper_topic, wait_for_maker_payment_conf_duration, watcher_reward_amount, TakerSwapWatcherData}; -use coins::{lp_coinfind, CanRefundHtlc, CheckIfMyPaymentSentArgs, FeeApproxStage, FoundSwapTxSpend, MmCoinEnum, - PaymentInstructions, PaymentInstructionsErr, RefundPaymentArgs, SearchForSwapTxSpendInput, - SendPaymentArgs, SpendPaymentArgs, TradeFee, TradePreimageValue, ValidatePaymentInput}; +use coins::{lp_coinfind, CanRefundHtlc, CheckIfMyPaymentSentArgs, ConfirmPaymentInput, FeeApproxStage, + FoundSwapTxSpend, MmCoinEnum, PaymentInstructions, PaymentInstructionsErr, RefundPaymentArgs, + SearchForSwapTxSpendInput, SendPaymentArgs, SpendPaymentArgs, TradeFee, TradePreimageValue, + ValidatePaymentInput}; use common::executor::Timer; use common::log::{debug, error, info, warn}; use common::{bits256, now_ms, DEX_FEE_ADDR_RAW_PUBKEY}; @@ -1338,13 +1339,15 @@ impl TakerSwap { async fn validate_maker_payment(&self) -> Result<(Option, Vec), String> { info!("Before wait confirm"); let confirmations = self.r().data.maker_payment_confirmations; - let f = self.maker_coin.wait_for_confirmations( - &self.r().maker_payment.clone().unwrap().tx_hex, + let confirm_maker_payment_input = ConfirmPaymentInput { + payment_tx: self.r().maker_payment.clone().unwrap().tx_hex.0, confirmations, - self.r().data.maker_payment_requires_nota.unwrap_or(false), - self.r().data.maker_payment_wait, - WAIT_CONFIRM_INTERVAL, - ); + requires_nota: self.r().data.maker_payment_requires_nota.unwrap_or(false), + wait_until: self.r().data.maker_payment_wait, + check_every: WAIT_CONFIRM_INTERVAL, + }; + + let f = self.maker_coin.wait_for_confirmations(confirm_maker_payment_input); if let Err(err) = f.compat().await { return Ok((Some(TakerSwapCommand::Finish), vec![ TakerSwapEvent::MakerPaymentWaitConfirmFailed( @@ -1614,15 +1617,16 @@ impl TakerSwap { self.p2p_privkey, ); + let confirm_taker_payment_input = ConfirmPaymentInput { + payment_tx: self.r().taker_payment.clone().unwrap().tx_hex.0, + confirmations: self.r().data.taker_payment_confirmations, + requires_nota: self.r().data.taker_payment_requires_nota.unwrap_or(false), + wait_until: self.r().data.taker_payment_lock, + check_every: WAIT_CONFIRM_INTERVAL, + }; let wait_f = self .taker_coin - .wait_for_confirmations( - &self.r().taker_payment.clone().unwrap().tx_hex, - self.r().data.taker_payment_confirmations, - self.r().data.taker_payment_requires_nota.unwrap_or(false), - self.r().data.taker_payment_lock, - WAIT_CONFIRM_INTERVAL, - ) + .wait_for_confirmations(confirm_taker_payment_input) .compat(); if let Err(err) = wait_f.await { return Ok((Some(TakerSwapCommand::PrepareForTakerPaymentRefund), vec![ diff --git a/mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs b/mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs index fe4145e002..40a6514c88 100644 --- a/mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs +++ b/mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs @@ -22,7 +22,7 @@ use coins::utxo::utxo_common::send_outputs_from_my_address; use coins::utxo::utxo_standard::{utxo_standard_coin_with_priv_key, UtxoStandardCoin}; use coins::utxo::{coin_daemon_data_dir, sat_from_big_decimal, zcash_params_path, UtxoActivationParams, UtxoAddressFormat, UtxoCoinFields, UtxoCommonOps}; -use coins::{CoinProtocol, MarketCoinOps, PrivKeyBuildPolicy, Transaction}; +use coins::{CoinProtocol, ConfirmPaymentInput, MarketCoinOps, PrivKeyBuildPolicy, Transaction}; use crypto::privkey::key_pair_from_seed; use crypto::Secp256k1Secret; use ethereum_types::H160 as H160Eth; @@ -277,10 +277,14 @@ impl BchDockerOps { let slp_genesis_tx = send_outputs_from_my_address(self.coin.clone(), bch_outputs) .wait() .unwrap(); - self.coin - .wait_for_confirmations(&slp_genesis_tx.tx_hex(), 1, false, now_ms() / 1000 + 30, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: slp_genesis_tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: now_ms() / 1000 + 30, + check_every: 1, + }; + self.coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let adex_slp = SlpToken::new( 8, @@ -292,10 +296,14 @@ impl BchDockerOps { .unwrap(); let tx = block_on(adex_slp.send_slp_outputs(slp_outputs)).unwrap(); - self.coin - .wait_for_confirmations(&tx.tx_hex(), 1, false, now_ms() / 1000 + 30, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: now_ms() / 1000 + 30, + check_every: 1, + }; + self.coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); *SLP_TOKEN_OWNERS.lock().unwrap() = slp_privkeys; *SLP_TOKEN_ID.lock().unwrap() = slp_genesis_tx.tx_hash().as_slice().into(); } @@ -552,9 +560,14 @@ pub fn fill_qrc20_address(coin: &Qrc20Coin, amount: BigDecimal, timeout: u64) { let tx_bytes = client.get_transaction_bytes(&hash).wait().unwrap(); log!("{:02x}", tx_bytes); - coin.wait_for_confirmations(&tx_bytes, 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx_bytes.clone().0, + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); } /// Generate random privkey, create a QRC20 coin and fill it's address with the specified balance. @@ -665,9 +678,14 @@ where client.import_address(address, address, false).wait().unwrap(); let hash = client.send_to_address(address, &amount).wait().unwrap(); let tx_bytes = client.get_transaction_bytes(&hash).wait().unwrap(); - coin.wait_for_confirmations(&tx_bytes, 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx_bytes.clone().0, + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); log!("{:02x}", tx_bytes); loop { let unspents = client 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 c89f99528a..f6afbf7d1c 100644 --- a/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs +++ b/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs @@ -5,8 +5,8 @@ use bitcrypto::dhash160; use chain::OutPoint; use coins::utxo::rpc_clients::UnspentInfo; use coins::utxo::{GetUtxoListOps, UtxoCommonOps}; -use coins::{FoundSwapTxSpend, MarketCoinOps, MmCoin, RefundPaymentArgs, SearchForSwapTxSpendInput, SendPaymentArgs, - SpendPaymentArgs, SwapOps, TransactionEnum, WithdrawRequest}; +use coins::{ConfirmPaymentInput, FoundSwapTxSpend, MarketCoinOps, MmCoin, RefundPaymentArgs, + SearchForSwapTxSpendInput, SendPaymentArgs, SpendPaymentArgs, SwapOps, TransactionEnum, WithdrawRequest}; use common::{block_on, now_ms}; use futures01::Future; use mm2_number::{BigDecimal, MmNumber}; @@ -41,9 +41,14 @@ fn test_search_for_swap_tx_spend_native_was_refunded_taker() { }; let tx = coin.send_taker_payment(taker_payment_args).wait().unwrap(); - coin.wait_for_confirmations(&tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let maker_refunds_payment_args = RefundPaymentArgs { payment_tx: &tx.tx_hex(), time_lock, @@ -58,9 +63,14 @@ fn test_search_for_swap_tx_spend_native_was_refunded_taker() { .wait() .unwrap(); - coin.wait_for_confirmations(&refund_tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: refund_tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let search_input = SearchForSwapTxSpendInput { time_lock, @@ -85,11 +95,14 @@ fn test_for_non_existent_tx_hex_utxo() { let (_ctx, coin, _) = generate_utxo_coin_with_random_privkey("MYCOIN", 1000u64.into()); // bad transaction hex let tx = hex::decode("0400008085202f8902bf17bf7d1daace52e08f732a6b8771743ca4b1cb765a187e72fd091a0aabfd52000000006a47304402203eaaa3c4da101240f80f9c5e9de716a22b1ec6d66080de6a0cca32011cd77223022040d9082b6242d6acf9a1a8e658779e1c655d708379862f235e8ba7b8ca4e69c6012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffffff023ca13c0e9e085dd13f481f193e8a3e8fd609020936e98b5587342d994f4d020000006b483045022100c0ba56adb8de923975052312467347d83238bd8d480ce66e8b709a7997373994022048507bcac921fdb2302fa5224ce86e41b7efc1a2e20ae63aa738dfa99b7be826012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffff0300e1f5050000000017a9141ee6d4c38a3c078eab87ad1a5e4b00f21259b10d87000000000000000016611400000000000000000000000000000000000000001b94d736000000001976a91405aab5342166f8594baf17a7d9bef5d56744332788ac2d08e35e000000000000000000000000000000").unwrap(); - let actual = coin - .wait_for_confirmations(&tx, 1, false, timeout, 1) - .wait() - .err() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx, + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + let actual = coin.wait_for_confirmations(confirm_payment_input).wait().err().unwrap(); assert!(actual.contains( "Tx d342ff9da528a2e262bddf2b6f9a27d1beb7aeb03f0fc8d9eac2987266447e44 was not found on chain after 10 tries" )); @@ -116,9 +129,14 @@ fn test_search_for_swap_tx_spend_native_was_refunded_maker() { }; let tx = coin.send_maker_payment(maker_payment_args).wait().unwrap(); - coin.wait_for_confirmations(&tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let maker_refunds_payment_args = RefundPaymentArgs { payment_tx: &tx.tx_hex(), time_lock, @@ -133,9 +151,14 @@ fn test_search_for_swap_tx_spend_native_was_refunded_maker() { .wait() .unwrap(); - coin.wait_for_confirmations(&refund_tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: refund_tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let search_input = SearchForSwapTxSpendInput { time_lock, @@ -176,9 +199,14 @@ fn test_search_for_taker_swap_tx_spend_native_was_spent_by_maker() { }; let tx = coin.send_taker_payment(taker_payment_args).wait().unwrap(); - coin.wait_for_confirmations(&tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let maker_spends_payment_args = SpendPaymentArgs { other_payment_tx: &tx.tx_hex(), time_lock, @@ -194,9 +222,14 @@ fn test_search_for_taker_swap_tx_spend_native_was_spent_by_maker() { .wait() .unwrap(); - coin.wait_for_confirmations(&spend_tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: spend_tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let search_input = SearchForSwapTxSpendInput { time_lock, @@ -237,9 +270,14 @@ fn test_search_for_maker_swap_tx_spend_native_was_spent_by_taker() { }; let tx = coin.send_maker_payment(maker_payment_args).wait().unwrap(); - coin.wait_for_confirmations(&tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let taker_spends_payment_args = SpendPaymentArgs { other_payment_tx: &tx.tx_hex(), time_lock, @@ -255,9 +293,14 @@ fn test_search_for_maker_swap_tx_spend_native_was_spent_by_taker() { .wait() .unwrap(); - coin.wait_for_confirmations(&spend_tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: spend_tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let search_input = SearchForSwapTxSpendInput { time_lock, @@ -2430,9 +2473,14 @@ fn test_maker_order_should_not_kick_start_and_appear_in_orderbook_if_balance_is_ .wait() .unwrap(); coin.send_raw_tx(&hex::encode(&withdraw.tx_hex.0)).wait().unwrap(); - coin.wait_for_confirmations(&withdraw.tx_hex.0, 1, false, (now_ms() / 1000) + 10, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: withdraw.tx_hex.0, + confirmations: 1, + requires_nota: false, + wait_until: (now_ms() / 1000) + 10, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let mm_bob_dup = MarketMakerIt::start(bob_conf, "pass".to_string(), None).unwrap(); let (_bob_dup_dump_log, _bob_dup_dump_dashboard) = mm_dump(&mm_bob_dup.log_path); diff --git a/mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs b/mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs index 6353005c9a..3601baa886 100644 --- a/mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs @@ -6,9 +6,9 @@ use coins::utxo::qtum::{qtum_coin_with_priv_key, QtumCoin}; use coins::utxo::rpc_clients::UtxoRpcClientEnum; use coins::utxo::utxo_common::big_decimal_from_sat; use coins::utxo::{UtxoActivationParams, UtxoCommonOps}; -use coins::{CheckIfMyPaymentSentArgs, FeeApproxStage, FoundSwapTxSpend, MarketCoinOps, MmCoin, RefundPaymentArgs, - SearchForSwapTxSpendInput, SendPaymentArgs, SpendPaymentArgs, SwapOps, TradePreimageValue, - TransactionEnum, ValidatePaymentInput}; +use coins::{CheckIfMyPaymentSentArgs, ConfirmPaymentInput, FeeApproxStage, FoundSwapTxSpend, MarketCoinOps, MmCoin, + RefundPaymentArgs, SearchForSwapTxSpendInput, SendPaymentArgs, SpendPaymentArgs, SwapOps, + TradePreimageValue, TransactionEnum, ValidatePaymentInput}; use common::log::debug; use common::{temp_dir, DEX_FEE_ADDR_RAW_PUBKEY}; use crypto::Secp256k1Secret; @@ -202,10 +202,14 @@ fn test_taker_spends_maker_payment() { let requires_nota = false; let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run let check_every = 1; - taker_coin - .wait_for_confirmations(&payment_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: payment_tx_hex.clone(), + confirmations, + requires_nota, + wait_until, + check_every, + }; + taker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let input = ValidatePaymentInput { payment_tx: payment_tx_hex.clone(), @@ -240,10 +244,14 @@ fn test_taker_spends_maker_payment() { log!("Taker spends tx: {:?}", spend_tx_hash); let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run - taker_coin - .wait_for_confirmations(&spend_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: spend_tx_hex, + confirmations, + requires_nota, + wait_until, + check_every, + }; + taker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let maker_balance = maker_coin .my_spendable_balance() @@ -299,10 +307,14 @@ fn test_maker_spends_taker_payment() { let requires_nota = false; let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run let check_every = 1; - maker_coin - .wait_for_confirmations(&payment_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: payment_tx_hex.clone(), + confirmations, + requires_nota, + wait_until, + check_every, + }; + maker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let input = ValidatePaymentInput { payment_tx: payment_tx_hex.clone(), @@ -337,10 +349,14 @@ fn test_maker_spends_taker_payment() { log!("Maker spends tx: {:?}", spend_tx_hash); let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run - maker_coin - .wait_for_confirmations(&spend_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: spend_tx_hex, + confirmations, + requires_nota, + wait_until, + check_every, + }; + maker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let maker_balance = maker_coin .my_spendable_balance() @@ -385,9 +401,14 @@ fn test_maker_refunds_payment() { let requires_nota = false; let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run let check_every = 1; - coin.wait_for_confirmations(&payment_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: payment_tx_hex.clone(), + confirmations, + requires_nota, + wait_until, + check_every, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let balance_after_payment = coin.my_spendable_balance().wait().unwrap(); assert_eq!(expected_balance.clone() - amount, balance_after_payment); @@ -409,9 +430,14 @@ fn test_maker_refunds_payment() { log!("Maker refunds payment: {:?}", refund_tx_hash); let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run - coin.wait_for_confirmations(&refund_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: refund_tx_hex, + confirmations, + requires_nota, + wait_until, + check_every, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let balance_after_refund = coin.my_spendable_balance().wait().unwrap(); assert_eq!(expected_balance, balance_after_refund); @@ -448,9 +474,14 @@ fn test_taker_refunds_payment() { let requires_nota = false; let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run let check_every = 1; - coin.wait_for_confirmations(&payment_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: payment_tx_hex.clone(), + confirmations, + requires_nota, + wait_until, + check_every, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let balance_after_payment = coin.my_spendable_balance().wait().unwrap(); assert_eq!(expected_balance.clone() - amount, balance_after_payment); @@ -472,9 +503,14 @@ fn test_taker_refunds_payment() { log!("Taker refunds payment: {:?}", refund_tx_hash); let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run - coin.wait_for_confirmations(&refund_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: refund_tx_hex, + confirmations, + requires_nota, + wait_until, + check_every, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let balance_after_refund = coin.my_spendable_balance().wait().unwrap(); assert_eq!(expected_balance, balance_after_refund); @@ -508,9 +544,14 @@ fn test_check_if_my_payment_sent() { let requires_nota = false; let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run let check_every = 1; - coin.wait_for_confirmations(&payment_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: payment_tx_hex, + confirmations, + requires_nota, + wait_until, + check_every, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let search_from_block = coin.current_block().wait().expect("!current_block") - 10; let if_my_payment_sent_args = CheckIfMyPaymentSentArgs { @@ -560,10 +601,14 @@ fn test_search_for_swap_tx_spend_taker_spent() { let requires_nota = false; let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run let check_every = 1; - taker_coin - .wait_for_confirmations(&payment_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: payment_tx_hex.clone(), + confirmations, + requires_nota, + wait_until, + check_every, + }; + taker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let taker_spends_payment_args = SpendPaymentArgs { other_payment_tx: &payment_tx_hex, time_lock: timelock, @@ -583,10 +628,14 @@ fn test_search_for_swap_tx_spend_taker_spent() { log!("Taker spends tx: {:?}", spend_tx_hash); let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run - taker_coin - .wait_for_confirmations(&spend_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: spend_tx_hex, + confirmations, + requires_nota, + wait_until, + check_every, + }; + taker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let search_input = SearchForSwapTxSpendInput { time_lock: timelock, @@ -634,10 +683,14 @@ fn test_search_for_swap_tx_spend_maker_refunded() { let requires_nota = false; let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run let check_every = 1; - maker_coin - .wait_for_confirmations(&payment_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: payment_tx_hex.clone(), + confirmations, + requires_nota, + wait_until, + check_every, + }; + maker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let maker_refunds_payment_args = RefundPaymentArgs { payment_tx: &payment_tx_hex, time_lock: timelock, @@ -656,10 +709,14 @@ fn test_search_for_swap_tx_spend_maker_refunded() { log!("Maker refunds tx: {:?}", refund_tx_hash); let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run - maker_coin - .wait_for_confirmations(&refund_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: refund_tx_hex, + confirmations, + requires_nota, + wait_until, + check_every, + }; + maker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let search_input = SearchForSwapTxSpendInput { time_lock: timelock, @@ -707,10 +764,14 @@ fn test_search_for_swap_tx_spend_not_spent() { let requires_nota = false; let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run let check_every = 1; - maker_coin - .wait_for_confirmations(&payment_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: payment_tx_hex.clone(), + confirmations, + requires_nota, + wait_until, + check_every, + }; + maker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let search_input = SearchForSwapTxSpendInput { time_lock: timelock, @@ -760,10 +821,14 @@ fn test_wait_for_tx_spend() { let requires_nota = false; let wait_until = (now_ms() / 1000) + 40; // timeout if test takes more than 40 seconds to run let check_every = 1; - taker_coin - .wait_for_confirmations(&payment_tx_hex, confirmations, requires_nota, wait_until, check_every) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: payment_tx_hex.clone(), + confirmations, + requires_nota, + wait_until, + check_every, + }; + taker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); // first try to check if the wait_for_htlc_tx_spend() returns an error correctly let wait_until = (now_ms() / 1000) + 5; @@ -1471,9 +1536,14 @@ fn test_search_for_segwit_swap_tx_spend_native_was_refunded_maker() { }; let tx = coin.send_maker_payment(maker_payment).wait().unwrap(); - coin.wait_for_confirmations(&tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let maker_refunds_payment_args = RefundPaymentArgs { payment_tx: &tx.tx_hex(), time_lock, @@ -1488,9 +1558,14 @@ fn test_search_for_segwit_swap_tx_spend_native_was_refunded_maker() { .wait() .unwrap(); - coin.wait_for_confirmations(&refund_tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: refund_tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let search_input = SearchForSwapTxSpendInput { time_lock, @@ -1530,9 +1605,14 @@ fn test_search_for_segwit_swap_tx_spend_native_was_refunded_taker() { }; let tx = coin.send_taker_payment(taker_payment).wait().unwrap(); - coin.wait_for_confirmations(&tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let maker_refunds_payment_args = RefundPaymentArgs { payment_tx: &tx.tx_hex(), time_lock, @@ -1547,9 +1627,14 @@ fn test_search_for_segwit_swap_tx_spend_native_was_refunded_taker() { .wait() .unwrap(); - coin.wait_for_confirmations(&refund_tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: refund_tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let search_input = SearchForSwapTxSpendInput { time_lock, 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 af4156efcc..1f7b713808 100644 --- a/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs @@ -4,11 +4,12 @@ use crate::{generate_utxo_coin_with_privkey, generate_utxo_coin_with_random_priv SecretKey}; use coins::coin_errors::ValidatePaymentError; use coins::utxo::{dhash160, UtxoCommonOps}; -use coins::{FoundSwapTxSpend, MarketCoinOps, MmCoin, MmCoinEnum, RefundPaymentArgs, SearchForSwapTxSpendInput, - SendPaymentArgs, SwapOps, WatcherOps, WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, - EARLY_CONFIRMATION_ERR_LOG, INSUFFICIENT_WATCHER_REWARD_ERR_LOG, INVALID_CONTRACT_ADDRESS_ERR_LOG, - INVALID_PAYMENT_STATE_ERR_LOG, INVALID_RECEIVER_ERR_LOG, INVALID_REFUND_TX_ERR_LOG, - INVALID_SCRIPT_ERR_LOG, INVALID_SENDER_ERR_LOG, INVALID_SWAP_ID_ERR_LOG, OLD_TRANSACTION_ERR_LOG}; +use coins::{ConfirmPaymentInput, FoundSwapTxSpend, MarketCoinOps, MmCoin, MmCoinEnum, RefundPaymentArgs, + SearchForSwapTxSpendInput, SendPaymentArgs, SwapOps, WatcherOps, WatcherValidatePaymentInput, + WatcherValidateTakerFeeInput, EARLY_CONFIRMATION_ERR_LOG, INSUFFICIENT_WATCHER_REWARD_ERR_LOG, + INVALID_CONTRACT_ADDRESS_ERR_LOG, INVALID_PAYMENT_STATE_ERR_LOG, INVALID_RECEIVER_ERR_LOG, + INVALID_REFUND_TX_ERR_LOG, INVALID_SCRIPT_ERR_LOG, INVALID_SENDER_ERR_LOG, INVALID_SWAP_ID_ERR_LOG, + OLD_TRANSACTION_ERR_LOG}; use common::{block_on, now_ms, DEX_FEE_ADDR_RAW_PUBKEY}; use crypto::privkey::key_pair_from_secret; use futures01::Future; @@ -470,10 +471,14 @@ fn test_watcher_validate_taker_fee_eth() { .wait() .unwrap(); - taker_coin - .wait_for_confirmations(&taker_fee.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: taker_fee.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + taker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let validate_taker_fee_res = taker_coin .watcher_validate_taker_fee(WatcherValidateTakerFeeInput { @@ -574,10 +579,14 @@ fn test_watcher_validate_taker_fee_erc20() { .wait() .unwrap(); - taker_coin - .wait_for_confirmations(&taker_fee.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: taker_fee.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + taker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let validate_taker_fee_res = taker_coin .watcher_validate_taker_fee(WatcherValidateTakerFeeInput { @@ -706,10 +715,14 @@ fn test_watcher_validate_taker_payment_eth() { .wait() .unwrap(); - taker_coin - .wait_for_confirmations(&taker_payment.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: taker_payment.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + taker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let validate_taker_payment_res = taker_coin .watcher_validate_taker_payment(coins::WatcherValidatePaymentInput { @@ -838,10 +851,14 @@ fn test_watcher_validate_taker_payment_eth() { .wait() .unwrap(); - taker_coin - .wait_for_confirmations(&taker_payment_wrong_secret.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: taker_payment_wrong_secret.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + taker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let error = taker_coin .watcher_validate_taker_payment(WatcherValidatePaymentInput { @@ -971,10 +988,14 @@ fn test_watcher_validate_taker_payment_erc20() { .wait() .unwrap(); - taker_coin - .wait_for_confirmations(&taker_payment.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: taker_payment.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + taker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let validate_taker_payment_res = taker_coin .watcher_validate_taker_payment(WatcherValidatePaymentInput { @@ -1103,10 +1124,14 @@ fn test_watcher_validate_taker_payment_erc20() { .wait() .unwrap(); - taker_coin - .wait_for_confirmations(&taker_payment_wrong_secret.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: taker_payment_wrong_secret.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + taker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let error = taker_coin .watcher_validate_taker_payment(WatcherValidatePaymentInput { @@ -1434,10 +1459,14 @@ fn test_watcher_validate_taker_fee_utxo() { .wait() .unwrap(); - taker_coin - .wait_for_confirmations(&taker_fee.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: taker_fee.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + taker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let validate_taker_fee_res = taker_coin .watcher_validate_taker_fee(WatcherValidateTakerFeeInput { @@ -1565,10 +1594,14 @@ fn test_watcher_validate_taker_payment_utxo() { .wait() .unwrap(); - taker_coin - .wait_for_confirmations(&taker_payment.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: taker_payment.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + taker_coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let taker_payment_refund_preimage = taker_coin .create_taker_payment_refund_preimage( @@ -1737,9 +1770,14 @@ fn test_send_taker_payment_refund_preimage_utxo() { }; let tx = coin.send_taker_payment(taker_payment_args).wait().unwrap(); - coin.wait_for_confirmations(&tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let refund_tx = coin .create_taker_payment_refund_preimage(&tx.tx_hex(), time_lock, my_public_key, &[0; 20], &None, &[]) @@ -1759,9 +1797,14 @@ fn test_send_taker_payment_refund_preimage_utxo() { .wait() .unwrap(); - coin.wait_for_confirmations(&refund_tx.tx_hex(), 1, false, timeout, 1) - .wait() - .unwrap(); + let confirm_payment_input = ConfirmPaymentInput { + payment_tx: refund_tx.tx_hex(), + confirmations: 1, + requires_nota: false, + wait_until: timeout, + check_every: 1, + }; + coin.wait_for_confirmations(confirm_payment_input).wait().unwrap(); let search_input = SearchForSwapTxSpendInput { time_lock, diff --git a/mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs b/mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs index ca257a6118..163722d527 100644 --- a/mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs +++ b/mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs @@ -4533,6 +4533,8 @@ fn test_tx_history_tbtc_non_segwit() { ); let expected = vec![ + // https://live.blockcypher.com/btc-testnet/tx/a41b2e5f0741d1dcbc309ce4c43fde1ad44c5e61bb34778ab0bf9f3d9fd6fb6c/ + "a41b2e5f0741d1dcbc309ce4c43fde1ad44c5e61bb34778ab0bf9f3d9fd6fb6c", // https://live.blockcypher.com/btc-testnet/tx/9c1ca9de9f3a47d71c8113209123410f44048c67951bf49cdfb1a84c2cc6a55b/ "9c1ca9de9f3a47d71c8113209123410f44048c67951bf49cdfb1a84c2cc6a55b", // https://live.blockcypher.com/btc-testnet/tx/ac6218b33d02e069c4055af709bbb6ca92ce11e55450cde96bc17411e281e5e7/