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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
use anyhow::Error;
use clap::Subcommand;
use fehler::throws;
use solana_sdk::{pubkey::Pubkey, signature::Signature};
use trdelnik_explorer::display::DisplayFormat;
mod account;
mod program;
mod transaction;
#[derive(Subcommand)]
pub enum ExplorerCommand {
/// Show the contents of an account
Account {
/// Ed25519 pubkey, PDA or hash of a pubkey
pubkey: Pubkey,
/// Pretty-printed JSON output
#[clap(long = "json-pretty", conflicts_with = "json")]
jsonpretty: bool,
/// JSON output
#[clap(long, conflicts_with = "jsonpretty")]
json: bool,
#[clap(long = "hide-lamports")]
/// Hide lamports in the output
hidelamports: bool,
/// Hide data in the output
#[clap(long = "hide-data")]
hidedata: bool,
#[clap(long = "hide-owner")]
/// Hide owner in the output
hideowner: bool,
#[clap(long = "hide-executable")]
/// Hide executable in the output
hideexecutable: bool,
/// Hide rent epoch in the output
#[clap(long = "hide-rent-epoch")]
hiderentepoch: bool,
},
/// Show the details of a program
Program {
/// Address of a program to show
pubkey: Pubkey,
/// Pretty-printed JSON output
#[clap(long = "json-pretty", conflicts_with = "json")]
jsonpretty: bool,
/// JSON output
#[clap(long, conflicts_with = "jsonpretty")]
json: bool,
/// Hide program account in the output
#[clap(long = "hide-program-account")]
hideprogramaccount: bool,
/// Hide programdata account in the output
#[clap(long = "hide-programdata-account")]
hideprogramdataaccount: bool,
},
/// Show the contents of a transaction
Transaction {
/// Signature of a transaction
signature: Signature,
/// Raw transaction without interpretation
#[clap(short, long)]
raw: bool,
/// Pretty-printed JSON output
#[clap(long = "json-pretty", conflicts_with = "json")]
jsonpretty: bool,
/// JSON output
#[clap(long, conflicts_with = "jsonpretty")]
json: bool,
/// Hide overview in the output
#[clap(long = "hide-overview")]
hideoverview: bool,
/// Hide transaction content in the output
#[clap(long = "hide-transaction")]
hidetransaction: bool,
/// Hide log messages in the output
#[clap(long = "hide-log-messages", conflicts_with = "raw")]
hidelogmessages: bool,
},
}
#[throws]
pub async fn explorer(subcmd: ExplorerCommand) {
match subcmd {
ExplorerCommand::Account {
pubkey,
jsonpretty,
json,
hidelamports,
hidedata,
hideowner,
hideexecutable,
hiderentepoch,
} => {
if jsonpretty {
account::view(
pubkey,
hidelamports,
hidedata,
hideowner,
hideexecutable,
hiderentepoch,
DisplayFormat::JSONPretty,
)
.await?
} else if json {
account::view(
pubkey,
hidelamports,
hidedata,
hideowner,
hideexecutable,
hiderentepoch,
DisplayFormat::JSON,
)
.await?
} else {
account::view(
pubkey,
hidelamports,
hidedata,
hideowner,
hideexecutable,
hiderentepoch,
DisplayFormat::Cli,
)
.await?
}
}
ExplorerCommand::Program {
pubkey,
jsonpretty,
json,
hideprogramaccount,
hideprogramdataaccount,
} => {
if jsonpretty {
program::view(
pubkey,
hideprogramaccount,
hideprogramdataaccount,
DisplayFormat::JSONPretty,
)
.await?
} else if json {
program::view(
pubkey,
hideprogramaccount,
hideprogramdataaccount,
DisplayFormat::JSON,
)
.await?
} else {
program::view(
pubkey,
hideprogramaccount,
hideprogramdataaccount,
DisplayFormat::Cli,
)
.await?
}
}
ExplorerCommand::Transaction {
signature,
raw,
jsonpretty,
json,
hideoverview,
hidetransaction,
hidelogmessages,
} => {
if jsonpretty {
transaction::view(
signature,
raw,
hideoverview,
hidetransaction,
hidelogmessages,
DisplayFormat::JSONPretty,
)
.await?
} else if json {
transaction::view(
signature,
raw,
hideoverview,
hidetransaction,
hidelogmessages,
DisplayFormat::JSON,
)
.await?
} else {
transaction::view(
signature,
raw,
hideoverview,
hidetransaction,
hidelogmessages,
DisplayFormat::Cli,
)
.await?
}
}
}
}