Skip to content

Commit

Permalink
Add --show-height to -ord find
Browse files Browse the repository at this point in the history
  • Loading branch information
gmart7t2 committed Aug 8, 2023
1 parent 5579982 commit 3562462
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,13 @@ impl Index {
self.client.get_raw_transaction_info(&txid, None)
}

pub(crate) fn get_block_height(
&self,
blockhash: bitcoin::BlockHash,
) -> Result<usize, bitcoincore_rpc::Error> {
Ok(self.client.get_block_header_info(&blockhash)?.height)
}

pub(crate) fn get_transaction_blockhash(&self, txid: Txid) -> Result<Option<BlockHash>> {
Ok(
self
Expand Down
10 changes: 10 additions & 0 deletions src/subcommand/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub(crate) struct Find {
show_blockhash: bool,
#[clap(long, help = "Show dates in the results.")]
show_date: bool,
#[clap(long, help = "Show block heights in the results.")]
show_height: bool,
#[clap(long, help = "Show sat names in the results.")]
show_name: bool,
#[clap(long, help = "Show timestamps in the results.")]
Expand All @@ -51,6 +53,8 @@ pub struct Output {
#[serde(skip_serializing_if = "Option::is_none")]
pub date: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub height: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub timestamp: Option<usize>,
Expand Down Expand Up @@ -167,6 +171,7 @@ impl Find {
let tx = if self.show_address
|| self.show_blockhash
|| self.show_date
|| self.show_height
|| self.show_time
|| self.show_value
{
Expand All @@ -184,6 +189,7 @@ impl Find {
address: None,
blockhash: None,
date: None,
height: None,
name: None,
timestamp: None,
value: None,
Expand All @@ -201,6 +207,10 @@ impl Find {
result.blockhash = tx.blockhash;
}

if self.show_height {
result.height = Some(index.get_block_height(tx.blockhash.unwrap())?);
}

if self.show_date {
result.date = Some(
NaiveDateTime::from_timestamp_opt(tx.time.unwrap() as i64, 0)
Expand Down

0 comments on commit 3562462

Please sign in to comment.