Skip to content

Commit

Permalink
Merge pull request #219 from teonite/fix_cancel_reservations_args
Browse files Browse the repository at this point in the history
Fix cancel reservations args
  • Loading branch information
wojcik91 authored Dec 12, 2024
2 parents 686ad6d + e349da0 commit 2e4bfcd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/cli/arg_handling.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -48,7 +48,7 @@ const ADD_RESERVATIONS_ARG_RESERVATIONS: RequiredArg<Vec<Reservation>> =
RequiredArg::new("reservations");

const CANCEL_RESERVATIONS_ARG_VALIDATOR: RequiredArg<PublicKey> = RequiredArg::new("validator");
const CANCEL_RESERVATIONS_ARG_DELEGATORS: RequiredArg<Vec<PublicKey>> =
const CANCEL_RESERVATIONS_ARG_DELEGATORS: RequiredArg<Vec<DelegatorKind>> =
RequiredArg::new("delegators");

struct RequiredArg<T> {
Expand Down Expand Up @@ -149,7 +149,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<PublicKey>,
delegators: Vec<DelegatorKind>,
) -> Result<RuntimeArgs, CLValueError> {
let mut args = RuntimeArgs::new();
CANCEL_RESERVATIONS_ARG_VALIDATOR.insert(&mut args, validator)?;
Expand Down
11 changes: 6 additions & 5 deletions lib/cli/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions lib/cli/transaction_builder_params.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use casper_types::{
bytesrepr::Bytes, system::auction::Reservation, AddressableEntityHash, PackageHash, PublicKey,
TransactionRuntimeParams, TransferTarget, URef, U512,
bytesrepr::Bytes,
system::auction::{DelegatorKind, Reservation},
AddressableEntityHash, PackageHash, PublicKey, TransactionRuntimeParams, TransferTarget, URef,
U512,
};

/// An enum representing the parameters needed to construct a transaction builder
Expand Down Expand Up @@ -69,7 +71,7 @@ pub enum TransactionBuilderParams<'a> {
/// The validator for the cancel reservations transaction
validator: PublicKey,
/// List of delegatora for the cancel reservations transaction
delegators: Vec<PublicKey>,
delegators: Vec<DelegatorKind>,
},
/// Parameters for the invocable entity variant of the transaction builder
InvocableEntity {
Expand Down
4 changes: 2 additions & 2 deletions lib/cli/transaction_v1_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, TransactionRuntimeParams,
Expand Down Expand Up @@ -303,7 +303,7 @@ impl<'a> TransactionV1Builder<'a> {
/// transaction.
pub fn new_cancel_reservations(
validator: PublicKey,
delegators: Vec<PublicKey>,
delegators: Vec<DelegatorKind>,
) -> Result<Self, CLValueError> {
let args = arg_handling::new_cancel_reservations_args(validator, delegators)?;
let mut builder = TransactionV1Builder::new();
Expand Down
6 changes: 3 additions & 3 deletions src/transaction/creation_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1467,10 +1467,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<PublicKey>";
const ARG_VALUE_NAME: &str = "JSON serialized Vec<DelegatorKind>";
const ARG_HELP: &str = "list of delegator public keys for the cancel-reservations transaction";

pub fn arg() -> Arg {
Expand All @@ -1489,7 +1489,7 @@ mod delegators {
.unwrap_or_default()
}

pub(super) fn parse_delegators(value: &str) -> Result<Vec<PublicKey>, CliError> {
pub(super) fn parse_delegators(value: &str) -> Result<Vec<DelegatorKind>, CliError> {
if !value.is_empty() {
serde_json::from_str(value).map_err(|_| {
CliError::InvalidCLValue(
Expand Down

0 comments on commit 2e4bfcd

Please sign in to comment.