Verify chain ID on start

This commit is contained in:
silverpill 2022-05-28 00:04:21 +00:00
parent 14cb90224f
commit c2c3ff1544
2 changed files with 6 additions and 8 deletions

View file

@ -57,6 +57,10 @@ pub async fn get_contracts(
config: &BlockchainConfig,
) -> Result<ContractSet, EthereumError> {
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(

View file

@ -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,