diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 0a5c33f5da..c034ea0dc8 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -110,23 +110,23 @@ cfg_wasm32! { use super::{coin_conf, lp_coinfind_or_err, AsyncMutex, BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, CoinProtocol, CoinTransportMetrics, CoinsContext, ConfirmPaymentInput, EthValidateFeeArgs, - FeeApproxStage, FoundSwapTxSpend, HistorySyncState, IguanaPrivKey, MakerSwapTakerCoin, MarketCoinOps, - MmCoin, MmCoinEnum, MyAddressError, MyWalletAddress, NegotiateSwapContractAddrErr, NumConversError, - NumConversResult, PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, + FeeApproxStage, FoundSwapTxSpend, HistorySyncState, IguanaPrivKey, MarketCoinOps, MmCoin, MmCoinEnum, + MyAddressError, MyWalletAddress, NegotiateSwapContractAddrErr, NumConversError, NumConversResult, + PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, RawTransactionError, RawTransactionFut, RawTransactionRequest, RawTransactionRes, - RawTransactionResult, RefundError, RefundPaymentArgs, RefundResult, RewardTarget, RpcClientType, - RpcTransportEventHandler, RpcTransportEventHandlerShared, SearchForSwapTxSpendInput, - SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignEthTransactionParams, SignRawTransactionEnum, - SignRawTransactionRequest, SignatureError, SignatureResult, SpendPaymentArgs, SwapOps, SwapTxFeePolicy, - TakerSwapMakerCoin, TradeFee, TradePreimageError, TradePreimageFut, TradePreimageResult, - TradePreimageValue, Transaction, TransactionDetails, TransactionEnum, TransactionErr, TransactionFut, - TransactionType, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, - ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, - ValidatePaymentInput, VerificationError, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, - WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, - WatcherValidateTakerFeeInput, WeakSpawner, WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest, - WithdrawResult, EARLY_CONFIRMATION_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}; + RawTransactionResult, RefundPaymentArgs, RewardTarget, RpcClientType, RpcTransportEventHandler, + RpcTransportEventHandlerShared, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, + SendPaymentArgs, SignEthTransactionParams, SignRawTransactionEnum, SignRawTransactionRequest, + SignatureError, SignatureResult, SpendPaymentArgs, SwapOps, SwapTxFeePolicy, TradeFee, TradePreimageError, + TradePreimageFut, TradePreimageResult, TradePreimageValue, Transaction, TransactionDetails, + TransactionEnum, TransactionErr, TransactionFut, TransactionType, TxMarshalingErr, + UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, + ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, VerificationError, + VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WatcherReward, WatcherRewardError, + WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WeakSpawner, + WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest, WithdrawResult, EARLY_CONFIRMATION_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_native! { use std::path::PathBuf; @@ -1465,10 +1465,6 @@ impl SwapOps for EthCoin { .await } - fn check_tx_signed_by_pub(&self, _tx: &[u8], _expected_pub: &[u8]) -> Result> { - unimplemented!(); - } - async fn extract_secret( &self, _secret_hash: &[u8], @@ -1504,14 +1500,6 @@ impl SwapOps for EthCoin { } } - fn is_auto_refundable(&self) -> bool { false } - - async fn wait_for_htlc_refund(&self, _tx: &[u8], _locktime: u64) -> RefundResult<()> { - MmError::err(RefundError::Internal( - "wait_for_htlc_refund is not supported for this coin!".into(), - )) - } - fn negotiate_swap_contract_addr( &self, other_side_address: Option<&[u8]>, @@ -1632,20 +1620,6 @@ impl SwapOps for EthCoin { } } -#[async_trait] -impl TakerSwapMakerCoin for EthCoin { - async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - -#[async_trait] -impl MakerSwapTakerCoin for EthCoin { - async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - #[async_trait] impl WatcherOps for EthCoin { fn send_maker_payment_spend_preimage(&self, input: SendMakerPaymentSpendPreimageInput) -> TransactionFut { diff --git a/mm2src/coins/lightning.rs b/mm2src/coins/lightning.rs index a4b604975c..ed85df9817 100644 --- a/mm2src/coins/lightning.rs +++ b/mm2src/coins/lightning.rs @@ -16,19 +16,16 @@ 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, ConfirmPaymentInput, DexFee, FeeApproxStage, - FoundSwapTxSpend, HistorySyncState, MakerSwapTakerCoin, MarketCoinOps, MmCoin, MmCoinEnum, - NegotiateSwapContractAddrErr, PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, - RawTransactionError, RawTransactionFut, RawTransactionRequest, RawTransactionResult, RefundError, - RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, - SendPaymentArgs, SignRawTransactionRequest, SignatureError, SignatureResult, SpendPaymentArgs, SwapOps, - TakerSwapMakerCoin, TradeFee, TradePreimageFut, TradePreimageResult, TradePreimageValue, Transaction, - TransactionEnum, TransactionErr, TransactionFut, TransactionResult, TxMarshalingErr, + FoundSwapTxSpend, HistorySyncState, MarketCoinOps, MmCoin, NegotiateSwapContractAddrErr, + PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, RawTransactionError, + RawTransactionFut, RawTransactionRequest, RawTransactionResult, RefundError, RefundPaymentArgs, + RefundResult, SearchForSwapTxSpendInput, SendPaymentArgs, SignRawTransactionRequest, SignatureError, + SignatureResult, SpendPaymentArgs, SwapOps, TradeFee, TradePreimageFut, TradePreimageResult, + TradePreimageValue, Transaction, TransactionEnum, TransactionErr, TransactionResult, TxMarshalingErr, UnexpectedDerivationMethod, UtxoStandardCoin, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, - ValidatePaymentInput, ValidateWatcherSpendInput, VerificationError, VerificationResult, - WaitForHTLCTxSpendArgs, WatcherOps, WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, - WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WeakSpawner, WithdrawError, WithdrawFut, - WithdrawRequest}; + ValidatePaymentInput, VerificationError, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, + WeakSpawner, WithdrawError, WithdrawFut, WithdrawRequest}; use async_trait::async_trait; use bitcoin::bech32::ToBase32; use bitcoin::hashes::Hash; @@ -785,10 +782,6 @@ impl SwapOps for LightningCoin { } } - fn check_tx_signed_by_pub(&self, _tx: &[u8], _expected_pub: &[u8]) -> Result> { - unimplemented!(); - } - async fn extract_secret( &self, _secret_hash: &[u8], @@ -916,19 +909,13 @@ impl SwapOps for LightningCoin { } fn maker_locktime_multiplier(&self) -> f64 { 1.5 } -} -#[async_trait] -impl TakerSwapMakerCoin for LightningCoin { async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } async fn on_taker_payment_refund_success(&self, maker_payment: &[u8]) -> RefundResult<()> { self.on_swap_refund(maker_payment).await } -} -#[async_trait] -impl MakerSwapTakerCoin for LightningCoin { async fn on_maker_payment_refund_start(&self, taker_payment: &[u8]) -> RefundResult<()> { self.on_swap_refund(taker_payment).await } @@ -953,77 +940,7 @@ fn payment_hash_from_slice(data: &[u8]) -> Result TransactionFut { - unimplemented!(); - } - - fn send_maker_payment_spend_preimage(&self, _input: SendMakerPaymentSpendPreimageInput) -> TransactionFut { - unimplemented!(); - } - - fn create_taker_payment_refund_preimage( - &self, - _taker_payment_tx: &[u8], - _time_lock: u64, - _maker_pub: &[u8], - _secret_hash: &[u8], - _swap_contract_address: &Option, - _swap_unique_data: &[u8], - ) -> TransactionFut { - unimplemented!(); - } - - fn send_taker_payment_refund_preimage(&self, _watcher_refunds_payment_args: RefundPaymentArgs) -> TransactionFut { - unimplemented!(); - } - - fn watcher_validate_taker_fee(&self, _input: WatcherValidateTakerFeeInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn watcher_validate_taker_payment(&self, _input: WatcherValidatePaymentInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn taker_validates_payment_spend_or_refund(&self, _input: ValidateWatcherSpendInput) -> ValidatePaymentFut<()> { - unimplemented!() - } - - async fn watcher_search_for_swap_tx_spend( - &self, - _input: WatcherSearchForSwapTxSpendInput<'_>, - ) -> Result, String> { - unimplemented!(); - } - - async fn get_taker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _coin_amount: Option, - _other_coin_amount: Option, - _reward_amount: Option, - _wait_until: u64, - ) -> Result> { - unimplemented!() - } - - async fn get_maker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _reward_amount: Option, - _wait_until: u64, - ) -> Result, MmError> { - unimplemented!() - } -} +impl WatcherOps for LightningCoin {} #[async_trait] impl MarketCoinOps for LightningCoin { diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 344d9d8306..da35c42108 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1120,8 +1120,6 @@ pub trait SwapOps { watcher_reward: bool, ) -> Result<[u8; 32], String>; - fn check_tx_signed_by_pub(&self, tx: &[u8], expected_pub: &[u8]) -> Result>; - /// Whether the refund transaction can be sent now /// For example: there are no additional conditions for ETH, but for some UTXO coins we should wait for /// locktime < MTP @@ -1135,10 +1133,15 @@ pub trait SwapOps { } /// Whether the swap payment is refunded automatically or not when the locktime expires, or the other side fails the HTLC. - fn is_auto_refundable(&self) -> bool; + /// lightning specific + fn is_auto_refundable(&self) -> bool { false } - /// Waits for an htlc to be refunded automatically. - async fn wait_for_htlc_refund(&self, _tx: &[u8], _locktime: u64) -> RefundResult<()>; + /// Waits for an htlc to be refunded automatically. - lightning specific + async fn wait_for_htlc_refund(&self, _tx: &[u8], _locktime: u64) -> RefundResult<()> { + MmError::err(RefundError::Internal( + "wait_for_htlc_refund is not supported for this coin!".into(), + )) + } fn negotiate_swap_contract_addr( &self, @@ -1154,29 +1157,43 @@ pub trait SwapOps { fn validate_other_pubkey(&self, raw_pubkey: &[u8]) -> MmResult<(), ValidateOtherPubKeyErr>; - /// Instructions from the taker on how the maker should send his payment. + /// Instructions from the taker on how the maker should send his payment. - lightning specific async fn maker_payment_instructions( &self, - args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError>; + _args: PaymentInstructionArgs<'_>, + ) -> Result>, MmError> { + Ok(None) + } - /// Instructions from the maker on how the taker should send his payment. + /// Instructions from the maker on how the taker should send his payment. - lightning specific async fn taker_payment_instructions( &self, - args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError>; + _args: PaymentInstructionArgs<'_>, + ) -> Result>, MmError> { + Ok(None) + } + /// lightning specific fn validate_maker_payment_instructions( &self, - instructions: &[u8], - args: PaymentInstructionArgs<'_>, - ) -> Result>; + _instructions: &[u8], + _args: PaymentInstructionArgs<'_>, + ) -> Result> { + MmError::err(ValidateInstructionsErr::UnsupportedCoin( + "validate_maker_payment_instructions is not supported for this coin!".into(), + )) + } + /// lightning specific fn validate_taker_payment_instructions( &self, - instructions: &[u8], - args: PaymentInstructionArgs<'_>, - ) -> Result>; + _instructions: &[u8], + _args: PaymentInstructionArgs<'_>, + ) -> Result> { + MmError::err(ValidateInstructionsErr::UnsupportedCoin( + "validate_taker_payment_instructions is not supported for this coin!".into(), + )) + } fn is_supported_by_watchers(&self) -> bool { false } @@ -1184,77 +1201,138 @@ pub trait SwapOps { fn contract_supports_watchers(&self) -> bool { true } fn maker_locktime_multiplier(&self) -> f64 { 2.0 } -} -/// Operations on maker coin from taker swap side -#[async_trait] -pub trait TakerSwapMakerCoin { /// Performs an action on Maker coin payment just before the Taker Swap payment refund begins - async fn on_taker_payment_refund_start(&self, maker_payment: &[u8]) -> RefundResult<()>; + /// Operation on maker coin from taker swap side + /// Currently lightning specific + async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } + /// Performs an action on Maker coin payment after the Taker Swap payment is refunded successfully - async fn on_taker_payment_refund_success(&self, maker_payment: &[u8]) -> RefundResult<()>; -} + /// Operation on maker coin from taker swap side + /// Currently lightning specific + async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -/// Operations on taker coin from maker swap side -#[async_trait] -pub trait MakerSwapTakerCoin { /// Performs an action on Taker coin payment just before the Maker Swap payment refund begins - async fn on_maker_payment_refund_start(&self, taker_payment: &[u8]) -> RefundResult<()>; + /// Operation on taker coin from maker swap side + /// Currently lightning specific + async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } + /// Performs an action on Taker coin payment after the Maker Swap payment is refunded successfully - async fn on_maker_payment_refund_success(&self, taker_payment: &[u8]) -> RefundResult<()>; + /// Operation on taker coin from maker swap side + /// Currently lightning specific + async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } } #[async_trait] pub trait WatcherOps { - fn send_maker_payment_spend_preimage(&self, input: SendMakerPaymentSpendPreimageInput) -> TransactionFut; + fn send_maker_payment_spend_preimage(&self, _input: SendMakerPaymentSpendPreimageInput) -> TransactionFut { + Box::new( + futures::future::ready(Err(TransactionErr::Plain( + "send_maker_payment_spend_preimage is not implemented".to_string(), + ))) + .compat(), + ) + } - fn send_taker_payment_refund_preimage(&self, watcher_refunds_payment_args: RefundPaymentArgs) -> TransactionFut; + fn send_taker_payment_refund_preimage(&self, _watcher_refunds_payment_args: RefundPaymentArgs) -> TransactionFut { + Box::new( + futures::future::ready(Err(TransactionErr::Plain( + "send_taker_payment_refund_preimage is not implemented".to_string(), + ))) + .compat(), + ) + } fn create_taker_payment_refund_preimage( &self, - taker_payment_tx: &[u8], - time_lock: u64, - maker_pub: &[u8], - secret_hash: &[u8], - swap_contract_address: &Option, - swap_unique_data: &[u8], - ) -> TransactionFut; + _taker_payment_tx: &[u8], + _time_lock: u64, + _maker_pub: &[u8], + _secret_hash: &[u8], + _swap_contract_address: &Option, + _swap_unique_data: &[u8], + ) -> TransactionFut { + Box::new( + futures::future::ready(Err(TransactionErr::Plain( + "create_taker_payment_refund_preimage is not implemented".to_string(), + ))) + .compat(), + ) + } fn create_maker_payment_spend_preimage( &self, - maker_payment_tx: &[u8], - time_lock: u64, - maker_pub: &[u8], - secret_hash: &[u8], - swap_unique_data: &[u8], - ) -> TransactionFut; - - fn watcher_validate_taker_fee(&self, input: WatcherValidateTakerFeeInput) -> ValidatePaymentFut<()>; - - fn watcher_validate_taker_payment(&self, input: WatcherValidatePaymentInput) -> ValidatePaymentFut<()>; - - fn taker_validates_payment_spend_or_refund(&self, _input: ValidateWatcherSpendInput) -> ValidatePaymentFut<()>; + _maker_payment_tx: &[u8], + _time_lock: u64, + _maker_pub: &[u8], + _secret_hash: &[u8], + _swap_unique_data: &[u8], + ) -> TransactionFut { + Box::new( + futures::future::ready(Err(TransactionErr::Plain( + "create_maker_payment_spend_preimage is not implemented".to_string(), + ))) + .compat(), + ) + } + + fn watcher_validate_taker_fee(&self, _input: WatcherValidateTakerFeeInput) -> ValidatePaymentFut<()> { + Box::new( + futures::future::ready(MmError::err(ValidatePaymentError::InternalError( + "watcher_validate_taker_fee is not implemented".to_string(), + ))) + .compat(), + ) + } + + fn watcher_validate_taker_payment(&self, _input: WatcherValidatePaymentInput) -> ValidatePaymentFut<()> { + Box::new( + futures::future::ready(MmError::err(ValidatePaymentError::InternalError( + "watcher_validate_taker_payment is not implemented".to_string(), + ))) + .compat(), + ) + } + + fn taker_validates_payment_spend_or_refund(&self, _input: ValidateWatcherSpendInput) -> ValidatePaymentFut<()> { + Box::new( + futures::future::ready(MmError::err(ValidatePaymentError::InternalError( + "taker_validates_payment_spend_or_refund is not implemented".to_string(), + ))) + .compat(), + ) + } async fn watcher_search_for_swap_tx_spend( &self, - input: WatcherSearchForSwapTxSpendInput<'_>, - ) -> Result, String>; + _input: WatcherSearchForSwapTxSpendInput<'_>, + ) -> Result, String> { + Err("watcher_search_for_swap_tx_spend is not implemented".to_string()) + } async fn get_taker_watcher_reward( &self, - other_coin: &MmCoinEnum, - coin_amount: Option, - other_coin_amount: Option, - reward_amount: Option, - wait_until: u64, - ) -> Result>; + _other_coin: &MmCoinEnum, + _coin_amount: Option, + _other_coin_amount: Option, + _reward_amount: Option, + _wait_until: u64, + ) -> Result> { + Err(WatcherRewardError::InternalError( + "get_taker_watcher_reward is not implemented".to_string(), + ))? + } async fn get_maker_watcher_reward( &self, - other_coin: &MmCoinEnum, - reward_amount: Option, - wait_until: u64, - ) -> Result, MmError>; + _other_coin: &MmCoinEnum, + _reward_amount: Option, + _wait_until: u64, + ) -> Result, MmError> { + Err(WatcherRewardError::InternalError( + "get_maker_watcher_reward is not implemented".to_string(), + ))? + } } /// Helper struct wrapping arguments for [TakerCoinSwapOpsV2::send_taker_funding] @@ -3294,9 +3372,7 @@ impl From for VerificationError { /// NB: Implementations are expected to follow the pImpl idiom, providing cheap reference-counted cloning and garbage collection. #[async_trait] -pub trait MmCoin: - SwapOps + TakerSwapMakerCoin + MakerSwapTakerCoin + WatcherOps + MarketCoinOps + Send + Sync + 'static -{ +pub trait MmCoin: SwapOps + WatcherOps + MarketCoinOps + Send + Sync + 'static { // `MmCoin` is an extension fulcrum for something that doesn't fit the `MarketCoinOps`. Practical examples: // name (might be required for some APIs, CoinMarketCap for instance); // coin statistics that we might want to share with UI; diff --git a/mm2src/coins/qrc20.rs b/mm2src/coins/qrc20.rs index 8cbf8a8786..2b4dc54a38 100644 --- a/mm2src/coins/qrc20.rs +++ b/mm2src/coins/qrc20.rs @@ -17,20 +17,15 @@ use crate::utxo::{qtum, ActualTxFee, AdditionalTxData, AddrFromStrError, Broadca UtxoFromLegacyReqErr, UtxoTx, UtxoTxBroadcastOps, UtxoTxGenerationOps, VerboseTransactionFrom, UTXO_LOCK}; use crate::{BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, ConfirmPaymentInput, DexFee, Eip1559Ops, - FeeApproxStage, FoundSwapTxSpend, HistorySyncState, IguanaPrivKey, MakerSwapTakerCoin, MarketCoinOps, - MmCoin, MmCoinEnum, NegotiateSwapContractAddrErr, PaymentInstructionArgs, PaymentInstructions, - PaymentInstructionsErr, PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, RawTransactionFut, - RawTransactionRequest, RawTransactionResult, RefundError, RefundPaymentArgs, RefundResult, - SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignRawTransactionRequest, - SignatureResult, SpendPaymentArgs, SwapOps, SwapTxFeePolicy, TakerSwapMakerCoin, TradeFee, - TradePreimageError, TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionData, - TransactionDetails, TransactionEnum, TransactionErr, TransactionFut, TransactionResult, TransactionType, - TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, - ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentFut, ValidatePaymentInput, - ValidateWatcherSpendInput, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WatcherReward, - WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, - WatcherValidateTakerFeeInput, WeakSpawner, WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest, - WithdrawResult}; + FeeApproxStage, FoundSwapTxSpend, HistorySyncState, IguanaPrivKey, MarketCoinOps, MmCoin, + NegotiateSwapContractAddrErr, PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, RawTransactionFut, + RawTransactionRequest, RawTransactionResult, RefundPaymentArgs, SearchForSwapTxSpendInput, + SendPaymentArgs, SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, SwapOps, SwapTxFeePolicy, + TradeFee, TradePreimageError, TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionData, + TransactionDetails, TransactionEnum, TransactionErr, TransactionResult, TransactionType, TxMarshalingErr, + UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateOtherPubKeyErr, + ValidatePaymentInput, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WeakSpawner, WithdrawError, + WithdrawFee, WithdrawFut, WithdrawRequest, WithdrawResult}; use async_trait::async_trait; use bitcrypto::{dhash160, sha256}; use chain::TransactionOutput; @@ -982,11 +977,6 @@ impl SwapOps for Qrc20Coin { .await } - #[inline] - fn check_tx_signed_by_pub(&self, tx: &[u8], expected_pub: &[u8]) -> Result> { - utxo_common::check_all_inputs_signed_by_pub(tx, expected_pub) - } - #[inline] async fn extract_secret( &self, @@ -997,14 +987,6 @@ impl SwapOps for Qrc20Coin { self.extract_secret_impl(secret_hash, spend_tx) } - fn is_auto_refundable(&self) -> bool { false } - - async fn wait_for_htlc_refund(&self, _tx: &[u8], _locktime: u64) -> RefundResult<()> { - MmError::err(RefundError::Internal( - "wait_for_htlc_refund is not supported for this coin!".into(), - )) - } - fn negotiate_swap_contract_addr( &self, other_side_address: Option<&[u8]>, @@ -1043,124 +1025,10 @@ impl SwapOps for Qrc20Coin { fn validate_other_pubkey(&self, raw_pubkey: &[u8]) -> MmResult<(), ValidateOtherPubKeyErr> { utxo_common::validate_other_pubkey(raw_pubkey) } - - async fn maker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - async fn taker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - fn validate_maker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } - - fn validate_taker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } } #[async_trait] -impl TakerSwapMakerCoin for Qrc20Coin { - async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - -#[async_trait] -impl MakerSwapTakerCoin for Qrc20Coin { - async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - -#[async_trait] -impl WatcherOps for Qrc20Coin { - fn create_maker_payment_spend_preimage( - &self, - _maker_payment_tx: &[u8], - _time_lock: u64, - _maker_pub: &[u8], - _secret_hash: &[u8], - _swap_unique_data: &[u8], - ) -> TransactionFut { - unimplemented!(); - } - - fn send_maker_payment_spend_preimage(&self, _input: SendMakerPaymentSpendPreimageInput) -> TransactionFut { - unimplemented!(); - } - - fn create_taker_payment_refund_preimage( - &self, - _taker_payment_tx: &[u8], - _time_lock: u64, - _maker_pub: &[u8], - _secret_hash: &[u8], - _swap_contract_address: &Option, - _swap_unique_data: &[u8], - ) -> TransactionFut { - unimplemented!(); - } - - fn send_taker_payment_refund_preimage(&self, _watcher_refunds_payment_args: RefundPaymentArgs) -> TransactionFut { - unimplemented!(); - } - - fn watcher_validate_taker_fee(&self, _input: WatcherValidateTakerFeeInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn watcher_validate_taker_payment(&self, _input: WatcherValidatePaymentInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn taker_validates_payment_spend_or_refund(&self, _input: ValidateWatcherSpendInput) -> ValidatePaymentFut<()> { - unimplemented!() - } - - async fn watcher_search_for_swap_tx_spend( - &self, - _input: WatcherSearchForSwapTxSpendInput<'_>, - ) -> Result, String> { - unimplemented!(); - } - - async fn get_taker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _coin_amount: Option, - _other_coin_amount: Option, - _reward_amount: Option, - _wait_until: u64, - ) -> Result> { - unimplemented!() - } - - async fn get_maker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _reward_amount: Option, - _wait_until: u64, - ) -> Result, MmError> { - unimplemented!() - } -} +impl WatcherOps for Qrc20Coin {} #[async_trait] impl MarketCoinOps for Qrc20Coin { diff --git a/mm2src/coins/siacoin.rs b/mm2src/coins/siacoin.rs index 46fe63deba..28055b4e7f 100644 --- a/mm2src/coins/siacoin.rs +++ b/mm2src/coins/siacoin.rs @@ -1,16 +1,12 @@ use super::{BalanceError, CoinBalance, HistorySyncState, MarketCoinOps, MmCoin, RawTransactionFut, - RawTransactionRequest, SwapOps, TradeFee, TransactionEnum, TransactionFut}; + RawTransactionRequest, SwapOps, TradeFee, TransactionEnum}; use crate::{coin_errors::MyAddressError, BalanceFut, CanRefundHtlc, CheckIfMyPaymentSentArgs, ConfirmPaymentInput, - DexFee, FeeApproxStage, FoundSwapTxSpend, MakerSwapTakerCoin, MmCoinEnum, NegotiateSwapContractAddrErr, - PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, PrivKeyPolicy, - RawTransactionResult, RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, - SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignRawTransactionRequest, SignatureResult, - SpendPaymentArgs, TakerSwapMakerCoin, TradePreimageFut, TradePreimageResult, TradePreimageValue, - TransactionResult, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, - ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, - ValidatePaymentInput, ValidatePaymentResult, ValidateWatcherSpendInput, VerificationResult, - WaitForHTLCTxSpendArgs, WatcherOps, WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, - WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WeakSpawner, WithdrawFut, WithdrawRequest}; + DexFee, FeeApproxStage, FoundSwapTxSpend, NegotiateSwapContractAddrErr, PrivKeyBuildPolicy, PrivKeyPolicy, + RawTransactionResult, RefundPaymentArgs, SearchForSwapTxSpendInput, SendPaymentArgs, + SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, TradePreimageFut, TradePreimageResult, + TradePreimageValue, TransactionResult, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, + ValidateFeeArgs, ValidateOtherPubKeyErr, ValidatePaymentInput, ValidatePaymentResult, VerificationResult, + WaitForHTLCTxSpendArgs, WatcherOps, WeakSpawner, WithdrawFut, WithdrawRequest}; use async_trait::async_trait; use common::executor::AbortedError; pub use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature}; @@ -477,10 +473,6 @@ impl SwapOps for SiaCoin { unimplemented!() } - fn check_tx_signed_by_pub(&self, _tx: &[u8], _expected_pub: &[u8]) -> Result> { - unimplemented!(); - } - async fn extract_secret( &self, _secret_hash: &[u8], @@ -490,15 +482,11 @@ impl SwapOps for SiaCoin { unimplemented!() } - fn is_auto_refundable(&self) -> bool { false } - - async fn wait_for_htlc_refund(&self, _tx: &[u8], _locktime: u64) -> RefundResult<()> { unimplemented!() } - fn negotiate_swap_contract_addr( &self, _other_side_address: Option<&[u8]>, ) -> Result, MmError> { - unimplemented!() + Ok(None) } fn derive_htlc_key_pair(&self, _swap_unique_data: &[u8]) -> KeyPair { unimplemented!() } @@ -508,124 +496,10 @@ impl SwapOps for SiaCoin { async fn can_refund_htlc(&self, _locktime: u64) -> Result { unimplemented!() } fn validate_other_pubkey(&self, _raw_pubkey: &[u8]) -> MmResult<(), ValidateOtherPubKeyErr> { unimplemented!() } - - async fn maker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - unimplemented!() - } - - async fn taker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - unimplemented!() - } - - fn validate_maker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - unimplemented!() - } - - fn validate_taker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - unimplemented!() - } } #[async_trait] -impl TakerSwapMakerCoin for SiaCoin { - async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - -#[async_trait] -impl MakerSwapTakerCoin for SiaCoin { - async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - -#[async_trait] -impl WatcherOps for SiaCoin { - fn send_maker_payment_spend_preimage(&self, _input: SendMakerPaymentSpendPreimageInput) -> TransactionFut { - unimplemented!(); - } - - fn send_taker_payment_refund_preimage(&self, _watcher_refunds_payment_args: RefundPaymentArgs) -> TransactionFut { - unimplemented!(); - } - - fn create_taker_payment_refund_preimage( - &self, - _taker_payment_tx: &[u8], - _time_lock: u64, - _maker_pub: &[u8], - _secret_hash: &[u8], - _swap_contract_address: &Option, - _swap_unique_data: &[u8], - ) -> TransactionFut { - unimplemented!(); - } - - fn create_maker_payment_spend_preimage( - &self, - _maker_payment_tx: &[u8], - _time_lock: u64, - _maker_pub: &[u8], - _secret_hash: &[u8], - _swap_unique_data: &[u8], - ) -> TransactionFut { - unimplemented!(); - } - - fn watcher_validate_taker_fee(&self, _input: WatcherValidateTakerFeeInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn watcher_validate_taker_payment(&self, _input: WatcherValidatePaymentInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn taker_validates_payment_spend_or_refund(&self, _input: ValidateWatcherSpendInput) -> ValidatePaymentFut<()> { - unimplemented!() - } - - async fn watcher_search_for_swap_tx_spend( - &self, - _input: WatcherSearchForSwapTxSpendInput<'_>, - ) -> Result, String> { - unimplemented!(); - } - - async fn get_taker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _coin_amount: Option, - _other_coin_amount: Option, - _reward_amount: Option, - _wait_until: u64, - ) -> Result> { - unimplemented!() - } - - async fn get_maker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _reward_amount: Option, - _wait_until: u64, - ) -> Result, MmError> { - unimplemented!() - } -} +impl WatcherOps for SiaCoin {} #[cfg(test)] mod tests { diff --git a/mm2src/coins/tendermint/tendermint_coin.rs b/mm2src/coins/tendermint/tendermint_coin.rs index cf20c37e81..2b5439c6d4 100644 --- a/mm2src/coins/tendermint/tendermint_coin.rs +++ b/mm2src/coins/tendermint/tendermint_coin.rs @@ -16,19 +16,15 @@ 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, ConfirmPaymentInput, DelegationError, DexFee, FeeApproxStage, FoundSwapTxSpend, - HistorySyncState, MakerSwapTakerCoin, MarketCoinOps, MmCoin, MmCoinEnum, NegotiateSwapContractAddrErr, - PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, PrivKeyPolicy, + HistorySyncState, MarketCoinOps, MmCoin, NegotiateSwapContractAddrErr, PrivKeyBuildPolicy, PrivKeyPolicy, PrivKeyPolicyNotAllowed, RawTransactionError, RawTransactionFut, RawTransactionRequest, RawTransactionRes, - RawTransactionResult, RefundError, RefundPaymentArgs, RefundResult, RpcCommonOps, - SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignRawTransactionRequest, - SignatureError, SignatureResult, SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, ToBytes, TradeFee, + RawTransactionResult, RefundPaymentArgs, RpcCommonOps, SearchForSwapTxSpendInput, SendPaymentArgs, + SignRawTransactionRequest, SignatureError, SignatureResult, SpendPaymentArgs, SwapOps, ToBytes, TradeFee, TradePreimageError, TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionData, TransactionDetails, TransactionEnum, TransactionErr, TransactionFut, TransactionResult, TransactionType, TxFeeDetails, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, - ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentFut, ValidatePaymentInput, - ValidateWatcherSpendInput, VerificationError, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, - WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, - WatcherValidateTakerFeeInput, WeakSpawner, WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest}; + ValidateOtherPubKeyErr, ValidatePaymentFut, ValidatePaymentInput, VerificationError, VerificationResult, + WaitForHTLCTxSpendArgs, WatcherOps, WeakSpawner, WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest}; use async_std::prelude::FutureExt as AsyncStdFutureExt; use async_trait::async_trait; use bip32::DerivationPath; @@ -3321,20 +3317,6 @@ impl SwapOps for TendermintCoin { Ok(try_s!(try_s!(hex::decode(htlc.secret())).as_slice().try_into())) } - fn check_tx_signed_by_pub(&self, tx: &[u8], expected_pub: &[u8]) -> Result> { - unimplemented!(); - } - - // Todo - fn is_auto_refundable(&self) -> bool { false } - - // Todo - async fn wait_for_htlc_refund(&self, _tx: &[u8], _locktime: u64) -> RefundResult<()> { - MmError::err(RefundError::Internal( - "wait_for_htlc_refund is not supported for this coin!".into(), - )) - } - fn negotiate_swap_contract_addr( &self, other_side_address: Option<&[u8]>, @@ -3366,124 +3348,10 @@ impl SwapOps for TendermintCoin { .or_mm_err(|| ValidateOtherPubKeyErr::InvalidPubKey(hex::encode(raw_pubkey)))?; Ok(()) } - - async fn maker_payment_instructions( - &self, - args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - async fn taker_payment_instructions( - &self, - args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - fn validate_maker_payment_instructions( - &self, - _instructions: &[u8], - args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } - - fn validate_taker_payment_instructions( - &self, - _instructions: &[u8], - args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } -} - -#[async_trait] -impl TakerSwapMakerCoin for TendermintCoin { - async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - -#[async_trait] -impl MakerSwapTakerCoin for TendermintCoin { - async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } } #[async_trait] -impl WatcherOps for TendermintCoin { - fn create_maker_payment_spend_preimage( - &self, - _maker_payment_tx: &[u8], - _time_lock: u64, - _maker_pub: &[u8], - _secret_hash: &[u8], - _swap_unique_data: &[u8], - ) -> TransactionFut { - unimplemented!(); - } - - fn send_maker_payment_spend_preimage(&self, _input: SendMakerPaymentSpendPreimageInput) -> TransactionFut { - unimplemented!(); - } - - fn create_taker_payment_refund_preimage( - &self, - _taker_payment_tx: &[u8], - _time_lock: u64, - _maker_pub: &[u8], - _secret_hash: &[u8], - _swap_contract_address: &Option, - _swap_unique_data: &[u8], - ) -> TransactionFut { - unimplemented!(); - } - - fn send_taker_payment_refund_preimage(&self, _watcher_refunds_payment_args: RefundPaymentArgs) -> TransactionFut { - unimplemented!(); - } - - fn watcher_validate_taker_fee(&self, _input: WatcherValidateTakerFeeInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn watcher_validate_taker_payment(&self, _input: WatcherValidatePaymentInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn taker_validates_payment_spend_or_refund(&self, _input: ValidateWatcherSpendInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - async fn watcher_search_for_swap_tx_spend( - &self, - _input: WatcherSearchForSwapTxSpendInput<'_>, - ) -> Result, String> { - unimplemented!(); - } - - async fn get_taker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _coin_amount: Option, - _other_coin_amount: Option, - _reward_amount: Option, - _wait_until: u64, - ) -> Result> { - unimplemented!() - } - - async fn get_maker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _reward_amount: Option, - _wait_until: u64, - ) -> Result, MmError> { - unimplemented!() - } -} +impl WatcherOps for TendermintCoin {} /// Processes the given `priv_key_build_policy` and returns corresponding `TendermintPrivKeyPolicy`. /// This function expects either [`PrivKeyBuildPolicy::IguanaPrivKey`] diff --git a/mm2src/coins/tendermint/tendermint_token.rs b/mm2src/coins/tendermint/tendermint_token.rs index 8eeb0cd09b..01f12963e3 100644 --- a/mm2src/coins/tendermint/tendermint_token.rs +++ b/mm2src/coins/tendermint/tendermint_token.rs @@ -6,20 +6,15 @@ use super::{create_withdraw_msg_as_any, TendermintCoin, TendermintFeeDetails, GA use crate::coin_errors::ValidatePaymentResult; 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, ConfirmPaymentInput, FeeApproxStage, FoundSwapTxSpend, - HistorySyncState, MakerSwapTakerCoin, MarketCoinOps, MmCoin, MyAddressError, NegotiateSwapContractAddrErr, - PaymentInstructions, PaymentInstructionsErr, RawTransactionError, RawTransactionFut, - RawTransactionRequest, RawTransactionResult, RefundError, RefundPaymentArgs, RefundResult, - SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignRawTransactionRequest, - SignatureResult, SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, TradeFee, TradePreimageFut, - TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionEnum, TransactionErr, - TransactionFut, TransactionResult, TransactionType, TxFeeDetails, TxMarshalingErr, - UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, - ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, - VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WatcherSearchForSwapTxSpendInput, - WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WeakSpawner, WithdrawError, WithdrawFut, - WithdrawRequest}; -use crate::{DexFee, MmCoinEnum, PaymentInstructionArgs, ValidateWatcherSpendInput, WatcherReward, WatcherRewardError}; + CheckIfMyPaymentSentArgs, CoinBalance, ConfirmPaymentInput, DexFee, FeeApproxStage, FoundSwapTxSpend, + HistorySyncState, MarketCoinOps, MmCoin, MyAddressError, NegotiateSwapContractAddrErr, + RawTransactionError, RawTransactionFut, RawTransactionRequest, RawTransactionResult, RefundPaymentArgs, + SearchForSwapTxSpendInput, SendPaymentArgs, SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, + SwapOps, TradeFee, TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionDetails, + TransactionEnum, TransactionErr, TransactionResult, TransactionType, TxFeeDetails, TxMarshalingErr, + UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateOtherPubKeyErr, + ValidatePaymentInput, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WeakSpawner, WithdrawError, + WithdrawFut, WithdrawRequest}; use async_trait::async_trait; use bitcrypto::sha256; use common::executor::abortable_queue::AbortableQueue; @@ -245,20 +240,6 @@ impl SwapOps for TendermintToken { .await } - fn check_tx_signed_by_pub(&self, tx: &[u8], expected_pub: &[u8]) -> Result> { - unimplemented!(); - } - - // Todo - fn is_auto_refundable(&self) -> bool { false } - - // Todo - async fn wait_for_htlc_refund(&self, _tx: &[u8], _locktime: u64) -> RefundResult<()> { - MmError::err(RefundError::Internal( - "wait_for_htlc_refund is not supported for this coin!".into(), - )) - } - fn negotiate_swap_contract_addr( &self, other_side_address: Option<&[u8]>, @@ -279,124 +260,10 @@ impl SwapOps for TendermintToken { fn validate_other_pubkey(&self, raw_pubkey: &[u8]) -> MmResult<(), ValidateOtherPubKeyErr> { self.platform_coin.validate_other_pubkey(raw_pubkey) } - - async fn maker_payment_instructions( - &self, - args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - async fn taker_payment_instructions( - &self, - args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - fn validate_maker_payment_instructions( - &self, - _instructions: &[u8], - args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } - - fn validate_taker_payment_instructions( - &self, - _instructions: &[u8], - args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } -} - -#[async_trait] -impl TakerSwapMakerCoin for TendermintToken { - async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - -#[async_trait] -impl MakerSwapTakerCoin for TendermintToken { - async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } } #[async_trait] -impl WatcherOps for TendermintToken { - fn create_maker_payment_spend_preimage( - &self, - _maker_payment_tx: &[u8], - _time_lock: u64, - _maker_pub: &[u8], - _secret_hash: &[u8], - _swap_unique_data: &[u8], - ) -> TransactionFut { - unimplemented!(); - } - - fn send_maker_payment_spend_preimage(&self, _input: SendMakerPaymentSpendPreimageInput) -> TransactionFut { - unimplemented!(); - } - - fn create_taker_payment_refund_preimage( - &self, - _taker_payment_tx: &[u8], - _time_lock: u64, - _maker_pub: &[u8], - _secret_hash: &[u8], - _swap_contract_address: &Option, - _swap_unique_data: &[u8], - ) -> TransactionFut { - unimplemented!(); - } - - fn send_taker_payment_refund_preimage(&self, _watcher_refunds_payment_args: RefundPaymentArgs) -> TransactionFut { - unimplemented!(); - } - - fn watcher_validate_taker_fee(&self, _input: WatcherValidateTakerFeeInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn watcher_validate_taker_payment(&self, _input: WatcherValidatePaymentInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn taker_validates_payment_spend_or_refund(&self, _input: ValidateWatcherSpendInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - async fn watcher_search_for_swap_tx_spend( - &self, - _input: WatcherSearchForSwapTxSpendInput<'_>, - ) -> Result, String> { - unimplemented!(); - } - - async fn get_taker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _coin_amount: Option, - _other_coin_amount: Option, - _reward_amount: Option, - _wait_until: u64, - ) -> Result> { - unimplemented!() - } - - async fn get_maker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _reward_amount: Option, - _wait_until: u64, - ) -> Result, MmError> { - unimplemented!() - } -} +impl WatcherOps for TendermintToken {} #[async_trait] impl MarketCoinOps for TendermintToken { diff --git a/mm2src/coins/test_coin.rs b/mm2src/coins/test_coin.rs index 63cd183924..fc78c75227 100644 --- a/mm2src/coins/test_coin.rs +++ b/mm2src/coins/test_coin.rs @@ -6,18 +6,17 @@ use super::{AddrToString, CoinBalance, CommonSwapOpsV2, FindPaymentSpendError, F use crate::coin_errors::ValidatePaymentResult; use crate::{coin_errors::MyAddressError, BalanceFut, CanRefundHtlc, CheckIfMyPaymentSentArgs, ConfirmPaymentInput, FeeApproxStage, FoundSwapTxSpend, GenPreimageResult, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, - MakerSwapTakerCoin, MmCoinEnum, NegotiateSwapContractAddrErr, ParseCoinAssocTypes, PaymentInstructionArgs, + MmCoinEnum, NegotiateSwapContractAddrErr, ParseCoinAssocTypes, PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, RawTransactionResult, RefundFundingSecretArgs, RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SendTakerFundingArgs, SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, - TakerCoinSwapOpsV2, TakerSwapMakerCoin, TradePreimageFut, TradePreimageResult, TradePreimageValue, - Transaction, TransactionErr, TransactionResult, TxMarshalingErr, TxPreimageWithSig, - UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, - ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, - ValidateSwapV2TxResult, ValidateTakerFundingArgs, ValidateTakerFundingSpendPreimageResult, - ValidateTakerPaymentSpendPreimageResult, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, - WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, - WatcherValidateTakerFeeInput, WeakSpawner, WithdrawFut, WithdrawRequest}; + TakerCoinSwapOpsV2, TradePreimageFut, TradePreimageResult, TradePreimageValue, Transaction, + TransactionErr, TransactionResult, TxMarshalingErr, TxPreimageWithSig, UnexpectedDerivationMethod, + ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, ValidateOtherPubKeyErr, + ValidatePaymentFut, ValidatePaymentInput, ValidateSwapV2TxResult, ValidateTakerFundingArgs, + ValidateTakerFundingSpendPreimageResult, ValidateTakerPaymentSpendPreimageResult, VerificationResult, + WaitForHTLCTxSpendArgs, WatcherOps, WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, + WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WeakSpawner, WithdrawFut, WithdrawRequest}; use crate::{DexFee, ToBytes, ValidateWatcherSpendInput}; use async_trait::async_trait; use common::executor::AbortedError; @@ -188,10 +187,6 @@ impl SwapOps for TestCoin { unimplemented!() } - fn check_tx_signed_by_pub(&self, tx: &[u8], expected_pub: &[u8]) -> Result> { - unimplemented!(); - } - async fn extract_secret( &self, secret_hash: &[u8], @@ -249,20 +244,14 @@ impl SwapOps for TestCoin { ) -> Result> { unimplemented!() } -} -#[async_trait] -impl TakerSwapMakerCoin for TestCoin { - async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } + async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { unimplemented!() } - async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} + async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { unimplemented!() } -#[async_trait] -impl MakerSwapTakerCoin for TestCoin { - async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } + async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { unimplemented!() } - async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } + async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { unimplemented!() } } #[async_trait] diff --git a/mm2src/coins/utxo/bch.rs b/mm2src/coins/utxo/bch.rs index 1a37738db0..cf5cb72d0e 100644 --- a/mm2src/coins/utxo/bch.rs +++ b/mm2src/coins/utxo/bch.rs @@ -15,16 +15,14 @@ use crate::utxo::utxo_tx_history_v2::{UtxoMyAddressesHistoryError, UtxoTxDetails UtxoTxHistoryOps}; use crate::{coin_balance, BlockHeightAndTime, CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinBalanceMap, CoinProtocol, CoinWithDerivationMethod, CoinWithPrivKeyPolicy, ConfirmPaymentInput, DexFee, - GetWithdrawSenderAddress, IguanaBalanceOps, IguanaPrivKey, MakerSwapTakerCoin, MmCoinEnum, - NegotiateSwapContractAddrErr, PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, - PrivKeyBuildPolicy, RawTransactionFut, RawTransactionRequest, RawTransactionResult, RefundError, - RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, - SendPaymentArgs, SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, SwapOps, - TakerSwapMakerCoin, TradePreimageValue, TransactionFut, TransactionResult, TransactionType, TxFeeDetails, - TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, - ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, - ValidatePaymentInput, ValidateWatcherSpendInput, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, - WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, + GetWithdrawSenderAddress, IguanaBalanceOps, IguanaPrivKey, MmCoinEnum, NegotiateSwapContractAddrErr, + PrivKeyBuildPolicy, RawTransactionFut, RawTransactionRequest, RawTransactionResult, RefundPaymentArgs, + SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignRawTransactionRequest, + SignatureResult, SpendPaymentArgs, SwapOps, TradePreimageValue, TransactionFut, TransactionResult, + TransactionType, TxFeeDetails, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, + ValidateFeeArgs, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, + ValidateWatcherSpendInput, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WatcherReward, + WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WithdrawFut}; use common::executor::{AbortableSystem, AbortedError}; use common::log::warn; @@ -996,11 +994,6 @@ impl SwapOps for BchCoin { utxo_common::search_for_swap_tx_spend_other(self, input, utxo_common::DEFAULT_SWAP_VOUT).await } - #[inline] - fn check_tx_signed_by_pub(&self, tx: &[u8], expected_pub: &[u8]) -> Result> { - utxo_common::check_all_inputs_signed_by_pub(tx, expected_pub) - } - #[inline] async fn extract_secret( &self, @@ -1011,14 +1004,6 @@ impl SwapOps for BchCoin { utxo_common::extract_secret(secret_hash, spend_tx) } - fn is_auto_refundable(&self) -> bool { false } - - async fn wait_for_htlc_refund(&self, _tx: &[u8], _locktime: u64) -> RefundResult<()> { - MmError::err(RefundError::Internal( - "wait_for_htlc_refund is not supported for this coin!".into(), - )) - } - #[inline] async fn can_refund_htlc(&self, locktime: u64) -> Result { utxo_common::can_refund_htlc(self, locktime) @@ -1047,53 +1032,9 @@ impl SwapOps for BchCoin { utxo_common::validate_other_pubkey(raw_pubkey) } - async fn maker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - async fn taker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - fn validate_maker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } - - fn validate_taker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } - fn is_supported_by_watchers(&self) -> bool { true } } -#[async_trait] -impl TakerSwapMakerCoin for BchCoin { - async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - -#[async_trait] -impl MakerSwapTakerCoin for BchCoin { - async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - fn total_unspent_value<'a>(unspents: impl IntoIterator) -> u64 { unspents.into_iter().fold(0, |cur, unspent| cur + unspent.value) } diff --git a/mm2src/coins/utxo/qtum.rs b/mm2src/coins/utxo/qtum.rs index dc5fc2a934..652a0c55ee 100644 --- a/mm2src/coins/utxo/qtum.rs +++ b/mm2src/coins/utxo/qtum.rs @@ -25,13 +25,11 @@ use crate::utxo::utxo_tx_history_v2::{UtxoMyAddressesHistoryError, UtxoTxDetails UtxoTxHistoryOps}; use crate::{eth, CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinBalanceMap, CoinWithDerivationMethod, CoinWithPrivKeyPolicy, ConfirmPaymentInput, DelegationError, DelegationFut, DexFee, - GetWithdrawSenderAddress, IguanaBalanceOps, IguanaPrivKey, MakerSwapTakerCoin, MmCoinEnum, - NegotiateSwapContractAddrErr, PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, - PrivKeyBuildPolicy, RawTransactionRequest, RawTransactionResult, RefundError, RefundPaymentArgs, - RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, - SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, StakingInfosFut, SwapOps, - TakerSwapMakerCoin, TradePreimageValue, TransactionFut, TransactionResult, TxMarshalingErr, - UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, + GetWithdrawSenderAddress, IguanaBalanceOps, IguanaPrivKey, MmCoinEnum, NegotiateSwapContractAddrErr, + PrivKeyBuildPolicy, RawTransactionRequest, RawTransactionResult, RefundPaymentArgs, + SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignRawTransactionRequest, + SignatureResult, SpendPaymentArgs, StakingInfosFut, SwapOps, TradePreimageValue, TransactionFut, + TransactionResult, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, ValidateWatcherSpendInput, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, @@ -631,11 +629,6 @@ impl SwapOps for QtumCoin { utxo_common::search_for_swap_tx_spend_other(self, input, utxo_common::DEFAULT_SWAP_VOUT).await } - #[inline] - fn check_tx_signed_by_pub(&self, tx: &[u8], expected_pub: &[u8]) -> Result> { - utxo_common::check_all_inputs_signed_by_pub(tx, expected_pub) - } - #[inline] async fn extract_secret( &self, @@ -646,14 +639,6 @@ impl SwapOps for QtumCoin { utxo_common::extract_secret(secret_hash, spend_tx) } - fn is_auto_refundable(&self) -> bool { false } - - async fn wait_for_htlc_refund(&self, _tx: &[u8], _locktime: u64) -> RefundResult<()> { - MmError::err(RefundError::Internal( - "wait_for_htlc_refund is not supported for this coin!".into(), - )) - } - #[inline] async fn can_refund_htlc(&self, locktime: u64) -> Result { utxo_common::can_refund_htlc(self, locktime) @@ -682,53 +667,9 @@ impl SwapOps for QtumCoin { utxo_common::validate_other_pubkey(raw_pubkey) } - async fn maker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - async fn taker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - fn validate_maker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } - - fn validate_taker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } - fn is_supported_by_watchers(&self) -> bool { true } } -#[async_trait] -impl TakerSwapMakerCoin for QtumCoin { - async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - -#[async_trait] -impl MakerSwapTakerCoin for QtumCoin { - async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - #[async_trait] impl WatcherOps for QtumCoin { #[inline] diff --git a/mm2src/coins/utxo/slp.rs b/mm2src/coins/utxo/slp.rs index 695e1c6889..6d04cca677 100644 --- a/mm2src/coins/utxo/slp.rs +++ b/mm2src/coins/utxo/slp.rs @@ -3,7 +3,7 @@ //! Tracking issue: https://github.com/KomodoPlatform/atomicDEX-API/issues/701 //! More info about the protocol and implementation guides can be found at https://slp.dev/ -use crate::coin_errors::{MyAddressError, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentResult}; +use crate::coin_errors::{MyAddressError, ValidatePaymentError, ValidatePaymentResult}; use crate::my_tx_history_v2::{CoinWithTxHistoryV2, MyTxHistoryErrorV2, MyTxHistoryTarget}; use crate::tx_history_storage::{GetTxHistoryFilters, WalletId}; use crate::utxo::bch::BchCoin; @@ -14,19 +14,15 @@ use crate::utxo::{generate_and_send_tx, sat_from_big_decimal, ActualTxFee, Addit FeePolicy, GenerateTxError, RecentlySpentOutPointsGuard, UtxoCoinConf, UtxoCoinFields, UtxoCommonOps, UtxoTx, UtxoTxBroadcastOps, UtxoTxGenerationOps}; use crate::{BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, ConfirmPaymentInput, DerivationMethod, DexFee, - FeeApproxStage, FoundSwapTxSpend, HistorySyncState, MakerSwapTakerCoin, MarketCoinOps, MmCoin, MmCoinEnum, - NegotiateSwapContractAddrErr, NumConversError, PaymentInstructionArgs, PaymentInstructions, - PaymentInstructionsErr, PrivKeyPolicyNotAllowed, RawTransactionFut, RawTransactionRequest, - RawTransactionResult, RefundError, RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, - SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignRawTransactionRequest, SignatureResult, - SpendPaymentArgs, SwapOps, SwapTxTypeWithSecretHash, TakerSwapMakerCoin, TradeFee, TradePreimageError, - TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionData, TransactionDetails, - TransactionEnum, TransactionErr, TransactionFut, TransactionResult, TxFeeDetails, TxMarshalingErr, - UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, - ValidateOtherPubKeyErr, ValidatePaymentInput, ValidateWatcherSpendInput, VerificationError, - VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WatcherReward, WatcherRewardError, - WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WeakSpawner, - WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest}; + FeeApproxStage, FoundSwapTxSpend, HistorySyncState, MarketCoinOps, MmCoin, NegotiateSwapContractAddrErr, + NumConversError, PrivKeyPolicyNotAllowed, RawTransactionFut, RawTransactionRequest, RawTransactionResult, + RefundPaymentArgs, SearchForSwapTxSpendInput, SendPaymentArgs, SignRawTransactionRequest, SignatureResult, + SpendPaymentArgs, SwapOps, SwapTxTypeWithSecretHash, TradeFee, TradePreimageError, TradePreimageFut, + TradePreimageResult, TradePreimageValue, TransactionData, TransactionDetails, TransactionEnum, + TransactionErr, TransactionResult, TxFeeDetails, TxMarshalingErr, UnexpectedDerivationMethod, + ValidateAddressResult, ValidateFeeArgs, ValidateOtherPubKeyErr, ValidatePaymentInput, VerificationError, + VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WeakSpawner, WithdrawError, WithdrawFee, + WithdrawFut, WithdrawRequest}; use async_trait::async_trait; use base64::engine::general_purpose::STANDARD; use base64::Engine; @@ -1406,10 +1402,6 @@ impl SwapOps for SlpToken { utxo_common::search_for_swap_tx_spend_other(&self.platform_coin, input, SLP_SWAP_VOUT).await } - fn check_tx_signed_by_pub(&self, _tx: &[u8], _expected_pub: &[u8]) -> Result> { - unimplemented!(); - } - #[inline] async fn extract_secret( &self, @@ -1420,14 +1412,6 @@ impl SwapOps for SlpToken { utxo_common::extract_secret(secret_hash, spend_tx) } - fn is_auto_refundable(&self) -> bool { false } - - async fn wait_for_htlc_refund(&self, _tx: &[u8], _locktime: u64) -> RefundResult<()> { - MmError::err(RefundError::Internal( - "wait_for_htlc_refund is not supported for this coin!".into(), - )) - } - #[inline] fn negotiate_swap_contract_addr( &self, @@ -1448,124 +1432,10 @@ impl SwapOps for SlpToken { fn validate_other_pubkey(&self, raw_pubkey: &[u8]) -> MmResult<(), ValidateOtherPubKeyErr> { utxo_common::validate_other_pubkey(raw_pubkey) } - - async fn maker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - async fn taker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - fn validate_maker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } - - fn validate_taker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } -} - -#[async_trait] -impl TakerSwapMakerCoin for SlpToken { - async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - -#[async_trait] -impl MakerSwapTakerCoin for SlpToken { - async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } } #[async_trait] -impl WatcherOps for SlpToken { - fn create_maker_payment_spend_preimage( - &self, - _maker_payment_tx: &[u8], - _time_lock: u64, - _maker_pub: &[u8], - _secret_hash: &[u8], - _swap_unique_data: &[u8], - ) -> TransactionFut { - unimplemented!(); - } - - fn send_maker_payment_spend_preimage(&self, _input: SendMakerPaymentSpendPreimageInput) -> TransactionFut { - unimplemented!(); - } - - fn create_taker_payment_refund_preimage( - &self, - _taker_payment_tx: &[u8], - _time_lock: u64, - _maker_pub: &[u8], - _secret_hash: &[u8], - _swap_contract_address: &Option, - _swap_unique_data: &[u8], - ) -> TransactionFut { - unimplemented!(); - } - - fn send_taker_payment_refund_preimage(&self, _watcher_refunds_payment_args: RefundPaymentArgs) -> TransactionFut { - unimplemented!(); - } - - fn watcher_validate_taker_fee(&self, _input: WatcherValidateTakerFeeInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn watcher_validate_taker_payment(&self, _input: WatcherValidatePaymentInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn taker_validates_payment_spend_or_refund(&self, _input: ValidateWatcherSpendInput) -> ValidatePaymentFut<()> { - unimplemented!() - } - - async fn watcher_search_for_swap_tx_spend( - &self, - _input: WatcherSearchForSwapTxSpendInput<'_>, - ) -> Result, String> { - unimplemented!(); - } - - async fn get_taker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _coin_amount: Option, - _other_coin_amount: Option, - _reward_amount: Option, - _wait_until: u64, - ) -> Result> { - unimplemented!() - } - - async fn get_maker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _reward_amount: Option, - _wait_until: u64, - ) -> Result, MmError> { - unimplemented!() - } -} +impl WatcherOps for SlpToken {} impl From for TradePreimageError { fn from(slp: GenSlpSpendErr) -> TradePreimageError { diff --git a/mm2src/coins/utxo/utxo_common.rs b/mm2src/coins/utxo/utxo_common.rs index 0de323beb0..829646c407 100644 --- a/mm2src/coins/utxo/utxo_common.rs +++ b/mm2src/coins/utxo/utxo_common.rs @@ -2013,11 +2013,6 @@ where } } -pub fn check_all_inputs_signed_by_pub(tx: &[u8], expected_pub: &[u8]) -> Result> { - let tx: UtxoTx = deserialize(tx)?; - check_all_utxo_inputs_signed_by_pub(&tx, expected_pub) -} - pub fn check_all_utxo_inputs_signed_by_pub( tx: &UtxoTx, expected_pub: &[u8], diff --git a/mm2src/coins/utxo/utxo_standard.rs b/mm2src/coins/utxo/utxo_standard.rs index c0991f578b..43e703f222 100644 --- a/mm2src/coins/utxo/utxo_standard.rs +++ b/mm2src/coins/utxo/utxo_standard.rs @@ -25,18 +25,16 @@ use crate::utxo::utxo_tx_history_v2::{UtxoMyAddressesHistoryError, UtxoTxDetails use crate::{CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinBalanceMap, CoinWithDerivationMethod, CoinWithPrivKeyPolicy, CommonSwapOpsV2, ConfirmPaymentInput, DexFee, FindPaymentSpendError, FundingTxSpend, GenPreimageResult, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, - GetWithdrawSenderAddress, IguanaBalanceOps, IguanaPrivKey, MakerCoinSwapOpsV2, MakerSwapTakerCoin, - MmCoinEnum, NegotiateSwapContractAddrErr, PaymentInstructionArgs, PaymentInstructions, - PaymentInstructionsErr, PrivKeyBuildPolicy, RawTransactionRequest, RawTransactionResult, RefundError, + GetWithdrawSenderAddress, IguanaBalanceOps, IguanaPrivKey, MakerCoinSwapOpsV2, MmCoinEnum, + NegotiateSwapContractAddrErr, PrivKeyBuildPolicy, RawTransactionRequest, RawTransactionResult, RefundFundingSecretArgs, RefundMakerPaymentSecretArgs, RefundMakerPaymentTimelockArgs, RefundPaymentArgs, - RefundResult, RefundTakerPaymentArgs, SearchForFundingSpendErr, SearchForSwapTxSpendInput, - SendMakerPaymentArgs, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SendTakerFundingArgs, - SignRawTransactionRequest, SignatureResult, SpendMakerPaymentArgs, SpendPaymentArgs, SwapOps, - SwapTxTypeWithSecretHash, TakerCoinSwapOpsV2, TakerSwapMakerCoin, ToBytes, TradePreimageValue, - TransactionFut, TransactionResult, TxMarshalingErr, TxPreimageWithSig, ValidateAddressResult, - ValidateFeeArgs, ValidateInstructionsErr, ValidateMakerPaymentArgs, ValidateOtherPubKeyErr, - ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, ValidateSwapV2TxResult, - ValidateTakerFundingArgs, ValidateTakerFundingSpendPreimageResult, + RefundTakerPaymentArgs, SearchForFundingSpendErr, SearchForSwapTxSpendInput, SendMakerPaymentArgs, + SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SendTakerFundingArgs, SignRawTransactionRequest, + SignatureResult, SpendMakerPaymentArgs, SpendPaymentArgs, SwapOps, SwapTxTypeWithSecretHash, + TakerCoinSwapOpsV2, ToBytes, TradePreimageValue, TransactionFut, TransactionResult, TxMarshalingErr, + TxPreimageWithSig, ValidateAddressResult, ValidateFeeArgs, ValidateMakerPaymentArgs, + ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, + ValidateSwapV2TxResult, ValidateTakerFundingArgs, ValidateTakerFundingSpendPreimageResult, ValidateTakerPaymentSpendPreimageResult, ValidateWatcherSpendInput, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WithdrawFut}; @@ -424,11 +422,6 @@ impl SwapOps for UtxoStandardCoin { utxo_common::search_for_swap_tx_spend_other(self, input, utxo_common::DEFAULT_SWAP_VOUT).await } - #[inline] - fn check_tx_signed_by_pub(&self, tx: &[u8], expected_pub: &[u8]) -> Result> { - utxo_common::check_all_inputs_signed_by_pub(tx, expected_pub) - } - #[inline] async fn extract_secret( &self, @@ -446,14 +439,6 @@ impl SwapOps for UtxoStandardCoin { .map_err(|e| ERRL!("{}", e)) } - fn is_auto_refundable(&self) -> bool { false } - - async fn wait_for_htlc_refund(&self, _tx: &[u8], _locktime: u64) -> RefundResult<()> { - MmError::err(RefundError::Internal( - "wait_for_htlc_refund is not supported for this coin!".into(), - )) - } - #[inline] fn negotiate_swap_contract_addr( &self, @@ -475,53 +460,9 @@ impl SwapOps for UtxoStandardCoin { utxo_common::validate_other_pubkey(raw_pubkey) } - async fn maker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - async fn taker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - fn validate_maker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } - - fn validate_taker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } - fn is_supported_by_watchers(&self) -> bool { true } } -#[async_trait] -impl TakerSwapMakerCoin for UtxoStandardCoin { - async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - -#[async_trait] -impl MakerSwapTakerCoin for UtxoStandardCoin { - async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - #[async_trait] impl WatcherOps for UtxoStandardCoin { #[inline] diff --git a/mm2src/coins/z_coin.rs b/mm2src/coins/z_coin.rs index b2b9f34e72..a13b14e3b0 100644 --- a/mm2src/coins/z_coin.rs +++ b/mm2src/coins/z_coin.rs @@ -30,19 +30,15 @@ use crate::z_coin::storage::{BlockDbImpl, WalletDbShared}; use crate::z_coin::z_tx_history::{fetch_tx_history_from_db, ZCoinTxHistoryItem}; use crate::{BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, ConfirmPaymentInput, DexFee, - FeeApproxStage, FoundSwapTxSpend, HistorySyncState, MakerSwapTakerCoin, MarketCoinOps, MmCoin, MmCoinEnum, - NegotiateSwapContractAddrErr, NumConversError, PaymentInstructionArgs, PaymentInstructions, - PaymentInstructionsErr, PrivKeyActivationPolicy, PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, - RawTransactionFut, RawTransactionRequest, RawTransactionResult, RefundError, RefundPaymentArgs, - RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, - SignRawTransactionRequest, SignatureError, SignatureResult, SpendPaymentArgs, SwapOps, TakerSwapMakerCoin, + FeeApproxStage, FoundSwapTxSpend, HistorySyncState, MarketCoinOps, MmCoin, NegotiateSwapContractAddrErr, + NumConversError, PrivKeyActivationPolicy, PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, RawTransactionFut, + RawTransactionRequest, RawTransactionResult, RefundPaymentArgs, SearchForSwapTxSpendInput, + SendPaymentArgs, SignRawTransactionRequest, SignatureError, SignatureResult, SpendPaymentArgs, SwapOps, TradeFee, TradePreimageFut, TradePreimageResult, TradePreimageValue, Transaction, TransactionData, - TransactionDetails, TransactionEnum, TransactionFut, TransactionResult, TxFeeDetails, TxMarshalingErr, - UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, - ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, - ValidateWatcherSpendInput, VerificationError, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, - WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, - WatcherValidateTakerFeeInput, WeakSpawner, WithdrawError, WithdrawFut, WithdrawRequest}; + TransactionDetails, TransactionEnum, TransactionResult, TxFeeDetails, TxMarshalingErr, + UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateOtherPubKeyErr, + ValidatePaymentError, ValidatePaymentInput, VerificationError, VerificationResult, WaitForHTLCTxSpendArgs, + WatcherOps, WeakSpawner, WithdrawError, WithdrawFut, WithdrawRequest}; use async_trait::async_trait; use bitcrypto::dhash256; @@ -1511,18 +1507,6 @@ impl SwapOps for ZCoin { utxo_common::extract_secret(secret_hash, spend_tx) } - fn check_tx_signed_by_pub(&self, _tx: &[u8], _expected_pub: &[u8]) -> Result> { - unimplemented!(); - } - - fn is_auto_refundable(&self) -> bool { false } - - async fn wait_for_htlc_refund(&self, _tx: &[u8], _locktime: u64) -> RefundResult<()> { - MmError::err(RefundError::Internal( - "wait_for_htlc_refund is not supported for this coin!".into(), - )) - } - #[inline] fn negotiate_swap_contract_addr( &self, @@ -1552,124 +1536,10 @@ impl SwapOps for ZCoin { fn validate_other_pubkey(&self, raw_pubkey: &[u8]) -> MmResult<(), ValidateOtherPubKeyErr> { utxo_common::validate_other_pubkey(raw_pubkey) } - - async fn maker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - async fn taker_payment_instructions( - &self, - _args: PaymentInstructionArgs<'_>, - ) -> Result>, MmError> { - Ok(None) - } - - fn validate_maker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } - - fn validate_taker_payment_instructions( - &self, - _instructions: &[u8], - _args: PaymentInstructionArgs, - ) -> Result> { - MmError::err(ValidateInstructionsErr::UnsupportedCoin(self.ticker().to_string())) - } -} - -#[async_trait] -impl TakerSwapMakerCoin for ZCoin { - async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) } -} - -#[async_trait] -impl MakerSwapTakerCoin for ZCoin { - async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } - - async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) } } #[async_trait] -impl WatcherOps for ZCoin { - fn send_maker_payment_spend_preimage(&self, _input: SendMakerPaymentSpendPreimageInput) -> TransactionFut { - unimplemented!(); - } - - fn send_taker_payment_refund_preimage(&self, _watcher_refunds_payment_args: RefundPaymentArgs) -> TransactionFut { - unimplemented!(); - } - - fn create_taker_payment_refund_preimage( - &self, - _taker_payment_tx: &[u8], - _time_lock: u64, - _maker_pub: &[u8], - _secret_hash: &[u8], - _swap_contract_address: &Option, - _swap_unique_data: &[u8], - ) -> TransactionFut { - unimplemented!(); - } - - fn create_maker_payment_spend_preimage( - &self, - _maker_payment_tx: &[u8], - _time_lock: u64, - _maker_pub: &[u8], - _secret_hash: &[u8], - _swap_unique_data: &[u8], - ) -> TransactionFut { - unimplemented!(); - } - - fn watcher_validate_taker_fee(&self, _input: WatcherValidateTakerFeeInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn watcher_validate_taker_payment(&self, _input: WatcherValidatePaymentInput) -> ValidatePaymentFut<()> { - unimplemented!(); - } - - fn taker_validates_payment_spend_or_refund(&self, _input: ValidateWatcherSpendInput) -> ValidatePaymentFut<()> { - unimplemented!() - } - - async fn watcher_search_for_swap_tx_spend( - &self, - _input: WatcherSearchForSwapTxSpendInput<'_>, - ) -> Result, String> { - unimplemented!(); - } - - async fn get_taker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _coin_amount: Option, - _other_coin_amount: Option, - _reward_amount: Option, - _wait_until: u64, - ) -> Result> { - unimplemented!() - } - - async fn get_maker_watcher_reward( - &self, - _other_coin: &MmCoinEnum, - _reward_amount: Option, - _wait_until: u64, - ) -> Result, MmError> { - unimplemented!() - } -} +impl WatcherOps for ZCoin {} #[async_trait] impl MmCoin for ZCoin { diff --git a/mm2src/mm2_event_stream/src/manager.rs b/mm2src/mm2_event_stream/src/manager.rs index f9c895a2d1..9e6398c9ea 100644 --- a/mm2src/mm2_event_stream/src/manager.rs +++ b/mm2src/mm2_event_stream/src/manager.rs @@ -314,12 +314,16 @@ impl StreamingManager { /// In this case, we need to remove the streamer and de-list it from all clients. fn remove_streamer_if_down(&self, streamer_id: &str) { let mut this = self.write(); - let Some(streamer_info) = this.streamers.get(streamer_id) else { return }; + let Some(streamer_info) = this.streamers.get(streamer_id) else { + return; + }; if !streamer_info.is_down() { return; } // Remove the streamer from our registry. - let Some(streamer_info) = this.streamers.remove(streamer_id) else { return }; + let Some(streamer_info) = this.streamers.remove(streamer_id) else { + return; + }; // And remove the streamer from all clients listening to it. for client_id in streamer_info.clients { if let Some(info) = this.clients.get_mut(&client_id) { diff --git a/mm2src/mm2_net/src/event_streaming/sse_handler.rs b/mm2src/mm2_net/src/event_streaming/sse_handler.rs index cd5ba585b3..e6d061004e 100644 --- a/mm2src/mm2_net/src/event_streaming/sse_handler.rs +++ b/mm2src/mm2_net/src/event_streaming/sse_handler.rs @@ -29,7 +29,7 @@ pub async fn handle_sse(request: Request, ctx_h: u32) -> Response { let event_stream_manager = ctx.event_stream_manager.clone(); let Ok(mut rx) = event_stream_manager.new_client(client_id) else { - return handle_internal_error("ID already in use".to_string()).await + return handle_internal_error("ID already in use".to_string()).await; }; let body = Body::wrap_stream(async_stream::stream! { while let Some(event) = rx.recv().await {