Skip to content

Commit ad78ed2

Browse files
authored
fix: deduplicate “0x” prefix stripping in args via shared helper (#12365)
* Update lib.rs * Update args.rs
1 parent f967713 commit ad78ed2

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

crates/cast/src/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub async fn run_command(args: CastArgs) -> Result<()> {
234234
let event = get_event(event_sig.as_str())?;
235235
event.decode_log_parts(core::iter::once(event.selector()), &hex::decode(data)?)?
236236
} else {
237-
let data = data.strip_prefix("0x").unwrap_or(data.as_str());
237+
let data = crate::strip_0x(&data);
238238
let selector = data.get(..64).unwrap_or_default();
239239
let selector = selector.parse()?;
240240
let identified_event =
@@ -254,7 +254,7 @@ pub async fn run_command(args: CastArgs) -> Result<()> {
254254
let error = if let Some(err_sig) = sig {
255255
get_error(err_sig.as_str())?
256256
} else {
257-
let data = data.strip_prefix("0x").unwrap_or(data.as_str());
257+
let data = crate::strip_0x(&data);
258258
let selector = data.get(..8).unwrap_or_default();
259259
let identified_error =
260260
SignaturesIdentifier::new(false)?.identify_error(selector.parse()?).await;

crates/cast/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2401,7 +2401,7 @@ impl SimpleCast {
24012401
}
24022402
}
24032403

2404-
fn strip_0x(s: &str) -> &str {
2404+
pub(crate) fn strip_0x(s: &str) -> &str {
24052405
s.strip_prefix("0x").unwrap_or(s)
24062406
}
24072407

0 commit comments

Comments
 (0)