Skip to content

Commit

Permalink
Amend
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph committed Dec 23, 2024
1 parent 72b833b commit 34eede2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
38 changes: 38 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,44 @@ impl Index {
Ok(acc)
}

pub(crate) fn get_output_recursive(
&self,
outpoint: OutPoint,
) -> Result<Option<api::OutputRecursive>> {
let sat_ranges = self.list(outpoint)?;

let inscriptions = self.get_inscriptions_for_output(outpoint)?;

let runes = self.get_rune_balances_for_output(outpoint)?;

let Some(utxo_entry) = self
.database
.begin_read()?
.open_table(OUTPOINT_TO_UTXO_ENTRY)?
.get(&outpoint.store())?
else {
return Ok(None);
};

let entry = utxo_entry.value().parse(self);
let script_pubkey = ScriptBuf::from_bytes(entry.script_pubkey().to_vec());
let value = entry.total_value();

Ok(Some(api::OutputRecursive {
address: self
.settings
.chain()
.address_from_script(&script_pubkey)
.ok()
.map(|address| address.as_unchecked().clone()),
inscriptions,
runes,
sat_ranges,
script_pubkey,
value,
}))
}

pub(crate) fn get_output_info(&self, outpoint: OutPoint) -> Result<Option<(api::Output, TxOut)>> {
let sat_ranges = self.list(outpoint)?;

Expand Down
17 changes: 5 additions & 12 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,19 +665,12 @@ impl Server {
Path(outpoint): Path<OutPoint>,
) -> ServerResult {
task::block_in_place(|| {
let (info, _) = index
.get_output_info(outpoint)?
.ok_or_not_found(|| format!("output {outpoint}"))?;

Ok(
Json(api::OutputRecursive {
address: info.address,
inscriptions: info.inscriptions,
runes: info.runes,
sat_ranges: info.sat_ranges,
script_pubkey: info.script_pubkey,
value: info.value,
})
Json(
index
.get_output_recursive(outpoint)?
.ok_or_not_found(|| format!("output {outpoint}"))?,
)
.into_response(),
)
})
Expand Down

0 comments on commit 34eede2

Please sign in to comment.