Skip to content

Commit fe250a2

Browse files
committed
callbacks: inline subcommand definitions
There is little use in going through the trait for this.
1 parent 0edf721 commit fe250a2

File tree

6 files changed

+18
-58
lines changed

6 files changed

+18
-58
lines changed

src/callbacks/balances.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fs::File;
22
use std::io::{BufWriter, Write};
33
use std::path::PathBuf;
44

5-
use clap::{Arg, ArgMatches, Command};
5+
use clap::ArgMatches;
66

77
use crate::callbacks::Callback;
88

@@ -22,20 +22,6 @@ impl Balances {
2222
}
2323

2424
impl Callback for Balances {
25-
fn build_subcommand() -> Command
26-
where
27-
Self: Sized,
28-
{
29-
Command::new("balances")
30-
.about("Dumps all addresses with non-zero balance to CSV file")
31-
.arg(
32-
Arg::new("dump-folder")
33-
.help("Folder to store csv file")
34-
.index(1)
35-
.required(true),
36-
)
37-
}
38-
3925
fn new(matches: &ArgMatches) -> anyhow::Result<Self>
4026
where
4127
Self: Sized,

src/callbacks/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clap::{ArgMatches, Command};
1+
use clap::ArgMatches;
22

33
pub mod balances;
44
pub mod opreturn;
@@ -9,12 +9,6 @@ pub mod unspentcsvdump;
99
/// The parser ensures that the blocks arrive in the correct order.
1010
/// At this stage the main chain is already determined and orphans/stales are removed.
1111
pub trait Callback {
12-
/// Builds Command to specify callback name and required args,
13-
/// exits if some required args are missing.
14-
fn build_subcommand() -> Command
15-
where
16-
Self: Sized;
17-
1812
/// Instantiates callback
1913
fn new(matches: &ArgMatches) -> anyhow::Result<Self>
2014
where

src/callbacks/opreturn.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
use clap::{ArgMatches, Command};
1+
use clap::ArgMatches;
22

33
use crate::callbacks::Callback;
44

55
#[derive(Default)]
66
pub struct OpReturn;
77

88
impl Callback for OpReturn {
9-
fn build_subcommand() -> Command
10-
where
11-
Self: Sized,
12-
{
13-
Command::new("opreturn")
14-
.about("Shows embedded OP_RETURN data that is representable as UTF8")
15-
}
16-
179
fn new(_: &ArgMatches) -> anyhow::Result<Self>
1810
where
1911
Self: Sized,

src/callbacks/simplestats.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use bitcoin::hashes::{sha256d, Hash};
22
use std::collections::HashMap;
33
use std::io::Write;
44

5-
use clap::{ArgMatches, Command};
5+
use clap::ArgMatches;
66

77
use crate::callbacks::Callback;
88

@@ -174,13 +174,6 @@ impl SimpleStats {
174174
}
175175

176176
impl Callback for SimpleStats {
177-
fn build_subcommand() -> Command
178-
where
179-
Self: Sized,
180-
{
181-
Command::new("simplestats").about("Shows various Blockchain stats")
182-
}
183-
184177
fn new(_: &ArgMatches) -> anyhow::Result<Self>
185178
where
186179
Self: Sized,

src/callbacks/unspentcsvdump.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fs::File;
22
use std::io::{BufWriter, Write};
33
use std::path::PathBuf;
44

5-
use clap::{Arg, ArgMatches, Command};
5+
use clap::ArgMatches;
66

77
/// Dumps the UTXOs along with address in a csv file
88
pub struct UnspentCsvDump {
@@ -22,20 +22,6 @@ impl UnspentCsvDump {
2222
}
2323

2424
impl crate::callbacks::Callback for UnspentCsvDump {
25-
fn build_subcommand() -> Command
26-
where
27-
Self: Sized,
28-
{
29-
Command::new("unspentcsvdump")
30-
.about("Dumps the unspent outputs to CSV file")
31-
.arg(
32-
Arg::new("dump-folder")
33-
.help("Folder to store csv file")
34-
.index(1)
35-
.required(true),
36-
)
37-
}
38-
3925
fn new(matches: &ArgMatches) -> anyhow::Result<Self>
4026
where
4127
Self: Sized,

src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,19 @@ pub fn command() -> Command {
9595
.value_parser(clap::value_parser!(u64))
9696
.help("Specify last block for parsing (inclusive) (default: all known blocks)"))
9797
// Add callbacks
98-
.subcommand(UnspentCsvDump::build_subcommand())
99-
.subcommand(SimpleStats::build_subcommand())
100-
.subcommand(Balances::build_subcommand())
101-
.subcommand(OpReturn::build_subcommand())
98+
.subcommand(Command::new("unspentcsvdump").about("Dumps the unspent outputs to CSV file").arg(
99+
Arg::new("dump-folder")
100+
.help("Folder to store csv file")
101+
.index(1)
102+
.required(true)))
103+
.subcommand(Command::new("simplestats").about("Shows various Blockchain stats"))
104+
.subcommand(Command::new("balances").about("Dumps all addresses with non-zero balance to CSV file").arg(
105+
Arg::new("dump-folder")
106+
.help("Folder to store csv file")
107+
.index(1)
108+
.required(true),
109+
))
110+
.subcommand(Command::new("opreturn").about("Shows embedded OP_RETURN data that is representable as UTF8"))
102111
}
103112

104113
/// Returns default directory. TODO: test on windows

0 commit comments

Comments
 (0)