-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lang, spl, cli: Add associated_token keyword (#790)
- Loading branch information
1 parent
6583742
commit 2c827bc
Showing
12 changed files
with
276 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use anchor_lang::solana_program::account_info::AccountInfo; | ||
use anchor_lang::solana_program::entrypoint::ProgramResult; | ||
use anchor_lang::solana_program::program_error::ProgramError; | ||
use anchor_lang::solana_program::pubkey::Pubkey; | ||
use anchor_lang::{Accounts, CpiContext}; | ||
|
||
pub use spl_associated_token_account::ID; | ||
|
||
pub fn create<'info>(ctx: CpiContext<'_, '_, '_, 'info, Create<'info>>) -> ProgramResult { | ||
let ix = spl_associated_token_account::create_associated_token_account( | ||
ctx.accounts.payer.key, | ||
ctx.accounts.authority.key, | ||
ctx.accounts.mint.key, | ||
); | ||
solana_program::program::invoke_signed( | ||
&ix, | ||
&[ | ||
ctx.accounts.payer, | ||
ctx.accounts.associated_token, | ||
ctx.accounts.authority, | ||
ctx.accounts.mint, | ||
ctx.accounts.system_program, | ||
ctx.accounts.token_program, | ||
ctx.accounts.rent, | ||
], | ||
ctx.signer_seeds, | ||
) | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct Create<'info> { | ||
pub payer: AccountInfo<'info>, | ||
pub associated_token: AccountInfo<'info>, | ||
pub authority: AccountInfo<'info>, | ||
pub mint: AccountInfo<'info>, | ||
pub system_program: AccountInfo<'info>, | ||
pub token_program: AccountInfo<'info>, | ||
pub rent: AccountInfo<'info>, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct AssociatedToken; | ||
|
||
impl anchor_lang::AccountDeserialize for AssociatedToken { | ||
fn try_deserialize(buf: &mut &[u8]) -> Result<Self, ProgramError> { | ||
AssociatedToken::try_deserialize_unchecked(buf) | ||
} | ||
|
||
fn try_deserialize_unchecked(_buf: &mut &[u8]) -> Result<Self, ProgramError> { | ||
Ok(AssociatedToken) | ||
} | ||
} | ||
|
||
impl anchor_lang::Id for AssociatedToken { | ||
fn id() -> Pubkey { | ||
ID | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod associated_token; | ||
pub mod dex; | ||
pub mod mint; | ||
pub mod shmem; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.