Skip to content

Commit

Permalink
Remove the deprecated KeyedAccount interface (#27147)
Browse files Browse the repository at this point in the history
* Removes the deprecated KeyedAccount interface.

* Removes outdated example code.
  • Loading branch information
Lichtso authored Aug 15, 2022
1 parent b6762fc commit f61f63c
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 406 deletions.
85 changes: 0 additions & 85 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[allow(deprecated)]
use solana_sdk::keyed_account::{create_keyed_accounts_unified, KeyedAccount};
use {
crate::{
accounts_data_meter::AccountsDataMeter,
Expand Down Expand Up @@ -175,38 +173,6 @@ impl fmt::Display for AllocErr {
}
}

#[deprecated(
since = "1.11.0",
note = "Please use InstructionContext instead of StackFrame"
)]
#[allow(deprecated)]
pub struct StackFrame<'a> {
pub number_of_program_accounts: usize,
pub keyed_accounts: Vec<KeyedAccount<'a>>,
pub keyed_accounts_range: std::ops::Range<usize>,
}

#[allow(deprecated)]
impl<'a> StackFrame<'a> {
pub fn new(number_of_program_accounts: usize, keyed_accounts: Vec<KeyedAccount<'a>>) -> Self {
let keyed_accounts_range = std::ops::Range {
start: 0,
end: keyed_accounts.len(),
};
Self {
number_of_program_accounts,
keyed_accounts,
keyed_accounts_range,
}
}

pub fn program_id(&self) -> Option<&Pubkey> {
self.keyed_accounts
.get(self.number_of_program_accounts.saturating_sub(1))
.map(|keyed_account| keyed_account.unsigned_key())
}
}

struct SyscallContext {
check_aligned: bool,
check_size: bool,
Expand All @@ -216,8 +182,6 @@ struct SyscallContext {

pub struct InvokeContext<'a> {
pub transaction_context: &'a mut TransactionContext,
#[allow(deprecated)]
invoke_stack: Vec<StackFrame<'a>>,
rent: Rent,
pre_accounts: Vec<PreAccount>,
builtin_programs: &'a [BuiltinProgram],
Expand Down Expand Up @@ -252,7 +216,6 @@ impl<'a> InvokeContext<'a> {
) -> Self {
Self {
transaction_context,
invoke_stack: Vec::with_capacity(compute_budget.max_invoke_depth),
rent,
pre_accounts: Vec::new(),
builtin_programs,
Expand Down Expand Up @@ -384,40 +347,6 @@ impl<'a> InvokeContext<'a> {
}
}

// Create the KeyedAccounts that will be passed to the program
#[allow(deprecated)]
let keyed_accounts = program_indices
.iter()
.map(|account_index| {
Ok((
false,
false,
self.transaction_context
.get_key_of_account_at_index(*account_index)?,
self.transaction_context
.get_account_at_index(*account_index)?,
))
})
.chain(instruction_accounts.iter().map(|instruction_account| {
Ok((
instruction_account.is_signer,
instruction_account.is_writable,
self.transaction_context
.get_key_of_account_at_index(instruction_account.index_in_transaction)?,
self.transaction_context
.get_account_at_index(instruction_account.index_in_transaction)?,
))
}))
.collect::<Result<Vec<_>, InstructionError>>()?;

// Unsafe will be removed together with the keyed_accounts
#[allow(deprecated)]
self.invoke_stack.push(StackFrame::new(
program_indices.len(),
create_keyed_accounts_unified(unsafe {
std::mem::transmute(keyed_accounts.as_slice())
}),
));
self.syscall_context.push(None);
self.transaction_context
.push(program_indices, instruction_accounts, instruction_data)
Expand All @@ -426,7 +355,6 @@ impl<'a> InvokeContext<'a> {
/// Pop a stack frame from the invocation stack
pub fn pop(&mut self) -> Result<(), InstructionError> {
self.syscall_context.pop();
self.invoke_stack.pop();
self.transaction_context.pop()
}

Expand Down Expand Up @@ -915,19 +843,6 @@ impl<'a> InvokeContext<'a> {
Err(InstructionError::UnsupportedProgramId)
}

#[deprecated(
since = "1.11.0",
note = "Please use BorrowedAccount instead of KeyedAccount"
)]
#[allow(deprecated)]
/// Get the list of keyed accounts including the chain of program accounts
pub fn get_keyed_accounts(&self) -> Result<&[KeyedAccount], InstructionError> {
self.invoke_stack
.last()
.and_then(|frame| frame.keyed_accounts.get(frame.keyed_accounts_range.clone()))
.ok_or(InstructionError::CallDepth)
}

/// Get this invocation's LogCollector
pub fn get_log_collector(&self) -> Option<Rc<RefCell<LogCollector>>> {
self.log_collector.clone()
Expand Down
61 changes: 0 additions & 61 deletions sdk/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,67 +65,6 @@ macro_rules! declare_builtin_name {
/// entrypoint: Program's entrypoint, must be of `type Entrypoint`
/// id: Path to the program id access function, used if this macro is not
/// called in `src/lib`
///
/// # Examples
///
/// ```
/// use std::str::FromStr;
/// // wrapper is used so that the macro invocation occurs in the item position
/// // rather than in the statement position which isn't allowed.
/// mod item_wrapper {
/// use solana_sdk::keyed_account::KeyedAccount;
/// use solana_sdk::instruction::InstructionError;
/// use solana_sdk::pubkey::Pubkey;
/// use solana_sdk::declare_builtin;
///
/// fn my_process_instruction(
/// first_instruction_account: usize,
/// keyed_accounts: &[KeyedAccount],
/// ) -> Result<(), InstructionError> {
/// // Process an instruction
/// Ok(())
/// }
///
/// declare_builtin!(
/// "My11111111111111111111111111111111111111111",
/// solana_my_program,
/// my_process_instruction
/// );
///
/// # }
/// # use solana_sdk::pubkey::Pubkey;
/// # use item_wrapper::id;
/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
/// assert_eq!(id(), my_id);
/// ```
/// ```
/// use std::str::FromStr;
/// # // wrapper is used so that the macro invocation occurs in the item position
/// # // rather than in the statement position which isn't allowed.
/// # mod item_wrapper {
/// use solana_sdk::keyed_account::KeyedAccount;
/// use solana_sdk::instruction::InstructionError;
/// use solana_sdk::pubkey::Pubkey;
/// use solana_sdk::declare_builtin;
///
/// fn my_process_instruction(
/// first_instruction_account: usize,
/// keyed_accounts: &[KeyedAccount],
/// ) -> Result<(), InstructionError> {
/// // Process an instruction
/// Ok(())
/// }
///
/// declare_builtin!(
/// solana_sdk::system_program::ID,
/// solana_my_program,
/// my_process_instruction
/// );
/// }
///
/// # use item_wrapper::id;
/// assert_eq!(id(), solana_sdk::system_program::ID);
/// ```
#[macro_export]
macro_rules! declare_builtin {
($bs58_string:expr, $name:ident, $entrypoint:expr) => {
Expand Down
Loading

0 comments on commit f61f63c

Please sign in to comment.