42 lines
1.2 KiB
Rust
Raw Normal View History

2026-03-20 18:05:48 -03:00
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
2026-03-30 23:50:54 -03:00
type Instruction = nssa_core::Timestamp;
2026-03-20 18:05:48 -03:00
fn main() {
let (
ProgramInput {
pre_states,
2026-03-30 23:50:54 -03:00
instruction: timestamp,
2026-03-20 18:05:48 -03:00
},
instruction_words,
) = read_nssa_inputs::<Instruction>();
let Ok([pre]) = <[_; 1]>::try_from(pre_states) else {
return;
};
let account_pre = &pre.account;
2026-03-30 23:50:54 -03:00
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"),
);
2026-03-20 18:05:48 -03:00
let mut account_post = account_pre.clone();
2026-03-30 23:50:54 -03:00
let next_block_id = block_id
2026-03-20 18:05:48 -03:00
.checked_add(1)
2026-03-30 23:50:54 -03:00
.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
2026-03-20 18:05:48 -03:00
.to_vec()
.try_into()
2026-03-30 23:50:54 -03:00
.expect("16 bytes should fit in account data");
2026-03-20 18:05:48 -03:00
let post = AccountPostState::new(account_post);
write_nssa_outputs(instruction_words, vec![pre], vec![post]);
}