-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solana: Add SPL Multisig wrapper for
InterfaceAccount
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 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
37 changes: 37 additions & 0 deletions
37
solana/programs/example-native-token-transfers/src/spl_multisig.rs
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,37 @@ | ||
use anchor_lang::{prelude::*, solana_program::program_pack::Pack, Ids, Owners}; | ||
use anchor_spl::token_interface::TokenInterface; | ||
use std::ops::Deref; | ||
|
||
/// Anchor does not have a SPL Multisig wrapper as a part of the token interface: | ||
/// https://docs.rs/anchor-spl/0.29.0/src/anchor_spl/token_interface.rs.html | ||
/// Thus, we have to write our own wrapper to use with `InterfaceAccount` | ||
#[derive(Clone, Debug, Default, PartialEq)] | ||
pub struct SplMultisig(spl_token_2022::state::Multisig); | ||
|
||
impl AccountDeserialize for SplMultisig { | ||
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> { | ||
spl_token_2022::state::Multisig::unpack(buf) | ||
.map(|t| SplMultisig(t)) | ||
.map_err(Into::into) | ||
} | ||
} | ||
|
||
impl AccountSerialize for SplMultisig {} | ||
|
||
impl Owners for SplMultisig { | ||
fn owners() -> &'static [Pubkey] { | ||
TokenInterface::ids() | ||
} | ||
} | ||
|
||
impl Deref for SplMultisig { | ||
type Target = spl_token_2022::state::Multisig; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
#[cfg(feature = "idl-build")] | ||
impl anchor_lang::IdlBuild for SplMultisig {} |