Skip to content

Commit

Permalink
Improve subcommand names (#867)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Dec 1, 2022
1 parent 785f9e0 commit 57b4099
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 102 deletions.
10 changes: 5 additions & 5 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ mod index;
mod info;
mod list;
mod parse;
mod range;
mod server;
mod subsidy;
mod supply;
mod traits;
mod wallet;
Expand All @@ -18,9 +18,9 @@ pub(crate) enum Subcommand {
Find(find::Find),
Index,
Info(info::Info),
ListRanges(list::List),
List(list::List),
Parse(parse::Parse),
Range(range::Range),
Subsidy(subsidy::Subsidy),
Server(server::Server),
Supply,
Traits(traits::Traits),
Expand All @@ -35,9 +35,9 @@ impl Subcommand {
Self::Find(find) => find.run(options),
Self::Index => index::run(options),
Self::Info(info) => info.run(options),
Self::ListRanges(list) => list.run(options),
Self::List(list) => list.run(options),
Self::Parse(parse) => parse.run(),
Self::Range(range) => range.run(),
Self::Subsidy(subsidy) => subsidy.run(),
Self::Server(server) => {
let index = Arc::new(Index::open(&options)?);
let handle = axum_server::Handle::new();
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;

#[derive(Debug, Parser)]
pub(crate) struct List {
#[clap(help = "List ordinal ranges in <OUTPOINT>.")]
#[clap(help = "List ordinals in <OUTPOINT>.")]
outpoint: OutPoint,
}

Expand Down
35 changes: 0 additions & 35 deletions src/subcommand/range.rs

This file was deleted.

23 changes: 23 additions & 0 deletions src/subcommand/subsidy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use super::*;

#[derive(Debug, Parser)]
pub(crate) struct Subsidy {
#[clap(help = "List ordinals in subsidy at <HEIGHT>.")]
height: Height,
}

impl Subsidy {
pub(crate) fn run(self) -> Result {
let first = self.height.starting_ordinal();

let subsidy = self.height.subsidy();

if subsidy == 0 {
bail!("block {} has no subsidy", self.height);
}

println!("{}\t{}\t{}", first, self.height.subsidy(), first.name());

Ok(())
}
}
4 changes: 2 additions & 2 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ mod expected;
mod find;
mod index;
mod info;
mod list_ranges;
mod list;
mod parse;
mod range;
mod server;
mod subsidy;
mod supply;
mod test_server;
mod traits;
Expand Down
4 changes: 2 additions & 2 deletions tests/list_ranges.rs → tests/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;
fn output_found() {
let rpc_server = test_bitcoincore_rpc::spawn();
CommandBuilder::new(
"--index-ordinals list-ranges 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0",
"--index-ordinals list 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0",
)
.rpc_server(&rpc_server)
.expected_stdout("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0\t0\t5000000000\tmythic\tnvtdijuwxlp\n")
Expand All @@ -15,7 +15,7 @@ fn output_found() {
fn output_not_found() {
let rpc_server = test_bitcoincore_rpc::spawn();
CommandBuilder::new(
"--index-ordinals list-ranges 0000000000000000000000000000000000000000000000000000000000000000:0",
"--index-ordinals list 0000000000000000000000000000000000000000000000000000000000000000:0",
)
.rpc_server(&rpc_server)
.expected_exit_code(1)
Expand Down
57 changes: 0 additions & 57 deletions tests/range.rs

This file was deleted.

37 changes: 37 additions & 0 deletions tests/subsidy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use super::*;

#[test]
fn genesis() {
CommandBuilder::new("subsidy 0")
.expected_stdout("0\t5000000000\tnvtdijuwxlp\n")
.run();
}

#[test]
fn second_block() {
CommandBuilder::new("subsidy 1")
.expected_stdout("5000000000\t5000000000\tnvtcsezkbth\n")
.run();
}

#[test]
fn second_to_last_block_with_subsidy() {
CommandBuilder::new("subsidy 6929998")
.expected_stdout("2099999997689998\t1\tb\n")
.run();
}

#[test]
fn last_block_with_subsidy() {
CommandBuilder::new("subsidy 6929999")
.expected_stdout("2099999997689999\t1\ta\n")
.run();
}

#[test]
fn first_block_without_subsidy() {
CommandBuilder::new("subsidy 6930000")
.expected_stderr("error: block 6930000 has no subsidy\n")
.expected_exit_code(1)
.run();
}

0 comments on commit 57b4099

Please sign in to comment.