mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-02-19 12:53:31 +00:00
39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
|
|
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
|
||
|
|
|
||
|
|
type Instruction = (Option<Vec<u8>>, bool);
|
||
|
|
|
||
|
|
/// A program that optionally modifies the account data and optionally claims it.
|
||
|
|
fn main() {
|
||
|
|
let (
|
||
|
|
ProgramInput {
|
||
|
|
pre_states,
|
||
|
|
instruction: (data_opt, should_claim),
|
||
|
|
},
|
||
|
|
instruction_words,
|
||
|
|
) = read_nssa_inputs::<Instruction>();
|
||
|
|
|
||
|
|
let [pre] = match pre_states.try_into() {
|
||
|
|
Ok(array) => array,
|
||
|
|
Err(_) => return,
|
||
|
|
};
|
||
|
|
|
||
|
|
let account_pre = &pre.account;
|
||
|
|
let mut account_post = account_pre.clone();
|
||
|
|
|
||
|
|
// Update data if provided
|
||
|
|
if let Some(data) = data_opt {
|
||
|
|
account_post.data = data
|
||
|
|
.try_into()
|
||
|
|
.expect("provided data should fit into data limit");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Claim or not based on the boolean flag
|
||
|
|
let post_state = if should_claim {
|
||
|
|
AccountPostState::new_claimed(account_post)
|
||
|
|
} else {
|
||
|
|
AccountPostState::new(account_post)
|
||
|
|
};
|
||
|
|
|
||
|
|
write_nssa_outputs(instruction_words, vec![pre], vec![post_state]);
|
||
|
|
}
|