refactor: abandon ChainCommunicationError type. embrace erasure

buddies-main-deployment
James Prestwich 4 years ago
parent ba46a337f4
commit 1a401eb1c1
No known key found for this signature in database
GPG Key ID: 75A7F5C06D747046
  1. 10
      rust/optics-base/config/default.toml
  2. 4
      rust/optics-base/src/abis/mod.rs
  3. 12
      rust/optics-base/src/main.rs
  4. 10
      rust/optics-core/src/traits/home.rs
  5. 25
      rust/optics-core/src/traits/mod.rs

@ -7,16 +7,16 @@ rpc-style = "Ethereum"
connection = { type = "Http", url = "http://localhost:8545" }
[replicas]
[replicas.Ethereum]
[replicas.EthereumMainnet]
slip44 = 60
address = "0x0000000000000000000000000000000000000000"
rpc-style = "Ethereum"
[replicas.Ethereum.config]
[replicas.EthereumMainnet.config]
connection = { type = "Ws", url = "ws://localhost:8545"}
[replicas.EthClassic]
[replicas.EthereumClassic]
slip44 = 61
address = "0x0000000000000000000000000000000000000000"
rpc-style = "Ethereum"
[replicas.EthClassic.config]
connection = { type = "Ws", url = ""}
[replicas.EthereumClassic.config]
connection = { type = "Ws", url = "ws://localhost:8545"}

@ -53,7 +53,7 @@ where
.client()
.get_transaction_receipt(txid)
.await
.map_err(|e| ChainCommunicationError::CustomError(Box::new(e)))?;
.map_err(Box::new)?;
Ok(receipt_opt.map(Into::into))
}
@ -209,7 +209,7 @@ where
.client()
.get_transaction_receipt(txid)
.await
.map_err(|e| ChainCommunicationError::CustomError(Box::new(e)))?;
.map_err(Box::new)?;
Ok(receipt_opt.map(Into::into))
}

@ -19,7 +19,10 @@ pub mod settings;
use optics_core::traits::{Home, Replica};
use color_eyre::{eyre::WrapErr, Result};
use color_eyre::{
eyre::{eyre, WrapErr},
Result,
};
use std::collections::HashMap;
/// The global app context.
@ -54,15 +57,16 @@ impl ChainConnections {
);
}
let app = ChainConnections { home, replicas };
Ok(app)
Ok(ChainConnections { home, replicas })
}
}
async fn _main(settings: settings::Settings) -> Result<()> {
let app = ChainConnections::try_from_settings(&settings).await?;
println!("\n{:#?}", &app);
let current = app.home.current_root().await.map_err(|e| eyre!(e))?;
println!("current is {}", &current);
Ok(())
}

@ -30,10 +30,7 @@ pub trait Home: Common + Send + Sync + std::fmt::Debug {
) -> Result<Option<Message>, ChainCommunicationError> {
self.raw_message_by_sequence(destination, sequence)
.await?
.map(|buf| {
Message::read_from(&mut &buf[..])
.map_err(|e| ChainCommunicationError::CustomError(Box::new(e)))
})
.map(|buf| Message::read_from(&mut &buf[..]).map_err(Into::into))
.transpose()
}
@ -52,10 +49,7 @@ pub trait Home: Common + Send + Sync + std::fmt::Debug {
) -> Result<Option<Message>, ChainCommunicationError> {
self.raw_message_by_leaf(leaf)
.await?
.map(|buf| {
Message::read_from(&mut &buf[..])
.map_err(|e| ChainCommunicationError::CustomError(Box::new(e)))
})
.map(|buf| Message::read_from(&mut &buf[..]).map_err(Into::into))
.transpose()
}

@ -6,7 +6,6 @@ pub mod replica;
use async_trait::async_trait;
use ethers_core::types::{TransactionReceipt, H256};
use thiserror::Error;
use crate::{utils::domain_hash, SignedUpdate};
@ -41,28 +40,8 @@ impl From<TransactionReceipt> for TxOutcome {
}
}
#[derive(Debug, Error)]
/// Error type for chain communication
pub enum ChainCommunicationError {
/// Provider Error
#[error(transparent)]
ProviderError(#[from] ethers_providers::ProviderError),
/// Contract Error
#[error(transparent)]
ContractError(Box<dyn std::error::Error>),
/// Custom error or contract error
#[error(transparent)]
CustomError(#[from] Box<dyn std::error::Error>),
}
impl<M> From<ethers_contract::ContractError<M>> for ChainCommunicationError
where
M: ethers_providers::Middleware + 'static,
{
fn from(e: ethers_contract::ContractError<M>) -> Self {
Self::ContractError(Box::new(e))
}
}
/// ChainCommunicationError is a type-erased, thread safe, std error
pub type ChainCommunicationError = Box<dyn std::error::Error + Send + Sync>;
/// Interface for attributes shared by Home and Replica
#[async_trait]

Loading…
Cancel
Save