Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(base_layer): add safe conversion to felt #856

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())?),
)))
}
}
Loading