Skip to content

Commit

Permalink
remove legacy_spend_events function and use new one instead
Browse files Browse the repository at this point in the history
  • Loading branch information
laruh committed Nov 18, 2024
1 parent 2056f9b commit 0b3ab9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
33 changes: 9 additions & 24 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Future<Item = Vec<Log>, 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(
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion mm2src/coins/eth/eth_tests.rs
Original file line number Diff line number Diff line change
@@ -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!(
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 0b3ab9a

Please sign in to comment.