Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress empty command output #2995

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ pub fn main() {

process::exit(1);
}
Ok(output) => output.print_json(),
Ok(output) => {
if let Some(output) = output {
output.print_json();
}
}
}

gracefully_shutdown_indexer();
Expand Down
5 changes: 1 addition & 4 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ impl Subcommand {
}
}

#[derive(Serialize, Deserialize)]
pub struct Empty {}

pub(crate) trait Output: Send {
fn print_json(&self);
}
Expand All @@ -94,4 +91,4 @@ where
}
}

pub(crate) type SubcommandResult = Result<Box<dyn Output>>;
pub(crate) type SubcommandResult = Result<Option<Box<dyn Output>>>;
4 changes: 2 additions & 2 deletions src/subcommand/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(crate) fn run(options: Options) -> SubcommandResult {

index.update()?;

Ok(Box::new(Output {
Ok(Some(Box::new(Output {
runes: index.get_rune_balance_map()?,
}))
})))
}
6 changes: 3 additions & 3 deletions src/subcommand/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ impl Decode {
let inscriptions = ParsedEnvelope::from_transaction(&transaction);

if self.compact {
Ok(Box::new(CompactOutput {
Ok(Some(Box::new(CompactOutput {
inscriptions: inscriptions
.clone()
.into_iter()
.map(|inscription| inscription.payload.try_into())
.collect::<Result<Vec<CompactInscription>>>()?,
}))
})))
} else {
Ok(Box::new(RawOutput { inscriptions }))
Ok(Some(Box::new(RawOutput { inscriptions })))
}
}
}
2 changes: 1 addition & 1 deletion src/subcommand/epochs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ pub(crate) fn run() -> SubcommandResult {
starting_sats.push(sat);
}

Ok(Box::new(Output { starting_sats }))
Ok(Some(Box::new(Output { starting_sats })))
}
4 changes: 2 additions & 2 deletions src/subcommand/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ impl Find {

match self.end {
Some(end) => match index.find_range(self.sat, end)? {
Some(result) => Ok(Box::new(result)),
Some(result) => Ok(Some(Box::new(result))),
None => Err(anyhow!("range has not been mined as of index height")),
},
None => match index.find(self.sat)? {
Some(satpoint) => Ok(Box::new(Output { satpoint })),
Some(satpoint) => Ok(Some(Box::new(Output { satpoint }))),
None => Err(anyhow!("sat has not been mined as of index height")),
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/index/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ impl Export {
index.update()?;
index.export(&self.tsv, self.include_addresses)?;

Ok(Box::new(Empty {}))
Ok(None)
}
}
4 changes: 2 additions & 2 deletions src/subcommand/index/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ impl Info {
elapsed: (end.starting_timestamp - start.starting_timestamp) as f64 / 1000.0 / 60.0,
});
}
Ok(Box::new(output))
Ok(Some(Box::new(output)))
} else {
Ok(Box::new(info))
Ok(Some(Box::new(info)))
}
}
}
2 changes: 1 addition & 1 deletion src/subcommand/index/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ pub(crate) fn run(options: Options) -> SubcommandResult {

index.update()?;

Ok(Box::new(Empty {}))
Ok(None)
}
2 changes: 1 addition & 1 deletion src/subcommand/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl List {
});
}

Ok(Box::new(outputs))
Ok(Some(Box::new(outputs)))
}
Some(crate::index::List::Spent) => Err(anyhow!("output spent.")),
None => Err(anyhow!("output not found")),
Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub struct Output {

impl Parse {
pub(crate) fn run(self) -> SubcommandResult {
Ok(Box::new(Output {
Ok(Some(Box::new(Output {
object: self.object,
}))
})))
}
}
2 changes: 1 addition & 1 deletion src/subcommand/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,6 @@ impl Preview {
.run()?;
}

Ok(Box::new(Empty {}))
Ok(None)
}
}
4 changes: 2 additions & 2 deletions src/subcommand/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) fn run(options: Options) -> SubcommandResult {

index.update()?;

Ok(Box::new(Output {
Ok(Some(Box::new(Output {
runes: index
.runes()?
.into_iter()
Expand Down Expand Up @@ -82,5 +82,5 @@ pub(crate) fn run(options: Options) -> SubcommandResult {
},
)
.collect::<BTreeMap<Rune, RuneInfo>>(),
}))
})))
}
2 changes: 1 addition & 1 deletion src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl Server {
(None, None) => unreachable!(),
}

Ok(Box::new(Empty {}) as Box<dyn Output>)
Ok(None)
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/subsidy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ impl Subsidy {
bail!("block {} has no subsidy", self.height);
}

Ok(Box::new(Output {
Ok(Some(Box::new(Output {
first: first.0,
subsidy,
name: first.name(),
}))
})))
}
}
4 changes: 2 additions & 2 deletions src/subcommand/supply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ pub(crate) fn run() -> SubcommandResult {
last += 1;
}

