migrate memberes from deprecated structs (#24263)
This commit is contained in:
@ -177,8 +177,6 @@ pub struct StackFrame<'a> {
|
||||
pub number_of_program_accounts: usize,
|
||||
pub keyed_accounts: Vec<KeyedAccount<'a>>,
|
||||
pub keyed_accounts_range: std::ops::Range<usize>,
|
||||
pub orig_account_lengths: Option<Vec<usize>>,
|
||||
pub allocator: Option<Rc<RefCell<dyn Alloc>>>,
|
||||
}
|
||||
|
||||
impl<'a> StackFrame<'a> {
|
||||
@ -191,8 +189,6 @@ impl<'a> StackFrame<'a> {
|
||||
number_of_program_accounts,
|
||||
keyed_accounts,
|
||||
keyed_accounts_range,
|
||||
orig_account_lengths: None,
|
||||
allocator: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,8 +216,10 @@ pub struct InvokeContext<'a> {
|
||||
pub timings: ExecuteDetailsTimings,
|
||||
pub blockhash: Hash,
|
||||
pub lamports_per_signature: u64,
|
||||
pub check_aligned: bool,
|
||||
pub check_size: bool,
|
||||
check_aligned: bool,
|
||||
check_size: bool,
|
||||
orig_account_lengths: Vec<Option<Vec<usize>>>,
|
||||
allocators: Vec<Option<Rc<RefCell<dyn Alloc>>>>,
|
||||
}
|
||||
|
||||
impl<'a> InvokeContext<'a> {
|
||||
@ -258,6 +256,8 @@ impl<'a> InvokeContext<'a> {
|
||||
lamports_per_signature,
|
||||
check_aligned: true,
|
||||
check_size: true,
|
||||
orig_account_lengths: Vec::new(),
|
||||
allocators: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -443,6 +443,8 @@ impl<'a> InvokeContext<'a> {
|
||||
std::mem::transmute(keyed_accounts.as_slice())
|
||||
}),
|
||||
));
|
||||
self.orig_account_lengths.push(None);
|
||||
self.allocators.push(None);
|
||||
self.transaction_context.push(
|
||||
program_indices,
|
||||
instruction_accounts,
|
||||
@ -454,6 +456,8 @@ impl<'a> InvokeContext<'a> {
|
||||
|
||||
/// Pop a stack frame from the invocation stack
|
||||
pub fn pop(&mut self) -> Result<(), InstructionError> {
|
||||
self.orig_account_lengths.pop();
|
||||
self.allocators.pop();
|
||||
self.invoke_stack.pop();
|
||||
self.transaction_context.pop()
|
||||
}
|
||||
@ -1085,57 +1089,61 @@ impl<'a> InvokeContext<'a> {
|
||||
&mut self,
|
||||
orig_account_lengths: Vec<usize>,
|
||||
) -> Result<(), InstructionError> {
|
||||
let stack_frame = &mut self
|
||||
.invoke_stack
|
||||
*self
|
||||
.orig_account_lengths
|
||||
.last_mut()
|
||||
.ok_or(InstructionError::CallDepth)?;
|
||||
stack_frame.orig_account_lengths = Some(orig_account_lengths);
|
||||
.ok_or(InstructionError::CallDepth)? = Some(orig_account_lengths);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get the original account lengths
|
||||
pub fn get_orig_account_lengths(&self) -> Result<&[usize], InstructionError> {
|
||||
self.invoke_stack
|
||||
self.orig_account_lengths
|
||||
.last()
|
||||
.and_then(|frame| frame.orig_account_lengths.as_ref())
|
||||
.ok_or(InstructionError::CallDepth)
|
||||
.and_then(|orig_account_lengths| orig_account_lengths.as_ref())
|
||||
.map(|orig_account_lengths| orig_account_lengths.as_slice())
|
||||
.ok_or(InstructionError::CallDepth)
|
||||
}
|
||||
|
||||
// Set should alignment be enforced during user pointer translation
|
||||
pub fn set_check_aligned(&mut self, check_aligned: bool) {
|
||||
self.check_aligned = check_aligned;
|
||||
}
|
||||
|
||||
// Sshould alignment be enforced during user pointer translation
|
||||
pub fn get_check_aligned(&self) -> bool {
|
||||
self.check_aligned
|
||||
}
|
||||
|
||||
// Set should type size be checked during user pointer translation
|
||||
pub fn set_check_size(&mut self, check_size: bool) {
|
||||
self.check_size = check_size;
|
||||
}
|
||||
|
||||
// Set should type size be checked during user pointer translation
|
||||
pub fn get_check_size(&self) -> bool {
|
||||
self.check_size
|
||||
}
|
||||
|
||||
// Get this instruction's memory allocator
|
||||
pub fn get_allocator(&self) -> Result<Rc<RefCell<dyn Alloc>>, InstructionError> {
|
||||
self.allocators
|
||||
.last()
|
||||
.and_then(|allocator| allocator.clone())
|
||||
.ok_or(InstructionError::CallDepth)
|
||||
}
|
||||
|
||||
// Set this instruction's memory allocator
|
||||
pub fn set_allocator(
|
||||
&mut self,
|
||||
allocator: Rc<RefCell<dyn Alloc>>,
|
||||
) -> Result<(), InstructionError> {
|
||||
let stack_frame = &mut self
|
||||
.invoke_stack
|
||||
*self
|
||||
.allocators
|
||||
.last_mut()
|
||||
.ok_or(InstructionError::CallDepth)?;
|
||||
stack_frame.allocator = Some(allocator);
|
||||
.ok_or(InstructionError::CallDepth)? = Some(allocator);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_allocator(&self) -> Result<Rc<RefCell<dyn Alloc>>, InstructionError> {
|
||||
self.invoke_stack
|
||||
.last()
|
||||
.and_then(|frame| frame.allocator.clone())
|
||||
.ok_or(InstructionError::CallDepth)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MockInvokeContextPreparation {
|
||||
|
Reference in New Issue
Block a user