derive more

This commit is contained in:
Bryan Stitt 2022-04-26 16:50:02 +00:00
parent 1aa6b89fc4
commit a870dfa63a
3 changed files with 27 additions and 16 deletions

22
Cargo.lock generated

@ -546,6 +546,12 @@ version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3"
[[package]]
name = "convert_case"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "convert_case"
version = "0.5.0"
@ -699,6 +705,19 @@ dependencies = [
"const-oid",
]
[[package]]
name = "derive_more"
version = "0.99.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
dependencies = [
"convert_case 0.4.0",
"proc-macro2",
"quote",
"rustc_version",
"syn",
]
[[package]]
name = "dialoguer"
version = "0.8.0"
@ -987,7 +1006,7 @@ dependencies = [
"arrayvec",
"bytes",
"cargo_metadata",
"convert_case",
"convert_case 0.5.0",
"elliptic-curve",
"ethabi",
"generic-array 0.14.5",
@ -3734,6 +3753,7 @@ dependencies = [
"argh",
"atomic-counter",
"dashmap",
"derive_more",
"ethers",
"futures",
"governor",

@ -10,6 +10,7 @@ argh = "0.1.7"
anyhow = "1.0.57"
atomic-counter = "1.0.1"
dashmap = "5.2.0"
derive_more = "0.99"
ethers = { git = "https://github.com/gakonst/ethers-rs", features = ["rustls", "ws"] }
futures = { version = "0.3.21", features = ["thread-pool"] }
governor = { version = "0.4.2", features = ["dashmap", "std"] }

@ -1,5 +1,6 @@
// TODO: don't use RwLock<HashMap>. i think we need a concurrent hashmap or we will hit all sorts of deadlocks
use derive_more::From;
use ethers::prelude::{Block, TxHash};
use ethers::providers::Middleware;
use futures::future;
@ -25,27 +26,15 @@ static APP_USER_AGENT: &str = concat!(
env!("CARGO_PKG_VERSION"),
);
// TODO: i'm not sure we need this. i think we can use dyn
// TODO: i tried to use Box<dyn Provider>, but hit https://github.com/gakonst/ethers-rs/issues/592
#[derive(From)]
enum EthersProvider {
Http(ethers::providers::Provider<ethers::providers::Http>),
Ws(ethers::providers::Provider<ethers::providers::Ws>),
}
// TODO: seems like this should be derivable
impl From<ethers::providers::Provider<ethers::providers::Http>> for EthersProvider {
fn from(item: ethers::providers::Provider<ethers::providers::Http>) -> Self {
EthersProvider::Http(item)
}
}
// TODO: seems like this should be derivable
impl From<ethers::providers::Provider<ethers::providers::Ws>> for EthersProvider {
fn from(item: ethers::providers::Provider<ethers::providers::Ws>) -> Self {
EthersProvider::Ws(item)
}
}
impl EthersProvider {
/// Send a web3 request
pub async fn request(
&self,
method: &str,
@ -57,6 +46,7 @@ impl EthersProvider {
}
}
/// Subscribe to new block heads
pub async fn new_heads(&self, url: String, blocks: Arc<BlockMap>) -> anyhow::Result<()> {
// TODO: automatically reconnect
match &self {