add timestamp to clock

This commit is contained in:
Sergio Chouhy
2026-03-30 23:50:54 -03:00
parent 3324bcf391
commit 7078e403ed
37 changed files with 126 additions and 87 deletions
+15 -11
View File
@@ -1,12 +1,12 @@
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
type Instruction = ();
type Instruction = nssa_core::Timestamp;
fn main() {
let (
ProgramInput {
pre_states,
instruction: (),
instruction: timestamp,
},
instruction_words,
) = read_nssa_inputs::<Instruction>();
@@ -16,20 +16,24 @@ fn main() {
};
let account_pre = &pre.account;
let account_pre_data = account_pre.data.clone();
let clock =
u64::from_le_bytes(account_pre_data.into_inner().try_into().expect(
"Block context program account data should be the LE encoding of a u64 integer",
));
let account_pre_data = account_pre.data.clone().into_inner();
let block_id = u64::from_le_bytes(
account_pre_data[..8]
.try_into()
.expect("Block context program account data should contain a LE-encoded block_id u64"),
);
let mut account_post = account_pre.clone();
account_post.data = clock
let next_block_id = block_id
.checked_add(1)
.expect("Next timestap should be within u64 boundaries")
.to_le_bytes()
.expect("Next block id should be within u64 boundaries");
let mut data = [0u8; 16];
data[..8].copy_from_slice(&next_block_id.to_le_bytes());
data[8..].copy_from_slice(&timestamp.to_le_bytes());
account_post.data = data
.to_vec()
.try_into()
.expect("u64 byte length should fit in account data");
.expect("16 bytes should fit in account data");
let post = AccountPostState::new(account_post);