remove old program output constructors

This commit is contained in:
Sergio Chouhy 2026-03-25 16:56:04 -03:00
parent 3356aef291
commit abc30c0ce0
25 changed files with 91 additions and 116 deletions

View File

@ -1,5 +1,5 @@
use nssa_core::program::{
AccountPostState, DEFAULT_PROGRAM_ID, ProgramInput, read_nssa_inputs, write_nssa_outputs,
AccountPostState, DEFAULT_PROGRAM_ID, ProgramInput, ProgramOutput, read_nssa_inputs,
};
// Hello-world example program.
@ -56,5 +56,7 @@ fn main() {
// The output is a proposed state difference. It will only succeed if the pre states coincide
// with the previous values of the accounts, and the transition to the post states conforms
// with the NSSA program rules.
write_nssa_outputs(instruction_data, vec![pre_state], vec![post_state]);
// 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();
}

View File

@ -1,5 +1,5 @@
use nssa_core::program::{
AccountPostState, DEFAULT_PROGRAM_ID, ProgramInput, read_nssa_inputs, write_nssa_outputs,
AccountPostState, DEFAULT_PROGRAM_ID, ProgramInput, ProgramOutput, read_nssa_inputs,
};
// Hello-world with authorization example program.
@ -63,5 +63,7 @@ fn main() {
// The output is a proposed state difference. It will only succeed if the pre states coincide
// with the previous values of the accounts, and the transition to the post states conforms
// with the NSSA program rules.
write_nssa_outputs(instruction_data, vec![pre_state], vec![post_state]);
// 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();
}

View File

@ -1,7 +1,7 @@
use nssa_core::{
account::{Account, AccountWithMetadata, Data},
program::{
AccountPostState, DEFAULT_PROGRAM_ID, ProgramInput, read_nssa_inputs, write_nssa_outputs,
AccountPostState, DEFAULT_PROGRAM_ID, ProgramInput, ProgramOutput, read_nssa_inputs,
},
};
@ -95,5 +95,7 @@ fn main() {
_ => panic!("invalid params"),
};
write_nssa_outputs(instruction_words, pre_states, post_states);
// 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();
}

View File

@ -1,6 +1,5 @@
use nssa_core::program::{
AccountPostState, ChainedCall, ProgramId, ProgramInput, read_nssa_inputs,
write_nssa_outputs_with_chained_call,
AccountPostState, ChainedCall, ProgramId, ProgramInput, ProgramOutput, read_nssa_inputs,
};
// Tail Call example program.
@ -53,11 +52,10 @@ fn main() {
pda_seeds: vec![],
};
// Write the outputs
write_nssa_outputs_with_chained_call(
instruction_data,
vec![pre_state],
vec![post_state],
vec![chained_call],
);
// 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])
.with_chained_calls(vec![chained_call])
.write();
}

View File

@ -1,6 +1,6 @@
use nssa_core::program::{
AccountPostState, ChainedCall, PdaSeed, ProgramId, ProgramInput, read_nssa_inputs,
write_nssa_outputs_with_chained_call,
AccountPostState, ChainedCall, PdaSeed, ProgramId, ProgramInput, ProgramOutput,
read_nssa_inputs,
};
// Tail Call with PDA example program.
@ -65,11 +65,10 @@ fn main() {
pda_seeds: vec![PDA_SEED],
};
// Write the outputs
write_nssa_outputs_with_chained_call(
instruction_data,
vec![pre_state],
vec![post_state],
vec![chained_call],
);
// 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])
.with_chained_calls(vec![chained_call])
.write();
}

View File

@ -380,25 +380,6 @@ pub fn read_nssa_inputs<T: DeserializeOwned>() -> (ProgramInput<T>, InstructionD
)
}
pub fn write_nssa_outputs(
instruction_data: InstructionData,
pre_states: Vec<AccountWithMetadata>,
post_states: Vec<AccountPostState>,
) {
ProgramOutput::new(instruction_data, pre_states, post_states).write();
}
pub fn write_nssa_outputs_with_chained_call(
instruction_data: InstructionData,
pre_states: Vec<AccountWithMetadata>,
post_states: Vec<AccountPostState>,
chained_calls: Vec<ChainedCall>,
) {
ProgramOutput::new(instruction_data, pre_states, post_states)
.with_chained_calls(chained_calls)
.write();
}
/// Validates well-behaved program execution.
///
/// # Parameters

View File

@ -9,7 +9,7 @@
use std::num::NonZero;
use amm_core::Instruction;
use nssa_core::program::{ProgramInput, read_nssa_inputs, write_nssa_outputs_with_chained_call};
use nssa_core::program::{ProgramInput, ProgramOutput, read_nssa_inputs};
fn main() {
let (
@ -133,10 +133,7 @@ fn main() {
}
};
write_nssa_outputs_with_chained_call(
instruction_words,
pre_states_clone,
post_states,
chained_calls,
);
ProgramOutput::new(instruction_words, pre_states_clone, post_states)
.with_chained_calls(chained_calls)
.write();
}

