make inputs a vector to allow variable number of input accounts

This commit is contained in:
Sergio Chouhy 2025-07-17 10:22:24 -03:00
parent 9e153b9ebd
commit f6a8a11f98
2 changed files with 6 additions and 5 deletions

View File

@ -20,9 +20,8 @@ fn write_inputs<P: Program>(
instruction_data: &P::InstructionData,
env_builder: &mut ExecutorEnvBuilder,
) -> Result<(), ()> {
for account in input_accounts {
env_builder.write(&account).map_err(|_| ())?;
}
let input_accounts = input_accounts.to_vec();
env_builder.write(&input_accounts).map_err(|_| ())?;
env_builder.write(&instruction_data).map_err(|_| ())?;
Ok(())
}

View File

@ -8,10 +8,12 @@ use risc0_zkvm::{
/// A transfer of balance program.
/// To be used both in public and private contexts.
fn main() {
let sender: Account = env::read();
let receiver: Account = env::read();
let mut input_accounts: Vec<Account> = env::read();
let balance_to_move: u128 = env::read();
assert_eq!(input_accounts.len(), 2);
let [sender, receiver] = input_accounts.try_into().unwrap();
// Check sender has enough balance
assert!(sender.balance >= balance_to_move);