Skip to content

Commit

Permalink
solana: Add SPL Multisig wrapper for InterfaceAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
nvsriram committed Dec 14, 2024
1 parent c996e9e commit e2c6d0c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions solana/programs/example-native-token-transfers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod messages;
pub mod peer;
pub mod queue;
pub mod registered_transceiver;
pub mod spl_multisig;
pub mod transceivers;
pub mod transfer;

Expand Down
37 changes: 37 additions & 0 deletions solana/programs/example-native-token-transfers/src/spl_multisig.rs
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 {}

0 comments on commit e2c6d0c

Please sign in to comment.