From 7a1ef0831fd09420d45ed8b43645e0f0176f95df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Fri, 19 Aug 2022 00:23:00 +0200 Subject: [PATCH] make InstructionContext::new() private --- programs/bpf_loader/src/serialization.rs | 19 +++++++++---------- sdk/src/transaction_context.rs | 22 +++++++++++----------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/programs/bpf_loader/src/serialization.rs b/programs/bpf_loader/src/serialization.rs index 6c046b2c0f2f0b..b06ba94e0c1310 100644 --- a/programs/bpf_loader/src/serialization.rs +++ b/programs/bpf_loader/src/serialization.rs @@ -497,21 +497,20 @@ mod tests { &program_indices, ) .instruction_accounts; + let instruction_data = vec![]; - let transaction_context = + let mut transaction_context = TransactionContext::new(transaction_accounts, Some(Rent::default()), 1, 1); - let instruction_data = vec![]; - let instruction_context = InstructionContext::new( - 0, - 0, - &program_indices, - &instruction_accounts, - &instruction_data, - ); + transaction_context + .push(&program_indices, &instruction_accounts, &instruction_data) + .unwrap(); + let instruction_context = transaction_context + .get_instruction_context_at_index(0) + .unwrap(); let serialization_result = serialize_parameters( &transaction_context, - &instruction_context, + instruction_context, should_cap_ix_accounts, ); assert_eq!( diff --git a/sdk/src/transaction_context.rs b/sdk/src/transaction_context.rs index 356b8ed539d6a6..7245c060a6aa1c 100644 --- a/sdk/src/transaction_context.rs +++ b/sdk/src/transaction_context.rs @@ -211,13 +211,13 @@ impl TransactionContext { return Err(InstructionError::UnbalancedInstruction); } } - let instruction_context = InstructionContext { - nesting_level: self.instruction_stack.len(), - instruction_accounts_lamport_sum: callee_instruction_accounts_lamport_sum, - program_accounts: program_accounts.to_vec(), - instruction_accounts: instruction_accounts.to_vec(), - instruction_data: instruction_data.to_vec(), - }; + let instruction_context = InstructionContext::new( + self.instruction_stack.len(), + callee_instruction_accounts_lamport_sum, + program_accounts.to_vec(), + instruction_accounts.to_vec(), + instruction_data.to_vec(), + ); let index_in_trace = self.instruction_trace.len(); self.instruction_trace.push(instruction_context); if self.instruction_stack.len() >= self.instruction_context_capacity { @@ -335,12 +335,12 @@ pub struct InstructionContext { impl InstructionContext { /// New - pub fn new( + fn new( nesting_level: usize, instruction_accounts_lamport_sum: u128, - program_accounts: &[usize], - instruction_accounts: &[InstructionAccount], - instruction_data: &[u8], + program_accounts: Vec, + instruction_accounts: Vec, + instruction_data: Vec, ) -> Self { InstructionContext { nesting_level,