Skip to content

Commit

Permalink
spl: add feature memo to support cpi to spl-memo (#2661)
Browse files Browse the repository at this point in the history
  • Loading branch information
kAsky53 authored Oct 12, 2023
1 parent 0fef819 commit 23eeb1e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions spl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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 }
3 changes: 3 additions & 0 deletions spl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ pub mod stake;

#[cfg(feature = "metadata")]
pub mod metadata;

#[cfg(feature = "memo")]
pub mod memo;
30 changes: 30 additions & 0 deletions spl/src/memo.rs
Original file line number Diff line number Diff line change
@@ -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
}
}

1 comment on commit 23eeb1e

@vercel
Copy link

@vercel vercel bot commented on 23eeb1e Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

anchor-docs – ./

anchor-docs-200ms.vercel.app
anchor-docs-git-master-200ms.vercel.app
www.anchor-lang.com
anchor-lang.com

Please sign in to comment.