From 315c6148db195d7d5c86fcac1c87c4c1279b419f Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Tue, 21 Mar 2023 14:28:26 +0100 Subject: [PATCH] Refactors tx client args --- apps/src/lib/cli.rs | 26 +++++++++++++------------- core/src/types/transaction/wrapper.rs | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index 9540a1606fe..af8156a9ed9 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -1624,12 +1624,12 @@ pub mod args { const EXPIRATION_OPT: ArgOpt = arg_opt("expiration"); const FORCE: ArgFlag = flag("force"); const DONT_PREFETCH_WASM: ArgFlag = flag("dont-prefetch-wasm"); - const GAS_AMOUNT: ArgDefault = - arg_default("gas-amount", DefaultFn(|| token::Amount::from(0))); - const GAS_LIMIT: ArgDefault = - arg_default("gas-limit", DefaultFn(|| token::Amount::from(0))); - const GAS_TOKEN: ArgDefaultFromCtx = - arg_default_from_ctx("gas-token", DefaultFn(|| "NAM".into())); + const FEE_AMOUNT: ArgDefault = + arg_default("fee-amount", DefaultFn(|| token::Amount::from(0))); + const GAS_LIMIT: ArgDefault = + arg_default("gas-limit", DefaultFn(|| GasLimit::from(10))); //FIXME: fix this default value + const FEE_TOKEN: ArgDefaultFromCtx = + arg_default_from_ctx("fee-token", DefaultFn(|| "NAM".into())); const GENESIS_PATH: Arg = arg("genesis-path"); const GENESIS_VALIDATOR: ArgOpt = arg("genesis-validator").opt(); const LEDGER_ADDRESS_ABOUT: &str = @@ -2858,7 +2858,7 @@ pub mod args { /// If any new account is initialized by the tx, use the given alias to /// save it in the wallet. pub initialized_account_alias: Option, - /// The amount being payed to include the transaction + /// The amount being payed (for gas unit) to include the transaction pub fee_amount: token::Amount, /// The token in which the fee is being paid pub fee_token: WalletAddress, @@ -2917,13 +2917,13 @@ pub mod args { initialized, the alias will be the prefix of each new \ address joined with a number.", )) - .arg(GAS_AMOUNT.def().about( + .arg(FEE_AMOUNT.def().about( "The amount being paid for the inclusion of this transaction", )) - .arg(GAS_TOKEN.def().about("The token for paying the gas")) + .arg(FEE_TOKEN.def().about("The token for paying the gas")) .arg( GAS_LIMIT.def().about( - "The maximum amount of gas needed to run transaction", + "The multiplier of the gas limit resolution definying the maximum amount of gas needed to run transaction", ), ) .arg(EXPIRATION_OPT.def().about( @@ -2960,9 +2960,9 @@ pub mod args { let broadcast_only = BROADCAST_ONLY.parse(matches); let ledger_address = LEDGER_ADDRESS_DEFAULT.parse(matches); let initialized_account_alias = ALIAS_OPT.parse(matches); - let fee_amount = GAS_AMOUNT.parse(matches); - let fee_token = GAS_TOKEN.parse(matches); - let gas_limit = GAS_LIMIT.parse(matches).into(); + let fee_amount = FEE_AMOUNT.parse(matches); + let fee_token = FEE_TOKEN.parse(matches); + let gas_limit = GAS_LIMIT.parse(matches); let expiration = EXPIRATION_OPT.parse(matches); let signing_key = SIGNING_KEY_OPT.parse(matches); diff --git a/core/src/types/transaction/wrapper.rs b/core/src/types/transaction/wrapper.rs index 5de138bacde..8eda482e8ba 100644 --- a/core/src/types/transaction/wrapper.rs +++ b/core/src/types/transaction/wrapper.rs @@ -4,6 +4,8 @@ #[cfg(feature = "ferveo-tpke")] pub mod wrapper_tx { use std::convert::TryFrom; + use std::num::ParseIntError; + use std::str::FromStr; pub use ark_bls12_381::Bls12_381 as EllipticCurve; pub use ark_ec::{AffineCurve, PairingEngine}; @@ -58,7 +60,7 @@ pub mod wrapper_tx { Deserialize, )] pub struct Fee { - /// amount of the fee + /// amount of fee per gas unit pub amount: Amount, /// address of the token pub token: Address, @@ -151,6 +153,17 @@ pub mod wrapper_tx { } } + impl FromStr for GasLimit { + type Err = ParseIntError; + + fn from_str(s: &str) -> Result { + // Expect input to be the multiplier + Ok(Self { + multiplier: s.parse()?, + }) + } + } + /// A transaction with an encrypted payload as well /// as some non-encrypted metadata for inclusion /// and / or verification purposes