Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inscriptions to address page #3843

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,23 @@ impl Index {
)
}

pub fn get_inscriptions_for_outputs(
&self,
outpoints: &Vec<OutPoint>,
) -> Result<Vec<InscriptionId>> {
let mut inscriptions = Vec::new();
for outpoint in outpoints {
inscriptions.extend(
self
.get_inscriptions_on_output_with_satpoints(*outpoint)?
.iter()
.map(|(_satpoint, inscription_id)| *inscription_id),
);
}

Ok(inscriptions)
}

pub fn get_transaction(&self, txid: Txid) -> Result<Option<Transaction>> {
if txid == self.genesis_block_coinbase_txid {
return Ok(Some(self.genesis_block_coinbase_transaction.clone()));
Expand Down
3 changes: 3 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,8 @@ impl Server {

let sat_balance = index.get_sat_balances_for_outputs(&outputs)?;

let inscriptions = index.get_inscriptions_for_outputs(&outputs)?;

let runes_balances = index.get_aggregated_rune_balances_for_outputs(&outputs)?;

Ok(if accept_json {
Expand All @@ -872,6 +874,7 @@ impl Server {
AddressHtml {
address,
outputs,
inscriptions,
sat_balance,
runes_balances,
}
Expand Down
9 changes: 9 additions & 0 deletions src/templates/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::*;
pub(crate) struct AddressHtml {
pub(crate) address: Address,
pub(crate) outputs: Vec<OutPoint>,
pub(crate) inscriptions: Vec<InscriptionId>,
pub(crate) sat_balance: u64,
pub(crate) runes_balances: Vec<(SpacedRune, Decimal, Option<char>)>,
}
Expand All @@ -25,6 +26,7 @@ mod tests {
.require_network(Network::Bitcoin)
.unwrap(),
outputs: vec![outpoint(1), outpoint(2)],
inscriptions: vec![inscription_id(1)],
sat_balance: 99,
runes_balances: vec![
(
Expand Down Expand Up @@ -68,6 +70,13 @@ mod tests {
assert_regex_match!(address_html, expected_pattern);
}

#[test]
fn test_inscriptions_rendering() {
let address_html = setup();
let expected_pattern = r#".*<dt>inscriptions</dt>\n\s*<dd class=thumbnails>.*<a href=/inscription/1{64}i1><iframe .* src=/preview/1{64}i1></iframe></a>.*</dd>.*"#;
assert_regex_match!(address_html, expected_pattern);
}

#[test]
fn test_runes_balances_rendering() {
let address_html = setup();
Expand Down
8 changes: 8 additions & 0 deletions templates/address.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ <h1>Address {{ self.address }}</h1>
<dl>
<dt>sat balance</dt>
<dd>{{ self.sat_balance }}</dd>
%% if !self.inscriptions.is_empty() {
<dt>inscriptions</dt>
<dd class=thumbnails>
%% for inscription in &self.inscriptions {
{{Iframe::thumbnail(*inscription)}}
%% }
</dd>
%% }
<dt>runes balances</dt>
%% for (rune, decimal, symbol) in self.runes_balances.iter() {
%% if let Some(symbol) = symbol {
Expand Down
47 changes: 47 additions & 0 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,53 @@ fn address_page_shows_aggregated_runes_balance() {
);
}

#[test]
fn address_page_shows_aggregated_inscriptions() {
let core = mockcore::builder().network(Network::Regtest).build();
let ord =
TestServer::spawn_with_args(&core, &["--index-runes", "--index-addresses", "--regtest"]);

create_wallet(&core, &ord);

let (inscription_id_1, _reveal) = inscribe(&core, &ord);

let address = "bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw";

CommandBuilder::new(format!(
"--chain regtest --index-runes wallet send --fee-rate 1 {address} {inscription_id_1}",
))
.core(&core)
.ord(&ord)
.stdout_regex(".*")
.run_and_deserialize_output::<Output>();

core.mine_blocks(1);

let (inscription_id_2, _reveal) = inscribe(&core, &ord);

CommandBuilder::new(format!(
"--chain regtest --index-runes wallet send --fee-rate 1 {address} {inscription_id_2}",
))
.core(&core)
.ord(&ord)
.stdout_regex(".*")
.run_and_deserialize_output::<Output>();

core.mine_blocks(1);

ord.assert_response_regex(
format!("/address/{address}"),
r".*
<dl>.*
<dt>inscriptions</dt>
<dd class=thumbnails>
<a href=/inscription/[[:xdigit:]]{64}i\d><iframe .* src=/preview/[[:xdigit:]]{64}i\d></iframe></a>
<a href=/inscription/[[:xdigit:]]{64}i\d><iframe .* src=/preview/[[:xdigit:]]{64}i\d></iframe></a>
</dd>.*"
,
);
}

#[test]
fn inscription_page() {
let core = mockcore::spawn();
Expand Down
Loading