View File

@ -1,7 +1,7 @@
use nssa_core::{
account::{Account, AccountWithMetadata},
program::{
AccountPostState, DEFAULT_PROGRAM_ID, ProgramInput, read_nssa_inputs, write_nssa_outputs,
AccountPostState, DEFAULT_PROGRAM_ID, ProgramInput, ProgramOutput, read_nssa_inputs,
},
};
@ -84,5 +84,5 @@ fn main() {
_ => panic!("invalid params"),
};
write_nssa_outputs(instruction_words, pre_states, post_states);
ProgramOutput::new(instruction_words, pre_states, post_states).write();
}

View File

@ -1,4 +1,4 @@
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nssa_inputs};
use risc0_zkvm::sha::{Impl, Sha256 as _};
const PRIZE: u128 = 150;
@ -78,12 +78,13 @@ fn main() {
.checked_add(PRIZE)
.expect("Overflow when adding prize to winner");
write_nssa_outputs(
ProgramOutput::new(
instruction_words,
vec![pinata, winner],
vec![
AccountPostState::new_claimed_if_default(pinata_post),
AccountPostState::new(winner_post),
],
);
)
.write();
}

View File

@ -1,8 +1,7 @@
use nssa_core::{
account::Data,
program::{
AccountPostState, ChainedCall, PdaSeed, ProgramInput, read_nssa_inputs,
write_nssa_outputs_with_chained_call,
AccountPostState, ChainedCall, PdaSeed, ProgramInput, ProgramOutput, read_nssa_inputs,
},
};
use risc0_zkvm::sha::{Impl, Sha256 as _};
@ -97,7 +96,7 @@ fn main() {
)
.with_pda_seeds(vec![PdaSeed::new([0; 32])]);
write_nssa_outputs_with_chained_call(
ProgramOutput::new(
instruction_words,
vec![
pinata_definition,
@ -109,6 +108,7 @@ fn main() {
AccountPostState::new(pinata_token_holding_post),
AccountPostState::new(winner_token_holding_post),
],
vec![chained_call],
);
)
.with_chained_calls(vec![chained_call])
.write();
}

View File

@ -6,7 +6,7 @@
//! Token program accepts [`Instruction`] as input, refer to the corresponding documentation
//! for more details.
use nssa_core::program::{ProgramInput, read_nssa_inputs, write_nssa_outputs};
use nssa_core::program::{ProgramInput, ProgramOutput, read_nssa_inputs};
use token_program::core::Instruction;
fn main() {
@ -81,5 +81,5 @@ fn main() {
}
};
write_nssa_outputs(instruction_words, pre_states_clone, post_states);
ProgramOutput::new(instruction_words, pre_states_clone, post_states).write();
}

View File

@ -1,4 +1,4 @@
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nssa_inputs};
type Instruction = u128;
@ -19,9 +19,6 @@ fn main() {
let mut account_post = account_pre.clone();
account_post.balance = account_post.balance.saturating_sub(balance_to_burn);
write_nssa_outputs(
instruction_words,
vec![pre],
vec![AccountPostState::new(account_post)],
);
ProgramOutput::new(instruction_words, vec![pre], vec![AccountPostState::new(account_post)])
.write();
}

View File

@ -1,6 +1,6 @@
use nssa_core::program::{
AccountPostState, ChainedCall, PdaSeed, ProgramId, ProgramInput, read_nssa_inputs,
write_nssa_outputs_with_chained_call,
AccountPostState, ChainedCall, PdaSeed, ProgramId, ProgramInput, ProgramOutput,
read_nssa_inputs,
};
use risc0_zkvm::serde::to_vec;
@ -54,13 +54,14 @@ fn main() {
};
}
write_nssa_outputs_with_chained_call(
ProgramOutput::new(
instruction_words,
vec![sender_pre.clone(), recipient_pre.clone()],
vec![
AccountPostState::new(sender_pre.account),
AccountPostState::new(recipient_pre.account),
],
chained_calls,
);
)
.with_chained_calls(chained_calls)
.write();
}

View File

@ -1,4 +1,4 @@
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nssa_inputs};
type Instruction = (Option<Vec<u8>>, bool);
@ -33,5 +33,5 @@ fn main() {
AccountPostState::new(account_post)
};
write_nssa_outputs(instruction_words, vec![pre], vec![post_state]);
ProgramOutput::new(instruction_words, vec![pre], vec![post_state]).write();
}

View File

@ -1,4 +1,4 @@
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nssa_inputs};
type Instruction = ();
@ -17,5 +17,5 @@ fn main() {
let account_post = AccountPostState::new_claimed(pre.account.clone());
write_nssa_outputs(instruction_words, vec![pre], vec![account_post]);
ProgramOutput::new(instruction_words, vec![pre], vec![account_post]).write();
}

View File

