From 737f414f9fed35ef5699b225cbc985ddbb7e1d7c Mon Sep 17 00:00:00 2001 From: raph Date: Tue, 19 Mar 2024 05:43:39 +0100 Subject: [PATCH] Display mintability on /rune (#3324) --- src/subcommand/server.rs | 31 +++++++++++++++++++++++++++---- src/templates/rune.rs | 8 ++++++++ templates/rune.html | 2 ++ tests/json_api.rs | 1 + tests/lib.rs | 16 +++++++++++++--- 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 76d0a4b3d0..c5963bf0e1 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -684,12 +684,35 @@ impl Server { .rune(rune)? .ok_or_not_found(|| format!("rune {rune}"))?; + let block_height = index.block_height()?.unwrap_or(Height(0)); + + let block_time: u32 = index + .block_time(block_height)? + .unix_timestamp() + .try_into() + .unwrap_or_default(); + + let mintable = entry + .mintable(Height(block_height.n() + 1), block_time) + .is_ok(); + Ok(if accept_json { - Json(api::Rune { entry, id, parent }).into_response() + Json(api::Rune { + entry, + id, + mintable, + parent, + }) + .into_response() } else { - RuneHtml { entry, id, parent } - .page(server_config) - .into_response() + RuneHtml { + entry, + id, + mintable, + parent, + } + .page(server_config) + .into_response() }) }) } diff --git a/src/templates/rune.rs b/src/templates/rune.rs index 50c452fcd9..91e62a0c14 100644 --- a/src/templates/rune.rs +++ b/src/templates/rune.rs @@ -4,6 +4,7 @@ use super::*; pub struct RuneHtml { pub entry: RuneEntry, pub id: RuneId, + pub mintable: bool, pub parent: Option, } @@ -40,6 +41,7 @@ mod tests { timestamp: 0, }, id: RuneId { block: 10, tx: 9 }, + mintable: true, parent: Some(InscriptionId { txid: Txid::all_zeros(), index: 0, @@ -69,6 +71,8 @@ mod tests {
1.000000001 %
mints
100
+
mintable
+
true
supply
@@ -109,6 +113,7 @@ mod tests { timestamp: 0, }, id: RuneId { block: 10, tx: 9 }, + mintable: false, parent: None, }, "

B•CGDENLQRQWDSLRUGSNLBTMFIJAV

@@ -165,6 +170,7 @@ mod tests { timestamp: 0, }, id: RuneId { block: 10, tx: 9 }, + mintable: false, parent: None, }, "

B•CGDENLQRQWDSLRUGSNLBTMFIJAV

@@ -190,6 +196,8 @@ mod tests {
none
mints
0
+
mintable
+
false
supply
diff --git a/templates/rune.html b/templates/rune.html index 38e249af0f..38532497f8 100644 --- a/templates/rune.html +++ b/templates/rune.html @@ -37,6 +37,8 @@

{{ self.entry.spaced_rune() }}

%% }
mints
{{ self.entry.mints }}
+
mintable
+
{{ self.mintable }}
%% } else { diff --git a/tests/json_api.rs b/tests/json_api.rs index c8675c4640..e4d7d61637 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -557,6 +557,7 @@ fn get_runes() { timestamp: 11, }, id: RuneId { block: 11, tx: 1 }, + mintable: false, parent: Some(InscriptionId { txid: a.inscribe.reveal, index: 0, diff --git a/tests/lib.rs b/tests/lib.rs index 45c681ae2b..f98827d12f 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -227,10 +227,12 @@ fn batch( bitcoin_rpc_server.mine_blocks(1); - let height = bitcoin_rpc_server.height(); + let block_height = bitcoin_rpc_server.height(); + let block_hash = *bitcoin_rpc_server.state().hashes.last().unwrap(); + let block_time = bitcoin_rpc_server.state().blocks[&block_hash].header.time; let id = RuneId { - block: u32::try_from(height).unwrap(), + block: u32::try_from(block_height).unwrap(), tx: 1, }; @@ -250,8 +252,12 @@ fn batch( if let Some(mint) = mint { mint_definition.push("
".into()); mint_definition.push("
".into()); + + let mut mintable = true; + mint_definition.push("
deadline
".into()); if let Some(deadline) = mint.deadline { + mintable &= block_time < deadline; mint_definition.push(format!( "
", ord::timestamp(deadline) @@ -263,7 +269,8 @@ fn batch( mint_definition.push("
end
".into()); if let Some(term) = mint.term { - let end = height + u64::from(term); + let end = block_height + u64::from(term); + mintable &= block_height + 1 < end; mint_definition.push(format!("
{end}
")); } else { mint_definition.push("
none
".into()); @@ -283,6 +290,9 @@ fn batch( mint_definition.push("
mints
".into()); mint_definition.push("
0
".into()); + mint_definition.push("
mintable
".into()); + mint_definition.push(format!("
{mintable}
")); + mint_definition.push("
".into()); mint_definition.push("
".into()); } else {