Skip to content

Commit

Permalink
Refactor OnceLock to lazy_static
Browse files Browse the repository at this point in the history
  • Loading branch information
vldm committed Jan 22, 2025
1 parent bf70f96 commit 17a5aa8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions evm-utils/programs/evm_loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ num = "0.2"
substrate-bn = { git = "https://github.com/paritytech/bn.git", rev = "63f8c58", default-features = false }
byteorder = "1.4.3"
eip-152 = "0.1.0"
lazy_static = "1.5.0"

[lib]
crate-type = ["lib", "cdylib"]
Expand Down
58 changes: 29 additions & 29 deletions evm-utils/programs/evm_loader/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use {
program_utils::limited_deserialize,
system_instruction,
},
std::{cell::RefMut, fmt::Write, ops::DerefMut, sync::OnceLock},
std::{cell::RefMut, fmt::Write, ops::DerefMut},
};

pub const BURN_ADDR: evm_state::H160 = evm_state::H160::zero();
Expand Down Expand Up @@ -1295,32 +1295,33 @@ impl EvmProcessor {
const MINT_BURN_CONTRACT: H160 = H160::zero();

fn transfer_event() -> &'static H256 {
static TRANSFER_EVENT: OnceLock<H256> = OnceLock::new();

TRANSFER_EVENT.get_or_init(|| {
ethabi::Event {
name: "Transfer".into(),
inputs: vec![
ethabi::EventParam {
name: "from".into(),
kind: ethabi::ParamType::Address,
indexed: true,
},
ethabi::EventParam {
name: "to".into(),
kind: ethabi::ParamType::Address,
indexed: true,
},
ethabi::EventParam {
name: "value".into(),
kind: ethabi::ParamType::Uint(256),
indexed: false,
},
],
anonymous: false,
}
.signature()
})
lazy_static::lazy_static! {
static ref TRANSFER_EVENT: H256 = {
ethabi::Event {
name: "Transfer".into(),
inputs: vec![
ethabi::EventParam {
name: "from".into(),
kind: ethabi::ParamType::Address,
indexed: true,
},
ethabi::EventParam {
name: "to".into(),
kind: ethabi::ParamType::Address,
indexed: true,
},
ethabi::EventParam {
name: "value".into(),
kind: ethabi::ParamType::Uint(256),
indexed: false,
},
],
anonymous: false,
}
.signature()
};
}
&TRANSFER_EVENT
}

for log in receipt.logs.iter() {
Expand Down Expand Up @@ -1411,15 +1412,14 @@ pub fn dummy_call_with_chain_id(

#[cfg(test)]
mod test {
use evm_state::BURN_GAS_PRICE_IN_SUBCHAIN;

use {
super::*,
crate::instructions::AllocAccount,
evm::lamports_to_wei,
evm_state::{
transactions::{TransactionAction, TransactionSignature},
AccountProvider, AccountState, ExitReason, ExitSucceed, FromKey, BURN_GAS_PRICE,
BURN_GAS_PRICE_IN_SUBCHAIN,
},
hex_literal::hex,
num_traits::Zero,
Expand Down

0 comments on commit 17a5aa8

Please sign in to comment.