Skip to content

Commit

Permalink
review: remove unnecessary param from extract_secret_v2_impl, add eve…
Browse files Browse the repository at this point in the history
…nts.is_empty() check, rename with_tpu_version function.
  • Loading branch information
laruh committed Nov 12, 2024
1 parent c700b59 commit 8d5ed46
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7386,8 +7386,8 @@ impl TakerCoinSwapOpsV2 for EthCoin {
.await
}

async fn extract_secret_v2(&self, secret_hash: &[u8], spend_tx: &Self::Tx) -> Result<Vec<u8>, 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<Vec<u8>, String> {
self.extract_secret_v2_impl(spend_tx).await
}
}

Expand Down
15 changes: 10 additions & 5 deletions mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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<Vec<u8>, String> {
pub(crate) async fn extract_secret_v2_impl(&self, spend_tx: &SignedEthTx) -> Result<Vec<u8>, String> {
let function = try_s!(TAKER_SWAP_V2.function("spendTakerPayment"));
// should be 0xcc90c199
let expected_signature = function.short_signature();
Expand Down
16 changes: 12 additions & 4 deletions mm2src/mm2_main/src/lp_ordermatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -4915,7 +4923,7 @@ pub async fn create_maker_order(ctx: &MmArc, req: SetPriceReq) -> Result<MakerOr
.with_save_in_history(req.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());

let new_order = try_s!(builder.build());

Expand Down

0 comments on commit 8d5ed46

Please sign in to comment.