Merge 42985e5c725da0f8de3fd03b67cb63c254c13eb6 into 3ed6288a658ca03164d3ef16d31d3f6a1dcce778

This commit is contained in:
buray 2026-04-08 09:00:16 +00:00 committed by GitHub
commit 088b25f555
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 3 deletions

View File

@ -8,6 +8,7 @@ license = { workspace = true }
workspace = true
[dependencies]
chrono = { workspace = true }
nssa_core = { workspace = true, optional = true, features = ["host"] }
nssa = { workspace = true, optional = true }
common = { workspace = true, optional = true }

View File

@ -303,11 +303,12 @@ pub struct Nullifier(
);
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
pub struct ValidityWindow(pub (Option<BlockId>, Option<BlockId>));
#[serde(transparent)]
pub struct ValidityWindow<T = BlockId>(pub (Option<T>, Option<T>));
impl Display for ValidityWindow {
impl<T: Display> Display for ValidityWindow<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.0 {
match &self.0 {
(Some(start), Some(end)) => write!(f, "[{start}, {end})"),
(Some(start), None) => write!(f, "[{start}, \u{221e})"),
(None, Some(end)) => write!(f, "(-\u{221e}, {end})"),
@ -316,6 +317,26 @@ impl Display for ValidityWindow {
}
}
impl ValidityWindow<BlockId> {
/// Convert to a UTC datetime window given a block-to-timestamp mapping.
pub fn to_datetime_window<F>(
&self,
block_to_timestamp_ms: F,
) -> ValidityWindow<chrono::DateTime<chrono::Utc>>
where
F: Fn(BlockId) -> Option<u64>,
{
let convert = |id: &BlockId| {
block_to_timestamp_ms(*id)
.and_then(|ms| chrono::DateTime::from_timestamp_millis(ms as i64))
};
ValidityWindow((
self.0.0.as_ref().and_then(&convert),
self.0.1.as_ref().and_then(&convert),
))
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
pub struct CommitmentSetDigest(
#[serde(with = "base64::arr")]