diff --git a/src/index.rs b/src/index.rs index b5e035b668..b1832b9c0b 100644 --- a/src/index.rs +++ b/src/index.rs @@ -2358,6 +2358,44 @@ impl Index { Ok(acc) } + pub(crate) fn get_output_recursive( + &self, + outpoint: OutPoint, + ) -> Result> { + 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> { let sat_ranges = self.list(outpoint)?; diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 33748cb824..141aa1d28c 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -665,19 +665,12 @@ impl Server { Path(outpoint): Path, ) -> 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(), ) })