Skip to content

Commit

Permalink
feat(base_layer): add safe conversion to felt
Browse files Browse the repository at this point in the history
commit-id:a4bb6349
  • Loading branch information
Gilad Chase authored and giladchase committed Sep 19, 2024
1 parent ac6ff34 commit 633f8fd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/papyrus_base_layer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
6 changes: 4 additions & 2 deletions crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,8 @@ pub enum EthereumBaseLayerError {
#[error(transparent)]
Contract(#[from] alloy_contract::Error),
#[error(transparent)]
FeltParseError(#[from] felt::FromStrError),
#[error(transparent)]
RpcError(#[from] RpcError<TransportErrorKind>),
#[error(transparent)]
Serde(#[from] serde_json::Error),
Expand Down Expand Up @@ -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())?),
)))
}
}

0 comments on commit 633f8fd

Please sign in to comment.