From 9d7f4761c9792ded536b1c4d903d2ec43bab9c70 Mon Sep 17 00:00:00 2001 From: laruh Date: Wed, 16 Oct 2024 16:50:30 +0700 Subject: [PATCH 01/59] add wait_for_maker_payment_spend to MakerPaymentSpent, add wait_for_taker_payment_spend to TakerPaymentSpent --- mm2src/mm2_main/src/lp_ordermatch.rs | 2 + mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs | 43 ++++++++++++++++++++ mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 41 +++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index 620cb79bfb..ea05caf25c 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -3005,6 +3005,7 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO taker_p2p_pubkey: match taker_p2p_pubkey { PublicKey::Secp256k1(pubkey) => pubkey.into(), }, + require_taker_payment_spend_confirm: true, }; #[allow(clippy::box_default)] maker_swap_state_machine @@ -3164,6 +3165,7 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat PublicKey::Secp256k1(pubkey) => pubkey.into(), }, require_maker_payment_confirm_before_funding_spend: true, + require_maker_payment_spend_confirm: true, }; #[allow(clippy::box_default)] taker_swap_state_machine diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index d0e667a752..27506ee747 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -121,6 +121,7 @@ pub enum MakerSwapEvent { maker_payment: TransactionIdentifier, taker_payment: TransactionIdentifier, taker_payment_spend: TransactionIdentifier, + negotiation_data: StoredNegotiationData, }, /// Swap has been aborted before maker payment was sent. Aborted { reason: AbortReason }, @@ -387,6 +388,7 @@ pub struct MakerSwapStateMachine @@ -400,6 +402,9 @@ impl u64 { self.started_at + 2 * self.lock_duration } + #[inline] + fn taker_payment_locktime(&self) -> u64 { self.started_at + self.lock_duration } + /// Returns secret hash generated using selected [SecretHashAlgo]. fn secret_hash(&self) -> Vec { match self.secret_hash_algo { @@ -593,6 +598,7 @@ impl Box::new(TakerPaymentSpent { maker_coin_start_block, taker_coin_start_block, @@ -608,6 +614,11 @@ impl return MmError::err(SwapRecreateError::SwapAborted), MakerSwapEvent::Completed => return MmError::err(SwapRecreateError::SwapCompleted), @@ -645,6 +656,7 @@ impl TransitionFrom> for MakerPaymentRefundRequired { } +impl + TransitionFrom> for MakerPaymentRefundRequired +{ +} #[async_trait] impl State @@ -1707,6 +1723,7 @@ impl, } impl @@ -1754,6 +1772,30 @@ impl; async fn on_changed(self: Box, state_machine: &mut Self::StateMachine) -> StateResult { + if state_machine.require_taker_payment_spend_confirm { + match state_machine + .taker_coin + .wait_for_taker_payment_spend( + &self.taker_payment_spend, + self.taker_coin_start_block, + state_machine.taker_payment_locktime(), + ) + .await + { + Ok(_) => {}, + Err(e) => { + let next_state = MakerPaymentRefundRequired { + maker_coin_start_block: self.maker_coin_start_block, + taker_coin_start_block: self.taker_coin_start_block, + negotiation_data: self.negotiation_data, + maker_payment: self.maker_payment, + reason: MakerPaymentRefundReason::TakerPaymentNotConfirmedInTime(e.to_string()), + }; + return Self::change_state(next_state, state_machine).await; + }, + } + } + Self::change_state(Completed::new(), state_machine).await } } @@ -1779,6 +1821,7 @@ impl @@ -432,6 +434,9 @@ impl u64 { self.started_at + self.lock_duration } + #[inline] + fn maker_payment_locktime(&self) -> u64 { self.started_at + 2 * self.lock_duration } + fn unique_data(&self) -> Vec { self.uuid.as_bytes().to_vec() } /// Returns secret hash generated using selected [SecretHashAlgo]. @@ -702,6 +707,7 @@ impl Box::new(MakerPaymentSpent { maker_coin_start_block, taker_coin_start_block, @@ -721,6 +727,11 @@ impl return MmError::err(SwapRecreateError::SwapAborted), TakerSwapEvent::Completed => return MmError::err(SwapRecreateError::SwapCompleted), @@ -762,6 +773,7 @@ impl TransitionFrom> for TakerPaymentRefundRequired { } +impl + TransitionFrom> for TakerPaymentRefundRequired +{ +} #[async_trait] impl State @@ -2116,6 +2132,7 @@ impl, } impl @@ -2186,6 +2204,7 @@ impl; async fn on_changed(self: Box, state_machine: &mut Self::StateMachine) -> StateResult { + if state_machine.require_maker_payment_spend_confirm { + match state_machine + .maker_coin + .wait_for_maker_payment_spend( + &self.maker_payment_spend, + self.maker_coin_start_block, + state_machine.maker_payment_locktime(), + ) + .await + { + Ok(_) => {}, + Err(e) => { + let next_state = TakerPaymentRefundRequired { + taker_payment: self.taker_payment, + negotiation_data: self.negotiation_data, + reason: TakerPaymentRefundReason::MakerDidNotSpendInTime(format!("{}", e)), + }; + return Self::change_state(next_state, state_machine).await; + }, + } + } + Self::change_state(Completed::new(), state_machine).await } } From de3a970df4d9f4fb1da0db1c1c404357359124ef Mon Sep 17 00:00:00 2001 From: laruh Date: Sat, 19 Oct 2024 21:41:05 +0700 Subject: [PATCH 02/59] support Eth in lp bob/alice and use start_taker/maker_swap_state_machine --- mm2src/mm2_main/src/lp_ordermatch.rs | 500 +++++++++++++----- .../src/lp_ordermatch/my_orders_storage.rs | 2 + .../src/lp_ordermatch/new_protocol.rs | 6 + mm2src/mm2_main/src/ordermatch_tests.rs | 52 ++ .../tests/docker_tests/swap_proto_v2_tests.rs | 8 +- 5 files changed, 426 insertions(+), 142 deletions(-) diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index ea05caf25c..4aae993f2e 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -25,7 +25,7 @@ use blake2::digest::{Update, VariableOutput}; use blake2::Blake2bVar; use coins::utxo::{compressed_pub_key_from_priv_raw, ChecksumType, UtxoAddressFormat}; use coins::{coin_conf, find_pair, lp_coinfind, BalanceTradeFeeUpdatedHandler, CoinProtocol, CoinsContext, - FeeApproxStage, MarketCoinOps, MmCoinEnum}; + FeeApproxStage, MakerCoinSwapOpsV2, MmCoin, MmCoinEnum, TakerCoinSwapOpsV2}; use common::executor::{simple_map::AbortableSimpleMap, AbortSettings, AbortableSystem, AbortedError, SpawnAbortable, SpawnFuture, Timer}; use common::log::{error, warn, LogOnError}; @@ -57,6 +57,7 @@ use my_orders_storage::{delete_my_maker_order, delete_my_taker_order, save_maker use num_traits::identities::Zero; use parking_lot::Mutex as PaMutex; use rpc::v1::types::H256 as H256Json; +use secp256k1::PublicKey as Secp256k1Pubkey; use serde_json::{self as json, Value as Json}; use sp_trie::{delta_trie_root, MemoryDB, Trie, TrieConfiguration, TrieDB, TrieDBMut, TrieHash, TrieMut}; use std::collections::hash_map::{Entry, HashMap, RawEntryMut}; @@ -78,8 +79,8 @@ use crate::lp_swap::{calc_max_maker_vol, check_balance_for_maker_swap, check_bal generate_secret, get_max_maker_vol, insert_new_swap_to_db, is_pubkey_banned, lp_atomic_locktime, p2p_keypair_and_peer_id_to_broadcast, p2p_private_and_peer_id_to_broadcast, run_maker_swap, run_taker_swap, swap_v2_topic, AtomicLocktimeVersion, CheckBalanceError, CheckBalanceResult, - CoinVolumeInfo, MakerSwap, RunMakerSwapInput, RunTakerSwapInput, SwapConfirmationsSettings, - TakerSwap, LEGACY_SWAP_TYPE}; + CoinVolumeInfo, MakerSwap, RunMakerSwapInput, RunTakerSwapInput, SecretHashAlgo, + SwapConfirmationsSettings, TakerSwap, LEGACY_SWAP_TYPE}; #[cfg(any(test, feature = "run-docker-tests"))] use crate::lp_swap::taker_swap::FailAt; @@ -99,6 +100,7 @@ mod best_orders; mod lp_bot; pub use lp_bot::{start_simple_market_maker_bot, stop_simple_market_maker_bot, StartSimpleMakerBotRequest, TradingBotEvent}; +use primitives::hash::{H256, H264}; mod my_orders_storage; mod new_protocol; @@ -131,6 +133,8 @@ const TRIE_STATE_HISTORY_TIMEOUT: u64 = 3; const TRIE_ORDER_HISTORY_TIMEOUT: u64 = 300; #[cfg(test)] const TRIE_ORDER_HISTORY_TIMEOUT: u64 = 3; +/// Swap protocol version +const SWAP_VERSION: u32 = 2; pub type OrderbookP2PHandlerResult = Result<(), MmError>; @@ -1167,6 +1171,9 @@ pub struct TakerRequest { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] pub rel_protocol_info: Option>, + #[serde(default)] + #[serde(skip_serializing_if = "Option::is_none")] + pub swap_version: Option, } impl TakerRequest { @@ -1187,6 +1194,7 @@ impl TakerRequest { conf_settings: Some(message.conf_settings), base_protocol_info: message.base_protocol_info, rel_protocol_info: message.rel_protocol_info, + swap_version: message.swap_version, } } @@ -1232,6 +1240,7 @@ impl From for new_protocol::OrdermatchMessage { conf_settings: taker_order.request.conf_settings.unwrap(), base_protocol_info: taker_order.request.base_protocol_info, rel_protocol_info: taker_order.request.rel_protocol_info, + swap_version: taker_order.request.swap_version, }) } } @@ -1257,6 +1266,7 @@ pub struct TakerOrderBuilder<'a> { min_volume: Option, timeout: u64, save_in_history: bool, + swap_version: u32, } pub enum TakerOrderBuildError { @@ -1336,6 +1346,7 @@ impl<'a> TakerOrderBuilder<'a> { order_type: OrderType::GoodTillCancelled, timeout: TAKER_ORDER_TIMEOUT, save_in_history: true, + swap_version: SWAP_VERSION, } } @@ -1399,6 +1410,13 @@ impl<'a> TakerOrderBuilder<'a> { self } + pub fn with_tpu_version(mut self, use_trading_proto_v2: bool) -> Self { + if !use_trading_proto_v2 { + self.swap_version = 1; + } + self + } + /// Validate fields and build #[allow(clippy::result_large_err)] pub fn build(self) -> Result { @@ -1487,6 +1505,7 @@ impl<'a> TakerOrderBuilder<'a> { conf_settings: self.conf_settings, base_protocol_info: Some(base_protocol_info), rel_protocol_info: Some(rel_protocol_info), + swap_version: Some(self.swap_version), }, matches: Default::default(), min_volume, @@ -1527,6 +1546,7 @@ impl<'a> TakerOrderBuilder<'a> { conf_settings: self.conf_settings, base_protocol_info: Some(base_protocol_info), rel_protocol_info: Some(rel_protocol_info), + swap_version: Some(self.swap_version), }, matches: HashMap::new(), min_volume: Default::default(), @@ -1688,6 +1708,9 @@ pub struct MakerOrder { /// A custom priv key for more privacy to prevent linking orders of the same node between each other /// Commonly used with privacy coins (ARRR, ZCash, etc.) p2p_privkey: Option, + #[serde(default)] + #[serde(skip_serializing_if = "Option::is_none")] + pub swap_version: Option, } pub struct MakerOrderBuilder<'a> { @@ -1700,6 +1723,7 @@ pub struct MakerOrderBuilder<'a> { rel_orderbook_ticker: Option, conf_settings: Option, save_in_history: bool, + swap_version: u32, } pub enum MakerOrderBuildError { @@ -1849,6 +1873,7 @@ impl<'a> MakerOrderBuilder<'a> { price: 0.into(), conf_settings: None, save_in_history: true, + swap_version: SWAP_VERSION, } } @@ -1887,6 +1912,13 @@ impl<'a> MakerOrderBuilder<'a> { self } + pub fn with_tpu_version(mut self, use_trading_proto_v2: bool) -> Self { + if !use_trading_proto_v2 { + self.swap_version = 1; + } + self + } + /// Build MakerOrder #[allow(clippy::result_large_err)] pub fn build(self) -> Result { @@ -1943,6 +1975,7 @@ impl<'a> MakerOrderBuilder<'a> { base_orderbook_ticker: self.base_orderbook_ticker, rel_orderbook_ticker: self.rel_orderbook_ticker, p2p_privkey, + swap_version: Some(self.swap_version), }) } @@ -1967,6 +2000,7 @@ impl<'a> MakerOrderBuilder<'a> { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: Some(self.swap_version), } } } @@ -2097,6 +2131,7 @@ impl From for MakerOrder { base_orderbook_ticker: taker_order.base_orderbook_ticker, rel_orderbook_ticker: taker_order.rel_orderbook_ticker, p2p_privkey: taker_order.p2p_privkey, + swap_version: taker_order.request.swap_version, }, // The "buy" taker order is recreated with reversed pair as Maker order is always considered as "sell" TakerAction::Buy => { @@ -2119,6 +2154,7 @@ impl From for MakerOrder { base_orderbook_ticker: taker_order.rel_orderbook_ticker, rel_orderbook_ticker: taker_order.base_orderbook_ticker, p2p_privkey: taker_order.p2p_privkey, + swap_version: taker_order.request.swap_version, } }, } @@ -2171,6 +2207,9 @@ pub struct MakerReserved { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] pub rel_protocol_info: Option>, + #[serde(default)] + #[serde(skip_serializing_if = "Option::is_none")] + pub swap_version: Option, } impl MakerReserved { @@ -2198,6 +2237,7 @@ impl MakerReserved { conf_settings: Some(message.conf_settings), base_protocol_info: message.base_protocol_info, rel_protocol_info: message.rel_protocol_info, + swap_version: message.swap_version, } } } @@ -2214,6 +2254,7 @@ impl From for new_protocol::OrdermatchMessage { conf_settings: maker_reserved.conf_settings.unwrap(), base_protocol_info: maker_reserved.base_protocol_info, rel_protocol_info: maker_reserved.rel_protocol_info, + swap_version: maker_reserved.swap_version, }) } } @@ -2967,8 +3008,6 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO uuid ); - let now = now_sec(); - let secret = match generate_secret() { Ok(s) => s.into(), Err(e) => { @@ -2977,73 +3016,75 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO }, }; - if ctx.use_trading_proto_v2() { - let secret_hash_algo = detect_secret_hash_algo(&maker_coin, &taker_coin); - match (maker_coin, taker_coin) { + let alice_swap_v = maker_match.request.swap_version; + // if taker order doesn't have swap version or taker uses legacy swap protocol, start legacy swap + if alice_swap_v.is_none() || alice_swap_v == Some(1) { + let params = LegacySwapParams { + maker_coin: &maker_coin, + taker_coin: &taker_coin, + uuid: &uuid, + my_conf_settings: &my_conf_settings, + my_persistent_pub: &my_persistent_pub, + maker_amount: &maker_amount, + taker_amount: &taker_amount, + locktime: &lock_time, + }; + start_maker_legacy_swap(&ctx, maker_order, alice, secret, params).await; + return; + } + + if ctx.use_trading_proto_v2() && alice_swap_v == Some(2) { + let params = StateMachineParams { + secret_hash_algo: &detect_secret_hash_algo(&maker_coin, &taker_coin), + uuid: &uuid, + my_conf_settings: &my_conf_settings, + locktime: &lock_time, + maker_amount: &maker_amount, + taker_amount: &taker_amount, + }; + let taker_p2p_pubkey = match taker_p2p_pubkey { + PublicKey::Secp256k1(pubkey) => pubkey.into(), + }; + + match (&maker_coin, &taker_coin) { (MmCoinEnum::UtxoCoin(m), MmCoinEnum::UtxoCoin(t)) => { - let mut maker_swap_state_machine = MakerSwapStateMachine { - storage: MakerSwapStorage::new(ctx.clone()), - abortable_system: ctx - .abortable_system - .create_subsystem() - .expect("create_subsystem should not fail"), - ctx, - started_at: now_sec(), - maker_coin: m.clone(), - maker_volume: maker_amount, - secret, - taker_coin: t.clone(), - dex_fee: dex_fee_amount_from_taker_coin(&t, m.ticker(), &taker_amount), - taker_volume: taker_amount, - taker_premium: Default::default(), - conf_settings: my_conf_settings, - p2p_topic: swap_v2_topic(&uuid), - uuid, - p2p_keypair: maker_order.p2p_privkey.map(SerializableSecp256k1Keypair::into_inner), - secret_hash_algo, - lock_duration: lock_time, - taker_p2p_pubkey: match taker_p2p_pubkey { - PublicKey::Secp256k1(pubkey) => pubkey.into(), - }, - require_taker_payment_spend_confirm: true, + start_maker_swap_state_machine(&ctx, &maker_order, &taker_p2p_pubkey, &secret, m, t, ¶ms).await; + }, + (MmCoinEnum::EthCoin(m), MmCoinEnum::EthCoin(t)) => { + start_maker_swap_state_machine(&ctx, &maker_order, &taker_p2p_pubkey, &secret, m, t, ¶ms).await; + }, + (MmCoinEnum::UtxoCoin(m), MmCoinEnum::EthCoin(t)) => { + start_maker_swap_state_machine(&ctx, &maker_order, &taker_p2p_pubkey, &secret, m, t, ¶ms).await; + }, + (MmCoinEnum::EthCoin(m), MmCoinEnum::UtxoCoin(t)) => { + start_maker_swap_state_machine(&ctx, &maker_order, &taker_p2p_pubkey, &secret, m, t, ¶ms).await; + }, + _ => { + let params = LegacySwapParams { + maker_coin: &maker_coin, + taker_coin: &taker_coin, + uuid: &uuid, + my_conf_settings: &my_conf_settings, + my_persistent_pub: &my_persistent_pub, + maker_amount: &maker_amount, + taker_amount: &taker_amount, + locktime: &lock_time, }; - #[allow(clippy::box_default)] - maker_swap_state_machine - .run(Box::new(maker_swap_v2::Initialize::default())) - .await - .error_log(); + start_maker_legacy_swap(&ctx, maker_order, alice, secret, params).await }, - _ => todo!("implement fallback to the old protocol here"), } } else { - if let Err(e) = insert_new_swap_to_db( - ctx.clone(), - maker_coin.ticker(), - taker_coin.ticker(), - uuid, - now, - LEGACY_SWAP_TYPE, - ) - .await - { - error!("Error {} on new swap insertion", e); - } - let maker_swap = MakerSwap::new( - ctx.clone(), - alice, - maker_amount.to_decimal(), - taker_amount.to_decimal(), - my_persistent_pub, - uuid, - Some(maker_order.uuid), - my_conf_settings, - maker_coin, - taker_coin, - lock_time, - maker_order.p2p_privkey.map(SerializableSecp256k1Keypair::into_inner), - secret, - ); - run_maker_swap(RunMakerSwapInput::StartNew(maker_swap), ctx).await; + let params = LegacySwapParams { + maker_coin: &maker_coin, + taker_coin: &taker_coin, + uuid: &uuid, + my_conf_settings: &my_conf_settings, + my_persistent_pub: &my_persistent_pub, + maker_amount: &maker_amount, + taker_amount: &taker_amount, + locktime: &lock_time, + }; + start_maker_legacy_swap(&ctx, maker_order, alice, secret, params).await } }; @@ -3051,6 +3092,98 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO spawner.spawn_with_settings(fut, settings); } +struct LegacySwapParams<'a> { + maker_coin: &'a MmCoinEnum, + taker_coin: &'a MmCoinEnum, + uuid: &'a Uuid, + my_conf_settings: &'a SwapConfirmationsSettings, + my_persistent_pub: &'a H264, + maker_amount: &'a MmNumber, + taker_amount: &'a MmNumber, + locktime: &'a u64, +} + +async fn start_maker_legacy_swap( + ctx: &MmArc, + maker_order: MakerOrder, + alice: bits256, + secret: H256, + params: LegacySwapParams<'_>, +) { + if let Err(e) = insert_new_swap_to_db( + ctx.clone(), + params.maker_coin.ticker(), + params.taker_coin.ticker(), + *params.uuid, + now_sec(), + LEGACY_SWAP_TYPE, + ) + .await + { + error!("Error {} on new swap insertion", e); + } + + let maker_swap = MakerSwap::new( + ctx.clone(), + alice, + params.maker_amount.to_decimal(), + params.taker_amount.to_decimal(), + *params.my_persistent_pub, + *params.uuid, + Some(maker_order.uuid), + *params.my_conf_settings, + params.maker_coin.clone(), + params.taker_coin.clone(), + *params.locktime, + maker_order.p2p_privkey.map(SerializableSecp256k1Keypair::into_inner), + secret, + ); + run_maker_swap(RunMakerSwapInput::StartNew(maker_swap), ctx.clone()).await; +} + +async fn start_maker_swap_state_machine< + MakerCoin: MmCoin + MakerCoinSwapOpsV2 + Clone, + TakerCoin: MmCoin + TakerCoinSwapOpsV2 + Clone, +>( + ctx: &MmArc, + maker_order: &MakerOrder, + taker_p2p_pubkey: &Secp256k1Pubkey, + secret: &H256, + maker_coin: &MakerCoin, + taker_coin: &TakerCoin, + params: &StateMachineParams<'_>, +) { + let mut maker_swap_state_machine = MakerSwapStateMachine { + storage: MakerSwapStorage::new(ctx.clone()), + abortable_system: ctx + .abortable_system + .create_subsystem() + .expect("create_subsystem should not fail"), + ctx: ctx.clone(), + started_at: now_sec(), + maker_coin: maker_coin.clone(), + maker_volume: params.maker_amount.clone(), + secret: *secret, + taker_coin: taker_coin.clone(), + dex_fee: dex_fee_amount_from_taker_coin(taker_coin, maker_coin.ticker(), params.taker_amount), + taker_volume: params.taker_amount.clone(), + taker_premium: Default::default(), + conf_settings: *params.my_conf_settings, + p2p_topic: swap_v2_topic(params.uuid), + uuid: *params.uuid, + p2p_keypair: maker_order.p2p_privkey.map(SerializableSecp256k1Keypair::into_inner), + secret_hash_algo: *params.secret_hash_algo, + lock_duration: *params.locktime, + taker_p2p_pubkey: *taker_p2p_pubkey, + require_taker_payment_spend_confirm: true, + }; + #[allow(clippy::box_default)] + maker_swap_state_machine + .run(Box::new(maker_swap_v2::Initialize::default())) + .await + .error_log(); +} + fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMatch, maker_p2p_pubkey: PublicKey) { let spawner = ctx.spawner(); let uuid = taker_match.reserved.taker_order_uuid; @@ -3128,8 +3261,24 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat uuid ); - let now = now_sec(); - if ctx.use_trading_proto_v2() { + let bob_swap_v = taker_match.reserved.swap_version; + // if maker order doesn't have swap version or maker uses legacy swap protocol, start legacy swap + if bob_swap_v.is_none() || bob_swap_v == Some(1) { + let params = LegacySwapParams { + maker_coin: &maker_coin, + taker_coin: &taker_coin, + uuid: &uuid, + my_conf_settings: &my_conf_settings, + my_persistent_pub: &my_persistent_pub, + maker_amount: &maker_amount, + taker_amount: &taker_amount, + locktime: &locktime, + }; + start_taker_legacy_swap(&ctx, taker_order, maker, params).await; + return; + } + + if ctx.use_trading_proto_v2() && bob_swap_v == Some(2) { let taker_secret = match generate_secret() { Ok(s) => s.into(), Err(e) => { @@ -3137,78 +3286,61 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat return; }, }; - let secret_hash_algo = detect_secret_hash_algo(&maker_coin, &taker_coin); - match (maker_coin, taker_coin) { + let params = StateMachineParams { + secret_hash_algo: &detect_secret_hash_algo(&maker_coin, &taker_coin), + uuid: &uuid, + my_conf_settings: &my_conf_settings, + locktime: &locktime, + maker_amount: &maker_amount, + taker_amount: &taker_amount, + }; + let maker_p2p_pubkey = match maker_p2p_pubkey { + PublicKey::Secp256k1(pubkey) => pubkey.into(), + }; + + match (&maker_coin, &taker_coin) { (MmCoinEnum::UtxoCoin(m), MmCoinEnum::UtxoCoin(t)) => { - let mut taker_swap_state_machine = TakerSwapStateMachine { - storage: TakerSwapStorage::new(ctx.clone()), - abortable_system: ctx - .abortable_system - .create_subsystem() - .expect("create_subsystem should not fail"), - ctx, - started_at: now, - lock_duration: locktime, - maker_coin: m.clone(), - maker_volume: maker_amount, - taker_coin: t.clone(), - dex_fee: dex_fee_amount_from_taker_coin(&t, maker_coin_ticker, &taker_amount), - taker_volume: taker_amount, - taker_premium: Default::default(), - secret_hash_algo, - conf_settings: my_conf_settings, - p2p_topic: swap_v2_topic(&uuid), - uuid, - p2p_keypair: taker_order.p2p_privkey.map(SerializableSecp256k1Keypair::into_inner), - taker_secret, - maker_p2p_pubkey: match maker_p2p_pubkey { - PublicKey::Secp256k1(pubkey) => pubkey.into(), - }, - require_maker_payment_confirm_before_funding_spend: true, - require_maker_payment_spend_confirm: true, + start_taker_swap_state_machine(&ctx, &taker_order, &maker_p2p_pubkey, &taker_secret, m, t, ¶ms) + .await; + }, + (MmCoinEnum::EthCoin(m), MmCoinEnum::EthCoin(t)) => { + start_taker_swap_state_machine(&ctx, &taker_order, &maker_p2p_pubkey, &taker_secret, m, t, ¶ms) + .await; + }, + (MmCoinEnum::UtxoCoin(m), MmCoinEnum::EthCoin(t)) => { + start_taker_swap_state_machine(&ctx, &taker_order, &maker_p2p_pubkey, &taker_secret, m, t, ¶ms) + .await; + }, + (MmCoinEnum::EthCoin(m), MmCoinEnum::UtxoCoin(t)) => { + start_taker_swap_state_machine(&ctx, &taker_order, &maker_p2p_pubkey, &taker_secret, m, t, ¶ms) + .await; + }, + _ => { + let params = LegacySwapParams { + maker_coin: &maker_coin, + taker_coin: &taker_coin, + uuid: &uuid, + my_conf_settings: &my_conf_settings, + my_persistent_pub: &my_persistent_pub, + maker_amount: &maker_amount, + taker_amount: &taker_amount, + locktime: &locktime, }; - #[allow(clippy::box_default)] - taker_swap_state_machine - .run(Box::new(taker_swap_v2::Initialize::default())) - .await - .error_log(); + start_taker_legacy_swap(&ctx, taker_order, maker, params).await; }, - _ => todo!("implement fallback to the old protocol here"), } } else { - #[cfg(any(test, feature = "run-docker-tests"))] - let fail_at = std::env::var("TAKER_FAIL_AT").map(FailAt::from).ok(); - - if let Err(e) = insert_new_swap_to_db( - ctx.clone(), - taker_coin.ticker(), - maker_coin.ticker(), - uuid, - now, - LEGACY_SWAP_TYPE, - ) - .await - { - error!("Error {} on new swap insertion", e); - } - - let taker_swap = TakerSwap::new( - ctx.clone(), - maker, - maker_amount, - taker_amount, - my_persistent_pub, - uuid, - Some(uuid), - my_conf_settings, - maker_coin, - taker_coin, - locktime, - taker_order.p2p_privkey.map(SerializableSecp256k1Keypair::into_inner), - #[cfg(any(test, feature = "run-docker-tests"))] - fail_at, - ); - run_taker_swap(RunTakerSwapInput::StartNew(taker_swap), ctx).await + let params = LegacySwapParams { + maker_coin: &maker_coin, + taker_coin: &taker_coin, + uuid: &uuid, + my_conf_settings: &my_conf_settings, + my_persistent_pub: &my_persistent_pub, + maker_amount: &maker_amount, + taker_amount: &taker_amount, + locktime: &locktime, + }; + start_taker_legacy_swap(&ctx, taker_order, maker, params).await; } }; @@ -3216,6 +3348,95 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat spawner.spawn_with_settings(fut, settings) } +async fn start_taker_legacy_swap(ctx: &MmArc, taker_order: TakerOrder, maker: bits256, params: LegacySwapParams<'_>) { + #[cfg(any(test, feature = "run-docker-tests"))] + let fail_at = std::env::var("TAKER_FAIL_AT").map(FailAt::from).ok(); + + if let Err(e) = insert_new_swap_to_db( + ctx.clone(), + params.taker_coin.ticker(), + params.maker_coin.ticker(), + *params.uuid, + now_sec(), + LEGACY_SWAP_TYPE, + ) + .await + { + error!("Error {} on new swap insertion", e); + } + + let taker_swap = TakerSwap::new( + ctx.clone(), + maker, + params.maker_amount.clone(), + params.taker_amount.clone(), + *params.my_persistent_pub, + *params.uuid, + Some(*params.uuid), + *params.my_conf_settings, + params.maker_coin.clone(), + params.taker_coin.clone(), + *params.locktime, + taker_order.p2p_privkey.map(SerializableSecp256k1Keypair::into_inner), + #[cfg(any(test, feature = "run-docker-tests"))] + fail_at, + ); + run_taker_swap(RunTakerSwapInput::StartNew(taker_swap), ctx.clone()).await +} + +struct StateMachineParams<'a> { + secret_hash_algo: &'a SecretHashAlgo, + uuid: &'a Uuid, + my_conf_settings: &'a SwapConfirmationsSettings, + locktime: &'a u64, + maker_amount: &'a MmNumber, + taker_amount: &'a MmNumber, +} + +async fn start_taker_swap_state_machine< + MakerCoin: MmCoin + MakerCoinSwapOpsV2 + Clone, + TakerCoin: MmCoin + TakerCoinSwapOpsV2 + Clone, +>( + ctx: &MmArc, + taker_order: &TakerOrder, + maker_p2p_pubkey: &Secp256k1Pubkey, + taker_secret: &H256, + maker_coin: &MakerCoin, + taker_coin: &TakerCoin, + params: &StateMachineParams<'_>, +) { + let mut taker_swap_state_machine = TakerSwapStateMachine { + storage: TakerSwapStorage::new(ctx.clone()), + abortable_system: ctx + .abortable_system + .create_subsystem() + .expect("create_subsystem should not fail"), + ctx: ctx.clone(), + started_at: now_sec(), + lock_duration: *params.locktime, + maker_coin: maker_coin.clone(), + maker_volume: params.maker_amount.clone(), + taker_coin: taker_coin.clone(), + dex_fee: dex_fee_amount_from_taker_coin(taker_coin, taker_order.maker_coin_ticker(), params.taker_amount), + taker_volume: params.taker_amount.clone(), + taker_premium: Default::default(), + secret_hash_algo: *params.secret_hash_algo, + conf_settings: *params.my_conf_settings, + p2p_topic: swap_v2_topic(params.uuid), + uuid: *params.uuid, + p2p_keypair: taker_order.p2p_privkey.map(SerializableSecp256k1Keypair::into_inner), + taker_secret: *taker_secret, + maker_p2p_pubkey: *maker_p2p_pubkey, + require_maker_payment_confirm_before_funding_spend: true, + require_maker_payment_spend_confirm: true, + }; + #[allow(clippy::box_default)] + taker_swap_state_machine + .run(Box::new(taker_swap_v2::Initialize::default())) + .await + .error_log(); +} + pub async fn lp_ordermatch_loop(ctx: MmArc) { // lp_ordermatch_loop is spawned only if CryptoCtx is initialized let my_pubsecp = CryptoCtx::from_ctx(&ctx) @@ -3714,6 +3935,7 @@ async fn process_taker_request(ctx: MmArc, from_pubkey: H256Json, taker_request: }), base_protocol_info: Some(base_coin.coin_protocol_info(None)), rel_protocol_info: Some(rel_coin.coin_protocol_info(Some(rel_amount.clone()))), + swap_version: order.swap_version, }; let topic = order.orderbook_topic(); log::debug!("Request matched sending reserved {:?}", reserved); @@ -3946,7 +4168,8 @@ pub async fn lp_auto_buy( .with_sender_pubkey(H256Json::from(our_public_id.bytes)) .with_save_in_history(input.save_in_history) .with_base_orderbook_ticker(ordermatch_ctx.orderbook_ticker(base_coin.ticker())) - .with_rel_orderbook_ticker(ordermatch_ctx.orderbook_ticker(rel_coin.ticker())); + .with_rel_orderbook_ticker(ordermatch_ctx.orderbook_ticker(rel_coin.ticker())) + .with_tpu_version(ctx.use_trading_proto_v2()); if let Some(timeout) = input.timeout { order_builder = order_builder.with_timeout(timeout); } @@ -4691,7 +4914,8 @@ pub async fn create_maker_order(ctx: &MmArc, req: SetPriceReq) -> Result>, + #[serde(default)] + #[serde(skip_serializing_if = "Option::is_none")] + pub swap_version: Option, } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -282,6 +285,9 @@ pub struct MakerReserved { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] pub rel_protocol_info: Option>, + #[serde(default)] + #[serde(skip_serializing_if = "Option::is_none")] + pub swap_version: Option, } #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/mm2src/mm2_main/src/ordermatch_tests.rs b/mm2src/mm2_main/src/ordermatch_tests.rs index 1ac83697af..6735587cbd 100644 --- a/mm2src/mm2_main/src/ordermatch_tests.rs +++ b/mm2src/mm2_main/src/ordermatch_tests.rs @@ -39,6 +39,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }; let request = TakerRequest { @@ -54,6 +55,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let actual = maker.match_with_request(&request); @@ -77,6 +79,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }; let request = TakerRequest { @@ -92,6 +95,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let actual = maker.match_with_request(&request); @@ -115,6 +119,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }; let request = TakerRequest { @@ -130,6 +135,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let actual = maker.match_with_request(&request); @@ -153,6 +159,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }; let request = TakerRequest { @@ -168,6 +175,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let actual = maker.match_with_request(&request); @@ -191,6 +199,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }; let request = TakerRequest { @@ -206,6 +215,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let actual = maker.match_with_request(&request); @@ -229,6 +239,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }; let request = TakerRequest { @@ -244,6 +255,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let actual = maker.match_with_request(&request); @@ -269,6 +281,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }; let request = TakerRequest { base: "KMD".to_owned(), @@ -283,6 +296,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let actual = maker.match_with_request(&request); assert_eq!(actual, OrderMatchResult::NotMatched); @@ -309,6 +323,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }; let request = TakerRequest { base: "REL".to_owned(), @@ -323,6 +338,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let actual = maker.match_with_request(&request); let expected_base_amount = MmNumber::from(3); @@ -380,6 +396,7 @@ fn test_maker_order_available_amount() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }; maker.matches.insert(new_uuid(), MakerMatch { request: TakerRequest { @@ -395,6 +412,7 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }, reserved: MakerReserved { base: "BASE".into(), @@ -408,6 +426,7 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }, connect: None, connected: None, @@ -427,6 +446,7 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }, reserved: MakerReserved { base: "BASE".into(), @@ -440,6 +460,7 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }, connect: None, connected: None, @@ -468,6 +489,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let order = TakerOrder { @@ -495,6 +517,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -512,6 +535,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let order = TakerOrder { @@ -539,6 +563,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -556,6 +581,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let order = TakerOrder { @@ -583,6 +609,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -600,6 +627,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let order = TakerOrder { @@ -627,6 +655,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; assert_eq!(MatchReservedResult::NotMatched, order.match_reserved(&reserved)); @@ -644,6 +673,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let order = TakerOrder { @@ -671,6 +701,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -688,6 +719,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let order = TakerOrder { @@ -715,6 +747,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -732,6 +765,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let order = TakerOrder { @@ -759,6 +793,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -776,6 +811,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let order = TakerOrder { @@ -803,6 +839,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; assert_eq!(MatchReservedResult::NotMatched, order.match_reserved(&reserved)); @@ -824,6 +861,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }, matches: HashMap::new(), order_type: OrderType::GoodTillCancelled, @@ -847,6 +885,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -867,6 +906,7 @@ fn test_taker_order_cancellable() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let order = TakerOrder { @@ -897,6 +937,7 @@ fn test_taker_order_cancellable() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let mut order = TakerOrder { @@ -926,6 +967,7 @@ fn test_taker_order_cancellable() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }, connect: TakerConnect { sender_pubkey: H256Json::default(), @@ -974,6 +1016,7 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }, None, ); @@ -996,6 +1039,7 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }, None, ); @@ -1018,6 +1062,7 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }, None, ); @@ -1037,6 +1082,7 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }, order_type: OrderType::GoodTillCancelled, min_volume: 0.into(), @@ -1130,6 +1176,7 @@ fn test_taker_order_match_by() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; let mut order = TakerOrder { @@ -1157,6 +1204,7 @@ fn test_taker_order_match_by() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, + swap_version: None, }; assert_eq!(MatchReservedResult::NotMatched, order.match_reserved(&reserved)); @@ -1197,6 +1245,7 @@ fn test_maker_order_was_updated() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }; let mut update_msg = MakerOrderUpdated::new(maker_order.uuid); update_msg.with_new_price(BigRational::from_integer(2.into())); @@ -3203,6 +3252,7 @@ fn test_maker_order_balance_loops() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }; let morty_order = MakerOrder { @@ -3222,6 +3272,7 @@ fn test_maker_order_balance_loops() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }; assert!(!maker_orders_ctx.balance_loop_exists(rick_ticker)); @@ -3254,6 +3305,7 @@ fn test_maker_order_balance_loops() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, + swap_version: None, }; maker_orders_ctx.add_order(ctx.weak(), rick_order_2.clone(), None); diff --git a/mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs b/mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs index 304f6f4819..1cba25152b 100644 --- a/mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs @@ -699,8 +699,8 @@ fn test_v2_swap_utxo_utxo() { assert_eq!(locked_bob.locked_amount, expected); for uuid in uuids { - block_on(wait_for_swap_finished(&mm_bob, &uuid, 60)); - block_on(wait_for_swap_finished(&mm_alice, &uuid, 30)); + block_on(wait_for_swap_finished(&mm_bob, &uuid, 180)); + block_on(wait_for_swap_finished(&mm_alice, &uuid, 100)); let maker_swap_status = block_on(my_swap_status(&mm_bob, &uuid)); log!("{:?}", maker_swap_status); @@ -829,8 +829,8 @@ fn test_v2_swap_utxo_utxo_kickstart() { assert_eq!(locked_bob.locked_amount, expected); for uuid in uuids { - block_on(wait_for_swap_finished(&mm_bob, &uuid, 60)); - block_on(wait_for_swap_finished(&mm_alice, &uuid, 30)); + block_on(wait_for_swap_finished(&mm_bob, &uuid, 180)); + block_on(wait_for_swap_finished(&mm_alice, &uuid, 100)); } } From ea5475bd1d053ab0b70202afed7700160c3658ee Mon Sep 17 00:00:00 2001 From: laruh Date: Tue, 29 Oct 2024 19:23:09 +0700 Subject: [PATCH 03/59] use wait_for_confirmations in MakerPaymentSpent and in TakerPaymentSpent --- mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs | 40 ++++++++++---------- mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 36 +++++++++--------- 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index 27506ee747..a2334748bb 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -403,7 +403,7 @@ impl u64 { self.started_at + 2 * self.lock_duration } #[inline] - fn taker_payment_locktime(&self) -> u64 { self.started_at + self.lock_duration } + fn spend_taker_payment_conf_timeout(&self) -> u64 { self.started_at + 3 * self.lock_duration } /// Returns secret hash generated using selected [SecretHashAlgo]. fn secret_hash(&self) -> Vec { @@ -1423,6 +1423,7 @@ pub enum MakerPaymentRefundReason { TakerPaymentNotConfirmedInTime(String), DidNotGetTakerPaymentSpendPreimage(String), TakerPaymentSpendPreimageIsNotValid(String), + TakerPaymentSpendNotConfirmedInTime(String), FailedToParseTakerPreimage(String), FailedToParseTakerSignature(String), TakerPaymentSpendBroadcastFailed(String), @@ -1773,26 +1774,23 @@ impl, state_machine: &mut Self::StateMachine) -> StateResult { if state_machine.require_taker_payment_spend_confirm { - match state_machine - .taker_coin - .wait_for_taker_payment_spend( - &self.taker_payment_spend, - self.taker_coin_start_block, - state_machine.taker_payment_locktime(), - ) - .await - { - Ok(_) => {}, - Err(e) => { - let next_state = MakerPaymentRefundRequired { - maker_coin_start_block: self.maker_coin_start_block, - taker_coin_start_block: self.taker_coin_start_block, - negotiation_data: self.negotiation_data, - maker_payment: self.maker_payment, - reason: MakerPaymentRefundReason::TakerPaymentNotConfirmedInTime(e.to_string()), - }; - return Self::change_state(next_state, state_machine).await; - }, + let input = ConfirmPaymentInput { + payment_tx: self.taker_payment_spend.tx_hex(), + confirmations: state_machine.conf_settings.taker_coin_confs, + requires_nota: state_machine.conf_settings.taker_coin_nota, + wait_until: state_machine.spend_taker_payment_conf_timeout(), + check_every: 10, + }; + + if let Err(e) = state_machine.taker_coin.wait_for_confirmations(input).compat().await { + let next_state = MakerPaymentRefundRequired { + maker_coin_start_block: self.maker_coin_start_block, + taker_coin_start_block: self.taker_coin_start_block, + negotiation_data: self.negotiation_data, + maker_payment: self.maker_payment, + reason: MakerPaymentRefundReason::TakerPaymentSpendNotConfirmedInTime(e.to_string()), + }; + return Self::change_state(next_state, state_machine).await; } } diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs index 2f56e1f09c..c766843592 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs @@ -435,7 +435,7 @@ impl u64 { self.started_at + self.lock_duration } #[inline] - fn maker_payment_locktime(&self) -> u64 { self.started_at + 2 * self.lock_duration } + fn spend_maker_payment_conf_timeout(&self) -> u64 { self.started_at + 4 * self.lock_duration } fn unique_data(&self) -> Vec { self.uuid.as_bytes().to_vec() } @@ -1860,6 +1860,7 @@ impl, state_machine: &mut Self::StateMachine) -> StateResult { if state_machine.require_maker_payment_spend_confirm { - match state_machine - .maker_coin - .wait_for_maker_payment_spend( - &self.maker_payment_spend, - self.maker_coin_start_block, - state_machine.maker_payment_locktime(), - ) - .await - { - Ok(_) => {}, - Err(e) => { - let next_state = TakerPaymentRefundRequired { - taker_payment: self.taker_payment, - negotiation_data: self.negotiation_data, - reason: TakerPaymentRefundReason::MakerDidNotSpendInTime(format!("{}", e)), - }; - return Self::change_state(next_state, state_machine).await; - }, + let input = ConfirmPaymentInput { + payment_tx: self.maker_payment_spend.tx_hex(), + confirmations: state_machine.conf_settings.maker_coin_confs, + requires_nota: state_machine.conf_settings.maker_coin_nota, + wait_until: state_machine.spend_maker_payment_conf_timeout(), + check_every: 10, + }; + + if let Err(e) = state_machine.maker_coin.wait_for_confirmations(input).compat().await { + let next_state = TakerPaymentRefundRequired { + taker_payment: self.taker_payment, + negotiation_data: self.negotiation_data, + reason: TakerPaymentRefundReason::MakerPaymentSpendNotConfirmedInTime(format!("{}", e)), + }; + return Self::change_state(next_state, state_machine).await; } } From 934a2f0489dca416baa13ed704923b417d922867 Mon Sep 17 00:00:00 2001 From: laruh Date: Wed, 30 Oct 2024 19:15:08 +0700 Subject: [PATCH 04/59] rename wait_for_taker_payment_spend to find_taker_payment_spend_tx --- mm2src/coins/eth.rs | 8 ++++---- .../coins/eth/eth_swap_v2/eth_taker_swap_v2.rs | 10 +++++----- mm2src/coins/lp_coins.rs | 18 +++++++++--------- mm2src/coins/test_coin.rs | 10 +++++----- mm2src/coins/utxo/utxo_standard.rs | 8 ++++---- mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 3 ++- .../tests/docker_tests/eth_docker_tests.rs | 4 ++-- 7 files changed, 31 insertions(+), 30 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 53e3b472a0..b6daeaaf21 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -7375,14 +7375,14 @@ impl TakerCoinSwapOpsV2 for EthCoin { self.sign_and_broadcast_taker_payment_spend_impl(gen_args, secret).await } - /// Wrapper for [EthCoin::wait_for_taker_payment_spend_impl] - async fn wait_for_taker_payment_spend( + /// Wrapper for [EthCoin::find_taker_payment_spend_tx_impl] + async fn find_taker_payment_spend_tx( &self, taker_payment: &Self::Tx, _from_block: u64, wait_until: u64, - ) -> MmResult { - self.wait_for_taker_payment_spend_impl(taker_payment, wait_until).await + ) -> MmResult { + self.find_taker_payment_spend_tx_impl(taker_payment, wait_until).await } } diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index fea91b0408..f7e741a9b2 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -4,8 +4,8 @@ use crate::eth::{decode_contract_call, get_function_input_data, wei_from_big_dec ParseCoinAssocTypes, RefundFundingSecretArgs, RefundTakerPaymentArgs, SendTakerFundingArgs, SignedEthTx, SwapTxTypeWithSecretHash, TakerPaymentStateV2, TransactionErr, ValidateSwapV2TxError, ValidateSwapV2TxResult, ValidateTakerFundingArgs, TAKER_SWAP_V2}; -use crate::{FundingTxSpend, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, SearchForFundingSpendErr, - WaitForPaymentSpendError}; +use crate::{FindPaymentSpendError, FundingTxSpend, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, + SearchForFundingSpendErr}; use common::executor::Timer; use common::now_sec; use ethabi::{Function, Token}; @@ -459,11 +459,11 @@ impl EthCoin { /// Checks that taker payment state is `MakerSpent`. /// Accepts maker spent payment transaction and returns it if payment status is correct. - pub(crate) async fn wait_for_taker_payment_spend_impl( + pub(crate) async fn find_taker_payment_spend_tx_impl( &self, taker_payment: &SignedEthTx, wait_until: u64, - ) -> MmResult { + ) -> MmResult { let (decoded, taker_swap_v2_contract) = self .get_decoded_and_swap_contract(taker_payment, "spendTakerPayment") .await?; @@ -482,7 +482,7 @@ impl EthCoin { } let now = now_sec(); if now > wait_until { - return MmError::err(WaitForPaymentSpendError::Timeout { wait_until, now }); + return MmError::err(FindPaymentSpendError::Timeout { wait_until, now }); } Timer::sleep(10.).await; } diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 9b0e43fc2e..af6c7b09ad 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1783,7 +1783,7 @@ pub trait MakerNftSwapOpsV2: ParseCoinAssocTypes + ParseNftAssocTypes + Send + S /// Enum representing errors that can occur while waiting for taker payment spend. #[derive(Display, Debug, EnumFromStringify)] -pub enum WaitForPaymentSpendError { +pub enum FindPaymentSpendError { /// Timeout error variant, indicating that the wait for taker payment spend has timed out. #[display( fmt = "Timed out waiting for taker payment spend, wait_until {}, now {}", @@ -1806,18 +1806,18 @@ pub enum WaitForPaymentSpendError { Transport(String), } -impl From for WaitForPaymentSpendError { +impl From for FindPaymentSpendError { fn from(err: WaitForOutputSpendErr) -> Self { match err { - WaitForOutputSpendErr::Timeout { wait_until, now } => WaitForPaymentSpendError::Timeout { wait_until, now }, + WaitForOutputSpendErr::Timeout { wait_until, now } => FindPaymentSpendError::Timeout { wait_until, now }, WaitForOutputSpendErr::NoOutputWithIndex(index) => { - WaitForPaymentSpendError::InvalidInputTx(format!("Tx doesn't have output with index {}", index)) + FindPaymentSpendError::InvalidInputTx(format!("Tx doesn't have output with index {}", index)) }, } } } -impl From for WaitForPaymentSpendError { +impl From for FindPaymentSpendError { fn from(e: PaymentStatusErr) -> Self { match e { PaymentStatusErr::ABIError(e) => Self::ABIError(e), @@ -1828,7 +1828,7 @@ impl From for WaitForPaymentSpendError { } } -impl From for WaitForPaymentSpendError { +impl From for FindPaymentSpendError { fn from(e: PrepareTxDataError) -> Self { match e { PrepareTxDataError::ABIError(e) => Self::ABIError(e), @@ -1963,13 +1963,13 @@ pub trait TakerCoinSwapOpsV2: ParseCoinAssocTypes + CommonSwapOpsV2 + Send + Syn swap_unique_data: &[u8], ) -> Result; - /// Wait until taker payment spend is found on-chain - async fn wait_for_taker_payment_spend( + /// Wait until taker payment spend transaction is found on-chain + async fn find_taker_payment_spend_tx( &self, taker_payment: &Self::Tx, from_block: u64, wait_until: u64, - ) -> MmResult; + ) -> MmResult; } #[async_trait] diff --git a/mm2src/coins/test_coin.rs b/mm2src/coins/test_coin.rs index 43765ab0ba..932f0c7cb3 100644 --- a/mm2src/coins/test_coin.rs +++ b/mm2src/coins/test_coin.rs @@ -1,8 +1,8 @@ #![allow(clippy::all)] -use super::{CoinBalance, CommonSwapOpsV2, FundingTxSpend, HistorySyncState, MarketCoinOps, MmCoin, RawTransactionFut, - RawTransactionRequest, RefundTakerPaymentArgs, SearchForFundingSpendErr, SwapOps, TradeFee, - TransactionEnum, TransactionFut, WaitForPaymentSpendError}; +use super::{CoinBalance, CommonSwapOpsV2, FindPaymentSpendError, FundingTxSpend, HistorySyncState, MarketCoinOps, + MmCoin, RawTransactionFut, RawTransactionRequest, RefundTakerPaymentArgs, SearchForFundingSpendErr, + SwapOps, TradeFee, TransactionEnum, TransactionFut}; use crate::coin_errors::ValidatePaymentResult; use crate::{coin_errors::MyAddressError, BalanceFut, CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinFutSpawner, ConfirmPaymentInput, FeeApproxStage, FoundSwapTxSpend, GenPreimageResult, GenTakerFundingSpendArgs, @@ -557,12 +557,12 @@ impl TakerCoinSwapOpsV2 for TestCoin { unimplemented!() } - async fn wait_for_taker_payment_spend( + async fn find_taker_payment_spend_tx( &self, taker_payment: &Self::Tx, from_block: u64, wait_until: u64, - ) -> MmResult { + ) -> MmResult { unimplemented!() } } diff --git a/mm2src/coins/utxo/utxo_standard.rs b/mm2src/coins/utxo/utxo_standard.rs index f5a02f5095..94c8f477ed 100644 --- a/mm2src/coins/utxo/utxo_standard.rs +++ b/mm2src/coins/utxo/utxo_standard.rs @@ -23,7 +23,7 @@ use crate::utxo::utxo_hd_wallet::{UtxoHDAccount, UtxoHDAddress}; use crate::utxo::utxo_tx_history_v2::{UtxoMyAddressesHistoryError, UtxoTxDetailsError, UtxoTxDetailsParams, UtxoTxHistoryOps}; use crate::{CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinBalanceMap, CoinWithDerivationMethod, - CoinWithPrivKeyPolicy, CommonSwapOpsV2, ConfirmPaymentInput, DexFee, FundingTxSpend, GenPreimageResult, + CoinWithPrivKeyPolicy, CommonSwapOpsV2, ConfirmPaymentInput, DexFee, FindPaymentSpendError,FundingTxSpend, GenPreimageResult, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, GetWithdrawSenderAddress, IguanaBalanceOps, IguanaPrivKey, MakerCoinSwapOpsV2, MakerSwapTakerCoin, MmCoinEnum, NegotiateSwapContractAddrErr, PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, @@ -37,7 +37,7 @@ use crate::{CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinBalanceMap ValidateMakerPaymentArgs, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, ValidateSwapV2TxResult, ValidateTakerFundingArgs, ValidateTakerFundingSpendPreimageResult, ValidateTakerPaymentSpendPreimageResult, - ValidateWatcherSpendInput, VerificationResult, WaitForHTLCTxSpendArgs, WaitForPaymentSpendError, + ValidateWatcherSpendInput, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WithdrawFut}; use common::executor::{AbortableSystem, AbortedError}; @@ -866,12 +866,12 @@ impl TakerCoinSwapOpsV2 for UtxoStandardCoin { utxo_common::sign_and_broadcast_taker_payment_spend(self, preimage, gen_args, secret, &htlc_keypair).await } - async fn wait_for_taker_payment_spend( + async fn find_taker_payment_spend_tx( &self, taker_payment: &Self::Tx, from_block: u64, wait_until: u64, - ) -> MmResult { + ) -> MmResult { let res = utxo_common::wait_for_output_spend_impl( self.as_ref(), taker_payment, diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs index c766843592..55d90e9dfa 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs @@ -1697,7 +1697,7 @@ impl, state_machine: &mut Self::StateMachine) -> StateResult { let unique_data = state_machine.unique_data(); + // TODO: impl extract_secret_v2 as we cant reuse legacy method for Eth which uses v2 smart contracts let secret = match state_machine .taker_coin .extract_secret( diff --git a/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs b/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs index 22675745fc..ad68609e10 100644 --- a/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs @@ -1767,7 +1767,7 @@ fn taker_send_approve_and_spend_eth() { .unwrap(); log!("Maker spent ETH payment, tx hash: {:02x}", spend_tx.tx_hash()); wait_for_confirmations(&maker_coin, &spend_tx, 100); - block_on(taker_coin.wait_for_taker_payment_spend(&spend_tx, 0u64, payment_time_lock)).unwrap(); + block_on(taker_coin.find_taker_payment_spend_tx(&spend_tx, 0u64, payment_time_lock)).unwrap(); } #[cfg(feature = "sepolia-taker-swap-v2-tests")] @@ -1877,7 +1877,7 @@ fn taker_send_approve_and_spend_erc20() { block_on(maker_coin.sign_and_broadcast_taker_payment_spend(&preimage, &spend_args, &maker_secret, &[])) .unwrap(); log!("Maker spent ERC20 payment, tx hash: {:02x}", spend_tx.tx_hash()); - block_on(taker_coin.wait_for_taker_payment_spend(&spend_tx, 0u64, payment_time_lock)).unwrap(); + block_on(taker_coin.find_taker_payment_spend_tx(&spend_tx, 0u64, payment_time_lock)).unwrap(); } #[cfg(feature = "sepolia-taker-swap-v2-tests")] From ca0ee568e89b66a148db0340e531d73623292c7f Mon Sep 17 00:00:00 2001 From: laruh Date: Wed, 30 Oct 2024 22:12:33 +0700 Subject: [PATCH 05/59] EthCoin find_taker_payment_spend_tx_impl function now tries to find maker's spendTakerPayment transaction on chain --- mm2src/coins/eth.rs | 5 +- .../eth/eth_swap_v2/eth_taker_swap_v2.rs | 125 ++++++++++++++---- .../tests/docker_tests/eth_docker_tests.rs | 8 +- 3 files changed, 109 insertions(+), 29 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index b6daeaaf21..657cc3aa32 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -7379,10 +7379,11 @@ impl TakerCoinSwapOpsV2 for EthCoin { async fn find_taker_payment_spend_tx( &self, taker_payment: &Self::Tx, - _from_block: u64, + from_block: u64, wait_until: u64, ) -> MmResult { - self.find_taker_payment_spend_tx_impl(taker_payment, wait_until).await + self.find_taker_payment_spend_tx_impl(taker_payment, from_block, wait_until, 10.) + .await } } diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index f7e741a9b2..336fc49e64 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -1,12 +1,13 @@ use super::{check_decoded_length, validate_amount, validate_from_to_and_status, validate_payment_state, EthPaymentType, PaymentMethod, PrepareTxDataError, ZERO_VALUE}; -use crate::eth::{decode_contract_call, get_function_input_data, wei_from_big_decimal, EthCoin, EthCoinType, - ParseCoinAssocTypes, RefundFundingSecretArgs, RefundTakerPaymentArgs, SendTakerFundingArgs, - SignedEthTx, SwapTxTypeWithSecretHash, TakerPaymentStateV2, TransactionErr, ValidateSwapV2TxError, - ValidateSwapV2TxResult, ValidateTakerFundingArgs, TAKER_SWAP_V2}; -use crate::{FindPaymentSpendError, FundingTxSpend, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, +use crate::eth::{decode_contract_call, get_function_input_data, signed_tx_from_web3_tx, wei_from_big_decimal, EthCoin, + EthCoinType, ParseCoinAssocTypes, RefundFundingSecretArgs, RefundTakerPaymentArgs, + SendTakerFundingArgs, SignedEthTx, SwapTxTypeWithSecretHash, TakerPaymentStateV2, TransactionErr, + ValidateSwapV2TxError, ValidateSwapV2TxResult, ValidateTakerFundingArgs, TAKER_SWAP_V2}; +use crate::{FindPaymentSpendError, FundingTxSpend, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, MarketCoinOps, SearchForFundingSpendErr}; use common::executor::Timer; +use common::log::{error, info}; use common::now_sec; use ethabi::{Function, Token}; use ethcore_transaction::Action; @@ -15,7 +16,7 @@ use ethkey::public_to_address; use futures::compat::Future01CompatExt; use mm2_err_handle::prelude::{MapToMmResult, MmError, MmResult}; use std::convert::TryInto; -use web3::types::TransactionId; +use web3::types::{BlockNumber, FilterBuilder, Log, TransactionId}; const ETH_TAKER_PAYMENT: &str = "ethTakerPayment"; const ERC20_TAKER_PAYMENT: &str = "erc20TakerPayment"; @@ -457,37 +458,111 @@ impl EthCoin { Ok(spend_payment_tx) } - /// Checks that taker payment state is `MakerSpent`. - /// Accepts maker spent payment transaction and returns it if payment status is correct. pub(crate) async fn find_taker_payment_spend_tx_impl( &self, - taker_payment: &SignedEthTx, + taker_payment: &SignedEthTx, // it's approve_tx in Eth case, as in sign_and_send_taker_funding_spend we return approve_tx tx for it + from_block: u64, wait_until: u64, + check_every: f64, ) -> MmResult { - let (decoded, taker_swap_v2_contract) = self - .get_decoded_and_swap_contract(taker_payment, "spendTakerPayment") - .await?; + let taker_swap_v2_contract = self + .swap_v2_contracts + .as_ref() + .map(|contracts| contracts.taker_swap_v2_contract) + .ok_or_else(|| { + FindPaymentSpendError::Internal("Expected swap_v2_contracts to be Some, but found None".to_string()) + })?; + let approve_func = TAKER_SWAP_V2.function(TAKER_PAYMENT_APPROVE)?; + let decoded = decode_contract_call(approve_func, taker_payment.unsigned().data())?; + let id = match decoded.first() { + Some(Token::FixedBytes(bytes)) => bytes, + invalid_token => { + return MmError::err(FindPaymentSpendError::InvalidData(format!( + "Expected Token::FixedBytes, got {:?}", + invalid_token + ))) + }, + }; + // loop to find maker's spendTakerPayment transaction loop { - let taker_status = self - .payment_status_v2( - taker_swap_v2_contract, - decoded[0].clone(), // id from spendTakerPayment - &TAKER_SWAP_V2, - EthPaymentType::TakerPayments, - TAKER_PAYMENT_STATE_INDEX, - ) - .await?; - if taker_status == U256::from(TakerPaymentStateV2::MakerSpent as u8) { - return Ok(taker_payment.clone()); - } let now = now_sec(); if now > wait_until { return MmError::err(FindPaymentSpendError::Timeout { wait_until, now }); } - Timer::sleep(10.).await; + + let current_block = match self.current_block().compat().await { + Ok(b) => b, + Err(e) => { + error!("Error getting block number: {}", e); + Timer::sleep(5.).await; + continue; + }, + }; + + // get all logged TakerPaymentSpent events from `from_block` till current block + let events = match self + .events_from_block(taker_swap_v2_contract, "TakerPaymentSpent", from_block, current_block) + .await + { + Ok(events) => events, + Err(e) => { + error!( + "Error getting TakerPaymentSpent events from {} block: {}", + from_block, e + ); + Timer::sleep(5.).await; + continue; + }, + }; + + // this is how spent event looks like in EtomicSwapTakerV2: event TakerPaymentSpent(bytes32 id, bytes32 secret) + let found_event = events.into_iter().find(|event| &event.data.0[..32] == id.as_slice()); + + if let Some(event) = found_event { + if let Some(tx_hash) = event.transaction_hash { + let transaction = match self.transaction(TransactionId::Hash(tx_hash)).await { + Ok(Some(t)) => t, + Ok(None) => { + info!("Tx {} not found yet", tx_hash); + Timer::sleep(check_every).await; + continue; + }, + Err(e) => { + error!("Get tx {} error: {}", tx_hash, e); + Timer::sleep(check_every).await; + continue; + }, + }; + let result = signed_tx_from_web3_tx(transaction).map_err(FindPaymentSpendError::Internal)?; + return Ok(result); + } + } + + Timer::sleep(5.).await; } } + async fn events_from_block( + &self, + swap_contract_address: Address, + event_name: &str, + from_block: u64, + to_block: u64, + ) -> MmResult, FindPaymentSpendError> { + let contract_event = TAKER_SWAP_V2.event(event_name)?; + let filter = FilterBuilder::default() + .topics(Some(vec![contract_event.signature()]), None, None, None) + .from_block(BlockNumber::Number(from_block.into())) + .to_block(BlockNumber::Number(to_block.into())) + .address(vec![swap_contract_address]) + .build(); + let events_logs = self + .logs(filter) + .await + .map_err(|e| FindPaymentSpendError::Transport(e.to_string()))?; + Ok(events_logs) + } + /// Prepares data for EtomicSwapTakerV2 contract [ethTakerPayment](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapTakerV2.sol#L44) method async fn prepare_taker_eth_funding_data(&self, args: &TakerFundingArgs) -> Result, PrepareTxDataError> { let function = TAKER_SWAP_V2.function(ETH_TAKER_PAYMENT)?; diff --git a/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs b/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs index ad68609e10..700600a380 100644 --- a/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs @@ -1694,6 +1694,7 @@ fn taker_send_approve_and_spend_eth() { swap_unique_data: &[], }; wait_pending_transactions(Address::from_slice(taker_address.as_bytes())); + let taker_coin_start_block = block_on(taker_coin.current_block().compat()).unwrap(); let funding_tx = block_on(taker_coin.send_taker_funding(payment_args)).unwrap(); log!("Taker sent ETH funding, tx hash: {:02x}", funding_tx.tx_hash()); wait_for_confirmations(&taker_coin, &funding_tx, 100); @@ -1767,7 +1768,8 @@ fn taker_send_approve_and_spend_eth() { .unwrap(); log!("Maker spent ETH payment, tx hash: {:02x}", spend_tx.tx_hash()); wait_for_confirmations(&maker_coin, &spend_tx, 100); - block_on(taker_coin.find_taker_payment_spend_tx(&spend_tx, 0u64, payment_time_lock)).unwrap(); + block_on(taker_coin.find_taker_payment_spend_tx(&taker_approve_tx, taker_coin_start_block, payment_time_lock)) + .unwrap(); } #[cfg(feature = "sepolia-taker-swap-v2-tests")] @@ -1805,6 +1807,7 @@ fn taker_send_approve_and_spend_erc20() { swap_unique_data: &[], }; wait_pending_transactions(Address::from_slice(taker_address.as_bytes())); + let taker_coin_start_block = block_on(taker_coin.current_block().compat()).unwrap(); let funding_tx = block_on(taker_coin.send_taker_funding(payment_args)).unwrap(); log!("Taker sent ERC20 funding, tx hash: {:02x}", funding_tx.tx_hash()); wait_for_confirmations(&taker_coin, &funding_tx, 100); @@ -1877,7 +1880,8 @@ fn taker_send_approve_and_spend_erc20() { block_on(maker_coin.sign_and_broadcast_taker_payment_spend(&preimage, &spend_args, &maker_secret, &[])) .unwrap(); log!("Maker spent ERC20 payment, tx hash: {:02x}", spend_tx.tx_hash()); - block_on(taker_coin.find_taker_payment_spend_tx(&spend_tx, 0u64, payment_time_lock)).unwrap(); + block_on(taker_coin.find_taker_payment_spend_tx(&taker_approve_tx, taker_coin_start_block, payment_time_lock)) + .unwrap(); } #[cfg(feature = "sepolia-taker-swap-v2-tests")] From 9449cca9bcb6be5f3de7fa9edcfe0ff8e2c62932 Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 31 Oct 2024 21:04:55 +0700 Subject: [PATCH 06/59] provide extract_secret_v2 in TakerSwapOpsV2, implement EthCoin extract_secret_v2 --- mm2src/coins/eth.rs | 4 ++ .../eth/eth_swap_v2/eth_taker_swap_v2.rs | 40 +++++++++++++++++++ mm2src/coins/lp_coins.rs | 2 + mm2src/coins/test_coin.rs | 4 ++ mm2src/coins/utxo/utxo_common.rs | 24 +++++++++++ mm2src/coins/utxo/utxo_standard.rs | 4 ++ mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 7 +--- 7 files changed, 79 insertions(+), 6 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 657cc3aa32..18a94810bd 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -7385,6 +7385,10 @@ impl TakerCoinSwapOpsV2 for EthCoin { self.find_taker_payment_spend_tx_impl(taker_payment, from_block, wait_until, 10.) .await } + + async fn extract_secret_v2(&self, secret_hash: &[u8], spend_tx: &Self::Tx) -> Result, String> { + self.extract_secret_v2_impl(secret_hash, spend_tx).await + } } impl CommonSwapOpsV2 for EthCoin { diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index 336fc49e64..ea75bd38a4 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -767,6 +767,46 @@ impl EthCoin { Ok((decoded, taker_swap_v2_contract)) } + + /// Extracts the maker's secret from the input of transaction that calls the `spendTakerPayment` smart contract method. + /// + /// function spendTakerPayment( + /// bytes32 id, + /// uint256 amount, + /// uint256 dexFee, + /// address taker, + /// bytes32 takerSecretHash, + /// bytes32 makerSecret, + /// address tokenAddress + /// ) + pub(crate) async fn extract_secret_v2_impl( + &self, + _secret_hash: &[u8], + spend_tx: &SignedEthTx, + ) -> Result, String> { + let function = try_s!(TAKER_SWAP_V2.function("spendTakerPayment")); + // should be 0xcc90c199 + let expected_signature = function.short_signature(); + let signature = &spend_tx.unsigned().data()[0..4]; + if signature != expected_signature { + return ERR!( + "Expected 'spendTakerPayment' contract call signature: {:?}, found {:?}", + expected_signature, + signature + ); + }; + let decoded = try_s!(decode_contract_call(function, spend_tx.unsigned().data())); + if decoded.len() < 7 { + return ERR!("Invalid arguments in 'spendTakerPayment' call: {:?}", decoded); + } + match &decoded[5] { + Token::FixedBytes(secret) => Ok(secret.to_vec()), + _ => ERR!( + "Expected secret to be fixed bytes, but decoded function data is {:?}", + decoded + ), + } + } } /// Validation function for ETH taker payment data diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index af6c7b09ad..b27edc3b68 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1970,6 +1970,8 @@ pub trait TakerCoinSwapOpsV2: ParseCoinAssocTypes + CommonSwapOpsV2 + Send + Syn from_block: u64, wait_until: u64, ) -> MmResult; + + async fn extract_secret_v2(&self, secret_hash: &[u8], spend_tx: &Self::Tx) -> Result, String>; } #[async_trait] diff --git a/mm2src/coins/test_coin.rs b/mm2src/coins/test_coin.rs index 932f0c7cb3..d3068b812a 100644 --- a/mm2src/coins/test_coin.rs +++ b/mm2src/coins/test_coin.rs @@ -565,6 +565,10 @@ impl TakerCoinSwapOpsV2 for TestCoin { ) -> MmResult { unimplemented!() } + + async fn extract_secret_v2(&self, secret_hash: &[u8], spend_tx: &Self::Tx) -> Result, String> { + unimplemented!() + } } impl CommonSwapOpsV2 for TestCoin { diff --git a/mm2src/coins/utxo/utxo_common.rs b/mm2src/coins/utxo/utxo_common.rs index 37955e9030..5d5ec59b02 100644 --- a/mm2src/coins/utxo/utxo_common.rs +++ b/mm2src/coins/utxo/utxo_common.rs @@ -2605,6 +2605,30 @@ pub fn extract_secret(secret_hash: &[u8], spend_tx: &[u8]) -> Result, St ERR!("Couldn't extract secret") } +/// Extract a secret from the `spend_tx`. +/// Note spender could generate the spend with several inputs where the only one input is the p2sh script. +pub fn extract_secret_v2(secret_hash: &[u8], spend_tx: &UtxoTx) -> Result, String> { + let expected_secret_hash = if secret_hash.len() == 32 { + ripemd160(secret_hash) + } else { + H160::from(secret_hash) + }; + for input in spend_tx.inputs.iter() { + let script: Script = input.script_sig.clone().into(); + for instruction in script.iter().flatten() { + if instruction.opcode == Opcode::OP_PUSHBYTES_32 { + if let Some(secret) = instruction.data { + let actual_secret_hash = dhash160(secret); + if actual_secret_hash == expected_secret_hash { + return Ok(secret.to_vec()); + } + } + } + } + } + ERR!("Couldn't extract secret") +} + pub fn my_address(coin: &T) -> MmResult { match coin.as_ref().derivation_method { DerivationMethod::SingleAddress(ref my_address) => { diff --git a/mm2src/coins/utxo/utxo_standard.rs b/mm2src/coins/utxo/utxo_standard.rs index 94c8f477ed..c7ba7937d1 100644 --- a/mm2src/coins/utxo/utxo_standard.rs +++ b/mm2src/coins/utxo/utxo_standard.rs @@ -883,6 +883,10 @@ impl TakerCoinSwapOpsV2 for UtxoStandardCoin { .await?; Ok(res) } + + async fn extract_secret_v2(&self, secret_hash: &[u8], spend_tx: &Self::Tx) -> Result, String> { + utxo_common::extract_secret_v2(secret_hash, spend_tx) + } } impl CommonSwapOpsV2 for UtxoStandardCoin { diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs index 55d90e9dfa..3ea6261b0e 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs @@ -2087,14 +2087,9 @@ impl, state_machine: &mut Self::StateMachine) -> StateResult { let unique_data = state_machine.unique_data(); - // TODO: impl extract_secret_v2 as we cant reuse legacy method for Eth which uses v2 smart contracts let secret = match state_machine .taker_coin - .extract_secret( - &self.negotiation_data.maker_secret_hash, - &self.taker_payment_spend.tx_hex(), - false, - ) + .extract_secret_v2(&self.negotiation_data.maker_secret_hash, &self.taker_payment_spend) .await { Ok(s) => s, From 2e65abf1156b4c1c31b265a9033b8d4b6df34e5c Mon Sep 17 00:00:00 2001 From: laruh Date: Mon, 4 Nov 2024 14:39:09 +0700 Subject: [PATCH 07/59] reuse utxo extract_secret_v2 in legacy extract_secret --- mm2src/coins/utxo/utxo_common.rs | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/mm2src/coins/utxo/utxo_common.rs b/mm2src/coins/utxo/utxo_common.rs index 5d5ec59b02..fde60ef42a 100644 --- a/mm2src/coins/utxo/utxo_common.rs +++ b/mm2src/coins/utxo/utxo_common.rs @@ -2584,25 +2584,7 @@ pub async fn get_taker_watcher_reward Result, String> { let spend_tx: UtxoTx = try_s!(deserialize(spend_tx).map_err(|e| ERRL!("{:?}", e))); - let expected_secret_hash = if secret_hash.len() == 32 { - ripemd160(secret_hash) - } else { - H160::from(secret_hash) - }; - for input in spend_tx.inputs.into_iter() { - let script: Script = input.script_sig.clone().into(); - for instruction in script.iter().flatten() { - if instruction.opcode == Opcode::OP_PUSHBYTES_32 { - if let Some(secret) = instruction.data { - let actual_secret_hash = dhash160(secret); - if actual_secret_hash == expected_secret_hash { - return Ok(secret.to_vec()); - } - } - } - } - } - ERR!("Couldn't extract secret") + extract_secret_v2(secret_hash, &spend_tx) } /// Extract a secret from the `spend_tx`. From 43a1bafaca3c0674b9b3378231120698fb0f429c Mon Sep 17 00:00:00 2001 From: laruh Date: Mon, 4 Nov 2024 15:36:45 +0700 Subject: [PATCH 08/59] eth extract_secret_v2 tests --- .../tests/docker_tests/eth_docker_tests.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs b/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs index 700600a380..a5cf0bcc30 100644 --- a/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs @@ -1768,8 +1768,11 @@ fn taker_send_approve_and_spend_eth() { .unwrap(); log!("Maker spent ETH payment, tx hash: {:02x}", spend_tx.tx_hash()); wait_for_confirmations(&maker_coin, &spend_tx, 100); - block_on(taker_coin.find_taker_payment_spend_tx(&taker_approve_tx, taker_coin_start_block, payment_time_lock)) - .unwrap(); + let found_spend_tx = + block_on(taker_coin.find_taker_payment_spend_tx(&taker_approve_tx, taker_coin_start_block, payment_time_lock)) + .unwrap(); + let extracted_maker_secret = block_on(taker_coin.extract_secret_v2(&[], &found_spend_tx)).unwrap(); + assert_eq!(maker_secret, extracted_maker_secret); } #[cfg(feature = "sepolia-taker-swap-v2-tests")] @@ -1880,8 +1883,11 @@ fn taker_send_approve_and_spend_erc20() { block_on(maker_coin.sign_and_broadcast_taker_payment_spend(&preimage, &spend_args, &maker_secret, &[])) .unwrap(); log!("Maker spent ERC20 payment, tx hash: {:02x}", spend_tx.tx_hash()); - block_on(taker_coin.find_taker_payment_spend_tx(&taker_approve_tx, taker_coin_start_block, payment_time_lock)) - .unwrap(); + let found_spend_tx = + block_on(taker_coin.find_taker_payment_spend_tx(&taker_approve_tx, taker_coin_start_block, payment_time_lock)) + .unwrap(); + let extracted_maker_secret = block_on(taker_coin.extract_secret_v2(&[], &found_spend_tx)).unwrap(); + assert_eq!(maker_secret, extracted_maker_secret); } #[cfg(feature = "sepolia-taker-swap-v2-tests")] From c700b59ae5bb564241389cd6d6d930d78be4d948 Mon Sep 17 00:00:00 2001 From: laruh Date: Fri, 8 Nov 2024 21:54:06 +0700 Subject: [PATCH 09/59] cargo fmt --- mm2src/coins/utxo/utxo_standard.rs | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mm2src/coins/utxo/utxo_standard.rs b/mm2src/coins/utxo/utxo_standard.rs index c7ba7937d1..85e2d1b383 100644 --- a/mm2src/coins/utxo/utxo_standard.rs +++ b/mm2src/coins/utxo/utxo_standard.rs @@ -23,22 +23,22 @@ use crate::utxo::utxo_hd_wallet::{UtxoHDAccount, UtxoHDAddress}; use crate::utxo::utxo_tx_history_v2::{UtxoMyAddressesHistoryError, UtxoTxDetailsError, UtxoTxDetailsParams, UtxoTxHistoryOps}; 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, 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, ValidateTakerPaymentSpendPreimageResult, - ValidateWatcherSpendInput, VerificationResult, WaitForHTLCTxSpendArgs, - WatcherOps, WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, + CoinWithPrivKeyPolicy, CommonSwapOpsV2, ConfirmPaymentInput, DexFee, FindPaymentSpendError, + FundingTxSpend, GenPreimageResult, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, + GetWithdrawSenderAddress, IguanaBalanceOps, IguanaPrivKey, MakerCoinSwapOpsV2, MakerSwapTakerCoin, + MmCoinEnum, NegotiateSwapContractAddrErr, PaymentInstructionArgs, PaymentInstructions, + PaymentInstructionsErr, PrivKeyBuildPolicy, RawTransactionRequest, RawTransactionResult, RefundError, + 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, + ValidateTakerPaymentSpendPreimageResult, ValidateWatcherSpendInput, VerificationResult, + WaitForHTLCTxSpendArgs, WatcherOps, WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WithdrawFut}; use common::executor::{AbortableSystem, AbortedError}; use futures::{FutureExt, TryFutureExt}; From 8d5ed46f1d2e935e270fd2144afc7c400ad4860e Mon Sep 17 00:00:00 2001 From: laruh Date: Tue, 12 Nov 2024 19:54:51 +0700 Subject: [PATCH 10/59] review: remove unnecessary param from extract_secret_v2_impl, add events.is_empty() check, rename with_tpu_version function. --- mm2src/coins/eth.rs | 4 ++-- .../coins/eth/eth_swap_v2/eth_taker_swap_v2.rs | 15 ++++++++++----- mm2src/mm2_main/src/lp_ordermatch.rs | 16 ++++++++++++---- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 18a94810bd..09b9c2b976 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -7386,8 +7386,8 @@ impl TakerCoinSwapOpsV2 for EthCoin { .await } - async fn extract_secret_v2(&self, secret_hash: &[u8], spend_tx: &Self::Tx) -> Result, String> { - self.extract_secret_v2_impl(secret_hash, spend_tx).await + async fn extract_secret_v2(&self, _secret_hash: &[u8], spend_tx: &Self::Tx) -> Result, String> { + self.extract_secret_v2_impl(spend_tx).await } } diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index ea75bd38a4..4a19645fc3 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -515,6 +515,15 @@ impl EthCoin { }, }; + if events.is_empty() { + info!( + "No events found yet for the block range {} to {}", + from_block, current_block + ); + Timer::sleep(5.).await; + continue; + } + // this is how spent event looks like in EtomicSwapTakerV2: event TakerPaymentSpent(bytes32 id, bytes32 secret) let found_event = events.into_iter().find(|event| &event.data.0[..32] == id.as_slice()); @@ -779,11 +788,7 @@ impl EthCoin { /// bytes32 makerSecret, /// address tokenAddress /// ) - pub(crate) async fn extract_secret_v2_impl( - &self, - _secret_hash: &[u8], - spend_tx: &SignedEthTx, - ) -> Result, String> { + pub(crate) async fn extract_secret_v2_impl(&self, spend_tx: &SignedEthTx) -> Result, String> { let function = try_s!(TAKER_SWAP_V2.function("spendTakerPayment")); // should be 0xcc90c199 let expected_signature = function.short_signature(); diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index 4aae993f2e..070c0e14da 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -1410,7 +1410,11 @@ impl<'a> TakerOrderBuilder<'a> { self } - pub fn with_tpu_version(mut self, use_trading_proto_v2: bool) -> Self { + /// When a new [TakerOrderBuilder::new] is created, it sets [SWAP_VERSION] by default. + /// However, if user has not specified in the config to use TPU V2, + /// the TakerOrderBuilder's swap_version is changed to legacy. + /// In the future alls users will be using TPU V2 by default without "use_trading_proto_v2" configuration. + pub fn use_trading_proto_v2(mut self, use_trading_proto_v2: bool) -> Self { if !use_trading_proto_v2 { self.swap_version = 1; } @@ -1912,7 +1916,11 @@ impl<'a> MakerOrderBuilder<'a> { self } - pub fn with_tpu_version(mut self, use_trading_proto_v2: bool) -> Self { + /// When a new [MakerOrderBuilder::new] is created, it sets [SWAP_VERSION] by default. + /// However, if user has not specified in the config to use TPU V2, + /// the MakerOrderBuilder's swap_version is changed to legacy. + /// In the future alls users will be using TPU V2 by default without "use_trading_proto_v2" configuration. + pub fn use_trading_proto_v2(mut self, use_trading_proto_v2: bool) -> Self { if !use_trading_proto_v2 { self.swap_version = 1; } @@ -4169,7 +4177,7 @@ pub async fn lp_auto_buy( .with_save_in_history(input.save_in_history) .with_base_orderbook_ticker(ordermatch_ctx.orderbook_ticker(base_coin.ticker())) .with_rel_orderbook_ticker(ordermatch_ctx.orderbook_ticker(rel_coin.ticker())) - .with_tpu_version(ctx.use_trading_proto_v2()); + .use_trading_proto_v2(ctx.use_trading_proto_v2()); if let Some(timeout) = input.timeout { order_builder = order_builder.with_timeout(timeout); } @@ -4915,7 +4923,7 @@ pub async fn create_maker_order(ctx: &MmArc, req: SetPriceReq) -> Result Date: Thu, 14 Nov 2024 11:32:54 +0700 Subject: [PATCH 11/59] review: simplify "swap_version" field type, make it non-optional --- mm2src/mm2_main/src/lp_ordermatch.rs | 38 ++++--- .../src/lp_ordermatch/my_orders_storage.rs | 4 +- .../src/lp_ordermatch/new_protocol.rs | 14 +-- mm2src/mm2_main/src/ordermatch_tests.rs | 104 +++++++++--------- 4 files changed, 82 insertions(+), 78 deletions(-) diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index 070c0e14da..d136661e54 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -1171,9 +1171,9 @@ pub struct TakerRequest { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] pub rel_protocol_info: Option>, - #[serde(default)] - #[serde(skip_serializing_if = "Option::is_none")] - pub swap_version: Option, + #[serde(default = "legacy_swap_version")] + #[serde(skip_serializing_if = "is_legacy_swap_version")] + pub swap_version: u32, } impl TakerRequest { @@ -1251,6 +1251,10 @@ impl TakerRequest { fn get_rel_amount(&self) -> &MmNumber { &self.rel_amount } } +fn legacy_swap_version() -> u32 { 1 } + +fn is_legacy_swap_version(swap_version: &u32) -> bool { *swap_version == 1 } + pub struct TakerOrderBuilder<'a> { base_coin: &'a MmCoinEnum, rel_coin: &'a MmCoinEnum, @@ -1509,7 +1513,7 @@ impl<'a> TakerOrderBuilder<'a> { conf_settings: self.conf_settings, base_protocol_info: Some(base_protocol_info), rel_protocol_info: Some(rel_protocol_info), - swap_version: Some(self.swap_version), + swap_version: self.swap_version, }, matches: Default::default(), min_volume, @@ -1550,7 +1554,7 @@ impl<'a> TakerOrderBuilder<'a> { conf_settings: self.conf_settings, base_protocol_info: Some(base_protocol_info), rel_protocol_info: Some(rel_protocol_info), - swap_version: Some(self.swap_version), + swap_version: self.swap_version, }, matches: HashMap::new(), min_volume: Default::default(), @@ -1712,9 +1716,9 @@ pub struct MakerOrder { /// A custom priv key for more privacy to prevent linking orders of the same node between each other /// Commonly used with privacy coins (ARRR, ZCash, etc.) p2p_privkey: Option, - #[serde(default)] - #[serde(skip_serializing_if = "Option::is_none")] - pub swap_version: Option, + #[serde(default = "legacy_swap_version")] + #[serde(skip_serializing_if = "is_legacy_swap_version")] + pub swap_version: u32, } pub struct MakerOrderBuilder<'a> { @@ -1983,7 +1987,7 @@ impl<'a> MakerOrderBuilder<'a> { base_orderbook_ticker: self.base_orderbook_ticker, rel_orderbook_ticker: self.rel_orderbook_ticker, p2p_privkey, - swap_version: Some(self.swap_version), + swap_version: self.swap_version, }) } @@ -2008,7 +2012,7 @@ impl<'a> MakerOrderBuilder<'a> { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: Some(self.swap_version), + swap_version: self.swap_version, } } } @@ -2215,9 +2219,9 @@ pub struct MakerReserved { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] pub rel_protocol_info: Option>, - #[serde(default)] - #[serde(skip_serializing_if = "Option::is_none")] - pub swap_version: Option, + #[serde(default = "legacy_swap_version")] + #[serde(skip_serializing_if = "is_legacy_swap_version")] + pub swap_version: u32, } impl MakerReserved { @@ -3026,7 +3030,7 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO let alice_swap_v = maker_match.request.swap_version; // if taker order doesn't have swap version or taker uses legacy swap protocol, start legacy swap - if alice_swap_v.is_none() || alice_swap_v == Some(1) { + if alice_swap_v == 1u32 { let params = LegacySwapParams { maker_coin: &maker_coin, taker_coin: &taker_coin, @@ -3041,7 +3045,7 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO return; } - if ctx.use_trading_proto_v2() && alice_swap_v == Some(2) { + if ctx.use_trading_proto_v2() && alice_swap_v == 2u32 { let params = StateMachineParams { secret_hash_algo: &detect_secret_hash_algo(&maker_coin, &taker_coin), uuid: &uuid, @@ -3271,7 +3275,7 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat let bob_swap_v = taker_match.reserved.swap_version; // if maker order doesn't have swap version or maker uses legacy swap protocol, start legacy swap - if bob_swap_v.is_none() || bob_swap_v == Some(1) { + if bob_swap_v == 1u32 { let params = LegacySwapParams { maker_coin: &maker_coin, taker_coin: &taker_coin, @@ -3286,7 +3290,7 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat return; } - if ctx.use_trading_proto_v2() && bob_swap_v == Some(2) { + if ctx.use_trading_proto_v2() && bob_swap_v == 2u32 { let taker_secret = match generate_secret() { Ok(s) => s.into(), Err(e) => { diff --git a/mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs b/mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs index e24a823624..4e84cdcd96 100644 --- a/mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs +++ b/mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs @@ -724,7 +724,7 @@ mod tests { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, } } @@ -743,7 +743,7 @@ mod tests { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }, matches: HashMap::new(), created_at: now_ms(), diff --git a/mm2src/mm2_main/src/lp_ordermatch/new_protocol.rs b/mm2src/mm2_main/src/lp_ordermatch/new_protocol.rs index 30eb61e107..d7435f3258 100644 --- a/mm2src/mm2_main/src/lp_ordermatch/new_protocol.rs +++ b/mm2src/mm2_main/src/lp_ordermatch/new_protocol.rs @@ -5,7 +5,7 @@ use mm2_rpc::data::legacy::{MatchBy as SuperMatchBy, OrderConfirmationsSettings, use std::collections::{HashMap, HashSet}; use uuid::Uuid; -use crate::lp_ordermatch::{AlbOrderedOrderbookPair, H64}; +use crate::lp_ordermatch::{is_legacy_swap_version, legacy_swap_version, AlbOrderedOrderbookPair, H64}; #[derive(Debug, Deserialize, Serialize)] #[allow(clippy::large_enum_variant)] @@ -265,9 +265,9 @@ pub struct TakerRequest { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] pub rel_protocol_info: Option>, - #[serde(default)] - #[serde(skip_serializing_if = "Option::is_none")] - pub swap_version: Option, + #[serde(default = "legacy_swap_version")] + #[serde(skip_serializing_if = "is_legacy_swap_version")] + pub swap_version: u32, } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -285,9 +285,9 @@ pub struct MakerReserved { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] pub rel_protocol_info: Option>, - #[serde(default)] - #[serde(skip_serializing_if = "Option::is_none")] - pub swap_version: Option, + #[serde(default = "legacy_swap_version")] + #[serde(skip_serializing_if = "is_legacy_swap_version")] + pub swap_version: u32, } #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/mm2src/mm2_main/src/ordermatch_tests.rs b/mm2src/mm2_main/src/ordermatch_tests.rs index 6735587cbd..e761fcfba6 100644 --- a/mm2src/mm2_main/src/ordermatch_tests.rs +++ b/mm2src/mm2_main/src/ordermatch_tests.rs @@ -39,7 +39,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }; let request = TakerRequest { @@ -55,7 +55,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let actual = maker.match_with_request(&request); @@ -79,7 +79,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }; let request = TakerRequest { @@ -95,7 +95,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let actual = maker.match_with_request(&request); @@ -119,7 +119,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }; let request = TakerRequest { @@ -135,7 +135,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let actual = maker.match_with_request(&request); @@ -159,7 +159,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }; let request = TakerRequest { @@ -175,7 +175,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let actual = maker.match_with_request(&request); @@ -199,7 +199,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }; let request = TakerRequest { @@ -215,7 +215,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let actual = maker.match_with_request(&request); @@ -239,7 +239,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }; let request = TakerRequest { @@ -255,7 +255,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let actual = maker.match_with_request(&request); @@ -281,7 +281,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }; let request = TakerRequest { base: "KMD".to_owned(), @@ -296,7 +296,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let actual = maker.match_with_request(&request); assert_eq!(actual, OrderMatchResult::NotMatched); @@ -323,7 +323,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }; let request = TakerRequest { base: "REL".to_owned(), @@ -338,7 +338,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let actual = maker.match_with_request(&request); let expected_base_amount = MmNumber::from(3); @@ -396,7 +396,7 @@ fn test_maker_order_available_amount() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }; maker.matches.insert(new_uuid(), MakerMatch { request: TakerRequest { @@ -412,7 +412,7 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }, reserved: MakerReserved { base: "BASE".into(), @@ -426,7 +426,7 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }, connect: None, connected: None, @@ -446,7 +446,7 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }, reserved: MakerReserved { base: "BASE".into(), @@ -460,7 +460,7 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }, connect: None, connected: None, @@ -489,7 +489,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let order = TakerOrder { @@ -517,7 +517,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -535,7 +535,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let order = TakerOrder { @@ -563,7 +563,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -581,7 +581,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let order = TakerOrder { @@ -609,7 +609,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -627,7 +627,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let order = TakerOrder { @@ -655,7 +655,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; assert_eq!(MatchReservedResult::NotMatched, order.match_reserved(&reserved)); @@ -673,7 +673,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let order = TakerOrder { @@ -701,7 +701,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -719,7 +719,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let order = TakerOrder { @@ -747,7 +747,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -765,7 +765,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let order = TakerOrder { @@ -793,7 +793,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -811,7 +811,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let order = TakerOrder { @@ -839,7 +839,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; assert_eq!(MatchReservedResult::NotMatched, order.match_reserved(&reserved)); @@ -861,7 +861,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }, matches: HashMap::new(), order_type: OrderType::GoodTillCancelled, @@ -885,7 +885,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -906,7 +906,7 @@ fn test_taker_order_cancellable() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let order = TakerOrder { @@ -937,7 +937,7 @@ fn test_taker_order_cancellable() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let mut order = TakerOrder { @@ -967,7 +967,7 @@ fn test_taker_order_cancellable() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }, connect: TakerConnect { sender_pubkey: H256Json::default(), @@ -1016,7 +1016,7 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }, None, ); @@ -1039,7 +1039,7 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }, None, ); @@ -1062,7 +1062,7 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }, None, ); @@ -1082,7 +1082,7 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }, order_type: OrderType::GoodTillCancelled, min_volume: 0.into(), @@ -1176,7 +1176,7 @@ fn test_taker_order_match_by() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; let mut order = TakerOrder { @@ -1204,7 +1204,7 @@ fn test_taker_order_match_by() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: None, + swap_version: 1, }; assert_eq!(MatchReservedResult::NotMatched, order.match_reserved(&reserved)); @@ -1245,7 +1245,7 @@ fn test_maker_order_was_updated() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }; let mut update_msg = MakerOrderUpdated::new(maker_order.uuid); update_msg.with_new_price(BigRational::from_integer(2.into())); @@ -3252,7 +3252,7 @@ fn test_maker_order_balance_loops() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }; let morty_order = MakerOrder { @@ -3272,7 +3272,7 @@ fn test_maker_order_balance_loops() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }; assert!(!maker_orders_ctx.balance_loop_exists(rick_ticker)); @@ -3305,7 +3305,7 @@ fn test_maker_order_balance_loops() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: None, + swap_version: 1, }; maker_orders_ctx.add_order(ctx.weak(), rick_order_2.clone(), None); From 1e7a197a4616c74a52f610583656bf12b179a326 Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 14 Nov 2024 11:44:35 +0700 Subject: [PATCH 12/59] review: simplify `if let Some(tx_hash) = event.transaction_hash` block --- .../eth/eth_swap_v2/eth_taker_swap_v2.rs | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index 4a19645fc3..69a9226cba 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -529,21 +529,16 @@ impl EthCoin { if let Some(event) = found_event { if let Some(tx_hash) = event.transaction_hash { - let transaction = match self.transaction(TransactionId::Hash(tx_hash)).await { - Ok(Some(t)) => t, - Ok(None) => { - info!("Tx {} not found yet", tx_hash); - Timer::sleep(check_every).await; - continue; - }, - Err(e) => { - error!("Get tx {} error: {}", tx_hash, e); - Timer::sleep(check_every).await; - continue; + match self.transaction(TransactionId::Hash(tx_hash)).await { + Ok(Some(t)) => { + let transaction = signed_tx_from_web3_tx(t).map_err(FindPaymentSpendError::Internal)?; + return Ok(transaction); }, + Ok(None) => info!("Tx {} not found yet", tx_hash), + Err(e) => error!("Get tx {} error: {}", tx_hash, e), }; - let result = signed_tx_from_web3_tx(transaction).map_err(FindPaymentSpendError::Internal)?; - return Ok(result); + Timer::sleep(check_every).await; + continue; } } From fb383fb5556feda04cc0f0c841b64c5b64b051d2 Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 14 Nov 2024 13:03:03 +0700 Subject: [PATCH 13/59] review: make spendTakerPayment transaction log message more informative --- mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index 69a9226cba..be581517e2 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -16,7 +16,7 @@ use ethkey::public_to_address; use futures::compat::Future01CompatExt; use mm2_err_handle::prelude::{MapToMmResult, MmError, MmResult}; use std::convert::TryInto; -use web3::types::{BlockNumber, FilterBuilder, Log, TransactionId}; +use web3::types::{BlockNumber, FilterBuilder, Log, TransactionId, H256}; const ETH_TAKER_PAYMENT: &str = "ethTakerPayment"; const ERC20_TAKER_PAYMENT: &str = "erc20TakerPayment"; @@ -483,6 +483,7 @@ impl EthCoin { ))) }, }; + let mut tx_hash = H256::default(); // loop to find maker's spendTakerPayment transaction loop { let now = now_sec(); @@ -534,7 +535,7 @@ impl EthCoin { let transaction = signed_tx_from_web3_tx(t).map_err(FindPaymentSpendError::Internal)?; return Ok(transaction); }, - Ok(None) => info!("Tx {} not found yet", tx_hash), + Ok(None) => info!("spendTakerPayment transaction {} not found yet", tx_hash), Err(e) => error!("Get tx {} error: {}", tx_hash, e), }; Timer::sleep(check_every).await; From 9ec0babe1802613ce77967a71051d82cde4c6caa Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 14 Nov 2024 14:43:00 +0700 Subject: [PATCH 14/59] review: provide LEGACY_SWAP_V const in tests --- .../eth/eth_swap_v2/eth_taker_swap_v2.rs | 2 +- .../src/lp_ordermatch/my_orders_storage.rs | 6 +- mm2src/mm2_main/src/ordermatch_tests.rs | 106 +++++++++--------- 3 files changed, 59 insertions(+), 55 deletions(-) diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index be581517e2..ea11a267e7 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -483,7 +483,7 @@ impl EthCoin { ))) }, }; - let mut tx_hash = H256::default(); + let _tx_hash = H256::default(); // loop to find maker's spendTakerPayment transaction loop { let now = now_sec(); diff --git a/mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs b/mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs index 4e84cdcd96..536e2014e6 100644 --- a/mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs +++ b/mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs @@ -706,6 +706,8 @@ mod tests { wasm_bindgen_test_configure!(run_in_browser); + const LEGACY_SWAP_V: u32 = 1; + fn maker_order_for_test() -> MakerOrder { MakerOrder { base: "BASE".to_owned(), @@ -724,7 +726,7 @@ mod tests { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, } } @@ -743,7 +745,7 @@ mod tests { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }, matches: HashMap::new(), created_at: now_ms(), diff --git a/mm2src/mm2_main/src/ordermatch_tests.rs b/mm2src/mm2_main/src/ordermatch_tests.rs index e761fcfba6..86fac98f32 100644 --- a/mm2src/mm2_main/src/ordermatch_tests.rs +++ b/mm2src/mm2_main/src/ordermatch_tests.rs @@ -20,6 +20,8 @@ use std::collections::HashSet; use std::iter::{self, FromIterator}; use std::sync::Mutex; +const LEGACY_SWAP_V: u32 = 1; + #[test] fn test_match_maker_order_and_taker_request() { let maker = MakerOrder { @@ -39,7 +41,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { @@ -55,7 +57,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); @@ -79,7 +81,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { @@ -95,7 +97,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); @@ -119,7 +121,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { @@ -135,7 +137,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); @@ -159,7 +161,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { @@ -175,7 +177,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); @@ -199,7 +201,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { @@ -215,7 +217,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); @@ -239,7 +241,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { @@ -255,7 +257,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); @@ -281,7 +283,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { base: "KMD".to_owned(), @@ -296,7 +298,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); assert_eq!(actual, OrderMatchResult::NotMatched); @@ -323,7 +325,7 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { base: "REL".to_owned(), @@ -338,7 +340,7 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); let expected_base_amount = MmNumber::from(3); @@ -396,7 +398,7 @@ fn test_maker_order_available_amount() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; maker.matches.insert(new_uuid(), MakerMatch { request: TakerRequest { @@ -412,7 +414,7 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }, reserved: MakerReserved { base: "BASE".into(), @@ -426,7 +428,7 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }, connect: None, connected: None, @@ -446,7 +448,7 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }, reserved: MakerReserved { base: "BASE".into(), @@ -460,7 +462,7 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }, connect: None, connected: None, @@ -489,7 +491,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -517,7 +519,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -535,7 +537,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -563,7 +565,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -581,7 +583,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -609,7 +611,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -627,7 +629,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -655,7 +657,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::NotMatched, order.match_reserved(&reserved)); @@ -673,7 +675,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -701,7 +703,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -719,7 +721,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -747,7 +749,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -765,7 +767,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -793,7 +795,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -811,7 +813,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -839,7 +841,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::NotMatched, order.match_reserved(&reserved)); @@ -861,7 +863,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }, matches: HashMap::new(), order_type: OrderType::GoodTillCancelled, @@ -885,7 +887,7 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -906,7 +908,7 @@ fn test_taker_order_cancellable() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -937,7 +939,7 @@ fn test_taker_order_cancellable() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let mut order = TakerOrder { @@ -967,7 +969,7 @@ fn test_taker_order_cancellable() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }, connect: TakerConnect { sender_pubkey: H256Json::default(), @@ -1016,7 +1018,7 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }, None, ); @@ -1039,7 +1041,7 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }, None, ); @@ -1062,7 +1064,7 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }, None, ); @@ -1082,7 +1084,7 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }, order_type: OrderType::GoodTillCancelled, min_volume: 0.into(), @@ -1176,7 +1178,7 @@ fn test_taker_order_match_by() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let mut order = TakerOrder { @@ -1204,7 +1206,7 @@ fn test_taker_order_match_by() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::NotMatched, order.match_reserved(&reserved)); @@ -1245,7 +1247,7 @@ fn test_maker_order_was_updated() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let mut update_msg = MakerOrderUpdated::new(maker_order.uuid); update_msg.with_new_price(BigRational::from_integer(2.into())); @@ -3252,7 +3254,7 @@ fn test_maker_order_balance_loops() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; let morty_order = MakerOrder { @@ -3272,7 +3274,7 @@ fn test_maker_order_balance_loops() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; assert!(!maker_orders_ctx.balance_loop_exists(rick_ticker)); @@ -3305,7 +3307,7 @@ fn test_maker_order_balance_loops() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: 1, + swap_version: LEGACY_SWAP_V, }; maker_orders_ctx.add_order(ctx.weak(), rick_order_2.clone(), None); From 6c8b2c132cffd36a08f55f655f0eacfffa205882 Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 14 Nov 2024 17:17:50 +0700 Subject: [PATCH 15/59] review: skip retrieving events if tx_hash is already found in find_taker_payment_spend_tx_impl function --- .../eth/eth_swap_v2/eth_taker_swap_v2.rs | 93 +++++++++---------- 1 file changed, 45 insertions(+), 48 deletions(-) diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index ea11a267e7..5d1d5fef72 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -4,7 +4,7 @@ use crate::eth::{decode_contract_call, get_function_input_data, signed_tx_from_w EthCoinType, ParseCoinAssocTypes, RefundFundingSecretArgs, RefundTakerPaymentArgs, SendTakerFundingArgs, SignedEthTx, SwapTxTypeWithSecretHash, TakerPaymentStateV2, TransactionErr, ValidateSwapV2TxError, ValidateSwapV2TxResult, ValidateTakerFundingArgs, TAKER_SWAP_V2}; -use crate::{FindPaymentSpendError, FundingTxSpend, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, MarketCoinOps, +use crate::{FindPaymentSpendError, FundingTxSpend, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, SearchForFundingSpendErr}; use common::executor::Timer; use common::log::{error, info}; @@ -483,7 +483,7 @@ impl EthCoin { ))) }, }; - let _tx_hash = H256::default(); + let mut tx_hash: Option = None; // loop to find maker's spendTakerPayment transaction loop { let now = now_sec(); @@ -491,74 +491,71 @@ impl EthCoin { return MmError::err(FindPaymentSpendError::Timeout { wait_until, now }); } - let current_block = match self.current_block().compat().await { - Ok(b) => b, - Err(e) => { - error!("Error getting block number: {}", e); - Timer::sleep(5.).await; - continue; - }, - }; + // Skip retrieving events if tx_hash is already found + if tx_hash.is_none() { + // get all logged TakerPaymentSpent events from `from_block` till current block + let events = match self + .events_from_block(taker_swap_v2_contract, "TakerPaymentSpent", from_block) + .await + { + Ok(events) => events, + Err(e) => { + error!( + "Error getting TakerPaymentSpent events from {} block: {}", + from_block, e + ); + Timer::sleep(5.).await; + continue; + }, + }; - // get all logged TakerPaymentSpent events from `from_block` till current block - let events = match self - .events_from_block(taker_swap_v2_contract, "TakerPaymentSpent", from_block, current_block) - .await - { - Ok(events) => events, - Err(e) => { - error!( - "Error getting TakerPaymentSpent events from {} block: {}", - from_block, e - ); + if events.is_empty() { + info!("No events found yet from block {}", from_block); Timer::sleep(5.).await; continue; - }, - }; + } - if events.is_empty() { - info!( - "No events found yet for the block range {} to {}", - from_block, current_block - ); - Timer::sleep(5.).await; - continue; - } + // this is how spent event looks like in EtomicSwapTakerV2: event TakerPaymentSpent(bytes32 id, bytes32 secret) + let found_event = events.into_iter().find(|event| &event.data.0[..32] == id.as_slice()); - // this is how spent event looks like in EtomicSwapTakerV2: event TakerPaymentSpent(bytes32 id, bytes32 secret) - let found_event = events.into_iter().find(|event| &event.data.0[..32] == id.as_slice()); - - if let Some(event) = found_event { - if let Some(tx_hash) = event.transaction_hash { - match self.transaction(TransactionId::Hash(tx_hash)).await { - Ok(Some(t)) => { - let transaction = signed_tx_from_web3_tx(t).map_err(FindPaymentSpendError::Internal)?; - return Ok(transaction); - }, - Ok(None) => info!("spendTakerPayment transaction {} not found yet", tx_hash), - Err(e) => error!("Get tx {} error: {}", tx_hash, e), - }; - Timer::sleep(check_every).await; - continue; + if let Some(event) = found_event { + if let Some(hash) = event.transaction_hash { + // Store tx_hash to skip fetching events in the next iteration if `"eth_getTransactionByHash"` is unsuccessful + tx_hash = Some(hash); + } } } + // Proceed to check transaction if we have a tx_hash + if let Some(tx_hash) = tx_hash { + match self.transaction(TransactionId::Hash(tx_hash)).await { + Ok(Some(t)) => { + let transaction = signed_tx_from_web3_tx(t).map_err(FindPaymentSpendError::Internal)?; + return Ok(transaction); + }, + Ok(None) => info!("spendTakerPayment transaction {} not found yet", tx_hash), + Err(e) => error!("Get tx {} error: {}", tx_hash, e), + }; + Timer::sleep(check_every).await; + continue; + } + Timer::sleep(5.).await; } } + /// Returns events from `from_block` to current `latest` block. + /// According to ["eth_getLogs" doc](https://docs.infura.io/api/networks/ethereum/json-rpc-methods/eth_getlogs) `toBlock` is optional, default is "latest". async fn events_from_block( &self, swap_contract_address: Address, event_name: &str, from_block: u64, - to_block: u64, ) -> MmResult, FindPaymentSpendError> { let contract_event = TAKER_SWAP_V2.event(event_name)?; let filter = FilterBuilder::default() .topics(Some(vec![contract_event.signature()]), None, None, None) .from_block(BlockNumber::Number(from_block.into())) - .to_block(BlockNumber::Number(to_block.into())) .address(vec![swap_contract_address]) .build(); let events_logs = self From f817f5cd97178af169afb14cfd8d559ed84c6700 Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 14 Nov 2024 19:32:43 +0700 Subject: [PATCH 16/59] review: combine legacy fallback conditions --- mm2src/mm2_main/src/lp_ordermatch.rs | 206 ++++++++++++--------------- 1 file changed, 89 insertions(+), 117 deletions(-) diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index d136661e54..bd737016cd 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -3029,8 +3029,8 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO }; let alice_swap_v = maker_match.request.swap_version; - // if taker order doesn't have swap version or taker uses legacy swap protocol, start legacy swap - if alice_swap_v == 1u32 { + // Start legacy swap if taker uses legacy protocol (version 1) or if conditions for trading_proto_v2 aren't met. + if alice_swap_v == 1u32 || !(ctx.use_trading_proto_v2() && alice_swap_v == 2u32) { let params = LegacySwapParams { maker_coin: &maker_coin, taker_coin: &taker_coin, @@ -3045,58 +3045,44 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO return; } - if ctx.use_trading_proto_v2() && alice_swap_v == 2u32 { - let params = StateMachineParams { - secret_hash_algo: &detect_secret_hash_algo(&maker_coin, &taker_coin), - uuid: &uuid, - my_conf_settings: &my_conf_settings, - locktime: &lock_time, - maker_amount: &maker_amount, - taker_amount: &taker_amount, - }; - let taker_p2p_pubkey = match taker_p2p_pubkey { - PublicKey::Secp256k1(pubkey) => pubkey.into(), - }; + let params = StateMachineParams { + secret_hash_algo: &detect_secret_hash_algo(&maker_coin, &taker_coin), + uuid: &uuid, + my_conf_settings: &my_conf_settings, + locktime: &lock_time, + maker_amount: &maker_amount, + taker_amount: &taker_amount, + }; + let taker_p2p_pubkey = match taker_p2p_pubkey { + PublicKey::Secp256k1(pubkey) => pubkey.into(), + }; - match (&maker_coin, &taker_coin) { - (MmCoinEnum::UtxoCoin(m), MmCoinEnum::UtxoCoin(t)) => { - start_maker_swap_state_machine(&ctx, &maker_order, &taker_p2p_pubkey, &secret, m, t, ¶ms).await; - }, - (MmCoinEnum::EthCoin(m), MmCoinEnum::EthCoin(t)) => { - start_maker_swap_state_machine(&ctx, &maker_order, &taker_p2p_pubkey, &secret, m, t, ¶ms).await; - }, - (MmCoinEnum::UtxoCoin(m), MmCoinEnum::EthCoin(t)) => { - start_maker_swap_state_machine(&ctx, &maker_order, &taker_p2p_pubkey, &secret, m, t, ¶ms).await; - }, - (MmCoinEnum::EthCoin(m), MmCoinEnum::UtxoCoin(t)) => { - start_maker_swap_state_machine(&ctx, &maker_order, &taker_p2p_pubkey, &secret, m, t, ¶ms).await; - }, - _ => { - let params = LegacySwapParams { - maker_coin: &maker_coin, - taker_coin: &taker_coin, - uuid: &uuid, - my_conf_settings: &my_conf_settings, - my_persistent_pub: &my_persistent_pub, - maker_amount: &maker_amount, - taker_amount: &taker_amount, - locktime: &lock_time, - }; - start_maker_legacy_swap(&ctx, maker_order, alice, secret, params).await - }, - } - } else { - let params = LegacySwapParams { - maker_coin: &maker_coin, - taker_coin: &taker_coin, - uuid: &uuid, - my_conf_settings: &my_conf_settings, - my_persistent_pub: &my_persistent_pub, - maker_amount: &maker_amount, - taker_amount: &taker_amount, - locktime: &lock_time, - }; - start_maker_legacy_swap(&ctx, maker_order, alice, secret, params).await + match (&maker_coin, &taker_coin) { + (MmCoinEnum::UtxoCoin(m), MmCoinEnum::UtxoCoin(t)) => { + start_maker_swap_state_machine(&ctx, &maker_order, &taker_p2p_pubkey, &secret, m, t, ¶ms).await; + }, + (MmCoinEnum::EthCoin(m), MmCoinEnum::EthCoin(t)) => { + start_maker_swap_state_machine(&ctx, &maker_order, &taker_p2p_pubkey, &secret, m, t, ¶ms).await; + }, + (MmCoinEnum::UtxoCoin(m), MmCoinEnum::EthCoin(t)) => { + start_maker_swap_state_machine(&ctx, &maker_order, &taker_p2p_pubkey, &secret, m, t, ¶ms).await; + }, + (MmCoinEnum::EthCoin(m), MmCoinEnum::UtxoCoin(t)) => { + start_maker_swap_state_machine(&ctx, &maker_order, &taker_p2p_pubkey, &secret, m, t, ¶ms).await; + }, + _ => { + let params = LegacySwapParams { + maker_coin: &maker_coin, + taker_coin: &taker_coin, + uuid: &uuid, + my_conf_settings: &my_conf_settings, + my_persistent_pub: &my_persistent_pub, + maker_amount: &maker_amount, + taker_amount: &taker_amount, + locktime: &lock_time, + }; + start_maker_legacy_swap(&ctx, maker_order, alice, secret, params).await + }, } }; @@ -3274,8 +3260,8 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat ); let bob_swap_v = taker_match.reserved.swap_version; - // if maker order doesn't have swap version or maker uses legacy swap protocol, start legacy swap - if bob_swap_v == 1u32 { + // Start legacy swap if maker uses legacy protocol (version 1) or if conditions for trading_proto_v2 aren't met. + if bob_swap_v == 1u32 || !(ctx.use_trading_proto_v2() && bob_swap_v == 2u32) { let params = LegacySwapParams { maker_coin: &maker_coin, taker_coin: &taker_coin, @@ -3290,69 +3276,55 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat return; } - if ctx.use_trading_proto_v2() && bob_swap_v == 2u32 { - let taker_secret = match generate_secret() { - Ok(s) => s.into(), - Err(e) => { - error!("Error {} on secret generation", e); - return; - }, - }; - let params = StateMachineParams { - secret_hash_algo: &detect_secret_hash_algo(&maker_coin, &taker_coin), - uuid: &uuid, - my_conf_settings: &my_conf_settings, - locktime: &locktime, - maker_amount: &maker_amount, - taker_amount: &taker_amount, - }; - let maker_p2p_pubkey = match maker_p2p_pubkey { - PublicKey::Secp256k1(pubkey) => pubkey.into(), - }; + let taker_secret = match generate_secret() { + Ok(s) => s.into(), + Err(e) => { + error!("Error {} on secret generation", e); + return; + }, + }; + let params = StateMachineParams { + secret_hash_algo: &detect_secret_hash_algo(&maker_coin, &taker_coin), + uuid: &uuid, + my_conf_settings: &my_conf_settings, + locktime: &locktime, + maker_amount: &maker_amount, + taker_amount: &taker_amount, + }; + let maker_p2p_pubkey = match maker_p2p_pubkey { + PublicKey::Secp256k1(pubkey) => pubkey.into(), + }; - match (&maker_coin, &taker_coin) { - (MmCoinEnum::UtxoCoin(m), MmCoinEnum::UtxoCoin(t)) => { - start_taker_swap_state_machine(&ctx, &taker_order, &maker_p2p_pubkey, &taker_secret, m, t, ¶ms) - .await; - }, - (MmCoinEnum::EthCoin(m), MmCoinEnum::EthCoin(t)) => { - start_taker_swap_state_machine(&ctx, &taker_order, &maker_p2p_pubkey, &taker_secret, m, t, ¶ms) - .await; - }, - (MmCoinEnum::UtxoCoin(m), MmCoinEnum::EthCoin(t)) => { - start_taker_swap_state_machine(&ctx, &taker_order, &maker_p2p_pubkey, &taker_secret, m, t, ¶ms) - .await; - }, - (MmCoinEnum::EthCoin(m), MmCoinEnum::UtxoCoin(t)) => { - start_taker_swap_state_machine(&ctx, &taker_order, &maker_p2p_pubkey, &taker_secret, m, t, ¶ms) - .await; - }, - _ => { - let params = LegacySwapParams { - maker_coin: &maker_coin, - taker_coin: &taker_coin, - uuid: &uuid, - my_conf_settings: &my_conf_settings, - my_persistent_pub: &my_persistent_pub, - maker_amount: &maker_amount, - taker_amount: &taker_amount, - locktime: &locktime, - }; - start_taker_legacy_swap(&ctx, taker_order, maker, params).await; - }, - } - } else { - let params = LegacySwapParams { - maker_coin: &maker_coin, - taker_coin: &taker_coin, - uuid: &uuid, - my_conf_settings: &my_conf_settings, - my_persistent_pub: &my_persistent_pub, - maker_amount: &maker_amount, - taker_amount: &taker_amount, - locktime: &locktime, - }; - start_taker_legacy_swap(&ctx, taker_order, maker, params).await; + match (&maker_coin, &taker_coin) { + (MmCoinEnum::UtxoCoin(m), MmCoinEnum::UtxoCoin(t)) => { + start_taker_swap_state_machine(&ctx, &taker_order, &maker_p2p_pubkey, &taker_secret, m, t, ¶ms) + .await; + }, + (MmCoinEnum::EthCoin(m), MmCoinEnum::EthCoin(t)) => { + start_taker_swap_state_machine(&ctx, &taker_order, &maker_p2p_pubkey, &taker_secret, m, t, ¶ms) + .await; + }, + (MmCoinEnum::UtxoCoin(m), MmCoinEnum::EthCoin(t)) => { + start_taker_swap_state_machine(&ctx, &taker_order, &maker_p2p_pubkey, &taker_secret, m, t, ¶ms) + .await; + }, + (MmCoinEnum::EthCoin(m), MmCoinEnum::UtxoCoin(t)) => { + start_taker_swap_state_machine(&ctx, &taker_order, &maker_p2p_pubkey, &taker_secret, m, t, ¶ms) + .await; + }, + _ => { + let params = LegacySwapParams { + maker_coin: &maker_coin, + taker_coin: &taker_coin, + uuid: &uuid, + my_conf_settings: &my_conf_settings, + my_persistent_pub: &my_persistent_pub, + maker_amount: &maker_amount, + taker_amount: &taker_amount, + locktime: &locktime, + }; + start_taker_legacy_swap(&ctx, taker_order, maker, params).await; + }, } }; From ddac3c816b496f5a725f43954c0b22f5876be11d Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 14 Nov 2024 19:44:45 +0700 Subject: [PATCH 17/59] remove unnecessary quotation marks --- mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index 5d1d5fef72..64f844aa63 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -520,7 +520,7 @@ impl EthCoin { if let Some(event) = found_event { if let Some(hash) = event.transaction_hash { - // Store tx_hash to skip fetching events in the next iteration if `"eth_getTransactionByHash"` is unsuccessful + // Store tx_hash to skip fetching events in the next iteration if "eth_getTransactionByHash" is unsuccessful tx_hash = Some(hash); } } From f437dde06e77774407afc71829c29961faa3366a Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 14 Nov 2024 21:52:00 +0700 Subject: [PATCH 18/59] review: remove as_ref, map, remove Timer::sleep from the end --- mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index 64f844aa63..bc2b04ad1b 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -467,11 +467,10 @@ impl EthCoin { ) -> MmResult { let taker_swap_v2_contract = self .swap_v2_contracts - .as_ref() - .map(|contracts| contracts.taker_swap_v2_contract) .ok_or_else(|| { FindPaymentSpendError::Internal("Expected swap_v2_contracts to be Some, but found None".to_string()) - })?; + })? + .taker_swap_v2_contract; let approve_func = TAKER_SWAP_V2.function(TAKER_PAYMENT_APPROVE)?; let decoded = decode_contract_call(approve_func, taker_payment.unsigned().data())?; let id = match decoded.first() { @@ -504,14 +503,14 @@ impl EthCoin { "Error getting TakerPaymentSpent events from {} block: {}", from_block, e ); - Timer::sleep(5.).await; + Timer::sleep(check_every).await; continue; }, }; if events.is_empty() { info!("No events found yet from block {}", from_block); - Timer::sleep(5.).await; + Timer::sleep(check_every).await; continue; } @@ -534,13 +533,11 @@ impl EthCoin { return Ok(transaction); }, Ok(None) => info!("spendTakerPayment transaction {} not found yet", tx_hash), - Err(e) => error!("Get tx {} error: {}", tx_hash, e), + Err(e) => error!("Get spendTakerPayment transaction {} error: {}", tx_hash, e), }; Timer::sleep(check_every).await; continue; } - - Timer::sleep(5.).await; } } From 02736e452096cf802c5c5309a5c733bc89f208c2 Mon Sep 17 00:00:00 2001 From: laruh Date: Fri, 15 Nov 2024 14:23:13 +0700 Subject: [PATCH 19/59] return Timer sleep at the end of loop --- mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index bc2b04ad1b..49c1a06daf 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -538,6 +538,8 @@ impl EthCoin { Timer::sleep(check_every).await; continue; } + + Timer::sleep(check_every).await; } } From a08b50068cc38bdfc8117a2b280a3fba1e00ba0d Mon Sep 17 00:00:00 2001 From: laruh Date: Fri, 15 Nov 2024 14:30:33 +0700 Subject: [PATCH 20/59] leave todo above coin tuple pattern matching in ordermatch --- mm2src/mm2_main/src/lp_ordermatch.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index bd737016cd..d187e53234 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -3057,6 +3057,7 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO PublicKey::Secp256k1(pubkey) => pubkey.into(), }; + // TODO try to handle it more gracefully during project redesign match (&maker_coin, &taker_coin) { (MmCoinEnum::UtxoCoin(m), MmCoinEnum::UtxoCoin(t)) => { start_maker_swap_state_machine(&ctx, &maker_order, &taker_p2p_pubkey, &secret, m, t, ¶ms).await; @@ -3295,6 +3296,7 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat PublicKey::Secp256k1(pubkey) => pubkey.into(), }; + // TODO try to handle it more gracefully during project redesign match (&maker_coin, &taker_coin) { (MmCoinEnum::UtxoCoin(m), MmCoinEnum::UtxoCoin(t)) => { start_taker_swap_state_machine(&ctx, &taker_order, &maker_p2p_pubkey, &taker_secret, m, t, ¶ms) From 24cb4c3fc5d5572d66548aee65822a95463df481 Mon Sep 17 00:00:00 2001 From: laruh Date: Fri, 15 Nov 2024 17:22:14 +0700 Subject: [PATCH 21/59] use `events_from_block` function in `wait_for_htlc_tx_spend` --- mm2src/coins/eth.rs | 40 ++++++++++++------- .../eth/eth_swap_v2/eth_taker_swap_v2.rs | 25 +----------- mm2src/coins/eth/eth_tests.rs | 2 +- 3 files changed, 29 insertions(+), 38 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 09b9c2b976..9d481173e4 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -2616,18 +2616,8 @@ impl MarketCoinOps for EthCoin { ); } - let current_block = match self.current_block().compat().await { - Ok(b) => b, - Err(e) => { - error!("Error getting block number: {}", e); - Timer::sleep(5.).await; - continue; - }, - }; - let events = match self - .spend_events(swap_contract_address, args.from_block, current_block) - .compat() + .events_from_block(swap_contract_address, "ReceiverSpent", args.from_block, &SWAP_CONTRACT) .await { Ok(ev) => ev, @@ -4872,8 +4862,8 @@ impl EthCoin { Box::new(fut.boxed().compat()) } - /// Gets `ReceiverSpent` events from etomic swap smart contract since `from_block` - fn spend_events( + /// Gets `ReceiverSpent` events from etomic swap smart contract since `from_block` to `to_block` + fn legacy_spend_events( &self, swap_contract_address: Address, from_block: u64, @@ -4893,6 +4883,28 @@ impl EthCoin { Box::new(fut.boxed().compat()) } + /// Returns events from `from_block` to current `latest` block. + /// According to ["eth_getLogs" doc](https://docs.infura.io/api/networks/ethereum/json-rpc-methods/eth_getlogs) `toBlock` is optional, default is "latest". + async fn events_from_block( + &self, + swap_contract_address: Address, + event_name: &str, + from_block: u64, + swap_contract: &Contract, + ) -> MmResult, FindPaymentSpendError> { + let contract_event = swap_contract.event(event_name)?; + let filter = FilterBuilder::default() + .topics(Some(vec![contract_event.signature()]), None, None, None) + .from_block(BlockNumber::Number(from_block.into())) + .address(vec![swap_contract_address]) + .build(); + let events_logs = self + .logs(filter) + .await + .map_err(|e| FindPaymentSpendError::Transport(e.to_string()))?; + Ok(events_logs) + } + fn validate_payment(&self, input: ValidatePaymentInput) -> ValidatePaymentFut<()> { let expected_swap_contract_address = try_f!(input .swap_contract_address @@ -5252,7 +5264,7 @@ impl EthCoin { let to_block = current_block.min(from_block + self.logs_block_range); let spend_events = try_s!( - self.spend_events(swap_contract_address, from_block, to_block) + self.legacy_spend_events(swap_contract_address, from_block, to_block) .compat() .await ); diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index 49c1a06daf..c1174e8f35 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -16,7 +16,7 @@ use ethkey::public_to_address; use futures::compat::Future01CompatExt; use mm2_err_handle::prelude::{MapToMmResult, MmError, MmResult}; use std::convert::TryInto; -use web3::types::{BlockNumber, FilterBuilder, Log, TransactionId, H256}; +use web3::types::{TransactionId, H256}; const ETH_TAKER_PAYMENT: &str = "ethTakerPayment"; const ERC20_TAKER_PAYMENT: &str = "erc20TakerPayment"; @@ -494,7 +494,7 @@ impl EthCoin { if tx_hash.is_none() { // get all logged TakerPaymentSpent events from `from_block` till current block let events = match self - .events_from_block(taker_swap_v2_contract, "TakerPaymentSpent", from_block) + .events_from_block(taker_swap_v2_contract, "TakerPaymentSpent", from_block, &TAKER_SWAP_V2) .await { Ok(events) => events, @@ -543,27 +543,6 @@ impl EthCoin { } } - /// Returns events from `from_block` to current `latest` block. - /// According to ["eth_getLogs" doc](https://docs.infura.io/api/networks/ethereum/json-rpc-methods/eth_getlogs) `toBlock` is optional, default is "latest". - async fn events_from_block( - &self, - swap_contract_address: Address, - event_name: &str, - from_block: u64, - ) -> MmResult, FindPaymentSpendError> { - let contract_event = TAKER_SWAP_V2.event(event_name)?; - let filter = FilterBuilder::default() - .topics(Some(vec![contract_event.signature()]), None, None, None) - .from_block(BlockNumber::Number(from_block.into())) - .address(vec![swap_contract_address]) - .build(); - let events_logs = self - .logs(filter) - .await - .map_err(|e| FindPaymentSpendError::Transport(e.to_string()))?; - Ok(events_logs) - } - /// Prepares data for EtomicSwapTakerV2 contract [ethTakerPayment](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapTakerV2.sol#L44) method async fn prepare_taker_eth_funding_data(&self, args: &TakerFundingArgs) -> Result, PrepareTxDataError> { let function = TAKER_SWAP_V2.function(ETH_TAKER_PAYMENT)?; diff --git a/mm2src/coins/eth/eth_tests.rs b/mm2src/coins/eth/eth_tests.rs index 19f45d10ae..5f60f5b045 100644 --- a/mm2src/coins/eth/eth_tests.rs +++ b/mm2src/coins/eth/eth_tests.rs @@ -163,7 +163,7 @@ fn test_wei_from_big_decimal() { fn test_wait_for_payment_spend_timeout() { const TAKER_PAYMENT_SPEND_SEARCH_INTERVAL: f64 = 1.; - EthCoin::spend_events.mock_safe(|_, _, _, _| MockResult::Return(Box::new(futures01::future::ok(vec![])))); + EthCoin::legacy_spend_events.mock_safe(|_, _, _, _| MockResult::Return(Box::new(futures01::future::ok(vec![])))); EthCoin::current_block.mock_safe(|_| MockResult::Return(Box::new(futures01::future::ok(900)))); let key_pair = Random.generate().unwrap(); From 5f666f3d14a879314bef9f864b06de3256337ac6 Mon Sep 17 00:00:00 2001 From: laruh Date: Sun, 17 Nov 2024 16:44:27 +0700 Subject: [PATCH 22/59] review: use logs_block_range in find_taker_payment_spend_tx --- mm2src/coins/eth.rs | 20 +++-- .../eth/eth_swap_v2/eth_taker_swap_v2.rs | 77 ++++++++++++------- 2 files changed, 63 insertions(+), 34 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 9d481173e4..3f5863e896 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -2617,7 +2617,13 @@ impl MarketCoinOps for EthCoin { } let events = match self - .events_from_block(swap_contract_address, "ReceiverSpent", args.from_block, &SWAP_CONTRACT) + .events_from_block( + swap_contract_address, + "ReceiverSpent", + args.from_block, + None, + &SWAP_CONTRACT, + ) .await { Ok(ev) => ev, @@ -4883,21 +4889,25 @@ impl EthCoin { Box::new(fut.boxed().compat()) } - /// Returns events from `from_block` to current `latest` block. + /// Returns events from `from_block` to `to_block` or current `latest` block. /// According to ["eth_getLogs" doc](https://docs.infura.io/api/networks/ethereum/json-rpc-methods/eth_getlogs) `toBlock` is optional, default is "latest". async fn events_from_block( &self, swap_contract_address: Address, event_name: &str, from_block: u64, + to_block: Option, swap_contract: &Contract, ) -> MmResult, FindPaymentSpendError> { let contract_event = swap_contract.event(event_name)?; - let filter = FilterBuilder::default() + let mut filter_builder = FilterBuilder::default() .topics(Some(vec![contract_event.signature()]), None, None, None) .from_block(BlockNumber::Number(from_block.into())) - .address(vec![swap_contract_address]) - .build(); + .address(vec![swap_contract_address]); + if let Some(block) = to_block { + filter_builder = filter_builder.to_block(BlockNumber::Number(block.into())); + } + let filter = filter_builder.build(); let events_logs = self .logs(filter) .await diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index c1174e8f35..9fec303bcb 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -4,7 +4,7 @@ use crate::eth::{decode_contract_call, get_function_input_data, signed_tx_from_w EthCoinType, ParseCoinAssocTypes, RefundFundingSecretArgs, RefundTakerPaymentArgs, SendTakerFundingArgs, SignedEthTx, SwapTxTypeWithSecretHash, TakerPaymentStateV2, TransactionErr, ValidateSwapV2TxError, ValidateSwapV2TxResult, ValidateTakerFundingArgs, TAKER_SWAP_V2}; -use crate::{FindPaymentSpendError, FundingTxSpend, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, +use crate::{FindPaymentSpendError, FundingTxSpend, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, MarketCoinOps, SearchForFundingSpendErr}; use common::executor::Timer; use common::log::{error, info}; @@ -490,38 +490,57 @@ impl EthCoin { return MmError::err(FindPaymentSpendError::Timeout { wait_until, now }); } - // Skip retrieving events if tx_hash is already found - if tx_hash.is_none() { - // get all logged TakerPaymentSpent events from `from_block` till current block - let events = match self - .events_from_block(taker_swap_v2_contract, "TakerPaymentSpent", from_block, &TAKER_SWAP_V2) - .await - { - Ok(events) => events, - Err(e) => { - error!( - "Error getting TakerPaymentSpent events from {} block: {}", - from_block, e - ); - Timer::sleep(check_every).await; - continue; - }, - }; - - if events.is_empty() { - info!("No events found yet from block {}", from_block); + let current_block = match self.current_block().compat().await { + Ok(b) => b, + Err(e) => { + error!("Error getting block number: {}", e); Timer::sleep(check_every).await; continue; - } - - // this is how spent event looks like in EtomicSwapTakerV2: event TakerPaymentSpent(bytes32 id, bytes32 secret) - let found_event = events.into_iter().find(|event| &event.data.0[..32] == id.as_slice()); + }, + }; - if let Some(event) = found_event { - if let Some(hash) = event.transaction_hash { - // Store tx_hash to skip fetching events in the next iteration if "eth_getTransactionByHash" is unsuccessful - tx_hash = Some(hash); + // Skip retrieving events if tx_hash is already found + if tx_hash.is_none() { + let mut next_from_block = from_block; + + while next_from_block <= current_block { + let to_block = std::cmp::min(next_from_block + self.logs_block_range - 1, current_block); + + // Fetch TakerPaymentSpent events for the current block range + let events = match self + .events_from_block( + taker_swap_v2_contract, + "TakerPaymentSpent", + next_from_block, + Some(to_block), + &TAKER_SWAP_V2, + ) + .await + { + Ok(events) => events, + Err(e) => { + error!( + "Error getting TakerPaymentSpent events from {} to {} block: {}", + next_from_block, to_block, e + ); + Timer::sleep(check_every).await; + // Move to next window if there was an error + next_from_block += self.logs_block_range; + continue; + }, + }; + + // This is how spent event looks like in EtomicSwapTakerV2: event TakerPaymentSpent(bytes32 id, bytes32 secret). + // Check if any event matches the ID. + if let Some(found_event) = events.into_iter().find(|event| &event.data.0[..32] == id.as_slice()) { + if let Some(hash) = found_event.transaction_hash { + // Store tx_hash to skip fetching events in the next iteration if "eth_getTransactionByHash" is unsuccessful + tx_hash = Some(hash); + break; + } } + + next_from_block += self.logs_block_range; } } From 47f904ceebd27a7d1d917f436c8ec0861579d2c6 Mon Sep 17 00:00:00 2001 From: laruh Date: Mon, 18 Nov 2024 15:51:39 +0700 Subject: [PATCH 23/59] use logs_block_range in legacy wait_for_htlc_tx_spend function --- mm2src/coins/eth.rs | 76 ++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 3f5863e896..3b6656f12e 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -2607,6 +2607,7 @@ impl MarketCoinOps for EthCoin { }, }; + let mut tx_hash: Option = None; loop { if now_sec() > args.wait_until { return TX_PLAIN_ERR!( @@ -2616,46 +2617,71 @@ impl MarketCoinOps for EthCoin { ); } - let events = match self - .events_from_block( - swap_contract_address, - "ReceiverSpent", - args.from_block, - None, - &SWAP_CONTRACT, - ) - .await - { - Ok(ev) => ev, + let current_block = match self.current_block().compat().await { + Ok(b) => b, Err(e) => { - error!("Error getting spend events: {}", e); + error!("Error getting block number: {}", e); Timer::sleep(5.).await; continue; }, }; - let found = events.iter().find(|event| &event.data.0[..32] == id.as_slice()); + if tx_hash.is_none() { + let mut next_from_block = args.from_block; - if let Some(event) = found { - if let Some(tx_hash) = event.transaction_hash { - let transaction = match self.transaction(TransactionId::Hash(tx_hash)).await { - Ok(Some(t)) => t, - Ok(None) => { - info!("Tx {} not found yet", tx_hash); - Timer::sleep(args.check_every).await; - continue; - }, + // Split the range into windows of size logs_block_range + while next_from_block <= current_block { + let to_block = std::cmp::min(next_from_block + self.logs_block_range - 1, current_block); + + let events = match self + .events_from_block( + swap_contract_address, + "ReceiverSpent", + next_from_block, + Some(to_block), + &SWAP_CONTRACT, + ) + .await + { + Ok(ev) => ev, Err(e) => { - error!("Get tx {} error: {}", tx_hash, e); - Timer::sleep(args.check_every).await; + error!( + "Error getting spend events from {} to {} block: {}", + next_from_block, to_block, e + ); + Timer::sleep(5.).await; + next_from_block += self.logs_block_range; continue; }, }; - return Ok(TransactionEnum::from(try_tx_s!(signed_tx_from_web3_tx(transaction)))); + // Check if any event matches the SWAP ID + if let Some(found_event) = events.iter().find(|event| &event.data.0[..32] == id.as_slice()) { + if let Some(hash) = found_event.transaction_hash { + // Store tx_hash to skip fetching events in the next iteration if "eth_getTransactionByHash" is unsuccessful + tx_hash = Some(hash); + break; + } + } + + // Move to the next block range window + next_from_block += self.logs_block_range; } } + // Proceed getting spend transaction if we have a tx_hash + if let Some(tx_hash) = tx_hash { + match self.transaction(TransactionId::Hash(tx_hash)).await { + Ok(Some(t)) => { + return Ok(TransactionEnum::from(try_tx_s!(signed_tx_from_web3_tx(t)))); + }, + Ok(None) => info!("Tx {} not found yet", tx_hash), + Err(e) => error!("Get tx {} error: {}", tx_hash, e), + }; + Timer::sleep(args.check_every).await; + continue; + } + Timer::sleep(5.).await; } } From 2056f9bfd9c7890d09657d9f92052f0613eb80a1 Mon Sep 17 00:00:00 2001 From: laruh Date: Mon, 18 Nov 2024 18:37:16 +0700 Subject: [PATCH 24/59] remove time sleep from the end of loop --- mm2src/coins/eth.rs | 2 -- mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 3b6656f12e..ec78e62738 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -2681,8 +2681,6 @@ impl MarketCoinOps for EthCoin { Timer::sleep(args.check_every).await; continue; } - - Timer::sleep(5.).await; } } diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index 9fec303bcb..eea6724b6a 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -557,8 +557,6 @@ impl EthCoin { Timer::sleep(check_every).await; continue; } - - Timer::sleep(check_every).await; } } From 0b3ab9a5e37d9b8847db2657efa704a24509f1c9 Mon Sep 17 00:00:00 2001 From: laruh Date: Mon, 18 Nov 2024 21:26:56 +0700 Subject: [PATCH 25/59] remove legacy_spend_events function and use new one instead --- mm2src/coins/eth.rs | 33 +++++++++------------------------ mm2src/coins/eth/eth_tests.rs | 3 ++- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index ec78e62738..7fa870e5c9 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -4892,27 +4892,6 @@ impl EthCoin { Box::new(fut.boxed().compat()) } - /// Gets `ReceiverSpent` events from etomic swap smart contract since `from_block` to `to_block` - fn legacy_spend_events( - &self, - swap_contract_address: Address, - from_block: u64, - to_block: u64, - ) -> Box, Error = String> + Send> { - let contract_event = try_fus!(SWAP_CONTRACT.event("ReceiverSpent")); - let filter = FilterBuilder::default() - .topics(Some(vec![contract_event.signature()]), None, None, None) - .from_block(BlockNumber::Number(from_block.into())) - .to_block(BlockNumber::Number(to_block.into())) - .address(vec![swap_contract_address]) - .build(); - - let coin = self.clone(); - - let fut = async move { coin.logs(filter).await.map_err(|e| ERRL!("{}", e)) }; - Box::new(fut.boxed().compat()) - } - /// Returns events from `from_block` to `to_block` or current `latest` block. /// According to ["eth_getLogs" doc](https://docs.infura.io/api/networks/ethereum/json-rpc-methods/eth_getlogs) `toBlock` is optional, default is "latest". async fn events_from_block( @@ -5298,10 +5277,16 @@ impl EthCoin { let to_block = current_block.min(from_block + self.logs_block_range); let spend_events = try_s!( - self.legacy_spend_events(swap_contract_address, from_block, to_block) - .compat() - .await + self.events_from_block( + swap_contract_address, + "ReceiverSpent", + from_block, + Some(to_block), + &SWAP_CONTRACT + ) + .await ); + let found = spend_events.iter().find(|event| &event.data.0[..32] == id.as_slice()); if let Some(event) = found { diff --git a/mm2src/coins/eth/eth_tests.rs b/mm2src/coins/eth/eth_tests.rs index 5f60f5b045..2e874e1e35 100644 --- a/mm2src/coins/eth/eth_tests.rs +++ b/mm2src/coins/eth/eth_tests.rs @@ -1,6 +1,7 @@ use super::*; use crate::IguanaPrivKey; use common::{block_on, block_on_f01}; +use futures_util::future; use mm2_core::mm_ctx::MmCtxBuilder; cfg_native!( @@ -163,7 +164,7 @@ fn test_wei_from_big_decimal() { fn test_wait_for_payment_spend_timeout() { const TAKER_PAYMENT_SPEND_SEARCH_INTERVAL: f64 = 1.; - EthCoin::legacy_spend_events.mock_safe(|_, _, _, _| MockResult::Return(Box::new(futures01::future::ok(vec![])))); + EthCoin::events_from_block.mock_safe(|_, _, _, _, _, _| MockResult::Return(Box::pin(future::ok(vec![])))); EthCoin::current_block.mock_safe(|_| MockResult::Return(Box::new(futures01::future::ok(900)))); let key_pair = Random.generate().unwrap(); From c1a5063da0498be25b53d02b746674dc052d8bee Mon Sep 17 00:00:00 2001 From: laruh Date: Wed, 27 Nov 2024 22:03:03 +0700 Subject: [PATCH 26/59] impl detect_secret_hash_algo_v2 function --- mm2src/coins/lp_coins.rs | 15 ++++++ mm2src/crypto/src/lib.rs | 1 + mm2src/crypto/src/secret_hash_algo.rs | 39 ++++++++++++++ mm2src/mm2_main/src/lp_ordermatch.rs | 11 ++-- mm2src/mm2_main/src/lp_swap.rs | 53 ++++++-------------- mm2src/mm2_main/src/lp_swap/maker_swap.rs | 5 +- mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs | 3 +- mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 4 +- 8 files changed, 83 insertions(+), 48 deletions(-) create mode 100644 mm2src/crypto/src/secret_hash_algo.rs diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index a01042bc16..06f9c8c52e 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -212,6 +212,7 @@ pub mod watcher_common; pub mod coin_errors; use coin_errors::{MyAddressError, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentResult}; +use crypto::secret_hash_algo::SecretHashAlgo; #[doc(hidden)] #[cfg(test)] @@ -3563,6 +3564,20 @@ impl MmCoinEnum { pub fn is_eth(&self) -> bool { matches!(self, MmCoinEnum::EthCoin(_)) } fn is_platform_coin(&self) -> bool { self.ticker() == self.platform_ticker() } + + pub fn maker_secret_hash_algo_v2(&self) -> SecretHashAlgo { + match self { + MmCoinEnum::EthCoin(_) => SecretHashAlgo::SHA256, + _ => SecretHashAlgo::DHASH160, + } + } + + pub fn taker_secret_hash_algo_v2(&self) -> SecretHashAlgo { + match self { + MmCoinEnum::EthCoin(_) => SecretHashAlgo::SHA256, + _ => SecretHashAlgo::DHASH160, + } + } } #[async_trait] diff --git a/mm2src/crypto/src/lib.rs b/mm2src/crypto/src/lib.rs index e2651a54ea..f735203232 100644 --- a/mm2src/crypto/src/lib.rs +++ b/mm2src/crypto/src/lib.rs @@ -12,6 +12,7 @@ pub mod hw_rpc_task; mod key_derivation; pub mod mnemonic; pub mod privkey; +pub mod secret_hash_algo; mod shared_db_id; mod slip21; mod standard_hd_path; diff --git a/mm2src/crypto/src/secret_hash_algo.rs b/mm2src/crypto/src/secret_hash_algo.rs new file mode 100644 index 0000000000..15d7a08f75 --- /dev/null +++ b/mm2src/crypto/src/secret_hash_algo.rs @@ -0,0 +1,39 @@ +use bitcrypto::{dhash160, sha256}; +use derive_more::Display; +use std::convert::TryFrom; + +/// Algorithm used to hash swap secret. +#[derive(Clone, Copy, Debug, Deserialize, Serialize, Default)] +pub enum SecretHashAlgo { + /// ripemd160(sha256(secret)) + #[default] + DHASH160 = 1, + /// sha256(secret) + SHA256 = 2, +} + +#[derive(Debug, Display)] +pub struct UnsupportedSecretHashAlgo(u8); + +impl std::error::Error for UnsupportedSecretHashAlgo {} + +impl TryFrom for SecretHashAlgo { + type Error = UnsupportedSecretHashAlgo; + + fn try_from(value: u8) -> Result { + match value { + 1 => Ok(SecretHashAlgo::DHASH160), + 2 => Ok(SecretHashAlgo::SHA256), + unsupported => Err(UnsupportedSecretHashAlgo(unsupported)), + } + } +} + +impl SecretHashAlgo { + pub fn hash_secret(&self, secret: &[u8]) -> Vec { + match self { + SecretHashAlgo::DHASH160 => dhash160(secret).take().into(), + SecretHashAlgo::SHA256 => sha256(secret).take().into(), + } + } +} diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index d187e53234..0dc7fd16da 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -75,17 +75,18 @@ use crate::lp_network::{broadcast_p2p_msg, request_any_relay, request_one_peer, use crate::lp_swap::maker_swap_v2::{self, MakerSwapStateMachine, MakerSwapStorage}; use crate::lp_swap::taker_swap_v2::{self, TakerSwapStateMachine, TakerSwapStorage}; use crate::lp_swap::{calc_max_maker_vol, check_balance_for_maker_swap, check_balance_for_taker_swap, - check_other_coin_balance_for_swap, detect_secret_hash_algo, dex_fee_amount_from_taker_coin, + check_other_coin_balance_for_swap, detect_secret_hash_algo_v2, dex_fee_amount_from_taker_coin, generate_secret, get_max_maker_vol, insert_new_swap_to_db, is_pubkey_banned, lp_atomic_locktime, p2p_keypair_and_peer_id_to_broadcast, p2p_private_and_peer_id_to_broadcast, run_maker_swap, run_taker_swap, swap_v2_topic, AtomicLocktimeVersion, CheckBalanceError, CheckBalanceResult, - CoinVolumeInfo, MakerSwap, RunMakerSwapInput, RunTakerSwapInput, SecretHashAlgo, - SwapConfirmationsSettings, TakerSwap, LEGACY_SWAP_TYPE}; + CoinVolumeInfo, MakerSwap, RunMakerSwapInput, RunTakerSwapInput, SwapConfirmationsSettings, + TakerSwap, LEGACY_SWAP_TYPE}; #[cfg(any(test, feature = "run-docker-tests"))] use crate::lp_swap::taker_swap::FailAt; pub use best_orders::{best_orders_rpc, best_orders_rpc_v2}; +use crypto::secret_hash_algo::SecretHashAlgo; pub use orderbook_depth::orderbook_depth_rpc; pub use orderbook_rpc::{orderbook_rpc, orderbook_rpc_v2}; @@ -3046,7 +3047,7 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO } let params = StateMachineParams { - secret_hash_algo: &detect_secret_hash_algo(&maker_coin, &taker_coin), + secret_hash_algo: &detect_secret_hash_algo_v2(&maker_coin, &taker_coin), uuid: &uuid, my_conf_settings: &my_conf_settings, locktime: &lock_time, @@ -3285,7 +3286,7 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat }, }; let params = StateMachineParams { - secret_hash_algo: &detect_secret_hash_algo(&maker_coin, &taker_coin), + secret_hash_algo: &detect_secret_hash_algo_v2(&maker_coin, &taker_coin), uuid: &uuid, my_conf_settings: &my_conf_settings, locktime: &locktime, diff --git a/mm2src/mm2_main/src/lp_swap.rs b/mm2src/mm2_main/src/lp_swap.rs index 0acb7fc443..3ae9aa57a5 100644 --- a/mm2src/mm2_main/src/lp_swap.rs +++ b/mm2src/mm2_main/src/lp_swap.rs @@ -61,7 +61,7 @@ use super::lp_network::P2PRequestResult; use crate::lp_network::{broadcast_p2p_msg, Libp2pPeerId, P2PProcessError, P2PProcessResult, P2PRequestError}; use crate::lp_swap::maker_swap_v2::{MakerSwapStateMachine, MakerSwapStorage}; use crate::lp_swap::taker_swap_v2::{TakerSwapStateMachine, TakerSwapStorage}; -use bitcrypto::{dhash160, sha256}; +use bitcrypto::sha256; use coins::{lp_coinfind, lp_coinfind_or_err, CoinFindError, DexFee, MmCoin, MmCoinEnum, TradeFee, TransactionEnum}; use common::log::{debug, warn}; use common::now_sec; @@ -83,7 +83,6 @@ use secp256k1::{PublicKey, SecretKey, Signature}; use serde::Serialize; use serde_json::{self as json, Value as Json}; use std::collections::{HashMap, HashSet}; -use std::convert::TryFrom; use std::num::NonZeroUsize; use std::path::PathBuf; use std::str::FromStr; @@ -118,6 +117,7 @@ mod trade_preimage; pub use check_balance::{check_other_coin_balance_for_swap, CheckBalanceError, CheckBalanceResult}; use coins::utxo::utxo_standard::UtxoStandardCoin; +use crypto::secret_hash_algo::SecretHashAlgo; use crypto::CryptoCtx; use keys::{KeyPair, SECP_SIGN, SECP_VERIFY}; use maker_swap::MakerSwapEvent; @@ -1624,42 +1624,6 @@ pub async fn active_swaps_rpc(ctx: MmArc, req: Json) -> Result> Ok(try_s!(Response::builder().body(res))) } -/// Algorithm used to hash swap secret. -#[derive(Clone, Copy, Debug, Deserialize, Serialize, Default)] -pub enum SecretHashAlgo { - /// ripemd160(sha256(secret)) - #[default] - DHASH160 = 1, - /// sha256(secret) - SHA256 = 2, -} - -#[derive(Debug, Display)] -pub struct UnsupportedSecretHashAlgo(u8); - -impl std::error::Error for UnsupportedSecretHashAlgo {} - -impl TryFrom for SecretHashAlgo { - type Error = UnsupportedSecretHashAlgo; - - fn try_from(value: u8) -> Result { - match value { - 1 => Ok(SecretHashAlgo::DHASH160), - 2 => Ok(SecretHashAlgo::SHA256), - unsupported => Err(UnsupportedSecretHashAlgo(unsupported)), - } - } -} - -impl SecretHashAlgo { - fn hash_secret(&self, secret: &[u8]) -> Vec { - match self { - SecretHashAlgo::DHASH160 => dhash160(secret).take().into(), - SecretHashAlgo::SHA256 => sha256(secret).take().into(), - } - } -} - // Todo: Maybe add a secret_hash_algo method to the SwapOps trait instead /// Selects secret hash algorithm depending on types of coins being swapped #[cfg(not(target_arch = "wasm32"))] @@ -1684,6 +1648,19 @@ pub fn detect_secret_hash_algo(maker_coin: &MmCoinEnum, taker_coin: &MmCoinEnum) } } +pub fn detect_secret_hash_algo_v2(maker_coin: &MmCoinEnum, taker_coin: &MmCoinEnum) -> SecretHashAlgo { + let maker_algo = maker_coin.maker_secret_hash_algo_v2(); + let taker_algo = taker_coin.taker_secret_hash_algo_v2(); + if matches!( + (maker_algo, taker_algo), + (SecretHashAlgo::SHA256, _) | (_, SecretHashAlgo::SHA256) + ) { + SecretHashAlgo::SHA256 + } else { + SecretHashAlgo::DHASH160 + } +} + pub struct SwapPubkeys { pub maker: String, pub taker: String, diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap.rs b/mm2src/mm2_main/src/lp_swap/maker_swap.rs index 0eb72b8a71..8031efe9e5 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap.rs @@ -8,8 +8,8 @@ use super::{broadcast_my_swap_status, broadcast_p2p_tx_msg, broadcast_swap_msg_e get_locked_amount, recv_swap_msg, swap_topic, taker_payment_spend_deadline, tx_helper_topic, wait_for_maker_payment_conf_until, AtomicSwap, LockedAmount, MySwapInfo, NegotiationDataMsg, NegotiationDataV2, NegotiationDataV3, RecoveredSwap, RecoveredSwapAction, SavedSwap, SavedSwapIo, - SavedTradeFee, SecretHashAlgo, SwapConfirmationsSettings, SwapError, SwapMsg, SwapPubkeys, SwapTxDataMsg, - SwapsContext, TransactionIdentifier, INCLUDE_REFUND_FEE, NO_REFUND_FEE, TAKER_FEE_VALIDATION_ATTEMPTS, + SavedTradeFee, SwapConfirmationsSettings, SwapError, SwapMsg, SwapPubkeys, SwapTxDataMsg, SwapsContext, + TransactionIdentifier, INCLUDE_REFUND_FEE, NO_REFUND_FEE, TAKER_FEE_VALIDATION_ATTEMPTS, TAKER_FEE_VALIDATION_RETRY_DELAY_SECS, WAIT_CONFIRM_INTERVAL_SEC}; use crate::lp_dispatcher::{DispatcherContext, LpEvents}; use crate::lp_network::subscribe_to_topic; @@ -25,6 +25,7 @@ use common::log::{debug, error, info, warn}; use common::{bits256, executor::Timer, now_ms, DEX_FEE_ADDR_RAW_PUBKEY}; use common::{now_sec, wait_until_sec}; use crypto::privkey::SerializableSecp256k1Keypair; +use crypto::secret_hash_algo::SecretHashAlgo; use crypto::CryptoCtx; use futures::{compat::Future01CompatExt, select, FutureExt}; use keys::KeyPair; diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index a2334748bb..3b0b20cc7b 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -3,7 +3,7 @@ use super::{swap_v2_topic, LockedAmount, LockedAmountInfo, SavedTradeFee, SwapsC NEGOTIATION_TIMEOUT_SEC}; use crate::lp_swap::maker_swap::MakerSwapPreparedParams; use crate::lp_swap::swap_lock::SwapLock; -use crate::lp_swap::{broadcast_swap_v2_msg_every, check_balance_for_maker_swap, recv_swap_v2_msg, SecretHashAlgo, +use crate::lp_swap::{broadcast_swap_v2_msg_every, check_balance_for_maker_swap, recv_swap_v2_msg, SwapConfirmationsSettings, TransactionIdentifier, MAKER_SWAP_V2_TYPE, MAX_STARTED_AT_DIFF}; use crate::lp_swap::{swap_v2_pb::*, NO_REFUND_FEE}; use async_trait::async_trait; @@ -17,6 +17,7 @@ use common::executor::{AbortableSystem, Timer}; use common::log::{debug, error, info, warn}; use common::{now_sec, Future01CompatExt, DEX_FEE_ADDR_RAW_PUBKEY}; use crypto::privkey::SerializableSecp256k1Keypair; +use crypto::secret_hash_algo::SecretHashAlgo; use keys::KeyPair; use mm2_core::mm_ctx::MmArc; use mm2_err_handle::prelude::*; diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs index 3ea6261b0e..c2ff7538b8 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs @@ -3,8 +3,7 @@ use super::{LockedAmount, LockedAmountInfo, SavedTradeFee, SwapsContext, TakerSw NEGOTIATE_SEND_INTERVAL, NEGOTIATION_TIMEOUT_SEC}; use crate::lp_swap::swap_lock::SwapLock; use crate::lp_swap::{broadcast_swap_v2_msg_every, check_balance_for_taker_swap, recv_swap_v2_msg, swap_v2_topic, - SecretHashAlgo, SwapConfirmationsSettings, TransactionIdentifier, MAX_STARTED_AT_DIFF, - TAKER_SWAP_V2_TYPE}; + SwapConfirmationsSettings, TransactionIdentifier, MAX_STARTED_AT_DIFF, TAKER_SWAP_V2_TYPE}; use crate::lp_swap::{swap_v2_pb::*, NO_REFUND_FEE}; use async_trait::async_trait; use bitcrypto::{dhash160, sha256}; @@ -18,6 +17,7 @@ use common::executor::{AbortableSystem, Timer}; use common::log::{debug, error, info, warn}; use common::{Future01CompatExt, DEX_FEE_ADDR_RAW_PUBKEY}; use crypto::privkey::SerializableSecp256k1Keypair; +use crypto::secret_hash_algo::SecretHashAlgo; use keys::KeyPair; use mm2_core::mm_ctx::MmArc; use mm2_err_handle::prelude::*; From 43c2d94bc94b21bdda580ca8eb5f0ed185dcaf1f Mon Sep 17 00:00:00 2001 From: laruh Date: Sat, 30 Nov 2024 17:49:27 +0700 Subject: [PATCH 27/59] Add new addr_to_string function to ParseCoinAssocTypes trait and use it in state machine, instead of to_string --- mm2src/coins/eth.rs | 3 +++ mm2src/coins/lp_coins.rs | 8 ++++++++ mm2src/coins/test_coin.rs | 2 ++ mm2src/coins/utxo.rs | 2 ++ mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs | 3 ++- 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 6502275d12..e88230758b 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -7041,7 +7041,10 @@ impl ParseCoinAssocTypes for EthCoin { } } + fn addr_to_string(&self, address: &Self::Address) -> String { eth_addr_to_hex(address) } + fn parse_address(&self, address: &str) -> Result { + // crate `Address::from_str` supports both address variants with and without `0x` prefix Address::from_str(address).map_to_mm(|e| EthAssocTypesError::InvalidHexString(e.to_string())) } diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 06f9c8c52e..1eb66ce655 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1547,6 +1547,14 @@ pub trait ParseCoinAssocTypes { async fn my_addr(&self) -> Self::Address; + /// Converts coin `Self::Address` type into a properly formatted string representation. + /// + /// Don't use `to_string` directly on `Self::Address` types in generic TPU code! + /// It may produce abbreviated or non-standard formats (e.g. `ethereum_types::Address` will be like this `0x7cc9…3874`), + /// which are not guaranteed to be parsable back into the original `Address` type. + /// This function should ensure the resulting string is consistently formatted and fully reversible. + fn addr_to_string(&self, address: &Self::Address) -> String; + fn parse_address(&self, address: &str) -> Result; fn parse_pubkey(&self, pubkey: &[u8]) -> Result; diff --git a/mm2src/coins/test_coin.rs b/mm2src/coins/test_coin.rs index d3068b812a..fcb4233765 100644 --- a/mm2src/coins/test_coin.rs +++ b/mm2src/coins/test_coin.rs @@ -456,6 +456,8 @@ impl ParseCoinAssocTypes for TestCoin { async fn my_addr(&self) -> Self::Address { todo!() } + fn addr_to_string(&self, address: &Self::Address) -> String { unimplemented!() } + fn parse_address(&self, address: &str) -> Result { todo!() } fn parse_pubkey(&self, pubkey: &[u8]) -> Result { unimplemented!() } diff --git a/mm2src/coins/utxo.rs b/mm2src/coins/utxo.rs index 6d98451c7f..f1c055f3fc 100644 --- a/mm2src/coins/utxo.rs +++ b/mm2src/coins/utxo.rs @@ -1053,6 +1053,8 @@ impl ParseCoinAssocTypes for T { } } + fn addr_to_string(&self, address: &Self::Address) -> String { address.to_string() } + fn parse_address(&self, address: &str) -> Result { self.address_from_str(address) } diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index 3b0b20cc7b..a306ab97e9 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -913,6 +913,7 @@ impl, state_machine: &mut Self::StateMachine) -> StateResult { let unique_data = state_machine.unique_data(); + let taker_coin_address = state_machine.taker_coin.my_addr().await; let maker_negotiation_msg = MakerNegotiation { started_at: state_machine.started_at, @@ -922,7 +923,7 @@ impl Date: Sun, 1 Dec 2024 20:13:31 +0700 Subject: [PATCH 28/59] require BlockNumber field in call_request func, use BlockNumber::Pending in payment_status_v2, leave todo in legacy payment_status to use BlockNumber::Pending instead of Latest --- mm2src/coins/eth.rs | 28 +++++++++++++++++++--------- mm2src/coins/eth/eth_swap_v2/mod.rs | 14 ++++++++++---- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index e88230758b..be08e3471f 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -4568,7 +4568,9 @@ impl EthCoin { let function = ERC20_CONTRACT.function("balanceOf")?; let data = function.encode_input(&[Token::Address(address)])?; - let res = coin.call_request(address, *token_addr, None, Some(data.into())).await?; + let res = coin + .call_request(address, *token_addr, None, Some(data.into()), BlockNumber::Latest) + .await?; let decoded = function.decode_output(&res.0)?; match decoded[0] { Token::Uint(number) => Ok(number), @@ -4632,7 +4634,7 @@ impl EthCoin { let function = ERC20_CONTRACT.function("balanceOf")?; let data = function.encode_input(&[Token::Address(address)])?; let res = self - .call_request(address, token_address, None, Some(data.into())) + .call_request(address, token_address, None, Some(data.into()), BlockNumber::Latest) .await?; let decoded = function.decode_output(&res.0)?; @@ -4659,7 +4661,7 @@ impl EthCoin { let my_address = self.derivation_method.single_addr_or_err().await?; let data = function.encode_input(&[Token::Address(my_address), Token::Uint(token_id_u256)])?; let result = self - .call_request(my_address, token_addr, None, Some(data.into())) + .call_request(my_address, token_addr, None, Some(data.into()), BlockNumber::Latest) .await?; let decoded = function.decode_output(&result.0)?; match decoded[0] { @@ -4690,7 +4692,7 @@ impl EthCoin { let data = function.encode_input(&[Token::Uint(token_id_u256)])?; let my_address = self.derivation_method.single_addr_or_err().await?; let result = self - .call_request(my_address, token_addr, None, Some(data.into())) + .call_request(my_address, token_addr, None, Some(data.into()), BlockNumber::Latest) .await?; let decoded = function.decode_output(&result.0)?; match decoded[0] { @@ -4768,6 +4770,7 @@ impl EthCoin { to: Address, value: Option, data: Option, + block_number: BlockNumber, ) -> Result { let request = CallRequest { from: Some(from), @@ -4779,7 +4782,7 @@ impl EthCoin { ..CallRequest::default() }; - self.call(request, Some(BlockId::Number(BlockNumber::Latest))).await + self.call(request, Some(BlockId::Number(block_number))).await } fn allowance(&self, spender: Address) -> Web3RpcFut { @@ -4795,7 +4798,7 @@ impl EthCoin { let data = function.encode_input(&[Token::Address(my_address), Token::Address(spender)])?; let res = coin - .call_request(my_address, *token_addr, None, Some(data.into())) + .call_request(my_address, *token_addr, None, Some(data.into()), BlockNumber::Latest) .await?; let decoded = function.decode_output(&res.0)?; @@ -5228,9 +5231,16 @@ impl EthCoin { .single_addr_or_err() .await .map_err(|e| ERRL!("{}", e))?; - coin.call_request(my_address, swap_contract_address, None, Some(data.into())) - .await - .map_err(|e| ERRL!("{}", e)) + coin.call_request( + my_address, + swap_contract_address, + None, + Some(data.into()), + // TODO worth changing this to BlockNumber::Pending + BlockNumber::Latest, + ) + .await + .map_err(|e| ERRL!("{}", e)) }; Box::new(fut.boxed().compat().and_then(move |bytes| { diff --git a/mm2src/coins/eth/eth_swap_v2/mod.rs b/mm2src/coins/eth/eth_swap_v2/mod.rs index 798a232d56..0b903a9b78 100644 --- a/mm2src/coins/eth/eth_swap_v2/mod.rs +++ b/mm2src/coins/eth/eth_swap_v2/mod.rs @@ -7,7 +7,7 @@ use futures::compat::Future01CompatExt; use mm2_err_handle::mm_error::MmError; use mm2_number::BigDecimal; use num_traits::Signed; -use web3::types::Transaction as Web3Tx; +use web3::types::{BlockNumber, Transaction as Web3Tx}; pub(crate) mod eth_maker_swap_v2; pub(crate) mod eth_taker_swap_v2; @@ -82,7 +82,13 @@ impl EthCoin { let function = contract_abi.function(function_name)?; let data = function.encode_input(&[swap_id])?; let bytes = self - .call_request(self.my_addr().await, swap_address, None, Some(data.into())) + .call_request( + self.my_addr().await, + swap_address, + None, + Some(data.into()), + BlockNumber::Pending, + ) .await?; let decoded_tokens = function.decode_output(&bytes.0)?; @@ -133,8 +139,8 @@ pub(crate) fn validate_from_to_and_status( ) -> Result<(), MmError> { if status != U256::from(expected_status) { return MmError::err(ValidatePaymentV2Err::UnexpectedPaymentState(format!( - "Payment state is not `PaymentSent`, got {}", - status + "tx {:?} Payment state is not `PaymentSent`, got {}", + tx_from_rpc.hash, status ))); } if tx_from_rpc.from != Some(expected_from) { From c60a06f2002e071293729200b69b9f55b12f0dc9 Mon Sep 17 00:00:00 2001 From: laruh Date: Mon, 2 Dec 2024 12:11:10 +0700 Subject: [PATCH 29/59] add todo about EVM support for swap v2 kickstart --- mm2src/mm2_main/src/lp_swap/swap_v2_common.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/mm2src/mm2_main/src/lp_swap/swap_v2_common.rs b/mm2src/mm2_main/src/lp_swap/swap_v2_common.rs index 686d263d5a..52f1690335 100644 --- a/mm2src/mm2_main/src/lp_swap/swap_v2_common.rs +++ b/mm2src/mm2_main/src/lp_swap/swap_v2_common.rs @@ -345,6 +345,7 @@ pub(super) async fn swap_kickstart_handler< }; }; + // TODO add ETH support let (maker_coin, taker_coin) = match (maker_coin, taker_coin) { (MmCoinEnum::UtxoCoin(m), MmCoinEnum::UtxoCoin(t)) => (m, t), _ => { From 71600459190372e305d5f0bdab26cea02f52b7ec Mon Sep 17 00:00:00 2001 From: laruh Date: Mon, 2 Dec 2024 13:44:38 +0700 Subject: [PATCH 30/59] accept funding tx in search_for_taker_funding_spend_impl instead of approve tx --- mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs | 12 ++++++------ mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 4 ++-- .../mm2_main/tests/docker_tests/eth_docker_tests.rs | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index eea6724b6a..07ed14af43 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -384,14 +384,14 @@ impl EthCoin { .await } - /// Checks that taker payment state is `TakerApproved`. - /// Accepts a taker-approved payment transaction and returns it if the state is correct. + /// Checks that taker payment state is `TakerApproved`. Called by maker. + /// Accepts a taker payment transaction and returns it if the state is correct. pub(crate) async fn search_for_taker_funding_spend_impl( &self, tx: &SignedEthTx, ) -> Result>, SearchForFundingSpendErr> { let (decoded, taker_swap_v2_contract) = self - .get_decoded_and_swap_contract(tx, TAKER_PAYMENT_APPROVE) + .get_funding_decoded_and_swap_contract(tx) .await .map_err(|e| SearchForFundingSpendErr::Internal(ERRL!("{}", e)))?; let taker_status = self @@ -738,14 +738,14 @@ impl EthCoin { Ok((taker_swap_v2_contract, func, token_address)) } - async fn get_decoded_and_swap_contract( + async fn get_funding_decoded_and_swap_contract( &self, tx: &SignedEthTx, - function_name: &str, ) -> Result<(Vec, Address), PrepareTxDataError> { let decoded = { let func = match self.coin_type { - EthCoinType::Eth | EthCoinType::Erc20 { .. } => TAKER_SWAP_V2.function(function_name)?, + EthCoinType::Eth => TAKER_SWAP_V2.function(ETH_TAKER_PAYMENT)?, + EthCoinType::Erc20 { .. } => TAKER_SWAP_V2.function(ERC20_TAKER_PAYMENT)?, EthCoinType::Nft { .. } => { return Err(PrepareTxDataError::Internal( "NFT protocol is not supported for ETH and ERC20 Swaps".to_string(), diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs index c2ff7538b8..aaa40a72b5 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs @@ -1585,7 +1585,7 @@ impl { - assert_eq!(tx, taker_approve_tx); + assert_eq!(tx, funding_tx); }, FundingTxSpend::RefundedTimelock(_) | FundingTxSpend::RefundedSecret { .. } => { panic!("Wrong FundingTxSpend variant, expected TransferredToTakerPayment") @@ -1857,12 +1857,12 @@ fn taker_send_approve_and_spend_erc20() { wait_for_confirmations(&taker_coin, &taker_approve_tx, 100); wait_pending_transactions(Address::from_slice(maker_address.as_bytes())); - let check_taker_approved_tx = block_on(maker_coin.search_for_taker_funding_spend(&taker_approve_tx, 0u64, &[])) + let check_taker_approved_tx = block_on(maker_coin.search_for_taker_funding_spend(&funding_tx, 0u64, &[])) .unwrap() .unwrap(); match check_taker_approved_tx { FundingTxSpend::TransferredToTakerPayment(tx) => { - assert_eq!(tx, taker_approve_tx); + assert_eq!(tx, funding_tx); }, FundingTxSpend::RefundedTimelock(_) | FundingTxSpend::RefundedSecret { .. } => { panic!("Wrong FundingTxSpend variant, expected TransferredToTakerPayment") From 6201aaea8a856f0a0dbec5b3a5f0e9ddd6be7eb3 Mon Sep 17 00:00:00 2001 From: laruh Date: Mon, 2 Dec 2024 19:16:13 +0700 Subject: [PATCH 31/59] fix sign_and_broadcast_taker_payment_spend_impl, improve doc comment --- .../eth/eth_swap_v2/eth_taker_swap_v2.rs | 102 ++++++++++++------ .../tests/docker_tests/eth_docker_tests.rs | 4 +- 2 files changed, 69 insertions(+), 37 deletions(-) diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index 07ed14af43..1407da3074 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -397,7 +397,7 @@ impl EthCoin { let taker_status = self .payment_status_v2( taker_swap_v2_contract, - decoded[0].clone(), // id from takerPaymentApprove + decoded[0].clone(), // id from ethTakerPayment or erc20TakerPayment &TAKER_SWAP_V2, EthPaymentType::TakerPayments, TAKER_PAYMENT_STATE_INDEX, @@ -410,8 +410,8 @@ impl EthCoin { Ok(None) } - /// Taker swap contract `spendTakerPayment` method is called for EVM based chains. - /// Returns maker spent payment transaction. + /// Returns maker spent taker payment transaction. Called by maker. + /// Taker swap contract's `spendTakerPayment` method is called for EVM-based chains. pub(crate) async fn sign_and_broadcast_taker_payment_spend_impl( &self, gen_args: &GenTakerPaymentSpendArgs<'_, Self>, @@ -422,10 +422,10 @@ impl EthCoin { .gas_limit(&self.coin_type, EthPaymentType::TakerPayments, PaymentMethod::Spend) .map_err(|e| TransactionErr::Plain(ERRL!("{}", e)))?; - let (taker_swap_v2_contract, approve_func, token_address) = self - .taker_swap_v2_details(TAKER_PAYMENT_APPROVE, TAKER_PAYMENT_APPROVE) + let (taker_swap_v2_contract, taker_payment, token_address) = self + .taker_swap_v2_details(ETH_TAKER_PAYMENT, ERC20_TAKER_PAYMENT) .await?; - let decoded = try_tx_s!(decode_contract_call(approve_func, gen_args.taker_tx.unsigned().data())); + let decoded = try_tx_s!(decode_contract_call(taker_payment, gen_args.taker_tx.unsigned().data())); let taker_status = try_tx_s!( self.payment_status_v2( taker_swap_v2_contract, @@ -647,24 +647,13 @@ impl EthCoin { let function = TAKER_SWAP_V2.function(TAKER_PAYMENT_APPROVE)?; let data = match self.coin_type { EthCoinType::Eth => { - check_decoded_length(&decoded, 7)?; - let dex_fee = match &decoded[1] { - Token::Uint(value) => value, - _ => return Err(PrepareTxDataError::Internal("Invalid token type for dex fee".into())), - }; - let amount = args - .funding_tx - .unsigned() - .value() - .checked_sub(*dex_fee) - .ok_or_else(|| { - PrepareTxDataError::Internal("Underflow occurred while calculating amount".into()) - })?; + let (dex_fee, amount) = + get_dex_fee_and_amount_from_eth_payment_data(&decoded, args.funding_tx.unsigned().value())?; function.encode_input(&[ - decoded[0].clone(), // id from ethTakerPayment - Token::Uint(amount), // calculated payment amount (tx value - dexFee) - decoded[1].clone(), // dexFee from ethTakerPayment - decoded[2].clone(), // receiver from ethTakerPayment + decoded[0].clone(), // id from ethTakerPayment + Token::Uint(amount), // calculated payment amount (tx value - dexFee) + Token::Uint(dex_fee), // dexFee from ethTakerPayment + decoded[2].clone(), // receiver from ethTakerPayment Token::FixedBytes(args.taker_secret_hash.to_vec()), Token::FixedBytes(args.maker_secret_hash.to_vec()), Token::Address(token_address), // should be zero address Address::default() @@ -683,7 +672,9 @@ impl EthCoin { ])? }, EthCoinType::Nft { .. } => { - return Err(PrepareTxDataError::Internal("EthCoinType must be ETH or ERC20".into())) + return Err(PrepareTxDataError::Internal( + "NFT protocol is not supported for ETH and ERC20 Swaps".into(), + )) }, }; Ok(data) @@ -697,19 +688,40 @@ impl EthCoin { decoded: Vec, token_address: Address, ) -> Result, PrepareTxDataError> { - check_decoded_length(&decoded, 7)?; let function = TAKER_SWAP_V2.function("spendTakerPayment")?; let taker_address = public_to_address(args.taker_pub); - let data = function.encode_input(&[ - decoded[0].clone(), // id from takerPaymentApprove - decoded[1].clone(), // amount from takerPaymentApprove - decoded[2].clone(), // dexFee from takerPaymentApprove - Token::Address(taker_address), // taker address - decoded[4].clone(), // takerSecretHash from ethTakerPayment - Token::FixedBytes(secret.to_vec()), // makerSecret - Token::Address(token_address), // tokenAddress - ])?; - Ok(data) + match self.coin_type { + EthCoinType::Eth => { + let (dex_fee, amount) = + get_dex_fee_and_amount_from_eth_payment_data(&decoded, args.taker_tx.unsigned().value())?; + let data = function.encode_input(&[ + decoded[0].clone(), // id from ethTakerPayment + Token::Uint(amount), // calculated payment amount (tx value - dexFee) + Token::Uint(dex_fee), // dexFee from ethTakerPayment + Token::Address(taker_address), // taker address + decoded[3].clone(), // takerSecretHash from ethTakerPayment + Token::FixedBytes(secret.to_vec()), // makerSecret + Token::Address(token_address), // tokenAddress + ])?; + Ok(data) + }, + EthCoinType::Erc20 { .. } => { + check_decoded_length(&decoded, 9)?; + let data = function.encode_input(&[ + decoded[0].clone(), // id from erc20TakerPayment + decoded[1].clone(), // amount from erc20TakerPayment + decoded[2].clone(), // dexFee from erc20TakerPayment + Token::Address(taker_address), // taker address + decoded[5].clone(), // takerSecretHash from erc20TakerPayment + Token::FixedBytes(secret.to_vec()), // makerSecret + Token::Address(token_address), // tokenAddress + ])?; + Ok(data) + }, + EthCoinType::Nft { .. } => Err(PrepareTxDataError::Internal( + "NFT protocol is not supported for ETH and ERC20 Swaps".to_string(), + )), + } } /// Retrieves the taker smart contract address, the corresponding function, and the token address. @@ -874,3 +886,23 @@ fn validate_erc20_taker_payment_data( } Ok(()) } + +fn get_dex_fee_and_amount_from_eth_payment_data( + decoded: &Vec, + tx_value: U256, +) -> Result<(U256, U256), PrepareTxDataError> { + check_decoded_length(decoded, 7)?; + let dex_fee = match decoded.get(1) { + Some(Token::Uint(dex_fee)) => *dex_fee, + _ => { + return Err(PrepareTxDataError::Internal(format!( + "Invalid token type for dex fee, got decoded function data: {:?}", + decoded + ))) + }, + }; + let amount = tx_value + .checked_sub(dex_fee) + .ok_or_else(|| PrepareTxDataError::Internal("Underflow occurred while calculating amount".into()))?; + Ok((dex_fee, amount)) +} diff --git a/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs b/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs index fdcdb1c9f3..3f93b27386 100644 --- a/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs @@ -1755,7 +1755,7 @@ fn taker_send_approve_and_spend_eth() { let dex_fee_pub = sepolia_taker_swap_v2(); let spend_args = GenTakerPaymentSpendArgs { - taker_tx: &taker_approve_tx, + taker_tx: &funding_tx, time_lock: payment_time_lock, maker_secret_hash: &maker_secret_hash, maker_pub, @@ -1871,7 +1871,7 @@ fn taker_send_approve_and_spend_erc20() { let dex_fee_pub = sepolia_taker_swap_v2(); let spend_args = GenTakerPaymentSpendArgs { - taker_tx: &taker_approve_tx, + taker_tx: &funding_tx, time_lock: payment_time_lock, maker_secret_hash: &maker_secret_hash, maker_pub, From 0877d06b43c7041e357b198fdb16408c3a4e904e Mon Sep 17 00:00:00 2001 From: laruh Date: Tue, 3 Dec 2024 21:23:26 +0700 Subject: [PATCH 32/59] move block_number to payment_status_v2 fields --- mm2src/coins/eth.rs | 2 +- mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs | 3 ++- mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs | 6 +++++- mm2src/coins/eth/eth_swap_v2/mod.rs | 3 ++- mm2src/coins/eth/nft_swap_v2/mod.rs | 4 +++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index be08e3471f..cb0445ab75 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -5236,7 +5236,7 @@ impl EthCoin { swap_contract_address, None, Some(data.into()), - // TODO worth changing this to BlockNumber::Pending + // TODO worth reviewing places where we could use BlockNumber::Pending BlockNumber::Latest, ) .await diff --git a/mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs index 3089604ede..732dc1a920 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs @@ -13,7 +13,7 @@ use futures::compat::Future01CompatExt; use mm2_err_handle::mm_error::MmError; use mm2_err_handle::prelude::MapToMmResult; use std::convert::TryInto; -use web3::types::TransactionId; +use web3::types::{BlockNumber, TransactionId}; const ETH_MAKER_PAYMENT: &str = "ethMakerPayment"; const ERC20_MAKER_PAYMENT: &str = "erc20MakerPayment"; @@ -143,6 +143,7 @@ impl EthCoin { &MAKER_SWAP_V2, EthPaymentType::MakerPayments, MAKER_PAYMENT_STATE_INDEX, + BlockNumber::Latest, ) .await?; diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index 1407da3074..02a3e97486 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -16,7 +16,7 @@ use ethkey::public_to_address; use futures::compat::Future01CompatExt; use mm2_err_handle::prelude::{MapToMmResult, MmError, MmResult}; use std::convert::TryInto; -use web3::types::{TransactionId, H256}; +use web3::types::{BlockNumber, TransactionId, H256}; const ETH_TAKER_PAYMENT: &str = "ethTakerPayment"; const ERC20_TAKER_PAYMENT: &str = "erc20TakerPayment"; @@ -166,6 +166,7 @@ impl EthCoin { &TAKER_SWAP_V2, EthPaymentType::TakerPayments, TAKER_PAYMENT_STATE_INDEX, + BlockNumber::Latest, ) .await?; @@ -244,6 +245,7 @@ impl EthCoin { &TAKER_SWAP_V2, EthPaymentType::TakerPayments, TAKER_PAYMENT_STATE_INDEX, + BlockNumber::Latest, ) .await ); @@ -401,6 +403,7 @@ impl EthCoin { &TAKER_SWAP_V2, EthPaymentType::TakerPayments, TAKER_PAYMENT_STATE_INDEX, + BlockNumber::Latest, ) .await .map_err(|e| SearchForFundingSpendErr::Internal(ERRL!("{}", e)))?; @@ -433,6 +436,7 @@ impl EthCoin { &TAKER_SWAP_V2, EthPaymentType::TakerPayments, TAKER_PAYMENT_STATE_INDEX, + BlockNumber::Latest ) .await ); diff --git a/mm2src/coins/eth/eth_swap_v2/mod.rs b/mm2src/coins/eth/eth_swap_v2/mod.rs index 0b903a9b78..2953e34cc2 100644 --- a/mm2src/coins/eth/eth_swap_v2/mod.rs +++ b/mm2src/coins/eth/eth_swap_v2/mod.rs @@ -77,6 +77,7 @@ impl EthCoin { contract_abi: &Contract, payment_type: EthPaymentType, state_index: usize, + block_number: BlockNumber, ) -> Result { let function_name = payment_type.as_str(); let function = contract_abi.function(function_name)?; @@ -87,7 +88,7 @@ impl EthCoin { swap_address, None, Some(data.into()), - BlockNumber::Pending, + block_number, ) .await?; let decoded_tokens = function.decode_output(&bytes.0)?; diff --git a/mm2src/coins/eth/nft_swap_v2/mod.rs b/mm2src/coins/eth/nft_swap_v2/mod.rs index f4c909bd32..1305668f83 100644 --- a/mm2src/coins/eth/nft_swap_v2/mod.rs +++ b/mm2src/coins/eth/nft_swap_v2/mod.rs @@ -6,7 +6,7 @@ use futures::compat::Future01CompatExt; use mm2_err_handle::prelude::{MapToMmResult, MmError, MmResult}; use mm2_number::BigDecimal; use num_traits::Signed; -use web3::types::TransactionId; +use web3::types::{BlockNumber, TransactionId}; use super::ContractType; use crate::coin_errors::{ValidatePaymentError, ValidatePaymentResult}; @@ -88,6 +88,7 @@ impl EthCoin { &NFT_MAKER_SWAP_V2, EthPaymentType::MakerPayments, 2, + BlockNumber::Latest, ) .await?; let tx_from_rpc = self @@ -467,6 +468,7 @@ impl EthCoin { contract_abi, payment_type, state_index, + BlockNumber::Latest, ) .await?; From d3e6ae140c6866ea7bac661806e8cf3b2df28faa Mon Sep 17 00:00:00 2001 From: laruh Date: Tue, 3 Dec 2024 21:34:58 +0700 Subject: [PATCH 33/59] review: remove swap_v == 2u32 restriction --- mm2src/mm2_main/src/lp_ordermatch.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index 0dc7fd16da..5b3a5f826b 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -3031,7 +3031,7 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO let alice_swap_v = maker_match.request.swap_version; // Start legacy swap if taker uses legacy protocol (version 1) or if conditions for trading_proto_v2 aren't met. - if alice_swap_v == 1u32 || !(ctx.use_trading_proto_v2() && alice_swap_v == 2u32) { + if alice_swap_v == 1u32 || !ctx.use_trading_proto_v2() { let params = LegacySwapParams { maker_coin: &maker_coin, taker_coin: &taker_coin, @@ -3263,7 +3263,7 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat let bob_swap_v = taker_match.reserved.swap_version; // Start legacy swap if maker uses legacy protocol (version 1) or if conditions for trading_proto_v2 aren't met. - if bob_swap_v == 1u32 || !(ctx.use_trading_proto_v2() && bob_swap_v == 2u32) { + if bob_swap_v == 1u32 || !ctx.use_trading_proto_v2() { let params = LegacySwapParams { maker_coin: &maker_coin, taker_coin: &taker_coin, From 90b80a3e60732a97a67e97e989593f5056458204 Mon Sep 17 00:00:00 2001 From: laruh Date: Wed, 4 Dec 2024 19:18:48 +0700 Subject: [PATCH 34/59] make trait extract_secret_v2 return [u8; 32] --- mm2src/coins/eth.rs | 2 +- mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs | 4 ++-- mm2src/coins/lp_coins.rs | 2 +- mm2src/coins/test_coin.rs | 2 +- mm2src/coins/utxo/utxo_common.rs | 6 +++--- mm2src/coins/utxo/utxo_standard.rs | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index cb0445ab75..8e2a17e34c 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -7407,7 +7407,7 @@ impl TakerCoinSwapOpsV2 for EthCoin { .await } - async fn extract_secret_v2(&self, _secret_hash: &[u8], spend_tx: &Self::Tx) -> Result, String> { + async fn extract_secret_v2(&self, _secret_hash: &[u8], spend_tx: &Self::Tx) -> Result<[u8; 32], String> { self.extract_secret_v2_impl(spend_tx).await } } diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index 02a3e97486..f68a984ee8 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -792,7 +792,7 @@ impl EthCoin { /// bytes32 makerSecret, /// address tokenAddress /// ) - pub(crate) async fn extract_secret_v2_impl(&self, spend_tx: &SignedEthTx) -> Result, String> { + pub(crate) async fn extract_secret_v2_impl(&self, spend_tx: &SignedEthTx) -> Result<[u8; 32], String> { let function = try_s!(TAKER_SWAP_V2.function("spendTakerPayment")); // should be 0xcc90c199 let expected_signature = function.short_signature(); @@ -809,7 +809,7 @@ impl EthCoin { return ERR!("Invalid arguments in 'spendTakerPayment' call: {:?}", decoded); } match &decoded[5] { - Token::FixedBytes(secret) => Ok(secret.to_vec()), + Token::FixedBytes(secret) => Ok(try_s!(secret.as_slice().try_into())), _ => ERR!( "Expected secret to be fixed bytes, but decoded function data is {:?}", decoded diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 1eb66ce655..df70241329 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1980,7 +1980,7 @@ pub trait TakerCoinSwapOpsV2: ParseCoinAssocTypes + CommonSwapOpsV2 + Send + Syn wait_until: u64, ) -> MmResult; - async fn extract_secret_v2(&self, secret_hash: &[u8], spend_tx: &Self::Tx) -> Result, String>; + async fn extract_secret_v2(&self, secret_hash: &[u8], spend_tx: &Self::Tx) -> Result<[u8; 32], String>; } #[async_trait] diff --git a/mm2src/coins/test_coin.rs b/mm2src/coins/test_coin.rs index fcb4233765..04511216c4 100644 --- a/mm2src/coins/test_coin.rs +++ b/mm2src/coins/test_coin.rs @@ -568,7 +568,7 @@ impl TakerCoinSwapOpsV2 for TestCoin { unimplemented!() } - async fn extract_secret_v2(&self, secret_hash: &[u8], spend_tx: &Self::Tx) -> Result, String> { + async fn extract_secret_v2(&self, secret_hash: &[u8], spend_tx: &Self::Tx) -> Result<[u8; 32], String> { unimplemented!() } } diff --git a/mm2src/coins/utxo/utxo_common.rs b/mm2src/coins/utxo/utxo_common.rs index 1dddbc9fff..d37332af26 100644 --- a/mm2src/coins/utxo/utxo_common.rs +++ b/mm2src/coins/utxo/utxo_common.rs @@ -2584,12 +2584,12 @@ pub async fn get_taker_watcher_reward Result, String> { let spend_tx: UtxoTx = try_s!(deserialize(spend_tx).map_err(|e| ERRL!("{:?}", e))); - extract_secret_v2(secret_hash, &spend_tx) + extract_secret_v2(secret_hash, &spend_tx).map(|secret_array| secret_array.to_vec()) } /// Extract a secret from the `spend_tx`. /// Note spender could generate the spend with several inputs where the only one input is the p2sh script. -pub fn extract_secret_v2(secret_hash: &[u8], spend_tx: &UtxoTx) -> Result, String> { +pub fn extract_secret_v2(secret_hash: &[u8], spend_tx: &UtxoTx) -> Result<[u8; 32], String> { let expected_secret_hash = if secret_hash.len() == 32 { ripemd160(secret_hash) } else { @@ -2602,7 +2602,7 @@ pub fn extract_secret_v2(secret_hash: &[u8], spend_tx: &UtxoTx) -> Result Result, String> { + async fn extract_secret_v2(&self, secret_hash: &[u8], spend_tx: &Self::Tx) -> Result<[u8; 32], String> { utxo_common::extract_secret_v2(secret_hash, spend_tx) } } From 17b1c9405c0927704ae9444fe3982a954bc338f2 Mon Sep 17 00:00:00 2001 From: laruh Date: Wed, 4 Dec 2024 20:29:47 +0700 Subject: [PATCH 35/59] use maker_secret:[u8; 32] in SpendMakerPaymentArgs --- mm2src/coins/lp_coins.rs | 2 +- mm2src/coins/utxo/utxo_common.rs | 2 +- mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 2 +- .../tests/docker_tests/eth_docker_tests.rs | 60 +++++++++---------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index df70241329..5df76914c4 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1708,7 +1708,7 @@ pub struct SpendMakerPaymentArgs<'a, Coin: ParseCoinAssocTypes + ?Sized> { /// The hash of the secret generated by maker, taker needs it to spend the payment pub maker_secret_hash: &'a [u8], /// The secret generated by maker, revealed when maker spends taker's payment - pub maker_secret: &'a [u8], + pub maker_secret: [u8; 32], /// Maker's HTLC pubkey pub maker_pub: &'a Coin::Pubkey, /// Unique data of specific swap diff --git a/mm2src/coins/utxo/utxo_common.rs b/mm2src/coins/utxo/utxo_common.rs index d37332af26..23d3201fa7 100644 --- a/mm2src/coins/utxo/utxo_common.rs +++ b/mm2src/coins/utxo/utxo_common.rs @@ -5015,7 +5015,7 @@ pub async fn spend_maker_payment_v2( let key_pair = coin.derive_htlc_key_pair(args.swap_unique_data); let script_data = Builder::default() - .push_data(args.maker_secret) + .push_data(&args.maker_secret) .push_opcode(Opcode::OP_1) .push_opcode(Opcode::OP_0) .into_script(); diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs index aaa40a72b5..2e802d8167 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs @@ -2104,7 +2104,7 @@ impl Date: Wed, 4 Dec 2024 20:49:36 +0700 Subject: [PATCH 36/59] use taker_secret: [u8; 32] in RefundMakerPaymentSecretArgs --- mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs | 3 +-- mm2src/coins/lp_coins.rs | 2 +- mm2src/coins/utxo/utxo_common.rs | 2 +- mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs | 2 +- mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs | 4 ++-- mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs | 4 ++-- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs index 732dc1a920..db7538ddfc 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs @@ -272,7 +272,6 @@ impl EthCoin { ) .map_err(|e| TransactionErr::Plain(ERRL!("{}", e)))?; - let taker_secret = try_tx_s!(args.taker_secret.try_into()); let maker_secret_hash = try_tx_s!(args.maker_secret_hash.try_into()); let payment_amount = try_tx_s!(wei_from_big_decimal(&args.amount, self.decimals)); let args = { @@ -280,7 +279,7 @@ impl EthCoin { MakerRefundSecretArgs { payment_amount, taker_address, - taker_secret, + taker_secret: args.taker_secret, maker_secret_hash, payment_time_lock: args.time_lock, token_address, diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 5df76914c4..c4030d3cce 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1673,7 +1673,7 @@ pub struct RefundMakerPaymentSecretArgs<'a, Coin: ParseCoinAssocTypes + ?Sized> /// The hash of the secret generated by maker, taker needs it to spend the payment pub maker_secret_hash: &'a [u8], /// Taker's secret - pub taker_secret: &'a [u8], + pub taker_secret: [u8; 32], /// Taker's HTLC pubkey pub taker_pub: &'a Coin::Pubkey, /// Unique data of specific swap diff --git a/mm2src/coins/utxo/utxo_common.rs b/mm2src/coins/utxo/utxo_common.rs index 23d3201fa7..7735905b46 100644 --- a/mm2src/coins/utxo/utxo_common.rs +++ b/mm2src/coins/utxo/utxo_common.rs @@ -5077,7 +5077,7 @@ where let key_pair = coin.derive_htlc_key_pair(args.swap_unique_data); let script_data = Builder::default() - .push_data(args.taker_secret) + .push_data(&args.taker_secret) .push_opcode(Opcode::OP_0) .push_opcode(Opcode::OP_0) .into_script(); diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index a306ab97e9..20096dba52 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -1475,7 +1475,7 @@ impl Date: Wed, 4 Dec 2024 20:56:28 +0700 Subject: [PATCH 37/59] use taker_secret: [u8; 32] in RefundFundingSecretArgs --- mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs | 3 +-- mm2src/coins/lp_coins.rs | 2 +- mm2src/coins/utxo/utxo_common.rs | 2 +- mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 2 +- mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs | 4 ++-- mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index f68a984ee8..4ddd397770 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -351,7 +351,6 @@ impl EthCoin { ) .map_err(|e| TransactionErr::Plain(ERRL!("{}", e)))?; - let taker_secret = try_tx_s!(args.taker_secret.try_into()); let maker_secret_hash = try_tx_s!(args.maker_secret_hash.try_into()); let dex_fee = try_tx_s!(wei_from_big_decimal( &args.dex_fee.fee_amount().to_decimal(), @@ -368,7 +367,7 @@ impl EthCoin { dex_fee, payment_amount, maker_address, - taker_secret, + taker_secret: args.taker_secret, maker_secret_hash, payment_time_lock: args.payment_time_lock, token_address, diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index c4030d3cce..a7a0628e65 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1286,7 +1286,7 @@ pub struct RefundFundingSecretArgs<'a, Coin: ParseCoinAssocTypes + ?Sized> { pub funding_time_lock: u64, pub payment_time_lock: u64, pub maker_pubkey: &'a Coin::Pubkey, - pub taker_secret: &'a [u8], + pub taker_secret: [u8; 32], pub taker_secret_hash: &'a [u8], pub maker_secret_hash: &'a [u8], pub dex_fee: &'a DexFee, diff --git a/mm2src/coins/utxo/utxo_common.rs b/mm2src/coins/utxo/utxo_common.rs index 7735905b46..a8b36dc281 100644 --- a/mm2src/coins/utxo/utxo_common.rs +++ b/mm2src/coins/utxo/utxo_common.rs @@ -4829,7 +4829,7 @@ where let key_pair = coin.derive_htlc_key_pair(args.swap_unique_data); let script_data = Builder::default() - .push_data(args.taker_secret) + .push_data(&args.taker_secret) .push_opcode(Opcode::OP_0) .push_opcode(Opcode::OP_0) .into_script(); diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs index 2e802d8167..354f90c04e 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs @@ -1810,7 +1810,7 @@ impl Date: Tue, 10 Dec 2024 13:54:08 +0700 Subject: [PATCH 38/59] review: use secret_hash_algo_v2 function for both maker and taker --- mm2src/coins/lp_coins.rs | 9 +-------- mm2src/crypto/src/secret_hash_algo.rs | 2 +- mm2src/mm2_main/src/lp_swap.rs | 10 ++++------ 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 9ba04ae541..3f94f91e00 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -3576,14 +3576,7 @@ impl MmCoinEnum { fn is_platform_coin(&self) -> bool { self.ticker() == self.platform_ticker() } - pub fn maker_secret_hash_algo_v2(&self) -> SecretHashAlgo { - match self { - MmCoinEnum::EthCoin(_) => SecretHashAlgo::SHA256, - _ => SecretHashAlgo::DHASH160, - } - } - - pub fn taker_secret_hash_algo_v2(&self) -> SecretHashAlgo { + pub fn secret_hash_algo_v2(&self) -> SecretHashAlgo { match self { MmCoinEnum::EthCoin(_) => SecretHashAlgo::SHA256, _ => SecretHashAlgo::DHASH160, diff --git a/mm2src/crypto/src/secret_hash_algo.rs b/mm2src/crypto/src/secret_hash_algo.rs index 15d7a08f75..c5add0492f 100644 --- a/mm2src/crypto/src/secret_hash_algo.rs +++ b/mm2src/crypto/src/secret_hash_algo.rs @@ -3,7 +3,7 @@ use derive_more::Display; use std::convert::TryFrom; /// Algorithm used to hash swap secret. -#[derive(Clone, Copy, Debug, Deserialize, Serialize, Default)] +#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize)] pub enum SecretHashAlgo { /// ripemd160(sha256(secret)) #[default] diff --git a/mm2src/mm2_main/src/lp_swap.rs b/mm2src/mm2_main/src/lp_swap.rs index 3ae9aa57a5..58fcbe58ea 100644 --- a/mm2src/mm2_main/src/lp_swap.rs +++ b/mm2src/mm2_main/src/lp_swap.rs @@ -1648,13 +1648,11 @@ pub fn detect_secret_hash_algo(maker_coin: &MmCoinEnum, taker_coin: &MmCoinEnum) } } +/// Determines the secret hash algorithm for TPU, prioritizing SHA256 if either coin supports it. pub fn detect_secret_hash_algo_v2(maker_coin: &MmCoinEnum, taker_coin: &MmCoinEnum) -> SecretHashAlgo { - let maker_algo = maker_coin.maker_secret_hash_algo_v2(); - let taker_algo = taker_coin.taker_secret_hash_algo_v2(); - if matches!( - (maker_algo, taker_algo), - (SecretHashAlgo::SHA256, _) | (_, SecretHashAlgo::SHA256) - ) { + let maker_algo = maker_coin.secret_hash_algo_v2(); + let taker_algo = taker_coin.secret_hash_algo_v2(); + if maker_algo == SecretHashAlgo::SHA256 || taker_algo == SecretHashAlgo::SHA256 { SecretHashAlgo::SHA256 } else { SecretHashAlgo::DHASH160 From e3b413225bfd87566987355992c4aa4f9eaeb4fc Mon Sep 17 00:00:00 2001 From: laruh Date: Tue, 10 Dec 2024 19:06:52 +0700 Subject: [PATCH 39/59] reuse extract_id_from_tx_data in find_taker_payment_spend_tx_impl and in wait_for_htlc_tx_spend --- mm2src/coins/eth.rs | 14 ++------------ .../eth/eth_swap_v2/eth_taker_swap_v2.rs | 17 ++++------------- mm2src/coins/eth/eth_swap_v2/mod.rs | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index f3d9761827..6313a50146 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -162,7 +162,7 @@ pub mod erc20; use erc20::get_token_decimals; pub(crate) mod eth_swap_v2; -use eth_swap_v2::{EthPaymentType, PaymentMethod}; +use eth_swap_v2::{extract_id_from_tx_data, EthPaymentType, PaymentMethod}; /// https://github.com/artemii235/etomic-swap/blob/master/contracts/EtomicSwap.sol /// Dev chain (195.201.137.5:8565) contract address: 0x83965C539899cC0F918552e5A26915de40ee8852 @@ -2587,17 +2587,7 @@ impl MarketCoinOps for EthCoin { }, }; - let payment_func = try_tx_s!(SWAP_CONTRACT.function(&func_name)); - let decoded = try_tx_s!(decode_contract_call(payment_func, tx.unsigned().data())); - let id = match decoded.first() { - Some(Token::FixedBytes(bytes)) => bytes.clone(), - invalid_token => { - return Err(TransactionErr::Plain(ERRL!( - "Expected Token::FixedBytes, got {:?}", - invalid_token - ))) - }, - }; + let id = try_tx_s!(extract_id_from_tx_data(tx.unsigned().data(), &SWAP_CONTRACT, &func_name).await); let mut tx_hash: Option = None; loop { diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index 4ddd397770..75a2f34acc 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -1,5 +1,5 @@ -use super::{check_decoded_length, validate_amount, validate_from_to_and_status, validate_payment_state, - EthPaymentType, PaymentMethod, PrepareTxDataError, ZERO_VALUE}; +use super::{check_decoded_length, extract_id_from_tx_data, validate_amount, validate_from_to_and_status, + validate_payment_state, EthPaymentType, PaymentMethod, PrepareTxDataError, ZERO_VALUE}; use crate::eth::{decode_contract_call, get_function_input_data, signed_tx_from_web3_tx, wei_from_big_decimal, EthCoin, EthCoinType, ParseCoinAssocTypes, RefundFundingSecretArgs, RefundTakerPaymentArgs, SendTakerFundingArgs, SignedEthTx, SwapTxTypeWithSecretHash, TakerPaymentStateV2, TransactionErr, @@ -474,17 +474,8 @@ impl EthCoin { FindPaymentSpendError::Internal("Expected swap_v2_contracts to be Some, but found None".to_string()) })? .taker_swap_v2_contract; - let approve_func = TAKER_SWAP_V2.function(TAKER_PAYMENT_APPROVE)?; - let decoded = decode_contract_call(approve_func, taker_payment.unsigned().data())?; - let id = match decoded.first() { - Some(Token::FixedBytes(bytes)) => bytes, - invalid_token => { - return MmError::err(FindPaymentSpendError::InvalidData(format!( - "Expected Token::FixedBytes, got {:?}", - invalid_token - ))) - }, - }; + let id = + extract_id_from_tx_data(taker_payment.unsigned().data(), &TAKER_SWAP_V2, TAKER_PAYMENT_APPROVE).await?; let mut tx_hash: Option = None; // loop to find maker's spendTakerPayment transaction loop { diff --git a/mm2src/coins/eth/eth_swap_v2/mod.rs b/mm2src/coins/eth/eth_swap_v2/mod.rs index 2953e34cc2..07bf531329 100644 --- a/mm2src/coins/eth/eth_swap_v2/mod.rs +++ b/mm2src/coins/eth/eth_swap_v2/mod.rs @@ -1,4 +1,5 @@ -use crate::eth::{EthCoin, EthCoinType, ParseCoinAssocTypes, Transaction, TransactionErr}; +use crate::eth::{decode_contract_call, EthCoin, EthCoinType, ParseCoinAssocTypes, Transaction, TransactionErr}; +use crate::FindPaymentSpendError; use enum_derives::EnumFromStringify; use ethabi::{Contract, Token}; use ethcore_transaction::SignedTransaction as SignedEthTx; @@ -208,3 +209,19 @@ impl EthCoin { Ok(()) } } + +pub async fn extract_id_from_tx_data( + tx_data: &[u8], + abi_contract: &Contract, + func_name: &str, +) -> Result, FindPaymentSpendError> { + let func = abi_contract.function(func_name)?; + let decoded = decode_contract_call(func, tx_data)?; + match decoded.first() { + Some(Token::FixedBytes(bytes)) => Ok(bytes.clone()), + invalid_token => Err(FindPaymentSpendError::InvalidData(format!( + "Expected Token::FixedBytes, got {:?}", + invalid_token + ))), + } +} From 9007f123183ef60ef71ddc6789cb42ae49f04caa Mon Sep 17 00:00:00 2001 From: laruh Date: Tue, 10 Dec 2024 20:42:30 +0700 Subject: [PATCH 40/59] reduce code duplication providing find_spend_transaction_hash and wait_for_spend_transaction --- mm2src/coins/eth.rs | 94 +++----------- .../eth/eth_swap_v2/eth_taker_swap_v2.rs | 105 +++------------ mm2src/coins/eth/eth_swap_v2/mod.rs | 122 +++++++++++++++++- 3 files changed, 156 insertions(+), 165 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 6313a50146..7a5bd74c07 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -162,7 +162,7 @@ pub mod erc20; use erc20::get_token_decimals; pub(crate) mod eth_swap_v2; -use eth_swap_v2::{extract_id_from_tx_data, EthPaymentType, PaymentMethod}; +use eth_swap_v2::{extract_id_from_tx_data, EthPaymentType, PaymentMethod, SpendTxSearchParams}; /// https://github.com/artemii235/etomic-swap/blob/master/contracts/EtomicSwap.sol /// Dev chain (195.201.137.5:8565) contract address: 0x83965C539899cC0F918552e5A26915de40ee8852 @@ -2589,81 +2589,25 @@ impl MarketCoinOps for EthCoin { let id = try_tx_s!(extract_id_from_tx_data(tx.unsigned().data(), &SWAP_CONTRACT, &func_name).await); - let mut tx_hash: Option = None; - loop { - if now_sec() > args.wait_until { - return TX_PLAIN_ERR!( - "Waited too long until {} for transaction {:?} to be spent ", - args.wait_until, - tx, - ); - } - - let current_block = match self.current_block().compat().await { - Ok(b) => b, - Err(e) => { - error!("Error getting block number: {}", e); - Timer::sleep(5.).await; - continue; - }, - }; - - if tx_hash.is_none() { - let mut next_from_block = args.from_block; - - // Split the range into windows of size logs_block_range - while next_from_block <= current_block { - let to_block = std::cmp::min(next_from_block + self.logs_block_range - 1, current_block); - - let events = match self - .events_from_block( - swap_contract_address, - "ReceiverSpent", - next_from_block, - Some(to_block), - &SWAP_CONTRACT, - ) - .await - { - Ok(ev) => ev, - Err(e) => { - error!( - "Error getting spend events from {} to {} block: {}", - next_from_block, to_block, e - ); - Timer::sleep(5.).await; - next_from_block += self.logs_block_range; - continue; - }, - }; - - // Check if any event matches the SWAP ID - if let Some(found_event) = events.iter().find(|event| &event.data.0[..32] == id.as_slice()) { - if let Some(hash) = found_event.transaction_hash { - // Store tx_hash to skip fetching events in the next iteration if "eth_getTransactionByHash" is unsuccessful - tx_hash = Some(hash); - break; - } - } - - // Move to the next block range window - next_from_block += self.logs_block_range; - } - } + let find_params = SpendTxSearchParams { + swap_contract_address, + event_name: "ReceiverSpent", + abi_contract: &SWAP_CONTRACT, + swap_id: &id, + from_block: args.from_block, + wait_until: args.wait_until, + check_every: args.check_every, + }; + let tx_hash = self + .find_transaction_hash_by_event(find_params) + .await + .map_err(|e| TransactionErr::Plain(e.get_inner().to_string()))?; - // Proceed getting spend transaction if we have a tx_hash - if let Some(tx_hash) = tx_hash { - match self.transaction(TransactionId::Hash(tx_hash)).await { - Ok(Some(t)) => { - return Ok(TransactionEnum::from(try_tx_s!(signed_tx_from_web3_tx(t)))); - }, - Ok(None) => info!("Tx {} not found yet", tx_hash), - Err(e) => error!("Get tx {} error: {}", tx_hash, e), - }; - Timer::sleep(args.check_every).await; - continue; - } - } + let spend_tx = self + .wait_for_spend_transaction(tx_hash, args.wait_until, args.check_every) + .await + .map_err(|e| TransactionErr::Plain(e.get_inner().to_string()))?; + Ok(TransactionEnum::from(spend_tx)) } fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result> { diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index 75a2f34acc..437d8eca2e 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -1,14 +1,11 @@ use super::{check_decoded_length, extract_id_from_tx_data, validate_amount, validate_from_to_and_status, - validate_payment_state, EthPaymentType, PaymentMethod, PrepareTxDataError, ZERO_VALUE}; -use crate::eth::{decode_contract_call, get_function_input_data, signed_tx_from_web3_tx, wei_from_big_decimal, EthCoin, - EthCoinType, ParseCoinAssocTypes, RefundFundingSecretArgs, RefundTakerPaymentArgs, - SendTakerFundingArgs, SignedEthTx, SwapTxTypeWithSecretHash, TakerPaymentStateV2, TransactionErr, - ValidateSwapV2TxError, ValidateSwapV2TxResult, ValidateTakerFundingArgs, TAKER_SWAP_V2}; -use crate::{FindPaymentSpendError, FundingTxSpend, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, MarketCoinOps, + validate_payment_state, EthPaymentType, PaymentMethod, PrepareTxDataError, SpendTxSearchParams, ZERO_VALUE}; +use crate::eth::{decode_contract_call, get_function_input_data, wei_from_big_decimal, EthCoin, EthCoinType, + ParseCoinAssocTypes, RefundFundingSecretArgs, RefundTakerPaymentArgs, SendTakerFundingArgs, + SignedEthTx, SwapTxTypeWithSecretHash, TakerPaymentStateV2, TransactionErr, ValidateSwapV2TxError, + ValidateSwapV2TxResult, ValidateTakerFundingArgs, TAKER_SWAP_V2}; +use crate::{FindPaymentSpendError, FundingTxSpend, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, SearchForFundingSpendErr}; -use common::executor::Timer; -use common::log::{error, info}; -use common::now_sec; use ethabi::{Function, Token}; use ethcore_transaction::Action; use ethereum_types::{Address, Public, U256}; @@ -16,7 +13,7 @@ use ethkey::public_to_address; use futures::compat::Future01CompatExt; use mm2_err_handle::prelude::{MapToMmResult, MmError, MmResult}; use std::convert::TryInto; -use web3::types::{BlockNumber, TransactionId, H256}; +use web3::types::{BlockNumber, TransactionId}; const ETH_TAKER_PAYMENT: &str = "ethTakerPayment"; const ERC20_TAKER_PAYMENT: &str = "erc20TakerPayment"; @@ -476,82 +473,22 @@ impl EthCoin { .taker_swap_v2_contract; let id = extract_id_from_tx_data(taker_payment.unsigned().data(), &TAKER_SWAP_V2, TAKER_PAYMENT_APPROVE).await?; - let mut tx_hash: Option = None; - // loop to find maker's spendTakerPayment transaction - loop { - let now = now_sec(); - if now > wait_until { - return MmError::err(FindPaymentSpendError::Timeout { wait_until, now }); - } - let current_block = match self.current_block().compat().await { - Ok(b) => b, - Err(e) => { - error!("Error getting block number: {}", e); - Timer::sleep(check_every).await; - continue; - }, - }; - - // Skip retrieving events if tx_hash is already found - if tx_hash.is_none() { - let mut next_from_block = from_block; - - while next_from_block <= current_block { - let to_block = std::cmp::min(next_from_block + self.logs_block_range - 1, current_block); - - // Fetch TakerPaymentSpent events for the current block range - let events = match self - .events_from_block( - taker_swap_v2_contract, - "TakerPaymentSpent", - next_from_block, - Some(to_block), - &TAKER_SWAP_V2, - ) - .await - { - Ok(events) => events, - Err(e) => { - error!( - "Error getting TakerPaymentSpent events from {} to {} block: {}", - next_from_block, to_block, e - ); - Timer::sleep(check_every).await; - // Move to next window if there was an error - next_from_block += self.logs_block_range; - continue; - }, - }; - - // This is how spent event looks like in EtomicSwapTakerV2: event TakerPaymentSpent(bytes32 id, bytes32 secret). - // Check if any event matches the ID. - if let Some(found_event) = events.into_iter().find(|event| &event.data.0[..32] == id.as_slice()) { - if let Some(hash) = found_event.transaction_hash { - // Store tx_hash to skip fetching events in the next iteration if "eth_getTransactionByHash" is unsuccessful - tx_hash = Some(hash); - break; - } - } - - next_from_block += self.logs_block_range; - } - } + let params = SpendTxSearchParams { + swap_contract_address: taker_swap_v2_contract, + event_name: "TakerPaymentSpent", + abi_contract: &TAKER_SWAP_V2, + swap_id: &id, + from_block, + wait_until, + check_every, + }; + let tx_hash = self.find_transaction_hash_by_event(params).await?; - // Proceed to check transaction if we have a tx_hash - if let Some(tx_hash) = tx_hash { - match self.transaction(TransactionId::Hash(tx_hash)).await { - Ok(Some(t)) => { - let transaction = signed_tx_from_web3_tx(t).map_err(FindPaymentSpendError::Internal)?; - return Ok(transaction); - }, - Ok(None) => info!("spendTakerPayment transaction {} not found yet", tx_hash), - Err(e) => error!("Get spendTakerPayment transaction {} error: {}", tx_hash, e), - }; - Timer::sleep(check_every).await; - continue; - } - } + let spend_tx = self + .wait_for_spend_transaction(tx_hash, wait_until, check_every) + .await?; + Ok(spend_tx) } /// Prepares data for EtomicSwapTakerV2 contract [ethTakerPayment](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapTakerV2.sol#L44) method diff --git a/mm2src/coins/eth/eth_swap_v2/mod.rs b/mm2src/coins/eth/eth_swap_v2/mod.rs index 07bf531329..0eed1f4812 100644 --- a/mm2src/coins/eth/eth_swap_v2/mod.rs +++ b/mm2src/coins/eth/eth_swap_v2/mod.rs @@ -1,14 +1,18 @@ -use crate::eth::{decode_contract_call, EthCoin, EthCoinType, ParseCoinAssocTypes, Transaction, TransactionErr}; -use crate::FindPaymentSpendError; +use crate::eth::{decode_contract_call, signed_tx_from_web3_tx, EthCoin, EthCoinType, ParseCoinAssocTypes, Transaction, + TransactionErr}; +use crate::{FindPaymentSpendError, MarketCoinOps}; +use common::executor::Timer; +use common::log::{error, info}; +use common::now_sec; use enum_derives::EnumFromStringify; use ethabi::{Contract, Token}; use ethcore_transaction::SignedTransaction as SignedEthTx; -use ethereum_types::{Address, U256}; +use ethereum_types::{Address, H256, U256}; use futures::compat::Future01CompatExt; -use mm2_err_handle::mm_error::MmError; +use mm2_err_handle::prelude::{MmError, MmResult}; use mm2_number::BigDecimal; use num_traits::Signed; -use web3::types::{BlockNumber, Transaction as Web3Tx}; +use web3::types::{BlockNumber, Transaction as Web3Tx, TransactionId}; pub(crate) mod eth_maker_swap_v2; pub(crate) mod eth_taker_swap_v2; @@ -116,6 +120,112 @@ impl EthCoin { EthCoinType::Nft { .. } => Err("NFT protocol is not supported for ETH and ERC20 Swaps".to_string()), } } + + /// A helper function that scans blocks for a specific event containing the given `swap_id`, + /// returning transaction hash of spend transaction once found. + /// **NOTE:** The current function implementation assumes that `swap_id` is the first 32 bytes of the transaction input data. + pub(crate) async fn find_transaction_hash_by_event( + &self, + params: SpendTxSearchParams<'_>, + ) -> MmResult { + loop { + let now = now_sec(); + if now > params.wait_until { + return MmError::err(FindPaymentSpendError::Timeout { + wait_until: params.wait_until, + now, + }); + } + + let current_block = match self.current_block().compat().await { + Ok(b) => b, + Err(e) => { + error!("Error getting block number: {}", e); + Timer::sleep(params.check_every).await; + continue; + }, + }; + + let mut next_from_block = params.from_block; + while next_from_block <= current_block { + let to_block = std::cmp::min(next_from_block + self.logs_block_range - 1, current_block); + + // Fetch events for the current block range + let events = match self + .events_from_block( + params.swap_contract_address, + params.event_name, + next_from_block, + Some(to_block), + params.abi_contract, + ) + .await + { + Ok(events) => events, + Err(e) => { + error!( + "Error getting {} events from {} to {} block: {}", + params.event_name, next_from_block, to_block, e + ); + Timer::sleep(params.check_every).await; + // Move to next window if there was an error + next_from_block += self.logs_block_range; + continue; + }, + }; + + // Check if any event matches the SWAP ID + if let Some(found_event) = events + .into_iter() + .find(|event| event.data.0.len() >= 32 && &event.data.0[..32] == params.swap_id) + { + if let Some(hash) = found_event.transaction_hash { + return Ok(hash); + } + } + + next_from_block += self.logs_block_range; + } + + Timer::sleep(params.check_every).await; + } + } + + /// Waits until the specified transaction is found by its hash or the given timeout is reached + pub(crate) async fn wait_for_spend_transaction( + &self, + tx_hash: H256, + wait_until: u64, + check_every: f64, + ) -> MmResult { + loop { + let now = now_sec(); + if now > wait_until { + return MmError::err(FindPaymentSpendError::Timeout { wait_until, now }); + } + + match self.transaction(TransactionId::Hash(tx_hash)).await { + Ok(Some(t)) => { + let transaction = signed_tx_from_web3_tx(t).map_err(FindPaymentSpendError::Internal)?; + return Ok(transaction); + }, + Ok(None) => info!("Transaction {} not found yet", tx_hash), + Err(e) => error!("Get transaction {} error: {}", tx_hash, e), + }; + + Timer::sleep(check_every).await; + } + } +} + +pub(crate) struct SpendTxSearchParams<'a> { + pub(crate) swap_contract_address: Address, + pub(crate) event_name: &'a str, + pub(crate) abi_contract: &'a Contract, + pub(crate) swap_id: &'a [u8], + pub(crate) from_block: u64, + pub(crate) wait_until: u64, + pub(crate) check_every: f64, } pub(crate) fn validate_payment_state( @@ -210,7 +320,7 @@ impl EthCoin { } } -pub async fn extract_id_from_tx_data( +pub(crate) async fn extract_id_from_tx_data( tx_data: &[u8], abi_contract: &Contract, func_name: &str, From 5bd4ee2a4fa2b6fa51a0690d50d0310c1d1ea213 Mon Sep 17 00:00:00 2001 From: laruh Date: Wed, 11 Dec 2024 20:45:07 +0700 Subject: [PATCH 41/59] review: fix taker payment log message --- mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs index 354f90c04e..3f3d0b906a 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs @@ -1585,7 +1585,7 @@ impl Date: Wed, 11 Dec 2024 20:48:28 +0700 Subject: [PATCH 42/59] review: fix functions names --- mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs | 4 ++-- mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index 20096dba52..ba0460644a 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -404,7 +404,7 @@ impl u64 { self.started_at + 2 * self.lock_duration } #[inline] - fn spend_taker_payment_conf_timeout(&self) -> u64 { self.started_at + 3 * self.lock_duration } + fn taker_payment_spend_conf_timeout(&self) -> u64 { self.started_at + 3 * self.lock_duration } /// Returns secret hash generated using selected [SecretHashAlgo]. fn secret_hash(&self) -> Vec { @@ -1780,7 +1780,7 @@ impl u64 { self.started_at + self.lock_duration } #[inline] - fn spend_maker_payment_conf_timeout(&self) -> u64 { self.started_at + 4 * self.lock_duration } + fn maker_payment_spend_conf_timeout(&self) -> u64 { self.started_at + 4 * self.lock_duration } fn unique_data(&self) -> Vec { self.uuid.as_bytes().to_vec() } @@ -2218,7 +2218,7 @@ impl Date: Thu, 12 Dec 2024 16:31:15 +0700 Subject: [PATCH 43/59] review: doc comms for require_maker_payment_spend_confirm and require_taker_payment_spend_confirm --- mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs | 1 + mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index ba0460644a..924ed4a4be 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -389,6 +389,7 @@ pub struct MakerSwapStateMachine Date: Thu, 12 Dec 2024 17:08:57 +0700 Subject: [PATCH 44/59] review: use references --- .../eth/eth_swap_v2/eth_maker_swap_v2.rs | 36 +++++++++---------- .../eth/eth_swap_v2/eth_taker_swap_v2.rs | 34 +++++++++--------- mm2src/coins/lp_coins.rs | 4 +-- mm2src/coins/utxo/utxo_common.rs | 4 +-- mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs | 2 +- mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 2 +- .../tests/docker_tests/eth_docker_tests.rs | 14 ++++---- 7 files changed, 48 insertions(+), 48 deletions(-) diff --git a/mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs index db7538ddfc..c5e97359e7 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs @@ -27,10 +27,10 @@ const ERC20_MAKER_PAYMENT: &str = "erc20MakerPayment"; /// } const MAKER_PAYMENT_STATE_INDEX: usize = 2; -struct MakerPaymentArgs { +struct MakerPaymentArgs<'a> { taker_address: Address, - taker_secret_hash: [u8; 32], - maker_secret_hash: [u8; 32], + taker_secret_hash: &'a [u8; 32], + maker_secret_hash: &'a [u8; 32], payment_time_lock: u64, } @@ -43,20 +43,20 @@ struct MakerValidationArgs<'a> { payment_time_lock: u64, } -struct MakerRefundTimelockArgs { +struct MakerRefundTimelockArgs<'a> { payment_amount: U256, taker_address: Address, - taker_secret_hash: [u8; 32], - maker_secret_hash: [u8; 32], + taker_secret_hash: &'a [u8; 32], + maker_secret_hash: &'a [u8; 32], payment_time_lock: u64, token_address: Address, } -struct MakerRefundSecretArgs { +struct MakerRefundSecretArgs<'a> { payment_amount: U256, taker_address: Address, - taker_secret: [u8; 32], - maker_secret_hash: [u8; 32], + taker_secret: &'a [u8; 32], + maker_secret_hash: &'a [u8; 32], payment_time_lock: u64, token_address: Address, } @@ -326,9 +326,9 @@ impl EthCoin { } /// Prepares data for EtomicSwapMakerV2 contract [ethMakerPayment](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapMakerV2.sol#L30) method - async fn prepare_maker_eth_payment_data(&self, args: &MakerPaymentArgs) -> Result, PrepareTxDataError> { + async fn prepare_maker_eth_payment_data(&self, args: &MakerPaymentArgs<'_>) -> Result, PrepareTxDataError> { let function = MAKER_SWAP_V2.function(ETH_MAKER_PAYMENT)?; - let id = self.etomic_swap_id_v2(args.payment_time_lock, &args.maker_secret_hash); + let id = self.etomic_swap_id_v2(args.payment_time_lock, args.maker_secret_hash); let data = function.encode_input(&[ Token::FixedBytes(id), Token::Address(args.taker_address), @@ -342,12 +342,12 @@ impl EthCoin { /// Prepares data for EtomicSwapMakerV2 contract [erc20MakerPayment](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapMakerV2.sol#L64) method async fn prepare_maker_erc20_payment_data( &self, - args: &MakerPaymentArgs, + args: &MakerPaymentArgs<'_>, payment_amount: U256, token_address: Address, ) -> Result, PrepareTxDataError> { let function = MAKER_SWAP_V2.function(ERC20_MAKER_PAYMENT)?; - let id = self.etomic_swap_id_v2(args.payment_time_lock, &args.maker_secret_hash); + let id = self.etomic_swap_id_v2(args.payment_time_lock, args.maker_secret_hash); let data = function.encode_input(&[ Token::FixedBytes(id), Token::Uint(payment_amount), @@ -363,10 +363,10 @@ impl EthCoin { /// Prepares data for EtomicSwapMakerV2 contract [refundMakerPaymentTimelock](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapMakerV2.sol#L144) method async fn prepare_refund_maker_payment_timelock_data( &self, - args: MakerRefundTimelockArgs, + args: MakerRefundTimelockArgs<'_>, ) -> Result, PrepareTxDataError> { let function = MAKER_SWAP_V2.function("refundMakerPaymentTimelock")?; - let id = self.etomic_swap_id_v2(args.payment_time_lock, &args.maker_secret_hash); + let id = self.etomic_swap_id_v2(args.payment_time_lock, args.maker_secret_hash); let data = function.encode_input(&[ Token::FixedBytes(id), Token::Uint(args.payment_amount), @@ -381,10 +381,10 @@ impl EthCoin { /// Prepares data for EtomicSwapMakerV2 contract [refundMakerPaymentSecret](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapMakerV2.sol#L190) method async fn prepare_refund_maker_payment_secret_data( &self, - args: MakerRefundSecretArgs, + args: MakerRefundSecretArgs<'_>, ) -> Result, PrepareTxDataError> { let function = MAKER_SWAP_V2.function("refundMakerPaymentSecret")?; - let id = self.etomic_swap_id_v2(args.payment_time_lock, &args.maker_secret_hash); + let id = self.etomic_swap_id_v2(args.payment_time_lock, args.maker_secret_hash); let data = function.encode_input(&[ Token::FixedBytes(id), Token::Uint(args.payment_amount), @@ -422,7 +422,7 @@ impl EthCoin { /// Validation function for ETH maker payment data fn validate_eth_maker_payment_data( decoded: &[Token], - args: &MakerValidationArgs, + args: &MakerValidationArgs<'_>, func: &Function, tx_value: U256, ) -> Result<(), MmError> { diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index 437d8eca2e..e8746f8e3d 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -29,32 +29,32 @@ const TAKER_PAYMENT_APPROVE: &str = "takerPaymentApprove"; /// } const TAKER_PAYMENT_STATE_INDEX: usize = 3; -struct TakerFundingArgs { +struct TakerFundingArgs<'a> { dex_fee: U256, payment_amount: U256, maker_address: Address, - taker_secret_hash: [u8; 32], - maker_secret_hash: [u8; 32], + taker_secret_hash: &'a [u8; 32], + maker_secret_hash: &'a [u8; 32], funding_time_lock: u64, payment_time_lock: u64, } -struct TakerRefundTimelockArgs { +struct TakerRefundTimelockArgs<'a> { dex_fee: U256, payment_amount: U256, maker_address: Address, - taker_secret_hash: [u8; 32], - maker_secret_hash: [u8; 32], + taker_secret_hash: &'a [u8; 32], + maker_secret_hash: &'a [u8; 32], payment_time_lock: u64, token_address: Address, } -struct TakerRefundSecretArgs { +struct TakerRefundSecretArgs<'a> { dex_fee: U256, payment_amount: U256, maker_address: Address, - taker_secret: [u8; 32], - maker_secret_hash: [u8; 32], + taker_secret: &'a [u8; 32], + maker_secret_hash: &'a [u8; 32], payment_time_lock: u64, token_address: Address, } @@ -492,9 +492,9 @@ impl EthCoin { } /// Prepares data for EtomicSwapTakerV2 contract [ethTakerPayment](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapTakerV2.sol#L44) method - async fn prepare_taker_eth_funding_data(&self, args: &TakerFundingArgs) -> Result, PrepareTxDataError> { + async fn prepare_taker_eth_funding_data(&self, args: &TakerFundingArgs<'_>) -> Result, PrepareTxDataError> { let function = TAKER_SWAP_V2.function(ETH_TAKER_PAYMENT)?; - let id = self.etomic_swap_id_v2(args.payment_time_lock, &args.maker_secret_hash); + let id = self.etomic_swap_id_v2(args.payment_time_lock, args.maker_secret_hash); let data = function.encode_input(&[ Token::FixedBytes(id), Token::Uint(args.dex_fee), @@ -510,11 +510,11 @@ impl EthCoin { /// Prepares data for EtomicSwapTakerV2 contract [erc20TakerPayment](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapTakerV2.sol#L83) method async fn prepare_taker_erc20_funding_data( &self, - args: &TakerFundingArgs, + args: &TakerFundingArgs<'_>, token_address: Address, ) -> Result, PrepareTxDataError> { let function = TAKER_SWAP_V2.function(ERC20_TAKER_PAYMENT)?; - let id = self.etomic_swap_id_v2(args.payment_time_lock, &args.maker_secret_hash); + let id = self.etomic_swap_id_v2(args.payment_time_lock, args.maker_secret_hash); let data = function.encode_input(&[ Token::FixedBytes(id), Token::Uint(args.payment_amount), @@ -532,10 +532,10 @@ impl EthCoin { /// Prepares data for EtomicSwapTakerV2 contract [refundTakerPaymentTimelock](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapTakerV2.sol#L208) method async fn prepare_taker_refund_payment_timelock_data( &self, - args: TakerRefundTimelockArgs, + args: TakerRefundTimelockArgs<'_>, ) -> Result, PrepareTxDataError> { let function = TAKER_SWAP_V2.function("refundTakerPaymentTimelock")?; - let id = self.etomic_swap_id_v2(args.payment_time_lock, &args.maker_secret_hash); + let id = self.etomic_swap_id_v2(args.payment_time_lock, args.maker_secret_hash); let data = function.encode_input(&[ Token::FixedBytes(id), Token::Uint(args.payment_amount), @@ -551,10 +551,10 @@ impl EthCoin { /// Prepares data for EtomicSwapTakerV2 contract [refundTakerPaymentSecret](https://github.com/KomodoPlatform/etomic-swap/blob/5e15641cbf41766cd5b37b4d71842c270773f788/contracts/EtomicSwapTakerV2.sol#L267) method async fn prepare_taker_refund_payment_secret_data( &self, - args: &TakerRefundSecretArgs, + args: &TakerRefundSecretArgs<'_>, ) -> Result, PrepareTxDataError> { let function = TAKER_SWAP_V2.function("refundTakerPaymentSecret")?; - let id = self.etomic_swap_id_v2(args.payment_time_lock, &args.maker_secret_hash); + let id = self.etomic_swap_id_v2(args.payment_time_lock, args.maker_secret_hash); let data = function.encode_input(&[ Token::FixedBytes(id), Token::Uint(args.payment_amount), diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 3f94f91e00..d0a1ae34c0 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1289,7 +1289,7 @@ pub struct RefundFundingSecretArgs<'a, Coin: ParseCoinAssocTypes + ?Sized> { pub funding_time_lock: u64, pub payment_time_lock: u64, pub maker_pubkey: &'a Coin::Pubkey, - pub taker_secret: [u8; 32], + pub taker_secret: &'a [u8; 32], pub taker_secret_hash: &'a [u8], pub maker_secret_hash: &'a [u8], pub dex_fee: &'a DexFee, @@ -1676,7 +1676,7 @@ pub struct RefundMakerPaymentSecretArgs<'a, Coin: ParseCoinAssocTypes + ?Sized> /// The hash of the secret generated by maker, taker needs it to spend the payment pub maker_secret_hash: &'a [u8], /// Taker's secret - pub taker_secret: [u8; 32], + pub taker_secret: &'a [u8; 32], /// Taker's HTLC pubkey pub taker_pub: &'a Coin::Pubkey, /// Unique data of specific swap diff --git a/mm2src/coins/utxo/utxo_common.rs b/mm2src/coins/utxo/utxo_common.rs index a8b36dc281..23d3201fa7 100644 --- a/mm2src/coins/utxo/utxo_common.rs +++ b/mm2src/coins/utxo/utxo_common.rs @@ -4829,7 +4829,7 @@ where let key_pair = coin.derive_htlc_key_pair(args.swap_unique_data); let script_data = Builder::default() - .push_data(&args.taker_secret) + .push_data(args.taker_secret) .push_opcode(Opcode::OP_0) .push_opcode(Opcode::OP_0) .into_script(); @@ -5077,7 +5077,7 @@ where let key_pair = coin.derive_htlc_key_pair(args.swap_unique_data); let script_data = Builder::default() - .push_data(&args.taker_secret) + .push_data(args.taker_secret) .push_opcode(Opcode::OP_0) .push_opcode(Opcode::OP_0) .into_script(); diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index 924ed4a4be..18df8d1c14 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -1476,7 +1476,7 @@ impl Date: Thu, 12 Dec 2024 17:55:10 +0700 Subject: [PATCH 45/59] review: move StateMachineParams closer to LegacySwapParams. place them above fn lp_connect --- mm2src/mm2_main/src/lp_ordermatch.rs | 39 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index 5b3a5f826b..98ad339451 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -2946,6 +2946,25 @@ impl MakerOrdersContext { fn balance_loop_exists(&mut self, ticker: &str) -> bool { self.balance_loops.lock().contains(ticker).unwrap() } } +struct LegacySwapParams<'a> { + maker_coin: &'a MmCoinEnum, + taker_coin: &'a MmCoinEnum, + uuid: &'a Uuid, + my_conf_settings: &'a SwapConfirmationsSettings, + my_persistent_pub: &'a H264, + maker_amount: &'a MmNumber, + taker_amount: &'a MmNumber, + locktime: &'a u64, +} +struct StateMachineParams<'a> { + secret_hash_algo: &'a SecretHashAlgo, + uuid: &'a Uuid, + my_conf_settings: &'a SwapConfirmationsSettings, + locktime: &'a u64, + maker_amount: &'a MmNumber, + taker_amount: &'a MmNumber, +} + #[cfg_attr(test, mockable)] fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerOrder, taker_p2p_pubkey: PublicKey) { let spawner = ctx.spawner(); @@ -3092,17 +3111,6 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO spawner.spawn_with_settings(fut, settings); } -struct LegacySwapParams<'a> { - maker_coin: &'a MmCoinEnum, - taker_coin: &'a MmCoinEnum, - uuid: &'a Uuid, - my_conf_settings: &'a SwapConfirmationsSettings, - my_persistent_pub: &'a H264, - maker_amount: &'a MmNumber, - taker_amount: &'a MmNumber, - locktime: &'a u64, -} - async fn start_maker_legacy_swap( ctx: &MmArc, maker_order: MakerOrder, @@ -3371,15 +3379,6 @@ async fn start_taker_legacy_swap(ctx: &MmArc, taker_order: TakerOrder, maker: bi run_taker_swap(RunTakerSwapInput::StartNew(taker_swap), ctx.clone()).await } -struct StateMachineParams<'a> { - secret_hash_algo: &'a SecretHashAlgo, - uuid: &'a Uuid, - my_conf_settings: &'a SwapConfirmationsSettings, - locktime: &'a u64, - maker_amount: &'a MmNumber, - taker_amount: &'a MmNumber, -} - async fn start_taker_swap_state_machine< MakerCoin: MmCoin + MakerCoinSwapOpsV2 + Clone, TakerCoin: MmCoin + TakerCoinSwapOpsV2 + Clone, From ac9a5a35fc606c61c647b3f7b9fdb0f5b456aafc Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 12 Dec 2024 18:02:51 +0700 Subject: [PATCH 46/59] review: rename taker/alice to taker_pubkey and maker to maker_pubkey --- mm2src/mm2_main/src/lp_ordermatch.rs | 25 +++++++++++-------- mm2src/mm2_main/src/lp_swap/maker_swap.rs | 16 ++++++------ .../src/lp_swap/recreate_swap_data.rs | 4 +-- mm2src/mm2_main/src/lp_swap/taker_swap.rs | 16 ++++++------ 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index 98ad339451..1dbc3689f9 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -2995,7 +2995,7 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO return; }, }; - let alice = bits256::from(maker_match.request.sender_pubkey.0); + let taker_pubkey = bits256::from(maker_match.request.sender_pubkey.0); let maker_amount = maker_match.reserved.get_base_amount().clone(); let taker_amount = maker_match.reserved.get_rel_amount().clone(); @@ -3061,7 +3061,7 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO taker_amount: &taker_amount, locktime: &lock_time, }; - start_maker_legacy_swap(&ctx, maker_order, alice, secret, params).await; + start_maker_legacy_swap(&ctx, maker_order, taker_pubkey, secret, params).await; return; } @@ -3102,7 +3102,7 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO taker_amount: &taker_amount, locktime: &lock_time, }; - start_maker_legacy_swap(&ctx, maker_order, alice, secret, params).await + start_maker_legacy_swap(&ctx, maker_order, taker_pubkey, secret, params).await }, } }; @@ -3114,7 +3114,7 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO async fn start_maker_legacy_swap( ctx: &MmArc, maker_order: MakerOrder, - alice: bits256, + taker_pubkey: bits256, secret: H256, params: LegacySwapParams<'_>, ) { @@ -3133,7 +3133,7 @@ async fn start_maker_legacy_swap( let maker_swap = MakerSwap::new( ctx.clone(), - alice, + taker_pubkey, params.maker_amount.to_decimal(), params.taker_amount.to_decimal(), *params.my_persistent_pub, @@ -3198,7 +3198,7 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat let fut = async move { // aka "taker_loop" - let maker = bits256::from(taker_match.reserved.sender_pubkey.0); + let maker_pubkey = bits256::from(taker_match.reserved.sender_pubkey.0); let taker_coin_ticker = taker_order.taker_coin_ticker(); let taker_coin = match lp_coinfind(&ctx, taker_coin_ticker).await { Ok(Some(c)) => c, @@ -3282,7 +3282,7 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat taker_amount: &taker_amount, locktime: &locktime, }; - start_taker_legacy_swap(&ctx, taker_order, maker, params).await; + start_taker_legacy_swap(&ctx, taker_order, maker_pubkey, params).await; return; } @@ -3334,7 +3334,7 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat taker_amount: &taker_amount, locktime: &locktime, }; - start_taker_legacy_swap(&ctx, taker_order, maker, params).await; + start_taker_legacy_swap(&ctx, taker_order, maker_pubkey, params).await; }, } }; @@ -3343,7 +3343,12 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat spawner.spawn_with_settings(fut, settings) } -async fn start_taker_legacy_swap(ctx: &MmArc, taker_order: TakerOrder, maker: bits256, params: LegacySwapParams<'_>) { +async fn start_taker_legacy_swap( + ctx: &MmArc, + taker_order: TakerOrder, + maker_pubkey: bits256, + params: LegacySwapParams<'_>, +) { #[cfg(any(test, feature = "run-docker-tests"))] let fail_at = std::env::var("TAKER_FAIL_AT").map(FailAt::from).ok(); @@ -3362,7 +3367,7 @@ async fn start_taker_legacy_swap(ctx: &MmArc, taker_order: TakerOrder, maker: bi let taker_swap = TakerSwap::new( ctx.clone(), - maker, + maker_pubkey, params.maker_amount.clone(), params.taker_amount.clone(), *params.my_persistent_pub, diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap.rs b/mm2src/mm2_main/src/lp_swap/maker_swap.rs index 8031efe9e5..97a3d63b2b 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap.rs @@ -142,7 +142,7 @@ impl TakerNegotiationData { pub struct MakerSwapData { pub taker_coin: String, pub maker_coin: String, - pub taker: H256Json, + pub taker_pubkey: H256Json, pub secret: H256Json, pub secret_hash: Option, pub my_persistent_pub: H264Json, @@ -217,7 +217,7 @@ pub struct MakerSwap { maker_amount: BigDecimal, taker_amount: BigDecimal, my_persistent_pub: H264, - taker: bits256, + taker_pubkey: bits256, uuid: Uuid, my_order_uuid: Option, taker_payment_lock: AtomicU64, @@ -357,7 +357,7 @@ impl MakerSwap { #[allow(clippy::too_many_arguments)] pub fn new( ctx: MmArc, - taker: bits256, + taker_pubkey: bits256, maker_amount: BigDecimal, taker_amount: BigDecimal, my_persistent_pub: H264, @@ -377,7 +377,7 @@ impl MakerSwap { maker_amount, taker_amount, my_persistent_pub, - taker, + taker_pubkey, uuid, my_order_uuid, taker_payment_lock: AtomicU64::new(0), @@ -549,7 +549,7 @@ impl MakerSwap { let data = MakerSwapData { taker_coin: self.taker_coin.ticker().to_owned(), maker_coin: self.maker_coin.ticker().to_owned(), - taker: self.taker.bytes.into(), + taker_pubkey: self.taker_pubkey.bytes.into(), secret: self.secret.into(), secret_hash: Some(self.secret_hash().into()), started_at, @@ -1339,7 +1339,7 @@ impl MakerSwap { } let mut taker = bits256::from([0; 32]); - taker.bytes = data.taker.0; + taker.bytes = data.taker_pubkey.0; let crypto_ctx = try_s!(CryptoCtx::from_ctx(&ctx)); let my_persistent_pub = H264::from(&**crypto_ctx.mm2_internal_key_pair().public()); @@ -2098,7 +2098,7 @@ pub async fn run_maker_swap(swap: RunMakerSwapInput, ctx: MmArc) { let running_swap = Arc::new(swap); let weak_ref = Arc::downgrade(&running_swap); let swap_ctx = SwapsContext::from_ctx(&ctx).unwrap(); - swap_ctx.init_msg_store(running_swap.uuid, running_swap.taker); + swap_ctx.init_msg_store(running_swap.uuid, running_swap.taker_pubkey); swap_ctx.running_swaps.lock().unwrap().push(weak_ref); let mut swap_fut = Box::pin( async move { @@ -2125,7 +2125,7 @@ pub async fn run_maker_swap(swap: RunMakerSwapInput, ctx: MmArc) { if event.should_ban_taker() { ban_pubkey_on_failed_swap( &ctx, - running_swap.taker.bytes.into(), + running_swap.taker_pubkey.bytes.into(), &running_swap.uuid, event.clone().into(), ) diff --git a/mm2src/mm2_main/src/lp_swap/recreate_swap_data.rs b/mm2src/mm2_main/src/lp_swap/recreate_swap_data.rs index e4e430c71c..c44455a7c1 100644 --- a/mm2src/mm2_main/src/lp_swap/recreate_swap_data.rs +++ b/mm2src/mm2_main/src/lp_swap/recreate_swap_data.rs @@ -122,7 +122,7 @@ fn recreate_maker_swap(ctx: MmArc, taker_swap: TakerSavedSwap) -> RecreateSwapRe let maker_started_event = MakerSwapEvent::Started(MakerSwapData { taker_coin: started_event.taker_coin, maker_coin: started_event.maker_coin, - taker: H256Json::from(taker_p2p_pubkey), + taker_pubkey: H256Json::from(taker_p2p_pubkey), // We could parse the `TakerSwapEvent::TakerPaymentSpent` event. // As for now, don't try to find the secret in the events since we can refund without it. secret: H256Json::default(), @@ -323,7 +323,7 @@ async fn recreate_taker_swap(ctx: MmArc, maker_swap: MakerSavedSwap) -> Recreate let taker_started_event = TakerSwapEvent::Started(TakerSwapData { taker_coin: started_event.taker_coin, maker_coin: started_event.maker_coin.clone(), - maker: H256Json::from(maker_p2p_pubkey), + maker_pubkey: H256Json::from(maker_p2p_pubkey), my_persistent_pub: negotiated_event.taker_pubkey, lock_duration: started_event.lock_duration, maker_amount: started_event.maker_amount, diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap.rs b/mm2src/mm2_main/src/lp_swap/taker_swap.rs index c7b1cf59a9..b00daf2ef5 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap.rs @@ -463,7 +463,7 @@ pub async fn run_taker_swap(swap: RunTakerSwapInput, ctx: MmArc) { let running_swap = Arc::new(swap); let weak_ref = Arc::downgrade(&running_swap); let swap_ctx = SwapsContext::from_ctx(&ctx).unwrap(); - swap_ctx.init_msg_store(running_swap.uuid, running_swap.maker); + swap_ctx.init_msg_store(running_swap.uuid, running_swap.maker_pubkey); swap_ctx.running_swaps.lock().unwrap().push(weak_ref); let mut swap_fut = Box::pin( @@ -484,7 +484,7 @@ pub async fn run_taker_swap(swap: RunTakerSwapInput, ctx: MmArc) { if event.should_ban_maker() { ban_pubkey_on_failed_swap( &ctx, - running_swap.maker.bytes.into(), + running_swap.maker_pubkey.bytes.into(), &running_swap.uuid, event.clone().into(), ) @@ -528,7 +528,7 @@ pub async fn run_taker_swap(swap: RunTakerSwapInput, ctx: MmArc) { pub struct TakerSwapData { pub taker_coin: String, pub maker_coin: String, - pub maker: H256Json, + pub maker_pubkey: H256Json, pub my_persistent_pub: H264Json, pub lock_duration: u64, pub maker_amount: BigDecimal, @@ -618,7 +618,7 @@ pub struct TakerSwap { pub maker_amount: MmNumber, pub taker_amount: MmNumber, my_persistent_pub: H264, - maker: bits256, + maker_pubkey: bits256, uuid: Uuid, my_order_uuid: Option, pub maker_payment_lock: AtomicU64, @@ -901,7 +901,7 @@ impl TakerSwap { #[allow(clippy::too_many_arguments)] pub fn new( ctx: MmArc, - maker: bits256, + maker_pubkey: bits256, maker_amount: MmNumber, taker_amount: MmNumber, my_persistent_pub: H264, @@ -920,7 +920,7 @@ impl TakerSwap { maker_amount, taker_amount, my_persistent_pub, - maker, + maker_pubkey, uuid, my_order_uuid, maker_payment_confirmed: AtomicBool::new(false), @@ -1111,7 +1111,7 @@ impl TakerSwap { let data = TakerSwapData { taker_coin: self.taker_coin.ticker().to_owned(), maker_coin: self.maker_coin.ticker().to_owned(), - maker: self.maker.bytes.into(), + maker_pubkey: self.maker_pubkey.bytes.into(), started_at, lock_duration: self.payment_locktime, maker_amount: self.maker_amount.to_decimal(), @@ -2043,7 +2043,7 @@ impl TakerSwap { let my_persistent_pub = H264::from(&**crypto_ctx.mm2_internal_key_pair().public()); let mut maker = bits256::from([0; 32]); - maker.bytes = data.maker.0; + maker.bytes = data.maker_pubkey.0; let conf_settings = SwapConfirmationsSettings { maker_coin_confs: data.maker_payment_confirmations, maker_coin_nota: data From ab56a126224b9b3be652f194cae9804e8f9e89bc Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 12 Dec 2024 18:32:34 +0700 Subject: [PATCH 47/59] fix clippy in tests --- mm2src/mm2_main/src/lp_swap/maker_swap.rs | 2 +- .../tests/docker_tests/eth_docker_tests.rs | 27 +++++++++---------- .../tests/docker_tests/swap_proto_v2_tests.rs | 18 ++++++------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap.rs b/mm2src/mm2_main/src/lp_swap/maker_swap.rs index 97a3d63b2b..79d57912f1 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap.rs @@ -1819,7 +1819,7 @@ impl MakerSavedSwap { event: MakerSwapEvent::Started(MakerSwapData { taker_coin: "".to_string(), maker_coin: "".to_string(), - taker: Default::default(), + taker_pubkey: Default::default(), secret: Default::default(), secret_hash: None, my_persistent_pub: Default::default(), diff --git a/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs b/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs index 079e566cfc..d922ba8f27 100644 --- a/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs @@ -1485,7 +1485,7 @@ fn send_and_refund_taker_funding_by_secret_eth() { let maker_coin = get_or_create_sepolia_coin(&MM_CTX, SEPOLIA_MAKER_PRIV, ETH, ð_sepolia_conf(), false); let taker_secret = &[0; 32]; - let taker_secret_hash = sha256(&taker_secret).to_vec(); + let taker_secret_hash = sha256(taker_secret).to_vec(); let maker_secret = &[1; 32]; let maker_secret_hash = sha256(maker_secret).to_vec(); let funding_time_lock = now_sec() + 3000; @@ -1548,7 +1548,7 @@ fn send_and_refund_taker_funding_by_secret_erc20() { let maker_coin = get_or_create_sepolia_coin(&MM_CTX1, SEPOLIA_MAKER_PRIV, ERC20, erc20_conf, true); let taker_secret = &[0; 32]; - let taker_secret_hash = sha256(&taker_secret).to_vec(); + let taker_secret_hash = sha256(taker_secret).to_vec(); let maker_secret = [1; 32]; let maker_secret_hash = sha256(&maker_secret).to_vec(); @@ -1675,7 +1675,7 @@ fn taker_send_approve_and_spend_eth() { let maker_coin = get_or_create_sepolia_coin(&MM_CTX, SEPOLIA_MAKER_PRIV, ETH, ð_sepolia_conf(), false); let taker_secret = &[0; 32]; - let taker_secret_hash = sha256(&taker_secret).to_vec(); + let taker_secret_hash = sha256(taker_secret).to_vec(); let maker_secret = &[1; 32]; let maker_secret_hash = sha256(maker_secret).to_vec(); let funding_time_lock = now_sec() + 3000; @@ -1770,15 +1770,14 @@ fn taker_send_approve_and_spend_eth() { }; wait_pending_transactions(Address::from_slice(maker_address.as_bytes())); let spend_tx = - block_on(maker_coin.sign_and_broadcast_taker_payment_spend(&preimage, &spend_args, &maker_secret, &[])) - .unwrap(); + block_on(maker_coin.sign_and_broadcast_taker_payment_spend(&preimage, &spend_args, maker_secret, &[])).unwrap(); log!("Maker spent ETH payment, tx hash: {:02x}", spend_tx.tx_hash()); wait_for_confirmations(&maker_coin, &spend_tx, 100); let found_spend_tx = block_on(taker_coin.find_taker_payment_spend_tx(&taker_approve_tx, taker_coin_start_block, payment_time_lock)) .unwrap(); let extracted_maker_secret = block_on(taker_coin.extract_secret_v2(&[], &found_spend_tx)).unwrap(); - assert_eq!(maker_secret, extracted_maker_secret); + assert_eq!(maker_secret, &extracted_maker_secret); } #[cfg(feature = "sepolia-taker-swap-v2-tests")] @@ -2249,10 +2248,10 @@ fn send_maker_payment_and_refund_secret_eth() { let taker_coin = get_or_create_sepolia_coin(&MM_CTX1, SEPOLIA_TAKER_PRIV, ETH, ð_sepolia_conf(), false); let maker_coin = get_or_create_sepolia_coin(&MM_CTX, SEPOLIA_MAKER_PRIV, ETH, ð_sepolia_conf(), false); - let taker_secret = [0; 32]; - let taker_secret_hash = sha256(&taker_secret).to_vec(); - let maker_secret = [1; 32]; - let maker_secret_hash = sha256(&maker_secret).to_vec(); + let taker_secret = &[0; 32]; + let taker_secret_hash = sha256(taker_secret).to_vec(); + let maker_secret = &[1; 32]; + let maker_secret_hash = sha256(maker_secret).to_vec(); let payment_time_lock = now_sec() + 1000; let maker_address = block_on(maker_coin.my_addr()); @@ -2301,10 +2300,10 @@ fn send_maker_payment_and_refund_secret_erc20() { let taker_coin = get_or_create_sepolia_coin(&MM_CTX1, SEPOLIA_TAKER_PRIV, ERC20, erc20_conf, true); let maker_coin = get_or_create_sepolia_coin(&MM_CTX, SEPOLIA_MAKER_PRIV, ERC20, erc20_conf, true); - let taker_secret = [0; 32]; - let taker_secret_hash = sha256(&taker_secret).to_vec(); - let maker_secret = [1; 32]; - let maker_secret_hash = sha256(&maker_secret).to_vec(); + let taker_secret = &[0; 32]; + let taker_secret_hash = sha256(taker_secret).to_vec(); + let maker_secret = &[1; 32]; + let maker_secret_hash = sha256(maker_secret).to_vec(); let payment_time_lock = now_sec() + 1000; let maker_address = block_on(maker_coin.my_addr()); diff --git a/mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs b/mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs index 840c4481a4..31cdd4d3ff 100644 --- a/mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs @@ -107,8 +107,8 @@ fn send_and_refund_taker_funding_secret() { let (_mm_arc, coin, _privkey) = generate_utxo_coin_with_random_privkey(MYCOIN, 1000.into()); let funding_time_lock = now_sec() - 1000; - let taker_secret = [0; 32]; - let taker_secret_hash_owned = dhash160(&taker_secret); + let taker_secret = &[0; 32]; + let taker_secret_hash_owned = dhash160(taker_secret); let taker_secret_hash = taker_secret_hash_owned.as_slice(); let maker_pub = coin.my_public_key().unwrap(); let dex_fee = &DexFee::Standard("0.01".into()); @@ -186,7 +186,7 @@ fn send_and_refund_taker_funding_secret() { match found_refund_tx { Some(FundingTxSpend::RefundedSecret { tx, secret }) => { assert_eq!(refund_tx, tx); - assert_eq!(taker_secret, secret); + assert_eq!(taker_secret, &secret); }, unexpected => panic!("Got unexpected FundingTxSpend variant {:?}", unexpected), } @@ -559,10 +559,10 @@ fn send_and_refund_maker_payment_timelock() { #[test] fn send_and_refund_maker_payment_taker_secret() { let (_mm_arc, coin, _privkey) = generate_utxo_coin_with_random_privkey(MYCOIN, 1000.into()); - let taker_secret = [1; 32]; + let taker_secret = &[1; 32]; let time_lock = now_sec() + 1000; - let taker_secret_hash_owned = dhash160(&taker_secret); + let taker_secret_hash_owned = dhash160(taker_secret); let taker_secret_hash = taker_secret_hash_owned.as_slice(); let maker_secret_hash = &[1; 20]; let taker_pub = coin.my_public_key().unwrap(); @@ -699,8 +699,8 @@ fn test_v2_swap_utxo_utxo() { assert_eq!(locked_bob.locked_amount, expected); for uuid in uuids { - block_on(wait_for_swap_finished(&mm_bob, &uuid, 180)); - block_on(wait_for_swap_finished(&mm_alice, &uuid, 100)); + block_on(wait_for_swap_finished(&mm_bob, &uuid, 60)); + block_on(wait_for_swap_finished(&mm_alice, &uuid, 30)); let maker_swap_status = block_on(my_swap_status(&mm_bob, &uuid)); log!("{:?}", maker_swap_status); @@ -829,8 +829,8 @@ fn test_v2_swap_utxo_utxo_kickstart() { assert_eq!(locked_bob.locked_amount, expected); for uuid in uuids { - block_on(wait_for_swap_finished(&mm_bob, &uuid, 180)); - block_on(wait_for_swap_finished(&mm_alice, &uuid, 100)); + block_on(wait_for_swap_finished(&mm_bob, &uuid, 60)); + block_on(wait_for_swap_finished(&mm_alice, &uuid, 30)); } } From 0ca61fd95277e505d14e646ea0c8328ce04ff9d9 Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 12 Dec 2024 18:59:54 +0700 Subject: [PATCH 48/59] update maker and taker pubkey fields in test jsons --- .../for_tests/iris_nimda_rick_maker_swap.json | 2 +- .../for_tests/iris_nimda_rick_taker_swap.json | 2 +- .../recreate_maker_swap_maker_expected.json | 2 +- ...nt_wait_confirm_failed_maker_expected.json | 2 +- ...yment_wait_confirm_failed_taker_saved.json | 2 +- .../recreate_maker_swap_taker_saved.json | 2 +- .../recreate_taker_swap_maker_saved.json | 2 +- .../recreate_taker_swap_taker_expected.json | 2 +- ...yment_wait_confirm_failed_maker_saved.json | 2 +- ...nt_wait_confirm_failed_taker_expected.json | 2 +- mm2src/mm2_main/src/lp_swap/maker_swap.rs | 28 +++++++++---------- mm2src/mm2_main/src/lp_swap/taker_swap.rs | 22 +++++++-------- 12 files changed, 35 insertions(+), 35 deletions(-) diff --git a/mm2src/mm2_main/src/for_tests/iris_nimda_rick_maker_swap.json b/mm2src/mm2_main/src/for_tests/iris_nimda_rick_maker_swap.json index 2d57f26ab6..cc805475f0 100644 --- a/mm2src/mm2_main/src/for_tests/iris_nimda_rick_maker_swap.json +++ b/mm2src/mm2_main/src/for_tests/iris_nimda_rick_maker_swap.json @@ -10,7 +10,7 @@ "data": { "taker_coin": "RICK", "maker_coin": "IRIS-NIMDA", - "taker": "5a37975c079a7543603fcab24e2565a4adee3cf9af8934690e103282fa402511", + "taker_pubkey": "5a37975c079a7543603fcab24e2565a4adee3cf9af8934690e103282fa402511", "secret": "cdb95a058d5c6e9d5781be69af10884a7c812ab59885656c4a0dc373a71b737a", "secret_hash": "019c4f058c23a54d9bad8727edc6287c3bb1e3cf367297745db0db9a15099d02", "my_persistent_pub": "02238527725c96affccb7c55f3900b345b80ec5268d483284f162807775d32b32b", diff --git a/mm2src/mm2_main/src/for_tests/iris_nimda_rick_taker_swap.json b/mm2src/mm2_main/src/for_tests/iris_nimda_rick_taker_swap.json index 93cab41558..08e9ee35ac 100644 --- a/mm2src/mm2_main/src/for_tests/iris_nimda_rick_taker_swap.json +++ b/mm2src/mm2_main/src/for_tests/iris_nimda_rick_taker_swap.json @@ -10,7 +10,7 @@ "data": { "taker_coin": "RICK", "maker_coin": "IRIS-NIMDA", - "maker": "238527725c96affccb7c55f3900b345b80ec5268d483284f162807775d32b32b", + "maker_pubkey": "238527725c96affccb7c55f3900b345b80ec5268d483284f162807775d32b32b", "my_persistent_pub": "025a37975c079a7543603fcab24e2565a4adee3cf9af8934690e103282fa402511", "lock_duration": 7800, "maker_amount": "0.01", diff --git a/mm2src/mm2_main/src/for_tests/recreate_maker_swap_maker_expected.json b/mm2src/mm2_main/src/for_tests/recreate_maker_swap_maker_expected.json index 180cade8d2..1f4c96c9f6 100644 --- a/mm2src/mm2_main/src/for_tests/recreate_maker_swap_maker_expected.json +++ b/mm2src/mm2_main/src/for_tests/recreate_maker_swap_maker_expected.json @@ -6,7 +6,7 @@ "data":{ "taker_coin":"MORTY", "maker_coin":"RICK", - "taker":"b1e544ce2d860219bc91314b5483421a553a7b33044659eff0be9214ed58addd", + "taker_pubkey":"b1e544ce2d860219bc91314b5483421a553a7b33044659eff0be9214ed58addd", "secret":"0000000000000000000000000000000000000000000000000000000000000000", "secret_hash":"4da9e7080175e8e10842e0e161b33cd298cab30b", "my_persistent_pub":"0315d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", diff --git a/mm2src/mm2_main/src/for_tests/recreate_maker_swap_maker_payment_wait_confirm_failed_maker_expected.json b/mm2src/mm2_main/src/for_tests/recreate_maker_swap_maker_payment_wait_confirm_failed_maker_expected.json index 4e95aa537a..c7e8f65941 100644 --- a/mm2src/mm2_main/src/for_tests/recreate_maker_swap_maker_payment_wait_confirm_failed_maker_expected.json +++ b/mm2src/mm2_main/src/for_tests/recreate_maker_swap_maker_payment_wait_confirm_failed_maker_expected.json @@ -6,7 +6,7 @@ "data":{ "taker_coin":"MORTY", "maker_coin":"RICK", - "taker":"b1e544ce2d860219bc91314b5483421a553a7b33044659eff0be9214ed58addd", + "taker_pubkey":"b1e544ce2d860219bc91314b5483421a553a7b33044659eff0be9214ed58addd", "secret":"0000000000000000000000000000000000000000000000000000000000000000", "secret_hash":"4da9e7080175e8e10842e0e161b33cd298cab30b", "my_persistent_pub":"0315d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", diff --git a/mm2src/mm2_main/src/for_tests/recreate_maker_swap_maker_payment_wait_confirm_failed_taker_saved.json b/mm2src/mm2_main/src/for_tests/recreate_maker_swap_maker_payment_wait_confirm_failed_taker_saved.json index 73261f641e..9f8903b540 100644 --- a/mm2src/mm2_main/src/for_tests/recreate_maker_swap_maker_payment_wait_confirm_failed_taker_saved.json +++ b/mm2src/mm2_main/src/for_tests/recreate_maker_swap_maker_payment_wait_confirm_failed_taker_saved.json @@ -6,7 +6,7 @@ "data":{ "taker_coin":"MORTY", "maker_coin":"RICK", - "maker":"15d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", + "maker_pubkey":"15d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", "my_persistent_pub":"03b1e544ce2d860219bc91314b5483421a553a7b33044659eff0be9214ed58addd", "lock_duration":7800, "maker_amount":"0.9090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909091", diff --git a/mm2src/mm2_main/src/for_tests/recreate_maker_swap_taker_saved.json b/mm2src/mm2_main/src/for_tests/recreate_maker_swap_taker_saved.json index a3158581c6..916df45415 100644 --- a/mm2src/mm2_main/src/for_tests/recreate_maker_swap_taker_saved.json +++ b/mm2src/mm2_main/src/for_tests/recreate_maker_swap_taker_saved.json @@ -6,7 +6,7 @@ "data":{ "taker_coin":"MORTY", "maker_coin":"RICK", - "maker":"15d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", + "maker_pubkey":"15d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", "my_persistent_pub":"03b1e544ce2d860219bc91314b5483421a553a7b33044659eff0be9214ed58addd", "lock_duration":7800, "maker_amount":"0.9090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909091", diff --git a/mm2src/mm2_main/src/for_tests/recreate_taker_swap_maker_saved.json b/mm2src/mm2_main/src/for_tests/recreate_taker_swap_maker_saved.json index e33610e2f1..51a4a26dc4 100644 --- a/mm2src/mm2_main/src/for_tests/recreate_taker_swap_maker_saved.json +++ b/mm2src/mm2_main/src/for_tests/recreate_taker_swap_maker_saved.json @@ -6,7 +6,7 @@ "data":{ "taker_coin":"MORTY", "maker_coin":"RICK", - "taker":"b1e544ce2d860219bc91314b5483421a553a7b33044659eff0be9214ed58addd", + "taker_pubkey":"b1e544ce2d860219bc91314b5483421a553a7b33044659eff0be9214ed58addd", "secret":"0000000000000000000000000000000000000000000000000000000000000000", "secret_hash":"4da9e7080175e8e10842e0e161b33cd298cab30b", "my_persistent_pub":"0315d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", diff --git a/mm2src/mm2_main/src/for_tests/recreate_taker_swap_taker_expected.json b/mm2src/mm2_main/src/for_tests/recreate_taker_swap_taker_expected.json index 1c1cc39acf..903c007aa8 100644 --- a/mm2src/mm2_main/src/for_tests/recreate_taker_swap_taker_expected.json +++ b/mm2src/mm2_main/src/for_tests/recreate_taker_swap_taker_expected.json @@ -6,7 +6,7 @@ "data":{ "taker_coin":"MORTY", "maker_coin":"RICK", - "maker":"15d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", + "maker_pubkey":"15d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", "my_persistent_pub":"03b1e544ce2d860219bc91314b5483421a553a7b33044659eff0be9214ed58addd", "lock_duration":7800, "maker_amount":"0.9090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909091", diff --git a/mm2src/mm2_main/src/for_tests/recreate_taker_swap_taker_payment_wait_confirm_failed_maker_saved.json b/mm2src/mm2_main/src/for_tests/recreate_taker_swap_taker_payment_wait_confirm_failed_maker_saved.json index 3e0ab14910..2b2dd51056 100644 --- a/mm2src/mm2_main/src/for_tests/recreate_taker_swap_taker_payment_wait_confirm_failed_maker_saved.json +++ b/mm2src/mm2_main/src/for_tests/recreate_taker_swap_taker_payment_wait_confirm_failed_maker_saved.json @@ -6,7 +6,7 @@ "data":{ "taker_coin":"MORTY", "maker_coin":"RICK", - "taker":"b1e544ce2d860219bc91314b5483421a553a7b33044659eff0be9214ed58addd", + "taker_pubkey":"b1e544ce2d860219bc91314b5483421a553a7b33044659eff0be9214ed58addd", "secret":"0000000000000000000000000000000000000000000000000000000000000000", "secret_hash":"4da9e7080175e8e10842e0e161b33cd298cab30b", "my_persistent_pub":"0315d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", diff --git a/mm2src/mm2_main/src/for_tests/recreate_taker_swap_taker_payment_wait_confirm_failed_taker_expected.json b/mm2src/mm2_main/src/for_tests/recreate_taker_swap_taker_payment_wait_confirm_failed_taker_expected.json index e743669805..7b96783380 100644 --- a/mm2src/mm2_main/src/for_tests/recreate_taker_swap_taker_payment_wait_confirm_failed_taker_expected.json +++ b/mm2src/mm2_main/src/for_tests/recreate_taker_swap_taker_payment_wait_confirm_failed_taker_expected.json @@ -6,7 +6,7 @@ "data":{ "taker_coin":"MORTY", "maker_coin":"RICK", - "maker":"15d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", + "maker_pubkey":"15d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", "my_persistent_pub":"03b1e544ce2d860219bc91314b5483421a553a7b33044659eff0be9214ed58addd", "lock_duration":7800, "maker_amount":"0.9090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909091", diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap.rs b/mm2src/mm2_main/src/lp_swap/maker_swap.rs index 79d57912f1..7e7ff33d84 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap.rs @@ -2390,7 +2390,7 @@ mod maker_swap_tests { // the swap ends up with MakerPaymentTransactionFailed error but the transaction is actually // sent, need to find it and refund // TODO remove TransactionDetails from json - let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563743939,"taker":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"MakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563763243350}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; + let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563743939,"taker_pubkey":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"MakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563763243350}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2430,7 +2430,7 @@ mod maker_swap_tests { let ctx = mm_ctx_with_iguana(PASSPHRASE); // the swap ends up with MakerPaymentRefundFailed error - let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_lock":1563636475,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563620875,"taker":"14a96292bfcd7762ece8eb08ead915da927c2619277363853572f30880d5155e","taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875062},{"event":{"data":{"taker_payment_locktime":1563628675,"taker_pubkey":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91"},"type":"Negotiated"},"timestamp":1563620915497},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeValidated"},"timestamp":1563620976060},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentSent"},"timestamp":1563620976189},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentReceived"},"timestamp":1563621268320},{"event":{"type":"TakerPaymentWaitConfirmStarted"},"timestamp":1563621268321},{"event":{"type":"TakerPaymentValidatedAndConfirmed"},"timestamp":1563621778471},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentSpendFailed"},"timestamp":1563638060583},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"MakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563621778483}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; + let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_lock":1563636475,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563620875,"taker_pubkey":"14a96292bfcd7762ece8eb08ead915da927c2619277363853572f30880d5155e","taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875062},{"event":{"data":{"taker_payment_locktime":1563628675,"taker_pubkey":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91"},"type":"Negotiated"},"timestamp":1563620915497},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeValidated"},"timestamp":1563620976060},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentSent"},"timestamp":1563620976189},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentReceived"},"timestamp":1563621268320},{"event":{"type":"TakerPaymentWaitConfirmStarted"},"timestamp":1563621268321},{"event":{"type":"TakerPaymentValidatedAndConfirmed"},"timestamp":1563621778471},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentSpendFailed"},"timestamp":1563638060583},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"MakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563621778483}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2464,7 +2464,7 @@ mod maker_swap_tests { let ctx = mm_ctx_with_iguana(PASSPHRASE); // the swap ends up with MakerPaymentRefundFailed error - let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_lock":1563636475,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563620875,"taker":"14a96292bfcd7762ece8eb08ead915da927c2619277363853572f30880d5155e","taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875062},{"event":{"data":{"taker_payment_locktime":1563628675,"taker_pubkey":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91"},"type":"Negotiated"},"timestamp":1563620915497},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeValidated"},"timestamp":1563620976060},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentSent"},"timestamp":1563620976189},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentReceived"},"timestamp":1563621268320},{"event":{"type":"TakerPaymentWaitConfirmStarted"},"timestamp":1563621268321},{"event":{"type":"TakerPaymentValidatedAndConfirmed"},"timestamp":1563621778471},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentSpendFailed"},"timestamp":1563638060583},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"MakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563621778483}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; + let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_lock":1563636475,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563620875,"taker_pubkey":"14a96292bfcd7762ece8eb08ead915da927c2619277363853572f30880d5155e","taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875062},{"event":{"data":{"taker_payment_locktime":1563628675,"taker_pubkey":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91"},"type":"Negotiated"},"timestamp":1563620915497},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeValidated"},"timestamp":1563620976060},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentSent"},"timestamp":1563620976189},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentReceived"},"timestamp":1563621268320},{"event":{"type":"TakerPaymentWaitConfirmStarted"},"timestamp":1563621268321},{"event":{"type":"TakerPaymentValidatedAndConfirmed"},"timestamp":1563621778471},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentSpendFailed"},"timestamp":1563638060583},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"MakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563621778483}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2486,7 +2486,7 @@ mod maker_swap_tests { let ctx = mm_ctx_with_iguana(PASSPHRASE); // the swap ends up with MakerPaymentRefundFailed error - let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_lock":1563636475,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563620875,"taker":"14a96292bfcd7762ece8eb08ead915da927c2619277363853572f30880d5155e","taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875062},{"event":{"data":{"taker_payment_locktime":1563628675,"taker_pubkey":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91"},"type":"Negotiated"},"timestamp":1563620915497},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeValidated"},"timestamp":1563620976060},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentSent"},"timestamp":1563620976189},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentReceived"},"timestamp":1563621268320},{"event":{"type":"TakerPaymentWaitConfirmStarted"},"timestamp":1563621268321},{"event":{"type":"TakerPaymentValidatedAndConfirmed"},"timestamp":1563621778471},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentSpendFailed"},"timestamp":1563638060583},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"MakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563621778483}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; + let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_lock":1563636475,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563620875,"taker_pubkey":"14a96292bfcd7762ece8eb08ead915da927c2619277363853572f30880d5155e","taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875062},{"event":{"data":{"taker_payment_locktime":1563628675,"taker_pubkey":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91"},"type":"Negotiated"},"timestamp":1563620915497},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeValidated"},"timestamp":1563620976060},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentSent"},"timestamp":1563620976189},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentReceived"},"timestamp":1563621268320},{"event":{"type":"TakerPaymentWaitConfirmStarted"},"timestamp":1563621268321},{"event":{"type":"TakerPaymentValidatedAndConfirmed"},"timestamp":1563621778471},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentSpendFailed"},"timestamp":1563638060583},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"MakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563621778483}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2522,7 +2522,7 @@ mod maker_swap_tests { // the swap ends up with MakerPaymentTransactionFailed error but the transaction is actually // sent, need to find it and refund, prevent refund if payment is not spendable due to locktime restrictions - let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563743939,"taker":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"MakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563763243350}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; + let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563743939,"taker_pubkey":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"MakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563763243350}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2551,7 +2551,7 @@ mod maker_swap_tests { // the swap ends up with MakerPaymentTransactionFailed error and transaction is not sent, // recover must return error in this case - let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563743939,"taker":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"MakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563763243350}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; + let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563743939,"taker_pubkey":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"MakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563763243350}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2574,7 +2574,7 @@ mod maker_swap_tests { let ctx = mm_ctx_with_iguana(PASSPHRASE); // return error if swap is not finished - let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563743939,"taker":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; + let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563743939,"taker_pubkey":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2590,7 +2590,7 @@ mod maker_swap_tests { let ctx = mm_ctx_with_iguana(PASSPHRASE); // return error if taker payment was spent by us - let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"1","maker_coin":"BEER","maker_coin_start_block":154892,"maker_payment_confirmations":1,"maker_payment_lock":1563444026,"my_persistent_pub":"02631dcf1d4b1b693aa8c2751afc68e4794b1e5996566cfc701a663f8b7bbbe640","secret":"e1c9bd12a83f810813dc078ac398069b63d56bf1e94657def995c43cd1975302","started_at":1563428426,"taker":"031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3","taker_amount":"1","taker_coin":"ETOMIC","taker_coin_start_block":150282,"taker_payment_confirmations":1,"uuid":"983ce732-62a8-4a44-b4ac-7e4271adc977"},"type":"Started"},"timestamp":1563428426510},{"event":{"data":{"taker_payment_locktime":1563436226,"taker_pubkey":"02031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3"},"type":"Negotiated"},"timestamp":1563428466880},{"event":{"data":{"tx_hash":"32f5bec2106dd3778dc32e3d856398ed0fa10b71c688672906a4fa0345cc4135","tx_hex":"0400008085202f89015ba9c8f0aec5b409bc824bcddc1a5a40148d4bd065c10169249e44ec44d62db2010000006a473044022050a213db7486e34871b9e7ef850845d55e0d53431350c16fa14fb60b81b1858302204f1042761f84e5f8d22948358b3c4103861adf5293d1d9e7f58f3b7491470b19012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffff02bcf60100000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac764d12ac010000001976a91405aab5342166f8594baf17a7d9bef5d56744332788ac8806305d000000000000000000000000000000"},"type":"TakerFeeValidated"},"timestamp":1563428507723},{"event":{"data":{"tx_hash":"1619d10a51925d2f3d0ef92d81cb6449b77d5dbe1f3ef5e7ae6c8bc19080cb5a","tx_hex":"0400008085202f890176ead03820bc0c4e92dba39b5d7e7a1e176b165f6cfc7a5e2c000ed62e8a8134010000006b48304502210086ca9a6ea5e787f4c3001c4ddb7b2f4732d8bb2642e9e43d0f39df4b736a4aa402206dbd17753f728d70c9631b6c2d1bba125745a5bc9be6112febf0e0c8ada786b1012102631dcf1d4b1b693aa8c2751afc68e4794b1e5996566cfc701a663f8b7bbbe640ffffffff0200e1f5050000000017a91410503cfea67f03f025c5e1eeb18524464adf77ee877f360c18c00000001976a91464ae8510aac9546d5e7704e31ce177451386455588ac9b06305d000000000000000000000000000000"},"type":"MakerPaymentSent"},"timestamp":1563428512925},{"event":{"data":{"tx_hash":"ee8b904efdee0d3bf0215d14a236489cde0b0efa92f7fa49faaa5fd97ed38ac0","tx_hex":"0400008085202f89013541cc4503faa406296788c6710ba10fed9863853d2ec38d77d36d10c2bef532010000006b483045022100a32e290d3a047ad75a512f9fd581c561c5153aa1b6be2b36915a9dd452cd0d4102204d1838b3cd15698ab424d15651d50983f0196e59b0b34abaad9cb792c97b527a012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffff0200e1f5050000000017a91424fc6f967eaa2751adbeb42a97c3497fbd9ddcce878e681ca6010000001976a91405aab5342166f8594baf17a7d9bef5d56744332788acbf06305d000000000000000000000000000000"},"type":"TakerPaymentReceived"},"timestamp":1563428664418},{"event":{"type":"TakerPaymentWaitConfirmStarted"},"timestamp":1563428664420},{"event":{"type":"TakerPaymentValidatedAndConfirmed"},"timestamp":1563428664824},{"event":{"data":{"tx_hash":"8b48d7452a2a1c6b1128aa83ab946e5a624037c5327b527b18c3dcadb404f139","tx_hex":"0400008085202f8901c08ad37ed95faafa49faf792fa0e0bde9c4836a2145d21f03b0deefd4e908bee00000000d747304402206ac1f2b5b856b86585b4d2147309e3a7ef9dd4c35ffd85a49c409a4acd11602902204be03e2114888fae460eaf99675bae0c834ff80be8531a5bd30ee14baf0a52e30120e1c9bd12a83f810813dc078ac398069b63d56bf1e94657def995c43cd1975302004c6b6304c224305db1752102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ac6782012088a9143501575fb9a12a689bb94adad33cc78c13b0688c882102631dcf1d4b1b693aa8c2751afc68e4794b1e5996566cfc701a663f8b7bbbe640ac68ffffffff0118ddf505000000001976a91464ae8510aac9546d5e7704e31ce177451386455588ac28f92f5d000000000000000000000000000000"},"type":"TakerPaymentSpent"},"timestamp":1563428666150},{"event":{"type":"Finished"},"timestamp":1563428666152}],"my_info":{"my_amount":"1","my_coin":"BEER","other_amount":"1","other_coin":"ETOMIC","started_at":1563428426},"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"type":"Maker","uuid":"983ce732-62a8-4a44-b4ac-7e4271adc977"}"#; + let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"1","maker_coin":"BEER","maker_coin_start_block":154892,"maker_payment_confirmations":1,"maker_payment_lock":1563444026,"my_persistent_pub":"02631dcf1d4b1b693aa8c2751afc68e4794b1e5996566cfc701a663f8b7bbbe640","secret":"e1c9bd12a83f810813dc078ac398069b63d56bf1e94657def995c43cd1975302","started_at":1563428426,"taker_pubkey":"031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3","taker_amount":"1","taker_coin":"ETOMIC","taker_coin_start_block":150282,"taker_payment_confirmations":1,"uuid":"983ce732-62a8-4a44-b4ac-7e4271adc977"},"type":"Started"},"timestamp":1563428426510},{"event":{"data":{"taker_payment_locktime":1563436226,"taker_pubkey":"02031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3"},"type":"Negotiated"},"timestamp":1563428466880},{"event":{"data":{"tx_hash":"32f5bec2106dd3778dc32e3d856398ed0fa10b71c688672906a4fa0345cc4135","tx_hex":"0400008085202f89015ba9c8f0aec5b409bc824bcddc1a5a40148d4bd065c10169249e44ec44d62db2010000006a473044022050a213db7486e34871b9e7ef850845d55e0d53431350c16fa14fb60b81b1858302204f1042761f84e5f8d22948358b3c4103861adf5293d1d9e7f58f3b7491470b19012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffff02bcf60100000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac764d12ac010000001976a91405aab5342166f8594baf17a7d9bef5d56744332788ac8806305d000000000000000000000000000000"},"type":"TakerFeeValidated"},"timestamp":1563428507723},{"event":{"data":{"tx_hash":"1619d10a51925d2f3d0ef92d81cb6449b77d5dbe1f3ef5e7ae6c8bc19080cb5a","tx_hex":"0400008085202f890176ead03820bc0c4e92dba39b5d7e7a1e176b165f6cfc7a5e2c000ed62e8a8134010000006b48304502210086ca9a6ea5e787f4c3001c4ddb7b2f4732d8bb2642e9e43d0f39df4b736a4aa402206dbd17753f728d70c9631b6c2d1bba125745a5bc9be6112febf0e0c8ada786b1012102631dcf1d4b1b693aa8c2751afc68e4794b1e5996566cfc701a663f8b7bbbe640ffffffff0200e1f5050000000017a91410503cfea67f03f025c5e1eeb18524464adf77ee877f360c18c00000001976a91464ae8510aac9546d5e7704e31ce177451386455588ac9b06305d000000000000000000000000000000"},"type":"MakerPaymentSent"},"timestamp":1563428512925},{"event":{"data":{"tx_hash":"ee8b904efdee0d3bf0215d14a236489cde0b0efa92f7fa49faaa5fd97ed38ac0","tx_hex":"0400008085202f89013541cc4503faa406296788c6710ba10fed9863853d2ec38d77d36d10c2bef532010000006b483045022100a32e290d3a047ad75a512f9fd581c561c5153aa1b6be2b36915a9dd452cd0d4102204d1838b3cd15698ab424d15651d50983f0196e59b0b34abaad9cb792c97b527a012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffff0200e1f5050000000017a91424fc6f967eaa2751adbeb42a97c3497fbd9ddcce878e681ca6010000001976a91405aab5342166f8594baf17a7d9bef5d56744332788acbf06305d000000000000000000000000000000"},"type":"TakerPaymentReceived"},"timestamp":1563428664418},{"event":{"type":"TakerPaymentWaitConfirmStarted"},"timestamp":1563428664420},{"event":{"type":"TakerPaymentValidatedAndConfirmed"},"timestamp":1563428664824},{"event":{"data":{"tx_hash":"8b48d7452a2a1c6b1128aa83ab946e5a624037c5327b527b18c3dcadb404f139","tx_hex":"0400008085202f8901c08ad37ed95faafa49faf792fa0e0bde9c4836a2145d21f03b0deefd4e908bee00000000d747304402206ac1f2b5b856b86585b4d2147309e3a7ef9dd4c35ffd85a49c409a4acd11602902204be03e2114888fae460eaf99675bae0c834ff80be8531a5bd30ee14baf0a52e30120e1c9bd12a83f810813dc078ac398069b63d56bf1e94657def995c43cd1975302004c6b6304c224305db1752102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ac6782012088a9143501575fb9a12a689bb94adad33cc78c13b0688c882102631dcf1d4b1b693aa8c2751afc68e4794b1e5996566cfc701a663f8b7bbbe640ac68ffffffff0118ddf505000000001976a91464ae8510aac9546d5e7704e31ce177451386455588ac28f92f5d000000000000000000000000000000"},"type":"TakerPaymentSpent"},"timestamp":1563428666150},{"event":{"type":"Finished"},"timestamp":1563428666152}],"my_info":{"my_amount":"1","my_coin":"BEER","other_amount":"1","other_coin":"ETOMIC","started_at":1563428426},"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"type":"Maker","uuid":"983ce732-62a8-4a44-b4ac-7e4271adc977"}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2626,7 +2626,7 @@ mod maker_swap_tests { let ctx = mm_ctx_with_iguana(PASSPHRASE); // return error if maker payment was refunded - let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"9.38455187130897","maker_coin":"VRSC","maker_coin_start_block":604407,"maker_payment_confirmations":1,"maker_payment_lock":1564317372,"my_persistent_pub":"03c2e08e48e6541b3265ccd430c5ecec7efc7d0d9fc4e310a9b052f9642673fb0a","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1564301772,"taker":"39c4bcdb1e6bbb29a3b131c2b82eba2552f4f8a804021b2064114ab857f00848","taker_amount":"0.999999999999999880468812552729","taker_coin":"KMD","taker_coin_start_block":1462209,"taker_payment_confirmations":1,"uuid":"8f5b267a-efa8-49d6-a92d-ec0523cca891"},"type":"Started"},"timestamp":1564301773193},{"event":{"data":{"taker_payment_locktime":1564309572,"taker_pubkey":"0339c4bcdb1e6bbb29a3b131c2b82eba2552f4f8a804021b2064114ab857f00848"},"type":"Negotiated"},"timestamp":1564301813664},{"event":{"data":{"tx_hash":"cf54a5f5dfdf2eb404855eaba6a05b41f893a20327d43770c0138bb9ed2cf9eb","tx_hex":"0400008085202f89018f03a4d46831ec541279d01998be6092a98ee0f103b69ab84697cdc3eea7e93c000000006a473044022046eb76ecf610832ef063a6d210b5d07bc90fd0f3b68550fd2945ce86b317252a02202d3438d2e83df49f1c8ab741553af65a0d97e6edccbb6c4d0c769b05426c637001210339c4bcdb1e6bbb29a3b131c2b82eba2552f4f8a804021b2064114ab857f00848ffffffff0276c40100000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88acddf7bd54000000001976a9144df806990ae0197402aeaa6d9b1ec60078d9eadf88ac01573d5d000000000000000000000000000000"},"type":"TakerFeeValidated"},"timestamp":1564301864738},{"event":{"data":{"tx_hash":"2252c9929707995aff6dbb03d23b7e7eb786611d26b6ae748ca13007e71d1de6","tx_hex":"0400008085202f8901f63aed15c53b794df1a9446755f452e9fd9db250e1f608636f6172b7d795358c010000006b483045022100b5adb583fbb4b1a628b9c58ec292bb7b1319bb881c2cf018af6fe33b7a182854022020d89a2d6cbf15a117e2e1122046941f95466af7507883c4fa05955f0dfb81f2012103c2e08e48e6541b3265ccd430c5ecec7efc7d0d9fc4e310a9b052f9642673fb0affffffff0293b0ef370000000017a914ca41def369fc07d8aea10ba26cf3e64a12470d4087163149f61c0000001976a914f4f89313803d610fa472a5849d2389ca6df3b90088ac285a3d5d000000000000000000000000000000"},"type":"MakerPaymentSent"},"timestamp":1564301867675},{"event":{"data":{"error":"timeout (2690.6 > 2690.0)"},"type":"TakerPaymentValidateFailed"},"timestamp":1564304558269},{"event":{"data":{"tx_hash":"96d0b50bc2371ab88052bc4d656f1b91b3e3e64eba650eac28ebce9387d234cb","tx_hex":"0400008085202f8901e61d1de70730a18c74aeb6261d6186b77e7e3bd203bb6dff5a99079792c9522200000000b647304402207d36206295eee6c936d0204552cc5a001d4de4bbc0c5ae1c6218cf8548b4f08b02204c2a6470e06a6caf407ea8f2704fdc1b1dee39f89d145f8c0460130cb1875b2b01514c6b6304bc963d5db1752103c2e08e48e6541b3265ccd430c5ecec7efc7d0d9fc4e310a9b052f9642673fb0aac6782012088a9145f5598259da7c0c0beffcc3e9da35e553bac727388210339c4bcdb1e6bbb29a3b131c2b82eba2552f4f8a804021b2064114ab857f00848ac68feffffff01abacef37000000001976a914f4f89313803d610fa472a5849d2389ca6df3b90088ac26973d5d000000000000000000000000000000"},"type":"MakerPaymentRefunded"},"timestamp":1564321080407},{"event":{"type":"Finished"},"timestamp":1564321080409}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"8f5b267a-efa8-49d6-a92d-ec0523cca891"}"#; + let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"9.38455187130897","maker_coin":"VRSC","maker_coin_start_block":604407,"maker_payment_confirmations":1,"maker_payment_lock":1564317372,"my_persistent_pub":"03c2e08e48e6541b3265ccd430c5ecec7efc7d0d9fc4e310a9b052f9642673fb0a","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1564301772,"taker_pubkey":"39c4bcdb1e6bbb29a3b131c2b82eba2552f4f8a804021b2064114ab857f00848","taker_amount":"0.999999999999999880468812552729","taker_coin":"KMD","taker_coin_start_block":1462209,"taker_payment_confirmations":1,"uuid":"8f5b267a-efa8-49d6-a92d-ec0523cca891"},"type":"Started"},"timestamp":1564301773193},{"event":{"data":{"taker_payment_locktime":1564309572,"taker_pubkey":"0339c4bcdb1e6bbb29a3b131c2b82eba2552f4f8a804021b2064114ab857f00848"},"type":"Negotiated"},"timestamp":1564301813664},{"event":{"data":{"tx_hash":"cf54a5f5dfdf2eb404855eaba6a05b41f893a20327d43770c0138bb9ed2cf9eb","tx_hex":"0400008085202f89018f03a4d46831ec541279d01998be6092a98ee0f103b69ab84697cdc3eea7e93c000000006a473044022046eb76ecf610832ef063a6d210b5d07bc90fd0f3b68550fd2945ce86b317252a02202d3438d2e83df49f1c8ab741553af65a0d97e6edccbb6c4d0c769b05426c637001210339c4bcdb1e6bbb29a3b131c2b82eba2552f4f8a804021b2064114ab857f00848ffffffff0276c40100000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88acddf7bd54000000001976a9144df806990ae0197402aeaa6d9b1ec60078d9eadf88ac01573d5d000000000000000000000000000000"},"type":"TakerFeeValidated"},"timestamp":1564301864738},{"event":{"data":{"tx_hash":"2252c9929707995aff6dbb03d23b7e7eb786611d26b6ae748ca13007e71d1de6","tx_hex":"0400008085202f8901f63aed15c53b794df1a9446755f452e9fd9db250e1f608636f6172b7d795358c010000006b483045022100b5adb583fbb4b1a628b9c58ec292bb7b1319bb881c2cf018af6fe33b7a182854022020d89a2d6cbf15a117e2e1122046941f95466af7507883c4fa05955f0dfb81f2012103c2e08e48e6541b3265ccd430c5ecec7efc7d0d9fc4e310a9b052f9642673fb0affffffff0293b0ef370000000017a914ca41def369fc07d8aea10ba26cf3e64a12470d4087163149f61c0000001976a914f4f89313803d610fa472a5849d2389ca6df3b90088ac285a3d5d000000000000000000000000000000"},"type":"MakerPaymentSent"},"timestamp":1564301867675},{"event":{"data":{"error":"timeout (2690.6 > 2690.0)"},"type":"TakerPaymentValidateFailed"},"timestamp":1564304558269},{"event":{"data":{"tx_hash":"96d0b50bc2371ab88052bc4d656f1b91b3e3e64eba650eac28ebce9387d234cb","tx_hex":"0400008085202f8901e61d1de70730a18c74aeb6261d6186b77e7e3bd203bb6dff5a99079792c9522200000000b647304402207d36206295eee6c936d0204552cc5a001d4de4bbc0c5ae1c6218cf8548b4f08b02204c2a6470e06a6caf407ea8f2704fdc1b1dee39f89d145f8c0460130cb1875b2b01514c6b6304bc963d5db1752103c2e08e48e6541b3265ccd430c5ecec7efc7d0d9fc4e310a9b052f9642673fb0aac6782012088a9145f5598259da7c0c0beffcc3e9da35e553bac727388210339c4bcdb1e6bbb29a3b131c2b82eba2552f4f8a804021b2064114ab857f00848ac68feffffff01abacef37000000001976a914f4f89313803d610fa472a5849d2389ca6df3b90088ac26973d5d000000000000000000000000000000"},"type":"MakerPaymentRefunded"},"timestamp":1564321080407},{"event":{"type":"Finished"},"timestamp":1564321080409}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"8f5b267a-efa8-49d6-a92d-ec0523cca891"}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2644,7 +2644,7 @@ mod maker_swap_tests { // The swap ends up with TakerPaymentSpendConfirmFailed error because the TakerPaymentSpend transaction was in mempool long time and finally not mined. // sent, need to find it and refund, prevent refund if payment is not spendable due to locktime restrictions - let maker_saved_json = r#"{"uuid":"7f95db1d-2ea5-4cce-b056-400e8b288042","events":[{"timestamp":1607887364672,"event":{"type":"Started","data":{"taker_coin":"KMD","maker_coin":"EMC2","taker":"ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900d","secret":"0000000000000000000000000000000000000000000000000000000000000000","secret_hash":"4a40a42a7d7192e5cbeaa3871f734612acfeaf76","my_persistent_pub":"03005e349c71a17334a3d7b712ebeb593c692e2401e611bbd829b6948c3acc15e5","lock_duration":31200,"maker_amount":"24.69126200952912480678056188200573124484152642245967528226624133800833910867311611640128371388479323","taker_amount":"3.094308955034189920785740015052958239603540091262646506373605364479205057098914911707408875024042288","maker_payment_confirmations":1,"maker_payment_requires_nota":true,"taker_payment_confirmations":2,"taker_payment_requires_nota":true,"maker_payment_lock":1607949764,"uuid":"7f95db1d-2ea5-4cce-b056-400e8b288042","started_at":1607887364,"maker_coin_start_block":3526364,"taker_coin_start_block":2178701}}},{"timestamp":1607887366684,"event":{"type":"Negotiated","data":{"taker_payment_locktime":1607918567,"taker_pubkey":"03ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900d"}}},{"timestamp":1607887367745,"event":{"type":"TakerFeeValidated","data":{"tx_hex":"0400008085202f8902f02f23931783009e01b7f250234eb7b3a96bd7e7e16dd61f21988bbc7600b6f7020000006b483045022100d4610ef1f147417476877aa09b1f110f7e6773355d6dc8cae7af429707f9da4d02203f5d1890da9d6efffee55869761f9353dbd3bcafb2a560f4564eba658ae2807b012103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dffffffffb7599816287b72f939b8e6b59fe4706d7b6826e5f6c04db18e3689cb76e846ce000000006a473044022021a486a9920ff8b3d892c00c10abaf58b4509fe9d3a6f8320e198e312e220db402203fab57d7ccfda1eded606ab3de6a32f626b5904ecf9f41e4a7a4800376952d67012103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dffffffff020e780500000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac5bdb0c00000000001976a914851bf1c11fb48beecc0a0e50982b9d43357743e688ac0c62d65f000000000000000000000000000000","tx_hash":"8a7c0ddbc2a0e94e1f58c920780563eb71266d932fe9435cf66def905db91efb"}}},{"timestamp":1607887367887,"event":{"type":"MakerPaymentSent","data":{"tx_hex":"010000000118c570eab3ec0f07a33640aff42a7b3565f4fa72561473b9f55d23b7a5360351090000006a4730440220047c5a917e7ac72b55357c657581ebf60b7281466be3dd00a92f68b85e03ae2e02204b07643faf3ae88a1775794c5afc406be4aaec87d0a98fb49a2125e02b9ed21d012103005e349c71a17334a3d7b712ebeb593c692e2401e611bbd829b6948c3acc15e5ffffffff0338e02b930000000017a914e0ddc80814f50249d097c3242e355a5d6fae462b870000000000000000166a144a40a42a7d7192e5cbeaa3871f734612acfeaf76284bcb93000000001976a914b86cb58669cc65e2f880e1df5d6e11c3dcb7230988ac076ad65f","tx_hash":"aa06c1647cb0418ed6ca7666dc517bfe8de92bc163b6765f9370bb316af1c1ff"}}},{"timestamp":1607887416097,"event":{"type":"TakerPaymentReceived","data":{"tx_hex":"0400008085202f8903fb1eb95d90ef6df65c43e92f936d2671eb63057820c9581f4ee9a0c2db0d7c8a010000006b483045022100d55c02f8536f0c1e5f10833b901adc3d2a77d7f0701371a29dcc155426b8f280022028f540607c349f9a73489801c45445f594f2552d165b2bd004af00c0297ce494012103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dffffffffe83e674cb46d0862cbc3ade7e363c5eb3a73a9ad977fff60544093efc6a2682b000000006a47304402200a324d95e7e7193a479aed48c608068f6d81ee8d7dd9b13735427e18f53bb25b0220606e075b56c675f10f6cb3332e4a28011d88428f54e3f09b016deec16c1ac41b012103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dffffffff987b47469a16aac4adaf0a47d8fbf813f8b20cf28eef82e14b74d732a263584e000000006a473044022062badf692bea3f13b5adb5cd66ff87f8f3224624762a75caaffa6fd856a0cfa602204d2477941cb781bba824d20e562f2d52a85c6c1103dccf28ddbfcadead87925b012103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dffffffff036f8a71120000000017a91415d9f7c7ad4e88b91d92c1480902fedfea92b981870000000000000000166a144a40a42a7d7192e5cbeaa3871f734612acfeaf76967e1500000000001976a914851bf1c11fb48beecc0a0e50982b9d43357743e688ac3c62d65f000000000000000000000000000000","tx_hash":"3e01651b399901192067e24f60371f640e840d240956676a416d26dec6f051f4"}}},{"timestamp":1607887416115,"event":{"type":"TakerPaymentWaitConfirmStarted"}},{"timestamp":1607901459795,"event":{"type":"TakerPaymentValidatedAndConfirmed"}},{"timestamp":1607901459843,"event":{"type":"TakerPaymentSpent","data":{"tx_hex":"0400008085202f8901f451f0c6de266d416a675609240d840e641f37604fe26720190199391b65013e00000000d8483045022100f8a8dade217e2595d3aaa287adc6cbf895b3d9c13f28aa707873943c1412c36d022053efe8c35fefbab2b298e0e4e8b93ad05b1d98d872b656616520dee15d79ea6801202e3d520b3d396cd2fc4aaac03257d13b2c82772ffe4479b7e0841987f8f673a7004c6b6304e7e3d65fb1752103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dac6782012088a9144a40a42a7d7192e5cbeaa3871f734612acfeaf76882103005e349c71a17334a3d7b712ebeb593c692e2401e611bbd829b6948c3acc15e5ac68ffffffff0187867112000000001976a914b86cb58669cc65e2f880e1df5d6e11c3dcb7230988ac1599d65f000000000000000000000000000000","tx_hash":"21cb40785f3e768c38c502be378448f33634430277360dc1c20fcdc238ebf806"}}},{"timestamp":1607901459850,"event":{"type":"TakerPaymentSpendConfirmStarted"}},{"timestamp":1607957899314,"event":{"type":"TakerPaymentSpendConfirmFailed","data":{"error":"maker_swap:714] !wait for taker payment spend confirmations: rpc_clients:123] Waited too long until 1607953464 for transaction Transaction { version: 4, n_time: None, overwintered: true, version_group_id: 2301567109, inputs: [TransactionInput { previous_output: OutPoint { hash: f451f0c6de266d416a675609240d840e641f37604fe26720190199391b65013e, index: 0 }, script_sig: 483045022100f8a8dade217e2595d3aaa287adc6cbf895b3d9c13f28aa707873943c1412c36d022053efe8c35fefbab2b298e0e4e8b93ad05b1d98d872b656616520dee15d79ea6801202e3d520b3d396cd2fc4aaac03257d13b2c82772ffe4479b7e0841987f8f673a7004c6b6304e7e3d65fb1752103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dac6782012088a9144a40a42a7d7192e5cbeaa3871f734612acfeaf76882103005e349c71a17334a3d7b712ebeb593c692e2401e611bbd829b6948c3acc15e5ac68, sequence: 4294967295, script_witness: [] }], outputs: [TransactionOutput { value: 309429895, script_pubkey: 76a914b86cb58669cc65e2f880e1df5d6e11c3dcb7230988ac }], lock_time: 1607899413, expiry_height: 0, shielded_spends: [], shielded_outputs: [], join_splits: [], value_balance: 0, join_split_pubkey: 0000000000000000000000000000000000000000000000000000000000000000, join_split_sig: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, binding_sig: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, zcash: true, str_d_zeel: None } to be confirmed 1 times"}}},{"timestamp":1607957899319,"event":{"type":"MakerPaymentWaitRefundStarted","data":{"wait_until":1607953464}}},{"timestamp":1607957899367,"event":{"type":"MakerPaymentRefundFailed","data":{"error":"maker_swap:746] !maker_coin.send_maker_refunds_payment: utxo_common:791] rpc_clients:1440] JsonRpcError { client_info: \"coin: EMC2\", request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"8\", method: \"blockchain.transaction.broadcast\", params: [String(\"0100000001ffc1f16a31bb70935f76b663c12be98dfe7b51dc6676cad68e41b07c64c106aa00000000b6473044022029d1626dde413ecb7af09c1609a0f1f3791539aef1a5f972787db39c6b8178f302202052b6c37f2334cbee21dc8c6ceeb368cc0bb69ab254da3a8b48a27d4542d84b01514c6b6304c45dd75fb1752103005e349c71a17334a3d7b712ebeb593c692e2401e611bbd829b6948c3acc15e5ac6782012088a9144a40a42a7d7192e5cbeaa3871f734612acfeaf76882103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dac68feffffff0198592a93000000001976a914b86cb58669cc65e2f880e1df5d6e11c3dcb7230988ac7b6fd75f\")] }, error: Response(electrum2.cipig.net:10062, Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\n18: bad-txns-inputs-spent\\n[0100000001ffc1f16a31bb70935f76b663c12be98dfe7b51dc6676cad68e41b07c64c106aa00000000b6473044022029d1626dde413ecb7af09c1609a0f1f3791539aef1a5f972787db39c6b8178f302202052b6c37f2334cbee21dc8c6ceeb368cc0bb69ab254da3a8b48a27d4542d84b01514c6b6304c45dd75fb1752103005e349c71a17334a3d7b712ebeb593c692e2401e611bbd829b6948c3acc15e5ac6782012088a9144a40a42a7d7192e5cbeaa3871f734612acfeaf76882103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dac68feffffff0198592a93000000001976a914b86cb58669cc65e2f880e1df5d6e11c3dcb7230988ac7b6fd75f]\")})) }"}}},{"timestamp":1607957899372,"event":{"type":"Finished"}}],"maker_amount":"24.69126200952912480678056188200573124484152642245967528226624133800833910867311611640128371388479323","maker_coin":"EMC2","taker_amount":"3.094308955034189920785740015052958239603540091262646506373605364479205057098914911707408875024042288","taker_coin":"KMD","gui":"AtomicDex Desktop 0.3.1-beta","mm_version":"2.1.2793_mm2.1_19701cc87_Windows_NT_Release","success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","MakerPaymentWaitConfirmFailed","TakerPaymentValidateFailed","TakerPaymentWaitConfirmFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentWaitRefundStarted","MakerPaymentRefunded","MakerPaymentRefundFailed"]}"#; + let maker_saved_json = r#"{"uuid":"7f95db1d-2ea5-4cce-b056-400e8b288042","events":[{"timestamp":1607887364672,"event":{"type":"Started","data":{"taker_coin":"KMD","maker_coin":"EMC2","taker_pubkey":"ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900d","secret":"0000000000000000000000000000000000000000000000000000000000000000","secret_hash":"4a40a42a7d7192e5cbeaa3871f734612acfeaf76","my_persistent_pub":"03005e349c71a17334a3d7b712ebeb593c692e2401e611bbd829b6948c3acc15e5","lock_duration":31200,"maker_amount":"24.69126200952912480678056188200573124484152642245967528226624133800833910867311611640128371388479323","taker_amount":"3.094308955034189920785740015052958239603540091262646506373605364479205057098914911707408875024042288","maker_payment_confirmations":1,"maker_payment_requires_nota":true,"taker_payment_confirmations":2,"taker_payment_requires_nota":true,"maker_payment_lock":1607949764,"uuid":"7f95db1d-2ea5-4cce-b056-400e8b288042","started_at":1607887364,"maker_coin_start_block":3526364,"taker_coin_start_block":2178701}}},{"timestamp":1607887366684,"event":{"type":"Negotiated","data":{"taker_payment_locktime":1607918567,"taker_pubkey":"03ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900d"}}},{"timestamp":1607887367745,"event":{"type":"TakerFeeValidated","data":{"tx_hex":"0400008085202f8902f02f23931783009e01b7f250234eb7b3a96bd7e7e16dd61f21988bbc7600b6f7020000006b483045022100d4610ef1f147417476877aa09b1f110f7e6773355d6dc8cae7af429707f9da4d02203f5d1890da9d6efffee55869761f9353dbd3bcafb2a560f4564eba658ae2807b012103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dffffffffb7599816287b72f939b8e6b59fe4706d7b6826e5f6c04db18e3689cb76e846ce000000006a473044022021a486a9920ff8b3d892c00c10abaf58b4509fe9d3a6f8320e198e312e220db402203fab57d7ccfda1eded606ab3de6a32f626b5904ecf9f41e4a7a4800376952d67012103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dffffffff020e780500000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac5bdb0c00000000001976a914851bf1c11fb48beecc0a0e50982b9d43357743e688ac0c62d65f000000000000000000000000000000","tx_hash":"8a7c0ddbc2a0e94e1f58c920780563eb71266d932fe9435cf66def905db91efb"}}},{"timestamp":1607887367887,"event":{"type":"MakerPaymentSent","data":{"tx_hex":"010000000118c570eab3ec0f07a33640aff42a7b3565f4fa72561473b9f55d23b7a5360351090000006a4730440220047c5a917e7ac72b55357c657581ebf60b7281466be3dd00a92f68b85e03ae2e02204b07643faf3ae88a1775794c5afc406be4aaec87d0a98fb49a2125e02b9ed21d012103005e349c71a17334a3d7b712ebeb593c692e2401e611bbd829b6948c3acc15e5ffffffff0338e02b930000000017a914e0ddc80814f50249d097c3242e355a5d6fae462b870000000000000000166a144a40a42a7d7192e5cbeaa3871f734612acfeaf76284bcb93000000001976a914b86cb58669cc65e2f880e1df5d6e11c3dcb7230988ac076ad65f","tx_hash":"aa06c1647cb0418ed6ca7666dc517bfe8de92bc163b6765f9370bb316af1c1ff"}}},{"timestamp":1607887416097,"event":{"type":"TakerPaymentReceived","data":{"tx_hex":"0400008085202f8903fb1eb95d90ef6df65c43e92f936d2671eb63057820c9581f4ee9a0c2db0d7c8a010000006b483045022100d55c02f8536f0c1e5f10833b901adc3d2a77d7f0701371a29dcc155426b8f280022028f540607c349f9a73489801c45445f594f2552d165b2bd004af00c0297ce494012103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dffffffffe83e674cb46d0862cbc3ade7e363c5eb3a73a9ad977fff60544093efc6a2682b000000006a47304402200a324d95e7e7193a479aed48c608068f6d81ee8d7dd9b13735427e18f53bb25b0220606e075b56c675f10f6cb3332e4a28011d88428f54e3f09b016deec16c1ac41b012103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dffffffff987b47469a16aac4adaf0a47d8fbf813f8b20cf28eef82e14b74d732a263584e000000006a473044022062badf692bea3f13b5adb5cd66ff87f8f3224624762a75caaffa6fd856a0cfa602204d2477941cb781bba824d20e562f2d52a85c6c1103dccf28ddbfcadead87925b012103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dffffffff036f8a71120000000017a91415d9f7c7ad4e88b91d92c1480902fedfea92b981870000000000000000166a144a40a42a7d7192e5cbeaa3871f734612acfeaf76967e1500000000001976a914851bf1c11fb48beecc0a0e50982b9d43357743e688ac3c62d65f000000000000000000000000000000","tx_hash":"3e01651b399901192067e24f60371f640e840d240956676a416d26dec6f051f4"}}},{"timestamp":1607887416115,"event":{"type":"TakerPaymentWaitConfirmStarted"}},{"timestamp":1607901459795,"event":{"type":"TakerPaymentValidatedAndConfirmed"}},{"timestamp":1607901459843,"event":{"type":"TakerPaymentSpent","data":{"tx_hex":"0400008085202f8901f451f0c6de266d416a675609240d840e641f37604fe26720190199391b65013e00000000d8483045022100f8a8dade217e2595d3aaa287adc6cbf895b3d9c13f28aa707873943c1412c36d022053efe8c35fefbab2b298e0e4e8b93ad05b1d98d872b656616520dee15d79ea6801202e3d520b3d396cd2fc4aaac03257d13b2c82772ffe4479b7e0841987f8f673a7004c6b6304e7e3d65fb1752103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dac6782012088a9144a40a42a7d7192e5cbeaa3871f734612acfeaf76882103005e349c71a17334a3d7b712ebeb593c692e2401e611bbd829b6948c3acc15e5ac68ffffffff0187867112000000001976a914b86cb58669cc65e2f880e1df5d6e11c3dcb7230988ac1599d65f000000000000000000000000000000","tx_hash":"21cb40785f3e768c38c502be378448f33634430277360dc1c20fcdc238ebf806"}}},{"timestamp":1607901459850,"event":{"type":"TakerPaymentSpendConfirmStarted"}},{"timestamp":1607957899314,"event":{"type":"TakerPaymentSpendConfirmFailed","data":{"error":"maker_swap:714] !wait for taker payment spend confirmations: rpc_clients:123] Waited too long until 1607953464 for transaction Transaction { version: 4, n_time: None, overwintered: true, version_group_id: 2301567109, inputs: [TransactionInput { previous_output: OutPoint { hash: f451f0c6de266d416a675609240d840e641f37604fe26720190199391b65013e, index: 0 }, script_sig: 483045022100f8a8dade217e2595d3aaa287adc6cbf895b3d9c13f28aa707873943c1412c36d022053efe8c35fefbab2b298e0e4e8b93ad05b1d98d872b656616520dee15d79ea6801202e3d520b3d396cd2fc4aaac03257d13b2c82772ffe4479b7e0841987f8f673a7004c6b6304e7e3d65fb1752103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dac6782012088a9144a40a42a7d7192e5cbeaa3871f734612acfeaf76882103005e349c71a17334a3d7b712ebeb593c692e2401e611bbd829b6948c3acc15e5ac68, sequence: 4294967295, script_witness: [] }], outputs: [TransactionOutput { value: 309429895, script_pubkey: 76a914b86cb58669cc65e2f880e1df5d6e11c3dcb7230988ac }], lock_time: 1607899413, expiry_height: 0, shielded_spends: [], shielded_outputs: [], join_splits: [], value_balance: 0, join_split_pubkey: 0000000000000000000000000000000000000000000000000000000000000000, join_split_sig: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, binding_sig: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, zcash: true, str_d_zeel: None } to be confirmed 1 times"}}},{"timestamp":1607957899319,"event":{"type":"MakerPaymentWaitRefundStarted","data":{"wait_until":1607953464}}},{"timestamp":1607957899367,"event":{"type":"MakerPaymentRefundFailed","data":{"error":"maker_swap:746] !maker_coin.send_maker_refunds_payment: utxo_common:791] rpc_clients:1440] JsonRpcError { client_info: \"coin: EMC2\", request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"8\", method: \"blockchain.transaction.broadcast\", params: [String(\"0100000001ffc1f16a31bb70935f76b663c12be98dfe7b51dc6676cad68e41b07c64c106aa00000000b6473044022029d1626dde413ecb7af09c1609a0f1f3791539aef1a5f972787db39c6b8178f302202052b6c37f2334cbee21dc8c6ceeb368cc0bb69ab254da3a8b48a27d4542d84b01514c6b6304c45dd75fb1752103005e349c71a17334a3d7b712ebeb593c692e2401e611bbd829b6948c3acc15e5ac6782012088a9144a40a42a7d7192e5cbeaa3871f734612acfeaf76882103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dac68feffffff0198592a93000000001976a914b86cb58669cc65e2f880e1df5d6e11c3dcb7230988ac7b6fd75f\")] }, error: Response(electrum2.cipig.net:10062, Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\n18: bad-txns-inputs-spent\\n[0100000001ffc1f16a31bb70935f76b663c12be98dfe7b51dc6676cad68e41b07c64c106aa00000000b6473044022029d1626dde413ecb7af09c1609a0f1f3791539aef1a5f972787db39c6b8178f302202052b6c37f2334cbee21dc8c6ceeb368cc0bb69ab254da3a8b48a27d4542d84b01514c6b6304c45dd75fb1752103005e349c71a17334a3d7b712ebeb593c692e2401e611bbd829b6948c3acc15e5ac6782012088a9144a40a42a7d7192e5cbeaa3871f734612acfeaf76882103ae3cc37d2a7cc9077fb5b1baa962d1539e1ffe5fb318c99dcba43059ed97900dac68feffffff0198592a93000000001976a914b86cb58669cc65e2f880e1df5d6e11c3dcb7230988ac7b6fd75f]\")})) }"}}},{"timestamp":1607957899372,"event":{"type":"Finished"}}],"maker_amount":"24.69126200952912480678056188200573124484152642245967528226624133800833910867311611640128371388479323","maker_coin":"EMC2","taker_amount":"3.094308955034189920785740015052958239603540091262646506373605364479205057098914911707408875024042288","taker_coin":"KMD","gui":"AtomicDex Desktop 0.3.1-beta","mm_version":"2.1.2793_mm2.1_19701cc87_Windows_NT_Release","success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","MakerPaymentWaitConfirmFailed","TakerPaymentValidateFailed","TakerPaymentWaitConfirmFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentWaitRefundStarted","MakerPaymentRefunded","MakerPaymentRefundFailed"]}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2688,7 +2688,7 @@ mod maker_swap_tests { fn test_recover_funds_should_not_refund_on_the_successful_swap() { let ctx = mm_ctx_with_iguana(PASSPHRASE); - let maker_saved_json = r#"{"type":"Maker","uuid":"12456076-58dd-4772-9d88-167d5fa103d2","my_order_uuid":"5ae22bf5-09cf-4828-87a7-c3aa7339ba10","events":[{"timestamp":1631695364907,"event":{"type":"Started","data":{"taker_coin":"KMD","maker_coin":"TKL","taker":"2b20b92e19e9e11b07f8309cebb1fcd1cce1606be8ab0de2c1b91f979c937996","secret":"0000000000000000000000000000000000000000000000000000000000000000","secret_hash":"65a10bd6dbdf6ebf7ec1f3bfb7451cde0582f9cb","my_persistent_pub":"03789c206e830f9e0083571f79e80eb58601d37bde8abb0c380d81127613060b74","lock_duration":31200,"maker_amount":"500","taker_amount":"140.7","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":2,"taker_payment_requires_nota":true,"maker_payment_lock":1631757764,"uuid":"12456076-58dd-4772-9d88-167d5fa103d2","started_at":1631695364,"maker_coin_start_block":61066,"taker_coin_start_block":2569118,"maker_payment_trade_fee":{"coin":"TKL","amount":"0.00001","paid_from_trading_vol":false},"taker_payment_spend_trade_fee":{"coin":"KMD","amount":"0.00001","paid_from_trading_vol":true}}}},{"timestamp":1631695366908,"event":{"type":"Negotiated","data":{"taker_payment_locktime":1631726564,"taker_pubkey":"032b20b92e19e9e11b07f8309cebb1fcd1cce1606be8ab0de2c1b91f979c937996","maker_coin_swap_contract_addr":null,"taker_coin_swap_contract_addr":null}}},{"timestamp":1631695367917,"event":{"type":"TakerFeeValidated","data":{"tx_hex":"0400008085202f8901562fdec6bbdac4c5c3212394e1fd439d3647ff04bdd79d51b9bbf697c9a925e7000000006a473044022074c71fcdc12654e3aa01c780b10d6c84b1d6ba28f0db476010002a1ed00e75cf022018e115923b1c1b5e872893fd6a1f270c0e8e3e84a869181c349aa78553e1423b0121032b20b92e19e9e11b07f8309cebb1fcd1cce1606be8ab0de2c1b91f979c937996ffffffff0251adf800000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac72731e4c080000001976a914dc1bea5367613f189da622e9bc5bdb2d61667e5b88ac08aa4161000000000000000000000000000000","tx_hash":"f315170aba20ff4d432b8a2d0a8fa0211444c8d27b56fc0d4fc2058e9f3c6e08"}}},{"timestamp":1631695368024,"event":{"type":"MakerPaymentSent","data":{"tx_hex":"0400008085202f8901bc488c4e0f9a3fe9d7f5dbcc17f61e7711a75c7ed277843988f3be4d236b9a02020000006a473044022027ac57a4a34b0d8561afc1ad63f9e1fb271d58577a80f26ba519017d65d882f802200b5617f32427b86b423de6740cd134fdb8b86c511943e778c65781573224cf4a012103789c206e830f9e0083571f79e80eb58601d37bde8abb0c380d81127613060b74ffffffff0300743ba40b00000017a914022be92579878d04c80d128cdfdcba4ed29a9f9a870000000000000000166a1465a10bd6dbdf6ebf7ec1f3bfb7451cde0582f9cb6494f93503c801001976a914bde146a76acf122caf5e460d01ddaf3be714247e88ac07b24161000000000000000000000000000000","tx_hash":"8693723462ef5ee6c3014230fd4a4aefe6bcd0eaeb727e1e5b33fe1105e9f8ad"}}},{"timestamp":1631696319310,"event":{"type":"TakerPaymentReceived","data":{"tx_hex":"0400008085202f8901086e3c9f8e05c24f0dfc567bd2c8441421a08f0a2d8a2b434dff20ba0a1715f3010000006a47304402207190691940b4834394c2a9e08a32b775f1c62a47ab76737c96c08e2937173988022040229094d51acb3d948413c349e36795b888a9b425b29ed7a96ed8eb97407d050121032b20b92e19e9e11b07f8309cebb1fcd1cce1606be8ab0de2c1b91f979c937996ffffffff038029a3460300000017a9146d0db00d111fcd0b83505cb805a3255cbaa8c747870000000000000000166a1465a10bd6dbdf6ebf7ec1f3bfb7451cde0582f9cb0a467b05050000001976a914dc1bea5367613f189da622e9bc5bdb2d61667e5b88acbfad4161000000000000000000000000000000","tx_hash":"a9b97c4c12c8eb637a7016459de644eae9e307efd2d051601d7d9f615fd62461"}}},{"timestamp":1631696319310,"event":{"type":"TakerPaymentWaitConfirmStarted"}},{"timestamp":1631697459816,"event":{"type":"TakerPaymentValidatedAndConfirmed"}},{"timestamp":1631697459821,"event":{"type":"TakerPaymentSpent","data":{"tx_hex":"0400008085202f89016124d65f619f7d1d6051d0d2ef07e3e9ea44e69d4516707a63ebc8124c7cb9a900000000d84830450221008c50c144382346247d7052a32e12f4d839fa22c12064b199d589cc62ead00c99022017e88f543e181fd92ebf32e1313ca6fb12f93226fd294c808b0904601102424f012068e659c506d57d94369ca520158d641ea997b0db39fdafb1e59b07867ad4be9d004c6b6304e42b4261b17521032b20b92e19e9e11b07f8309cebb1fcd1cce1606be8ab0de2c1b91f979c937996ac6782012088a91465a10bd6dbdf6ebf7ec1f3bfb7451cde0582f9cb882103789c206e830f9e0083571f79e80eb58601d37bde8abb0c380d81127613060b74ac68ffffffff019825a346030000001976a914bde146a76acf122caf5e460d01ddaf3be714247e88ace42b4261000000000000000000000000000000","tx_hash":"8a6d65518d3a01f6f659f11e0667373052ebfc2e600f80c6592dec556bee4a39"}}},{"timestamp":1631697459822,"event":{"type":"TakerPaymentSpendConfirmStarted"}},{"timestamp":1631697489840,"event":{"type":"TakerPaymentSpendConfirmed"}},{"timestamp":1631697489841,"event":{"type":"Finished"}}],"maker_amount":"500","maker_coin":"TKL","taker_amount":"140.7","taker_coin":"KMD","gui":"TOKEL-IDO","mm_version":"41170748d","success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","MakerPaymentWaitConfirmFailed","TakerPaymentValidateFailed","TakerPaymentWaitConfirmFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentWaitRefundStarted","MakerPaymentRefunded","MakerPaymentRefundFailed"]}"#; + let maker_saved_json = r#"{"type":"Maker","uuid":"12456076-58dd-4772-9d88-167d5fa103d2","my_order_uuid":"5ae22bf5-09cf-4828-87a7-c3aa7339ba10","events":[{"timestamp":1631695364907,"event":{"type":"Started","data":{"taker_coin":"KMD","maker_coin":"TKL","taker_pubkey":"2b20b92e19e9e11b07f8309cebb1fcd1cce1606be8ab0de2c1b91f979c937996","secret":"0000000000000000000000000000000000000000000000000000000000000000","secret_hash":"65a10bd6dbdf6ebf7ec1f3bfb7451cde0582f9cb","my_persistent_pub":"03789c206e830f9e0083571f79e80eb58601d37bde8abb0c380d81127613060b74","lock_duration":31200,"maker_amount":"500","taker_amount":"140.7","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":2,"taker_payment_requires_nota":true,"maker_payment_lock":1631757764,"uuid":"12456076-58dd-4772-9d88-167d5fa103d2","started_at":1631695364,"maker_coin_start_block":61066,"taker_coin_start_block":2569118,"maker_payment_trade_fee":{"coin":"TKL","amount":"0.00001","paid_from_trading_vol":false},"taker_payment_spend_trade_fee":{"coin":"KMD","amount":"0.00001","paid_from_trading_vol":true}}}},{"timestamp":1631695366908,"event":{"type":"Negotiated","data":{"taker_payment_locktime":1631726564,"taker_pubkey":"032b20b92e19e9e11b07f8309cebb1fcd1cce1606be8ab0de2c1b91f979c937996","maker_coin_swap_contract_addr":null,"taker_coin_swap_contract_addr":null}}},{"timestamp":1631695367917,"event":{"type":"TakerFeeValidated","data":{"tx_hex":"0400008085202f8901562fdec6bbdac4c5c3212394e1fd439d3647ff04bdd79d51b9bbf697c9a925e7000000006a473044022074c71fcdc12654e3aa01c780b10d6c84b1d6ba28f0db476010002a1ed00e75cf022018e115923b1c1b5e872893fd6a1f270c0e8e3e84a869181c349aa78553e1423b0121032b20b92e19e9e11b07f8309cebb1fcd1cce1606be8ab0de2c1b91f979c937996ffffffff0251adf800000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac72731e4c080000001976a914dc1bea5367613f189da622e9bc5bdb2d61667e5b88ac08aa4161000000000000000000000000000000","tx_hash":"f315170aba20ff4d432b8a2d0a8fa0211444c8d27b56fc0d4fc2058e9f3c6e08"}}},{"timestamp":1631695368024,"event":{"type":"MakerPaymentSent","data":{"tx_hex":"0400008085202f8901bc488c4e0f9a3fe9d7f5dbcc17f61e7711a75c7ed277843988f3be4d236b9a02020000006a473044022027ac57a4a34b0d8561afc1ad63f9e1fb271d58577a80f26ba519017d65d882f802200b5617f32427b86b423de6740cd134fdb8b86c511943e778c65781573224cf4a012103789c206e830f9e0083571f79e80eb58601d37bde8abb0c380d81127613060b74ffffffff0300743ba40b00000017a914022be92579878d04c80d128cdfdcba4ed29a9f9a870000000000000000166a1465a10bd6dbdf6ebf7ec1f3bfb7451cde0582f9cb6494f93503c801001976a914bde146a76acf122caf5e460d01ddaf3be714247e88ac07b24161000000000000000000000000000000","tx_hash":"8693723462ef5ee6c3014230fd4a4aefe6bcd0eaeb727e1e5b33fe1105e9f8ad"}}},{"timestamp":1631696319310,"event":{"type":"TakerPaymentReceived","data":{"tx_hex":"0400008085202f8901086e3c9f8e05c24f0dfc567bd2c8441421a08f0a2d8a2b434dff20ba0a1715f3010000006a47304402207190691940b4834394c2a9e08a32b775f1c62a47ab76737c96c08e2937173988022040229094d51acb3d948413c349e36795b888a9b425b29ed7a96ed8eb97407d050121032b20b92e19e9e11b07f8309cebb1fcd1cce1606be8ab0de2c1b91f979c937996ffffffff038029a3460300000017a9146d0db00d111fcd0b83505cb805a3255cbaa8c747870000000000000000166a1465a10bd6dbdf6ebf7ec1f3bfb7451cde0582f9cb0a467b05050000001976a914dc1bea5367613f189da622e9bc5bdb2d61667e5b88acbfad4161000000000000000000000000000000","tx_hash":"a9b97c4c12c8eb637a7016459de644eae9e307efd2d051601d7d9f615fd62461"}}},{"timestamp":1631696319310,"event":{"type":"TakerPaymentWaitConfirmStarted"}},{"timestamp":1631697459816,"event":{"type":"TakerPaymentValidatedAndConfirmed"}},{"timestamp":1631697459821,"event":{"type":"TakerPaymentSpent","data":{"tx_hex":"0400008085202f89016124d65f619f7d1d6051d0d2ef07e3e9ea44e69d4516707a63ebc8124c7cb9a900000000d84830450221008c50c144382346247d7052a32e12f4d839fa22c12064b199d589cc62ead00c99022017e88f543e181fd92ebf32e1313ca6fb12f93226fd294c808b0904601102424f012068e659c506d57d94369ca520158d641ea997b0db39fdafb1e59b07867ad4be9d004c6b6304e42b4261b17521032b20b92e19e9e11b07f8309cebb1fcd1cce1606be8ab0de2c1b91f979c937996ac6782012088a91465a10bd6dbdf6ebf7ec1f3bfb7451cde0582f9cb882103789c206e830f9e0083571f79e80eb58601d37bde8abb0c380d81127613060b74ac68ffffffff019825a346030000001976a914bde146a76acf122caf5e460d01ddaf3be714247e88ace42b4261000000000000000000000000000000","tx_hash":"8a6d65518d3a01f6f659f11e0667373052ebfc2e600f80c6592dec556bee4a39"}}},{"timestamp":1631697459822,"event":{"type":"TakerPaymentSpendConfirmStarted"}},{"timestamp":1631697489840,"event":{"type":"TakerPaymentSpendConfirmed"}},{"timestamp":1631697489841,"event":{"type":"Finished"}}],"maker_amount":"500","maker_coin":"TKL","taker_amount":"140.7","taker_coin":"KMD","gui":"TOKEL-IDO","mm_version":"41170748d","success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","MakerPaymentWaitConfirmFailed","TakerPaymentValidateFailed","TakerPaymentWaitConfirmFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentWaitRefundStarted","MakerPaymentRefunded","MakerPaymentRefundFailed"]}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2730,7 +2730,7 @@ mod maker_swap_tests { let ctx = mm_ctx_with_iguana(PASSPHRASE); - let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563743939,"taker":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; + let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563743939,"taker_pubkey":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2749,7 +2749,7 @@ mod maker_swap_tests { let ctx = mm_ctx_with_iguana(PASSPHRASE); // swap file contains neither maker_coin_swap_contract_address nor taker_coin_swap_contract_address - let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563743939,"taker":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; + let maker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"0000000000000000000000000000000000000000000000000000000000000000","started_at":1563743939,"taker_pubkey":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2778,7 +2778,7 @@ mod maker_swap_tests { let ctx = mm_ctx_with_iguana(PASSPHRASE); // swap file contains only maker_coin_swap_contract_address - let maker_saved_json = r#"{"type":"Maker","uuid":"c52659d7-4e13-41f5-9c1a-30cc2f646033","events":[{"timestamp":1608541830095,"event":{"type":"Started","data":{"taker_coin":"JST","maker_coin":"ETH","taker":"031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3","secret":"dc45c1d22028970d8d30d1ddacbfc50eb92403b0d6076c94f2216c4c44512b41","secret_hash":"943e11f7c74e2d6493ef8ad01a06ef2ce9bd1fb3","my_persistent_pub":"03c6a78589e18b482aea046975e6d0acbdea7bf7dbf04d9d5bd67fda917815e3ed","lock_duration":7800,"maker_amount":"0.1","taker_amount":"0.1","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":1,"taker_payment_requires_nota":false,"maker_payment_lock":1608557429,"uuid":"c52659d7-4e13-41f5-9c1a-30cc2f646033","started_at":1608541829,"maker_coin_start_block":14353,"taker_coin_start_block":14353,"maker_coin_swap_contract_address":"eA6D65434A15377081495a9E7C5893543E7c32cB"}}},{"timestamp":1608541830399,"event":{"type":"Negotiated","data":{"taker_payment_locktime":1608549629,"taker_pubkey":"02031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3"}}},{"timestamp":1608541831810,"event":{"type":"TakerFeeValidated","data":{"tx_hex":"f8a7821fb58083033450942b294f029fde858b2c62184e8390591755521d8e80b844a9059cbb000000000000000000000000d8997941dd1346e9231118d5685d866294f59e5b0000000000000000000000000000000000000000000000000000750d557426e01ba06ddad2dfe6933b8d70d5739beb3005c8f367bc72eac4e5609b81c2f8e5843cd9a07fa695cc42f8c6b6a7b10f6ae9e4dca3e750e37f64a85b54dec736236790f05e","tx_hash":"b13c3428f70b46d8c1d7f5863af020a27c380a8ede0927554beabf234998bcc8"}}},{"timestamp":1608541832884,"event":{"type":"MakerPaymentSent","data":{"tx_hex":"f8ef82021980830249f094a09ad3cd7e96586ebd05a2607ee56b56fb2db8fd88016345785d8a0000b884152cf3af7c7ce37fac65bd995eae3d58ccdc367d79f3a10e6ca55f609e6dcefac960982b000000000000000000000000bab36286672fbdc7b250804bf6d14be0df69fa29943e11f7c74e2d6493ef8ad01a06ef2ce9bd1fb3000000000000000000000000000000000000000000000000000000000000000000000000000000005fe0a3751ca03ab6306b8b8875c7d2cbaa71a3991eb8e7ae44e192dc9974cecc1f9dcfe5e4d6a04ec2808db06fe7b246134997fcce81ca201ced1257f1f8e93cacadd6554ca653","tx_hash":"ceba36dff0b2c7aec69cb2d5be7055858e09889959ba63f7957b45a15dceade4"}}},{"timestamp":1608541835207,"event":{"type":"TakerPaymentReceived","data":{"tx_hex":"f90127821fb680830249f094a09ad3cd7e96586ebd05a2607ee56b56fb2db8fd80b8c49b415b2a64bdf61f195a1767f547bb0886ed697f3c1a063ce928ff9a47222c0b5d099200000000000000000000000000000000000000000000000000016345785d8a00000000000000000000000000002b294f029fde858b2c62184e8390591755521d8e0000000000000000000000004b2d0d6c2c785217457b69b922a2a9cea98f71e9943e11f7c74e2d6493ef8ad01a06ef2ce9bd1fb3000000000000000000000000000000000000000000000000000000000000000000000000000000005fe084fd1ba0a5b6ef54217c5a03a588d01410ef1187ce6107bdb075306ced06a06e25a50984a03f541f1f392079ae2590d0f48f2065f8721a8b46c44a060ae53f00bfb5160118","tx_hash":"1247a1be3da89f3612ca33d83d493808388775e2897036f640c0efe69c3b162f"}}},{"timestamp":1608541835208,"event":{"type":"TakerPaymentWaitConfirmStarted"}},{"timestamp":1608541836196,"event":{"type":"TakerPaymentValidatedAndConfirmed"}},{"timestamp":1608541837173,"event":{"type":"TakerPaymentSpent","data":{"tx_hex":"f9010782021a80830249f094a09ad3cd7e96586ebd05a2607ee56b56fb2db8fd80b8a402ed292b64bdf61f195a1767f547bb0886ed697f3c1a063ce928ff9a47222c0b5d099200000000000000000000000000000000000000000000000000016345785d8a0000dc45c1d22028970d8d30d1ddacbfc50eb92403b0d6076c94f2216c4c44512b410000000000000000000000002b294f029fde858b2c62184e8390591755521d8e000000000000000000000000bab36286672fbdc7b250804bf6d14be0df69fa291ba053af89feb4ab066b26e76de9788c85ec1bf14ae6dcbdd7ff53e561e48e1b822ca043796d45bd4233500a120a1571b3fee95a34e8cc6b616c69552da4352c0d8e39","tx_hash":"d9a839c6eead3fbf538eca0a4ec39e28647104920a5c8b9c107524287dd90165"}}},{"timestamp":1608541837175,"event":{"type":"TakerPaymentSpendConfirmStarted"}},{"timestamp":1608541837612,"event":{"type":"TakerPaymentSpendConfirmed"}},{"timestamp":1608541837614,"event":{"type":"Finished"}}],"maker_amount":"0.1","maker_coin":"ETH","taker_amount":"0.1","taker_coin":"JST","gui":"nogui","mm_version":"1a6082121","success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","MakerPaymentWaitConfirmFailed","TakerPaymentValidateFailed","TakerPaymentWaitConfirmFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentWaitRefundStarted","MakerPaymentRefunded","MakerPaymentRefundFailed"]}"#; + let maker_saved_json = r#"{"type":"Maker","uuid":"c52659d7-4e13-41f5-9c1a-30cc2f646033","events":[{"timestamp":1608541830095,"event":{"type":"Started","data":{"taker_coin":"JST","maker_coin":"ETH","taker_pubkey":"031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3","secret":"dc45c1d22028970d8d30d1ddacbfc50eb92403b0d6076c94f2216c4c44512b41","secret_hash":"943e11f7c74e2d6493ef8ad01a06ef2ce9bd1fb3","my_persistent_pub":"03c6a78589e18b482aea046975e6d0acbdea7bf7dbf04d9d5bd67fda917815e3ed","lock_duration":7800,"maker_amount":"0.1","taker_amount":"0.1","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":1,"taker_payment_requires_nota":false,"maker_payment_lock":1608557429,"uuid":"c52659d7-4e13-41f5-9c1a-30cc2f646033","started_at":1608541829,"maker_coin_start_block":14353,"taker_coin_start_block":14353,"maker_coin_swap_contract_address":"eA6D65434A15377081495a9E7C5893543E7c32cB"}}},{"timestamp":1608541830399,"event":{"type":"Negotiated","data":{"taker_payment_locktime":1608549629,"taker_pubkey":"02031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3"}}},{"timestamp":1608541831810,"event":{"type":"TakerFeeValidated","data":{"tx_hex":"f8a7821fb58083033450942b294f029fde858b2c62184e8390591755521d8e80b844a9059cbb000000000000000000000000d8997941dd1346e9231118d5685d866294f59e5b0000000000000000000000000000000000000000000000000000750d557426e01ba06ddad2dfe6933b8d70d5739beb3005c8f367bc72eac4e5609b81c2f8e5843cd9a07fa695cc42f8c6b6a7b10f6ae9e4dca3e750e37f64a85b54dec736236790f05e","tx_hash":"b13c3428f70b46d8c1d7f5863af020a27c380a8ede0927554beabf234998bcc8"}}},{"timestamp":1608541832884,"event":{"type":"MakerPaymentSent","data":{"tx_hex":"f8ef82021980830249f094a09ad3cd7e96586ebd05a2607ee56b56fb2db8fd88016345785d8a0000b884152cf3af7c7ce37fac65bd995eae3d58ccdc367d79f3a10e6ca55f609e6dcefac960982b000000000000000000000000bab36286672fbdc7b250804bf6d14be0df69fa29943e11f7c74e2d6493ef8ad01a06ef2ce9bd1fb3000000000000000000000000000000000000000000000000000000000000000000000000000000005fe0a3751ca03ab6306b8b8875c7d2cbaa71a3991eb8e7ae44e192dc9974cecc1f9dcfe5e4d6a04ec2808db06fe7b246134997fcce81ca201ced1257f1f8e93cacadd6554ca653","tx_hash":"ceba36dff0b2c7aec69cb2d5be7055858e09889959ba63f7957b45a15dceade4"}}},{"timestamp":1608541835207,"event":{"type":"TakerPaymentReceived","data":{"tx_hex":"f90127821fb680830249f094a09ad3cd7e96586ebd05a2607ee56b56fb2db8fd80b8c49b415b2a64bdf61f195a1767f547bb0886ed697f3c1a063ce928ff9a47222c0b5d099200000000000000000000000000000000000000000000000000016345785d8a00000000000000000000000000002b294f029fde858b2c62184e8390591755521d8e0000000000000000000000004b2d0d6c2c785217457b69b922a2a9cea98f71e9943e11f7c74e2d6493ef8ad01a06ef2ce9bd1fb3000000000000000000000000000000000000000000000000000000000000000000000000000000005fe084fd1ba0a5b6ef54217c5a03a588d01410ef1187ce6107bdb075306ced06a06e25a50984a03f541f1f392079ae2590d0f48f2065f8721a8b46c44a060ae53f00bfb5160118","tx_hash":"1247a1be3da89f3612ca33d83d493808388775e2897036f640c0efe69c3b162f"}}},{"timestamp":1608541835208,"event":{"type":"TakerPaymentWaitConfirmStarted"}},{"timestamp":1608541836196,"event":{"type":"TakerPaymentValidatedAndConfirmed"}},{"timestamp":1608541837173,"event":{"type":"TakerPaymentSpent","data":{"tx_hex":"f9010782021a80830249f094a09ad3cd7e96586ebd05a2607ee56b56fb2db8fd80b8a402ed292b64bdf61f195a1767f547bb0886ed697f3c1a063ce928ff9a47222c0b5d099200000000000000000000000000000000000000000000000000016345785d8a0000dc45c1d22028970d8d30d1ddacbfc50eb92403b0d6076c94f2216c4c44512b410000000000000000000000002b294f029fde858b2c62184e8390591755521d8e000000000000000000000000bab36286672fbdc7b250804bf6d14be0df69fa291ba053af89feb4ab066b26e76de9788c85ec1bf14ae6dcbdd7ff53e561e48e1b822ca043796d45bd4233500a120a1571b3fee95a34e8cc6b616c69552da4352c0d8e39","tx_hash":"d9a839c6eead3fbf538eca0a4ec39e28647104920a5c8b9c107524287dd90165"}}},{"timestamp":1608541837175,"event":{"type":"TakerPaymentSpendConfirmStarted"}},{"timestamp":1608541837612,"event":{"type":"TakerPaymentSpendConfirmed"}},{"timestamp":1608541837614,"event":{"type":"Finished"}}],"maker_amount":"0.1","maker_coin":"ETH","taker_amount":"0.1","taker_coin":"JST","gui":"nogui","mm_version":"1a6082121","success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","MakerPaymentWaitConfirmFailed","TakerPaymentValidateFailed","TakerPaymentWaitConfirmFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentWaitRefundStarted","MakerPaymentRefunded","MakerPaymentRefundFailed"]}"#; let maker_saved_swap: MakerSavedSwap = json::from_str(maker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap.rs b/mm2src/mm2_main/src/lp_swap/taker_swap.rs index b00daf2ef5..7f29e5ad4a 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap.rs @@ -2755,7 +2755,7 @@ mod taker_swap_tests { fn test_recover_funds_taker_swap_maker_payment_spend_errored() { let ctx = mm_ctx_with_iguana(PASSPHRASE); - let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.12596566232185483","maker_coin":"KMD","maker_coin_start_block":1458035,"maker_payment_confirmations":1,"maker_payment_wait":1564053079,"my_persistent_pub":"0326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0a","started_at":1564050479,"taker_amount":"50.000000000000001504212457800000","taker_coin":"DOGE","taker_coin_start_block":2823448,"taker_payment_confirmations":1,"taker_payment_lock":1564058279,"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"},"type":"Started"},"timestamp":1564050480269},{"event":{"data":{"maker_payment_locktime":1564066080,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"3669eb83a007a3c507448d79f45a9f06ec2f36a8"},"type":"Negotiated"},"timestamp":1564050540991},{"event":{"data":{"tx_hash":"bdde828b492d6d1cc25cd2322fd592dafd722fcc7d8b0fedce4d3bb4a1a8c8ff","tx_hex":"0100000002c7efa995c8b7be0a8b6c2d526c6c444c1634d65584e9ee89904e9d8675eac88c010000006a473044022051f34d5e3b7d0b9098d5e35333f3550f9cb9e57df83d5e4635b7a8d2986d6d5602200288c98da05de6950e01229a637110a1800ba643e75cfec59d4eb1021ad9b40801210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffffae6c233989efa7c7d2aa6534adc96078917ff395b7f09f734a147b2f44ade164000000006a4730440220393a784c2da74d0e2a28ec4f7df6c8f9d8b2af6ae6957f1e68346d744223a8fd02201b7a96954ac06815a43a6c7668d829ae9cbb5de76fa77189ddfd9e3038df662c01210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffff02115f5800000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac41a84641020000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac6d84395d"},"type":"TakerFeeSent"},"timestamp":1564050545296},{"event":{"data":{"tx_hash":"0a0f11fa82802c2c30862c50ab2162185dae8de7f7235f32c506f814c142b382","tx_hex":"0400008085202f8902ace337db2dd4c56b0697f58fb8cfb6bd1cd6f469d925fc0376d1dcfb7581bf82000000006b483045022100d1f95be235c5c8880f5d703ace287e2768548792c58c5dbd27f5578881b30ea70220030596106e21c7e0057ee0dab283f9a1fe273f15208cba80870c447bd559ef0d0121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff9f339752567c404427fd77f2b35cecdb4c21489edc64e25e729fdb281785e423000000006a47304402203179e95877dbc107123a417f1e648e3ff13d384890f1e4a67b6dd5087235152e0220102a8ab799fadb26b5d89ceb9c7bc721a7e0c2a0d0d7e46bbe0cf3d130010d430121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff025635c0000000000017a91480a95d366d65e34a465ab17b0c9eb1d5a33bae08876cbfce05000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac8d7c395d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1564050588176},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1564050588178},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1564050693585},{"event":{"data":{"tx_hash":"539cb6dbdc25465bbccc575554f05d1bb04c70efce4316e41194e747375c3659","tx_hex":"0100000001ffc8a8a1b43b4dceed0f8b7dcc2f72fdda92d52f32d25cc21c6d2d498b82debd010000006a47304402203967b7f9f5532fa47116585c7d1bcba51861ea2059cca00409f34660db18e33a0220640991911852533a12fdfeb039fb9c8ca2c45482c6993bd84636af3670d49c1501210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffff0200f2052a0100000017a914f2fa08ae416b576779ae5da975e5442663215fce87415173f9000000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac0585395d"},"type":"TakerPaymentSent"},"timestamp":1564050695611},{"event":{"data":{"secret":"1b8886b8a2cdb62505699400b694ac20f04d7bd4abd80e1ab154aa8d861fc093","transaction":{"tx_hash":"cc5af1cf68d246419fee49c3d74c0cd173599d115b86efe274368a614951bc47","tx_hex":"010000000159365c3747e79411e41643ceef704cb01b5df0545557ccbc5b4625dcdbb69c5300000000d747304402200e78e27d2f1c18676f98ca3dfa4e4a9eeaa8209b55f57b4dd5d9e1abdf034cfa0220623b5c22b62234cec230342aa306c497e43494b44ec2425b84e236b1bf01257001201b8886b8a2cdb62505699400b694ac20f04d7bd4abd80e1ab154aa8d861fc093004c6b6304a7a2395db175210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0aac6782012088a9143669eb83a007a3c507448d79f45a9f06ec2f36a88821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68ffffffff01008d380c010000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac8c77395d"}},"type":"TakerPaymentSpent"},"timestamp":1564051092890},{"event":{"data":{"error":"lp_swap:1981] utxo:891] rpc_clients:738] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"67\", method: \"blockchain.transaction.broadcast\", params: [String(\"0400008085202f890182b342c114f806c5325f23f7e78dae5d186221ab502c86302c2c8082fa110f0a00000000d7473044022035791ea5548f87484065c9e1f0bdca9ebc699f2c7f51182c84f360102e32dc3d02200612ed53bca52d9c2568437f087598531534badf26229fe0f652ea72ddf03ca501201b8886b8a2cdb62505699400b694ac20f04d7bd4abd80e1ab154aa8d861fc093004c6b630420c1395db17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a9143669eb83a007a3c507448d79f45a9f06ec2f36a888210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0aac68ffffffff01460ec000000000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac967e395d000000000000000000000000000000\")] }, error: Transport(\"rpc_clients:668] All electrums are currently disconnected\") }"},"type":"MakerPaymentSpendFailed"},"timestamp":1564051092897},{"event":{"type":"Finished"},"timestamp":1564051092900}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"}"#; + let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_pubkey":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.12596566232185483","maker_coin":"KMD","maker_coin_start_block":1458035,"maker_payment_confirmations":1,"maker_payment_wait":1564053079,"my_persistent_pub":"0326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0a","started_at":1564050479,"taker_amount":"50.000000000000001504212457800000","taker_coin":"DOGE","taker_coin_start_block":2823448,"taker_payment_confirmations":1,"taker_payment_lock":1564058279,"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"},"type":"Started"},"timestamp":1564050480269},{"event":{"data":{"maker_payment_locktime":1564066080,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"3669eb83a007a3c507448d79f45a9f06ec2f36a8"},"type":"Negotiated"},"timestamp":1564050540991},{"event":{"data":{"tx_hash":"bdde828b492d6d1cc25cd2322fd592dafd722fcc7d8b0fedce4d3bb4a1a8c8ff","tx_hex":"0100000002c7efa995c8b7be0a8b6c2d526c6c444c1634d65584e9ee89904e9d8675eac88c010000006a473044022051f34d5e3b7d0b9098d5e35333f3550f9cb9e57df83d5e4635b7a8d2986d6d5602200288c98da05de6950e01229a637110a1800ba643e75cfec59d4eb1021ad9b40801210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffffae6c233989efa7c7d2aa6534adc96078917ff395b7f09f734a147b2f44ade164000000006a4730440220393a784c2da74d0e2a28ec4f7df6c8f9d8b2af6ae6957f1e68346d744223a8fd02201b7a96954ac06815a43a6c7668d829ae9cbb5de76fa77189ddfd9e3038df662c01210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffff02115f5800000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac41a84641020000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac6d84395d"},"type":"TakerFeeSent"},"timestamp":1564050545296},{"event":{"data":{"tx_hash":"0a0f11fa82802c2c30862c50ab2162185dae8de7f7235f32c506f814c142b382","tx_hex":"0400008085202f8902ace337db2dd4c56b0697f58fb8cfb6bd1cd6f469d925fc0376d1dcfb7581bf82000000006b483045022100d1f95be235c5c8880f5d703ace287e2768548792c58c5dbd27f5578881b30ea70220030596106e21c7e0057ee0dab283f9a1fe273f15208cba80870c447bd559ef0d0121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff9f339752567c404427fd77f2b35cecdb4c21489edc64e25e729fdb281785e423000000006a47304402203179e95877dbc107123a417f1e648e3ff13d384890f1e4a67b6dd5087235152e0220102a8ab799fadb26b5d89ceb9c7bc721a7e0c2a0d0d7e46bbe0cf3d130010d430121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff025635c0000000000017a91480a95d366d65e34a465ab17b0c9eb1d5a33bae08876cbfce05000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac8d7c395d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1564050588176},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1564050588178},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1564050693585},{"event":{"data":{"tx_hash":"539cb6dbdc25465bbccc575554f05d1bb04c70efce4316e41194e747375c3659","tx_hex":"0100000001ffc8a8a1b43b4dceed0f8b7dcc2f72fdda92d52f32d25cc21c6d2d498b82debd010000006a47304402203967b7f9f5532fa47116585c7d1bcba51861ea2059cca00409f34660db18e33a0220640991911852533a12fdfeb039fb9c8ca2c45482c6993bd84636af3670d49c1501210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffff0200f2052a0100000017a914f2fa08ae416b576779ae5da975e5442663215fce87415173f9000000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac0585395d"},"type":"TakerPaymentSent"},"timestamp":1564050695611},{"event":{"data":{"secret":"1b8886b8a2cdb62505699400b694ac20f04d7bd4abd80e1ab154aa8d861fc093","transaction":{"tx_hash":"cc5af1cf68d246419fee49c3d74c0cd173599d115b86efe274368a614951bc47","tx_hex":"010000000159365c3747e79411e41643ceef704cb01b5df0545557ccbc5b4625dcdbb69c5300000000d747304402200e78e27d2f1c18676f98ca3dfa4e4a9eeaa8209b55f57b4dd5d9e1abdf034cfa0220623b5c22b62234cec230342aa306c497e43494b44ec2425b84e236b1bf01257001201b8886b8a2cdb62505699400b694ac20f04d7bd4abd80e1ab154aa8d861fc093004c6b6304a7a2395db175210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0aac6782012088a9143669eb83a007a3c507448d79f45a9f06ec2f36a88821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68ffffffff01008d380c010000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac8c77395d"}},"type":"TakerPaymentSpent"},"timestamp":1564051092890},{"event":{"data":{"error":"lp_swap:1981] utxo:891] rpc_clients:738] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"67\", method: \"blockchain.transaction.broadcast\", params: [String(\"0400008085202f890182b342c114f806c5325f23f7e78dae5d186221ab502c86302c2c8082fa110f0a00000000d7473044022035791ea5548f87484065c9e1f0bdca9ebc699f2c7f51182c84f360102e32dc3d02200612ed53bca52d9c2568437f087598531534badf26229fe0f652ea72ddf03ca501201b8886b8a2cdb62505699400b694ac20f04d7bd4abd80e1ab154aa8d861fc093004c6b630420c1395db17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a9143669eb83a007a3c507448d79f45a9f06ec2f36a888210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0aac68ffffffff01460ec000000000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac967e395d000000000000000000000000000000\")] }, error: Transport(\"rpc_clients:668] All electrums are currently disconnected\") }"},"type":"MakerPaymentSpendFailed"},"timestamp":1564051092897},{"event":{"type":"Finished"},"timestamp":1564051092900}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"}"#; let taker_saved_swap: TakerSavedSwap = json::from_str(taker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2791,7 +2791,7 @@ mod taker_swap_tests { fn test_recover_funds_taker_swap_taker_payment_errored_but_sent_not_spent() { let ctx = mm_ctx_with_iguana(PASSPHRASE); - let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_wait":1563746537,"my_persistent_pub":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","started_at":1563743937,"taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"taker_payment_lock":1563751737,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743937741},{"event":{"data":{"maker_payment_locktime":1563759539,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"432c8272ac59b47dea2d299b5cf1ee64ea1917b9"},"type":"Negotiated"},"timestamp":1563744003530},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeSent"},"timestamp":1563744020598},{"event":{"data":{"tx_hash":"0cf4acbcefde53645851c5c6053ea61fe0cbb5f828a906d69eb809e0b071a03b","tx_hex":"0400008085202f89025d5ae3e8c87418c9b735f8f2f7d29e26820c33c9f30d53f2d31f8b99ea9b1490010000006a47304402201185c06ca575261c539b287175751b7de642eb7466c59128639a19b4c2dd2f9b02201c8c4167d581864bedd4d1deb5596472e6e3ce29fe9e7996907a7b59c905d5490121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff06dbf9971c8dfd4a0c8c49f4f15c51de59ba13b2efa702682e26869843af9a87000000006a473044022012b47c12c7f6ad7d8b778fc4b5dcfd56a39325daf302f56e7b84753ba5216cfa022076bf571cf9e20facf70d2f134e8ed2de67aa08581a27ff3128bf93a9b594ac770121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff02fed727150000000017a914d5268b31131a652f9b6ddf57db62f02285cdfad1874e1d7835000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac37cf345d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1563744071778},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1563744071781},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1563744118073},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"TakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563744118580}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; + let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_pubkey":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_wait":1563746537,"my_persistent_pub":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","started_at":1563743937,"taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"taker_payment_lock":1563751737,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743937741},{"event":{"data":{"maker_payment_locktime":1563759539,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"432c8272ac59b47dea2d299b5cf1ee64ea1917b9"},"type":"Negotiated"},"timestamp":1563744003530},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeSent"},"timestamp":1563744020598},{"event":{"data":{"tx_hash":"0cf4acbcefde53645851c5c6053ea61fe0cbb5f828a906d69eb809e0b071a03b","tx_hex":"0400008085202f89025d5ae3e8c87418c9b735f8f2f7d29e26820c33c9f30d53f2d31f8b99ea9b1490010000006a47304402201185c06ca575261c539b287175751b7de642eb7466c59128639a19b4c2dd2f9b02201c8c4167d581864bedd4d1deb5596472e6e3ce29fe9e7996907a7b59c905d5490121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff06dbf9971c8dfd4a0c8c49f4f15c51de59ba13b2efa702682e26869843af9a87000000006a473044022012b47c12c7f6ad7d8b778fc4b5dcfd56a39325daf302f56e7b84753ba5216cfa022076bf571cf9e20facf70d2f134e8ed2de67aa08581a27ff3128bf93a9b594ac770121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff02fed727150000000017a914d5268b31131a652f9b6ddf57db62f02285cdfad1874e1d7835000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac37cf345d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1563744071778},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1563744071781},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1563744118073},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"TakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563744118580}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; let taker_saved_swap: TakerSavedSwap = json::from_str(taker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2841,7 +2841,7 @@ mod taker_swap_tests { fn test_recover_funds_taker_swap_taker_payment_errored_but_sent_and_spent_by_maker() { let ctx = mm_ctx_with_iguana(PASSPHRASE); - let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_wait":1563746537,"my_persistent_pub":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","started_at":1563743937,"taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"taker_payment_lock":1563751737,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743937741},{"event":{"data":{"maker_payment_locktime":1563759539,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"432c8272ac59b47dea2d299b5cf1ee64ea1917b9"},"type":"Negotiated"},"timestamp":1563744003530},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeSent"},"timestamp":1563744020598},{"event":{"data":{"tx_hash":"0cf4acbcefde53645851c5c6053ea61fe0cbb5f828a906d69eb809e0b071a03b","tx_hex":"0400008085202f89025d5ae3e8c87418c9b735f8f2f7d29e26820c33c9f30d53f2d31f8b99ea9b1490010000006a47304402201185c06ca575261c539b287175751b7de642eb7466c59128639a19b4c2dd2f9b02201c8c4167d581864bedd4d1deb5596472e6e3ce29fe9e7996907a7b59c905d5490121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff06dbf9971c8dfd4a0c8c49f4f15c51de59ba13b2efa702682e26869843af9a87000000006a473044022012b47c12c7f6ad7d8b778fc4b5dcfd56a39325daf302f56e7b84753ba5216cfa022076bf571cf9e20facf70d2f134e8ed2de67aa08581a27ff3128bf93a9b594ac770121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff02fed727150000000017a914d5268b31131a652f9b6ddf57db62f02285cdfad1874e1d7835000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac37cf345d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1563744071778},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1563744071781},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1563744118073},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"TakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563744118580}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; + let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_pubkey":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_wait":1563746537,"my_persistent_pub":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","started_at":1563743937,"taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"taker_payment_lock":1563751737,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743937741},{"event":{"data":{"maker_payment_locktime":1563759539,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"432c8272ac59b47dea2d299b5cf1ee64ea1917b9"},"type":"Negotiated"},"timestamp":1563744003530},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeSent"},"timestamp":1563744020598},{"event":{"data":{"tx_hash":"0cf4acbcefde53645851c5c6053ea61fe0cbb5f828a906d69eb809e0b071a03b","tx_hex":"0400008085202f89025d5ae3e8c87418c9b735f8f2f7d29e26820c33c9f30d53f2d31f8b99ea9b1490010000006a47304402201185c06ca575261c539b287175751b7de642eb7466c59128639a19b4c2dd2f9b02201c8c4167d581864bedd4d1deb5596472e6e3ce29fe9e7996907a7b59c905d5490121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff06dbf9971c8dfd4a0c8c49f4f15c51de59ba13b2efa702682e26869843af9a87000000006a473044022012b47c12c7f6ad7d8b778fc4b5dcfd56a39325daf302f56e7b84753ba5216cfa022076bf571cf9e20facf70d2f134e8ed2de67aa08581a27ff3128bf93a9b594ac770121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff02fed727150000000017a914d5268b31131a652f9b6ddf57db62f02285cdfad1874e1d7835000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac37cf345d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1563744071778},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1563744071781},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1563744118073},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"TakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563744118580}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; let taker_saved_swap: TakerSavedSwap = json::from_str(taker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2894,7 +2894,7 @@ mod taker_swap_tests { fn test_recover_funds_taker_swap_taker_payment_refund_failed_not_spent() { let ctx = mm_ctx_with_iguana(PASSPHRASE); - let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_wait":1563623475,"my_persistent_pub":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91","started_at":1563620875,"taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"taker_payment_lock":1563628675,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875766},{"event":{"data":{"maker_payment_locktime":1563636475,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"7ed38daab6085c1a1e4426e61dc87a3c2c081a95"},"type":"Negotiated"},"timestamp":1563620955014},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeSent"},"timestamp":1563620958220},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1563620999307},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1563620999310},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1563621244153},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentSent"},"timestamp":1563621246370},{"event":{"data":{"error":"utxo:1145] rpc_clients:782] Waited too long until 1563628675 for output TransactionOutput { value: 777000, script_pubkey: a91483818667161bf94adda3964a81a231cbf6f5338187 } to be spent "},"type":"TakerPaymentWaitForSpendFailed"},"timestamp":1563638060370},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563638060585}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; + let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_pubkey":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_wait":1563623475,"my_persistent_pub":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91","started_at":1563620875,"taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"taker_payment_lock":1563628675,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875766},{"event":{"data":{"maker_payment_locktime":1563636475,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"7ed38daab6085c1a1e4426e61dc87a3c2c081a95"},"type":"Negotiated"},"timestamp":1563620955014},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeSent"},"timestamp":1563620958220},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1563620999307},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1563620999310},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1563621244153},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentSent"},"timestamp":1563621246370},{"event":{"data":{"error":"utxo:1145] rpc_clients:782] Waited too long until 1563628675 for output TransactionOutput { value: 777000, script_pubkey: a91483818667161bf94adda3964a81a231cbf6f5338187 } to be spent "},"type":"TakerPaymentWaitForSpendFailed"},"timestamp":1563638060370},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563638060585}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; let taker_saved_swap: TakerSavedSwap = json::from_str(taker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2937,7 +2937,7 @@ mod taker_swap_tests { fn test_recover_funds_taker_swap_taker_payment_refund_failed_not_spent_too_early_to_refund() { let ctx = mm_ctx_with_iguana(PASSPHRASE); - let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_wait":1563623475,"my_persistent_pub":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91","started_at":1563620875,"taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"taker_payment_lock":1563628675,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875766},{"event":{"data":{"maker_payment_locktime":1563636475,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"7ed38daab6085c1a1e4426e61dc87a3c2c081a95"},"type":"Negotiated"},"timestamp":1563620955014},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeSent"},"timestamp":1563620958220},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1563620999307},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1563620999310},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1563621244153},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentSent"},"timestamp":1563621246370},{"event":{"data":{"error":"utxo:1145] rpc_clients:782] Waited too long until 1563628675 for output TransactionOutput { value: 777000, script_pubkey: a91483818667161bf94adda3964a81a231cbf6f5338187 } to be spent "},"type":"TakerPaymentWaitForSpendFailed"},"timestamp":1563638060370},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563638060585}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; + let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_pubkey":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_wait":1563623475,"my_persistent_pub":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91","started_at":1563620875,"taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"taker_payment_lock":1563628675,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875766},{"event":{"data":{"maker_payment_locktime":1563636475,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"7ed38daab6085c1a1e4426e61dc87a3c2c081a95"},"type":"Negotiated"},"timestamp":1563620955014},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeSent"},"timestamp":1563620958220},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1563620999307},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1563620999310},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1563621244153},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentSent"},"timestamp":1563621246370},{"event":{"data":{"error":"utxo:1145] rpc_clients:782] Waited too long until 1563628675 for output TransactionOutput { value: 777000, script_pubkey: a91483818667161bf94adda3964a81a231cbf6f5338187 } to be spent "},"type":"TakerPaymentWaitForSpendFailed"},"timestamp":1563638060370},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563638060585}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; let taker_saved_swap: TakerSavedSwap = json::from_str(taker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -2968,7 +2968,7 @@ mod taker_swap_tests { fn test_recover_funds_taker_swap_taker_payment_refund_failed_spent_by_maker() { let ctx = mm_ctx_with_iguana(PASSPHRASE); - let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_wait":1563623475,"my_persistent_pub":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91","started_at":1563620875,"taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"taker_payment_lock":1563628675,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875766},{"event":{"data":{"maker_payment_locktime":1563636475,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"7ed38daab6085c1a1e4426e61dc87a3c2c081a95"},"type":"Negotiated"},"timestamp":1563620955014},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeSent"},"timestamp":1563620958220},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1563620999307},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1563620999310},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1563621244153},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentSent"},"timestamp":1563621246370},{"event":{"data":{"error":"utxo:1145] rpc_clients:782] Waited too long until 1563628675 for output TransactionOutput { value: 777000, script_pubkey: a91483818667161bf94adda3964a81a231cbf6f5338187 } to be spent "},"type":"TakerPaymentWaitForSpendFailed"},"timestamp":1563638060370},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563638060585}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; + let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_pubkey":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_wait":1563623475,"my_persistent_pub":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91","started_at":1563620875,"taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"taker_payment_lock":1563628675,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875766},{"event":{"data":{"maker_payment_locktime":1563636475,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"7ed38daab6085c1a1e4426e61dc87a3c2c081a95"},"type":"Negotiated"},"timestamp":1563620955014},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeSent"},"timestamp":1563620958220},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1563620999307},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1563620999310},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1563621244153},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentSent"},"timestamp":1563621246370},{"event":{"data":{"error":"utxo:1145] rpc_clients:782] Waited too long until 1563628675 for output TransactionOutput { value: 777000, script_pubkey: a91483818667161bf94adda3964a81a231cbf6f5338187 } to be spent "},"type":"TakerPaymentWaitForSpendFailed"},"timestamp":1563638060370},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563638060585}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; let taker_saved_swap: TakerSavedSwap = json::from_str(taker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -3015,7 +3015,7 @@ mod taker_swap_tests { let ctx = mm_ctx_with_iguana(PASSPHRASE); // the json doesn't have Finished event at the end - let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.12596566232185483","maker_coin":"KMD","maker_coin_start_block":1458035,"maker_payment_confirmations":1,"maker_payment_wait":1564053079,"my_persistent_pub":"0326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0a","started_at":1564050479,"taker_amount":"50.000000000000001504212457800000","taker_coin":"DOGE","taker_coin_start_block":2823448,"taker_payment_confirmations":1,"taker_payment_lock":1564058279,"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"},"type":"Started"},"timestamp":1564050480269},{"event":{"data":{"maker_payment_locktime":1564066080,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"3669eb83a007a3c507448d79f45a9f06ec2f36a8"},"type":"Negotiated"},"timestamp":1564050540991},{"event":{"data":{"tx_hash":"bdde828b492d6d1cc25cd2322fd592dafd722fcc7d8b0fedce4d3bb4a1a8c8ff","tx_hex":"0100000002c7efa995c8b7be0a8b6c2d526c6c444c1634d65584e9ee89904e9d8675eac88c010000006a473044022051f34d5e3b7d0b9098d5e35333f3550f9cb9e57df83d5e4635b7a8d2986d6d5602200288c98da05de6950e01229a637110a1800ba643e75cfec59d4eb1021ad9b40801210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffffae6c233989efa7c7d2aa6534adc96078917ff395b7f09f734a147b2f44ade164000000006a4730440220393a784c2da74d0e2a28ec4f7df6c8f9d8b2af6ae6957f1e68346d744223a8fd02201b7a96954ac06815a43a6c7668d829ae9cbb5de76fa77189ddfd9e3038df662c01210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffff02115f5800000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac41a84641020000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac6d84395d"},"type":"TakerFeeSent"},"timestamp":1564050545296},{"event":{"data":{"tx_hash":"0a0f11fa82802c2c30862c50ab2162185dae8de7f7235f32c506f814c142b382","tx_hex":"0400008085202f8902ace337db2dd4c56b0697f58fb8cfb6bd1cd6f469d925fc0376d1dcfb7581bf82000000006b483045022100d1f95be235c5c8880f5d703ace287e2768548792c58c5dbd27f5578881b30ea70220030596106e21c7e0057ee0dab283f9a1fe273f15208cba80870c447bd559ef0d0121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff9f339752567c404427fd77f2b35cecdb4c21489edc64e25e729fdb281785e423000000006a47304402203179e95877dbc107123a417f1e648e3ff13d384890f1e4a67b6dd5087235152e0220102a8ab799fadb26b5d89ceb9c7bc721a7e0c2a0d0d7e46bbe0cf3d130010d430121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff025635c0000000000017a91480a95d366d65e34a465ab17b0c9eb1d5a33bae08876cbfce05000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac8d7c395d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1564050588176},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1564050588178},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1564050693585},{"event":{"data":{"tx_hash":"539cb6dbdc25465bbccc575554f05d1bb04c70efce4316e41194e747375c3659","tx_hex":"0100000001ffc8a8a1b43b4dceed0f8b7dcc2f72fdda92d52f32d25cc21c6d2d498b82debd010000006a47304402203967b7f9f5532fa47116585c7d1bcba51861ea2059cca00409f34660db18e33a0220640991911852533a12fdfeb039fb9c8ca2c45482c6993bd84636af3670d49c1501210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffff0200f2052a0100000017a914f2fa08ae416b576779ae5da975e5442663215fce87415173f9000000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac0585395d"},"type":"TakerPaymentSent"},"timestamp":1564050695611},{"event":{"data":{"secret":"1b8886b8a2cdb62505699400b694ac20f04d7bd4abd80e1ab154aa8d861fc093","transaction":{"tx_hash":"cc5af1cf68d246419fee49c3d74c0cd173599d115b86efe274368a614951bc47","tx_hex":"010000000159365c3747e79411e41643ceef704cb01b5df0545557ccbc5b4625dcdbb69c5300000000d747304402200e78e27d2f1c18676f98ca3dfa4e4a9eeaa8209b55f57b4dd5d9e1abdf034cfa0220623b5c22b62234cec230342aa306c497e43494b44ec2425b84e236b1bf01257001201b8886b8a2cdb62505699400b694ac20f04d7bd4abd80e1ab154aa8d861fc093004c6b6304a7a2395db175210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0aac6782012088a9143669eb83a007a3c507448d79f45a9f06ec2f36a88821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68ffffffff01008d380c010000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac8c77395d"}},"type":"TakerPaymentSpent"},"timestamp":1564051092890},{"event":{"data":{"error":"lp_swap:1981] utxo:891] rpc_clients:738] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"67\", method: \"blockchain.transaction.broadcast\", params: [String(\"0400008085202f890182b342c114f806c5325f23f7e78dae5d186221ab502c86302c2c8082fa110f0a00000000d7473044022035791ea5548f87484065c9e1f0bdca9ebc699f2c7f51182c84f360102e32dc3d02200612ed53bca52d9c2568437f087598531534badf26229fe0f652ea72ddf03ca501201b8886b8a2cdb62505699400b694ac20f04d7bd4abd80e1ab154aa8d861fc093004c6b630420c1395db17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a9143669eb83a007a3c507448d79f45a9f06ec2f36a888210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0aac68ffffffff01460ec000000000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac967e395d000000000000000000000000000000\")] }, error: Transport(\"rpc_clients:668] All electrums are currently disconnected\") }"},"type":"MakerPaymentSpendFailed"},"timestamp":1564051092897}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"}"#; + let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_pubkey":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.12596566232185483","maker_coin":"KMD","maker_coin_start_block":1458035,"maker_payment_confirmations":1,"maker_payment_wait":1564053079,"my_persistent_pub":"0326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0a","started_at":1564050479,"taker_amount":"50.000000000000001504212457800000","taker_coin":"DOGE","taker_coin_start_block":2823448,"taker_payment_confirmations":1,"taker_payment_lock":1564058279,"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"},"type":"Started"},"timestamp":1564050480269},{"event":{"data":{"maker_payment_locktime":1564066080,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"3669eb83a007a3c507448d79f45a9f06ec2f36a8"},"type":"Negotiated"},"timestamp":1564050540991},{"event":{"data":{"tx_hash":"bdde828b492d6d1cc25cd2322fd592dafd722fcc7d8b0fedce4d3bb4a1a8c8ff","tx_hex":"0100000002c7efa995c8b7be0a8b6c2d526c6c444c1634d65584e9ee89904e9d8675eac88c010000006a473044022051f34d5e3b7d0b9098d5e35333f3550f9cb9e57df83d5e4635b7a8d2986d6d5602200288c98da05de6950e01229a637110a1800ba643e75cfec59d4eb1021ad9b40801210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffffae6c233989efa7c7d2aa6534adc96078917ff395b7f09f734a147b2f44ade164000000006a4730440220393a784c2da74d0e2a28ec4f7df6c8f9d8b2af6ae6957f1e68346d744223a8fd02201b7a96954ac06815a43a6c7668d829ae9cbb5de76fa77189ddfd9e3038df662c01210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffff02115f5800000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac41a84641020000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac6d84395d"},"type":"TakerFeeSent"},"timestamp":1564050545296},{"event":{"data":{"tx_hash":"0a0f11fa82802c2c30862c50ab2162185dae8de7f7235f32c506f814c142b382","tx_hex":"0400008085202f8902ace337db2dd4c56b0697f58fb8cfb6bd1cd6f469d925fc0376d1dcfb7581bf82000000006b483045022100d1f95be235c5c8880f5d703ace287e2768548792c58c5dbd27f5578881b30ea70220030596106e21c7e0057ee0dab283f9a1fe273f15208cba80870c447bd559ef0d0121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff9f339752567c404427fd77f2b35cecdb4c21489edc64e25e729fdb281785e423000000006a47304402203179e95877dbc107123a417f1e648e3ff13d384890f1e4a67b6dd5087235152e0220102a8ab799fadb26b5d89ceb9c7bc721a7e0c2a0d0d7e46bbe0cf3d130010d430121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff025635c0000000000017a91480a95d366d65e34a465ab17b0c9eb1d5a33bae08876cbfce05000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac8d7c395d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1564050588176},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1564050588178},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1564050693585},{"event":{"data":{"tx_hash":"539cb6dbdc25465bbccc575554f05d1bb04c70efce4316e41194e747375c3659","tx_hex":"0100000001ffc8a8a1b43b4dceed0f8b7dcc2f72fdda92d52f32d25cc21c6d2d498b82debd010000006a47304402203967b7f9f5532fa47116585c7d1bcba51861ea2059cca00409f34660db18e33a0220640991911852533a12fdfeb039fb9c8ca2c45482c6993bd84636af3670d49c1501210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffff0200f2052a0100000017a914f2fa08ae416b576779ae5da975e5442663215fce87415173f9000000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac0585395d"},"type":"TakerPaymentSent"},"timestamp":1564050695611},{"event":{"data":{"secret":"1b8886b8a2cdb62505699400b694ac20f04d7bd4abd80e1ab154aa8d861fc093","transaction":{"tx_hash":"cc5af1cf68d246419fee49c3d74c0cd173599d115b86efe274368a614951bc47","tx_hex":"010000000159365c3747e79411e41643ceef704cb01b5df0545557ccbc5b4625dcdbb69c5300000000d747304402200e78e27d2f1c18676f98ca3dfa4e4a9eeaa8209b55f57b4dd5d9e1abdf034cfa0220623b5c22b62234cec230342aa306c497e43494b44ec2425b84e236b1bf01257001201b8886b8a2cdb62505699400b694ac20f04d7bd4abd80e1ab154aa8d861fc093004c6b6304a7a2395db175210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0aac6782012088a9143669eb83a007a3c507448d79f45a9f06ec2f36a88821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68ffffffff01008d380c010000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac8c77395d"}},"type":"TakerPaymentSpent"},"timestamp":1564051092890},{"event":{"data":{"error":"lp_swap:1981] utxo:891] rpc_clients:738] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"67\", method: \"blockchain.transaction.broadcast\", params: [String(\"0400008085202f890182b342c114f806c5325f23f7e78dae5d186221ab502c86302c2c8082fa110f0a00000000d7473044022035791ea5548f87484065c9e1f0bdca9ebc699f2c7f51182c84f360102e32dc3d02200612ed53bca52d9c2568437f087598531534badf26229fe0f652ea72ddf03ca501201b8886b8a2cdb62505699400b694ac20f04d7bd4abd80e1ab154aa8d861fc093004c6b630420c1395db17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a9143669eb83a007a3c507448d79f45a9f06ec2f36a888210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0aac68ffffffff01460ec000000000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac967e395d000000000000000000000000000000\")] }, error: Transport(\"rpc_clients:668] All electrums are currently disconnected\") }"},"type":"MakerPaymentSpendFailed"},"timestamp":1564051092897}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"}"#; let taker_saved_swap: TakerSavedSwap = json::from_str(taker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -3052,7 +3052,7 @@ mod taker_swap_tests { let ctx = mm_ctx_with_iguana(PASSPHRASE); // swap file contains neither maker_coin_swap_contract_address nor taker_coin_swap_contract_address - let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_wait":1563623475,"my_persistent_pub":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91","started_at":1563620875,"taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"taker_payment_lock":1563628675,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875766},{"event":{"data":{"maker_payment_locktime":1563636475,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"7ed38daab6085c1a1e4426e61dc87a3c2c081a95"},"type":"Negotiated"},"timestamp":1563620955014},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeSent"},"timestamp":1563620958220},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1563620999307},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1563620999310},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1563621244153},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentSent"},"timestamp":1563621246370},{"event":{"data":{"error":"utxo:1145] rpc_clients:782] Waited too long until 1563628675 for output TransactionOutput { value: 777000, script_pubkey: a91483818667161bf94adda3964a81a231cbf6f5338187 } to be spent "},"type":"TakerPaymentWaitForSpendFailed"},"timestamp":1563638060370},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563638060585}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; + let taker_saved_json = r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","TakerPaymentTransactionFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_pubkey":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.58610590","maker_coin":"KMD","maker_coin_start_block":1450923,"maker_payment_confirmations":1,"maker_payment_wait":1563623475,"my_persistent_pub":"02713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91","started_at":1563620875,"taker_amount":"0.0077700000552410000000000","taker_coin":"LTC","taker_coin_start_block":1670837,"taker_payment_confirmations":1,"taker_payment_lock":1563628675,"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"},"type":"Started"},"timestamp":1563620875766},{"event":{"data":{"maker_payment_locktime":1563636475,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"7ed38daab6085c1a1e4426e61dc87a3c2c081a95"},"type":"Negotiated"},"timestamp":1563620955014},{"event":{"data":{"tx_hash":"6740136eaaa615d9d231969e3a9599d0fc59e53989237a8d31cd6fc86c160013","tx_hex":"0100000001a2586ea8294cedc55741bef625ba72c646399903391a7f6c604a58c6263135f2000000006b4830450221009c78c8ba4a7accab6b09f9a95da5bc59c81f4fc1e60b288ec3c5462b4d02ef01022056b63be1629cf17751d3cc5ffec51bcb1d7f9396e9ce9ca254d0f34104f7263a012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac78aa1900000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac5bf6325d"},"type":"TakerFeeSent"},"timestamp":1563620958220},{"event":{"data":{"tx_hash":"d0f6e664cea9d89fe7b5cf8005fdca070d1ab1d05a482aaef95c08cdaecddf0a","tx_hex":"0400008085202f89019f1cbda354342cdf982046b331bbd3791f53b692efc6e4becc36be495b2977d9000000006b483045022100fa9d4557394141f6a8b9bfb8cd594a521fd8bcd1965dbf8bc4e04abc849ac66e0220589f521814c10a7561abfd5e432f7a2ee60d4875fe4604618af3207dae531ac00121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff029e537e030000000017a9145534898009f1467191065f6890b96914b39a1c018791857702000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac72ee325d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1563620999307},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1563620999310},{"event":{"type":"MakerPaymentValidatedAndConfirmed"},"timestamp":1563621244153},{"event":{"data":{"tx_hash":"1e883eb2f3991e84ba27f53651f89b7dda708678a5b9813d043577f222b9ca30","tx_hex":"01000000011300166cc86fcd318d7a238939e559fcd099953a9e9631d2d915a6aa6e134067010000006a47304402206781d5f2db2ff13d2ec7e266f774ea5630cc2dba4019e18e9716131b8b026051022006ebb33857b6d180f13aa6be2fc532f9734abde9d00ae14757e7d7ba3741c08c012102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ffffffff0228db0b000000000017a91483818667161bf94adda3964a81a231cbf6f5338187b0480c00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac7cf7325d"},"type":"TakerPaymentSent"},"timestamp":1563621246370},{"event":{"data":{"error":"utxo:1145] rpc_clients:782] Waited too long until 1563628675 for output TransactionOutput { value: 777000, script_pubkey: a91483818667161bf94adda3964a81a231cbf6f5338187 } to be spent "},"type":"TakerPaymentWaitForSpendFailed"},"timestamp":1563638060370},{"event":{"data":{"error":"lp_swap:2025] utxo:938] rpc_clients:719] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"9\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nMissing inputs\\n[010000000130cab922f27735043d81b9a5788670da7d9bf85136f527ba841e99f3b23e881e00000000b6473044022058a0c1da6bcf8c1418899ff8475f3ab6dddbff918528451c1fe71c2f7dad176302204c2e0bcf8f9b5f09e02ccfeb9256e9b34fb355ea655a5704a8a3fa920079b91501514c6b63048314335db1752102713015d3fa4d30259e90be5f131beb593bf0131f3af2dcdb304e3322d8d52b91ac6782012088a9147ed38daab6085c1a1e4426e61dc87a3c2c081a958821031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac68feffffff0188540a00000000001976a91406ccabfd5f9075ecd5e8d0d31c0e973a54d51e8288ac1c2b335d]\")})) }"},"type":"TakerPaymentRefundFailed"},"timestamp":1563638060583},{"event":{"type":"Finished"},"timestamp":1563638060585}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"9db641f5-4300-4527-9fa6-f1c391d42c35"}"#; let taker_saved_swap: TakerSavedSwap = json::from_str(taker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -3087,7 +3087,7 @@ mod taker_swap_tests { let ctx = mm_ctx_with_iguana(PASSPHRASE); // swap file contains only maker_coin_swap_contract_address - let taker_saved_json = r#"{"type":"Taker","uuid":"49c79ea4-e1eb-4fb2-a0ef-265bded0b77f","events":[{"timestamp":1608542326909,"event":{"type":"Started","data":{"taker_coin":"RICK","maker_coin":"ETH","maker":"c6a78589e18b482aea046975e6d0acbdea7bf7dbf04d9d5bd67fda917815e3ed","my_persistent_pub":"02031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3","lock_duration":7800,"maker_amount":"0.1","taker_amount":"0.1","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":0,"taker_payment_requires_nota":false,"taker_payment_lock":1608550126,"uuid":"49c79ea4-e1eb-4fb2-a0ef-265bded0b77f","started_at":1608542326,"maker_payment_wait":1608545446,"maker_coin_start_block":14360,"taker_coin_start_block":723123,"maker_coin_swap_contract_address":"eA6D65434A15377081495a9E7C5893543E7c32cB"}}},{"timestamp":1608542327416,"event":{"type":"Negotiated","data":{"maker_payment_locktime":1608557926,"maker_pubkey":"03c6a78589e18b482aea046975e6d0acbdea7bf7dbf04d9d5bd67fda917815e3ed","secret_hash":"8b0221f3b977c1c65dddf17c1c28e2bbced9e7b4"}}},{"timestamp":1608542332604,"event":{"type":"TakerFeeSent","data":{"tx_hex":"0400008085202f89011ca964f77200b73d64b481f47de84098041d3470d6256e44f2741f080e2b11cf020000006b4830450221008a064f5e51ef8281d43eb7bcd016fed7e560ea1eb7b0713ec977602c96d8f79b02205bfaa6655b849b9922c03276b938273f2edb8fb9ffcaa2a9212d7220560f6060012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffff0246320000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac62752e27000000001976a91405aab5342166f8594baf17a7d9bef5d56744332788ac7768e05f000000000000000000000000000000","tx_hash":"3793df28ed2aac6188d2c48ec65eff12eea301089d60da655fc96f598326d708"}}},{"timestamp":1608542334018,"event":{"type":"MakerPaymentReceived","data":{"tx_hex":"f8ef82021c80830249f094a09ad3cd7e96586ebd05a2607ee56b56fb2db8fd88016345785d8a0000b884152cf3af50aebafeaf827c62c2eed09e265fa5aa9e013c0f27f0a88259f1aaa1279f0c32000000000000000000000000bab36286672fbdc7b250804bf6d14be0df69fa298b0221f3b977c1c65dddf17c1c28e2bbced9e7b4000000000000000000000000000000000000000000000000000000000000000000000000000000005fe0a5661ba0f18a0c5c349462b51dacd1a0761e4997d4572a01e48480c4e310d69a40308ad3a04510513f01a79c59f22c9cb79952547c8dfc4c74785b630f512d64369323e0c1","tx_hash":"6782323490584a2bc768cd5199506bfa1ed91e7515b35bb72fa269604b7dc0aa"}}},{"timestamp":1608542334019,"event":{"type":"MakerPaymentWaitConfirmStarted"}},{"timestamp":1608542334825,"event":{"type":"MakerPaymentValidatedAndConfirmed"}},{"timestamp":1608542337671,"event":{"type":"TakerPaymentSent","data":{"tx_hex":"0400008085202f890108d72683596fc95f65da609d0801a3ee12ff5ec68ec4d28861ac2aed28df9337010000006b48304502210086a03db599438b243bee2b02af56e23447f85d09854416b51305536b9ca5890e02204b288acdea4cdc7ab1ffbd9766a7bdf95f5bd02d2917dfb7089dbf29032591b0012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffff03809698000000000017a914888e9e1816214c3960eac7b55e35521ca4426b0c870000000000000000166a148b0221f3b977c1c65dddf17c1c28e2bbced9e7b4fada9526000000001976a91405aab5342166f8594baf17a7d9bef5d56744332788ac7f68e05f000000000000000000000000000000","tx_hash":"44fa493757df5fdca823bbac05a8b8feb5862d799d4947fd544abcd129feceea"}}},{"timestamp":1608542348271,"event":{"type":"TakerPaymentSpent","data":{"transaction":{"tx_hex":"0400008085202f8901eacefe29d1bc4a54fd47499d792d86b5feb8a805acbb23a8dc5fdf573749fa4400000000d74730440220508c853cc4f1fcb9e6aa00e704eef99adaee9a4ea63a1fd6393bb7ff18da02c802200396bb5d52157bd77ff26ac521ed75aca388d3ec1e5e3ebb7b3aed73c3d33ec50120df871242dcbcc4fe9ed4d3413e21b2f8ce606a3ee7128c9b2d2e31fcedc1848e004c6b6304ee86e05fb1752102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ac6782012088a9148b0221f3b977c1c65dddf17c1c28e2bbced9e7b4882103c6a78589e18b482aea046975e6d0acbdea7bf7dbf04d9d5bd67fda917815e3edac68ffffffff0198929800000000001976a9146d9d2b554d768232320587df75c4338ecc8bf37d88ac725ae05f000000000000000000000000000000","tx_hash":"9376dde62249802a0aba8259f51def9bb2e509af85a5ec7df04b479a9da28a29"},"secret":"df871242dcbcc4fe9ed4d3413e21b2f8ce606a3ee7128c9b2d2e31fcedc1848e"}}},{"timestamp":1608542349372,"event":{"type":"MakerPaymentSpent","data":{"tx_hex":"f90107821fb980830249f094a09ad3cd7e96586ebd05a2607ee56b56fb2db8fd80b8a402ed292b50aebafeaf827c62c2eed09e265fa5aa9e013c0f27f0a88259f1aaa1279f0c32000000000000000000000000000000000000000000000000016345785d8a0000df871242dcbcc4fe9ed4d3413e21b2f8ce606a3ee7128c9b2d2e31fcedc1848e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000004b2d0d6c2c785217457b69b922a2a9cea98f71e91ca0ed6a4942a78c7ae6eb3c9dec496459a9ef68b34cb389acd939d13d3ecaf7e4aca021bb77e80fc60acf25a7a01cc1272b1b76594a521fb1abe1322d650e58a672c2","tx_hash":"c2d206e665aee159a5ab9aff60f76444e97bdad8f9152eccb6ca07d9204974ca"}}},{"timestamp":1608542349373,"event":{"type":"Finished"}}],"maker_amount":"0.1","maker_coin":"ETH","taker_amount":"0.1","taker_coin":"RICK","gui":"nogui","mm_version":"1a6082121","success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"]}"#; + let taker_saved_json = r#"{"type":"Taker","uuid":"49c79ea4-e1eb-4fb2-a0ef-265bded0b77f","events":[{"timestamp":1608542326909,"event":{"type":"Started","data":{"taker_coin":"RICK","maker_coin":"ETH","maker_pubkey":"c6a78589e18b482aea046975e6d0acbdea7bf7dbf04d9d5bd67fda917815e3ed","my_persistent_pub":"02031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3","lock_duration":7800,"maker_amount":"0.1","taker_amount":"0.1","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":0,"taker_payment_requires_nota":false,"taker_payment_lock":1608550126,"uuid":"49c79ea4-e1eb-4fb2-a0ef-265bded0b77f","started_at":1608542326,"maker_payment_wait":1608545446,"maker_coin_start_block":14360,"taker_coin_start_block":723123,"maker_coin_swap_contract_address":"eA6D65434A15377081495a9E7C5893543E7c32cB"}}},{"timestamp":1608542327416,"event":{"type":"Negotiated","data":{"maker_payment_locktime":1608557926,"maker_pubkey":"03c6a78589e18b482aea046975e6d0acbdea7bf7dbf04d9d5bd67fda917815e3ed","secret_hash":"8b0221f3b977c1c65dddf17c1c28e2bbced9e7b4"}}},{"timestamp":1608542332604,"event":{"type":"TakerFeeSent","data":{"tx_hex":"0400008085202f89011ca964f77200b73d64b481f47de84098041d3470d6256e44f2741f080e2b11cf020000006b4830450221008a064f5e51ef8281d43eb7bcd016fed7e560ea1eb7b0713ec977602c96d8f79b02205bfaa6655b849b9922c03276b938273f2edb8fb9ffcaa2a9212d7220560f6060012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffff0246320000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac62752e27000000001976a91405aab5342166f8594baf17a7d9bef5d56744332788ac7768e05f000000000000000000000000000000","tx_hash":"3793df28ed2aac6188d2c48ec65eff12eea301089d60da655fc96f598326d708"}}},{"timestamp":1608542334018,"event":{"type":"MakerPaymentReceived","data":{"tx_hex":"f8ef82021c80830249f094a09ad3cd7e96586ebd05a2607ee56b56fb2db8fd88016345785d8a0000b884152cf3af50aebafeaf827c62c2eed09e265fa5aa9e013c0f27f0a88259f1aaa1279f0c32000000000000000000000000bab36286672fbdc7b250804bf6d14be0df69fa298b0221f3b977c1c65dddf17c1c28e2bbced9e7b4000000000000000000000000000000000000000000000000000000000000000000000000000000005fe0a5661ba0f18a0c5c349462b51dacd1a0761e4997d4572a01e48480c4e310d69a40308ad3a04510513f01a79c59f22c9cb79952547c8dfc4c74785b630f512d64369323e0c1","tx_hash":"6782323490584a2bc768cd5199506bfa1ed91e7515b35bb72fa269604b7dc0aa"}}},{"timestamp":1608542334019,"event":{"type":"MakerPaymentWaitConfirmStarted"}},{"timestamp":1608542334825,"event":{"type":"MakerPaymentValidatedAndConfirmed"}},{"timestamp":1608542337671,"event":{"type":"TakerPaymentSent","data":{"tx_hex":"0400008085202f890108d72683596fc95f65da609d0801a3ee12ff5ec68ec4d28861ac2aed28df9337010000006b48304502210086a03db599438b243bee2b02af56e23447f85d09854416b51305536b9ca5890e02204b288acdea4cdc7ab1ffbd9766a7bdf95f5bd02d2917dfb7089dbf29032591b0012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffff03809698000000000017a914888e9e1816214c3960eac7b55e35521ca4426b0c870000000000000000166a148b0221f3b977c1c65dddf17c1c28e2bbced9e7b4fada9526000000001976a91405aab5342166f8594baf17a7d9bef5d56744332788ac7f68e05f000000000000000000000000000000","tx_hash":"44fa493757df5fdca823bbac05a8b8feb5862d799d4947fd544abcd129feceea"}}},{"timestamp":1608542348271,"event":{"type":"TakerPaymentSpent","data":{"transaction":{"tx_hex":"0400008085202f8901eacefe29d1bc4a54fd47499d792d86b5feb8a805acbb23a8dc5fdf573749fa4400000000d74730440220508c853cc4f1fcb9e6aa00e704eef99adaee9a4ea63a1fd6393bb7ff18da02c802200396bb5d52157bd77ff26ac521ed75aca388d3ec1e5e3ebb7b3aed73c3d33ec50120df871242dcbcc4fe9ed4d3413e21b2f8ce606a3ee7128c9b2d2e31fcedc1848e004c6b6304ee86e05fb1752102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ac6782012088a9148b0221f3b977c1c65dddf17c1c28e2bbced9e7b4882103c6a78589e18b482aea046975e6d0acbdea7bf7dbf04d9d5bd67fda917815e3edac68ffffffff0198929800000000001976a9146d9d2b554d768232320587df75c4338ecc8bf37d88ac725ae05f000000000000000000000000000000","tx_hash":"9376dde62249802a0aba8259f51def9bb2e509af85a5ec7df04b479a9da28a29"},"secret":"df871242dcbcc4fe9ed4d3413e21b2f8ce606a3ee7128c9b2d2e31fcedc1848e"}}},{"timestamp":1608542349372,"event":{"type":"MakerPaymentSpent","data":{"tx_hex":"f90107821fb980830249f094a09ad3cd7e96586ebd05a2607ee56b56fb2db8fd80b8a402ed292b50aebafeaf827c62c2eed09e265fa5aa9e013c0f27f0a88259f1aaa1279f0c32000000000000000000000000000000000000000000000000016345785d8a0000df871242dcbcc4fe9ed4d3413e21b2f8ce606a3ee7128c9b2d2e31fcedc1848e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000004b2d0d6c2c785217457b69b922a2a9cea98f71e91ca0ed6a4942a78c7ae6eb3c9dec496459a9ef68b34cb389acd939d13d3ecaf7e4aca021bb77e80fc60acf25a7a01cc1272b1b76594a521fb1abe1322d650e58a672c2","tx_hash":"c2d206e665aee159a5ab9aff60f76444e97bdad8f9152eccb6ca07d9204974ca"}}},{"timestamp":1608542349373,"event":{"type":"Finished"}}],"maker_amount":"0.1","maker_coin":"ETH","taker_amount":"0.1","taker_coin":"RICK","gui":"nogui","mm_version":"1a6082121","success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"]}"#; let taker_saved_swap: TakerSavedSwap = json::from_str(taker_saved_json).unwrap(); TestCoin::ticker.mock_safe(|_| MockResult::Return("ticker")); @@ -3121,7 +3121,7 @@ mod taker_swap_tests { fn test_recoverable() { // Swap ended with MakerPaymentWaitConfirmFailed event. // MM2 did not attempt to send the payment in this case so swap is not recoverable. - let swap: TakerSavedSwap = json::from_str(r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.12596566232185483","maker_coin":"KMD","maker_coin_start_block":1458035,"maker_payment_confirmations":1,"maker_payment_wait":1564053079,"my_persistent_pub":"0326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0a","started_at":1564050479,"taker_amount":"50.000000000000001504212457800000","taker_coin":"DOGE","taker_coin_start_block":2823448,"taker_payment_confirmations":1,"taker_payment_lock":1564058279,"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"},"type":"Started"},"timestamp":1564050480269},{"event":{"data":{"maker_payment_locktime":1564066080,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"3669eb83a007a3c507448d79f45a9f06ec2f36a8"},"type":"Negotiated"},"timestamp":1564050540991},{"event":{"data":{"tx_hash":"bdde828b492d6d1cc25cd2322fd592dafd722fcc7d8b0fedce4d3bb4a1a8c8ff","tx_hex":"0100000002c7efa995c8b7be0a8b6c2d526c6c444c1634d65584e9ee89904e9d8675eac88c010000006a473044022051f34d5e3b7d0b9098d5e35333f3550f9cb9e57df83d5e4635b7a8d2986d6d5602200288c98da05de6950e01229a637110a1800ba643e75cfec59d4eb1021ad9b40801210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffffae6c233989efa7c7d2aa6534adc96078917ff395b7f09f734a147b2f44ade164000000006a4730440220393a784c2da74d0e2a28ec4f7df6c8f9d8b2af6ae6957f1e68346d744223a8fd02201b7a96954ac06815a43a6c7668d829ae9cbb5de76fa77189ddfd9e3038df662c01210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffff02115f5800000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac41a84641020000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac6d84395d"},"type":"TakerFeeSent"},"timestamp":1564050545296},{"event":{"data":{"tx_hash":"0a0f11fa82802c2c30862c50ab2162185dae8de7f7235f32c506f814c142b382","tx_hex":"0400008085202f8902ace337db2dd4c56b0697f58fb8cfb6bd1cd6f469d925fc0376d1dcfb7581bf82000000006b483045022100d1f95be235c5c8880f5d703ace287e2768548792c58c5dbd27f5578881b30ea70220030596106e21c7e0057ee0dab283f9a1fe273f15208cba80870c447bd559ef0d0121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff9f339752567c404427fd77f2b35cecdb4c21489edc64e25e729fdb281785e423000000006a47304402203179e95877dbc107123a417f1e648e3ff13d384890f1e4a67b6dd5087235152e0220102a8ab799fadb26b5d89ceb9c7bc721a7e0c2a0d0d7e46bbe0cf3d130010d430121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff025635c0000000000017a91480a95d366d65e34a465ab17b0c9eb1d5a33bae08876cbfce05000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac8d7c395d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1564050588176},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1564050588178},{"event":{"data":{"error":"error"},"type":"MakerPaymentWaitConfirmFailed"},"timestamp":1564051092897},{"event":{"type":"Finished"},"timestamp":1564051092900}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"}"#).unwrap(); + let swap: TakerSavedSwap = json::from_str(r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","MakerPaymentSpendConfirmFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefunded","TakerPaymentRefundedByWatcher","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_pubkey":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.12596566232185483","maker_coin":"KMD","maker_coin_start_block":1458035,"maker_payment_confirmations":1,"maker_payment_wait":1564053079,"my_persistent_pub":"0326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0a","started_at":1564050479,"taker_amount":"50.000000000000001504212457800000","taker_coin":"DOGE","taker_coin_start_block":2823448,"taker_payment_confirmations":1,"taker_payment_lock":1564058279,"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"},"type":"Started"},"timestamp":1564050480269},{"event":{"data":{"maker_payment_locktime":1564066080,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"3669eb83a007a3c507448d79f45a9f06ec2f36a8"},"type":"Negotiated"},"timestamp":1564050540991},{"event":{"data":{"tx_hash":"bdde828b492d6d1cc25cd2322fd592dafd722fcc7d8b0fedce4d3bb4a1a8c8ff","tx_hex":"0100000002c7efa995c8b7be0a8b6c2d526c6c444c1634d65584e9ee89904e9d8675eac88c010000006a473044022051f34d5e3b7d0b9098d5e35333f3550f9cb9e57df83d5e4635b7a8d2986d6d5602200288c98da05de6950e01229a637110a1800ba643e75cfec59d4eb1021ad9b40801210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffffae6c233989efa7c7d2aa6534adc96078917ff395b7f09f734a147b2f44ade164000000006a4730440220393a784c2da74d0e2a28ec4f7df6c8f9d8b2af6ae6957f1e68346d744223a8fd02201b7a96954ac06815a43a6c7668d829ae9cbb5de76fa77189ddfd9e3038df662c01210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffff02115f5800000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac41a84641020000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac6d84395d"},"type":"TakerFeeSent"},"timestamp":1564050545296},{"event":{"data":{"tx_hash":"0a0f11fa82802c2c30862c50ab2162185dae8de7f7235f32c506f814c142b382","tx_hex":"0400008085202f8902ace337db2dd4c56b0697f58fb8cfb6bd1cd6f469d925fc0376d1dcfb7581bf82000000006b483045022100d1f95be235c5c8880f5d703ace287e2768548792c58c5dbd27f5578881b30ea70220030596106e21c7e0057ee0dab283f9a1fe273f15208cba80870c447bd559ef0d0121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff9f339752567c404427fd77f2b35cecdb4c21489edc64e25e729fdb281785e423000000006a47304402203179e95877dbc107123a417f1e648e3ff13d384890f1e4a67b6dd5087235152e0220102a8ab799fadb26b5d89ceb9c7bc721a7e0c2a0d0d7e46bbe0cf3d130010d430121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff025635c0000000000017a91480a95d366d65e34a465ab17b0c9eb1d5a33bae08876cbfce05000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac8d7c395d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1564050588176},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1564050588178},{"event":{"data":{"error":"error"},"type":"MakerPaymentWaitConfirmFailed"},"timestamp":1564051092897},{"event":{"type":"Finished"},"timestamp":1564051092900}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"}"#).unwrap(); assert!(!swap.is_recoverable()); } @@ -3214,7 +3214,7 @@ mod taker_swap_tests { "data": { "taker_coin": "MORTY", "maker_coin": "RICK", - "maker": "15d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", + "maker_pubkey": "15d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732", "my_persistent_pub": "03ad6f89abc2e5beaa8a3ac28e22170659b3209fe2ddf439681b4b8f31508c36fa", "lock_duration": 7800, "maker_amount": "0.1", From 653e0744c7e0ff0773c8fb2d228033dbd43c606d Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 12 Dec 2024 19:53:34 +0700 Subject: [PATCH 49/59] update maker and taker pubkey fields in test jsons in swaps_file_lock_tests.rs --- .../mm2_main/tests/docker_tests/swaps_file_lock_tests.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm2src/mm2_main/tests/docker_tests/swaps_file_lock_tests.rs b/mm2src/mm2_main/tests/docker_tests/swaps_file_lock_tests.rs index 785eb0a849..ec2e8ca29e 100644 --- a/mm2src/mm2_main/tests/docker_tests/swaps_file_lock_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/swaps_file_lock_tests.rs @@ -10,11 +10,11 @@ use serde_json::Value as Json; use std::thread; use std::time::Duration; -const UNFINISHED_MAKER_SWAP: &str = r#"{"type":"Maker","uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","events":[{"timestamp":1588244036250,"event":{"type":"Started","data":{"taker_coin":"MYCOIN1","maker_coin":"MYCOIN","taker":"859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521","secret":"dedf3c8dcfff9ee2787b4bf211f960fd044fdab7fa8e922ef613a0115848a498","secret_hash":"9304bce3196f344b2a22dc99db406e95ab6f3107","my_persistent_pub":"02987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4d","lock_duration":7800,"maker_amount":"999.99999","taker_amount":"999.99999","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":1,"taker_payment_requires_nota":false,"maker_payment_lock":1588259636,"uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","started_at":1588244036,"maker_coin_start_block":12,"taker_coin_start_block":11}}},{"timestamp":1588244038035,"event":{"type":"Negotiated","data":{"taker_payment_locktime":1588251836,"taker_pubkey":"02859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521"}}}],"maker_amount":"999.99999","maker_coin":"MYCOIN","taker_amount":"999.99999","taker_coin":"MYCOIN1","gui":"nogui","mm_version":"UNKNOWN","success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","MakerPaymentWaitConfirmFailed","TakerPaymentValidateFailed","TakerPaymentWaitConfirmFailed","TakerPaymentSpendFailed","MakerPaymentWaitRefundStarted","MakerPaymentRefunded","MakerPaymentRefundFailed"]}"#; -const FINISHED_MAKER_SWAP: &str = r#"{"type":"Maker","uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","events":[{"timestamp":1588244036250,"event":{"type":"Started","data":{"taker_coin":"MYCOIN1","maker_coin":"MYCOIN","taker":"859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521","secret":"dedf3c8dcfff9ee2787b4bf211f960fd044fdab7fa8e922ef613a0115848a498","secret_hash":"9304bce3196f344b2a22dc99db406e95ab6f3107","my_persistent_pub":"02987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4d","lock_duration":7800,"maker_amount":"999.99999","taker_amount":"999.99999","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":1,"taker_payment_requires_nota":false,"maker_payment_lock":1588259636,"uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","started_at":1588244036,"maker_coin_start_block":12,"taker_coin_start_block":11}}},{"timestamp":1588244038035,"event":{"type":"Negotiated","data":{"taker_payment_locktime":1588251836,"taker_pubkey":"02859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521"}}},{"timestamp":1588244038463,"event":{"type":"TakerFeeValidated","data":{"tx_hex":"0400008085202f8901bdde9bca02870787441f6068e4c2a869a3aac3d1d0925f6a6e27874343544d0a010000006a47304402206694a794693b55fbe8205cb1cbb992d92fa2a9a851763ad1bf1628c16deaf73e02203cfff465504bdd6c51e8fbd45dd2e1187142fdc29e82f36f577616d9d6097d7a012102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ffffffff02dfceab07000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac39fd41892e0000001976a914d24e799df360da3ca3158d63b89ffaff27722c1588ac46aeaa5e000000000000000000000000000000","tx_hash":"7118d7484d1cbfdd6126673a848a228856f8748d946f6a9a440c90f0d62e27c6","from":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"to":["RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf","RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"total_amount":"2000","spent_by_me":"0","received_by_me":"0","my_balance_change":"0","block_height":13,"timestamp":1588244038,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"7118d7484d1cbfdd6126673a848a228856f8748d946f6a9a440c90f0d62e27c6"}}},{"timestamp":1588244038505,"event":{"type":"MakerPaymentSent","data":{"tx_hex":"0400008085202f890163cc0aceb3b432f84c1407991a0389b74b7842f030aa261203aa0b4b9a9a15fd010000006b483045022100f3239794b7b0e1c75aae084a65535270f154231ce86a4739976ff69eeff1ebd402206c0aeb28b7b4b2e77e98b3c3efd9a20d85c2cd0627acc3f45d577c0e88c34fb4012102987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4dffffffff0118e476481700000017a914dc4ed4686174503b85374bfb0aefe07a9fb37bcf8746aeaa5e000000000000000000000000000000","tx_hash":"9a4c0b3f85ed0bb24dc9575ce7c2fd6bc50ad9d37c91c478946f9c33d15abfdf","from":["RAzSdYQhjCFdyhjrBz1AZQDVg3Hu8DrzYc"],"to":["bYp9ncp3V7FYsymipriVbdd3QL72hK9hio"],"total_amount":"1000","spent_by_me":"1000","received_by_me":"0","my_balance_change":"-1000","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN","internal_id":"9a4c0b3f85ed0bb24dc9575ce7c2fd6bc50ad9d37c91c478946f9c33d15abfdf"}}},{"timestamp":1588244053938,"event":{"type":"TakerPaymentReceived","data":{"tx_hex":"0400008085202f8901c6272ed6f0900c449a6a6f948d74f85688228a843a672661ddbf1c4d48d71871010000006b483045022100c37627385c66b7bdf466b4dd4e7095b7551e6f5ea35f9bcc6344eb629f2edcb202203280eaba64b4d72010500166fab62cf34a687a516b2fe83d4eceaf8572cb37a7012102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ffffffff0218e476481700000017a91431ff75ed72cd135a7ce50d121e71efc37066b9f9873915cb40170000001976a914d24e799df360da3ca3158d63b89ffaff27722c1588ac55aeaa5e000000000000000000000000000000","tx_hash":"b4718ce94aa43f9073ab0b70c18ab4ea4b587338fb7110f20ff7d1bb452df08f","from":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"to":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC","bHHdqM8XWDHee2oyzydwUJKEE2BjofEtZH"],"total_amount":"1998.71298873","spent_by_me":"0","received_by_me":"0","my_balance_change":"0","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"b4718ce94aa43f9073ab0b70c18ab4ea4b587338fb7110f20ff7d1bb452df08f"}}},{"timestamp":1588244053939,"event":{"type":"TakerPaymentWaitConfirmStarted"}},{"timestamp":1588244068951,"event":{"type":"TakerPaymentValidatedAndConfirmed"}},{"timestamp":1588244068959,"event":{"type":"TakerPaymentSpent","data":{"tx_hex":"0400008085202f89018ff02d45bbd1f70ff21071fb3873584beab48ac1700bab73903fa44ae98c71b400000000d747304402204f0d641a3916e54d6788744c3229110a431eff18634c66fbd1741f9ca7dba99d02202315ee1d9317cc4d5d75d01f066f2c8a59876f790106d310144cdc03c25f985e0120dedf3c8dcfff9ee2787b4bf211f960fd044fdab7fa8e922ef613a0115848a498004c6b6304bcccaa5eb1752102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ac6782012088a9149304bce3196f344b2a22dc99db406e95ab6f3107882102987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4dac68ffffffff0130e07648170000001976a91412c553e8469363f2d30268c475af1e9186cc90af88ac54a0aa5e000000000000000000000000000000","tx_hash":"e7aed7a77e47b44dc9d12166589bbade70faea10b64888f73ed4be04bcc9f9a9","from":["bHHdqM8XWDHee2oyzydwUJKEE2BjofEtZH"],"to":["RAzSdYQhjCFdyhjrBz1AZQDVg3Hu8DrzYc"],"total_amount":"999.99999","spent_by_me":"0","received_by_me":"999.99998","my_balance_change":"999.99998","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"e7aed7a77e47b44dc9d12166589bbade70faea10b64888f73ed4be04bcc9f9a9"}}},{"timestamp":1588244068960,"event":{"type":"Finished"}}],"maker_amount":"999.99999","maker_coin":"MYCOIN","taker_amount":"999.99999","taker_coin":"MYCOIN1","gui":"nogui","mm_version":"UNKNOWN","success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","MakerPaymentWaitConfirmFailed","TakerPaymentValidateFailed","TakerPaymentWaitConfirmFailed","TakerPaymentSpendFailed","MakerPaymentWaitRefundStarted","MakerPaymentRefunded","MakerPaymentRefundFailed"]}"#; +const UNFINISHED_MAKER_SWAP: &str = r#"{"type":"Maker","uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","events":[{"timestamp":1588244036250,"event":{"type":"Started","data":{"taker_coin":"MYCOIN1","maker_coin":"MYCOIN","taker_pubkey":"859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521","secret":"dedf3c8dcfff9ee2787b4bf211f960fd044fdab7fa8e922ef613a0115848a498","secret_hash":"9304bce3196f344b2a22dc99db406e95ab6f3107","my_persistent_pub":"02987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4d","lock_duration":7800,"maker_amount":"999.99999","taker_amount":"999.99999","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":1,"taker_payment_requires_nota":false,"maker_payment_lock":1588259636,"uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","started_at":1588244036,"maker_coin_start_block":12,"taker_coin_start_block":11}}},{"timestamp":1588244038035,"event":{"type":"Negotiated","data":{"taker_payment_locktime":1588251836,"taker_pubkey":"02859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521"}}}],"maker_amount":"999.99999","maker_coin":"MYCOIN","taker_amount":"999.99999","taker_coin":"MYCOIN1","gui":"nogui","mm_version":"UNKNOWN","success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","MakerPaymentWaitConfirmFailed","TakerPaymentValidateFailed","TakerPaymentWaitConfirmFailed","TakerPaymentSpendFailed","MakerPaymentWaitRefundStarted","MakerPaymentRefunded","MakerPaymentRefundFailed"]}"#; +const FINISHED_MAKER_SWAP: &str = r#"{"type":"Maker","uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","events":[{"timestamp":1588244036250,"event":{"type":"Started","data":{"taker_coin":"MYCOIN1","maker_coin":"MYCOIN","taker_pubkey":"859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521","secret":"dedf3c8dcfff9ee2787b4bf211f960fd044fdab7fa8e922ef613a0115848a498","secret_hash":"9304bce3196f344b2a22dc99db406e95ab6f3107","my_persistent_pub":"02987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4d","lock_duration":7800,"maker_amount":"999.99999","taker_amount":"999.99999","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":1,"taker_payment_requires_nota":false,"maker_payment_lock":1588259636,"uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","started_at":1588244036,"maker_coin_start_block":12,"taker_coin_start_block":11}}},{"timestamp":1588244038035,"event":{"type":"Negotiated","data":{"taker_payment_locktime":1588251836,"taker_pubkey":"02859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521"}}},{"timestamp":1588244038463,"event":{"type":"TakerFeeValidated","data":{"tx_hex":"0400008085202f8901bdde9bca02870787441f6068e4c2a869a3aac3d1d0925f6a6e27874343544d0a010000006a47304402206694a794693b55fbe8205cb1cbb992d92fa2a9a851763ad1bf1628c16deaf73e02203cfff465504bdd6c51e8fbd45dd2e1187142fdc29e82f36f577616d9d6097d7a012102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ffffffff02dfceab07000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac39fd41892e0000001976a914d24e799df360da3ca3158d63b89ffaff27722c1588ac46aeaa5e000000000000000000000000000000","tx_hash":"7118d7484d1cbfdd6126673a848a228856f8748d946f6a9a440c90f0d62e27c6","from":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"to":["RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf","RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"total_amount":"2000","spent_by_me":"0","received_by_me":"0","my_balance_change":"0","block_height":13,"timestamp":1588244038,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"7118d7484d1cbfdd6126673a848a228856f8748d946f6a9a440c90f0d62e27c6"}}},{"timestamp":1588244038505,"event":{"type":"MakerPaymentSent","data":{"tx_hex":"0400008085202f890163cc0aceb3b432f84c1407991a0389b74b7842f030aa261203aa0b4b9a9a15fd010000006b483045022100f3239794b7b0e1c75aae084a65535270f154231ce86a4739976ff69eeff1ebd402206c0aeb28b7b4b2e77e98b3c3efd9a20d85c2cd0627acc3f45d577c0e88c34fb4012102987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4dffffffff0118e476481700000017a914dc4ed4686174503b85374bfb0aefe07a9fb37bcf8746aeaa5e000000000000000000000000000000","tx_hash":"9a4c0b3f85ed0bb24dc9575ce7c2fd6bc50ad9d37c91c478946f9c33d15abfdf","from":["RAzSdYQhjCFdyhjrBz1AZQDVg3Hu8DrzYc"],"to":["bYp9ncp3V7FYsymipriVbdd3QL72hK9hio"],"total_amount":"1000","spent_by_me":"1000","received_by_me":"0","my_balance_change":"-1000","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN","internal_id":"9a4c0b3f85ed0bb24dc9575ce7c2fd6bc50ad9d37c91c478946f9c33d15abfdf"}}},{"timestamp":1588244053938,"event":{"type":"TakerPaymentReceived","data":{"tx_hex":"0400008085202f8901c6272ed6f0900c449a6a6f948d74f85688228a843a672661ddbf1c4d48d71871010000006b483045022100c37627385c66b7bdf466b4dd4e7095b7551e6f5ea35f9bcc6344eb629f2edcb202203280eaba64b4d72010500166fab62cf34a687a516b2fe83d4eceaf8572cb37a7012102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ffffffff0218e476481700000017a91431ff75ed72cd135a7ce50d121e71efc37066b9f9873915cb40170000001976a914d24e799df360da3ca3158d63b89ffaff27722c1588ac55aeaa5e000000000000000000000000000000","tx_hash":"b4718ce94aa43f9073ab0b70c18ab4ea4b587338fb7110f20ff7d1bb452df08f","from":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"to":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC","bHHdqM8XWDHee2oyzydwUJKEE2BjofEtZH"],"total_amount":"1998.71298873","spent_by_me":"0","received_by_me":"0","my_balance_change":"0","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"b4718ce94aa43f9073ab0b70c18ab4ea4b587338fb7110f20ff7d1bb452df08f"}}},{"timestamp":1588244053939,"event":{"type":"TakerPaymentWaitConfirmStarted"}},{"timestamp":1588244068951,"event":{"type":"TakerPaymentValidatedAndConfirmed"}},{"timestamp":1588244068959,"event":{"type":"TakerPaymentSpent","data":{"tx_hex":"0400008085202f89018ff02d45bbd1f70ff21071fb3873584beab48ac1700bab73903fa44ae98c71b400000000d747304402204f0d641a3916e54d6788744c3229110a431eff18634c66fbd1741f9ca7dba99d02202315ee1d9317cc4d5d75d01f066f2c8a59876f790106d310144cdc03c25f985e0120dedf3c8dcfff9ee2787b4bf211f960fd044fdab7fa8e922ef613a0115848a498004c6b6304bcccaa5eb1752102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ac6782012088a9149304bce3196f344b2a22dc99db406e95ab6f3107882102987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4dac68ffffffff0130e07648170000001976a91412c553e8469363f2d30268c475af1e9186cc90af88ac54a0aa5e000000000000000000000000000000","tx_hash":"e7aed7a77e47b44dc9d12166589bbade70faea10b64888f73ed4be04bcc9f9a9","from":["bHHdqM8XWDHee2oyzydwUJKEE2BjofEtZH"],"to":["RAzSdYQhjCFdyhjrBz1AZQDVg3Hu8DrzYc"],"total_amount":"999.99999","spent_by_me":"0","received_by_me":"999.99998","my_balance_change":"999.99998","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"e7aed7a77e47b44dc9d12166589bbade70faea10b64888f73ed4be04bcc9f9a9"}}},{"timestamp":1588244068960,"event":{"type":"Finished"}}],"maker_amount":"999.99999","maker_coin":"MYCOIN","taker_amount":"999.99999","taker_coin":"MYCOIN1","gui":"nogui","mm_version":"UNKNOWN","success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","MakerPaymentWaitConfirmFailed","TakerPaymentValidateFailed","TakerPaymentWaitConfirmFailed","TakerPaymentSpendFailed","MakerPaymentWaitRefundStarted","MakerPaymentRefunded","MakerPaymentRefundFailed"]}"#; -const UNFINISHED_TAKER_SWAP: &str = r#"{"type":"Taker","uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","events":[{"timestamp":1588244036253,"event":{"type":"Started","data":{"taker_coin":"MYCOIN1","maker_coin":"MYCOIN","maker":"987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4d","my_persistent_pub":"02859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521","lock_duration":7800,"maker_amount":"999.99999","taker_amount":"999.99999","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":1,"taker_payment_requires_nota":false,"taker_payment_lock":1588251836,"uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","started_at":1588244036,"maker_payment_wait":1588247156,"maker_coin_start_block":12,"taker_coin_start_block":11}}},{"timestamp":1588244038239,"event":{"type":"Negotiated","data":{"maker_payment_locktime":1588259636,"maker_pubkey":"02987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4d","secret_hash":"9304bce3196f344b2a22dc99db406e95ab6f3107"}}},{"timestamp":1588244038271,"event":{"type":"TakerFeeSent","data":{"tx_hex":"0400008085202f8901bdde9bca02870787441f6068e4c2a869a3aac3d1d0925f6a6e27874343544d0a010000006a47304402206694a794693b55fbe8205cb1cbb992d92fa2a9a851763ad1bf1628c16deaf73e02203cfff465504bdd6c51e8fbd45dd2e1187142fdc29e82f36f577616d9d6097d7a012102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ffffffff02dfceab07000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac39fd41892e0000001976a914d24e799df360da3ca3158d63b89ffaff27722c1588ac46aeaa5e000000000000000000000000000000","tx_hash":"7118d7484d1cbfdd6126673a848a228856f8748d946f6a9a440c90f0d62e27c6","from":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"to":["RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf","RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"total_amount":"2000","spent_by_me":"2000","received_by_me":"1998.71298873","my_balance_change":"-1.28701127","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"7118d7484d1cbfdd6126673a848a228856f8748d946f6a9a440c90f0d62e27c6"}}}],"maker_amount":"999.99999","maker_coin":"MYCOIN","taker_amount":"999.99999","taker_coin":"MYCOIN1","gui":"nogui","mm_version":"UNKNOWN","success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefunded","TakerPaymentRefundFailed"]}"#; -const FINISHED_TAKER_SWAP: &str = r#"{"type":"Taker","uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","events":[{"timestamp":1588244036253,"event":{"type":"Started","data":{"taker_coin":"MYCOIN1","maker_coin":"MYCOIN","maker":"987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4d","my_persistent_pub":"02859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521","lock_duration":7800,"maker_amount":"999.99999","taker_amount":"999.99999","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":1,"taker_payment_requires_nota":false,"taker_payment_lock":1588251836,"uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","started_at":1588244036,"maker_payment_wait":1588247156,"maker_coin_start_block":12,"taker_coin_start_block":11}}},{"timestamp":1588244038239,"event":{"type":"Negotiated","data":{"maker_payment_locktime":1588259636,"maker_pubkey":"02987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4d","secret_hash":"9304bce3196f344b2a22dc99db406e95ab6f3107"}}},{"timestamp":1588244038271,"event":{"type":"TakerFeeSent","data":{"tx_hex":"0400008085202f8901bdde9bca02870787441f6068e4c2a869a3aac3d1d0925f6a6e27874343544d0a010000006a47304402206694a794693b55fbe8205cb1cbb992d92fa2a9a851763ad1bf1628c16deaf73e02203cfff465504bdd6c51e8fbd45dd2e1187142fdc29e82f36f577616d9d6097d7a012102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ffffffff02dfceab07000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac39fd41892e0000001976a914d24e799df360da3ca3158d63b89ffaff27722c1588ac46aeaa5e000000000000000000000000000000","tx_hash":"7118d7484d1cbfdd6126673a848a228856f8748d946f6a9a440c90f0d62e27c6","from":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"to":["RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf","RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"total_amount":"2000","spent_by_me":"2000","received_by_me":"1998.71298873","my_balance_change":"-1.28701127","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"7118d7484d1cbfdd6126673a848a228856f8748d946f6a9a440c90f0d62e27c6"}}},{"timestamp":1588244038698,"event":{"type":"MakerPaymentReceived","data":{"tx_hex":"0400008085202f890163cc0aceb3b432f84c1407991a0389b74b7842f030aa261203aa0b4b9a9a15fd010000006b483045022100f3239794b7b0e1c75aae084a65535270f154231ce86a4739976ff69eeff1ebd402206c0aeb28b7b4b2e77e98b3c3efd9a20d85c2cd0627acc3f45d577c0e88c34fb4012102987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4dffffffff0118e476481700000017a914dc4ed4686174503b85374bfb0aefe07a9fb37bcf8746aeaa5e000000000000000000000000000000","tx_hash":"9a4c0b3f85ed0bb24dc9575ce7c2fd6bc50ad9d37c91c478946f9c33d15abfdf","from":["RAzSdYQhjCFdyhjrBz1AZQDVg3Hu8DrzYc"],"to":["bYp9ncp3V7FYsymipriVbdd3QL72hK9hio"],"total_amount":"1000","spent_by_me":"0","received_by_me":"0","my_balance_change":"0","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN","internal_id":"9a4c0b3f85ed0bb24dc9575ce7c2fd6bc50ad9d37c91c478946f9c33d15abfdf"}}},{"timestamp":1588244038699,"event":{"type":"MakerPaymentWaitConfirmStarted"}},{"timestamp":1588244053712,"event":{"type":"MakerPaymentValidatedAndConfirmed"}},{"timestamp":1588244053745,"event":{"type":"TakerPaymentSent","data":{"tx_hex":"0400008085202f8901c6272ed6f0900c449a6a6f948d74f85688228a843a672661ddbf1c4d48d71871010000006b483045022100c37627385c66b7bdf466b4dd4e7095b7551e6f5ea35f9bcc6344eb629f2edcb202203280eaba64b4d72010500166fab62cf34a687a516b2fe83d4eceaf8572cb37a7012102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ffffffff0218e476481700000017a91431ff75ed72cd135a7ce50d121e71efc37066b9f9873915cb40170000001976a914d24e799df360da3ca3158d63b89ffaff27722c1588ac55aeaa5e000000000000000000000000000000","tx_hash":"b4718ce94aa43f9073ab0b70c18ab4ea4b587338fb7110f20ff7d1bb452df08f","from":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"to":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC","bHHdqM8XWDHee2oyzydwUJKEE2BjofEtZH"],"total_amount":"1998.71298873","spent_by_me":"1998.71298873","received_by_me":"998.71298873","my_balance_change":"-1000","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"b4718ce94aa43f9073ab0b70c18ab4ea4b587338fb7110f20ff7d1bb452df08f"}}},{"timestamp":1588244078860,"event":{"type":"TakerPaymentSpent","data":{"transaction":{"tx_hex":"0400008085202f89018ff02d45bbd1f70ff21071fb3873584beab48ac1700bab73903fa44ae98c71b400000000d747304402204f0d641a3916e54d6788744c3229110a431eff18634c66fbd1741f9ca7dba99d02202315ee1d9317cc4d5d75d01f066f2c8a59876f790106d310144cdc03c25f985e0120dedf3c8dcfff9ee2787b4bf211f960fd044fdab7fa8e922ef613a0115848a498004c6b6304bcccaa5eb1752102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ac6782012088a9149304bce3196f344b2a22dc99db406e95ab6f3107882102987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4dac68ffffffff0130e07648170000001976a91412c553e8469363f2d30268c475af1e9186cc90af88ac54a0aa5e000000000000000000000000000000","tx_hash":"e7aed7a77e47b44dc9d12166589bbade70faea10b64888f73ed4be04bcc9f9a9","from":["bHHdqM8XWDHee2oyzydwUJKEE2BjofEtZH"],"to":["RAzSdYQhjCFdyhjrBz1AZQDVg3Hu8DrzYc"],"total_amount":"999.99999","spent_by_me":"0","received_by_me":"0","my_balance_change":"0","block_height":29,"timestamp":1588244070,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"e7aed7a77e47b44dc9d12166589bbade70faea10b64888f73ed4be04bcc9f9a9"},"secret":"dedf3c8dcfff9ee2787b4bf211f960fd044fdab7fa8e922ef613a0115848a498"}}},{"timestamp":1588244078870,"event":{"type":"MakerPaymentSpent","data":{"tx_hex":"0400008085202f8901dfbf5ad1339c6f9478c4917cd3d90ac56bfdc2e75c57c94db20bed853f0b4c9a00000000d848304502210092535c081325ba5261699d7cfd4c503fb6125dde86389b83f40f3e2c006039bb022063cfd72aa15558dee874cac08b22dbcf11d3f06c8e48b0ddaf75b86887d604410120dedf3c8dcfff9ee2787b4bf211f960fd044fdab7fa8e922ef613a0115848a498004c6b630434ebaa5eb1752102987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4dac6782012088a9149304bce3196f344b2a22dc99db406e95ab6f3107882102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ac68ffffffff0130e07648170000001976a914d24e799df360da3ca3158d63b89ffaff27722c1588ac5ea0aa5e000000000000000000000000000000","tx_hash":"caea128b1c85a88abd5924e512780ee18952dadc217b0c06f4b2820eb71d03bc","from":["bYp9ncp3V7FYsymipriVbdd3QL72hK9hio"],"to":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"total_amount":"999.99999","spent_by_me":"0","received_by_me":"999.99998","my_balance_change":"999.99998","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN","internal_id":"caea128b1c85a88abd5924e512780ee18952dadc217b0c06f4b2820eb71d03bc"}}},{"timestamp":1588244078871,"event":{"type":"MakerPaymentSpendConfirmed"}},{"timestamp":1588244078872,"event":{"type":"Finished"}}],"maker_amount":"999.99999","maker_coin":"MYCOIN","taker_amount":"999.99999","taker_coin":"MYCOIN1","gui":"nogui","mm_version":"UNKNOWN","success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefunded","TakerPaymentRefundFailed"]}"#; +const UNFINISHED_TAKER_SWAP: &str = r#"{"type":"Taker","uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","events":[{"timestamp":1588244036253,"event":{"type":"Started","data":{"taker_coin":"MYCOIN1","maker_coin":"MYCOIN","maker_pubkey":"987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4d","my_persistent_pub":"02859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521","lock_duration":7800,"maker_amount":"999.99999","taker_amount":"999.99999","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":1,"taker_payment_requires_nota":false,"taker_payment_lock":1588251836,"uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","started_at":1588244036,"maker_payment_wait":1588247156,"maker_coin_start_block":12,"taker_coin_start_block":11}}},{"timestamp":1588244038239,"event":{"type":"Negotiated","data":{"maker_payment_locktime":1588259636,"maker_pubkey":"02987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4d","secret_hash":"9304bce3196f344b2a22dc99db406e95ab6f3107"}}},{"timestamp":1588244038271,"event":{"type":"TakerFeeSent","data":{"tx_hex":"0400008085202f8901bdde9bca02870787441f6068e4c2a869a3aac3d1d0925f6a6e27874343544d0a010000006a47304402206694a794693b55fbe8205cb1cbb992d92fa2a9a851763ad1bf1628c16deaf73e02203cfff465504bdd6c51e8fbd45dd2e1187142fdc29e82f36f577616d9d6097d7a012102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ffffffff02dfceab07000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac39fd41892e0000001976a914d24e799df360da3ca3158d63b89ffaff27722c1588ac46aeaa5e000000000000000000000000000000","tx_hash":"7118d7484d1cbfdd6126673a848a228856f8748d946f6a9a440c90f0d62e27c6","from":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"to":["RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf","RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"total_amount":"2000","spent_by_me":"2000","received_by_me":"1998.71298873","my_balance_change":"-1.28701127","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"7118d7484d1cbfdd6126673a848a228856f8748d946f6a9a440c90f0d62e27c6"}}}],"maker_amount":"999.99999","maker_coin":"MYCOIN","taker_amount":"999.99999","taker_coin":"MYCOIN1","gui":"nogui","mm_version":"UNKNOWN","success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefunded","TakerPaymentRefundFailed"]}"#; +const FINISHED_TAKER_SWAP: &str = r#"{"type":"Taker","uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","events":[{"timestamp":1588244036253,"event":{"type":"Started","data":{"taker_coin":"MYCOIN1","maker_coin":"MYCOIN","maker_pubkey":"987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4d","my_persistent_pub":"02859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521","lock_duration":7800,"maker_amount":"999.99999","taker_amount":"999.99999","maker_payment_confirmations":1,"maker_payment_requires_nota":false,"taker_payment_confirmations":1,"taker_payment_requires_nota":false,"taker_payment_lock":1588251836,"uuid":"5acb0e63-8b26-469e-81df-7dd9e4a9ad15","started_at":1588244036,"maker_payment_wait":1588247156,"maker_coin_start_block":12,"taker_coin_start_block":11}}},{"timestamp":1588244038239,"event":{"type":"Negotiated","data":{"maker_payment_locktime":1588259636,"maker_pubkey":"02987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4d","secret_hash":"9304bce3196f344b2a22dc99db406e95ab6f3107"}}},{"timestamp":1588244038271,"event":{"type":"TakerFeeSent","data":{"tx_hex":"0400008085202f8901bdde9bca02870787441f6068e4c2a869a3aac3d1d0925f6a6e27874343544d0a010000006a47304402206694a794693b55fbe8205cb1cbb992d92fa2a9a851763ad1bf1628c16deaf73e02203cfff465504bdd6c51e8fbd45dd2e1187142fdc29e82f36f577616d9d6097d7a012102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ffffffff02dfceab07000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac39fd41892e0000001976a914d24e799df360da3ca3158d63b89ffaff27722c1588ac46aeaa5e000000000000000000000000000000","tx_hash":"7118d7484d1cbfdd6126673a848a228856f8748d946f6a9a440c90f0d62e27c6","from":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"to":["RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf","RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"total_amount":"2000","spent_by_me":"2000","received_by_me":"1998.71298873","my_balance_change":"-1.28701127","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"7118d7484d1cbfdd6126673a848a228856f8748d946f6a9a440c90f0d62e27c6"}}},{"timestamp":1588244038698,"event":{"type":"MakerPaymentReceived","data":{"tx_hex":"0400008085202f890163cc0aceb3b432f84c1407991a0389b74b7842f030aa261203aa0b4b9a9a15fd010000006b483045022100f3239794b7b0e1c75aae084a65535270f154231ce86a4739976ff69eeff1ebd402206c0aeb28b7b4b2e77e98b3c3efd9a20d85c2cd0627acc3f45d577c0e88c34fb4012102987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4dffffffff0118e476481700000017a914dc4ed4686174503b85374bfb0aefe07a9fb37bcf8746aeaa5e000000000000000000000000000000","tx_hash":"9a4c0b3f85ed0bb24dc9575ce7c2fd6bc50ad9d37c91c478946f9c33d15abfdf","from":["RAzSdYQhjCFdyhjrBz1AZQDVg3Hu8DrzYc"],"to":["bYp9ncp3V7FYsymipriVbdd3QL72hK9hio"],"total_amount":"1000","spent_by_me":"0","received_by_me":"0","my_balance_change":"0","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN","internal_id":"9a4c0b3f85ed0bb24dc9575ce7c2fd6bc50ad9d37c91c478946f9c33d15abfdf"}}},{"timestamp":1588244038699,"event":{"type":"MakerPaymentWaitConfirmStarted"}},{"timestamp":1588244053712,"event":{"type":"MakerPaymentValidatedAndConfirmed"}},{"timestamp":1588244053745,"event":{"type":"TakerPaymentSent","data":{"tx_hex":"0400008085202f8901c6272ed6f0900c449a6a6f948d74f85688228a843a672661ddbf1c4d48d71871010000006b483045022100c37627385c66b7bdf466b4dd4e7095b7551e6f5ea35f9bcc6344eb629f2edcb202203280eaba64b4d72010500166fab62cf34a687a516b2fe83d4eceaf8572cb37a7012102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ffffffff0218e476481700000017a91431ff75ed72cd135a7ce50d121e71efc37066b9f9873915cb40170000001976a914d24e799df360da3ca3158d63b89ffaff27722c1588ac55aeaa5e000000000000000000000000000000","tx_hash":"b4718ce94aa43f9073ab0b70c18ab4ea4b587338fb7110f20ff7d1bb452df08f","from":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"to":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC","bHHdqM8XWDHee2oyzydwUJKEE2BjofEtZH"],"total_amount":"1998.71298873","spent_by_me":"1998.71298873","received_by_me":"998.71298873","my_balance_change":"-1000","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"b4718ce94aa43f9073ab0b70c18ab4ea4b587338fb7110f20ff7d1bb452df08f"}}},{"timestamp":1588244078860,"event":{"type":"TakerPaymentSpent","data":{"transaction":{"tx_hex":"0400008085202f89018ff02d45bbd1f70ff21071fb3873584beab48ac1700bab73903fa44ae98c71b400000000d747304402204f0d641a3916e54d6788744c3229110a431eff18634c66fbd1741f9ca7dba99d02202315ee1d9317cc4d5d75d01f066f2c8a59876f790106d310144cdc03c25f985e0120dedf3c8dcfff9ee2787b4bf211f960fd044fdab7fa8e922ef613a0115848a498004c6b6304bcccaa5eb1752102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ac6782012088a9149304bce3196f344b2a22dc99db406e95ab6f3107882102987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4dac68ffffffff0130e07648170000001976a91412c553e8469363f2d30268c475af1e9186cc90af88ac54a0aa5e000000000000000000000000000000","tx_hash":"e7aed7a77e47b44dc9d12166589bbade70faea10b64888f73ed4be04bcc9f9a9","from":["bHHdqM8XWDHee2oyzydwUJKEE2BjofEtZH"],"to":["RAzSdYQhjCFdyhjrBz1AZQDVg3Hu8DrzYc"],"total_amount":"999.99999","spent_by_me":"0","received_by_me":"0","my_balance_change":"0","block_height":29,"timestamp":1588244070,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN1","internal_id":"e7aed7a77e47b44dc9d12166589bbade70faea10b64888f73ed4be04bcc9f9a9"},"secret":"dedf3c8dcfff9ee2787b4bf211f960fd044fdab7fa8e922ef613a0115848a498"}}},{"timestamp":1588244078870,"event":{"type":"MakerPaymentSpent","data":{"tx_hex":"0400008085202f8901dfbf5ad1339c6f9478c4917cd3d90ac56bfdc2e75c57c94db20bed853f0b4c9a00000000d848304502210092535c081325ba5261699d7cfd4c503fb6125dde86389b83f40f3e2c006039bb022063cfd72aa15558dee874cac08b22dbcf11d3f06c8e48b0ddaf75b86887d604410120dedf3c8dcfff9ee2787b4bf211f960fd044fdab7fa8e922ef613a0115848a498004c6b630434ebaa5eb1752102987d5f82205a55d789616f470ae9df48537f050ee050d501aa316651642a0a4dac6782012088a9149304bce3196f344b2a22dc99db406e95ab6f3107882102859a80b83941e4e8ff2f511080e3ea5021db4ba95caec30eb37864e71ae73521ac68ffffffff0130e07648170000001976a914d24e799df360da3ca3158d63b89ffaff27722c1588ac5ea0aa5e000000000000000000000000000000","tx_hash":"caea128b1c85a88abd5924e512780ee18952dadc217b0c06f4b2820eb71d03bc","from":["bYp9ncp3V7FYsymipriVbdd3QL72hK9hio"],"to":["RUTBzLtJNTn89Wkb6oZocbesKrjBDTRMrC"],"total_amount":"999.99999","spent_by_me":"0","received_by_me":"999.99998","my_balance_change":"999.99998","block_height":0,"timestamp":0,"fee_details":{"amount":"0.00001"},"coin":"MYCOIN","internal_id":"caea128b1c85a88abd5924e512780ee18952dadc217b0c06f4b2820eb71d03bc"}}},{"timestamp":1588244078871,"event":{"type":"MakerPaymentSpendConfirmed"}},{"timestamp":1588244078872,"event":{"type":"Finished"}}],"maker_amount":"999.99999","maker_coin":"MYCOIN","taker_amount":"999.99999","taker_coin":"MYCOIN1","gui":"nogui","mm_version":"UNKNOWN","success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","MakerPaymentSpendConfirmed","Finished"],"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefunded","TakerPaymentRefundFailed"]}"#; fn swap_file_lock_prevents_double_swap_start_on_kick_start(swap_json: &str) { let (_ctx, _, bob_priv_key) = generate_utxo_coin_with_random_privkey("MYCOIN", 1000.into()); From f8ba9751dd8d3ebf19f88bf93615cb410181729b Mon Sep 17 00:00:00 2001 From: laruh Date: Mon, 16 Dec 2024 21:14:12 +0700 Subject: [PATCH 50/59] revert "swap_version" field --- mm2src/mm2_main/src/lp_ordermatch.rs | 68 ++----------------- .../src/lp_ordermatch/my_orders_storage.rs | 2 - .../src/lp_ordermatch/new_protocol.rs | 8 +-- mm2src/mm2_main/src/ordermatch_tests.rs | 54 --------------- 4 files changed, 7 insertions(+), 125 deletions(-) diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index 1dbc3689f9..4874e3abc2 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -134,8 +134,6 @@ const TRIE_STATE_HISTORY_TIMEOUT: u64 = 3; const TRIE_ORDER_HISTORY_TIMEOUT: u64 = 300; #[cfg(test)] const TRIE_ORDER_HISTORY_TIMEOUT: u64 = 3; -/// Swap protocol version -const SWAP_VERSION: u32 = 2; pub type OrderbookP2PHandlerResult = Result<(), MmError>; @@ -1172,9 +1170,6 @@ pub struct TakerRequest { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] pub rel_protocol_info: Option>, - #[serde(default = "legacy_swap_version")] - #[serde(skip_serializing_if = "is_legacy_swap_version")] - pub swap_version: u32, } impl TakerRequest { @@ -1195,7 +1190,6 @@ impl TakerRequest { conf_settings: Some(message.conf_settings), base_protocol_info: message.base_protocol_info, rel_protocol_info: message.rel_protocol_info, - swap_version: message.swap_version, } } @@ -1241,7 +1235,6 @@ impl From for new_protocol::OrdermatchMessage { conf_settings: taker_order.request.conf_settings.unwrap(), base_protocol_info: taker_order.request.base_protocol_info, rel_protocol_info: taker_order.request.rel_protocol_info, - swap_version: taker_order.request.swap_version, }) } } @@ -1252,10 +1245,6 @@ impl TakerRequest { fn get_rel_amount(&self) -> &MmNumber { &self.rel_amount } } -fn legacy_swap_version() -> u32 { 1 } - -fn is_legacy_swap_version(swap_version: &u32) -> bool { *swap_version == 1 } - pub struct TakerOrderBuilder<'a> { base_coin: &'a MmCoinEnum, rel_coin: &'a MmCoinEnum, @@ -1271,7 +1260,6 @@ pub struct TakerOrderBuilder<'a> { min_volume: Option, timeout: u64, save_in_history: bool, - swap_version: u32, } pub enum TakerOrderBuildError { @@ -1351,7 +1339,6 @@ impl<'a> TakerOrderBuilder<'a> { order_type: OrderType::GoodTillCancelled, timeout: TAKER_ORDER_TIMEOUT, save_in_history: true, - swap_version: SWAP_VERSION, } } @@ -1415,17 +1402,6 @@ impl<'a> TakerOrderBuilder<'a> { self } - /// When a new [TakerOrderBuilder::new] is created, it sets [SWAP_VERSION] by default. - /// However, if user has not specified in the config to use TPU V2, - /// the TakerOrderBuilder's swap_version is changed to legacy. - /// In the future alls users will be using TPU V2 by default without "use_trading_proto_v2" configuration. - pub fn use_trading_proto_v2(mut self, use_trading_proto_v2: bool) -> Self { - if !use_trading_proto_v2 { - self.swap_version = 1; - } - self - } - /// Validate fields and build #[allow(clippy::result_large_err)] pub fn build(self) -> Result { @@ -1514,7 +1490,6 @@ impl<'a> TakerOrderBuilder<'a> { conf_settings: self.conf_settings, base_protocol_info: Some(base_protocol_info), rel_protocol_info: Some(rel_protocol_info), - swap_version: self.swap_version, }, matches: Default::default(), min_volume, @@ -1555,7 +1530,6 @@ impl<'a> TakerOrderBuilder<'a> { conf_settings: self.conf_settings, base_protocol_info: Some(base_protocol_info), rel_protocol_info: Some(rel_protocol_info), - swap_version: self.swap_version, }, matches: HashMap::new(), min_volume: Default::default(), @@ -1717,9 +1691,6 @@ pub struct MakerOrder { /// A custom priv key for more privacy to prevent linking orders of the same node between each other /// Commonly used with privacy coins (ARRR, ZCash, etc.) p2p_privkey: Option, - #[serde(default = "legacy_swap_version")] - #[serde(skip_serializing_if = "is_legacy_swap_version")] - pub swap_version: u32, } pub struct MakerOrderBuilder<'a> { @@ -1732,7 +1703,6 @@ pub struct MakerOrderBuilder<'a> { rel_orderbook_ticker: Option, conf_settings: Option, save_in_history: bool, - swap_version: u32, } pub enum MakerOrderBuildError { @@ -1882,7 +1852,6 @@ impl<'a> MakerOrderBuilder<'a> { price: 0.into(), conf_settings: None, save_in_history: true, - swap_version: SWAP_VERSION, } } @@ -1921,17 +1890,6 @@ impl<'a> MakerOrderBuilder<'a> { self } - /// When a new [MakerOrderBuilder::new] is created, it sets [SWAP_VERSION] by default. - /// However, if user has not specified in the config to use TPU V2, - /// the MakerOrderBuilder's swap_version is changed to legacy. - /// In the future alls users will be using TPU V2 by default without "use_trading_proto_v2" configuration. - pub fn use_trading_proto_v2(mut self, use_trading_proto_v2: bool) -> Self { - if !use_trading_proto_v2 { - self.swap_version = 1; - } - self - } - /// Build MakerOrder #[allow(clippy::result_large_err)] pub fn build(self) -> Result { @@ -1988,7 +1946,6 @@ impl<'a> MakerOrderBuilder<'a> { base_orderbook_ticker: self.base_orderbook_ticker, rel_orderbook_ticker: self.rel_orderbook_ticker, p2p_privkey, - swap_version: self.swap_version, }) } @@ -2013,7 +1970,6 @@ impl<'a> MakerOrderBuilder<'a> { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: self.swap_version, } } } @@ -2144,7 +2100,6 @@ impl From for MakerOrder { base_orderbook_ticker: taker_order.base_orderbook_ticker, rel_orderbook_ticker: taker_order.rel_orderbook_ticker, p2p_privkey: taker_order.p2p_privkey, - swap_version: taker_order.request.swap_version, }, // The "buy" taker order is recreated with reversed pair as Maker order is always considered as "sell" TakerAction::Buy => { @@ -2167,7 +2122,6 @@ impl From for MakerOrder { base_orderbook_ticker: taker_order.rel_orderbook_ticker, rel_orderbook_ticker: taker_order.base_orderbook_ticker, p2p_privkey: taker_order.p2p_privkey, - swap_version: taker_order.request.swap_version, } }, } @@ -2220,9 +2174,6 @@ pub struct MakerReserved { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] pub rel_protocol_info: Option>, - #[serde(default = "legacy_swap_version")] - #[serde(skip_serializing_if = "is_legacy_swap_version")] - pub swap_version: u32, } impl MakerReserved { @@ -2250,7 +2201,6 @@ impl MakerReserved { conf_settings: Some(message.conf_settings), base_protocol_info: message.base_protocol_info, rel_protocol_info: message.rel_protocol_info, - swap_version: message.swap_version, } } } @@ -2267,7 +2217,6 @@ impl From for new_protocol::OrdermatchMessage { conf_settings: maker_reserved.conf_settings.unwrap(), base_protocol_info: maker_reserved.base_protocol_info, rel_protocol_info: maker_reserved.rel_protocol_info, - swap_version: maker_reserved.swap_version, }) } } @@ -3048,9 +2997,8 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO }, }; - let alice_swap_v = maker_match.request.swap_version; - // Start legacy swap if taker uses legacy protocol (version 1) or if conditions for trading_proto_v2 aren't met. - if alice_swap_v == 1u32 || !ctx.use_trading_proto_v2() { + // TODO add alice swap protocol version check once protocol versioning is implemented + if !ctx.use_trading_proto_v2() { let params = LegacySwapParams { maker_coin: &maker_coin, taker_coin: &taker_coin, @@ -3269,9 +3217,8 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat uuid ); - let bob_swap_v = taker_match.reserved.swap_version; - // Start legacy swap if maker uses legacy protocol (version 1) or if conditions for trading_proto_v2 aren't met. - if bob_swap_v == 1u32 || !ctx.use_trading_proto_v2() { + // TODO add bob swap protocol version check once protocol versioning is implemented + if !ctx.use_trading_proto_v2() { let params = LegacySwapParams { maker_coin: &maker_coin, taker_coin: &taker_coin, @@ -3926,7 +3873,6 @@ async fn process_taker_request(ctx: MmArc, from_pubkey: H256Json, taker_request: }), base_protocol_info: Some(base_coin.coin_protocol_info(None)), rel_protocol_info: Some(rel_coin.coin_protocol_info(Some(rel_amount.clone()))), - swap_version: order.swap_version, }; let topic = order.orderbook_topic(); log::debug!("Request matched sending reserved {:?}", reserved); @@ -4159,8 +4105,7 @@ pub async fn lp_auto_buy( .with_sender_pubkey(H256Json::from(our_public_id.bytes)) .with_save_in_history(input.save_in_history) .with_base_orderbook_ticker(ordermatch_ctx.orderbook_ticker(base_coin.ticker())) - .with_rel_orderbook_ticker(ordermatch_ctx.orderbook_ticker(rel_coin.ticker())) - .use_trading_proto_v2(ctx.use_trading_proto_v2()); + .with_rel_orderbook_ticker(ordermatch_ctx.orderbook_ticker(rel_coin.ticker())); if let Some(timeout) = input.timeout { order_builder = order_builder.with_timeout(timeout); } @@ -4905,8 +4850,7 @@ pub async fn create_maker_order(ctx: &MmArc, req: SetPriceReq) -> Result>, - #[serde(default = "legacy_swap_version")] - #[serde(skip_serializing_if = "is_legacy_swap_version")] - pub swap_version: u32, } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -285,9 +282,6 @@ pub struct MakerReserved { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] pub rel_protocol_info: Option>, - #[serde(default = "legacy_swap_version")] - #[serde(skip_serializing_if = "is_legacy_swap_version")] - pub swap_version: u32, } #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/mm2src/mm2_main/src/ordermatch_tests.rs b/mm2src/mm2_main/src/ordermatch_tests.rs index 58d7ffa8f1..3bf81d6370 100644 --- a/mm2src/mm2_main/src/ordermatch_tests.rs +++ b/mm2src/mm2_main/src/ordermatch_tests.rs @@ -20,8 +20,6 @@ use std::collections::HashSet; use std::iter::{self, FromIterator}; use std::sync::Mutex; -const LEGACY_SWAP_V: u32 = 1; - #[test] fn test_match_maker_order_and_taker_request() { let maker = MakerOrder { @@ -41,7 +39,6 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { @@ -57,7 +54,6 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); @@ -81,7 +77,6 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { @@ -97,7 +92,6 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); @@ -121,7 +115,6 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { @@ -137,7 +130,6 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); @@ -161,7 +153,6 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { @@ -177,7 +168,6 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); @@ -201,7 +191,6 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { @@ -217,7 +206,6 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); @@ -241,7 +229,6 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { @@ -257,7 +244,6 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); @@ -283,7 +269,6 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { base: "KMD".to_owned(), @@ -298,7 +283,6 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); assert_eq!(actual, OrderMatchResult::NotMatched); @@ -325,7 +309,6 @@ fn test_match_maker_order_and_taker_request() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }; let request = TakerRequest { base: "REL".to_owned(), @@ -340,7 +323,6 @@ fn test_match_maker_order_and_taker_request() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let actual = maker.match_with_request(&request); let expected_base_amount = MmNumber::from(3); @@ -398,7 +380,6 @@ fn test_maker_order_available_amount() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }; maker.matches.insert(new_uuid(), MakerMatch { request: TakerRequest { @@ -414,7 +395,6 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }, reserved: MakerReserved { base: "BASE".into(), @@ -428,7 +408,6 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }, connect: None, connected: None, @@ -448,7 +427,6 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }, reserved: MakerReserved { base: "BASE".into(), @@ -462,7 +440,6 @@ fn test_maker_order_available_amount() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }, connect: None, connected: None, @@ -491,7 +468,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -519,7 +495,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -537,7 +512,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -565,7 +539,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -583,7 +556,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -611,7 +583,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -629,7 +600,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -657,7 +627,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::NotMatched, order.match_reserved(&reserved)); @@ -675,7 +644,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -703,7 +671,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -721,7 +688,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -749,7 +715,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -767,7 +732,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -795,7 +759,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -813,7 +776,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -841,7 +803,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::NotMatched, order.match_reserved(&reserved)); @@ -863,7 +824,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }, matches: HashMap::new(), order_type: OrderType::GoodTillCancelled, @@ -887,7 +847,6 @@ fn test_taker_match_reserved() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::Matched, order.match_reserved(&reserved)); @@ -908,7 +867,6 @@ fn test_taker_order_cancellable() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let order = TakerOrder { @@ -939,7 +897,6 @@ fn test_taker_order_cancellable() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let mut order = TakerOrder { @@ -969,7 +926,6 @@ fn test_taker_order_cancellable() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }, connect: TakerConnect { sender_pubkey: H256Json::default(), @@ -1018,7 +974,6 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }, None, ); @@ -1041,7 +996,6 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }, None, ); @@ -1064,7 +1018,6 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }, None, ); @@ -1084,7 +1037,6 @@ fn prepare_for_cancel_by(ctx: &MmArc) -> mpsc::Receiver { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }, order_type: OrderType::GoodTillCancelled, min_volume: 0.into(), @@ -1187,7 +1139,6 @@ fn test_taker_order_match_by() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; let mut order = TakerOrder { @@ -1215,7 +1166,6 @@ fn test_taker_order_match_by() { conf_settings: None, base_protocol_info: None, rel_protocol_info: None, - swap_version: LEGACY_SWAP_V, }; assert_eq!(MatchReservedResult::NotMatched, order.match_reserved(&reserved)); @@ -1256,7 +1206,6 @@ fn test_maker_order_was_updated() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }; let mut update_msg = MakerOrderUpdated::new(maker_order.uuid); update_msg.with_new_price(BigRational::from_integer(2.into())); @@ -3263,7 +3212,6 @@ fn test_maker_order_balance_loops() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }; let morty_order = MakerOrder { @@ -3283,7 +3231,6 @@ fn test_maker_order_balance_loops() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }; assert!(!maker_orders_ctx.balance_loop_exists(rick_ticker)); @@ -3316,7 +3263,6 @@ fn test_maker_order_balance_loops() { base_orderbook_ticker: None, rel_orderbook_ticker: None, p2p_privkey: None, - swap_version: LEGACY_SWAP_V, }; maker_orders_ctx.add_order(ctx.weak(), rick_order_2.clone(), None); From ec0d13cd877bfe19f1e2183f5858b2d1069cc9b2 Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 26 Dec 2024 12:45:16 +0700 Subject: [PATCH 51/59] review: remove leftover --- mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs b/mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs index 1e0eee0f3e..05322325a5 100644 --- a/mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs +++ b/mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs @@ -706,8 +706,6 @@ mod tests { wasm_bindgen_test_configure!(run_in_browser); - const LEGACY_SWAP_V: u32 = 1; - fn maker_order_for_test() -> MakerOrder { MakerOrder { base: "BASE".to_owned(), From b04f217df034e491b8f851a1480a3a85cac05999 Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 26 Dec 2024 15:08:00 +0700 Subject: [PATCH 52/59] review: use fixed-size array reference --- mm2src/coins/eth.rs | 2 +- mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs | 8 +++++--- mm2src/coins/eth/eth_swap_v2/mod.rs | 2 +- mm2src/coins/lp_coins.rs | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 7a5bd74c07..3aa00d7edb 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -2593,7 +2593,7 @@ impl MarketCoinOps for EthCoin { swap_contract_address, event_name: "ReceiverSpent", abi_contract: &SWAP_CONTRACT, - swap_id: &id, + swap_id: &try_tx_s!(id.as_slice().try_into()), from_block: args.from_block, wait_until: args.wait_until, check_every: args.check_every, diff --git a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs index e8746f8e3d..4bb757e636 100644 --- a/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs +++ b/mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs @@ -471,14 +471,16 @@ impl EthCoin { FindPaymentSpendError::Internal("Expected swap_v2_contracts to be Some, but found None".to_string()) })? .taker_swap_v2_contract; - let id = - extract_id_from_tx_data(taker_payment.unsigned().data(), &TAKER_SWAP_V2, TAKER_PAYMENT_APPROVE).await?; + let id_array = extract_id_from_tx_data(taker_payment.unsigned().data(), &TAKER_SWAP_V2, TAKER_PAYMENT_APPROVE) + .await? + .as_slice() + .try_into()?; let params = SpendTxSearchParams { swap_contract_address: taker_swap_v2_contract, event_name: "TakerPaymentSpent", abi_contract: &TAKER_SWAP_V2, - swap_id: &id, + swap_id: &id_array, from_block, wait_until, check_every, diff --git a/mm2src/coins/eth/eth_swap_v2/mod.rs b/mm2src/coins/eth/eth_swap_v2/mod.rs index 0eed1f4812..a7cffec91d 100644 --- a/mm2src/coins/eth/eth_swap_v2/mod.rs +++ b/mm2src/coins/eth/eth_swap_v2/mod.rs @@ -222,7 +222,7 @@ pub(crate) struct SpendTxSearchParams<'a> { pub(crate) swap_contract_address: Address, pub(crate) event_name: &'a str, pub(crate) abi_contract: &'a Contract, - pub(crate) swap_id: &'a [u8], + pub(crate) swap_id: &'a [u8; 32], pub(crate) from_block: u64, pub(crate) wait_until: u64, pub(crate) check_every: f64, diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index d0a1ae34c0..063e49cd34 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1810,6 +1810,7 @@ pub enum FindPaymentSpendError { }, /// Invalid input transaction error variant, containing additional information about the error. InvalidInputTx(String), + #[from_stringify("TryFromSliceError")] Internal(String), #[from_stringify("ethabi::Error")] #[display(fmt = "ABI error: {}", _0)] From a9f481ce5dffaf3c1e9b86221812e12e5f238db1 Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 26 Dec 2024 16:12:46 +0700 Subject: [PATCH 53/59] review: dont move block window if err --- mm2src/coins/eth/eth_swap_v2/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/mm2src/coins/eth/eth_swap_v2/mod.rs b/mm2src/coins/eth/eth_swap_v2/mod.rs index a7cffec91d..cb739f5b02 100644 --- a/mm2src/coins/eth/eth_swap_v2/mod.rs +++ b/mm2src/coins/eth/eth_swap_v2/mod.rs @@ -168,8 +168,6 @@ impl EthCoin { params.event_name, next_from_block, to_block, e ); Timer::sleep(params.check_every).await; - // Move to next window if there was an error - next_from_block += self.logs_block_range; continue; }, }; From 41f20f9c323936aabec70f8704943d45b29b3879 Mon Sep 17 00:00:00 2001 From: laruh Date: Thu, 26 Dec 2024 16:31:41 +0700 Subject: [PATCH 54/59] fix clippy --- mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs index 7cd9d111b3..3a4200f789 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs @@ -2227,7 +2227,7 @@ impl Date: Thu, 26 Dec 2024 17:00:13 +0700 Subject: [PATCH 55/59] add `taker_pubkey` field in wasm test jsons --- mm2src/mm2_main/src/lp_swap/saved_swap.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm2src/mm2_main/src/lp_swap/saved_swap.rs b/mm2src/mm2_main/src/lp_swap/saved_swap.rs index c471f7eacb..fd1e8e7579 100644 --- a/mm2src/mm2_main/src/lp_swap/saved_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/saved_swap.rs @@ -449,7 +449,7 @@ mod tests { async fn test_saved_swap_table() { let ctx = MmCtxBuilder::new().with_test_db_namespace().into_mm_arc(); - let saved_swap_str = r#"{"type":"Maker","error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"e1c9bd12a83f810813dc078ac398069b63d56bf1e94657def995c43cd1975302","started_at":1563743939,"taker":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"MakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563763243350}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; + let saved_swap_str = r#"{"type":"Maker","error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"e1c9bd12a83f810813dc078ac398069b63d56bf1e94657def995c43cd1975302","started_at":1563743939,"taker_pubkey":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"MakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563763243350}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; let mut saved_swap: SavedSwap = json::from_str(saved_swap_str).unwrap(); let first_saved_item = SavedSwapTable { uuid: *saved_swap.uuid(), @@ -519,7 +519,7 @@ mod tests { async fn test_migrate_swaps_data() { let ctx = MmCtxBuilder::new().with_test_db_namespace().into_mm_arc(); - let saved_swap_str = r#"{"type":"Maker","error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"e1c9bd12a83f810813dc078ac398069b63d56bf1e94657def995c43cd1975302","started_at":1563743939,"taker":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"MakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563763243350}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; + let saved_swap_str = r#"{"type":"Maker","error_events":["StartFailed","NegotiateFailed","TakerFeeValidateFailed","MakerPaymentTransactionFailed","MakerPaymentDataSendFailed","TakerPaymentValidateFailed","TakerPaymentSpendFailed","TakerPaymentSpendConfirmFailed","MakerPaymentRefunded","MakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker_amount":"3.54932734","maker_coin":"KMD","maker_coin_start_block":1452970,"maker_payment_confirmations":1,"maker_payment_lock":1563759539,"my_persistent_pub":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret":"e1c9bd12a83f810813dc078ac398069b63d56bf1e94657def995c43cd1975302","started_at":1563743939,"taker_pubkey":"101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9","taker_amount":"0.02004833998671660000000000","taker_coin":"ETH","taker_coin_start_block":8196380,"taker_payment_confirmations":1,"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"},"type":"Started"},"timestamp":1563743939211},{"event":{"data":{"taker_payment_locktime":1563751737,"taker_pubkey":"03101ace6b08605b9424b0582b5cce044b70a3c8d8d10cb2965e039b0967ae92b9"},"type":"Negotiated"},"timestamp":1563743979835},{"event":{"data":{"tx_hash":"a59203eb2328827de00bed699a29389792906e4f39fdea145eb40dc6b3821bd6","tx_hex":"f8690284ee6b280082520894d8997941dd1346e9231118d5685d866294f59e5b865af3107a4000801ca0743d2b7c9fad65805d882179062012261be328d7628ae12ee08eff8d7657d993a07eecbd051f49d35279416778faa4664962726d516ce65e18755c9b9406a9c2fd"},"type":"TakerFeeValidated"},"timestamp":1563744052878},{"event":{"data":{"error":"lp_swap:1888] eth:654] RPC error: Error { code: ServerError(-32010), message: \"Transaction with the same hash was already imported.\", data: None }"},"type":"MakerPaymentTransactionFailed"},"timestamp":1563744118577},{"event":{"type":"Finished"},"timestamp":1563763243350}],"success_events":["Started","Negotiated","TakerFeeValidated","MakerPaymentSent","TakerPaymentReceived","TakerPaymentWaitConfirmStarted","TakerPaymentValidatedAndConfirmed","TakerPaymentSpent","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","TakerPaymentSpendConfirmStarted","TakerPaymentSpendConfirmed","Finished"],"uuid":"3447b727-fe93-4357-8e5a-8cf2699b7e86"}"#; let saved_swap: SavedSwap = json::from_str(saved_swap_str).unwrap(); saved_swap.save_to_db(&ctx).await.expect("!save_to_db"); From 49f46e075e22c61e370d82ee946ff45b65667510 Mon Sep 17 00:00:00 2001 From: laruh Date: Fri, 27 Dec 2024 10:29:51 +0700 Subject: [PATCH 56/59] review: move SpendTxSearchParams up --- mm2src/coins/eth/eth_swap_v2/mod.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm2src/coins/eth/eth_swap_v2/mod.rs b/mm2src/coins/eth/eth_swap_v2/mod.rs index cb739f5b02..dc199fa5f3 100644 --- a/mm2src/coins/eth/eth_swap_v2/mod.rs +++ b/mm2src/coins/eth/eth_swap_v2/mod.rs @@ -73,6 +73,16 @@ pub(crate) enum PrepareTxDataError { Internal(String), } +pub(crate) struct SpendTxSearchParams<'a> { + pub(crate) swap_contract_address: Address, + pub(crate) event_name: &'a str, + pub(crate) abi_contract: &'a Contract, + pub(crate) swap_id: &'a [u8; 32], + pub(crate) from_block: u64, + pub(crate) wait_until: u64, + pub(crate) check_every: f64, +} + impl EthCoin { /// Retrieves the payment status from a given smart contract address based on the swap ID and state type. pub(crate) async fn payment_status_v2( @@ -216,16 +226,6 @@ impl EthCoin { } } -pub(crate) struct SpendTxSearchParams<'a> { - pub(crate) swap_contract_address: Address, - pub(crate) event_name: &'a str, - pub(crate) abi_contract: &'a Contract, - pub(crate) swap_id: &'a [u8; 32], - pub(crate) from_block: u64, - pub(crate) wait_until: u64, - pub(crate) check_every: f64, -} - pub(crate) fn validate_payment_state( tx: &SignedEthTx, state: U256, From 0f31d07d1eebf03a086c3cff657e524434581592 Mon Sep 17 00:00:00 2001 From: laruh Date: Sun, 29 Dec 2024 13:39:07 +0700 Subject: [PATCH 57/59] review: remove "address" param from addr_to_string func and use self.my_addr() directly inside it --- mm2src/coins/eth.rs | 2 +- mm2src/coins/lp_coins.rs | 4 ++-- mm2src/coins/test_coin.rs | 2 +- mm2src/coins/utxo.rs | 2 +- mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs | 3 +-- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 3aa00d7edb..fa10ce6317 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -6980,7 +6980,7 @@ impl ParseCoinAssocTypes for EthCoin { } } - fn addr_to_string(&self, address: &Self::Address) -> String { eth_addr_to_hex(address) } + async fn my_addr_as_string(&self) -> String { eth_addr_to_hex(&self.my_addr().await) } fn parse_address(&self, address: &str) -> Result { // crate `Address::from_str` supports both address variants with and without `0x` prefix diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 063e49cd34..53779e21d5 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1550,13 +1550,13 @@ pub trait ParseCoinAssocTypes { async fn my_addr(&self) -> Self::Address; - /// Converts coin `Self::Address` type into a properly formatted string representation. + /// Should convert coin `Self::Address` type into a properly formatted string representation. /// /// Don't use `to_string` directly on `Self::Address` types in generic TPU code! /// It may produce abbreviated or non-standard formats (e.g. `ethereum_types::Address` will be like this `0x7cc9…3874`), /// which are not guaranteed to be parsable back into the original `Address` type. /// This function should ensure the resulting string is consistently formatted and fully reversible. - fn addr_to_string(&self, address: &Self::Address) -> String; + async fn my_addr_as_string(&self) -> String; fn parse_address(&self, address: &str) -> Result; diff --git a/mm2src/coins/test_coin.rs b/mm2src/coins/test_coin.rs index 04511216c4..af05276ff0 100644 --- a/mm2src/coins/test_coin.rs +++ b/mm2src/coins/test_coin.rs @@ -456,7 +456,7 @@ impl ParseCoinAssocTypes for TestCoin { async fn my_addr(&self) -> Self::Address { todo!() } - fn addr_to_string(&self, address: &Self::Address) -> String { unimplemented!() } + async fn my_addr_as_string(&self) -> String { unimplemented!() } fn parse_address(&self, address: &str) -> Result { todo!() } diff --git a/mm2src/coins/utxo.rs b/mm2src/coins/utxo.rs index f1c055f3fc..33f6f97298 100644 --- a/mm2src/coins/utxo.rs +++ b/mm2src/coins/utxo.rs @@ -1053,7 +1053,7 @@ impl ParseCoinAssocTypes for T { } } - fn addr_to_string(&self, address: &Self::Address) -> String { address.to_string() } + async fn my_addr_as_string(&self) -> String { self.my_addr().await.to_string() } fn parse_address(&self, address: &str) -> Result { self.address_from_str(address) diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index 18df8d1c14..72ccd092d0 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -914,7 +914,6 @@ impl, state_machine: &mut Self::StateMachine) -> StateResult { let unique_data = state_machine.unique_data(); - let taker_coin_address = state_machine.taker_coin.my_addr().await; let maker_negotiation_msg = MakerNegotiation { started_at: state_machine.started_at, @@ -924,7 +923,7 @@ impl Date: Tue, 7 Jan 2025 22:25:49 +0700 Subject: [PATCH 58/59] Revert "review: remove "address" param from addr_to_string func and use self.my_addr() directly inside it" This reverts commit 0f31d07d1eebf03a086c3cff657e524434581592. --- mm2src/coins/eth.rs | 2 +- mm2src/coins/lp_coins.rs | 4 ++-- mm2src/coins/test_coin.rs | 2 +- mm2src/coins/utxo.rs | 2 +- mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs | 3 ++- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index fa10ce6317..3aa00d7edb 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -6980,7 +6980,7 @@ impl ParseCoinAssocTypes for EthCoin { } } - async fn my_addr_as_string(&self) -> String { eth_addr_to_hex(&self.my_addr().await) } + fn addr_to_string(&self, address: &Self::Address) -> String { eth_addr_to_hex(address) } fn parse_address(&self, address: &str) -> Result { // crate `Address::from_str` supports both address variants with and without `0x` prefix diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 53779e21d5..063e49cd34 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1550,13 +1550,13 @@ pub trait ParseCoinAssocTypes { async fn my_addr(&self) -> Self::Address; - /// Should convert coin `Self::Address` type into a properly formatted string representation. + /// Converts coin `Self::Address` type into a properly formatted string representation. /// /// Don't use `to_string` directly on `Self::Address` types in generic TPU code! /// It may produce abbreviated or non-standard formats (e.g. `ethereum_types::Address` will be like this `0x7cc9…3874`), /// which are not guaranteed to be parsable back into the original `Address` type. /// This function should ensure the resulting string is consistently formatted and fully reversible. - async fn my_addr_as_string(&self) -> String; + fn addr_to_string(&self, address: &Self::Address) -> String; fn parse_address(&self, address: &str) -> Result; diff --git a/mm2src/coins/test_coin.rs b/mm2src/coins/test_coin.rs index af05276ff0..04511216c4 100644 --- a/mm2src/coins/test_coin.rs +++ b/mm2src/coins/test_coin.rs @@ -456,7 +456,7 @@ impl ParseCoinAssocTypes for TestCoin { async fn my_addr(&self) -> Self::Address { todo!() } - async fn my_addr_as_string(&self) -> String { unimplemented!() } + fn addr_to_string(&self, address: &Self::Address) -> String { unimplemented!() } fn parse_address(&self, address: &str) -> Result { todo!() } diff --git a/mm2src/coins/utxo.rs b/mm2src/coins/utxo.rs index 33f6f97298..f1c055f3fc 100644 --- a/mm2src/coins/utxo.rs +++ b/mm2src/coins/utxo.rs @@ -1053,7 +1053,7 @@ impl ParseCoinAssocTypes for T { } } - async fn my_addr_as_string(&self) -> String { self.my_addr().await.to_string() } + fn addr_to_string(&self, address: &Self::Address) -> String { address.to_string() } fn parse_address(&self, address: &str) -> Result { self.address_from_str(address) diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index 72ccd092d0..18df8d1c14 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -914,6 +914,7 @@ impl, state_machine: &mut Self::StateMachine) -> StateResult { let unique_data = state_machine.unique_data(); + let taker_coin_address = state_machine.taker_coin.my_addr().await; let maker_negotiation_msg = MakerNegotiation { started_at: state_machine.started_at, @@ -923,7 +924,7 @@ impl Date: Tue, 7 Jan 2025 22:46:06 +0700 Subject: [PATCH 59/59] provide trait AddrToString to be able to properly convert address to string for StoredNegotiationData --- mm2src/coins/eth.rs | 6 ++++-- mm2src/coins/lp_coins.rs | 20 ++++++++++--------- mm2src/coins/test_coin.rs | 21 ++++++++++++++------ mm2src/coins/utxo.rs | 14 +++++++------ mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs | 11 +++++----- mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 4 ++-- 6 files changed, 46 insertions(+), 30 deletions(-) diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 3aa00d7edb..3c8c9ed857 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -6980,8 +6980,6 @@ impl ParseCoinAssocTypes for EthCoin { } } - fn addr_to_string(&self, address: &Self::Address) -> String { eth_addr_to_hex(address) } - fn parse_address(&self, address: &str) -> Result { // crate `Address::from_str` supports both address variants with and without `0x` prefix Address::from_str(address).map_to_mm(|e| EthAssocTypesError::InvalidHexString(e.to_string())) @@ -7016,6 +7014,10 @@ impl ToBytes for Address { fn to_bytes(&self) -> Vec { self.0.to_vec() } } +impl AddrToString for Address { + fn addr_to_string(&self) -> String { eth_addr_to_hex(self) } +} + impl ToBytes for BigUint { fn to_bytes(&self) -> Vec { self.to_bytes_be() } } diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 063e49cd34..a2978b0e00 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1534,10 +1534,20 @@ pub trait ToBytes { fn to_bytes(&self) -> Vec; } +/// Should convert coin `Self::Address` type into a properly formatted string representation. +/// +/// Don't use `to_string` directly on `Self::Address` types in generic TPU code! +/// It may produce abbreviated or non-standard formats (e.g. `ethereum_types::Address` will be like this `0x7cc9…3874`), +/// which are not guaranteed to be parsable back into the original `Address` type. +/// This function should ensure the resulting string is consistently formatted and fully reversible. +pub trait AddrToString { + fn addr_to_string(&self) -> String; +} + /// Defines associated types specific to each coin (Pubkey, Address, etc.) #[async_trait] pub trait ParseCoinAssocTypes { - type Address: Send + Sync + fmt::Display; + type Address: Send + Sync + fmt::Display + AddrToString; type AddressParseError: fmt::Debug + Send + fmt::Display; type Pubkey: ToBytes + Send + Sync; type PubkeyParseError: fmt::Debug + Send + fmt::Display; @@ -1550,14 +1560,6 @@ pub trait ParseCoinAssocTypes { async fn my_addr(&self) -> Self::Address; - /// Converts coin `Self::Address` type into a properly formatted string representation. - /// - /// Don't use `to_string` directly on `Self::Address` types in generic TPU code! - /// It may produce abbreviated or non-standard formats (e.g. `ethereum_types::Address` will be like this `0x7cc9…3874`), - /// which are not guaranteed to be parsable back into the original `Address` type. - /// This function should ensure the resulting string is consistently formatted and fully reversible. - fn addr_to_string(&self, address: &Self::Address) -> String; - fn parse_address(&self, address: &str) -> Result; fn parse_pubkey(&self, pubkey: &[u8]) -> Result; diff --git a/mm2src/coins/test_coin.rs b/mm2src/coins/test_coin.rs index 04511216c4..0d8ec2a7ee 100644 --- a/mm2src/coins/test_coin.rs +++ b/mm2src/coins/test_coin.rs @@ -1,8 +1,8 @@ #![allow(clippy::all)] -use super::{CoinBalance, CommonSwapOpsV2, FindPaymentSpendError, FundingTxSpend, HistorySyncState, MarketCoinOps, - MmCoin, RawTransactionFut, RawTransactionRequest, RefundTakerPaymentArgs, SearchForFundingSpendErr, - SwapOps, TradeFee, TransactionEnum, TransactionFut}; +use super::{AddrToString, CoinBalance, CommonSwapOpsV2, FindPaymentSpendError, FundingTxSpend, HistorySyncState, + MarketCoinOps, MmCoin, RawTransactionFut, RawTransactionRequest, RefundTakerPaymentArgs, + SearchForFundingSpendErr, SwapOps, TradeFee, TransactionEnum, TransactionFut}; use crate::coin_errors::ValidatePaymentResult; use crate::{coin_errors::MyAddressError, BalanceFut, CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinFutSpawner, ConfirmPaymentInput, FeeApproxStage, FoundSwapTxSpend, GenPreimageResult, GenTakerFundingSpendArgs, @@ -29,6 +29,7 @@ use mm2_number::{BigDecimal, MmNumber}; use mocktopus::macros::*; use rpc::v1::types::Bytes as BytesJson; use serde_json::Value as Json; +use std::fmt::{Display, Formatter}; use std::ops::Deref; use std::sync::Arc; @@ -441,9 +442,19 @@ impl ToBytes for TestSig { fn to_bytes(&self) -> Vec { vec![] } } +pub struct TestAddress {} + +impl AddrToString for TestAddress { + fn addr_to_string(&self) -> String { unimplemented!() } +} + +impl Display for TestAddress { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { unimplemented!() } +} + #[async_trait] impl ParseCoinAssocTypes for TestCoin { - type Address = String; + type Address = TestAddress; type AddressParseError = String; type Pubkey = TestPubkey; type PubkeyParseError = String; @@ -456,8 +467,6 @@ impl ParseCoinAssocTypes for TestCoin { async fn my_addr(&self) -> Self::Address { todo!() } - fn addr_to_string(&self, address: &Self::Address) -> String { unimplemented!() } - fn parse_address(&self, address: &str) -> Result { todo!() } fn parse_pubkey(&self, pubkey: &[u8]) -> Result { unimplemented!() } diff --git a/mm2src/coins/utxo.rs b/mm2src/coins/utxo.rs index f1c055f3fc..626836864e 100644 --- a/mm2src/coins/utxo.rs +++ b/mm2src/coins/utxo.rs @@ -102,10 +102,10 @@ use utxo_signer::{TxProvider, TxProviderError, UtxoSignTxError, UtxoSignTxResult use self::rpc_clients::{electrum_script_hash, ElectrumClient, ElectrumConnectionSettings, EstimateFeeMethod, EstimateFeeMode, NativeClient, UnspentInfo, UnspentMap, UtxoRpcClientEnum, UtxoRpcError, UtxoRpcFut, UtxoRpcResult}; -use super::{big_decimal_from_sat_unsigned, BalanceError, BalanceFut, BalanceResult, CoinBalance, CoinFutSpawner, - CoinsContext, DerivationMethod, FeeApproxStage, FoundSwapTxSpend, HistorySyncState, KmdRewardsDetails, - MarketCoinOps, MmCoin, NumConversError, NumConversResult, PrivKeyActivationPolicy, PrivKeyPolicy, - PrivKeyPolicyNotAllowed, RawTransactionFut, TradeFee, TradePreimageError, TradePreimageFut, +use super::{big_decimal_from_sat_unsigned, AddrToString, BalanceError, BalanceFut, BalanceResult, CoinBalance, + CoinFutSpawner, CoinsContext, DerivationMethod, FeeApproxStage, FoundSwapTxSpend, HistorySyncState, + KmdRewardsDetails, MarketCoinOps, MmCoin, NumConversError, NumConversResult, PrivKeyActivationPolicy, + PrivKeyPolicy, PrivKeyPolicyNotAllowed, RawTransactionFut, TradeFee, TradePreimageError, TradePreimageFut, TradePreimageResult, Transaction, TransactionDetails, TransactionEnum, TransactionErr, UnexpectedDerivationMethod, VerificationError, WithdrawError, WithdrawRequest}; use crate::coin_balance::{EnableCoinScanPolicy, EnabledCoinBalanceParams, HDAddressBalanceScanner}; @@ -1028,6 +1028,10 @@ impl ToBytes for Signature { fn to_bytes(&self) -> Vec { self.to_vec() } } +impl AddrToString for Address { + fn addr_to_string(&self) -> String { self.to_string() } +} + #[async_trait] impl ParseCoinAssocTypes for T { type Address = Address; @@ -1053,8 +1057,6 @@ impl ParseCoinAssocTypes for T { } } - fn addr_to_string(&self, address: &Self::Address) -> String { address.to_string() } - fn parse_address(&self, address: &str) -> Result { self.address_from_str(address) } diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index 18df8d1c14..bf79c402a0 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -8,10 +8,11 @@ use crate::lp_swap::{broadcast_swap_v2_msg_every, check_balance_for_maker_swap, use crate::lp_swap::{swap_v2_pb::*, NO_REFUND_FEE}; use async_trait::async_trait; use bitcrypto::{dhash160, sha256}; -use coins::{CanRefundHtlc, ConfirmPaymentInput, DexFee, FeeApproxStage, FundingTxSpend, GenTakerFundingSpendArgs, - GenTakerPaymentSpendArgs, MakerCoinSwapOpsV2, MmCoin, ParseCoinAssocTypes, RefundMakerPaymentSecretArgs, - RefundMakerPaymentTimelockArgs, SearchForFundingSpendErr, SendMakerPaymentArgs, SwapTxTypeWithSecretHash, - TakerCoinSwapOpsV2, ToBytes, TradePreimageValue, Transaction, TxPreimageWithSig, ValidateTakerFundingArgs}; +use coins::{AddrToString, CanRefundHtlc, ConfirmPaymentInput, DexFee, FeeApproxStage, FundingTxSpend, + GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, MakerCoinSwapOpsV2, MmCoin, ParseCoinAssocTypes, + RefundMakerPaymentSecretArgs, RefundMakerPaymentTimelockArgs, SearchForFundingSpendErr, + SendMakerPaymentArgs, SwapTxTypeWithSecretHash, TakerCoinSwapOpsV2, ToBytes, TradePreimageValue, + Transaction, TxPreimageWithSig, ValidateTakerFundingArgs}; use common::executor::abortable_queue::AbortableQueue; use common::executor::{AbortableSystem, Timer}; use common::log::{debug, error, info, warn}; @@ -924,7 +925,7 @@ impl Negotiation StoredNegotiationData { maker_payment_locktime: self.maker_payment_locktime, maker_secret_hash: self.maker_secret_hash.clone().into(), - taker_coin_maker_address: self.taker_coin_maker_address.to_string(), + taker_coin_maker_address: self.taker_coin_maker_address.addr_to_string(), maker_coin_htlc_pub_from_maker: self.maker_coin_htlc_pub_from_maker.to_bytes().into(), taker_coin_htlc_pub_from_maker: self.taker_coin_htlc_pub_from_maker.to_bytes().into(), maker_coin_swap_contract: self.maker_coin_swap_contract.clone().map(|b| b.into()),