Skip to content

Commit e2c6d0c

Browse files
committed
solana: Add SPL Multisig wrapper for InterfaceAccount
1 parent c996e9e commit e2c6d0c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

solana/programs/example-native-token-transfers/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub mod messages;
2020
pub mod peer;
2121
pub mod queue;
2222
pub mod registered_transceiver;
23+
pub mod spl_multisig;
2324
pub mod transceivers;
2425
pub mod transfer;
2526

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use anchor_lang::{prelude::*, solana_program::program_pack::Pack, Ids, Owners};
2+
use anchor_spl::token_interface::TokenInterface;
3+
use std::ops::Deref;
4+
5+
/// Anchor does not have a SPL Multisig wrapper as a part of the token interface:
6+
/// https://docs.rs/anchor-spl/0.29.0/src/anchor_spl/token_interface.rs.html
7+
/// Thus, we have to write our own wrapper to use with `InterfaceAccount`
8+
9+
#[derive(Clone, Debug, Default, PartialEq)]
10+
pub struct SplMultisig(spl_token_2022::state::Multisig);
11+
12+
impl AccountDeserialize for SplMultisig {
13+
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
14+
spl_token_2022::state::Multisig::unpack(buf)
15+
.map(|t| SplMultisig(t))
16+
.map_err(Into::into)
17+
}
18+
}
19+
20+
impl AccountSerialize for SplMultisig {}
21+
22+
impl Owners for SplMultisig {
23+
fn owners() -> &'static [Pubkey] {
24+
TokenInterface::ids()
25+
}
26+
}
27+
28+
impl Deref for SplMultisig {
29+
type Target = spl_token_2022::state::Multisig;
30+
31+
fn deref(&self) -> &Self::Target {
32+
&self.0
33+
}
34+
}
35+
36+
#[cfg(feature = "idl-build")]
37+
impl anchor_lang::IdlBuild for SplMultisig {}

0 commit comments

Comments
 (0)