From 987710e6950cfe1495c824519e77f3de10ce7a52 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 ce4ba84cf2..fdec849f8e 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 ada17f3104..7042800e08 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())?), ))) } }