spl: add feature memo to support cpi to spl-memo (#2661)

This commit is contained in:
0xWoo 2023-10-12 19:23:35 -04:00 committed by GitHub
parent 0fef819e4b
commit 23eeb1ec2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 0 deletions

View File

@ -32,6 +32,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- lang: Add support for type aliases in IDLs ([#2637](https://github.com/coral-xyz/anchor/pull/2637)).
- cli: Add `test.upgradeable`, `test.genesis.upgradeable` setting in anchor.toml to support testing upgradeable programs ([#2641](https://github.com/coral-xyz/anchor/pull/2642)).
- cli, client, lang, spl: Update Solana toolchain and dependencies to `1.17.0`, `1.16` remains supported ([#2645](https://github.com/coral-xyz/anchor/pull/2645)).
- spl: Add support for memo program ([#2660](https://github.com/coral-xyz/anchor/issues/2660)).
### Fixes

1
Cargo.lock generated
View File

@ -290,6 +290,7 @@ dependencies = [
"serum_dex",
"solana-program",
"spl-associated-token-account",
"spl-memo",
"spl-token 4.0.0",
"spl-token-2022",
]

View File

@ -20,6 +20,7 @@ shmem = []
stake = ["borsh"]
token = ["spl-token"]
token_2022 = ["spl-token-2022"]
memo = ["spl-memo"]
[dependencies]
anchor-lang = { path = "../lang", version = "0.28.0", features = ["derive"] }
@ -30,3 +31,4 @@ solana-program = ">=1.16, <1.18"
spl-associated-token-account = { version = "2.2", features = ["no-entrypoint"], optional = true }
spl-token = { version = "4", features = ["no-entrypoint"], optional = true }
spl-token-2022 = { version = "0.9", features = ["no-entrypoint"], optional = true }
spl-memo = { version = "4", features = ["no-entrypoint"], optional = true }

View File

@ -27,3 +27,6 @@ pub mod stake;
#[cfg(feature = "metadata")]
pub mod metadata;
#[cfg(feature = "memo")]
pub mod memo;

30
spl/src/memo.rs Normal file
View File

@ -0,0 +1,30 @@
use anchor_lang::solana_program::pubkey::Pubkey;
use anchor_lang::Result;
use anchor_lang::{context::CpiContext, Accounts};
pub use spl_memo;
pub use spl_memo::ID;
pub fn build_memo<'info>(ctx: CpiContext<'_, '_, '_, 'info, BuildMemo>, memo: &[u8]) -> Result<()> {
let ix = spl_memo::build_memo(
memo,
&ctx.remaining_accounts
.iter()
.map(|account| account.key)
.collect::<Vec<_>>(),
);
solana_program::program::invoke_signed(&ix, &ctx.remaining_accounts, ctx.signer_seeds)
.map_err(Into::into)
}
#[derive(Accounts)]
pub struct BuildMemo {}
#[derive(Clone)]
pub struct Memo;
impl anchor_lang::Id for Memo {
fn id() -> Pubkey {
ID
}
}