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

Display rune mintability #3324

Merged
merged 9 commits into from
Mar 19, 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
31 changes: 27 additions & 4 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
}
Expand Down
8 changes: 8 additions & 0 deletions src/templates/rune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::*;
pub struct RuneHtml {
pub entry: RuneEntry,
pub id: RuneId,
pub mintable: bool,
pub parent: Option<InscriptionId>,
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -69,6 +71,8 @@ mod tests {
<dd>1.000000001 %</dd>
<dt>mints</dt>
<dd>100</dd>
<dt>mintable</dt>
<dd>true</dd>
</dl>
</dd>
<dt>supply</dt>
Expand Down Expand Up @@ -109,6 +113,7 @@ mod tests {
timestamp: 0,
},
id: RuneId { block: 10, tx: 9 },
mintable: false,
parent: None,
},
"<h1>B•CGDENLQRQWDSLRUGSNLBTMFIJAV</h1>
Expand Down Expand Up @@ -165,6 +170,7 @@ mod tests {
timestamp: 0,
},
id: RuneId { block: 10, tx: 9 },
mintable: false,
parent: None,
},
"<h1>B•CGDENLQRQWDSLRUGSNLBTMFIJAV</h1>
Expand All @@ -190,6 +196,8 @@ mod tests {
<dd>none</dd>
<dt>mints</dt>
<dd>0</dd>
<dt>mintable</dt>
<dd>false</dd>
</dl>
</dd>
<dt>supply</dt>
Expand Down
2 changes: 2 additions & 0 deletions templates/rune.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ <h1>{{ self.entry.spaced_rune() }}</h1>
%% }
<dt>mints</dt>
<dd>{{ self.entry.mints }}</dd>
<dt>mintable</dt>
<dd>{{ self.mintable }}</dd>
</dl>
</dd>
%% } else {
Expand Down
1 change: 1 addition & 0 deletions tests/json_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 13 additions & 3 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -250,8 +252,12 @@ fn batch(
if let Some(mint) = mint {
mint_definition.push("<dd>".into());
mint_definition.push("<dl>".into());

let mut mintable = true;

mint_definition.push("<dt>deadline</dt>".into());
if let Some(deadline) = mint.deadline {
mintable &= block_time < deadline;
mint_definition.push(format!(
"<dd><time>{}</time></dd>",
ord::timestamp(deadline)
Expand All @@ -263,7 +269,8 @@ fn batch(
mint_definition.push("<dt>end</dt>".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!("<dd><a href=/block/{end}>{end}</a></dd>"));
} else {
mint_definition.push("<dd>none</dd>".into());
Expand All @@ -283,6 +290,9 @@ fn batch(
mint_definition.push("<dt>mints</dt>".into());
mint_definition.push("<dd>0</dd>".into());

mint_definition.push("<dt>mintable</dt>".into());
mint_definition.push(format!("<dd>{mintable}</dd>"));

mint_definition.push("</dl>".into());
mint_definition.push("</dd>".into());
} else {
Expand Down
Loading