Merge 75bca03d59e2a2e88db95f39e8335e0a9716984e into 694e48422847771b9d3d1948dc796830986003f2

This commit is contained in:
buray 2026-05-21 16:42:48 +02:00 committed by GitHub
commit 96c6f9efd4
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")]