Skip to content

Commit

Permalink
Merge branch 'feat-track-node-2.0' of github.com:casper-ecosystem/cas…
Browse files Browse the repository at this point in the history
…per-client-rs into rustSDK-feat-2.0
  • Loading branch information
gRoussac committed Aug 5, 2024
2 parents 237cffc + d22945c commit a782b37
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/cli/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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",
Expand Down
4 changes: 3 additions & 1 deletion lib/rpcs/v2_0_0/get_reward.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
}
67 changes: 59 additions & 8 deletions src/transaction/creation_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,25 +433,76 @@ 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::<String>(ARG_NAME)
.map(String::as_str)
.unwrap_or_default()
#[derive(Debug, Clone, Copy)]
pub enum PricingMode {
Classic,
Reserved,
Fixed,
}

impl PricingMode {
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 {
fn value_variants<'a>() -> &'a [Self] {
&[Self::Classic, Self::Reserved, Self::Fixed]
}

fn to_possible_value(&self) -> Option<PossibleValue> {
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<Self, Self::Err> {
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)
}
}

Expand Down Expand Up @@ -1870,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,
Expand All @@ -1884,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,
Expand Down

0 comments on commit a782b37

Please sign in to comment.