start using ethers-rs

This commit is contained in:
Bryan Stitt 2022-04-25 19:42:51 +00:00
parent 7705991b4c
commit 969bb32495
4 changed files with 2166 additions and 15 deletions

2157
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,7 @@ argh = "0.1.7"
anyhow = "1.0.57"
atomic-counter = "1.0.1"
dashmap = "5.2.0"
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"] }
tokio = { version = "1.17.0", features = ["full"] }

21
examples/watch_blocks.rs Normal file
View File

@ -0,0 +1,21 @@
use ethers::prelude::*;
use std::time::Duration;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// let ws = Ws::connect("ws://10.11.12.16:8545").await?;
let ws = Ws::connect("ws://10.11.12.16:8946").await?;
let provider = Provider::new(ws).interval(Duration::from_secs(1));
let mut stream = provider.watch_blocks().await?.take(5);
while let Some(block_number) = stream.next().await {
let block = provider.get_block(block_number).await?.unwrap();
println!(
"Ts: {:?}, block number: {} -> {:?}",
block.timestamp,
block.number.unwrap(),
block.hash.unwrap()
);
}
Ok(())
}

View File

@ -45,7 +45,7 @@ async fn handle_new_head_message(message: tungstenite::Message) -> anyhow::Resul
// TODO: parse the message as json and get out the block data. then update a map for this rpc
println!("now what? {:?}", data);
unimplemented!();
Ok(())
}
impl BalancedRpcs {