From 4f0d83f59e1377e7a81c6908e9cc4df79c1a1f1a Mon Sep 17 00:00:00 2001 From: Gilad Chase Date: Wed, 18 Sep 2024 14:41:22 +0300 Subject: [PATCH] feat(base_layer): add safe conversion to felt commit-id:a4bb6349 --- crates/papyrus_base_layer/Cargo.toml | 1 + .../papyrus_base_layer/src/ethereum_base_layer_contract.rs | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/papyrus_base_layer/Cargo.toml b/crates/papyrus_base_layer/Cargo.toml index 33cf92f1b1..aaa624cdf3 100644 --- a/crates/papyrus_base_layer/Cargo.toml +++ b/crates/papyrus_base_layer/Cargo.toml @@ -19,6 +19,7 @@ ethers.workspace = true papyrus_config.workspace = true serde.workspace = true serde_json.workspace = true +starknet-types-core.workspace = true starknet_api.workspace = true thiserror.workspace = true tokio = { workspace = true, features = ["full", "sync"] } diff --git a/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs b/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs index f89bd3d263..22785eafa8 100644 --- a/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs +++ b/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs @@ -16,6 +16,7 @@ use papyrus_config::{ParamPath, ParamPrivacyInput, SerializationType, Serialized use serde::{Deserialize, Serialize}; use starknet_api::block::{BlockHash, BlockNumber}; use starknet_api::hash::StarkHash; +use starknet_types_core::felt; use url::Url; use crate::BaseLayerContract; @@ -30,6 +31,8 @@ pub enum EthereumBaseLayerError { Serde(#[from] serde_json::Error), #[error(transparent)] TypeError(#[from] alloy_sol_types::Error), + #[error(transparent)] + FeltParseError(#[from] felt::FromStrError), } #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] @@ -120,8 +123,7 @@ impl BaseLayerContract for EthereumBaseLayerContract { Ok(Some(( BlockNumber(sol_data::Uint::<64>::abi_decode(&state_block_number, true)?), - // TODO: use safe conversion. - BlockHash(StarkHash::from_hex_unchecked(&state_block_hash.to_string())), + BlockHash(StarkHash::from_hex(&state_block_hash.to_string())?), ))) } }