Skip to content

Commit

Permalink
Bunch of cleanup (solana-labs#31)
Browse files Browse the repository at this point in the history
* Remove untested --no-wait feature

* Make --transactions-db an option, not an arg

So that in the future, we can make it optional

* Remove more untested features

Too many false positives in that santity check.  Use --dry-run
instead.

* Add dry-run mode to ThinClient

* Cleaner dry-run

* Make key parameters required

Just don't use them in --dry-run

* Add option to write the transaction log

--dry-run doesn't write to the database. Use this option if you
want a copy of the transaction log before the final run.

* Revert --transaction-log addition

Implement solana-labs#27 first

* Fix CI

* Update readme

* Fix CI in copypasta
  • Loading branch information
garious authored May 12, 2020
1 parent 256c409 commit 041565d
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 256 deletions.
10 changes: 5 additions & 5 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-tokens --from <KEYPAIR> --dollars-per-sol <NUMBER> --input-csv <BIDS_CSV> <TRANSACTION_LOG> --fee-payer <KEYPAIR>
solana-tokens distribute-tokens --from <KEYPAIR> --dollars-per-sol <NUMBER> --from-bids --input-csv <BIDS_CSV> --transaction-db <FILE> --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-tokens --from <KEYPAIR> --dollars-per-sol <NUMBER> --input-csv <BIDS_CSV> <TRANSACTION_LOG> --fee-payer <KEYPAIR>
solana-tokens distribute-tokens --from <KEYPAIR> --dollars-per-sol <NUMBER> --from-bids --input-csv <BIDS_CSV> --transaction-db <FILE> --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-tokens --dollars-per-sol <NUMBER> --dry-run --input-csv <BIDS_CSV> <TRANSACTION_LOG>
solana-tokens distribute-tokens --dollars-per-sol <NUMBER> --dry-run --from-bids --input-csv <BIDS_CSV> --transaction-db <FILE>
```

Example bids.csv:
Expand Down Expand Up @@ -90,8 +90,8 @@ the new accounts inherit any lockup or custodian settings of the original.

```bash
solana-tokens distribute-stake --stake-account-address <ACCOUNT_ADDRESS> \
--allocations-csv <ALLOCATIONS_CSV> \
<TRANSACTION_LOG> \
--input-csv <ALLOCATIONS_CSV> \
--transaction-db <FILE> \
--stake-authority <KEYPAIR> --withdraw-authority <KEYPAIR> --fee-payer <KEYPAIR>
```

Expand Down
59 changes: 23 additions & 36 deletions src/arg_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ where
SubCommand::with_name("distribute-tokens")
.about("Distribute tokens")
.arg(
Arg::with_name("transactions_db")
Arg::with_name("transaction_db")
.long("transaction-db")
.required(true)
.index(1)
.takes_value(true)
.value_name("FILE")
.help("Transactions database file"),
.help("Transaction database file"),
)
.arg(
Arg::with_name("from_bids")
Expand All @@ -68,14 +68,10 @@ where
.long("dry-run")
.help("Do not execute any transfers"),
)
.arg(
Arg::with_name("no_wait")
.long("no-wait")
.help("Don't wait for transaction confirmations"),
)
.arg(
Arg::with_name("sender_keypair")
.long("from")
.required(true)
.takes_value(true)
.value_name("SENDING_KEYPAIR")
.validator(is_valid_signer)
Expand All @@ -84,27 +80,23 @@ where
.arg(
Arg::with_name("fee_payer")
.long("fee-payer")
.required(true)
.takes_value(true)
.value_name("KEYPAIR")
.validator(is_valid_signer)
.help("Fee payer"),
)
.arg(
Arg::with_name("force")
.long("force")
.help("Do not block transfers is recipients have a non-zero balance"),
),
)
.subcommand(
SubCommand::with_name("distribute-stake")
.about("Distribute stake accounts")
.arg(
Arg::with_name("transactions_db")
Arg::with_name("transaction_db")
.long("transaction-db")
.required(true)
.index(1)
.takes_value(true)
.value_name("FILE")
.help("Transactions database file"),
.help("Transaction database file"),
)
.arg(
Arg::with_name("input_csv")
Expand All @@ -119,14 +111,10 @@ where
.long("dry-run")
.help("Do not execute any transfers"),
)
.arg(
Arg::with_name("no_wait")
.long("no-wait")
.help("Don't wait for transaction confirmations"),
)
.arg(
Arg::with_name("sender_keypair")
.long("from")
.required(true)
.takes_value(true)
.value_name("SENDING_KEYPAIR")
.validator(is_valid_signer)
Expand All @@ -152,6 +140,7 @@ where
.arg(
Arg::with_name("stake_authority")
.long("stake-authority")
.required(true)
.takes_value(true)
.value_name("KEYPAIR")
.validator(is_valid_signer)
Expand All @@ -160,6 +149,7 @@ where
.arg(
Arg::with_name("withdraw_authority")
.long("withdraw-authority")
.required(true)
.takes_value(true)
.value_name("KEYPAIR")
.validator(is_valid_signer)
Expand All @@ -168,6 +158,7 @@ where
.arg(
Arg::with_name("fee_payer")
.long("fee-payer")
.required(true)
.takes_value(true)
.value_name("KEYPAIR")
.validator(is_valid_signer)
Expand Down Expand Up @@ -202,9 +193,9 @@ where
SubCommand::with_name("transaction-log")
.about("Print the database to a CSV file")
.arg(
Arg::with_name("transactions_db")
Arg::with_name("transaction_db")
.long("transaction-db")
.required(true)
.index(1)
.takes_value(true)
.value_name("FILE")
.help("Transactions database file"),
Expand All @@ -225,13 +216,11 @@ fn parse_distribute_tokens_args(matches: &ArgMatches<'_>) -> DistributeTokensArg
DistributeTokensArgs {
input_csv: value_t_or_exit!(matches, "input_csv", String),
from_bids: matches.is_present("from_bids"),
transactions_db: value_t_or_exit!(matches, "transactions_db", String),
transaction_db: value_t_or_exit!(matches, "transaction_db", String),
dollars_per_sol: value_t!(matches, "dollars_per_sol", f64).ok(),
dry_run: matches.is_present("dry_run"),
no_wait: matches.is_present("no_wait"),
sender_keypair: value_t!(matches, "sender_keypair", String).ok(),
fee_payer: value_t!(matches, "fee_payer", String).ok(),
force: matches.is_present("force"),
sender_keypair: value_t_or_exit!(matches, "sender_keypair", String),
fee_payer: value_t_or_exit!(matches, "fee_payer", String),
stake_args: None,
}
}
Expand All @@ -240,19 +229,17 @@ fn parse_distribute_stake_args(matches: &ArgMatches<'_>) -> DistributeTokensArgs
let stake_args = StakeArgs {
stake_account_address: value_t_or_exit!(matches, "stake_account_address", String),
sol_for_fees: value_t_or_exit!(matches, "sol_for_fees", f64),
stake_authority: value_t!(matches, "stake_authority", String).ok(),
withdraw_authority: value_t!(matches, "withdraw_authority", String).ok(),
stake_authority: value_t_or_exit!(matches, "stake_authority", String),
withdraw_authority: value_t_or_exit!(matches, "withdraw_authority", String),
};
DistributeTokensArgs {
input_csv: value_t_or_exit!(matches, "input_csv", String),
from_bids: false,
transactions_db: value_t_or_exit!(matches, "transactions_db", String),
transaction_db: value_t_or_exit!(matches, "transaction_db", String),
dollars_per_sol: None,
dry_run: matches.is_present("dry_run"),
no_wait: matches.is_present("no_wait"),
sender_keypair: value_t!(matches, "sender_keypair", String).ok(),
fee_payer: value_t!(matches, "fee_payer", String).ok(),
force: false,
sender_keypair: value_t_or_exit!(matches, "sender_keypair", String),
fee_payer: value_t_or_exit!(matches, "fee_payer", String),
stake_args: Some(stake_args),
}
}
Expand All @@ -267,7 +254,7 @@ fn parse_balances_args(matches: &ArgMatches<'_>) -> BalancesArgs {

fn parse_transaction_log_args(matches: &ArgMatches<'_>) -> TransactionLogArgs {
TransactionLogArgs {
transactions_db: value_t_or_exit!(matches, "transactions_db", String),
transaction_db: value_t_or_exit!(matches, "transaction_db", String),
output_path: value_t_or_exit!(matches, "output_path", String),
}
}
Expand Down
58 changes: 35 additions & 23 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@ use std::{error::Error, sync::Arc};
pub struct DistributeTokensArgs<P, K> {
pub input_csv: String,
pub from_bids: bool,
pub transactions_db: String,
pub transaction_db: String,
pub dollars_per_sol: Option<f64>,
pub dry_run: bool,
pub no_wait: bool,
pub sender_keypair: Option<K>,
pub fee_payer: Option<K>,
pub force: bool,
pub sender_keypair: K,
pub fee_payer: K,
pub stake_args: Option<StakeArgs<P, K>>,
}

pub struct StakeArgs<P, K> {
pub sol_for_fees: f64,
pub stake_account_address: P,
pub stake_authority: Option<K>,
pub withdraw_authority: Option<K>,
pub stake_authority: K,
pub withdraw_authority: K,
}

pub struct BalancesArgs {
Expand All @@ -31,7 +29,7 @@ pub struct BalancesArgs {
}

pub struct TransactionLogArgs {
pub transactions_db: String,
pub transaction_db: String,
pub output_path: String,
}

Expand Down Expand Up @@ -61,12 +59,20 @@ pub fn resolve_stake_args(
)
.unwrap(),
sol_for_fees: args.sol_for_fees,
stake_authority: args.stake_authority.as_ref().map(|key_url| {
signer_from_path(&matches, &key_url, "stake authority", wallet_manager).unwrap()
}),
withdraw_authority: args.withdraw_authority.as_ref().map(|key_url| {
signer_from_path(&matches, &key_url, "withdraw authority", wallet_manager).unwrap()
}),
stake_authority: signer_from_path(
&matches,
&args.stake_authority,
"stake authority",
wallet_manager,
)
.unwrap(),
withdraw_authority: signer_from_path(
&matches,
&args.withdraw_authority,
"withdraw authority",
wallet_manager,
)
.unwrap(),
};
Ok(resolved_args)
}
Expand All @@ -84,17 +90,23 @@ pub fn resolve_command(
let resolved_args = DistributeTokensArgs {
input_csv: args.input_csv,
from_bids: args.from_bids,
transactions_db: args.transactions_db,
transaction_db: args.transaction_db,
dollars_per_sol: args.dollars_per_sol,
dry_run: args.dry_run,
no_wait: args.no_wait,
sender_keypair: args.sender_keypair.as_ref().map(|key_url| {
signer_from_path(&matches, &key_url, "sender", &mut wallet_manager).unwrap()
}),
fee_payer: args.fee_payer.as_ref().map(|key_url| {
signer_from_path(&matches, &key_url, "fee-payer", &mut wallet_manager).unwrap()
}),
force: args.force,
sender_keypair: signer_from_path(
&matches,
&args.sender_keypair,
"sender",
&mut wallet_manager,
)
.unwrap(),
fee_payer: signer_from_path(
&matches,
&args.fee_payer,
"fee-payer",
&mut wallet_manager,
)
.unwrap(),
stake_args: resolved_stake_args.map_or(Ok(None), |r| r.map(Some))?,
};
Ok(Command::DistributeTokens(resolved_args))
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ fn main() -> Result<(), Box<dyn Error>> {
let config = Config::load(&command_args.config_file)?;
let json_rpc_url = command_args.url.unwrap_or(config.json_rpc_url);
let client = RpcClient::new(json_rpc_url);
let thin_client = ThinClient::new(client);

match resolve_command(command_args.command)? {
Command::DistributeTokens(args) => {
let thin_client = ThinClient::new(client, args.dry_run);
tokens::process_distribute_tokens(&thin_client, &args)?;
}
Command::Balances(args) => {
let thin_client = ThinClient::new(client, false);
tokens::process_balances(&thin_client, &args)?;
}
Command::TransactionLog(args) => {
Expand Down
Loading

0 comments on commit 041565d

Please sign in to comment.