Skip to content

Commit

Permalink
single-pool-cli: Fix parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
joncinque committed Oct 17, 2023
1 parent 1dbbda5 commit cfd5d0f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
16 changes: 5 additions & 11 deletions single-pool/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ use {
ArgGroup, ArgMatches, Args, Parser, Subcommand,
},
solana_clap_v3_utils::{
input_validators::{
is_amount_or_all, is_url_or_moniker, is_valid_pubkey, is_valid_signer,
normalize_to_url_if_moniker,
},
input_parsers::{parse_url_or_moniker, Amount},
input_validators::{is_valid_pubkey, is_valid_signer},
keypair::{pubkey_from_path, signer_from_path},
},
solana_remote_wallet::remote_wallet::RemoteWalletManager,
Expand Down Expand Up @@ -40,7 +38,7 @@ pub struct Cli {
short = 'u',
long = "url",
id = "URL_OR_MONIKER",
value_parser = parse_json_rpc_url,
value_parser = parse_url_or_moniker,
)]
pub json_rpc_url: Option<String>,

Expand Down Expand Up @@ -190,8 +188,8 @@ pub struct DepositCli {
#[clap(group(pool_source_group()))]
pub struct WithdrawCli {
/// Amount of tokens to burn for withdrawal
#[clap(validator = |s| is_amount_or_all(s))]
pub token_amount: String,
#[clap(value_parser = Amount::parse_decimal_or_all)]
pub token_amount: Amount,

/// The token account to withdraw from. Defaults to the associated token account for the pool mint
#[clap(long = "token-account", value_parser = |p: &str| parse_address(p, "token_account_address"))]
Expand Down Expand Up @@ -299,10 +297,6 @@ fn pool_source_group() -> ArgGroup<'static> {
.args(&["pool-address", "vote-account-address"])
}

pub fn parse_json_rpc_url(url_or_moniker: &str) -> Result<String, String> {
is_url_or_moniker(url_or_moniker).map(|_| normalize_to_url_if_moniker(url_or_moniker))
}

pub fn parse_address(path: &str, name: &str) -> Result<Pubkey, String> {
if is_valid_pubkey(path).is_ok() {
// this all is ugly but safe
Expand Down
8 changes: 5 additions & 3 deletions single-pool/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use {
borsh::BorshSerialize,
clap::{CommandFactory, Parser},
solana_clap_v3_utils::input_parsers::Amount,
solana_client::{
rpc_config::RpcProgramAccountsConfig,
rpc_filter::{Memcmp, RpcFilterType},
Expand Down Expand Up @@ -438,9 +439,10 @@ async fn command_withdraw(config: &Config, command_config: WithdrawCli) -> Comma

let token_account = token.get_account_info(&token_account_address).await?;

let token_amount = match command_config.token_amount.as_ref() {
"ALL" => token_account.base.amount,
amount => amount.parse::<u64>()?,
let token_amount = match command_config.token_amount.sol_to_lamport() {
Amount::All => token_account.base.amount,
Amount::Raw(amount) => amount,
Amount::Decimal(_) => unreachable!(),
};

println_display(
Expand Down

0 comments on commit cfd5d0f

Please sign in to comment.