light_sdk/instruction/
packed_accounts.rs1use std::ops::{Deref, DerefMut};
2
3use super::system_accounts::{get_light_system_account_metas, SystemAccountMetaConfig};
4
5type Inner = light_sdk_types::pack_accounts::PackedAccounts<solana_instruction::AccountMeta>;
6
7#[derive(Debug, Default)]
12pub struct PackedAccounts(pub Inner);
13
14impl Deref for PackedAccounts {
15 type Target = Inner;
16 fn deref(&self) -> &Self::Target {
17 &self.0
18 }
19}
20
21impl DerefMut for PackedAccounts {
22 fn deref_mut(&mut self) -> &mut Self::Target {
23 &mut self.0
24 }
25}
26
27impl From<Inner> for PackedAccounts {
28 fn from(inner: Inner) -> Self {
29 Self(inner)
30 }
31}
32
33impl From<PackedAccounts> for Inner {
34 fn from(wrapper: PackedAccounts) -> Self {
35 wrapper.0
36 }
37}
38
39impl PackedAccounts {
40 pub fn new_with_system_accounts(config: SystemAccountMetaConfig) -> crate::error::Result<Self> {
44 let mut accounts = Self::default();
45 accounts.add_system_accounts(config)?;
46 Ok(accounts)
47 }
48
49 pub fn add_system_accounts(
56 &mut self,
57 config: SystemAccountMetaConfig,
58 ) -> crate::error::Result<()> {
59 self.0
60 .add_system_accounts_raw(get_light_system_account_metas(config));
61 Ok(())
62 }
63
64 #[cfg(feature = "v2")]
71 pub fn add_system_accounts_v2(
72 &mut self,
73 config: SystemAccountMetaConfig,
74 ) -> crate::error::Result<()> {
75 self.0
76 .add_system_accounts_raw(super::system_accounts::get_light_system_account_metas_v2(
77 config,
78 ));
79 Ok(())
80 }
81}