Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
Review of #1436 (#1438)
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav authored Sep 14, 2022
1 parent 897125f commit af0b4f0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frame/bridge/message-gadget/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ version = "2.9.4"
# crates.io
codec = { package = "parity-scale-codec", version = "2.3", default-features = false }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
sha3 = { version = "0.9", default-features = false }
# darwinia-network
darwinia-ethereum = { default-features = false, path = "../../dvm/ethereum" }
# paritytech
frame-support = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.4" }
frame-system = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.4" }
sp-core = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.4" }
sp-io = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.4" }

[features]
default = ["std"]
Expand All @@ -28,11 +28,11 @@ std = [
# crates.io
"codec/std",
"scale-info/std",
"sha3/std",
# darwinia-network
"darwinia-ethereum/std",
# paritytech
"frame-support/std",
"frame-system/std",
"sp-core/std",
"sp-io/std",
]
30 changes: 10 additions & 20 deletions frame/bridge/message-gadget/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@

// --- core ---
use core::marker::PhantomData;
// --- crates.io ---
use sha3::{Digest, Keccak256};
// --- darwinia-network ---
use darwinia_ethereum::InternalTransactHandler;
// --- paritytech ---
use frame_support::{log, pallet_prelude::*, traits::Get};
use frame_system::pallet_prelude::*;
use sp_core::{H160, H256};
use sp_io::hashing;

#[frame_support::pallet]
pub mod pallet {
Expand Down Expand Up @@ -80,25 +79,16 @@ where
T: Config + darwinia_ethereum::Config,
{
fn get() -> Option<H256> {
macro_rules! unwrap_or_return {
($r:expr, $err_msg:expr) => {
if let Ok(r) = $r {
r
} else {
log::warn!(target: LOG_TARGET, "{}", $err_msg);
let raw_message_root = if let Ok(r) = <darwinia_ethereum::Pallet<T>>::read_only_call(
<CommitmentContract<T>>::get(),
hashing::keccak_256(b"commitment()")[..4].to_vec(),
) {
r
} else {
log::warn!(target: LOG_TARGET, "Fail to read message root from DVM, return.");

return None;
}
};
}

let raw_message_root = unwrap_or_return!(
<darwinia_ethereum::Pallet<T>>::read_only_call(
<CommitmentContract<T>>::get(),
Keccak256::digest(b"commitment()")[0..4].to_vec()
),
"Fail to read message root from DVM, return."
);
return None;
};

if raw_message_root.len() != 32 {
log::warn!(
Expand Down

0 comments on commit af0b4f0

Please sign in to comment.