Skip to content

Commit

Permalink
Add ord inscribedsats <start> <end> to list inscriptions on the spe…
Browse files Browse the repository at this point in the history
…cified range of sats.
  • Loading branch information
gmart7t2 committed Mar 5, 2024
1 parent c432783 commit df3e243
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,29 @@ impl Index {
Ok(ids)
}

pub(crate) fn get_inscription_ids_by_sat_range(&self, start: Sat, end: Sat) -> Result<Vec<(Sat, InscriptionId)>> {
let rtx = self.database.begin_read()?;

let sequence_number_to_inscription_entry =
rtx.open_table(SEQUENCE_NUMBER_TO_INSCRIPTION_ENTRY)?;

let mut ids = Vec::new();

for range in rtx
.open_multimap_table(SAT_TO_SEQUENCE_NUMBER)?
.range(start.n()..end.n())? {
let (sat, seqs) = range?;
let sat = sat.value();
for seq in seqs {
ids.push((Sat(sat), sequence_number_to_inscription_entry
.get(seq?.value())
.map(|entry| InscriptionEntry::load(entry.unwrap().value()).id)?));
}
}

Ok(ids)
}

pub(crate) fn get_inscription_ids_by_sat_paginated(
&self,
sat: Sat,
Expand Down
4 changes: 4 additions & 0 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod decode;
pub mod epochs;
pub mod find;
pub mod index;
pub mod inscribedsats;
pub mod list;
pub mod parse;
mod preview;
Expand All @@ -30,6 +31,8 @@ pub(crate) enum Subcommand {
#[command(subcommand, about = "Index commands")]
Index(index::IndexSubcommand),
#[command(about = "List the satoshis in an output")]
Inscribedsats(inscribedsats::Inscribedsats),
#[command(about = "List inscriptions on a range of sats")]
List(list::List),
#[command(about = "Parse a satoshi from ordinal notation")]
Parse(parse::Parse),
Expand Down Expand Up @@ -61,6 +64,7 @@ impl Subcommand {
Self::Epochs => epochs::run(),
Self::Find(find) => find.run(options),
Self::Index(index) => index.run(options),
Self::Inscribedsats(inscribedsats) => inscribedsats.run(options),
Self::List(list) => list.run(options),
Self::Parse(parse) => parse.run(),
Self::Preview(preview) => preview.run(),
Expand Down
23 changes: 23 additions & 0 deletions src/subcommand/inscribedsats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use super::*;

#[derive(Debug, Parser)]
pub(crate) struct Inscribedsats {
#[arg(help = "List inscriptions on sats in range starting with <START>.")]
start: Sat,
#[arg(help = "List inscriptions on sats in range ending with <END>.")]
end: Sat,
}

impl Inscribedsats {
pub(crate) fn run(self, options: Options) -> SubcommandResult {
let index = Index::open(&options)?;

if !index.has_sat_index() {
bail!("list requires index created with `--index-sats` flag");
}

index.update()?;

Ok(Box::new(index.get_inscription_ids_by_sat_range(self.start, self.end)?))
}
}

0 comments on commit df3e243

Please sign in to comment.