Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
5005: Fixed arg_handling code which forced optional arguments to be passed … r=zajko a=zajko

…as actual Option

This will affect the client-rs app

Co-authored-by: Jakub Zajkowski <[email protected]>
  • Loading branch information
casperlabs-bors-ng[bot] and Jakub Zajkowski authored Dec 5, 2024
2 parents 91871a3 + 0315d14 commit 1b626fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
15 changes: 8 additions & 7 deletions node/src/types/transaction/arg_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use tracing::debug;
const TRANSFER_ARG_AMOUNT: RequiredArg<U512> = RequiredArg::new("amount");
const TRANSFER_ARG_SOURCE: OptionalArg<URef> = OptionalArg::new("source");
const TRANSFER_ARG_TARGET: &str = "target";
const TRANSFER_ARG_ID: OptionalArg<u64> = OptionalArg::new("id");
// "id" for legacy reasons, if the argument is passed it is [Option]
const TRANSFER_ARG_ID: OptionalArg<Option<u64>> = OptionalArg::new("id");

const ADD_BID_ARG_PUBLIC_KEY: RequiredArg<PublicKey> = RequiredArg::new("public_key");
const ADD_BID_ARG_DELEGATION_RATE: RequiredArg<u8> = RequiredArg::new("delegation_rate");
Expand Down Expand Up @@ -111,16 +112,16 @@ impl<T> OptionalArg<T> {
Some(value) => value,
None => return Ok(None),
};
let value = parse_cl_value(cl_value, self.name)?;
Ok(value)
let value = parse_cl_value::<T>(cl_value, self.name)?;
Ok(Some(value))
}

#[cfg(test)]
fn insert(&self, args: &mut RuntimeArgs, value: T) -> Result<(), CLValueError>
where
T: CLTyped + ToBytes,
{
args.insert(self.name, Some(value))
args.insert(self.name, value)
}
}

Expand Down Expand Up @@ -165,8 +166,8 @@ pub fn new_transfer_args<A: Into<U512>, T: Into<TransferTarget>>(
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)
}
Expand Down Expand Up @@ -591,7 +592,7 @@ mod tests {
};
let expected_error = InvalidTransactionV1::UnexpectedArgType {
arg_name: TRANSFER_ARG_SOURCE.name.to_string(),
expected: vec![Option::<URef>::cl_type()],
expected: vec![URef::cl_type()],
got: CLType::U8,
};
assert_eq!(
Expand Down
10 changes: 5 additions & 5 deletions types/src/transaction/transaction_v1/arg_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const TRANSFER_ARG_AMOUNT: RequiredArg<U512> = RequiredArg::new("amount");

const TRANSFER_ARG_SOURCE: OptionalArg<URef> = OptionalArg::new("source");
const TRANSFER_ARG_TARGET: &str = "target";

const TRANSFER_ARG_ID: OptionalArg<u64> = OptionalArg::new("id");
// "id" for legacy reasons, if the argument is passed it is [Option]
const TRANSFER_ARG_ID: OptionalArg<Option<u64>> = OptionalArg::new("id");

const ADD_BID_ARG_PUBLIC_KEY: RequiredArg<PublicKey> = RequiredArg::new("public_key");
const ADD_BID_ARG_DELEGATION_RATE: RequiredArg<u8> = RequiredArg::new("delegation_rate");
Expand Down Expand Up @@ -77,7 +77,7 @@ impl<T> OptionalArg<T> {
where
T: CLTyped + ToBytes,
{
args.insert(self.name, Some(value))
args.insert(self.name, value)
}
}

Expand All @@ -101,8 +101,8 @@ pub(crate) fn new_transfer_args<A: Into<U512>, T: Into<TransferTarget>>(
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)
}
Expand Down

0 comments on commit 1b626fb

Please sign in to comment.