-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubcommand.rs
102 lines (96 loc) Β· 2.88 KB
/
subcommand.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use super::*;
pub mod balances;
pub mod decode;
pub mod env;
pub mod epochs;
pub mod find;
pub mod index;
pub mod list;
pub mod parse;
pub mod runes;
pub(crate) mod server;
mod settings;
pub mod subsidy;
pub mod supply;
pub mod teleburn;
pub mod traits;
pub mod wallet;
#[derive(Debug, Parser)]
pub(crate) enum Subcommand {
#[command(about = "List all rune balances")]
Balances,
#[command(about = "Decode a transaction")]
Decode(decode::Decode),
#[command(about = "Start a regtest ord and bitcoind instance")]
Env(env::Env),
#[command(about = "List the first satoshis of each reward epoch")]
Epochs,
#[command(about = "Find a satoshi's current location")]
Find(find::Find),
#[command(subcommand, about = "Index commands")]
Index(index::IndexSubcommand),
#[command(about = "List the satoshis in an output")]
List(list::List),
#[command(about = "Parse a satoshi from ordinal notation")]
Parse(parse::Parse),
#[command(about = "List all runes")]
Runes,
#[command(about = "Run the explorer server")]
Server(server::Server),
#[command(about = "Display settings")]
Settings,
#[command(about = "Display information about a block's subsidy")]
Subsidy(subsidy::Subsidy),
#[command(about = "Display Bitcoin supply information")]
Supply,
#[command(about = "Generate teleburn addresses")]
Teleburn(teleburn::Teleburn),
#[command(about = "Display satoshi traits")]
Traits(traits::Traits),
#[command(about = "Wallet commands")]
Wallet(wallet::WalletCommand),
}
impl Subcommand {
pub(crate) fn run(self, settings: Settings) -> SubcommandResult {
match self {
Self::Balances => balances::run(settings),
Self::Decode(decode) => decode.run(settings),
Self::Env(env) => env.run(),
Self::Epochs => epochs::run(),
Self::Find(find) => find.run(settings),
Self::Index(index) => index.run(settings),
Self::List(list) => list.run(settings),
Self::Parse(parse) => parse.run(),
Self::Runes => runes::run(settings),
Self::Server(server) => {
let index = Arc::new(Index::open(&settings)?);
let handle = axum_server::Handle::new();
LISTENERS.lock().unwrap().push(handle.clone());
server.run(settings, index, handle)
}
Self::Settings => settings::run(settings),
Self::Subsidy(subsidy) => subsidy.run(),
Self::Supply => supply::run(),
Self::Teleburn(teleburn) => teleburn.run(),
Self::Traits(traits) => traits.run(),
Self::Wallet(wallet) => wallet.run(settings),
}
}
}
pub trait Output: Send {
fn print_json(&self, minify: bool);
}
impl<T> Output for T
where
T: Serialize + Send,
{
fn print_json(&self, minify: bool) {
if minify {
serde_json::to_writer(io::stdout(), self).ok();
} else {
serde_json::to_writer_pretty(io::stdout(), self).ok();
}
println!();
}
}
pub(crate) type SubcommandResult = Result<Option<Box<dyn Output>>>;