Skip to content

Commit

Permalink
feat: support block option in cast call (gakonst#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
mds1 authored Jan 30, 2022
1 parent fee6b51 commit 46e36e8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ where
args: (&str, Vec<String>),
chain: Chain,
etherscan_api_key: Option<String>,
block: Option<BlockId>,
) -> Result<String> {
let (tx, func) = self
.build_tx(from, to, Some(args), None, None, None, chain, etherscan_api_key, false)
.await?;
let res = self.provider.call(&tx, None).await?;
let res = self.provider.call(&tx, block).await?;

// decode args into tokens
let func = func.expect("no valid function signature was provided.");
Expand Down
5 changes: 3 additions & 2 deletions cli/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async fn main() -> eyre::Result<()> {
let provider = Provider::try_from(rpc_url)?;
println!("{}", Cast::new(provider).block_number().await?);
}
Subcommands::Call { eth, address, sig, args } => {
Subcommands::Call { eth, address, sig, args, block } => {
let provider = Provider::try_from(eth.rpc_url()?)?;
println!(
"{}",
Expand All @@ -149,7 +149,8 @@ async fn main() -> eyre::Result<()> {
address,
(&sig, args),
eth.chain,
eth.etherscan_api_key
eth.etherscan_api_key,
block
)
.await?
);
Expand Down
2 changes: 2 additions & 0 deletions cli/src/opts/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ pub enum Subcommands {
address: NameOrAddress,
sig: String,
args: Vec<String>,
#[clap(long, short, help = "the block you want to query, can also be earliest/latest/pending", parse(try_from_str = parse_block_id))]
block: Option<BlockId>,
#[clap(flatten)]
eth: EthereumOpts,
},
Expand Down

0 comments on commit 46e36e8

Please sign in to comment.