update
This commit is contained in:
parent
f71ff97eb6
commit
3601add947
|
@ -406,3 +406,10 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Owner + Clone> DerefMut for
|
|||
&mut self.account
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "deprecated-layout"))]
|
||||
impl<'a, T: AccountSerialize + AccountDeserialize + Owner + Clone> Bump for Account<'a, T> {
|
||||
fn seed(&self) -> u8 {
|
||||
self.info.data.borrow()[1]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
//! Type facilitating on demand zero copy deserialization.
|
||||
|
||||
use crate::error::ErrorCode;
|
||||
use crate::{
|
||||
Accounts, AccountsClose, AccountsExit, Bump, Owner, ToAccountInfo, ToAccountInfos,
|
||||
ToAccountMetas, ZeroCopy,
|
||||
};
|
||||
use crate::*;
|
||||
use arrayref::array_ref;
|
||||
use solana_program::account_info::AccountInfo;
|
||||
use solana_program::entrypoint::ProgramResult;
|
||||
|
@ -245,11 +242,8 @@ impl<'info, T: ZeroCopy + Owner> ToAccountInfos<'info> for AccountLoader<'info,
|
|||
}
|
||||
|
||||
#[cfg(not(feature = "deprecated-layout"))]
|
||||
impl<'info, T> Bump for T
|
||||
where
|
||||
T: AsRef<AccountInfo<'info>>,
|
||||
{
|
||||
impl<'a, T: ZeroCopy + Owner> Bump for AccountLoader<'a, T> {
|
||||
fn seed(&self) -> u8 {
|
||||
self.as_ref().data.borrow()[1]
|
||||
self.acc_info.data.borrow()[1]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use crate::error::ErrorCode;
|
||||
use crate::{
|
||||
Accounts, AccountsClose, AccountsExit, ToAccountInfo, ToAccountInfos, ToAccountMetas, ZeroCopy,
|
||||
};
|
||||
use crate::*;
|
||||
use arrayref::array_ref;
|
||||
use solana_program::account_info::AccountInfo;
|
||||
use solana_program::entrypoint::ProgramResult;
|
||||
|
@ -189,3 +187,10 @@ impl<'info, T: ZeroCopy> ToAccountInfos<'info> for Loader<'info, T> {
|
|||
vec![self.acc_info.clone()]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "deprecated-layout"))]
|
||||
impl<'a, T: ZeroCopy> Bump for Loader<'a, T> {
|
||||
fn seed(&self) -> u8 {
|
||||
self.acc_info.data.borrow()[1]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
#[allow(deprecated)]
|
||||
use crate::accounts::cpi_account::CpiAccount;
|
||||
use crate::error::ErrorCode;
|
||||
use crate::{
|
||||
AccountDeserialize, AccountSerialize, Accounts, AccountsClose, AccountsExit, ToAccountInfo,
|
||||
ToAccountInfos, ToAccountMetas,
|
||||
};
|
||||
use crate::*;
|
||||
use solana_program::account_info::AccountInfo;
|
||||
use solana_program::entrypoint::ProgramResult;
|
||||
use solana_program::instruction::AccountMeta;
|
||||
|
@ -182,3 +179,10 @@ where
|
|||
Self::new(a.to_account_info(), Deref::deref(&a).clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "deprecated-layout"))]
|
||||
impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Bump for ProgramAccount<'a, T> {
|
||||
fn seed(&self) -> u8 {
|
||||
self.inner.info.data.borrow()[1]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,10 +142,6 @@ fn generate_constraint_address(f: &Field, c: &ConstraintAddress) -> proc_macro2:
|
|||
}
|
||||
}
|
||||
|
||||
pub fn generate_constraint_init(f: &Field, c: &ConstraintInitGroup) -> proc_macro2::TokenStream {
|
||||
generate_constraint_init_group(f, c)
|
||||
}
|
||||
|
||||
pub fn generate_constraint_zeroed(f: &Field, _c: &ConstraintZeroed) -> proc_macro2::TokenStream {
|
||||
let field = &f.ident;
|
||||
let ty_decl = f.ty_decl();
|
||||
|
@ -304,54 +300,6 @@ pub fn generate_constraint_rent_exempt(
|
|||
}
|
||||
}
|
||||
|
||||
fn generate_constraint_init_group(f: &Field, c: &ConstraintInitGroup) -> proc_macro2::TokenStream {
|
||||
let payer = {
|
||||
let p = &c.payer;
|
||||
quote! {
|
||||
let payer = #p.to_account_info();
|
||||
}
|
||||
};
|
||||
|
||||
let seeds_with_nonce = match &c.seeds {
|
||||
None => quote! {},
|
||||
Some(c) => {
|
||||
let s = &mut c.seeds.clone();
|
||||
// If the seeds came with a trailing comma, we need to chop it off
|
||||
// before we interpolate them below.
|
||||
if let Some(pair) = s.pop() {
|
||||
s.push_value(pair.into_value());
|
||||
}
|
||||
let maybe_seeds_plus_comma = (!s.is_empty()).then(|| {
|
||||
quote! { #s, }
|
||||
});
|
||||
let inner = match c.bump.as_ref() {
|
||||
// Bump target not given. Use the canonical bump.
|
||||
None => {
|
||||
quote! {
|
||||
[
|
||||
#maybe_seeds_plus_comma
|
||||
&[
|
||||
Pubkey::find_program_address(
|
||||
&[#s],
|
||||
program_id,
|
||||
).1
|
||||
][..]
|
||||
]
|
||||
}
|
||||
}
|
||||
// Bump target given. Use it.
|
||||
Some(b) => quote! {
|
||||
[#maybe_seeds_plus_comma &[#b][..]]
|
||||
},
|
||||
};
|
||||
quote! {
|
||||
&#inner[..]
|
||||
}
|
||||
}
|
||||
};
|
||||
generate_init(f, c.if_needed, seeds_with_nonce, payer, &c.space, &c.kind)
|
||||
}
|
||||
|
||||
fn generate_constraint_seeds(f: &Field, c: &ConstraintSeedsGroup) -> proc_macro2::TokenStream {
|
||||
let name = &f.ident;
|
||||
let s = &mut c.seeds.clone();
|
||||
|
@ -442,6 +390,54 @@ fn generate_constraint_associated_token(
|
|||
}
|
||||
}
|
||||
|
||||
fn generate_constraint_init(f: &Field, c: &ConstraintInitGroup) -> proc_macro2::TokenStream {
|
||||
let payer = {
|
||||
let p = &c.payer;
|
||||
quote! {
|
||||
let payer = #p.to_account_info();
|
||||
}
|
||||
};
|
||||
|
||||
let seeds_with_nonce = match &c.seeds {
|
||||
None => quote! {},
|
||||
Some(c) => {
|
||||
let s = &mut c.seeds.clone();
|
||||
// If the seeds came with a trailing comma, we need to chop it off
|
||||
// before we interpolate them below.
|
||||
if let Some(pair) = s.pop() {
|
||||
s.push_value(pair.into_value());
|
||||
}
|
||||
let maybe_seeds_plus_comma = (!s.is_empty()).then(|| {
|
||||
quote! { #s, }
|
||||
});
|
||||
let inner = match c.bump.as_ref() {
|
||||
// Bump target not given. Use the canonical bump.
|
||||
None => {
|
||||
quote! {
|
||||
[
|
||||
#maybe_seeds_plus_comma
|
||||
&[
|
||||
Pubkey::find_program_address(
|
||||
&[#s],
|
||||
program_id,
|
||||
).1
|
||||
][..]
|
||||
]
|
||||
}
|
||||
}
|
||||
// Bump target given. Use it.
|
||||
Some(b) => quote! {
|
||||
[#maybe_seeds_plus_comma &[#b][..]]
|
||||
},
|
||||
};
|
||||
quote! {
|
||||
&#inner[..]
|
||||
}
|
||||
}
|
||||
};
|
||||
generate_init(f, c.if_needed, seeds_with_nonce, payer, &c.space, &c.kind)
|
||||
}
|
||||
|
||||
// `if_needed` is set if account allocation and initialization is optional.
|
||||
pub fn generate_init(
|
||||
f: &Field,
|
||||
|
|
|
@ -5,6 +5,7 @@ pub mod file;
|
|||
pub mod pda;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Idl {
|
||||
// Version of the idl protocol.
|
||||
pub layout_version: String,
|
||||
|
|
Loading…
Reference in New Issue