From c2c3ff1544dbab0c55571025c290ed7f5f0fa497 Mon Sep 17 00:00:00 2001 From: silverpill Date: Sat, 28 May 2022 00:04:21 +0000 Subject: [PATCH] Verify chain ID on start --- src/ethereum/contracts.rs | 4 ++++ src/ethereum/errors.rs | 10 ++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ethereum/contracts.rs b/src/ethereum/contracts.rs index 1a41bd3..9cf9db1 100644 --- a/src/ethereum/contracts.rs +++ b/src/ethereum/contracts.rs @@ -57,6 +57,10 @@ pub async fn get_contracts( config: &BlockchainConfig, ) -> Result { let web3 = connect(&config.api_url)?; + let chain_id = web3.eth().chain_id().await?; + if chain_id != config.ethereum_chain_id().into() { + return Err(EthereumError::ImproperlyConfigured("incorrect chain ID")); + }; let adapter_abi = load_abi(&config.contract_dir, ADAPTER)?; let adapter_address = parse_address(&config.contract_address)?; let adapter = Contract::from_json( diff --git a/src/ethereum/errors.rs b/src/ethereum/errors.rs index 4c8d3d4..064253f 100644 --- a/src/ethereum/errors.rs +++ b/src/ethereum/errors.rs @@ -5,11 +5,8 @@ use super::utils::AddressError; #[derive(thiserror::Error, Debug)] pub enum EthereumError { - #[error("io error")] - IoError(#[from] std::io::Error), - - #[error("json error")] - JsonError(#[from] serde_json::Error), + #[error("{0}")] + ImproperlyConfigured(&'static str), #[error("invalid address")] InvalidAddress(#[from] AddressError), @@ -26,9 +23,6 @@ pub enum EthereumError { #[error("contract error")] ContractError(#[from] web3::contract::Error), - #[error("improprely configured")] - ImproperlyConfigured, - #[error("data conversion error")] ConversionError,