Skip to content

Commit

Permalink
Adds keyed_accounts property and getter to InvokeContext.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Feb 18, 2021
1 parent 73d8693 commit ed973e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions runtime/src/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ pub struct ThisInvokeContext<'a> {
rent: Rent,
pre_accounts: Vec<PreAccount>,
account_deps: &'a [(Pubkey, RefCell<Account>)],
keyed_accounts: &'a [KeyedAccount<'a>],
programs: &'a [(Pubkey, ProcessInstructionWithContext)],
logger: Rc<RefCell<dyn Logger>>,
bpf_compute_budget: BpfComputeBudget,
Expand Down Expand Up @@ -244,6 +245,7 @@ impl<'a> ThisInvokeContext<'a> {
rent,
pre_accounts,
account_deps,
keyed_accounts: &[], // TODO [KeyedAccounts to InvokeContext refactoring]
programs,
logger: Rc::new(RefCell::new(ThisLogger { log_collector })),
bpf_compute_budget,
Expand Down Expand Up @@ -302,6 +304,9 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> {
.last()
.ok_or(InstructionError::GenericError)
}
fn get_keyed_accounts(&self) -> &[KeyedAccount] {
self.keyed_accounts
}
fn get_programs(&self) -> &[(Pubkey, ProcessInstructionWithContext)] {
self.programs
}
Expand Down
13 changes: 10 additions & 3 deletions sdk/src/process_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub trait InvokeContext {
) -> Result<(), InstructionError>;
/// Get the program ID of the currently executing program
fn get_caller(&self) -> Result<&Pubkey, InstructionError>;
/// Get the list of keyed accounts
fn get_keyed_accounts(&self) -> &[KeyedAccount];
/// Get a list of built-in programs
fn get_programs(&self) -> &[(Pubkey, ProcessInstructionWithContext)];
/// Get this invocation's logger
Expand Down Expand Up @@ -303,15 +305,16 @@ impl Logger for MockLogger {
}
}

pub struct MockInvokeContext {
pub struct MockInvokeContext<'a> {
pub key: Pubkey,
pub logger: MockLogger,
pub bpf_compute_budget: BpfComputeBudget,
pub compute_meter: MockComputeMeter,
pub keyed_accounts: &'a [KeyedAccount<'a>],
pub programs: Vec<(Pubkey, ProcessInstructionWithContext)>,
pub invoke_depth: usize,
}
impl Default for MockInvokeContext {
impl<'a> Default for MockInvokeContext<'a> {
fn default() -> Self {
MockInvokeContext {
key: Pubkey::default(),
Expand All @@ -320,12 +323,13 @@ impl Default for MockInvokeContext {
compute_meter: MockComputeMeter {
remaining: std::i64::MAX as u64,
},
keyed_accounts: &[], // TODO [KeyedAccounts to InvokeContext refactoring]
programs: vec![],
invoke_depth: 0,
}
}
}
impl InvokeContext for MockInvokeContext {
impl<'a> InvokeContext for MockInvokeContext<'a> {
fn push(&mut self, _key: &Pubkey) -> Result<(), InstructionError> {
self.invoke_depth += 1;
Ok(())
Expand All @@ -348,6 +352,9 @@ impl InvokeContext for MockInvokeContext {
fn get_caller(&self) -> Result<&Pubkey, InstructionError> {
Ok(&self.key)
}
fn get_keyed_accounts(&self) -> &[KeyedAccount] {
self.keyed_accounts
}
fn get_programs(&self) -> &[(Pubkey, ProcessInstructionWithContext)] {
&self.programs
}
Expand Down

0 comments on commit ed973e1

Please sign in to comment.