From 40dc003403b051bff3720e235614a19a2000fdeb Mon Sep 17 00:00:00 2001 From: EjembiEmmanuel Date: Tue, 9 Jul 2024 12:59:08 +0100 Subject: [PATCH] refac: modify signed integer decoder --- bin/sozo/src/commands/calldata_decoder.rs | 22 +++++----------------- bin/sozo/src/commands/execute.rs | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/bin/sozo/src/commands/calldata_decoder.rs b/bin/sozo/src/commands/calldata_decoder.rs index 021572b4e8..b8c3bedff5 100644 --- a/bin/sozo/src/commands/calldata_decoder.rs +++ b/bin/sozo/src/commands/calldata_decoder.rs @@ -1,5 +1,4 @@ use anyhow::{self, Result}; -use bigdecimal::FromPrimitive; use cainome::cairo_serde::{ByteArray, CairoSerde}; use num_bigint::BigUint; use starknet::core::types::{Felt, FromStrError}; @@ -98,21 +97,10 @@ impl CalldataDecoder for ShortStrCalldataDecoder { struct SignedIntegerCalldataDecoder; impl CalldataDecoder for SignedIntegerCalldataDecoder { fn decode(&self, input: &str) -> DecoderResult> { - match input.parse::() { - Ok(value) if value <= i8::MAX as i128 && value >= i8::MIN as i128 => { - Ok(vec![Felt::from_i8(value as i8).expect("Invalid numeric string")]) - } - Ok(value) if value <= i16::MAX as i128 && value >= i16::MIN as i128 => { - Ok(vec![Felt::from_i16(value as i16).expect("Invalid numeric string")]) - } - Ok(value) if value <= i32::MAX as i128 && value >= i32::MIN as i128 => { - Ok(vec![Felt::from_i32(value as i32).expect("Invalid numeric string")]) - } - Ok(value) if value <= i64::MAX as i128 && value >= i64::MIN as i128 => { - Ok(vec![Felt::from_i64(value as i64).expect("Invalid numeric string")]) - } - Ok(value) => Ok(vec![Felt::from_i128(value).expect("Invalid numeric string")]), - Err(_) => Err(CalldataDecoderError::ParseError("Invalid numeric string".to_string())), + if let Ok(value) = input.parse::() { + Ok(vec![value.into()]) + } else { + Err(CalldataDecoderError::ParseError("Invalid numeric string".to_string())) } } } @@ -174,7 +162,7 @@ fn decode_inner(item: &str) -> DecoderResult> { "u256" => U256CalldataDecoder.decode(value)?, "str" => StrCalldataDecoder.decode(value)?, "sstr" => ShortStrCalldataDecoder.decode(value)?, - "-" => SignedIntegerCalldataDecoder.decode(value)?, + "int" => SignedIntegerCalldataDecoder.decode(value)?, _ => DefaultCalldataDecoder.decode(item)?, } } else { diff --git a/bin/sozo/src/commands/execute.rs b/bin/sozo/src/commands/execute.rs index 89e7e5fb6d..145b0b81e0 100644 --- a/bin/sozo/src/commands/execute.rs +++ b/bin/sozo/src/commands/execute.rs @@ -31,7 +31,7 @@ pub struct ExecuteArgs { - u256: A 256-bit unsigned integer. - sstr: A cairo short string. - str: A cairo string (ByteArray). - - -: A signed integer. + - int: A signed integer. - no prefix: A cairo felt or any type that fit into one felt.")] pub calldata: Option,