Skip to content

Commit

Permalink
Seth: block-number
Browse files Browse the repository at this point in the history
  • Loading branch information
Anish-Agnihotri committed Sep 19, 2021
1 parent 425b884 commit 072670a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dapptools/src/seth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ async fn main() -> eyre::Result<()> {
.await?
);
}
Subcommands::BlockNumber { rpc_url } => {
let provider = Provider::try_from(rpc_url)?;
println!("{}", Seth::new(provider).block_number().await?);
}
Subcommands::Call {
rpc_url,
address,
Expand Down
6 changes: 6 additions & 0 deletions dapptools/src/seth_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ pub enum Subcommands {
#[structopt(long, env = "ETH_RPC_URL")]
rpc_url: String,
},
#[structopt(name = "block-number")]
#[structopt(about = "returns latest block number")]
BlockNumber {
#[structopt(long, env = "ETH_RPC_URL")]
rpc_url: String,
},
#[structopt(name = "call")]
#[structopt(about = "Perform a local call to <to> without publishing a transaction.")]
Call {
Expand Down
17 changes: 17 additions & 0 deletions seth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@ where

Ok(block)
}

/// ```no_run
/// use seth::Seth;
/// use ethers_providers::{Provider, Http};
/// use std::convert::TryFrom;
///
/// # async fn foo() -> eyre::Result<()> {
/// let provider = Provider::<Http>::try_from("http://localhost:8545")?;
/// let seth = Seth::new(provider);
/// let latest_block_number = seth.block_number().await?;
/// println!("{}", latest_block_number);
/// # Ok(())
/// # }
/// ```
pub async fn block_number(&self) -> Result<U64, M::Error> {
self.provider.get_block_number().await
}
}

pub struct SimpleSeth;
Expand Down

0 comments on commit 072670a

Please sign in to comment.