diff --git a/README.md b/README.md index 9c956382b853e1..1450edeaef8e2a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ primary_address,bid_amount_dollars ``` ```bash -solana-tokens distribute-tokens --from --dollars-per-sol --input_csv --fee-payer +solana-tokens distribute-tokens --from --dollars-per-sol --input-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-tokens --from --dollars-per-sol --input_csv --fee-payer +solana-tokens distribute-tokens --from --dollars-per-sol --input-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-tokens --dollars-per-sol --dry-run --input_csv +solana-tokens distribute-tokens --dollars-per-sol --dry-run --input-csv ``` Example bids.csv: diff --git a/src/arg_parser.rs b/src/arg_parser.rs index 6aaee6b0ce5220..35933c6a8ee157 100644 --- a/src/arg_parser.rs +++ b/src/arg_parser.rs @@ -60,7 +60,7 @@ where .required(true) .takes_value(true) .value_name("NUMBER") - .help("Dollars per SOL, if input CSV contains bids") + .help("Dollars per SOL, if input CSV contains bids"), ) .arg( Arg::with_name("dry_run") @@ -155,16 +155,20 @@ where .about("Balance of each account") .arg( Arg::with_name("input_csv") - .long("input_csv") + .long("input-csv") .required(true) .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") - .required(true) .takes_value(true) .value_name("NUMBER") .help("Dollars per SOL"), @@ -201,7 +205,8 @@ fn parse_distribute_stake_args(matches: &ArgMatches<'_>) -> DistributeStakeArgs< fn parse_balances_args(matches: &ArgMatches<'_>) -> BalancesArgs { BalancesArgs { input_csv: value_t_or_exit!(matches, "input_csv", String), - dollars_per_sol: value_t_or_exit!(matches, "dollars_per_sol", f64), + from_bids: matches.is_present("from_bids"), + dollars_per_sol: value_t!(matches, "dollars_per_sol", f64).ok(), } } diff --git a/src/args.rs b/src/args.rs index ea913681cd595c..60814eca11ba59 100644 --- a/src/args.rs +++ b/src/args.rs @@ -27,7 +27,8 @@ pub struct DistributeStakeArgs { pub struct BalancesArgs { pub input_csv: String, - pub dollars_per_sol: f64, + pub from_bids: bool, + pub dollars_per_sol: Option, } pub enum Command { diff --git a/src/tokens.rs b/src/tokens.rs index 7ad7a8c3336894..87a5a3bd5c0fbe 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -273,19 +273,21 @@ fn set_transaction_info( } fn read_allocations( - args: &DistributeTokensArgs> + input_csv: &str, + from_bids: bool, + dollars_per_sol: Option, ) -> Vec { - let rdr = ReaderBuilder::new() - .trim(Trim::All) - .from_path(&args.input_csv); - if args.from_bids { + let rdr = ReaderBuilder::new().trim(Trim::All).from_path(input_csv); + if from_bids { let bids: Vec = rdr.unwrap().deserialize().map(|bid| bid.unwrap()).collect(); - bids - .into_iter() - .map(|bid| create_allocation(&bid, args.dollars_per_sol.unwrap())) + bids.into_iter() + .map(|bid| create_allocation(&bid, dollars_per_sol.unwrap())) .collect() } else { - rdr.unwrap().deserialize().map(|entry| entry.unwrap()).collect() + rdr.unwrap() + .deserialize() + .map(|entry| entry.unwrap()) + .collect() } } @@ -293,7 +295,8 @@ pub fn process_distribute_tokens( client: &ThinClient, args: &DistributeTokensArgs>, ) -> Result<(), Error> { - let mut allocations: Vec = read_allocations(&args); + let mut allocations: Vec = + read_allocations(&args.input_csv, args.from_bids, args.dollars_per_sol); let starting_total_tokens: f64 = allocations.iter().map(|x| x.amount).sum(); println!( @@ -423,14 +426,8 @@ pub fn process_balances( client: &ThinClient, args: &BalancesArgs, ) -> Result<(), csv::Error> { - let mut rdr = ReaderBuilder::new() - .trim(Trim::All) - .from_path(&args.input_csv)?; - let bids: Vec = rdr.deserialize().map(|bid| bid.unwrap()).collect(); - let allocations: Vec = bids - .into_iter() - .map(|bid| create_allocation(&bid, args.dollars_per_sol)) - .collect(); + let allocations: Vec = + read_allocations(&args.input_csv, args.from_bids, args.dollars_per_sol); let allocations = merge_allocations(&allocations); println!( @@ -521,7 +518,10 @@ pub fn test_process_distribute_bids_with_client(client: C, sender_key ); } -pub fn test_process_distribute_allocations_with_client(client: C, sender_keypair: Keypair) { +pub fn test_process_distribute_allocations_with_client( + client: C, + sender_keypair: Keypair, +) { let thin_client = ThinClient(client); let fee_payer = Keypair::new(); thin_client