Skip to content

Commit

Permalink
make InstructionContext::new() private
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Aug 19, 2022
1 parent 76f4843 commit f51dab8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
19 changes: 9 additions & 10 deletions programs/bpf_loader/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_in_trace(0)
.unwrap();

let serialization_result = serialize_parameters(
&transaction_context,
&instruction_context,
instruction_context,
should_cap_ix_accounts,
);
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,14 +766,14 @@ pub fn inner_instructions_list_from_instruction_trace(
transaction_context: &TransactionContext,
) -> InnerInstructionsList {
debug_assert!(transaction_context
.get_instruction_context_at_index(0)
.get_instruction_context_at_index_in_trace(0)
.map(|instruction_context| instruction_context.get_stack_height()
== TRANSACTION_LEVEL_STACK_HEIGHT)
.unwrap_or(true));
let mut outer_instructions = Vec::new();
for index_in_trace in 0..transaction_context.get_instruction_trace_length() {
if let Ok(instruction_context) =
transaction_context.get_instruction_context_at_index(index_in_trace)
transaction_context.get_instruction_context_at_index_in_trace(index_in_trace)
{
if instruction_context.get_stack_height() == TRANSACTION_LEVEL_STACK_HEIGHT {
outer_instructions.push(Vec::new());
Expand Down
28 changes: 14 additions & 14 deletions sdk/src/transaction_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -335,19 +335,19 @@ 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<usize>,
instruction_accounts: Vec<InstructionAccount>,
instruction_data: Vec<u8>,
) -> Self {
InstructionContext {
nesting_level,
instruction_accounts_lamport_sum,
program_accounts: program_accounts.to_vec(),
instruction_accounts: instruction_accounts.to_vec(),
instruction_data: instruction_data.to_vec(),
program_accounts,
instruction_accounts,
instruction_data,
}
}

Expand Down

0 comments on commit f51dab8

Please sign in to comment.