mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-04-03 17:53:09 +00:00
refactor: pass self_program_id to ProgramOutput in test and example guest programs
This commit is contained in:
parent
58b72dd77c
commit
7def0c4664
@ -18,8 +18,7 @@ type Instruction = Vec<u8>;
|
||||
fn main() {
|
||||
// Read inputs
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: greeting,
|
||||
},
|
||||
@ -51,5 +50,5 @@ fn main() {
|
||||
// with the NSSA program rules.
|
||||
// WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be
|
||||
// called to commit the output.
|
||||
ProgramOutput::new(instruction_data, vec![pre_state], vec![post_state]).write();
|
||||
ProgramOutput::new(self_program_id, instruction_data, vec![pre_state], vec![post_state]).write();
|
||||
}
|
||||
|
||||
@ -18,8 +18,7 @@ type Instruction = Vec<u8>;
|
||||
fn main() {
|
||||
// Read inputs
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: greeting,
|
||||
},
|
||||
@ -58,5 +57,5 @@ fn main() {
|
||||
// with the NSSA program rules.
|
||||
// WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be
|
||||
// called to commit the output.
|
||||
ProgramOutput::new(instruction_data, vec![pre_state], vec![post_state]).write();
|
||||
ProgramOutput::new(self_program_id, instruction_data, vec![pre_state], vec![post_state]).write();
|
||||
}
|
||||
|
||||
@ -65,8 +65,7 @@ fn move_data(from_pre: AccountWithMetadata, to_pre: AccountWithMetadata) -> Vec<
|
||||
fn main() {
|
||||
// Read input accounts.
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: (function_id, data),
|
||||
},
|
||||
@ -86,5 +85,5 @@ fn main() {
|
||||
|
||||
// WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be
|
||||
// called to commit the output.
|
||||
ProgramOutput::new(instruction_words, pre_states, post_states).write();
|
||||
ProgramOutput::new(self_program_id, instruction_words, pre_states, post_states).write();
|
||||
}
|
||||
|
||||
@ -26,8 +26,7 @@ fn hello_world_program_id() -> ProgramId {
|
||||
fn main() {
|
||||
// Read inputs
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: (),
|
||||
},
|
||||
@ -56,7 +55,7 @@ fn main() {
|
||||
// Write the outputs.
|
||||
// WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be
|
||||
// called to commit the output.
|
||||
ProgramOutput::new(instruction_data, vec![pre_state], vec![post_state])
|
||||
ProgramOutput::new(self_program_id, instruction_data, vec![pre_state], vec![post_state])
|
||||
.with_chained_calls(vec![chained_call])
|
||||
.write();
|
||||
}
|
||||
|
||||
@ -32,8 +32,7 @@ fn hello_world_program_id() -> ProgramId {
|
||||
fn main() {
|
||||
// Read inputs
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: (),
|
||||
},
|
||||
@ -69,7 +68,7 @@ fn main() {
|
||||
// Write the outputs.
|
||||
// WARNING: constructing a `ProgramOutput` has no effect on its own. `.write()` must be
|
||||
// called to commit the output.
|
||||
ProgramOutput::new(instruction_data, vec![pre_state], vec![post_state])
|
||||
ProgramOutput::new(self_program_id, instruction_data, vec![pre_state], vec![post_state])
|
||||
.with_chained_calls(vec![chained_call])
|
||||
.write();
|
||||
}
|
||||
|
||||
@ -4,8 +4,7 @@ type Instruction = u128;
|
||||
|
||||
fn main() {
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: balance_to_burn,
|
||||
},
|
||||
@ -21,6 +20,7 @@ fn main() {
|
||||
account_post.balance = account_post.balance.saturating_sub(balance_to_burn);
|
||||
|
||||
ProgramOutput::new(
|
||||
self_program_id,
|
||||
instruction_words,
|
||||
vec![pre],
|
||||
vec![AccountPostState::new(account_post)],
|
||||
|
||||
@ -12,8 +12,7 @@ type Instruction = (u128, ProgramId, u32, Option<PdaSeed>);
|
||||
/// program.
|
||||
fn main() {
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: (balance, auth_transfer_id, num_chain_calls, pda_seed),
|
||||
},
|
||||
@ -56,6 +55,7 @@ fn main() {
|
||||
}
|
||||
|
||||
ProgramOutput::new(
|
||||
self_program_id,
|
||||
instruction_words,
|
||||
vec![sender_pre.clone(), recipient_pre.clone()],
|
||||
vec![
|
||||
|
||||
@ -5,8 +5,7 @@ type Instruction = (Option<Vec<u8>>, bool);
|
||||
/// A program that optionally modifies the account data and optionally claims it.
|
||||
fn main() {
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: (data_opt, should_claim),
|
||||
},
|
||||
@ -34,5 +33,5 @@ fn main() {
|
||||
AccountPostState::new(account_post)
|
||||
};
|
||||
|
||||
ProgramOutput::new(instruction_words, vec![pre], vec![post_state]).write();
|
||||
ProgramOutput::new(self_program_id, instruction_words, vec![pre], vec![post_state]).write();
|
||||
}
|
||||
|
||||
@ -4,8 +4,7 @@ type Instruction = ();
|
||||
|
||||
fn main() {
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: (),
|
||||
},
|
||||
@ -18,5 +17,5 @@ fn main() {
|
||||
|
||||
let account_post = AccountPostState::new_claimed(pre.account.clone(), Claim::Authorized);
|
||||
|
||||
ProgramOutput::new(instruction_words, vec![pre], vec![account_post]).write();
|
||||
ProgramOutput::new(self_program_id, instruction_words, vec![pre], vec![account_post]).write();
|
||||
}
|
||||
|
||||
@ -5,8 +5,7 @@ type Instruction = Vec<u8>;
|
||||
/// A program that modifies the account data by setting bytes sent in instruction.
|
||||
fn main() {
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: data,
|
||||
},
|
||||
@ -24,6 +23,7 @@ fn main() {
|
||||
.expect("provided data should fit into data limit");
|
||||
|
||||
ProgramOutput::new(
|
||||
self_program_id,
|
||||
instruction_words,
|
||||
vec![pre],
|
||||
vec![AccountPostState::new_claimed(
|
||||
|
||||
@ -6,7 +6,7 @@ use nssa_core::{
|
||||
type Instruction = ();
|
||||
|
||||
fn main() {
|
||||
let (ProgramInput { pre_states, .. }, instruction_words) = read_nssa_inputs::<Instruction>();
|
||||
let (ProgramInput { self_program_id, pre_states, .. }, instruction_words) = read_nssa_inputs::<Instruction>();
|
||||
|
||||
let Ok([pre]) = <[_; 1]>::try_from(pre_states) else {
|
||||
return;
|
||||
@ -15,6 +15,7 @@ fn main() {
|
||||
let account_pre = pre.account.clone();
|
||||
|
||||
ProgramOutput::new(
|
||||
self_program_id,
|
||||
instruction_words,
|
||||
vec![pre],
|
||||
vec![
|
||||
|
||||
@ -13,8 +13,7 @@ type Instruction = (u128, ProgramId);
|
||||
/// but sets the `is_authorized` field of the first account to true.
|
||||
fn main() {
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: (balance, transfer_program_id),
|
||||
},
|
||||
@ -41,6 +40,7 @@ fn main() {
|
||||
};
|
||||
|
||||
ProgramOutput::new(
|
||||
self_program_id,
|
||||
instruction_words,
|
||||
vec![sender.clone(), receiver.clone()],
|
||||
vec![
|
||||
|
||||
@ -3,7 +3,7 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss
|
||||
type Instruction = ();
|
||||
|
||||
fn main() {
|
||||
let (ProgramInput { pre_states, .. }, instruction_words) = read_nssa_inputs::<Instruction>();
|
||||
let (ProgramInput { self_program_id, pre_states, .. }, instruction_words) = read_nssa_inputs::<Instruction>();
|
||||
|
||||
let Ok([pre]) = <[_; 1]>::try_from(pre_states) else {
|
||||
return;
|
||||
@ -17,6 +17,7 @@ fn main() {
|
||||
.expect("Balance overflow");
|
||||
|
||||
ProgramOutput::new(
|
||||
self_program_id,
|
||||
instruction_words,
|
||||
vec![pre],
|
||||
vec![AccountPostState::new(account_post)],
|
||||
|
||||
@ -3,7 +3,7 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss
|
||||
type Instruction = ();
|
||||
|
||||
fn main() {
|
||||
let (ProgramInput { pre_states, .. }, instruction_words) = read_nssa_inputs::<Instruction>();
|
||||
let (ProgramInput { self_program_id, pre_states, .. }, instruction_words) = read_nssa_inputs::<Instruction>();
|
||||
|
||||
let Ok([pre1, pre2]) = <[_; 2]>::try_from(pre_states) else {
|
||||
return;
|
||||
@ -12,6 +12,7 @@ fn main() {
|
||||
let account_pre1 = pre1.account.clone();
|
||||
|
||||
ProgramOutput::new(
|
||||
self_program_id,
|
||||
instruction_words,
|
||||
vec![pre1, pre2],
|
||||
vec![AccountPostState::new(account_pre1)],
|
||||
|
||||
@ -63,8 +63,7 @@ fn transfer(
|
||||
fn main() {
|
||||
// Read input accounts.
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: balance_to_move,
|
||||
},
|
||||
@ -81,5 +80,5 @@ fn main() {
|
||||
}
|
||||
_ => panic!("invalid params"),
|
||||
};
|
||||
ProgramOutput::new(instruction_data, pre_states, post_states).write();
|
||||
ProgramOutput::new(self_program_id, instruction_data, pre_states, post_states).write();
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss
|
||||
type Instruction = ();
|
||||
|
||||
fn main() {
|
||||
let (ProgramInput { pre_states, .. }, instruction_words) = read_nssa_inputs::<Instruction>();
|
||||
let (ProgramInput { self_program_id, pre_states, .. }, instruction_words) = read_nssa_inputs::<Instruction>();
|
||||
|
||||
let Ok([pre]) = <[_; 1]>::try_from(pre_states) else {
|
||||
return;
|
||||
@ -14,6 +14,7 @@ fn main() {
|
||||
account_post.nonce.public_account_nonce_increment();
|
||||
|
||||
ProgramOutput::new(
|
||||
self_program_id,
|
||||
instruction_words,
|
||||
vec![pre],
|
||||
vec![AccountPostState::new(account_post)],
|
||||
|
||||
@ -3,11 +3,11 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss
|
||||
type Instruction = ();
|
||||
|
||||
fn main() {
|
||||
let (ProgramInput { pre_states, .. }, instruction_words) = read_nssa_inputs::<Instruction>();
|
||||
let (ProgramInput { self_program_id, pre_states, .. }, instruction_words) = read_nssa_inputs::<Instruction>();
|
||||
|
||||
let post_states = pre_states
|
||||
.iter()
|
||||
.map(|account| AccountPostState::new(account.account.clone()))
|
||||
.collect();
|
||||
ProgramOutput::new(instruction_words, pre_states, post_states).write();
|
||||
ProgramOutput::new(self_program_id, instruction_words, pre_states, post_states).write();
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nss
|
||||
type Instruction = ();
|
||||
|
||||
fn main() {
|
||||
let (ProgramInput { pre_states, .. }, instruction_words) = read_nssa_inputs::<Instruction>();
|
||||
let (ProgramInput { self_program_id, pre_states, .. }, instruction_words) = read_nssa_inputs::<Instruction>();
|
||||
|
||||
let Ok([pre]) = <[_; 1]>::try_from(pre_states) else {
|
||||
return;
|
||||
@ -14,6 +14,7 @@ fn main() {
|
||||
account_post.program_owner = [0, 1, 2, 3, 4, 5, 6, 7];
|
||||
|
||||
ProgramOutput::new(
|
||||
self_program_id,
|
||||
instruction_words,
|
||||
vec![pre],
|
||||
vec![AccountPostState::new(account_post)],
|
||||
|
||||
@ -4,8 +4,7 @@ type Instruction = u128;
|
||||
|
||||
fn main() {
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: balance,
|
||||
},
|
||||
@ -28,6 +27,7 @@ fn main() {
|
||||
.expect("Overflow when adding balance");
|
||||
|
||||
ProgramOutput::new(
|
||||
self_program_id,
|
||||
instruction_words,
|
||||
vec![sender_pre, receiver_pre],
|
||||
vec![
|
||||
|
||||
@ -7,8 +7,7 @@ type Instruction = (BlockValidityWindow, TimestampValidityWindow);
|
||||
|
||||
fn main() {
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: (block_validity_window, timestamp_validity_window),
|
||||
},
|
||||
@ -22,6 +21,7 @@ fn main() {
|
||||
let post = pre.account.clone();
|
||||
|
||||
ProgramOutput::new(
|
||||
self_program_id,
|
||||
instruction_words,
|
||||
vec![pre],
|
||||
vec![AccountPostState::new(post)],
|
||||
|
||||
@ -15,8 +15,7 @@ type Instruction = (BlockValidityWindow, ProgramId, BlockValidityWindow);
|
||||
|
||||
fn main() {
|
||||
let (
|
||||
ProgramInput {
|
||||
self_program_id: _,
|
||||
ProgramInput { self_program_id,
|
||||
pre_states,
|
||||
instruction: (block_validity_window, chained_program_id, chained_block_validity_window),
|
||||
},
|
||||
@ -39,6 +38,7 @@ fn main() {
|
||||
};
|
||||
|
||||
ProgramOutput::new(
|
||||
self_program_id,
|
||||
instruction_words,
|
||||
vec![pre],
|
||||
vec![AccountPostState::new(post)],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user