From 8d5ed46f1d2e935e270fd2144afc7c400ad4860e Mon Sep 17 00:00:00 2001 From: laruh Date: Tue, 12 Nov 2024 19:54:51 +0700 Subject: [PATCH] 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