@ -1,4 +1,4 @@
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nssa_inputs};
type Instruction = Vec<u8>;
@ -22,9 +22,10 @@ fn main() {
.try_into()
.expect("provided data should fit into data limit");
write_nssa_outputs(
ProgramOutput::new(
instruction_words,
vec![pre],
vec![AccountPostState::new_claimed(account_post)],
);
)
.write();
}

View File

@ -1,6 +1,6 @@
use nssa_core::{
account::Account,
program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs},
program::{AccountPostState, ProgramInput, ProgramOutput, read_nssa_inputs},
};
type Instruction = ();
@ -14,12 +14,13 @@ fn main() {
let account_pre = pre.account.clone();
write_nssa_outputs(
ProgramOutput::new(
instruction_words,
vec![pre],
vec![
AccountPostState::new(account_pre),
AccountPostState::new(Account::default()),
],
);
)
.write();
}

View File

@ -1,8 +1,7 @@
use nssa_core::{
account::AccountWithMetadata,
program::{
AccountPostState, ChainedCall, ProgramId, ProgramInput, read_nssa_inputs,
write_nssa_outputs_with_chained_call,
AccountPostState, ChainedCall, ProgramId, ProgramInput, ProgramOutput, read_nssa_inputs,
},
};
use risc0_zkvm::serde::to_vec;
@ -40,13 +39,14 @@ fn main() {
pda_seeds: vec![],
};
write_nssa_outputs_with_chained_call(
ProgramOutput::new(
instruction_words,
vec![sender.clone(), receiver.clone()],
vec![
AccountPostState::new(sender.account),
AccountPostState::new(receiver.account),
],
vec![chained_call],
);
)
.with_chained_calls(vec![chained_call])
.write();
}

View File

@ -1,4 +1,4 @@
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nssa_inputs};
type Instruction = ();
@ -16,9 +16,6 @@ fn main() {
.checked_add(1)
.expect("Balance overflow");
write_nssa_outputs(
instruction_words,
vec![pre],
vec![AccountPostState::new(account_post)],
);
ProgramOutput::new(instruction_words, vec![pre], vec![AccountPostState::new(account_post)])
.write();
}

View File

@ -1,4 +1,4 @@
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nssa_inputs};
type Instruction = ();
@ -11,9 +11,10 @@ fn main() {
let account_pre1 = pre1.account.clone();
write_nssa_outputs(
ProgramOutput::new(
instruction_words,
vec![pre1, pre2],
vec![AccountPostState::new(account_pre1)],
);
)
.write();
}

View File

@ -5,7 +5,7 @@
use nssa_core::{
account::{Account, AccountWithMetadata},
program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs},
program::{AccountPostState, ProgramInput, ProgramOutput, read_nssa_inputs},
};
/// Initializes a default account under the ownership of this program.
@ -80,5 +80,5 @@ fn main() {
}
_ => panic!("invalid params"),
};
write_nssa_outputs(instruction_data, pre_states, post_states);
ProgramOutput::new(instruction_data, pre_states, post_states).write();
}

View File

@ -1,4 +1,4 @@
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nssa_inputs};
type Instruction = ();
@ -13,9 +13,6 @@ fn main() {
let mut account_post = account_pre.clone();
account_post.nonce.public_account_nonce_increment();
write_nssa_outputs(
instruction_words,
vec![pre],
vec![AccountPostState::new(account_post)],
);
ProgramOutput::new(instruction_words, vec![pre], vec![AccountPostState::new(account_post)])
.write();
}

View File

@ -1,4 +1,4 @@
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nssa_inputs};
type Instruction = ();
@ -9,5 +9,5 @@ fn main() {
.iter()
.map(|account| AccountPostState::new(account.account.clone()))
.collect();
write_nssa_outputs(instruction_words, pre_states, post_states);
ProgramOutput::new(instruction_words, pre_states, post_states).write();
}

View File

@ -1,4 +1,4 @@
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nssa_inputs};
type Instruction = ();
@ -13,9 +13,6 @@ fn main() {
let mut account_post = account_pre.clone();
account_post.program_owner = [0, 1, 2, 3, 4, 5, 6, 7];
write_nssa_outputs(
instruction_words,
vec![pre],
vec![AccountPostState::new(account_post)],
);
ProgramOutput::new(instruction_words, vec![pre], vec![AccountPostState::new(account_post)])
.write();
}

View File

@ -1,4 +1,4 @@
use nssa_core::program::{AccountPostState, ProgramInput, read_nssa_inputs, write_nssa_outputs};
use nssa_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_nssa_inputs};
type Instruction = u128;
@ -26,12 +26,13 @@ fn main() {
.checked_add(balance)
.expect("Overflow when adding balance");
write_nssa_outputs(
ProgramOutput::new(
instruction_words,
vec![sender_pre, receiver_pre],
vec![
AccountPostState::new(sender_post),
AccountPostState::new(receiver_post),
],
);
)
.write();
}