refactor so that indexer checks clock constraints

This commit is contained in:
Sergio Chouhy
2026-04-02 18:30:10 -03:00
parent 6a467da3b1
commit b525447e2d
30 changed files with 141 additions and 90 deletions
+11
View File
@@ -0,0 +1,11 @@
[package]
name = "clock_core"
version = "0.1.0"
edition = "2024"
license = { workspace = true }
[lints]
workspace = true
[dependencies]
nssa_core.workspace = true
+49
View File
@@ -0,0 +1,49 @@
//! Core data structures and constants for the Clock Program.
use nssa_core::{Timestamp, account::AccountId};
/// The instruction type for the Clock Program. The sequencer passes the current block timestamp.
pub type Instruction = Timestamp;
pub const CLOCK_01_PROGRAM_ACCOUNT_ID: AccountId =
AccountId::new(*b"/LEZ/ClockProgramAccount/0000001");
pub const CLOCK_10_PROGRAM_ACCOUNT_ID: AccountId =
AccountId::new(*b"/LEZ/ClockProgramAccount/0000010");
pub const CLOCK_50_PROGRAM_ACCOUNT_ID: AccountId =
AccountId::new(*b"/LEZ/ClockProgramAccount/0000050");
/// All clock program account ID int the order expected by the clock program
pub const CLOCK_PROGRAM_ACCOUNT_IDS: [AccountId; 3] = [
CLOCK_01_PROGRAM_ACCOUNT_ID,
CLOCK_10_PROGRAM_ACCOUNT_ID,
CLOCK_50_PROGRAM_ACCOUNT_ID,
];
/// The data stored in a clock account: `[block_id: u64 LE | timestamp: u64 LE]`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ClockAccountData {
pub block_id: u64,
pub timestamp: Timestamp,
}
impl ClockAccountData {
#[must_use]
pub fn to_bytes(self) -> [u8; 16] {
let mut data = [0_u8; 16];
data[..8].copy_from_slice(&self.block_id.to_le_bytes());
data[8..].copy_from_slice(&self.timestamp.to_le_bytes());
data
}
#[must_use]
pub fn from_bytes(bytes: &[u8; 16]) -> Self {
let block_id = u64::from_le_bytes(bytes[..8].try_into().unwrap());
let timestamp = u64::from_le_bytes(bytes[8..].try_into().unwrap());
Self {
block_id,
timestamp,
}
}
}