From 7305334f60e3a638e8d12829941ce86e61cc4561 Mon Sep 17 00:00:00 2001 From: Stoyan Kirov Date: Thu, 25 Apr 2024 18:04:53 +0300 Subject: [PATCH] OnceCell fixed --- ampd/src/starknet/events/contract_call.rs | 1 - ampd/src/starknet/events/mod.rs | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ampd/src/starknet/events/contract_call.rs b/ampd/src/starknet/events/contract_call.rs index 3b604b5bf..d6786746b 100644 --- a/ampd/src/starknet/events/contract_call.rs +++ b/ampd/src/starknet/events/contract_call.rs @@ -1,4 +1,3 @@ -use std::fmt; use std::num::TryFromIntError; use ethers::types::H256; diff --git a/ampd/src/starknet/events/mod.rs b/ampd/src/starknet/events/mod.rs index f5f54ad25..28030a6e7 100644 --- a/ampd/src/starknet/events/mod.rs +++ b/ampd/src/starknet/events/mod.rs @@ -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 = OnceCell::new(); + /// All Axelar event types supported by starknet #[derive(Eq, PartialEq)] pub enum EventType { @@ -13,11 +17,8 @@ pub enum EventType { impl EventType { fn parse(event_type_felt: FieldElement) -> Option { - // 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 = 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)