Skip to content

Commit

Permalink
Merge pull request #96 from dspicher/bump-clap
Browse files Browse the repository at this point in the history
bump clap dependency to 4.x
  • Loading branch information
gcarq authored Jul 10, 2023
2 parents 442fd20 + 886e0ae commit d592c92
Show file tree
Hide file tree
Showing 10 changed files with 545 additions and 170 deletions.
299 changes: 249 additions & 50 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ edition = "2021"
[dependencies]
log = { version = "^0.4", default-features = false, features = ["std"] }
chrono = { version = "^0.4.24", default-features = false, features = ["std"] }
clap = "^2.34.0"
clap = { version = "^4.3.8", features = [ "cargo" ] }
byteorder = "^1.3"
rusty-leveldb = "^1.0.6"
dirs = "^5.0.0"
bitcoin = "^0.30.0"
rayon = "^1.3"
seek_bufread = "^1.2.2"

[dev-dependencies]
tempfile = "^3.6.0"

# The development profile, used for `cargo build`
[profile.dev]
opt-level = 0 # Controls the --opt-level the compiler builds with
Expand Down
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,33 @@ If something doesn't match the parser exits.

## Usage
```
USAGE:
rusty-blockparser [FLAGS] [OPTIONS] [SUBCOMMAND]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
-v Increases verbosity level. Info=0, Debug=1, Trace=2 (default: 0)
--verify Verifies the leveldb index integrity and verifies merkle roots
OPTIONS:
-d, --blockchain-dir <blockchain-dir> Sets blockchain directory which contains blk.dat files (default:
~/.bitcoin/blocks)
-c, --coin <NAME> Specify blockchain coin (default: bitcoin) [possible values: bitcoin,
testnet3, namecoin, litecoin, dogecoin, myriadcoin, unobtanium,
noteblockchain]
-e, --end <HEIGHT> Specify last block for parsing (inclusive) (default: all known blocks)
-s, --start <HEIGHT> Specify starting block for parsing (inclusive)
SUBCOMMANDS:
balances Dumps all addresses with non-zero balance to CSV file
csvdump Dumps the whole blockchain into CSV files
help Prints this message or the help of the given subcommand(s)
opreturn Shows embedded OP_RETURN data that is representable as UTF8
simplestats Shows various Blockchain stats
unspentcsvdump Dumps the unspent outputs to CSV file
Usage: rusty-blockparser [OPTIONS] [COMMAND]
Commands:
unspentcsvdump Dumps the unspent outputs to CSV file
csvdump Dumps the whole blockchain into CSV files
simplestats Shows various Blockchain stats
balances Dumps all addresses with non-zero balance to CSV file
opreturn Shows embedded OP_RETURN data that is representable as UTF8
help Print this message or the help of the given subcommand(s)
Options:
--verify
Verifies merkle roots and block hashes
-v...
Increases verbosity level. Info=0, Debug=1, Trace=2 (default: 0)
-c, --coin <NAME>
Specify blockchain coin (default: bitcoin) [possible values: bitcoin, testnet3, namecoin, litecoin, dogecoin, myriadcoin, unobtanium, noteblockchain]
-d, --blockchain-dir <blockchain-dir>
Sets blockchain directory which contains blk.dat files (default: ~/.bitcoin/blocks)
-s, --start <HEIGHT>
Specify starting block for parsing (inclusive)
-e, --end <HEIGHT>
Specify last block for parsing (inclusive) (default: all known blocks)
-h, --help
Print help
-V, --version
Print version
```
### Example

Expand Down
10 changes: 5 additions & 5 deletions src/callbacks/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fs::{self, File};
use std::io::{BufWriter, Write};
use std::path::PathBuf;

use clap::{App, Arg, ArgMatches, SubCommand};
use clap::{Arg, ArgMatches, Command};

use crate::blockchain::proto::block::Block;
use crate::callbacks::{common, Callback};
Expand All @@ -28,16 +28,16 @@ impl Balances {
}

