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 locked rune unlock time on /rune #4192

Merged
merged 2 commits into from
Jan 24, 2025
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
18 changes: 11 additions & 7 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1789,13 +1789,17 @@ impl Index {
.with_context(|| format!("current {current} height is greater than sat height {height}"))?;

Ok(Blocktime::Expected(
Utc::now()
.round_subsecs(0)
.checked_add_signed(
chrono::Duration::try_seconds(10 * 60 * i64::from(expected_blocks))
.context("timestamp out of range")?,
)
.context("timestamp out of range")?,
if self.settings.chain() == Chain::Regtest {
DateTime::default()
} else {
Utc::now()
}
.round_subsecs(0)
.checked_add_signed(
chrono::Duration::try_seconds(10 * 60 * i64::from(expected_blocks))
.context("timestamp out of range")?,
)
.context("timestamp out of range")?,
))
}

Expand Down
19 changes: 12 additions & 7 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,13 +849,15 @@ impl Server {
return Ok(if accept_json {
StatusCode::NOT_FOUND.into_response()
} else {
let unlock = if let Some(height) = rune.unlock_height(server_config.chain.network()) {
Some((height, index.block_time(height)?.timestamp()))
} else {
None
};

(
StatusCode::NOT_FOUND,
RuneNotFoundHtml {
rune,
unlock_height: rune.unlock_height(server_config.chain.network()),
}
.page(server_config),
RuneNotFoundHtml { rune, unlock }.page(server_config),
)
.into_response()
});
Expand Down Expand Up @@ -3295,7 +3297,10 @@ mod tests {
StatusCode::NOT_FOUND,
RuneNotFoundHtml {
rune: Rune(0),
unlock_height: Some(Height(209999)),
unlock: Some((
Height(209999),
DateTime::from_timestamp(125998800, 0).unwrap(),
)),
},
);
}
Expand All @@ -3314,7 +3319,7 @@ mod tests {
StatusCode::NOT_FOUND,
RuneNotFoundHtml {
rune: Rune(Rune::RESERVED),
unlock_height: None,
unlock: None,
},
);
}
Expand Down
10 changes: 6 additions & 4 deletions src/templates/rune_not_found.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::*;
#[derive(Boilerplate, Debug, PartialEq, Serialize)]
pub struct RuneNotFoundHtml {
pub rune: Rune,
pub unlock_height: Option<Height>,
pub unlock: Option<(Height, DateTime<Utc>)>,
}

impl PageContent for RuneNotFoundHtml {
Expand All @@ -21,12 +21,14 @@ mod tests {
assert_regex_match!(
RuneNotFoundHtml {
rune: Rune(u128::MAX),
unlock_height: Some(Height(111)),
unlock: Some((Height(111), DateTime::default())),
},
"<h1>BCGDENLQRQWDSLRUGSNLBTMFIJAV</h1>
r"<h1>BCGDENLQRQWDSLRUGSNLBTMFIJAV</h1>
<dl>
<dt>unlock height</dt>
<dd>111</dd>
<dt>unlock time</dt>
<dd><time>1970-01-01 00:00:00 UTC</time> \(expected\)</dd>
<dt>reserved</dt>
<dd>false</dd>
</dl>
Expand All @@ -39,7 +41,7 @@ mod tests {
assert_regex_match!(
RuneNotFoundHtml {
rune: Rune(Rune::RESERVED),
unlock_height: None,
unlock: None,
},
"<h1>AAAAAAAAAAAAAAAAAAAAAAAAAAA</h1>
<dl>
Expand Down
6 changes: 4 additions & 2 deletions templates/rune-not-found.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<h1>{{ self.rune }}</h1>
<dl>
%% if let Some(unlock_height) = self.unlock_height {
%% if let Some((height, time)) = self.unlock {
<dt>unlock height</dt>
<dd>{{ unlock_height }}</dd>
<dd>{{ height }}</dd>
<dt>unlock time</dt>
<dd><time>{{ time }}</time> (expected)</dd>
<dt>reserved</dt>
<dd>false</dd>
%% } else {
Expand Down
Loading