From f0c311183433691089fb0b4ffa91b1517a92cd13 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 23 Dec 2022 13:54:23 -0800 Subject: [PATCH] Display inscription content on /inscriptions --- src/index.rs | 16 +--------- src/subcommand/server.rs | 4 +-- .../server/templates/inscriptions.rs | 32 +++++-------------- templates/inscriptions.html | 13 +++----- tests/server.rs | 18 ++++------- 5 files changed, 21 insertions(+), 62 deletions(-) diff --git a/src/index.rs b/src/index.rs index f6fbbbeb47..c76c780a72 100644 --- a/src/index.rs +++ b/src/index.rs @@ -614,21 +614,7 @@ impl Index { ) } - pub(crate) fn get_latest_inscription_ids(&self, n: usize) -> Result> { - Ok( - self - .database - .begin_read()? - .open_table(INSCRIPTION_NUMBER_TO_INSCRIPTION_ID)? - .iter()? - .rev() - .map(|(_n, id)| decode_inscription_id(*id)) - .take(n) - .collect(), - ) - } - - pub(crate) fn get_latest_graphical_inscriptions( + pub(crate) fn get_latest_inscriptions( &self, n: usize, ) -> Result> { diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 92335f262e..1978370051 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -432,7 +432,7 @@ impl Server { .blocks(100) .map_err(|err| ServerError::Internal(anyhow!("error getting blocks: {err}")))?, index - .get_latest_graphical_inscriptions(8) + .get_latest_inscriptions(8) .map_err(|err| ServerError::Internal(anyhow!("error getting inscriptions: {err}")))?, ) .page( @@ -743,7 +743,7 @@ impl Server { Ok( InscriptionsHtml { inscriptions: index - .get_latest_inscription_ids(100) + .get_latest_inscriptions(100) .map_err(|err| ServerError::Internal(anyhow!("error getting inscriptions: {err}")))?, } .page( diff --git a/src/subcommand/server/templates/inscriptions.rs b/src/subcommand/server/templates/inscriptions.rs index c82ad0f69c..2bd2081500 100644 --- a/src/subcommand/server/templates/inscriptions.rs +++ b/src/subcommand/server/templates/inscriptions.rs @@ -2,7 +2,7 @@ use super::*; #[derive(Boilerplate)] pub(crate) struct InscriptionsHtml { - pub(crate) inscriptions: Vec, + pub(crate) inscriptions: Vec<(Inscription, InscriptionId)>, } impl PageContent for InscriptionsHtml { @@ -19,32 +19,16 @@ mod tests { fn inscriptions() { pretty_assert_eq!( InscriptionsHtml { - inscriptions: vec![ - InscriptionId::from_str("ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc").unwrap(), - InscriptionId::from_str("ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc").unwrap(), - InscriptionId::from_str("ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc").unwrap(), - ] + inscriptions: vec![( + inscription("text/plain;charset=utf-8", "HELLOWORLD"), + txid(1) + )], }.to_string(), "

Inscriptions

- - + ".unindent() ); } diff --git a/templates/inscriptions.html b/templates/inscriptions.html index 4da294c95c..f2c1abe985 100644 --- a/templates/inscriptions.html +++ b/templates/inscriptions.html @@ -1,11 +1,6 @@

Inscriptions

- - + diff --git a/tests/server.rs b/tests/server.rs index 423e8ab8fd..91b19ff3ca 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -258,14 +258,11 @@ fn inscriptions_page() { TestServer::spawn_with_args(&rpc_server, &[]).assert_response_regex( "/inscriptions", &format!( - ".*

Inscriptions

.* -.*", + ".*

Inscriptions

+ +.*", ), ); } @@ -278,10 +275,7 @@ fn inscriptions_page_is_sorted() { for i in 0..8 { let id = create_inscription(&rpc_server, &format!("{i}.png")); - inscriptions.insert_str( - 0, - &format!(".*.*"), - ); + inscriptions.insert_str(0, &format!(".*.*")); } TestServer::spawn_with_args(&rpc_server, &[])