Skip to content

Commit

Permalink
Show 'genesis outpoint' and 'genesis address' on /inscription/ pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmart7t2 committed Feb 7, 2024
1 parent aa92dd8 commit f41c1b6
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ pub(crate) struct InscriptionEntry {
pub(crate) height: u32,
pub(crate) id: InscriptionId,
pub(crate) inscription_number: i32,
pub(crate) outpoint: OutPoint,
pub(crate) parent: Option<u32>,
pub(crate) sat: Option<Sat>,
pub(crate) sequence_number: u32,
Expand All @@ -271,6 +272,8 @@ pub(crate) type InscriptionEntryValue = (
Option<u64>, // sat
u32, // sequence number
u32, // timestamp
(u128, u128), // txid
u32, // vout
);

impl Entry for InscriptionEntry {
Expand All @@ -288,6 +291,8 @@ impl Entry for InscriptionEntry {
sat,
sequence_number,
timestamp,
txid,
vout,
): InscriptionEntryValue,
) -> Self {
Self {
Expand All @@ -296,6 +301,19 @@ impl Entry for InscriptionEntry {
height,
id: InscriptionId::load(id),
inscription_number,
outpoint: OutPoint {
txid: {
let low = txid.0.to_le_bytes();
let high = txid.1.to_le_bytes();
Txid::from_byte_array([
low[0], low[1], low[2], low[3], low[4], low[5], low[6], low[7], low[8], low[9], low[10],
low[11], low[12], low[13], low[14], low[15], high[0], high[1], high[2], high[3], high[4],
high[5], high[6], high[7], high[8], high[9], high[10], high[11], high[12], high[13],
high[14], high[15],
])
},
vout,
},
parent,
sat: sat.map(Sat),
sequence_number,
Expand All @@ -314,6 +332,20 @@ impl Entry for InscriptionEntry {
self.sat.map(Sat::n),
self.sequence_number,
self.timestamp,
{
let bytes = self.outpoint.txid.to_byte_array();
(
u128::from_le_bytes([
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15],
]),
u128::from_le_bytes([
bytes[16], bytes[17], bytes[18], bytes[19], bytes[20], bytes[21], bytes[22], bytes[23],
bytes[24], bytes[25], bytes[26], bytes[27], bytes[28], bytes[29], bytes[30], bytes[31],
]),
)
},
self.outpoint.vout,
)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
height: self.height,
id: inscription_id,
inscription_number,
outpoint: if unbound { unbound_outpoint() } else { new_satpoint.outpoint },
parent,
sat,
sequence_number,
Expand Down
15 changes: 15 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,19 @@ impl Server {
let info = Index::inscription_info(&index, query)?
.ok_or_not_found(|| format!("inscription {query}"))?;

let genesis_outpoint = info.entry.outpoint;
let genesis_output = if genesis_outpoint == OutPoint::null() || genesis_outpoint == unbound_outpoint() {
TxOut {value: 0, script_pubkey: ScriptBuf::new()}
} else {
index
.get_transaction(genesis_outpoint.txid)?
.ok_or_not_found(|| format!("output {genesis_outpoint}"))?
.output
.into_iter()
.nth(genesis_outpoint.vout as usize)
.ok_or_not_found(|| format!("output {genesis_outpoint}"))?
};

Ok(if accept_json {
Json(InscriptionJson {
inscription_id: info.entry.id,
Expand Down Expand Up @@ -1717,6 +1730,8 @@ impl Server {
children: info.children,
genesis_fee: info.entry.fee,
genesis_height: info.entry.height,
genesis_outpoint,
genesis_output,
inscription: info.inscription,
inscription_id: info.entry.id,
inscription_number: info.entry.inscription_number,
Expand Down
2 changes: 2 additions & 0 deletions src/templates/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub(crate) struct InscriptionHtml {
pub(crate) children: Vec<InscriptionId>,
pub(crate) genesis_fee: u64,
pub(crate) genesis_height: u32,
pub(crate) genesis_outpoint: OutPoint,
pub(crate) genesis_output: TxOut,
pub(crate) inscription: Inscription,
pub(crate) inscription_id: InscriptionId,
pub(crate) inscription_number: i32,
Expand Down
5 changes: 5 additions & 0 deletions templates/inscription.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ <h1>Inscription {{ self.inscription_number }}</h1>
<dd>{{ self.genesis_fee }}</dd>
<dt>genesis transaction</dt>
<dd><a class=monospace href=/tx/{{ self.inscription_id.txid }}>{{ self.inscription_id.txid }}</a></dd>
<dt>genesis outpoint</dt>
<dd><a class=monospace href=/output/{{ self.genesis_outpoint }}>{{ self.genesis_outpoint }}</a></dd>
%% if let Ok(address) = self.chain.address_from_script(&self.genesis_output.script_pubkey ) {
<dt>genesis address</dt><dd class=monospace>{{ address }}</dd>
%% }
<dt>location</dt>
<dd class=monospace>{{ self.satpoint }}</dd>
<dt>output</dt>
Expand Down

0 comments on commit f41c1b6

Please sign in to comment.