Skip to content

Commit

Permalink
Refactors tx client args
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Mar 22, 2023
1 parent c1b77bb commit 315c614
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
26 changes: 13 additions & 13 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1624,12 +1624,12 @@ pub mod args {
const EXPIRATION_OPT: ArgOpt<DateTimeUtc> = arg_opt("expiration");
const FORCE: ArgFlag = flag("force");
const DONT_PREFETCH_WASM: ArgFlag = flag("dont-prefetch-wasm");
const GAS_AMOUNT: ArgDefault<token::Amount> =
arg_default("gas-amount", DefaultFn(|| token::Amount::from(0)));
const GAS_LIMIT: ArgDefault<token::Amount> =
arg_default("gas-limit", DefaultFn(|| token::Amount::from(0)));
const GAS_TOKEN: ArgDefaultFromCtx<WalletAddress> =
arg_default_from_ctx("gas-token", DefaultFn(|| "NAM".into()));
const FEE_AMOUNT: ArgDefault<token::Amount> =
arg_default("fee-amount", DefaultFn(|| token::Amount::from(0)));
const GAS_LIMIT: ArgDefault<GasLimit> =
arg_default("gas-limit", DefaultFn(|| GasLimit::from(10))); //FIXME: fix this default value
const FEE_TOKEN: ArgDefaultFromCtx<WalletAddress> =
arg_default_from_ctx("fee-token", DefaultFn(|| "NAM".into()));
const GENESIS_PATH: Arg<PathBuf> = arg("genesis-path");
const GENESIS_VALIDATOR: ArgOpt<String> = arg("genesis-validator").opt();
const LEDGER_ADDRESS_ABOUT: &str =
Expand Down Expand Up @@ -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<String>,
/// 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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 14 additions & 1 deletion core/src/types/transaction/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -151,6 +153,17 @@ pub mod wrapper_tx {
}
}

impl FromStr for GasLimit {
type Err = ParseIntError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
// 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
Expand Down

0 comments on commit 315c614

Please sign in to comment.