Skip to content

Commit

Permalink
fix evm logs addr check (#204)
Browse files Browse the repository at this point in the history
* fix evm logs addr check
  • Loading branch information
StewartYe authored Feb 6, 2025
1 parent e95cca7 commit c3dff78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
9 changes: 5 additions & 4 deletions route/bitfinity/src/evm_scan.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::str::FromStr;
use anyhow::anyhow;
use did::{TransactionReceipt, transaction::TransactionReceiptLog, H160};
use did::{TransactionReceipt, transaction::TransactionReceiptLog};
use ethers_core::abi::RawLog;
use ethers_core::utils::hex::ToHexExt;
use ic_canister_log::log;
use ic_stable_structures::Storable;
use itertools::Itertools;

use omnity_types::{ChainState, Directive, Ticket, ChainId, Memo};
Expand All @@ -17,7 +15,6 @@ use crate::contract_types::{
TokenBurned, TokenMinted, TokenTransportRequested,
};
use crate::convert::{ticket_from_burn_event, ticket_from_runes_mint_event, ticket_from_transport_event};
use crate::eth_common::EvmAddress;
use crate::state::{mutate_state, read_state, bitfinity_get_redeem_fee};

pub fn scan_evm_task() {
Expand Down Expand Up @@ -86,7 +83,11 @@ pub fn scan_evm_task() {
}

pub async fn handle_port_events(logs: Vec<TransactionReceiptLog>) -> anyhow::Result<()> {
let port = read_state(|s|s.omnity_port_contract.clone());
for l in logs {
if l.address.to_hex_str() != port.to_hex() {
continue;
}
if l.removed {
return Err(anyhow!("log is removed"));
}
Expand Down
15 changes: 10 additions & 5 deletions route/evm/src/evm_scan.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::anyhow;
use cketh_common::address::Address;
use cketh_common::eth_rpc::Hash;
use cketh_common::eth_rpc::LogEntry;
use ethers_core::abi::RawLog;
Expand Down Expand Up @@ -61,7 +62,7 @@ pub async fn sync_mint_status(hash: String) {
return;
}

if tr.to != port_address.to_hex() {
if tr.to.to_lowercase() != port_address.to_hex() {
mutate_state(|s| s.pending_events_on_chain.remove(&hash));
return;
}
Expand All @@ -84,7 +85,11 @@ pub async fn sync_mint_status(hash: String) {
}

pub async fn handle_port_events(logs: Vec<LogEntry>) -> anyhow::Result<()> {
let port = read_state(|s| s.omnity_port_contract.clone());
for l in logs {
if l.address.to_string().to_lowercase() != port.to_hex() {
continue;
}
if l.removed {
return Err(anyhow!("log is removed"));
}
Expand Down Expand Up @@ -301,8 +306,8 @@ pub fn get_memo(memo: Option<String>, dst_chain: ChainId) -> Option<String> {
memo,
bridge_fee: fee.unwrap_or_default() as u128,
}
.convert_to_memo_json()
.unwrap_or_default();
.convert_to_memo_json()
.unwrap_or_default();
Some(memo_json)
}

Expand All @@ -317,8 +322,8 @@ mod evm_route_test {
memo,
bridge_fee: 999_u128,
}
.convert_to_memo_json()
.unwrap_or_default();
.convert_to_memo_json()
.unwrap_or_default();
Some(memo_json)
}

Expand Down

0 comments on commit c3dff78

Please sign in to comment.