Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add anchor bindings anchor-lang #3440

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ borsh = "0.10.3"
bytemuck = "1"
solana-program = "2"
thiserror = "1"
shrinkwraprs = "0.3.0"
mgild marked this conversation as resolved.
Show resolved Hide resolved
39 changes: 39 additions & 0 deletions lang/src/address_lookup_table_program.rs
mgild marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::prelude::*;
use crate::solana_program::address_lookup_table;
use solana_program::pubkey::Pubkey;
use solana_program::address_lookup_table::state::AddressLookupTable as SolanaAddressLookupTable;

#[derive(Debug, Clone)]
pub struct AddressLookupTable;
impl anchor_lang::Id for AddressLookupTable {
fn id() -> Pubkey {
address_lookup_table::program::ID
}
}

#[derive(Clone, shrinkwraprs::Shrinkwrap)]
mgild marked this conversation as resolved.
Show resolved Hide resolved
pub struct AddressLookupTableAccount<'info>(pub SolanaAddressLookupTable<'info>);
mgild marked this conversation as resolved.
Show resolved Hide resolved

impl AccountSerialize for AddressLookupTableAccount<'_> {}

impl<'info> AccountDeserialize for AddressLookupTableAccount<'info> {
fn try_deserialize_unchecked(buf: &mut &[u8]) -> Result<Self> {
// Deserialize into the temporary struct
let table = SolanaAddressLookupTable::deserialize(buf)
.map_err(|_| ProgramError::InvalidAccountData)?;

// Construct a new AddressLookupTable with a lifetime tied to 'info
let new_table = SolanaAddressLookupTable {
meta: table.meta,
addresses: std::borrow::Cow::Owned(table.addresses.into_owned()),
};

Ok(Self(new_table))
}
}

impl Owner for AddressLookupTableAccount<'_> {
fn owner() -> Pubkey {
address_lookup_table::program::ID
}
}
1 change: 1 addition & 0 deletions lang/src/lib.rs
mgild marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub mod event;
pub mod idl;
pub mod system_program;
mod vec;
pub mod address_lookup_table_program;
mgild marked this conversation as resolved.
Show resolved Hide resolved

#[cfg(feature = "lazy-account")]
mod lazy;
Expand Down