From 9710837a9e3fcf2e8f2a918e211e3b60f4a58065 Mon Sep 17 00:00:00 2001 From: Gilad Chase Date: Tue, 17 Sep 2024 19:07:10 +0300 Subject: [PATCH] refactor(base_layer): remove unnecessary dep + style commit-id:19ed8b4a --- Cargo.lock | 1 - Cargo.toml | 1 - crates/papyrus_base_layer/Cargo.toml | 1 - .../src/ethereum_base_layer_contract.rs | 23 ++++++++++--------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f7193506d..313af11e06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7082,7 +7082,6 @@ version = "0.0.0" dependencies = [ "alloy-contract", "alloy-dyn-abi", - "alloy-json-abi", "alloy-json-rpc", "alloy-primitives", "alloy-provider", diff --git a/Cargo.toml b/Cargo.toml index a5ea8cb75f..9412b453cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,6 @@ license-file = "LICENSE" # TODO: Remove this once udeps is fixed. alloy-contract = "0.3.5" alloy-dyn-abi = "0.8.3" -alloy-json-abi = "0.8.3" alloy-json-rpc = "0.3.5" alloy-primitives = "0.8.3" alloy-provider = "0.3.5" diff --git a/crates/papyrus_base_layer/Cargo.toml b/crates/papyrus_base_layer/Cargo.toml index ca06b1bb9f..3fd20b7073 100644 --- a/crates/papyrus_base_layer/Cargo.toml +++ b/crates/papyrus_base_layer/Cargo.toml @@ -8,7 +8,6 @@ license-file.workspace = true [dependencies] alloy-contract.workspace = true alloy-dyn-abi.workspace = true -alloy-json-abi.workspace = true alloy-json-rpc.workspace = true alloy-primitives.workspace = true alloy-provider.workspace = true 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 3b6c028f8a..0e119cfacf 100644 --- a/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs +++ b/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs @@ -3,7 +3,8 @@ use std::future::IntoFuture; use alloy_contract::{ContractInstance, Interface}; use alloy_dyn_abi::SolType; -use alloy_json_abi::JsonAbi; +use alloy_json_rpc::RpcError; +use alloy_primitives::hex::FromHexError; use alloy_primitives::Address; use alloy_provider::network::Ethereum; use alloy_provider::{Provider, ProviderBuilder, RootProvider}; @@ -23,17 +24,17 @@ use crate::BaseLayerContract; #[derive(thiserror::Error, Debug)] pub enum EthereumBaseLayerError { #[error(transparent)] - FromHex(#[from] alloy_primitives::hex::FromHexError), + Contract(#[from] alloy_contract::Error), #[error(transparent)] - Url(#[from] ParseError), + FromHex(#[from] FromHexError), #[error(transparent)] - Serde(#[from] serde_json::Error), + RpcError(#[from] RpcError), #[error(transparent)] - Contract(#[from] alloy_contract::Error), + Serde(#[from] serde_json::Error), #[error(transparent)] TypeError(#[from] alloy_sol_types::Error), #[error(transparent)] - RpcError(#[from] alloy_json_rpc::RpcError), + Url(#[from] ParseError), } #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] @@ -71,18 +72,18 @@ impl Default for EthereumBaseLayerConfig { } } +#[derive(Debug)] pub struct EthereumBaseLayerContract { contract: ContractInstance, RootProvider>, Ethereum>, } impl EthereumBaseLayerContract { pub fn new(config: EthereumBaseLayerConfig) -> Result { - let address = config.starknet_contract_address.parse::
()?; + let address: Address = config.starknet_contract_address.parse()?; let client = ProviderBuilder::new().on_http(config.node_url.parse()?); // The solidity contract was pre-compiled, and only the relevant functions were kept. - let abi: JsonAbi = - serde_json::from_str::(include_str!("core_contract_latest_block.abi"))?; + let abi = serde_json::from_str(include_str!("core_contract_latest_block.abi"))?; Ok(Self { contract: ContractInstance::new(address, client, Interface::new(abi)) }) } } @@ -93,14 +94,14 @@ impl BaseLayerContract for EthereumBaseLayerContract { async fn latest_proved_block( &self, - min_confirmations: Option, + finality: Option, ) -> Result, Self::Error> { let ethereum_block_number = self .contract .provider() .get_block_number() .await? - .checked_sub(min_confirmations.unwrap_or(0).into()); + .checked_sub(finality.unwrap_or_default()); let Some(ethereum_block_number) = ethereum_block_number else { return Ok(None); };