Skip to content

Commit

Permalink
Exposes is_signer() and is_writable() in InstructionContext.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Feb 1, 2022
1 parent 987d3fc commit c34020d
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions sdk/src/transaction_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,30 @@ impl InstructionContext {
)
}

/// Returns whether an account is a signer
pub fn is_signer(&self, index_in_instruction: usize) -> bool {
if index_in_instruction < self.program_accounts.len() {
false
} else {
self.instruction_accounts[
index_in_instruction
.saturating_sub(self.program_accounts.len())]
.is_signer
}
}

/// Returns whether an account is writable
pub fn is_writable(&self, index_in_instruction: usize) -> bool {
if index_in_instruction < self.program_accounts.len() {
false
} else {
self.instruction_accounts[
index_in_instruction
.saturating_sub(self.program_accounts.len())]
.is_writable
}
}

/// Calculates the set of all keys of signer accounts in this Instruction
pub fn get_signers(&self, transaction_context: &TransactionContext) -> HashSet<Pubkey> {
let mut result = HashSet::new();
Expand Down Expand Up @@ -521,25 +545,11 @@ impl<'a> BorrowedAccount<'a> {

/// Returns whether this account is a signer (instruction wide)
pub fn is_signer(&self) -> bool {
if self.index_in_instruction < self.instruction_context.program_accounts.len() {
false
} else {
self.instruction_context.instruction_accounts[self
.index_in_instruction
.saturating_sub(self.instruction_context.program_accounts.len())]
.is_signer
}
self.instruction_context.is_signer(self.index_in_instruction)
}

/// Returns whether this account is writable (instruction wide)
pub fn is_writable(&self) -> bool {
if self.index_in_instruction < self.instruction_context.program_accounts.len() {
false
} else {
self.instruction_context.instruction_accounts[self
.index_in_instruction
.saturating_sub(self.instruction_context.program_accounts.len())]
.is_writable
}
self.instruction_context.is_writable(self.index_in_instruction)
}
}

0 comments on commit c34020d

Please sign in to comment.