Skip to content

Commit

Permalink
Rename print-database command to transaction-log (solana-labs#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
garious authored May 8, 2020
1 parent 426ec4f commit 6007905
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
14 changes: 9 additions & 5 deletions src/arg_parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::args::{Args, BalancesArgs, Command, DistributeTokensArgs, PrintDbArgs, StakeArgs};
use crate::args::{
Args, BalancesArgs, Command, DistributeTokensArgs, StakeArgs, TransactionLogArgs,
};
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 @@ -198,7 +200,7 @@ where
),
)
.subcommand(
SubCommand::with_name("print-database")
SubCommand::with_name("transaction-log")
.about("Print the database to a CSV file")
.arg(
Arg::with_name("transactions_db")
Expand Down Expand Up @@ -264,8 +266,8 @@ fn parse_balances_args(matches: &ArgMatches<'_>) -> BalancesArgs {
}
}

fn parse_print_db_args(matches: &ArgMatches<'_>) -> PrintDbArgs {
PrintDbArgs {
fn parse_transaction_log_args(matches: &ArgMatches<'_>) -> TransactionLogArgs {
TransactionLogArgs {
transactions_db: value_t_or_exit!(matches, "transactions_db", String),
output_path: value_t_or_exit!(matches, "output_path", String),
}
Expand All @@ -288,7 +290,9 @@ where
Command::DistributeTokens(parse_distribute_stake_args(matches))
}
("balances", Some(matches)) => Command::Balances(parse_balances_args(matches)),
("print-database", Some(matches)) => Command::PrintDb(parse_print_db_args(matches)),
("transaction-log", Some(matches)) => {
Command::TransactionLog(parse_transaction_log_args(matches))
}
_ => {
eprintln!("{}", matches.usage());
exit(1);
Expand Down
6 changes: 3 additions & 3 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ pub struct BalancesArgs {
pub dollars_per_sol: Option<f64>,
}

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

pub enum Command<P, K> {
DistributeTokens(DistributeTokensArgs<P, K>),
Balances(BalancesArgs),
PrintDb(PrintDbArgs),
TransactionLog(TransactionLogArgs),
}

pub struct Args<P, K> {
Expand Down Expand Up @@ -100,6 +100,6 @@ pub fn resolve_command(
Ok(Command::DistributeTokens(resolved_args))
}
Command::Balances(args) => Ok(Command::Balances(args)),
Command::PrintDb(args) => Ok(Command::PrintDb(args)),
Command::TransactionLog(args) => Ok(Command::TransactionLog(args)),
}
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ fn main() -> Result<(), Box<dyn Error>> {
Command::Balances(args) => {
tokens::process_balances(&thin_client, &args)?;
}
Command::PrintDb(args) => {
tokens::process_print_db(&args)?;
Command::TransactionLog(args) => {
tokens::process_transaction_log(&args)?;
}
}
Ok(())
Expand Down
12 changes: 6 additions & 6 deletions src/tokens.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::args::{BalancesArgs, DistributeTokensArgs, PrintDbArgs, StakeArgs};
use crate::args::{BalancesArgs, DistributeTokensArgs, StakeArgs, TransactionLogArgs};
use crate::thin_client::{Client, ThinClient};
use console::style;
use csv::{ReaderBuilder, Trim};
Expand Down Expand Up @@ -235,7 +235,7 @@ fn open_db(path: &str, dry_run: bool) -> Result<PickleDb, pickledb::error::Error
}
}

pub fn print_db<P: AsRef<Path>>(db: &PickleDb, path: &P) -> Result<(), io::Error> {
pub fn write_transaction_log<P: AsRef<Path>>(db: &PickleDb, path: &P) -> Result<(), io::Error> {
let mut wtr = csv::WriterBuilder::new().from_path(path).unwrap();
for (signature, info) in read_transaction_data(db) {
let signed_info = SignedTransactionInfo {
Expand Down Expand Up @@ -518,9 +518,9 @@ pub fn process_balances<T: Client>(
Ok(())
}

pub fn process_print_db(args: &PrintDbArgs) -> Result<(), Error> {
pub fn process_transaction_log(args: &TransactionLogArgs) -> Result<(), Error> {
let db = open_db(&args.transactions_db, true)?;
print_db(&db, &args.output_path)?;
write_transaction_log(&db, &args.output_path)?;
Ok(())
}

Expand Down Expand Up @@ -893,15 +893,15 @@ mod tests {
}

#[test]
fn test_print_db() {
fn test_write_transaction_log() {
let mut db =
PickleDb::new_yaml(NamedTempFile::new().unwrap(), PickleDbDumpPolicy::NeverDump);
let signature = Signature::default();
let transaction_info = TransactionInfo::default();
db.set(&signature.to_string(), &transaction_info).unwrap();

let csv_file = NamedTempFile::new().unwrap();
print_db(&db, &csv_file).unwrap();
write_transaction_log(&db, &csv_file).unwrap();

let mut rdr = ReaderBuilder::new().trim(Trim::All).from_reader(csv_file);
let signed_infos: Vec<SignedTransactionInfo> =
Expand Down

0 comments on commit 6007905

Please sign in to comment.