From 9bcb042aab455ed8b5f757ce9718c937b591f638 Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Mon, 21 Oct 2024 18:20:52 -0700 Subject: [PATCH 1/5] Show total child count on inscription page. --- src/api.rs | 1 + src/index.rs | 7 +++++-- src/subcommand/server.rs | 1 + src/templates/inscription.rs | 1 + templates/inscription.html | 2 +- tests/json_api.rs | 1 + 6 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/api.rs b/src/api.rs index 60ffe28f43..cbc92cad91 100644 --- a/src/api.rs +++ b/src/api.rs @@ -93,6 +93,7 @@ pub struct ChildInscriptions { pub struct Inscription { pub address: Option, pub charms: Vec, + pub child_count: u64, pub children: Vec, pub content_length: Option, pub content_type: Option, diff --git a/src/index.rs b/src/index.rs index c5b9f36e99..36e5e528d1 100644 --- a/src/index.rs +++ b/src/index.rs @@ -2034,9 +2034,11 @@ impl Index { .get(sequence_number + 1)? .map(|guard| InscriptionEntry::load(guard.value()).id); - let children = rtx + let all_children = rtx .open_multimap_table(SEQUENCE_NUMBER_TO_CHILDREN)? - .get(sequence_number)? + .get(sequence_number)?; + let child_count = all_children.len(); + let children = all_children .take(4) .map(|result| { result @@ -2107,6 +2109,7 @@ impl Index { }) .map(|address| address.to_string()), charms: Charm::charms(charms), + child_count, children, content_length: inscription.content_length(), content_type: inscription.content_type().map(|s| s.to_string()), diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 8cc7763f57..46c3297261 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -1668,6 +1668,7 @@ impl Server { charm.set(&mut acc); acc })), + child_count: info.child_count, children: info.children, fee: info.fee, height: info.height, diff --git a/src/templates/inscription.rs b/src/templates/inscription.rs index 3ff2f05d7b..0e611d40ca 100644 --- a/src/templates/inscription.rs +++ b/src/templates/inscription.rs @@ -4,6 +4,7 @@ use super::*; pub(crate) struct InscriptionHtml { pub(crate) chain: Chain, pub(crate) charms: u16, + pub(crate) child_count: u64, pub(crate) children: Vec, pub(crate) fee: u64, pub(crate) height: u32, diff --git a/templates/inscription.html b/templates/inscription.html index cbf3c5e646..f93076b32e 100644 --- a/templates/inscription.html +++ b/templates/inscription.html @@ -27,7 +27,7 @@

Inscription {{ self.number }}

%% } %% if !self.children.is_empty() { -
children
+
children ({{self.child_count}})
%% for id in &self.children { diff --git a/tests/json_api.rs b/tests/json_api.rs index dd6c0d16c2..2886291ff5 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -158,6 +158,7 @@ fn get_inscription() { api::Inscription { address: None, charms: vec![Charm::Coin, Charm::Uncommon], + child_count: 0, children: Vec::new(), content_length: Some(3), content_type: Some("text/plain;charset=utf-8".to_string()), From 675b285839c8ebf26364e8aca6a780bb4bc089b8 Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Mon, 21 Oct 2024 19:38:13 -0700 Subject: [PATCH 2/5] Fix unit tests. --- src/subcommand/server.rs | 2 +- src/templates/inscription.rs | 6 ++++-- templates/inscription.html | 2 +- tests/wallet/inscribe.rs | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 46c3297261..7e3ad433ac 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -5210,7 +5210,7 @@ next server.assert_response_regex( format!("/inscription/{parent_inscription_id}"), StatusCode::OK, - format!(".*Inscription 0.*
children
.*.*.*"), + format!(".*Inscription 0.*
children \\(1\\)
.*.*.*"), ); assert_eq!( diff --git a/src/templates/inscription.rs b/src/templates/inscription.rs index 0e611d40ca..924652fe03 100644 --- a/src/templates/inscription.rs +++ b/src/templates/inscription.rs @@ -269,6 +269,7 @@ mod tests { fn with_children() { assert_regex_match!( InscriptionHtml { + child_count: 2, // note that there is no invariant enforcement for accuracy children: vec![inscription_id(2), inscription_id(3)], fee: 1, inscription: inscription("text/plain;charset=utf-8", "HELLOWORLD"), @@ -285,7 +286,7 @@ mod tests {
-
children
+
children \\(2\\)
@@ -331,6 +332,7 @@ mod tests { fn with_paginated_children() { assert_regex_match!( InscriptionHtml { + child_count: 1, // note that there is no invariant enforcement for accuracy children: vec![inscription_id(2)], fee: 1, inscription: inscription("text/plain;charset=utf-8", "HELLOWORLD"), @@ -347,7 +349,7 @@ mod tests {
-
children
+
children \\(1\\)
diff --git a/templates/inscription.html b/templates/inscription.html index f93076b32e..db973876ff 100644 --- a/templates/inscription.html +++ b/templates/inscription.html @@ -27,7 +27,7 @@

Inscription {{ self.number }}

%% } %% if !self.children.is_empty() { -
children ({{self.child_count}})
+
children ({{ self.child_count }})
%% for id in &self.children { diff --git a/tests/wallet/inscribe.rs b/tests/wallet/inscribe.rs index d4adccfddd..da663ee34e 100644 --- a/tests/wallet/inscribe.rs +++ b/tests/wallet/inscribe.rs @@ -635,7 +635,7 @@ fn inscribe_with_parent_inscription_and_fee_rate() { ord.assert_response_regex( format!("/inscription/{}", child_output.parents.first().unwrap()), format!( - ".*
children
.*.*", + ".*
children \\(1\\)
.*
.*", child_output.inscriptions[0].id ), ); From c6616a7a877ce8584b3b0f379d7d8e75ebfd6b45 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 24 Oct 2024 13:41:11 -0700 Subject: [PATCH 3/5] fixasdf --- src/index.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.rs b/src/index.rs index 36e5e528d1..d1260359a1 100644 --- a/src/index.rs +++ b/src/index.rs @@ -2037,7 +2037,9 @@ impl Index { let all_children = rtx .open_multimap_table(SEQUENCE_NUMBER_TO_CHILDREN)? .get(sequence_number)?; + let child_count = all_children.len(); + let children = all_children .take(4) .map(|result| { From 0ab7067738f44ca81f8948017c43683e9bbb345a Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 24 Oct 2024 14:47:38 -0700 Subject: [PATCH 4/5] Amend --- src/templates/inscription.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/templates/inscription.rs b/src/templates/inscription.rs index 924652fe03..69354cc463 100644 --- a/src/templates/inscription.rs +++ b/src/templates/inscription.rs @@ -269,7 +269,7 @@ mod tests { fn with_children() { assert_regex_match!( InscriptionHtml { - child_count: 2, // note that there is no invariant enforcement for accuracy + child_count: 2, children: vec![inscription_id(2), inscription_id(3)], fee: 1, inscription: inscription("text/plain;charset=utf-8", "HELLOWORLD"), @@ -332,7 +332,7 @@ mod tests { fn with_paginated_children() { assert_regex_match!( InscriptionHtml { - child_count: 1, // note that there is no invariant enforcement for accuracy + child_count: 1, children: vec![inscription_id(2)], fee: 1, inscription: inscription("text/plain;charset=utf-8", "HELLOWORLD"), From 1e785e2840fbd542ee71641edcffb988461dd357 Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Thu, 24 Oct 2024 15:43:38 -0700 Subject: [PATCH 5/5] Move the child totalizer to the `all` link. --- src/subcommand/server.rs | 4 ++-- src/templates/inscription.rs | 8 ++++---- templates/inscription.html | 4 ++-- tests/wallet/inscribe.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 7e3ad433ac..8a58f85784 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -5210,7 +5210,7 @@ next server.assert_response_regex( format!("/inscription/{parent_inscription_id}"), StatusCode::OK, - format!(".*Inscription 0.*
children \\(1\\)
.*
.*.*"), + format!(".*Inscription 0.*
children
.*.*.*"), ); assert_eq!( @@ -5377,7 +5377,7 @@ next .*.* .*.* .*" ), ); diff --git a/src/templates/inscription.rs b/src/templates/inscription.rs index 69354cc463..b0d2a00871 100644 --- a/src/templates/inscription.rs +++ b/src/templates/inscription.rs @@ -286,14 +286,14 @@ mod tests {
-
children \\(2\\)
+
children
id
@@ -349,13 +349,13 @@ mod tests {
-
children \\(1\\)
+
children
id
diff --git a/templates/inscription.html b/templates/inscription.html index db973876ff..183481f996 100644 --- a/templates/inscription.html +++ b/templates/inscription.html @@ -27,7 +27,7 @@

Inscription {{ self.number }}

%% } %% if !self.children.is_empty() { -
children ({{ self.child_count }})
+
children
%% for id in &self.children { @@ -35,7 +35,7 @@

Inscription {{ self.number }}

%% }
%% } diff --git a/tests/wallet/inscribe.rs b/tests/wallet/inscribe.rs index da663ee34e..d4adccfddd 100644 --- a/tests/wallet/inscribe.rs +++ b/tests/wallet/inscribe.rs @@ -635,7 +635,7 @@ fn inscribe_with_parent_inscription_and_fee_rate() { ord.assert_response_regex( format!("/inscription/{}", child_output.parents.first().unwrap()), format!( - ".*
children \\(1\\)
.*.*", + ".*
children
.*
.*", child_output.inscriptions[0].id ), );