impl Callback for Balances {
fn build_subcommand<'a, 'b>() -> App<'a, 'b>
fn build_subcommand() -> Command
where
Self: Sized,
{
SubCommand::with_name("balances")
Command::new("balances")
.about("Dumps all addresses with non-zero balance to CSV file")
.version("0.1")
.author("gcarq <[email protected]>")
.arg(
Arg::with_name("dump-folder")
Arg::new("dump-folder")
.help("Folder to store csv file")
.index(1)
.required(true),
Expand All @@ -48,7 +48,7 @@ impl Callback for Balances {
where
Self: Sized,
{
let dump_folder = &PathBuf::from(matches.value_of("dump-folder").unwrap());
let dump_folder = &PathBuf::from(matches.get_one::<String>("dump-folder").unwrap());
let cb = Balances {
dump_folder: PathBuf::from(dump_folder),
writer: Balances::create_writer(4000000, dump_folder.join("balances.csv.tmp"))?,
Expand Down
10 changes: 5 additions & 5 deletions src/callbacks/csvdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fs::{self, File};
use std::io::{BufWriter, Write};
use std::path::PathBuf;

use clap::{App, Arg, ArgMatches, SubCommand};
use clap::{Arg, ArgMatches, Command};

use crate::blockchain::proto::block::Block;
use crate::blockchain::proto::tx::{EvaluatedTx, EvaluatedTxOut, TxInput};
Expand Down Expand Up @@ -33,16 +33,16 @@ impl CsvDump {
}

impl Callback for CsvDump {
fn build_subcommand<'a, 'b>() -> App<'a, 'b>
fn build_subcommand() -> Command
where
Self: Sized,
{
SubCommand::with_name("csvdump")
Command::new("csvdump")
.about("Dumps the whole blockchain into CSV files")
.version("0.1")
.author("gcarq <[email protected]>")
.arg(
Arg::with_name("dump-folder")
Arg::new("dump-folder")
.help("Folder to store csv files")
.index(1)
.required(true),
Expand All @@ -53,7 +53,7 @@ impl Callback for CsvDump {
where
Self: Sized,
{
let dump_folder = &PathBuf::from(matches.value_of("dump-folder").unwrap());
let dump_folder = &PathBuf::from(matches.get_one::<String>("dump-folder").unwrap());
let cap = 4000000;
let cb = CsvDump {
dump_folder: PathBuf::from(dump_folder),
Expand Down
6 changes: 3 additions & 3 deletions src/callbacks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{App, ArgMatches};
use clap::{ArgMatches, Command};

use crate::blockchain::proto::block::Block;
use crate::errors::OpResult;
Expand All @@ -14,9 +14,9 @@ pub mod unspentcsvdump;
/// The parser ensures that the blocks arrive in the correct order.
/// At this stage the main chain is already determined and orphans/stales are removed.
pub trait Callback {
/// Builds SubCommand to specify callback name and required args,
/// Builds Command to specify callback name and required args,
/// exits if some required args are missing.
fn build_subcommand<'a, 'b>() -> App<'a, 'b>
fn build_subcommand() -> Command
where
Self: Sized;

Expand Down
6 changes: 3 additions & 3 deletions src/callbacks/opreturn.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{App, ArgMatches, SubCommand};
use clap::{ArgMatches, Command};

use crate::blockchain::proto::block::Block;
use crate::blockchain::proto::script::ScriptPattern;
Expand All @@ -9,11 +9,11 @@ use crate::errors::OpResult;
pub struct OpReturn;

impl Callback for OpReturn {
fn build_subcommand<'a, 'b>() -> App<'a, 'b>
fn build_subcommand() -> Command
where
Self: Sized,
{
SubCommand::with_name("opreturn")
Command::new("opreturn")
.about("Shows embedded OP_RETURN data that is representable as UTF8")
.version("0.1")
.author("gcarq <[email protected]>")
Expand Down
6 changes: 3 additions & 3 deletions src/callbacks/simplestats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bitcoin::hashes::{sha256d, Hash};
use std::collections::HashMap;
use std::io::{self, Write};

use clap::{App, ArgMatches, SubCommand};
use clap::{ArgMatches, Command};

use crate::blockchain::proto::block::{self, Block};
use crate::blockchain::proto::script::ScriptPattern;
Expand Down Expand Up @@ -182,11 +182,11 @@ impl SimpleStats {
}

impl Callback for SimpleStats {
fn build_subcommand<'a, 'b>() -> App<'a, 'b>
fn build_subcommand() -> Command
where
Self: Sized,
{
SubCommand::with_name("simplestats")
Command::new("simplestats")
.about("Shows various Blockchain stats")
.version("0.1")
.author("gcarq <[email protected]>")
Expand Down
10 changes: 5 additions & 5 deletions src/callbacks/unspentcsvdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::io::{BufWriter, Write};
use std::path::PathBuf;

use byteorder::{LittleEndian, ReadBytesExt};
use clap::{App, Arg, ArgMatches, SubCommand};
use clap::{Arg, ArgMatches, Command};

use crate::blockchain::proto::block::Block;
use crate::callbacks::{common, Callback};
Expand All @@ -32,16 +32,16 @@ impl UnspentCsvDump {
}

impl Callback for UnspentCsvDump {
fn build_subcommand<'a, 'b>() -> App<'a, 'b>
fn build_subcommand() -> Command
where
Self: Sized,
{
SubCommand::with_name("unspentcsvdump")
Command::new("unspentcsvdump")
.about("Dumps the unspent outputs to CSV file")
.version("0.1")
.author("fsvm88 <[email protected]>")
.arg(
Arg::with_name("dump-folder")
Arg::new("dump-folder")
.help("Folder to store csv file")
.index(1)
.required(true),
Expand All @@ -52,7 +52,7 @@ impl Callback for UnspentCsvDump {
where
Self: Sized,
{
let dump_folder = &PathBuf::from(matches.value_of("dump-folder").unwrap());
let dump_folder = &PathBuf::from(matches.get_one::<String>("dump-folder").unwrap());
let cb = UnspentCsvDump {
dump_folder: PathBuf::from(dump_folder),
writer: UnspentCsvDump::create_writer(4000000, dump_folder.join("unspent.csv.tmp"))?,
Expand Down
Loading

0 comments on commit d592c92

Please sign in to comment.