From d65b3beae671bc987b9d64731b51416d291f7efe Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Wed, 29 Apr 2020 16:47:49 -0600 Subject: [PATCH] Distribute -> DistributeTokens (#3) --- README.md | 6 +++--- src/arg_parser.rs | 10 ++++++---- src/args.rs | 10 +++++----- src/main.rs | 4 ++-- src/tokens.rs | 14 +++++++------- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index ad98da5327b116..7e162be74ed4dd 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ primary_address,bid_amount_dollars ``` ```bash -solana-tokens distribute --from --dollars-per-sol --bids-csv --fee-payer +solana-tokens distribute-tokens --from --dollars-per-sol --bids-csv --fee-payer ``` Example transaction log before: @@ -31,7 +31,7 @@ Send tokens to the recipients in `` if the distribution is not already recordered in the transaction log. ```bash -solana-tokens distribute --from --dollars-per-sol --bids-csv --fee-payer +solana-tokens distribute-tokens --from --dollars-per-sol --bids-csv --fee-payer ``` Example output: @@ -60,7 +60,7 @@ List the differences between a list of expected distributions and the record of transactions have already been sent. ```bash -solana-tokens distribute --dollars-per-sol --dry-run --bids-csv +solana-tokens distribute-tokens --dollars-per-sol --dry-run --bids-csv ``` Example bids.csv: diff --git a/src/arg_parser.rs b/src/arg_parser.rs index 833ebf5df83d80..378ad231c47e0b 100644 --- a/src/arg_parser.rs +++ b/src/arg_parser.rs @@ -1,4 +1,4 @@ -use crate::args::{Args, BalancesArgs, Command, DistributeArgs, DistributeStakeArgs}; +use crate::args::{Args, BalancesArgs, Command, DistributeStakeArgs, DistributeTokensArgs}; use clap::{value_t, value_t_or_exit, App, Arg, ArgMatches, SubCommand}; use solana_clap_utils::input_validators::{is_valid_pubkey, is_valid_signer}; use solana_cli_config::CONFIG_FILE; @@ -160,8 +160,8 @@ where .get_matches_from(args) } -fn parse_distribute_args(matches: &ArgMatches<'_>) -> DistributeArgs { - DistributeArgs { +fn parse_distribute_tokens_args(matches: &ArgMatches<'_>) -> DistributeTokensArgs { + DistributeTokensArgs { bids_csv: value_t_or_exit!(matches, "bids_csv", String), transactions_csv: value_t_or_exit!(matches, "transactions_csv", String), dollars_per_sol: value_t_or_exit!(matches, "dollars_per_sol", f64), @@ -200,7 +200,9 @@ where let url = matches.value_of("url").map(|x| x.to_string()); let command = match matches.subcommand() { - ("distribute", Some(matches)) => Command::Distribute(parse_distribute_args(matches)), + ("distribute-tokens", Some(matches)) => { + Command::DistributeTokens(parse_distribute_tokens_args(matches)) + } ("distribute-stake", Some(matches)) => { Command::DistributeStake(parse_distribute_stake_args(matches)) } diff --git a/src/args.rs b/src/args.rs index ca9d4c7bd4a12c..106cbd8239b1be 100644 --- a/src/args.rs +++ b/src/args.rs @@ -4,7 +4,7 @@ use solana_remote_wallet::remote_wallet::maybe_wallet_manager; use solana_sdk::{pubkey::Pubkey, signature::Signer}; use std::error::Error; -pub struct DistributeArgs { +pub struct DistributeTokensArgs { pub bids_csv: String, pub transactions_csv: String, pub dollars_per_sol: f64, @@ -29,7 +29,7 @@ pub struct BalancesArgs { } pub enum Command { - Distribute(DistributeArgs), + DistributeTokens(DistributeTokensArgs), DistributeStake(DistributeStakeArgs), Balances(BalancesArgs), } @@ -44,10 +44,10 @@ pub fn resolve_command( command: Command, ) -> Result>, Box> { match command { - Command::Distribute(args) => { + Command::DistributeTokens(args) => { let mut wallet_manager = maybe_wallet_manager()?; let matches = ArgMatches::default(); - let resolved_args = DistributeArgs { + let resolved_args = DistributeTokensArgs { bids_csv: args.bids_csv, transactions_csv: args.transactions_csv, dollars_per_sol: args.dollars_per_sol, @@ -59,7 +59,7 @@ pub fn resolve_command( signer_from_path(&matches, &key_url, "fee-payer", &mut wallet_manager).unwrap() }), }; - Ok(Command::Distribute(resolved_args)) + Ok(Command::DistributeTokens(resolved_args)) } Command::DistributeStake(args) => { let mut wallet_manager = maybe_wallet_manager()?; diff --git a/src/main.rs b/src/main.rs index f0f1ef27184890..6a44419a1d14ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,8 +17,8 @@ fn main() -> Result<(), Box> { let thin_client = ThinClient(client); match resolve_command(command_args.command)? { - Command::Distribute(args) => { - tokens::process_distribute(&thin_client, &args)?; + Command::DistributeTokens(args) => { + tokens::process_distribute_tokens(&thin_client, &args)?; } Command::DistributeStake(args) => { tokens::process_distribute_stake(&thin_client, &args)?; diff --git a/src/tokens.rs b/src/tokens.rs index 4730ad3c2c9afe..072b7b5c6c2104 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -1,4 +1,4 @@ -use crate::args::{BalancesArgs, DistributeArgs, DistributeStakeArgs}; +use crate::args::{BalancesArgs, DistributeStakeArgs, DistributeTokensArgs}; use crate::thin_client::{Client, ThinClient}; use console::style; use csv::{ReaderBuilder, Trim}; @@ -84,7 +84,7 @@ fn create_allocation(bid: &Bid, dollars_per_sol: f64) -> Allocation { fn distribute_tokens( client: &ThinClient, allocations: &[Allocation], - args: &DistributeArgs>, + args: &DistributeTokensArgs>, ) -> Result<(), csv::Error> { let signers = if args.dry_run { vec![] @@ -243,9 +243,9 @@ fn append_transaction_info( Ok(()) } -pub fn process_distribute( +pub fn process_distribute_tokens( client: &ThinClient, - args: &DistributeArgs>, + args: &DistributeTokensArgs>, ) -> Result<(), csv::Error> { let mut rdr = ReaderBuilder::new() .trim(Trim::All) @@ -431,7 +431,7 @@ pub fn test_process_distribute_with_client(client: C, sender_keypair: .unwrap() .to_string(); - let args: DistributeArgs> = DistributeArgs { + let args: DistributeTokensArgs> = DistributeTokensArgs { sender_keypair: Some(Box::new(sender_keypair)), fee_payer: Some(Box::new(fee_payer)), dry_run: false, @@ -439,7 +439,7 @@ pub fn test_process_distribute_with_client(client: C, sender_keypair: transactions_csv: transactions_csv.clone(), dollars_per_sol: 0.22, }; - process_distribute(&thin_client, &args).unwrap(); + process_distribute_tokens(&thin_client, &args).unwrap(); let transaction_infos = read_transaction_infos(&transactions_csv); assert_eq!(transaction_infos.len(), 1); assert_eq!(transaction_infos[0].recipient, alice_pubkey.to_string()); @@ -452,7 +452,7 @@ pub fn test_process_distribute_with_client(client: C, sender_keypair: ); // Now, run it again, and check there's no double-spend. - process_distribute(&thin_client, &args).unwrap(); + process_distribute_tokens(&thin_client, &args).unwrap(); let transaction_infos = read_transaction_infos(&transactions_csv); assert_eq!(transaction_infos.len(), 1); assert_eq!(transaction_infos[0].recipient, alice_pubkey.to_string());