Skip to content

Commit

Permalink
Distribute -> DistributeTokens (solana-labs#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
garious authored Apr 29, 2020
1 parent 2148fb3 commit d65b3be
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ primary_address,bid_amount_dollars
```

```bash
solana-tokens distribute --from <KEYPAIR> --dollars-per-sol <NUMBER> --bids-csv <BIDS_CSV> <TRANSACTION_LOG> --fee-payer <KEYPAIR>
solana-tokens distribute-tokens --from <KEYPAIR> --dollars-per-sol <NUMBER> --bids-csv <BIDS_CSV> <TRANSACTION_LOG> --fee-payer <KEYPAIR>
```

Example transaction log before:
Expand All @@ -31,7 +31,7 @@ Send tokens to the recipients in `<BIDS_CSV>` if the distribution is
not already recordered in the transaction log.

```bash
solana-tokens distribute --from <KEYPAIR> --dollars-per-sol <NUMBER> --bids-csv <BIDS_CSV> <TRANSACTION_LOG> --fee-payer <KEYPAIR>
solana-tokens distribute-tokens --from <KEYPAIR> --dollars-per-sol <NUMBER> --bids-csv <BIDS_CSV> <TRANSACTION_LOG> --fee-payer <KEYPAIR>
```

Example output:
Expand Down Expand Up @@ -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 <NUMBER> --dry-run --bids-csv <BIDS_CSV> <TRANSACTION_LOG>
solana-tokens distribute-tokens --dollars-per-sol <NUMBER> --dry-run --bids-csv <BIDS_CSV> <TRANSACTION_LOG>
```

Example bids.csv:
Expand Down
10 changes: 6 additions & 4 deletions src/arg_parser.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -160,8 +160,8 @@ where
.get_matches_from(args)
}

fn parse_distribute_args(matches: &ArgMatches<'_>) -> DistributeArgs<String> {
DistributeArgs {
fn parse_distribute_tokens_args(matches: &ArgMatches<'_>) -> DistributeTokensArgs<String> {
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),
Expand Down Expand Up @@ -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))
}
Expand Down
10 changes: 5 additions & 5 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<K> {
pub struct DistributeTokensArgs<K> {
pub bids_csv: String,
pub transactions_csv: String,
pub dollars_per_sol: f64,
Expand All @@ -29,7 +29,7 @@ pub struct BalancesArgs {
}

pub enum Command<P, K> {
Distribute(DistributeArgs<K>),
DistributeTokens(DistributeTokensArgs<K>),
DistributeStake(DistributeStakeArgs<P, K>),
Balances(BalancesArgs),
}
Expand All @@ -44,10 +44,10 @@ pub fn resolve_command(
command: Command<String, String>,
) -> Result<Command<Pubkey, Box<dyn Signer>>, Box<dyn Error>> {
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,
Expand All @@ -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()?;
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ fn main() -> Result<(), Box<dyn Error>> {
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)?;
Expand Down
14 changes: 7 additions & 7 deletions src/tokens.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -84,7 +84,7 @@ fn create_allocation(bid: &Bid, dollars_per_sol: f64) -> Allocation {
fn distribute_tokens<T: Client>(
client: &ThinClient<T>,
allocations: &[Allocation],
args: &DistributeArgs<Box<dyn Signer>>,
args: &DistributeTokensArgs<Box<dyn Signer>>,
) -> Result<(), csv::Error> {
let signers = if args.dry_run {
vec![]
Expand Down Expand Up @@ -243,9 +243,9 @@ fn append_transaction_info(
Ok(())
}

pub fn process_distribute<T: Client>(
pub fn process_distribute_tokens<T: Client>(
client: &ThinClient<T>,
args: &DistributeArgs<Box<dyn Signer>>,
args: &DistributeTokensArgs<Box<dyn Signer>>,
) -> Result<(), csv::Error> {
let mut rdr = ReaderBuilder::new()
.trim(Trim::All)
Expand Down Expand Up @@ -431,15 +431,15 @@ pub fn test_process_distribute_with_client<C: Client>(client: C, sender_keypair:
.unwrap()
.to_string();

let args: DistributeArgs<Box<dyn Signer>> = DistributeArgs {
let args: DistributeTokensArgs<Box<dyn Signer>> = DistributeTokensArgs {
sender_keypair: Some(Box::new(sender_keypair)),
fee_payer: Some(Box::new(fee_payer)),
dry_run: false,
bids_csv,
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());
Expand All @@ -452,7 +452,7 @@ pub fn test_process_distribute_with_client<C: 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());
Expand Down

0 comments on commit d65b3be

Please sign in to comment.