Skip to content

Commit

Permalink
feat: add cast sig (#645)
Browse files Browse the repository at this point in the history
* feat: cast sig

* docs: update cast feature list
  • Loading branch information
mds1 authored Jan 31, 2022
1 parent 4717708 commit 9fb5d9d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- [x] `calldata`
- [x] `chain`
- [x] `chain-id`
- [x] `client`
- [x] `code`
- [ ] `debug`
- [x] `estimate`
Expand All @@ -58,6 +59,7 @@
- [x] `resolve-name`
- [ ] `run-tx`
- [x] `send` (partial)
- [x] `sig`
- [ ] `sign`
- [x] `storage`
- [x] `tx`
7 changes: 7 additions & 0 deletions cli/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use cast::{Cast, SimpleCast};
mod opts;
use cast::InterfacePath;
use ethers::{
contract::BaseContract,
core::{
abi::parse_abi,
rand::thread_rng,
types::{BlockId, BlockNumber::Latest},
},
Expand Down Expand Up @@ -446,6 +448,11 @@ async fn main() -> eyre::Result<()> {
SimpleCast::etherscan_source(chain.inner, address, etherscan_api_key).await?
);
}
Subcommands::Sig { sig } => {
let contract = BaseContract::from(parse_abi(&[&sig]).unwrap());
let selector = contract.abi().functions().last().unwrap().short_signature();
println!("0x{}", hex::encode(selector));
}
Subcommands::Wallet { command } => match command {
WalletSubcommands::New { path, password, unsafe_password } => {
let mut rng = thread_rng();
Expand Down
5 changes: 5 additions & 0 deletions cli/src/opts/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@ pub enum Subcommands {
#[clap(flatten)]
chain: ClapChain,
},
#[clap(name = "sig", about = "Print a function's 4-byte selector")]
Sig {
#[clap(help = "The human-readable function signature, e.g. 'transfer(address,uint256)'")]
sig: String,
},
#[clap(about = "generate shell completions script")]
Completions {
#[clap(arg_enum)]
Expand Down

0 comments on commit 9fb5d9d

Please sign in to comment.