From 4a934f8834fe73e5a39168204465fb6ac1912ba0 Mon Sep 17 00:00:00 2001 From: Jakub Zajkowski Date: Wed, 4 Dec 2024 19:45:06 +0100 Subject: [PATCH 1/2] Fixed arg_handling code which forced optional arguments to be passed as actual Option --- node/src/types/transaction/arg_handling.rs | 11 ++++++----- types/src/transaction/transaction_v1/arg_handling.rs | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/node/src/types/transaction/arg_handling.rs b/node/src/types/transaction/arg_handling.rs index 0fe19b5145..f669df565a 100644 --- a/node/src/types/transaction/arg_handling.rs +++ b/node/src/types/transaction/arg_handling.rs @@ -15,7 +15,8 @@ use tracing::debug; const TRANSFER_ARG_AMOUNT: RequiredArg = RequiredArg::new("amount"); const TRANSFER_ARG_SOURCE: OptionalArg = OptionalArg::new("source"); const TRANSFER_ARG_TARGET: &str = "target"; -const TRANSFER_ARG_ID: OptionalArg = OptionalArg::new("id"); +// "id" for legacy reasons, if the argument is passed it is [Option] +const TRANSFER_ARG_ID: OptionalArg> = OptionalArg::new("id"); const ADD_BID_ARG_PUBLIC_KEY: RequiredArg = RequiredArg::new("public_key"); const ADD_BID_ARG_DELEGATION_RATE: RequiredArg = RequiredArg::new("delegation_rate"); @@ -111,8 +112,8 @@ impl OptionalArg { Some(value) => value, None => return Ok(None), }; - let value = parse_cl_value(cl_value, self.name)?; - Ok(value) + let value = parse_cl_value::(cl_value, self.name)?; + Ok(Some(value)) } #[cfg(test)] @@ -165,8 +166,8 @@ pub fn new_transfer_args, T: Into>( TransferTarget::URef(uref) => args.insert(TRANSFER_ARG_TARGET, uref)?, } TRANSFER_ARG_AMOUNT.insert(&mut args, amount.into())?; - if let Some(id) = maybe_id { - TRANSFER_ARG_ID.insert(&mut args, id)?; + if maybe_id.is_some() { + TRANSFER_ARG_ID.insert(&mut args, maybe_id)?; } Ok(args) } diff --git a/types/src/transaction/transaction_v1/arg_handling.rs b/types/src/transaction/transaction_v1/arg_handling.rs index 1650e055b6..fbfe008891 100644 --- a/types/src/transaction/transaction_v1/arg_handling.rs +++ b/types/src/transaction/transaction_v1/arg_handling.rs @@ -8,8 +8,8 @@ const TRANSFER_ARG_AMOUNT: RequiredArg = RequiredArg::new("amount"); const TRANSFER_ARG_SOURCE: OptionalArg = OptionalArg::new("source"); const TRANSFER_ARG_TARGET: &str = "target"; - -const TRANSFER_ARG_ID: OptionalArg = OptionalArg::new("id"); +// "id" for legacy reasons, if the argument is passed it is [Option] +const TRANSFER_ARG_ID: OptionalArg> = OptionalArg::new("id"); const ADD_BID_ARG_PUBLIC_KEY: RequiredArg = RequiredArg::new("public_key"); const ADD_BID_ARG_DELEGATION_RATE: RequiredArg = RequiredArg::new("delegation_rate"); @@ -101,8 +101,8 @@ pub(crate) fn new_transfer_args, T: Into>( TransferTarget::URef(uref) => args.insert(TRANSFER_ARG_TARGET, uref)?, } TRANSFER_ARG_AMOUNT.insert(&mut args, amount.into())?; - if let Some(id) = maybe_id { - TRANSFER_ARG_ID.insert(&mut args, id)?; + if maybe_id.is_some() { + TRANSFER_ARG_ID.insert(&mut args, maybe_id)?; } Ok(args) } From 0315d145fea2c949132b9f0977e6d7f489ec81a1 Mon Sep 17 00:00:00 2001 From: Jakub Zajkowski Date: Thu, 5 Dec 2024 00:38:41 +0100 Subject: [PATCH 2/2] Fixing failing tests --- node/src/types/transaction/arg_handling.rs | 4 ++-- types/src/transaction/transaction_v1/arg_handling.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/node/src/types/transaction/arg_handling.rs b/node/src/types/transaction/arg_handling.rs index f669df565a..e31ff8394c 100644 --- a/node/src/types/transaction/arg_handling.rs +++ b/node/src/types/transaction/arg_handling.rs @@ -121,7 +121,7 @@ impl OptionalArg { where T: CLTyped + ToBytes, { - args.insert(self.name, Some(value)) + args.insert(self.name, value) } } @@ -592,7 +592,7 @@ mod tests { }; let expected_error = InvalidTransactionV1::UnexpectedArgType { arg_name: TRANSFER_ARG_SOURCE.name.to_string(), - expected: vec![Option::::cl_type()], + expected: vec![URef::cl_type()], got: CLType::U8, }; assert_eq!( diff --git a/types/src/transaction/transaction_v1/arg_handling.rs b/types/src/transaction/transaction_v1/arg_handling.rs index fbfe008891..3bd8f7a14b 100644 --- a/types/src/transaction/transaction_v1/arg_handling.rs +++ b/types/src/transaction/transaction_v1/arg_handling.rs @@ -77,7 +77,7 @@ impl OptionalArg { where T: CLTyped + ToBytes, { - args.insert(self.name, Some(value)) + args.insert(self.name, value) } }