Skip to content

Commit

Permalink
Update ord list to include inscriptions and runes information (#3766)
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoni9n committed May 24, 2024
1 parent 034cb72 commit b0a26e2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
33 changes: 24 additions & 9 deletions src/subcommand/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@ use super::*;

#[derive(Debug, Parser)]
pub(crate) struct List {
#[arg(help = "List sats in <OUTPOINT>.")]
#[arg(help = "List information for <OUTPOINT>.")]
outpoint: OutPoint,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Output {
pub ranges: Option<Vec<Range>>,
pub address: Option<Address<NetworkUnchecked>>,
pub indexed: bool,
pub inscriptions: Vec<InscriptionId>,
pub runes: BTreeMap<SpacedRune, Pile>,
pub sat_ranges: Option<Vec<Range>>,
pub script_pubkey: String,
pub spent: bool,
pub transaction: String,
pub value: u64,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Range {
pub end: u64,
pub start: u64,
pub name: String,
pub offset: u64,
pub rarity: Rarity,
pub end: u64,
pub size: u64,
pub start: u64,
}

impl List {
Expand All @@ -37,13 +44,21 @@ impl List {
"output not found"
}

let ranges = index.list(self.outpoint)?;

let spent = index.is_output_spent(self.outpoint)?;
let (list, _txout) = match index.get_output_info(self.outpoint)? {
Some((output, txout)) => (output, txout),
None => return Ok(None),
};

Ok(Some(Box::new(Output {
spent,
ranges: ranges.map(output_ranges),
address: list.address,
indexed: list.indexed,
inscriptions: list.inscriptions,
runes: list.runes,
sat_ranges: list.sat_ranges.map(output_ranges),
script_pubkey: list.script_pubkey,
spent: list.spent,
transaction: list.transaction,
value: list.value,
})))
}
}
Expand Down
11 changes: 9 additions & 2 deletions tests/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@ fn output_found() {
assert_eq!(
output,
Output {
ranges: Some(vec![Range {
address: None,
indexed: true,
inscriptions: vec![],
runes: BTreeMap::new(),
sat_ranges: Some(vec![Range {
end: 50 * COIN_VALUE,
name: "nvtdijuwxlp".into(),
offset: 0,
rarity: "mythic".parse().unwrap(),
size: 50 * COIN_VALUE,
start: 0,
}]),
}]),
script_pubkey: "OP_PUSHBYTES_65 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f OP_CHECKSIG".to_string(),
spent: false,
transaction: "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b".to_string(),
value: 5000000000,
}
);
}
Expand Down

0 comments on commit b0a26e2

Please sign in to comment.