Ok(Box::new(Output {
Ok(Some(Box::new(Output {
supply: Sat::SUPPLY,
first: 0,
last: Sat::SUPPLY - 1,
last_mined_in_block: last,
}))
})))
}
4 changes: 2 additions & 2 deletions src/subcommand/teleburn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub struct Output {

impl Teleburn {
pub(crate) fn run(self) -> SubcommandResult {
Ok(Box::new(Output {
Ok(Some(Box::new(Output {
ethereum: self.destination.into(),
}))
})))
}
}
4 changes: 2 additions & 2 deletions src/subcommand/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct Output {

impl Traits {
pub(crate) fn run(self) -> SubcommandResult {
Ok(Box::new(Output {
Ok(Some(Box::new(Output {
number: self.sat.n(),
decimal: self.sat.decimal().to_string(),
degree: self.sat.degree().to_string(),
Expand All @@ -33,6 +33,6 @@ impl Traits {
period: self.sat.period(),
offset: self.sat.third(),
rarity: self.sat.rarity(),
}))
})))
}
}
4 changes: 2 additions & 2 deletions src/subcommand/wallet/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ pub(crate) fn run(wallet: String, options: Options) -> SubcommandResult {
}
}

Ok(Box::new(Output {
Ok(Some(Box::new(Output {
cardinal,
ordinal,
runes: index.has_rune_index().then_some(runes),
runic: index.has_rune_index().then_some(runic),
total: cardinal + ordinal + runic,
}))
})))
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet/cardinals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ pub(crate) fn run(wallet: String, options: Options) -> SubcommandResult {
})
.collect::<Vec<CardinalUtxo>>();

Ok(Box::new(cardinal_utxos))
Ok(Some(Box::new(cardinal_utxos)))
}
4 changes: 2 additions & 2 deletions src/subcommand/wallet/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ impl Create {

wallet::initialize(wallet, &options, mnemonic.to_seed(self.passphrase.clone()))?;

Ok(Box::new(Output {
Ok(Some(Box::new(Output {
mnemonic,
passphrase: Some(self.passphrase),
}))
})))
}
}
4 changes: 2 additions & 2 deletions src/subcommand/wallet/etch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ impl Etch {

let transaction = client.send_raw_transaction(&signed_transaction)?;

Ok(Box::new(Output {
Ok(Some(Box::new(Output {
rune: self.rune,
transaction,
}))
})))
}
}
8 changes: 4 additions & 4 deletions src/subcommand/wallet/inscribe/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ impl Batch {
)?;

if self.dry_run {
return Ok(Box::new(self.output(
return Ok(Some(Box::new(self.output(
commit_tx.txid(),
reveal_tx.txid(),
total_fees,
self.inscriptions.clone(),
)));
))));
}

let signed_commit_tx = client
Expand Down Expand Up @@ -114,12 +114,12 @@ impl Batch {
}
};

Ok(Box::new(self.output(
Ok(Some(Box::new(self.output(
commit,
reveal,
total_fees,
self.inscriptions.clone(),
)))
))))
}

fn output(
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet/inscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ pub(crate) fn run(wallet: String, options: Options) -> SubcommandResult {
}
}

Ok(Box::new(output))
Ok(Some(Box::new(output)))
}
2 changes: 1 addition & 1 deletion src/subcommand/wallet/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ pub(crate) fn run(wallet: String, options: Options) -> SubcommandResult {
});
}

Ok(Box::new(outputs))
Ok(Some(Box::new(outputs)))
}
2 changes: 1 addition & 1 deletion src/subcommand/wallet/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ pub(crate) fn run(wallet: String, options: Options) -> SubcommandResult {
let address = bitcoin_rpc_client_for_wallet_command(wallet, &options)?
.get_new_address(None, Some(bitcoincore_rpc::json::AddressType::Bech32m))?;

Ok(Box::new(Output { address }))
Ok(Some(Box::new(Output { address })))
}
2 changes: 1 addition & 1 deletion src/subcommand/wallet/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ impl Restore {
self.mnemonic.to_seed(self.passphrase),
)?;

Ok(Box::new(Empty {}))
Ok(None)
}
}
4 changes: 2 additions & 2 deletions src/subcommand/wallet/sats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Sats {
output: outpoint,
});
}
Ok(Box::new(output))
Ok(Some(Box::new(output)))
} else {
let mut output = Vec::new();
for (outpoint, sat, offset, rarity) in rare_sats(utxos) {
Expand All @@ -60,7 +60,7 @@ impl Sats {
rarity,
});
}
Ok(Box::new(output))
Ok(Some(Box::new(output)))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/subcommand/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Send {
Outgoing::Amount(amount) => {
Self::lock_non_cardinal_outputs(&client, &inscriptions, &runic_outputs, unspent_outputs)?;
let transaction = Self::send_amount(&client, amount, address, self.fee_rate)?;
return Ok(Box::new(Output { transaction }));
return Ok(Some(Box::new(Output { transaction })));
}
Outgoing::InscriptionId(id) => index
.get_inscription_satpoint_by_id(id)?
Expand All @@ -64,7 +64,7 @@ impl Send {
runic_outputs,
unspent_outputs,
)?;
return Ok(Box::new(Output { transaction }));
return Ok(Some(Box::new(Output { transaction })));
}
Outgoing::SatPoint(satpoint) => {
for inscription_satpoint in inscriptions.keys() {
Expand Down Expand Up @@ -112,7 +112,7 @@ impl Send {

let txid = client.send_raw_transaction(&signed_tx)?;

Ok(Box::new(Output { transaction: txid }))
Ok(Some(Box::new(Output { transaction: txid })))
}

fn lock_non_cardinal_outputs(
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ impl Transactions {
});
}

Ok(Box::new(output))
Ok(Some(Box::new(output)))
}
}
Loading
Loading