Skip to content

Commit aa382a7

Browse files
authored
feat(cast): add --file option for decode-calldata (#11201)
feat: add --file option for decode-calldata
1 parent 9518101 commit aa382a7

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

crates/cast/src/args.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,15 @@ pub async fn run_command(args: CastArgs) -> Result<()> {
194194
sh_println!("{}", SimpleCast::abi_encode_packed(&sig, &args)?)?
195195
}
196196
}
197-
CastSubcommand::DecodeCalldata { sig, calldata } => {
198-
let tokens = SimpleCast::calldata_decode(&sig, &calldata, true)?;
197+
CastSubcommand::DecodeCalldata { sig, calldata, file } => {
198+
let raw_hex = if let Some(file_path) = file {
199+
let contents = fs::read_to_string(&file_path)?;
200+
contents.trim().to_string()
201+
} else {
202+
calldata.unwrap()
203+
};
204+
205+
let tokens = SimpleCast::calldata_decode(&sig, &raw_hex, true)?;
199206
print_tokens(&tokens);
200207
}
201208
CastSubcommand::CalldataEncode { sig, args, file } => {

crates/cast/src/opts.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,12 @@ pub enum CastSubcommand {
574574
sig: String,
575575

576576
/// The ABI-encoded calldata.
577-
calldata: String,
577+
#[arg(required_unless_present = "file", index = 2)]
578+
calldata: Option<String>,
579+
580+
/// Load ABI-encoded calldata from a file instead.
581+
#[arg(long = "file", short = 'f', conflicts_with = "calldata")]
582+
file: Option<PathBuf>,
578583
},
579584

580585
/// Decode ABI-encoded string.

0 commit comments

Comments
 (0)