From 3adc5f3f0f9704d5c155fed8418d1ef13c4fd91b Mon Sep 17 00:00:00 2001 From: Gregory Roussac Date: Fri, 19 Jul 2024 14:26:50 +0200 Subject: [PATCH 1/3] Fix typo on pricing_mode and define pricing_mode ARG_VALUE_NAME options (#176) * Fix typo on pricing_mode and define pricing_mode ARG_VALUE_NAME options * Bad commit * get PricingMode values for string match --- lib/cli/transaction.rs | 2 +- src/transaction/creation_common.rs | 55 ++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/lib/cli/transaction.rs b/lib/cli/transaction.rs index 86dcf5c5..9a84ab8e 100644 --- a/lib/cli/transaction.rs +++ b/lib/cli/transaction.rs @@ -46,7 +46,7 @@ pub fn create_transaction( error: "pricing_mode is required to be non empty".to_string(), }); } - let pricing_mode = if transaction_params.payment_amount.to_lowercase().as_str() == "reserved" { + let pricing_mode = if transaction_params.pricing_mode.to_lowercase().as_str() == "reserved" { let digest = Digest::from_hex(transaction_params.receipt).map_err(|error| { CliError::FailedToParseDigest { context: "pricing_digest", diff --git a/src/transaction/creation_common.rs b/src/transaction/creation_common.rs index b7dc0e21..6faca44f 100644 --- a/src/transaction/creation_common.rs +++ b/src/transaction/creation_common.rs @@ -433,25 +433,68 @@ pub(super) mod transfer_amount { pub(super) mod pricing_mode { use super::*; + use clap::{builder::PossibleValue, value_parser, ValueEnum}; + use std::str::FromStr; + pub(in crate::transaction) const ARG_NAME: &str = "pricing-mode"; - const ARG_VALUE_NAME: &str = common::ARG_STRING; + const ARG_VALUE_NAME: &str = "classic|reserved|fixed"; const ARG_HELP: &str = "Used to identify the payment mode chosen to execute the transaction"; + const ARG_DEFAULT: &str = PricingMode::FIXED; pub(in crate::transaction) fn arg() -> Arg { Arg::new(ARG_NAME) .long(ARG_NAME) .required(false) .value_name(ARG_VALUE_NAME) + .default_value(ARG_DEFAULT) .help(ARG_HELP) .display_order(DisplayOrder::PricingMode as usize) + .value_parser(value_parser!(PricingMode)) } - pub fn get(matches: &ArgMatches) -> &str { - matches - .get_one::(ARG_NAME) - .map(String::as_str) - .unwrap_or_default() + #[derive(Debug, Clone, Copy)] + pub(super) enum PricingMode { + Classic, + Reserved, + Fixed, + } + + impl PricingMode { + const CLASSIC: &'static str = "classic"; + const RESERVED: &'static str = "reserved"; + const FIXED: &'static str = "fixed"; + } + + impl ValueEnum for PricingMode { + fn value_variants<'a>() -> &'a [Self] { + &[Self::Classic, Self::Reserved, Self::Fixed] + } + + fn to_possible_value(&self) -> Option { + Some(match self { + Self::Classic => PossibleValue::new(PricingMode::CLASSIC), + Self::Reserved => PossibleValue::new(PricingMode::RESERVED), + Self::Fixed => PossibleValue::new(PricingMode::FIXED), + }) + } + } + + impl FromStr for PricingMode { + type Err = String; + + fn from_str(s: &str) -> Result { + match s.to_lowercase().as_str() { + PricingMode::CLASSIC => Ok(Self::Classic), + PricingMode::RESERVED => Ok(Self::Reserved), + PricingMode::FIXED => Ok(Self::Fixed), + _ => Err(format!("'{}' is not a valid pricing option", s)), + } + } + } + + pub fn get(matches: &ArgMatches) -> Option<&PricingMode> { + matches.get_one(ARG_NAME) } } From 5156a1df1ce37b5b1acf651469b5a8bed41fa9bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Chabowski?= <88321181+rafal-ch@users.noreply.github.com> Date: Mon, 22 Jul 2024 15:17:00 +0200 Subject: [PATCH 2/3] Update for changed interface of 'pricing_mode' enum (#189) --- src/transaction/creation_common.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/transaction/creation_common.rs b/src/transaction/creation_common.rs index 6faca44f..daf52920 100644 --- a/src/transaction/creation_common.rs +++ b/src/transaction/creation_common.rs @@ -454,7 +454,7 @@ pub(super) mod pricing_mode { } #[derive(Debug, Clone, Copy)] - pub(super) enum PricingMode { + pub enum PricingMode { Classic, Reserved, Fixed, @@ -464,6 +464,14 @@ pub(super) mod pricing_mode { const CLASSIC: &'static str = "classic"; const RESERVED: &'static str = "reserved"; const FIXED: &'static str = "fixed"; + + pub(crate) fn as_str(&self) -> &str { + match self { + Self::Classic => Self::CLASSIC, + Self::Reserved => Self::RESERVED, + Self::Fixed => Self::FIXED, + } + } } impl ValueEnum for PricingMode { @@ -1913,7 +1921,7 @@ pub(super) fn build_transaction_str_params( initiator_addr, session_args_simple, session_args_json, - pricing_mode: maybe_pricing_mode, + pricing_mode: maybe_pricing_mode.map(|pm| pm.as_str()).unwrap_or_default(), output_path: maybe_output_path, payment_amount, gas_price_tolerance, @@ -1927,7 +1935,7 @@ pub(super) fn build_transaction_str_params( ttl, chain_name, initiator_addr, - pricing_mode: maybe_pricing_mode, + pricing_mode: maybe_pricing_mode.map(|pm| pm.as_str()).unwrap_or_default(), output_path: maybe_output_path, payment_amount, gas_price_tolerance, From d22945c0e1ac3e55e218ac93a1f8c2d30d37c972 Mon Sep 17 00:00:00 2001 From: jacek-casper <145967538+jacek-casper@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:32:42 +0100 Subject: [PATCH 3/3] Update GetRewardResult (#190) Signed-off-by: Jacek Malec <145967538+jacek-casper@users.noreply.github.com> --- lib/rpcs/v2_0_0/get_reward.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/rpcs/v2_0_0/get_reward.rs b/lib/rpcs/v2_0_0/get_reward.rs index 1b6cd023..751256ed 100644 --- a/lib/rpcs/v2_0_0/get_reward.rs +++ b/lib/rpcs/v2_0_0/get_reward.rs @@ -1,4 +1,4 @@ -use casper_types::{EraId, ProtocolVersion, PublicKey, U512}; +use casper_types::{BlockHash, EraId, ProtocolVersion, PublicKey, U512}; use serde::{Deserialize, Serialize}; use crate::rpcs::common::BlockIdentifier; @@ -53,4 +53,6 @@ pub struct GetRewardResult { pub era_id: EraId, /// The delegation rate of the validator. pub delegation_rate: u8, + /// The switch block hash at which the reward was distributed. + pub switch_block_hash: BlockHash, }