lang: Deprecate account wrappers (#700)
This commit is contained in:
parent
526de235d1
commit
c76db691cd
|
@ -104,11 +104,13 @@ impl<'info, T: Accounts<'info>> ToAccountMetas for CpiContext<'_, '_, '_, 'info,
|
|||
|
||||
/// Context specifying non-argument inputs for cross-program-invocations
|
||||
/// targeted at program state instructions.
|
||||
#[deprecated]
|
||||
pub struct CpiStateContext<'a, 'b, 'c, 'info, T: Accounts<'info>> {
|
||||
state: AccountInfo<'info>,
|
||||
cpi_ctx: CpiContext<'a, 'b, 'c, 'info, T>,
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'a, 'b, 'c, 'info, T: Accounts<'info>> CpiStateContext<'a, 'b, 'c, 'info, T> {
|
||||
pub fn new(program: AccountInfo<'info>, state: AccountInfo<'info>, accounts: T) -> Self {
|
||||
Self {
|
||||
|
@ -153,6 +155,7 @@ impl<'a, 'b, 'c, 'info, T: Accounts<'info>> CpiStateContext<'a, 'b, 'c, 'info, T
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'a, 'b, 'c, 'info, T: Accounts<'info>> ToAccountMetas
|
||||
for CpiStateContext<'a, 'b, 'c, 'info, T>
|
||||
{
|
||||
|
@ -167,6 +170,7 @@ impl<'a, 'b, 'c, 'info, T: Accounts<'info>> ToAccountMetas
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'a, 'b, 'c, 'info, T: Accounts<'info>> ToAccountInfos<'info>
|
||||
for CpiStateContext<'a, 'b, 'c, 'info, T>
|
||||
{
|
||||
|
|
|
@ -9,11 +9,13 @@ use std::ops::{Deref, DerefMut};
|
|||
|
||||
/// Container for any account *not* owned by the current program.
|
||||
#[derive(Clone)]
|
||||
#[deprecated(note = "Please use Account instead")]
|
||||
pub struct CpiAccount<'a, T: AccountDeserialize + Clone> {
|
||||
info: AccountInfo<'a>,
|
||||
account: Box<T>,
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'a, T: AccountDeserialize + Clone> CpiAccount<'a, T> {
|
||||
fn new(info: AccountInfo<'a>, account: Box<T>) -> CpiAccount<'a, T> {
|
||||
Self { info, account }
|
||||
|
@ -41,6 +43,7 @@ impl<'a, T: AccountDeserialize + Clone> CpiAccount<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T> Accounts<'info> for CpiAccount<'info, T>
|
||||
where
|
||||
T: AccountDeserialize + Clone,
|
||||
|
@ -62,6 +65,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountDeserialize + Clone> ToAccountMetas for CpiAccount<'info, T> {
|
||||
fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
|
||||
let is_signer = is_signer.unwrap_or(self.info.is_signer);
|
||||
|
@ -73,24 +77,28 @@ impl<'info, T: AccountDeserialize + Clone> ToAccountMetas for CpiAccount<'info,
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountDeserialize + Clone> ToAccountInfos<'info> for CpiAccount<'info, T> {
|
||||
fn to_account_infos(&self) -> Vec<AccountInfo<'info>> {
|
||||
vec![self.info.clone()]
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountDeserialize + Clone> ToAccountInfo<'info> for CpiAccount<'info, T> {
|
||||
fn to_account_info(&self) -> AccountInfo<'info> {
|
||||
self.info.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountDeserialize + Clone> AsRef<AccountInfo<'info>> for CpiAccount<'info, T> {
|
||||
fn as_ref(&self) -> &AccountInfo<'info> {
|
||||
&self.info
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'a, T: AccountDeserialize + Clone> Deref for CpiAccount<'a, T> {
|
||||
type Target = T;
|
||||
|
||||
|
@ -99,12 +107,14 @@ impl<'a, T: AccountDeserialize + Clone> Deref for CpiAccount<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'a, T: AccountDeserialize + Clone> DerefMut for CpiAccount<'a, T> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.account
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountDeserialize + Clone> AccountsExit<'info> for CpiAccount<'info, T> {
|
||||
fn exit(&self, _program_id: &Pubkey) -> ProgramResult {
|
||||
// no-op
|
||||
|
@ -112,12 +122,14 @@ impl<'info, T: AccountDeserialize + Clone> AccountsExit<'info> for CpiAccount<'i
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountDeserialize + Clone> Key for CpiAccount<'info, T> {
|
||||
fn key(&self) -> Pubkey {
|
||||
*self.info.key
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T> From<Account<'info, T>> for CpiAccount<'info, T>
|
||||
where
|
||||
T: AccountSerialize + AccountDeserialize + Owner + Clone,
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
use crate::error::ErrorCode;
|
||||
use crate::{
|
||||
AccountDeserialize, AccountSerialize, Accounts, AccountsExit, CpiStateContext, Key,
|
||||
ProgramState, ToAccountInfo, ToAccountInfos, ToAccountMetas,
|
||||
AccountDeserialize, AccountSerialize, Accounts, AccountsExit, Key, ToAccountInfo,
|
||||
ToAccountInfos, ToAccountMetas,
|
||||
};
|
||||
#[allow(deprecated)]
|
||||
use crate::{CpiStateContext, ProgramState};
|
||||
use solana_program::account_info::AccountInfo;
|
||||
use solana_program::entrypoint::ProgramResult;
|
||||
use solana_program::instruction::AccountMeta;
|
||||
|
@ -13,6 +15,7 @@ use std::ops::{Deref, DerefMut};
|
|||
/// Boxed container for the program state singleton, used when the state
|
||||
/// is for a program not currently executing.
|
||||
#[derive(Clone)]
|
||||
#[deprecated]
|
||||
pub struct CpiState<'info, T: AccountSerialize + AccountDeserialize + Clone> {
|
||||
inner: Box<Inner<'info, T>>,
|
||||
}
|
||||
|
@ -23,6 +26,7 @@ struct Inner<'info, T: AccountSerialize + AccountDeserialize + Clone> {
|
|||
account: T,
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> CpiState<'info, T> {
|
||||
pub fn new(i: AccountInfo<'info>, account: T) -> CpiState<'info, T> {
|
||||
Self {
|
||||
|
@ -58,6 +62,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> CpiState<'info, T>
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T> Accounts<'info> for CpiState<'info, T>
|
||||
where
|
||||
T: AccountSerialize + AccountDeserialize + Clone,
|
||||
|
@ -81,6 +86,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountMetas
|
||||
for CpiState<'info, T>
|
||||
{
|
||||
|
@ -94,6 +100,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountMetas
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfos<'info>
|
||||
for CpiState<'info, T>
|
||||
{
|
||||
|
@ -102,6 +109,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfos<'in
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfo<'info>
|
||||
for CpiState<'info, T>
|
||||
{
|
||||
|
@ -110,6 +118,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfo<'inf
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<AccountInfo<'info>>
|
||||
for CpiState<'info, T>
|
||||
{
|
||||
|
@ -118,6 +127,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<AccountInfo<
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> Deref for CpiState<'info, T> {
|
||||
type Target = T;
|
||||
|
||||
|
@ -126,12 +136,14 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> Deref for CpiState
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> DerefMut for CpiState<'info, T> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut DerefMut::deref_mut(&mut self.inner).account
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AccountsExit<'info>
|
||||
for CpiState<'info, T>
|
||||
{
|
||||
|
@ -141,6 +153,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AccountsExit<'info
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> Key for CpiState<'info, T> {
|
||||
fn key(&self) -> Pubkey {
|
||||
*self.inner.info.key
|
||||
|
|
|
@ -50,11 +50,22 @@ mod sysvar;
|
|||
mod vec;
|
||||
|
||||
pub use crate::account::Account;
|
||||
pub use crate::context::{Context, CpiContext, CpiStateContext};
|
||||
#[doc(hidden)]
|
||||
#[allow(deprecated)]
|
||||
pub use crate::context::CpiStateContext;
|
||||
pub use crate::context::{Context, CpiContext};
|
||||
#[doc(hidden)]
|
||||
#[allow(deprecated)]
|
||||
pub use crate::cpi_account::CpiAccount;
|
||||
#[doc(hidden)]
|
||||
#[allow(deprecated)]
|
||||
pub use crate::cpi_state::CpiState;
|
||||
pub use crate::loader::Loader;
|
||||
#[doc(hidden)]
|
||||
#[allow(deprecated)]
|
||||
pub use crate::program_account::ProgramAccount;
|
||||
#[doc(hidden)]
|
||||
#[allow(deprecated)]
|
||||
pub use crate::state::ProgramState;
|
||||
pub use crate::sysvar::Sysvar;
|
||||
pub use anchor_attribute_access_control::access_control;
|
||||
|
@ -223,11 +234,13 @@ pub mod prelude {
|
|||
pub use super::{
|
||||
access_control, account, declare_id, emit, error, event, interface, program, require,
|
||||
state, zero_copy, Account, AccountDeserialize, AccountSerialize, Accounts, AccountsExit,
|
||||
AnchorDeserialize, AnchorSerialize, Context, CpiAccount, CpiContext, CpiState,
|
||||
CpiStateContext, Key, Loader, ProgramAccount, ProgramState, Sysvar, ToAccountInfo,
|
||||
ToAccountInfos, ToAccountMetas,
|
||||
AnchorDeserialize, AnchorSerialize, Context, CpiContext, Key, Loader, Owner,
|
||||
ProgramAccount, Sysvar, ToAccountInfo, ToAccountInfos, ToAccountMetas,
|
||||
};
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub use super::{CpiAccount, CpiState, CpiStateContext, ProgramState};
|
||||
|
||||
pub use borsh;
|
||||
pub use solana_program::account_info::{next_account_info, AccountInfo};
|
||||
pub use solana_program::entrypoint::ProgramResult;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use crate::error::ErrorCode;
|
||||
#[allow(deprecated)]
|
||||
use crate::CpiAccount;
|
||||
use crate::{
|
||||
AccountDeserialize, AccountSerialize, Accounts, AccountsClose, AccountsExit, CpiAccount, Key,
|
||||
AccountDeserialize, AccountSerialize, Accounts, AccountsClose, AccountsExit, Key,
|
||||
ToAccountInfo, ToAccountInfos, ToAccountMetas,
|
||||
};
|
||||
use solana_program::account_info::AccountInfo;
|
||||
|
@ -166,6 +168,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> DerefMut for ProgramA
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T> From<CpiAccount<'info, T>> for ProgramAccount<'info, T>
|
||||
where
|
||||
T: AccountSerialize + AccountDeserialize + Clone,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use crate::error::ErrorCode;
|
||||
#[allow(deprecated)]
|
||||
use crate::CpiAccount;
|
||||
use crate::{
|
||||
AccountDeserialize, AccountSerialize, Accounts, AccountsExit, CpiAccount, Key, ToAccountInfo,
|
||||
AccountDeserialize, AccountSerialize, Accounts, AccountsExit, Key, ToAccountInfo,
|
||||
ToAccountInfos, ToAccountMetas,
|
||||
};
|
||||
use solana_program::account_info::AccountInfo;
|
||||
|
@ -14,6 +16,7 @@ pub const PROGRAM_STATE_SEED: &str = "unversioned";
|
|||
|
||||
/// Boxed container for the program state singleton.
|
||||
#[derive(Clone)]
|
||||
#[deprecated]
|
||||
pub struct ProgramState<'info, T: AccountSerialize + AccountDeserialize + Clone> {
|
||||
inner: Box<Inner<'info, T>>,
|
||||
}
|
||||
|
@ -24,6 +27,8 @@ struct Inner<'info, T: AccountSerialize + AccountDeserialize + Clone> {
|
|||
account: T,
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
|
||||
impl<'a, T: AccountSerialize + AccountDeserialize + Clone> ProgramState<'a, T> {
|
||||
fn new(info: AccountInfo<'a>, account: T) -> ProgramState<'a, T> {
|
||||
Self {
|
||||
|
@ -60,6 +65,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> ProgramState<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T> Accounts<'info> for ProgramState<'info, T>
|
||||
where
|
||||
T: AccountSerialize + AccountDeserialize + Clone,
|
||||
|
@ -79,6 +85,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountMetas
|
||||
for ProgramState<'info, T>
|
||||
{
|
||||
|
@ -92,6 +99,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountMetas
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfos<'info>
|
||||
for ProgramState<'info, T>
|
||||
{
|
||||
|
@ -100,6 +108,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfos<'in
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfo<'info>
|
||||
for ProgramState<'info, T>
|
||||
{
|
||||
|
@ -108,6 +117,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfo<'inf
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<AccountInfo<'info>>
|
||||
for ProgramState<'info, T>
|
||||
{
|
||||
|
@ -116,6 +126,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<AccountInfo<
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Deref for ProgramState<'a, T> {
|
||||
type Target = T;
|
||||
|
||||
|
@ -124,12 +135,14 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Deref for ProgramStat
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'a, T: AccountSerialize + AccountDeserialize + Clone> DerefMut for ProgramState<'a, T> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut DerefMut::deref_mut(&mut self.inner).account
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T> From<CpiAccount<'info, T>> for ProgramState<'info, T>
|
||||
where
|
||||
T: AccountSerialize + AccountDeserialize + Clone,
|
||||
|
@ -139,6 +152,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AccountsExit<'info>
|
||||
for ProgramState<'info, T>
|
||||
{
|
||||
|
@ -159,6 +173,7 @@ pub fn address(program_id: &Pubkey) -> Pubkey {
|
|||
Pubkey::create_with_seed(&base, seed, owner).unwrap()
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'info, T: AccountSerialize + AccountDeserialize + Clone> Key for ProgramState<'info, T> {
|
||||
fn key(&self) -> Pubkey {
|
||||
*self.inner.info.key
|
||||
|
|
|
@ -10,17 +10,17 @@ declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
|
|||
#[derive(Accounts)]
|
||||
pub struct GenericsTest<'info, T, U, const N: usize>
|
||||
where
|
||||
T: AccountSerialize + AccountDeserialize + Clone,
|
||||
T: AccountSerialize + AccountDeserialize + Owner + Clone,
|
||||
U: BorshSerialize + BorshDeserialize + Default + Clone,
|
||||
{
|
||||
pub non_generic: AccountInfo<'info>,
|
||||
pub generic: ProgramAccount<'info, T>,
|
||||
pub const_generic: Loader<'info, Account<N>>,
|
||||
pub associated: CpiAccount<'info, Associated<U>>,
|
||||
pub generic: Account<'info, T>,
|
||||
pub const_generic: Loader<'info, FooAccount<N>>,
|
||||
pub associated: Account<'info, Associated<U>>,
|
||||
}
|
||||
|
||||
#[account(zero_copy)]
|
||||
pub struct Account<const N: usize> {
|
||||
pub struct FooAccount<const N: usize> {
|
||||
pub data: WrappedU8Array<N>,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue