From 394221718d14a5efd86b08e03e7be64e686db960 Mon Sep 17 00:00:00 2001 From: gmart7t2 <49558347+gmart7t2@users.noreply.github.com> Date: Thu, 23 May 2024 13:47:52 -0300 Subject: [PATCH 1/3] Remove duplicate example (#3776) --- docs/src/inscriptions/recursion.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/docs/src/inscriptions/recursion.md b/docs/src/inscriptions/recursion.md index 98a1a8238a..ea901eda9b 100644 --- a/docs/src/inscriptions/recursion.md +++ b/docs/src/inscriptions/recursion.md @@ -176,19 +176,3 @@ Examples "id":"17541f6adf6eb160d52bc6eb0a3546c7c1d2adfe607b1a3cddc72cc0619526adi0" } ``` - -- `/r/children/60bcf821240064a9c55225c4f01711b0ebbcab39aa3fafeefe4299ab158536fai0/49`: - -```json -{ - "ids":[ - "7cd66b8e3a63dcd2fada917119830286bca0637267709d6df1ca78d98a1b4487i4900", - "7cd66b8e3a63dcd2fada917119830286bca0637267709d6df1ca78d98a1b4487i4901", - ... - "7cd66b8e3a63dcd2fada917119830286bca0637267709d6df1ca78d98a1b4487i4935", - "7cd66b8e3a63dcd2fada917119830286bca0637267709d6df1ca78d98a1b4487i4936" - ], - "more":false, - "page":49 -} -``` From abd7f6cc00ada499fc3b7ee2e80423bfafea5c3e Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 23 May 2024 13:46:40 -0700 Subject: [PATCH 2/3] Add /inscription/:query/:child_number route (#3777) --- src/index.rs | 17 ++++++ src/subcommand/server.rs | 115 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 129 insertions(+), 3 deletions(-) diff --git a/src/index.rs b/src/index.rs index 29ca0c4e33..162a37a347 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1884,6 +1884,7 @@ impl Index { pub(crate) fn inscription_info( &self, query: query::Inscription, + child: Option, ) -> Result, Inscription)>> { let rtx = self.database.begin_read()?; @@ -1908,6 +1909,22 @@ impl Index { return Ok(None); }; + let sequence_number = if let Some(child) = child { + let Some(child) = rtx + .open_multimap_table(SEQUENCE_NUMBER_TO_CHILDREN)? + .get(sequence_number)? + .nth(child) + .transpose()? + .map(|child| child.value()) + else { + return Ok(None); + }; + + child + } else { + sequence_number + }; + let sequence_number_to_inscription_entry = rtx.open_table(SEQUENCE_NUMBER_TO_INSCRIPTION_ENTRY)?; diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index c2bc97eb0a..f1ab8e2c16 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -203,6 +203,10 @@ impl Server { .route("/feed.xml", get(Self::feed)) .route("/input/:block/:transaction/:input", get(Self::input)) .route("/inscription/:inscription_query", get(Self::inscription)) + .route( + "/inscription/:inscription_query/:child", + get(Self::inscription_child), + ) .route("/inscriptions", get(Self::inscriptions)) .route("/inscriptions", post(Self::inscriptions_json)) .route("/inscriptions/:page", get(Self::inscriptions_paginated)) @@ -1588,8 +1592,27 @@ impl Server { async fn inscription( Extension(server_config): Extension>, Extension(index): Extension>, + AcceptJson(accept_json): AcceptJson, Path(DeserializeFromStr(query)): Path>, + ) -> ServerResult { + Self::inscription_inner(server_config, &index, accept_json, query, None).await + } + + async fn inscription_child( + Extension(server_config): Extension>, + Extension(index): Extension>, AcceptJson(accept_json): AcceptJson, + Path((DeserializeFromStr(query), child)): Path<(DeserializeFromStr, usize)>, + ) -> ServerResult { + Self::inscription_inner(server_config, &index, accept_json, query, Some(child)).await + } + + async fn inscription_inner( + server_config: Arc, + index: &Index, + accept_json: bool, + query: query::Inscription, + child: Option, ) -> ServerResult { task::block_in_place(|| { if let query::Inscription::Sat(_) = query { @@ -1599,7 +1622,7 @@ impl Server { } let (info, txout, inscription) = index - .inscription_info(query)? + .inscription_info(query, child)? .ok_or_not_found(|| format!("inscription {query}"))?; Ok(if accept_json { @@ -1643,7 +1666,7 @@ impl Server { for inscription in inscriptions { let query = query::Inscription::Id(inscription); let (info, _, _) = index - .inscription_info(query)? + .inscription_info(query, None)? .ok_or_not_found(|| format!("inscription {query}"))?; response.push(info); @@ -2305,7 +2328,12 @@ mod tests { regex: impl AsRef, ) { let response = self.get(path); - assert_eq!(response.status(), status); + assert_eq!( + response.status(), + status, + "response: {}", + response.text().unwrap() + ); assert_regex_match!(response.text().unwrap(), regex.as_ref()); } @@ -5251,6 +5279,87 @@ next ); } + #[test] + fn inscription_child() { + let server = TestServer::builder().chain(Chain::Regtest).build(); + server.mine_blocks(1); + + let parent_txid = server.core.broadcast_tx(TransactionTemplate { + inputs: &[(1, 0, 0, inscription("text/plain", "hello").to_witness())], + ..default() + }); + + server.mine_blocks(2); + + let parent_inscription_id = InscriptionId { + txid: parent_txid, + index: 0, + }; + + let child_txid = server.core.broadcast_tx(TransactionTemplate { + inputs: &[ + ( + 2, + 0, + 0, + Inscription { + content_type: Some("text/plain".into()), + body: Some("hello".into()), + parents: vec![parent_inscription_id.value()], + ..default() + } + .to_witness(), + ), + ( + 3, + 0, + 0, + Inscription { + content_type: Some("text/plain".into()), + body: Some("hello".into()), + parents: vec![parent_inscription_id.value()], + ..default() + } + .to_witness(), + ), + (2, 1, 0, Default::default()), + ], + ..default() + }); + + server.mine_blocks(1); + + let child0 = InscriptionId { + txid: child_txid, + index: 0, + }; + + server.assert_response_regex( + format!("/inscription/{parent_inscription_id}/0"), + StatusCode::OK, + format!( + ".*Inscription 1.* +.*
id
+.*
{child0}
.*" + ), + ); + + let child1 = InscriptionId { + txid: child_txid, + index: 1, + }; + + server.assert_response_regex( + format!("/inscription/{parent_inscription_id}/1"), + StatusCode::OK, + format!( + ".*Inscription -1.* +.*
id
+.*
{child1}
.*" + ), + ); + } + #[test] fn inscription_with_parent_page() { let server = TestServer::builder().chain(Chain::Regtest).build(); From aba1d7a079f970aeff1d972c6e38ee0899c68195 Mon Sep 17 00:00:00 2001 From: nine <118634361+cryptoni9n@users.noreply.github.com> Date: Fri, 24 May 2024 07:11:27 -0400 Subject: [PATCH 3/3] Add mint progress field to rune.html (#3748) --- src/index/entry.rs | 9 +++++++++ src/subcommand/server.rs | 2 ++ src/templates/rune.rs | 2 ++ templates/rune.html | 2 ++ tests/lib.rs | 14 ++++++++++++-- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/index/entry.rs b/src/index/entry.rs index a908d73595..330c2541cf 100644 --- a/src/index/entry.rs +++ b/src/index/entry.rs @@ -92,6 +92,15 @@ impl RuneEntry { .unwrap_or_default() } + pub fn max_supply(&self) -> u128 { + self.premine + + self.terms.and_then(|terms| terms.cap).unwrap_or_default() + * self + .terms + .and_then(|terms| terms.amount) + .unwrap_or_default() + } + pub fn pile(&self, amount: u128) -> Pile { Pile { amount, diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index f1ab8e2c16..e6e168f2a1 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -3007,6 +3007,8 @@ mod tests {
no
supply
340282366920938463463374607431768211455\u{A0}%
+
mint progress
+
100%
premine
340282366920938463463374607431768211455\u{A0}%
premine percentage
diff --git a/src/templates/rune.rs b/src/templates/rune.rs index c4333315fa..b85c477915 100644 --- a/src/templates/rune.rs +++ b/src/templates/rune.rs @@ -85,6 +85,8 @@ mod tests {
supply
100.123456889\u{A0}%
+
mint progress
+
99.01%
premine
0.123456789\u{A0}%
premine percentage
diff --git a/templates/rune.html b/templates/rune.html index 98a9b1ac00..a45aecaff1 100644 --- a/templates/rune.html +++ b/templates/rune.html @@ -52,6 +52,8 @@

{{ self.entry.spaced_rune }}

%% }
supply
{{ self.entry.pile(self.entry.supply()) }}
+
mint progress
+
{{ Decimal { value: ((self.entry.supply() as f64 / self.entry.max_supply() as f64) * 10000.0) as u128, scale: 2 } }}%
premine
{{ self.entry.pile(self.entry.premine) }}
premine percentage
diff --git a/tests/lib.rs b/tests/lib.rs index 8c53a04cd3..6afc3cefe1 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -12,8 +12,8 @@ use { executable_path::executable_path, mockcore::TransactionTemplate, ord::{ - api, chain::Chain, outgoing::Outgoing, subcommand::runes::RuneInfo, wallet::batch, - InscriptionId, RuneEntry, + api, chain::Chain, decimal::Decimal, outgoing::Outgoing, subcommand::runes::RuneInfo, + wallet::batch, InscriptionId, RuneEntry, }, ordinals::{ Artifact, Charm, Edict, Pile, Rarity, Rune, RuneId, Runestone, Sat, SatPoint, SpacedRune, @@ -321,6 +321,14 @@ fn batch(core: &mockcore::Handle, ord: &TestServer, batchfile: batch::File) -> E let RuneId { block, tx } = id; + let supply_int = supply.to_integer(divisibility).unwrap(); + let premine_int = premine.to_integer(divisibility).unwrap(); + + let mint_progress = Decimal { + value: ((premine_int as f64 / supply_int as f64) * 10000.0) as u128, + scale: 2, + }; + ord.assert_response_regex( format!("/rune/{rune}"), format!( @@ -334,6 +342,8 @@ fn batch(core: &mockcore::Handle, ord: &TestServer, batchfile: batch::File) -> E {}
supply
{premine} {symbol}
+
mint progress
+
{mint_progress}%
premine
{premine} {symbol}
premine percentage