Skip to content

Commit

Permalink
OnceCell fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ctoyan committed Apr 25, 2024
1 parent b682bc6 commit 9cbd79d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 0 additions & 1 deletion ampd/src/starknet/events/contract_call.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::fmt;
use std::num::TryFromIntError;

use ethers::types::H256;
Expand Down
11 changes: 6 additions & 5 deletions ampd/src/starknet/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use starknet_core::utils::starknet_keccak;

pub mod contract_call;

// Since a keccak hash over a string is a deterministic operation,
// we can use `OnceCall` to eliminate useless hash calculations.
const CALL_CONTRACT_FELT: OnceCell<FieldElement> = OnceCell::new();

/// All Axelar event types supported by starknet
#[derive(Eq, PartialEq)]
pub enum EventType {
Expand All @@ -13,11 +17,8 @@ pub enum EventType {

impl EventType {
fn parse(event_type_felt: FieldElement) -> Option<Self> {
// Since a keccak hash over a string is a deterministic operation,
// we can use `OnceCell` to eliminate useless hash calculations.
let call_contract_felt: OnceCell<FieldElement> = OnceCell::new();
let contract_call_type =
call_contract_felt.get_or_init(|| starknet_keccak("ContractCall".as_bytes()));
let binding = CALL_CONTRACT_FELT;
let contract_call_type = binding.get_or_init(|| starknet_keccak("ContractCall".as_bytes()));

if event_type_felt == *contract_call_type {
Some(EventType::ContractCall)
Expand Down

0 comments on commit 9cbd79d

Please sign in to comment.