Improve solana-tokens UX (#12253)

* Fix computed banks port

* Readme incorrect

* Return error if csv cannot be read

* Move column headers over columns

* Add dry-run check for sender/fee-payer balances

* Use clap requires method for paired args

* Write transaction-log anytime outfile is specified

* Replace campaign-name with required db-path

* Remove bids

* Exclude new_stake_account_address from logs for non-stake distributions

* Fix readme
This commit is contained in:
Tyera Eulberg
2020-09-15 19:38:22 -06:00
committed by GitHub
parent 3930cb865a
commit 90a591da0e
6 changed files with 199 additions and 200 deletions

View File

@@ -41,16 +41,16 @@ where
SubCommand::with_name("distribute-tokens")
.about("Distribute tokens")
.arg(
Arg::with_name("campaign_name")
.long("campaign-name")
Arg::with_name("db_path")
.long("db-path")
.required(true)
.takes_value(true)
.value_name("NAME")
.help("Campaign name for storing transaction data"),
)
.arg(
Arg::with_name("from_bids")
.long("from-bids")
.help("Input CSV contains bids in dollars, not allocations in SOL"),
.value_name("FILE")
.help(
"Location for storing distribution database. \
The database is used for tracking transactions as they are finalized \
and preventing double spends.",
),
)
.arg(
Arg::with_name("input_csv")
@@ -60,18 +60,19 @@ where
.value_name("FILE")
.help("Input CSV file"),
)
.arg(
Arg::with_name("dollars_per_sol")
.long("dollars-per-sol")
.takes_value(true)
.value_name("NUMBER")
.help("Dollars per SOL, if input CSV contains bids"),
)
.arg(
Arg::with_name("dry_run")
.long("dry-run")
.help("Do not execute any transfers"),
)
.arg(
Arg::with_name("output_path")
.long("output-path")
.short("o")
.value_name("FILE")
.takes_value(true)
.help("Write the transaction log to this file"),
)
.arg(
Arg::with_name("sender_keypair")
.long("from")
@@ -95,11 +96,16 @@ where
SubCommand::with_name("distribute-stake")
.about("Distribute stake accounts")
.arg(
Arg::with_name("campaign_name")
.long("campaign-name")
Arg::with_name("db_path")
.long("db-path")
.required(true)
.takes_value(true)
.value_name("NAME")
.help("Campaign name for storing transaction data"),
.value_name("FILE")
.help(
"Location for storing distribution database. \
The database is used for tracking transactions as they are finalized \
and preventing double spends.",
),
)
.arg(
Arg::with_name("input_csv")
@@ -114,6 +120,14 @@ where
.long("dry-run")
.help("Do not execute any transfers"),
)
.arg(
Arg::with_name("output_path")
.long("output-path")
.short("o")
.value_name("FILE")
.takes_value(true)
.help("Write the transaction log to this file"),
)
.arg(
Arg::with_name("sender_keypair")
.long("from")
@@ -186,29 +200,18 @@ where
.takes_value(true)
.value_name("FILE")
.help("Bids CSV file"),
)
.arg(
Arg::with_name("from_bids")
.long("from-bids")
.help("Input CSV contains bids in dollars, not allocations in SOL"),
)
.arg(
Arg::with_name("dollars_per_sol")
.long("dollars-per-sol")
.takes_value(true)
.value_name("NUMBER")
.help("Dollars per SOL"),
),
)
.subcommand(
SubCommand::with_name("transaction-log")
.about("Print the database to a CSV file")
.arg(
Arg::with_name("campaign_name")
.long("campaign-name")
Arg::with_name("db_path")
.long("db-path")
.required(true)
.takes_value(true)
.value_name("NAME")
.help("Campaign name for storing transaction data"),
.value_name("FILE")
.help("Location of database to query"),
)
.arg(
Arg::with_name("output_path")
@@ -222,22 +225,6 @@ where
.get_matches_from(args)
}
fn create_db_path(campaign_name: Option<String>) -> String {
let (prefix, hyphen) = if let Some(name) = campaign_name {
(name, "-")
} else {
("".to_string(), "")
};
let path = dirs::home_dir().unwrap();
let filename = format!("{}{}transactions.db", prefix, hyphen);
path.join(".config")
.join("solana-tokens")
.join(filename)
.to_str()
.unwrap()
.to_string()
}
fn parse_distribute_tokens_args(
matches: &ArgMatches<'_>,
) -> Result<DistributeTokensArgs, Box<dyn Error>> {
@@ -262,9 +249,8 @@ fn parse_distribute_tokens_args(
Ok(DistributeTokensArgs {
input_csv: value_t_or_exit!(matches, "input_csv", String),
from_bids: matches.is_present("from_bids"),
transaction_db: create_db_path(value_t!(matches, "campaign_name", String).ok()),
dollars_per_sol: value_t!(matches, "dollars_per_sol", f64).ok(),
transaction_db: value_t_or_exit!(matches, "db_path", String),
output_path: matches.value_of("output_path").map(|path| path.to_string()),
dry_run: matches.is_present("dry_run"),
sender_keypair,
fee_payer,
@@ -338,9 +324,8 @@ fn parse_distribute_stake_args(
};
Ok(DistributeTokensArgs {
input_csv: value_t_or_exit!(matches, "input_csv", String),
from_bids: false,
transaction_db: create_db_path(value_t!(matches, "campaign_name", String).ok()),
dollars_per_sol: None,
transaction_db: value_t_or_exit!(matches, "db_path", String),
output_path: matches.value_of("output_path").map(|path| path.to_string()),
dry_run: matches.is_present("dry_run"),
sender_keypair,
fee_payer,
@@ -351,14 +336,12 @@ fn parse_distribute_stake_args(
fn parse_balances_args(matches: &ArgMatches<'_>) -> BalancesArgs {
BalancesArgs {
input_csv: value_t_or_exit!(matches, "input_csv", String),
from_bids: matches.is_present("from_bids"),
dollars_per_sol: value_t!(matches, "dollars_per_sol", f64).ok(),
}
}
fn parse_transaction_log_args(matches: &ArgMatches<'_>) -> TransactionLogArgs {
TransactionLogArgs {
transaction_db: create_db_path(value_t!(matches, "campaign_name", String).ok()),
transaction_db: value_t_or_exit!(matches, "db_path", String),
output_path: value_t_or_exit!(matches, "output_path", String),
}
}