From dddf2f467af623c5f05450ba3bdeb38d86d62eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20W=C3=B3jcik?= Date: Wed, 11 Dec 2024 10:55:34 +0100 Subject: [PATCH 1/2] fix cancel_reservations typing --- lib/cli/arg_handling.rs | 6 +++--- lib/cli/transaction_builder_params.rs | 7 ++++--- lib/cli/transaction_v1_builder.rs | 4 ++-- src/transaction/creation_common.rs | 6 +++--- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/cli/arg_handling.rs b/lib/cli/arg_handling.rs index ee205cd..6cc25e3 100644 --- a/lib/cli/arg_handling.rs +++ b/lib/cli/arg_handling.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use casper_types::system::auction::{Reservation, ARG_VALIDATOR}; +use casper_types::system::auction::{DelegatorKind, Reservation, ARG_VALIDATOR}; use casper_types::TransferTarget; use casper_types::{bytesrepr::ToBytes, CLTyped, CLValueError, PublicKey, RuntimeArgs, URef, U512}; @@ -47,7 +47,7 @@ const ADD_RESERVATIONS_ARG_RESERVATIONS: RequiredArg> = RequiredArg::new("reservations"); const CANCEL_RESERVATIONS_ARG_VALIDATOR: RequiredArg = RequiredArg::new("validator"); -const CANCEL_RESERVATIONS_ARG_DELEGATORS: RequiredArg> = +const CANCEL_RESERVATIONS_ARG_DELEGATORS: RequiredArg> = RequiredArg::new("delegators"); struct RequiredArg { @@ -148,7 +148,7 @@ pub fn new_add_reservations_args( /// Creates a `RuntimeArgs` suitable for use in a cancel reservations transaction. pub fn new_cancel_reservations_args( validator: PublicKey, - delegators: Vec, + delegators: Vec, ) -> Result { let mut args = RuntimeArgs::new(); CANCEL_RESERVATIONS_ARG_VALIDATOR.insert(&mut args, validator)?; diff --git a/lib/cli/transaction_builder_params.rs b/lib/cli/transaction_builder_params.rs index a9582b5..d390b53 100644 --- a/lib/cli/transaction_builder_params.rs +++ b/lib/cli/transaction_builder_params.rs @@ -1,6 +1,7 @@ use casper_types::{ - bytesrepr::Bytes, system::auction::Reservation, AddressableEntityHash, PackageHash, PublicKey, - TransactionRuntime, TransferTarget, URef, U512, + bytesrepr::Bytes, + system::auction::{DelegatorKind, Reservation}, + AddressableEntityHash, PackageHash, PublicKey, TransactionRuntime, TransferTarget, URef, U512, }; /// An enum representing the parameters needed to construct a transaction builder @@ -69,7 +70,7 @@ pub enum TransactionBuilderParams<'a> { /// The validator for the cancel reservations transaction validator: PublicKey, /// List of delegatora for the cancel reservations transaction - delegators: Vec, + delegators: Vec, }, /// Parameters for the invocable entity variant of the transaction builder InvocableEntity { diff --git a/lib/cli/transaction_v1_builder.rs b/lib/cli/transaction_v1_builder.rs index ecb3861..a9310ce 100644 --- a/lib/cli/transaction_v1_builder.rs +++ b/lib/cli/transaction_v1_builder.rs @@ -9,7 +9,7 @@ use alloc::collections::BTreeSet; use alloc::vec::Vec; use casper_types::{ bytesrepr::{Bytes, ToBytes}, - system::auction::Reservation, + system::auction::{DelegatorKind, Reservation}, AddressableEntityHash, CLValueError, Digest, EntityVersion, InitiatorAddr, PackageHash, PricingMode, PublicKey, RuntimeArgs, SecretKey, TimeDiff, Timestamp, TransactionArgs, TransactionEntryPoint, TransactionInvocationTarget, TransactionRuntime, TransactionScheduling, @@ -302,7 +302,7 @@ impl<'a> TransactionV1Builder<'a> { /// transaction. pub fn new_cancel_reservations( validator: PublicKey, - delegators: Vec, + delegators: Vec, ) -> Result { let args = arg_handling::new_cancel_reservations_args(validator, delegators)?; let mut builder = TransactionV1Builder::new(); diff --git a/src/transaction/creation_common.rs b/src/transaction/creation_common.rs index 31351dc..f316283 100644 --- a/src/transaction/creation_common.rs +++ b/src/transaction/creation_common.rs @@ -1466,10 +1466,10 @@ mod reservations { mod delegators { use super::*; use casper_client::cli::CliError; - use casper_types::PublicKey; + use casper_types::system::auction::DelegatorKind; pub const ARG_NAME: &str = "delegators"; - const ARG_VALUE_NAME: &str = "JSON serialized Vec"; + const ARG_VALUE_NAME: &str = "JSON serialized Vec"; const ARG_HELP: &str = "list of delegator public keys for the cancel-reservations transaction"; pub fn arg() -> Arg { @@ -1488,7 +1488,7 @@ mod delegators { .unwrap_or_default() } - pub(super) fn parse_delegators(value: &str) -> Result, CliError> { + pub(super) fn parse_delegators(value: &str) -> Result, CliError> { if !value.is_empty() { serde_json::from_str(value).map_err(|_| { CliError::InvalidCLValue( From e349da0e5577545a38473621b6409d25047e363c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20W=C3=B3jcik?= Date: Wed, 11 Dec 2024 11:34:02 +0100 Subject: [PATCH 2/2] fix tests --- lib/cli/tests.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/cli/tests.rs b/lib/cli/tests.rs index 89a7cde..40f5657 100644 --- a/lib/cli/tests.rs +++ b/lib/cli/tests.rs @@ -447,9 +447,10 @@ mod transaction { use super::*; use crate::{cli::TransactionV1BuilderError, Error::TransactionBuild}; use casper_types::{ - bytesrepr::Bytes, system::auction::Reservation, PackageAddr, TransactionArgs, - TransactionEntryPoint, TransactionInvocationTarget, TransactionRuntimeParams, - TransactionTarget, TransferTarget, + bytesrepr::Bytes, + system::auction::{DelegatorKind, Reservation}, + PackageAddr, TransactionArgs, TransactionEntryPoint, TransactionInvocationTarget, + TransactionRuntimeParams, TransactionTarget, TransferTarget, }; use once_cell::sync::Lazy; use rand::{thread_rng, Rng}; @@ -1092,7 +1093,7 @@ mod transaction { let delegators = (0..rng.gen_range(1..10)) .map(|_| { let secret_key = SecretKey::generate_ed25519().unwrap(); - PublicKey::from(&secret_key) + DelegatorKind::PublicKey(PublicKey::from(&secret_key)) }) .collect(); @@ -1448,7 +1449,7 @@ mod transaction { let maybe_source = Some(source_uref); - let source_uref_cl = &CLValue::from_t(&source_uref).unwrap(); + let source_uref_cl = &CLValue::from_t(source_uref).unwrap(); let target_uref_cl = &CLValue::from_t(target_uref).unwrap(); let transaction_string_params = TransactionStrParams {