mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-08-26 20:01:16 +00:00
add timestamp to clock
This commit is contained in:
@@ -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(×tamp.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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user