Skip to content

Commit

Permalink
fix 4-bytecalldata (#9952)
Browse files Browse the repository at this point in the history
* fix fourbytecalldata

* add test
  • Loading branch information
Haxry authored Feb 25, 2025
1 parent 4974a08 commit 9bcfbaa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/cast/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,21 @@ async fn main_args(args: CastArgs) -> Result<()> {
sh_println!("{sig}")?
}
}

CastSubcommand::FourByteCalldata { calldata } => {
let calldata = stdin::unwrap_line(calldata)?;

if calldata.len() == 10 {
let sigs = decode_function_selector(&calldata).await?;
if sigs.is_empty() {
eyre::bail!("No matching function signatures found for calldata `{calldata}`");
}
for sig in sigs {
sh_println!("{sig}")?
}
return Ok(());
}

let sigs = decode_calldata(&calldata).await?;
sigs.iter().enumerate().for_each(|(i, sig)| {
let _ = sh_println!("{}) \"{sig}\"", i + 1);
Expand All @@ -537,6 +550,7 @@ async fn main_args(args: CastArgs) -> Result<()> {
let tokens = SimpleCast::calldata_decode(sig, &calldata, true)?;
print_tokens(&tokens);
}

CastSubcommand::FourByteEvent { topic } => {
let topic = stdin::unwrap_line(topic)?;
let sigs = decode_event_topic(&topic).await?;
Expand Down
7 changes: 7 additions & 0 deletions crates/cast/tests/cli/selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ casttest!(fourbyte_calldata, |_prj, cmd| {
"#]]);
});

casttest!(fourbyte_calldata_only_selector, |_prj, cmd| {
cmd.args(["4byte-calldata", "0xa9059cbb"]).assert_success().stdout_eq(str![[r#"
transfer(address,uint256)
"#]]);
});

casttest!(fourbyte_calldata_alias, |_prj, cmd| {
cmd.args(["4byte-decode", "0xa9059cbb0000000000000000000000000a2ac0c368dc8ec680a0c98c907656bd970675950000000000000000000000000000000000000000000000000000000767954a79"]).assert_success().stdout_eq(str![[r#"
1) "transfer(address,uint256)"
Expand Down

0 comments on commit 9bcfbaa

Please sign in to comment.