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 committed Sep 18, 2024
1 parent 23fa49d commit 987710e
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 @@ -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)]
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 987710e

Please sign in to comment.