spl_memo_client/generated/instructions/
add_memo.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use kaigan::types::RemainderStr;
11
12/// Accounts.
13pub struct AddMemo {}
14
15impl AddMemo {
16    pub fn instruction(
17        &self,
18        args: AddMemoInstructionArgs,
19    ) -> solana_program::instruction::Instruction {
20        self.instruction_with_remaining_accounts(args, &[])
21    }
22    #[allow(clippy::vec_init_then_push)]
23    pub fn instruction_with_remaining_accounts(
24        &self,
25        args: AddMemoInstructionArgs,
26        remaining_accounts: &[solana_program::instruction::AccountMeta],
27    ) -> solana_program::instruction::Instruction {
28        let mut accounts = Vec::with_capacity(remaining_accounts.len());
29        accounts.extend_from_slice(remaining_accounts);
30        let mut data = AddMemoInstructionData::new().try_to_vec().unwrap();
31        let mut args = args.try_to_vec().unwrap();
32        data.append(&mut args);
33
34        solana_program::instruction::Instruction {
35            program_id: crate::MEMO_ID,
36            accounts,
37            data,
38        }
39    }
40}
41
42#[derive(BorshDeserialize, BorshSerialize)]
43pub struct AddMemoInstructionData {}
44
45impl AddMemoInstructionData {
46    pub fn new() -> Self {
47        Self {}
48    }
49}
50
51impl Default for AddMemoInstructionData {
52    fn default() -> Self {
53        Self::new()
54    }
55}
56
57#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
58#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
59pub struct AddMemoInstructionArgs {
60    pub memo: RemainderStr,
61}
62
63/// Instruction builder for `AddMemo`.
64///
65/// ### Accounts:
66///
67#[derive(Clone, Debug, Default)]
68pub struct AddMemoBuilder {
69    memo: Option<RemainderStr>,
70    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
71}
72
73impl AddMemoBuilder {
74    pub fn new() -> Self {
75        Self::default()
76    }
77    #[inline(always)]
78    pub fn memo(&mut self, memo: RemainderStr) -> &mut Self {
79        self.memo = Some(memo);
80        self
81    }
82    /// Add an additional account to the instruction.
83    #[inline(always)]
84    pub fn add_remaining_account(
85        &mut self,
86        account: solana_program::instruction::AccountMeta,
87    ) -> &mut Self {
88        self.__remaining_accounts.push(account);
89        self
90    }
91    /// Add additional accounts to the instruction.
92    #[inline(always)]
93    pub fn add_remaining_accounts(
94        &mut self,
95        accounts: &[solana_program::instruction::AccountMeta],
96    ) -> &mut Self {
97        self.__remaining_accounts.extend_from_slice(accounts);
98        self
99    }
100    #[allow(clippy::clone_on_copy)]
101    pub fn instruction(&self) -> solana_program::instruction::Instruction {
102        let accounts = AddMemo {};
103        let args = AddMemoInstructionArgs {
104            memo: self.memo.clone().expect("memo is not set"),
105        };
106
107        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
108    }
109}
110
111/// `add_memo` CPI instruction.
112pub struct AddMemoCpi<'a, 'b> {
113    /// The program to invoke.
114    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
115    /// The arguments for the instruction.
116    pub __args: AddMemoInstructionArgs,
117}
118
119impl<'a, 'b> AddMemoCpi<'a, 'b> {
120    pub fn new(
121        program: &'b solana_program::account_info::AccountInfo<'a>,
122        args: AddMemoInstructionArgs,
123    ) -> Self {
124        Self {
125            __program: program,
126            __args: args,
127        }
128    }
129    #[inline(always)]
130    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
131        self.invoke_signed_with_remaining_accounts(&[], &[])
132    }
133    #[inline(always)]
134    pub fn invoke_with_remaining_accounts(
135        &self,
136        remaining_accounts: &[(
137            &'b solana_program::account_info::AccountInfo<'a>,
138            bool,
139            bool,
140        )],
141    ) -> solana_program::entrypoint::ProgramResult {
142        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
143    }
144    #[inline(always)]
145    pub fn invoke_signed(
146        &self,
147        signers_seeds: &[&[&[u8]]],
148    ) -> solana_program::entrypoint::ProgramResult {
149        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
150    }
151    #[allow(clippy::clone_on_copy)]
152    #[allow(clippy::vec_init_then_push)]
153    pub fn invoke_signed_with_remaining_accounts(
154        &self,
155        signers_seeds: &[&[&[u8]]],
156        remaining_accounts: &[(
157            &'b solana_program::account_info::AccountInfo<'a>,
158            bool,
159            bool,
160        )],
161    ) -> solana_program::entrypoint::ProgramResult {
162        let mut accounts = Vec::with_capacity(remaining_accounts.len());
163        remaining_accounts.iter().for_each(|remaining_account| {
164            accounts.push(solana_program::instruction::AccountMeta {
165                pubkey: *remaining_account.0.key,
166                is_signer: remaining_account.1,
167                is_writable: remaining_account.2,
168            })
169        });
170        let mut data = AddMemoInstructionData::new().try_to_vec().unwrap();
171        let mut args = self.__args.try_to_vec().unwrap();
172        data.append(&mut args);
173
174        let instruction = solana_program::instruction::Instruction {
175            program_id: crate::MEMO_ID,
176            accounts,
177            data,
178        };
179        let mut account_infos = Vec::with_capacity(1 + remaining_accounts.len());
180        account_infos.push(self.__program.clone());
181        remaining_accounts
182            .iter()
183            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
184
185        if signers_seeds.is_empty() {
186            solana_program::program::invoke(&instruction, &account_infos)
187        } else {
188            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
189        }
190    }
191}
192
193/// Instruction builder for `AddMemo` via CPI.
194///
195/// ### Accounts:
196///
197#[derive(Clone, Debug)]
198pub struct AddMemoCpiBuilder<'a, 'b> {
199    instruction: Box<AddMemoCpiBuilderInstruction<'a, 'b>>,
200}
201
202impl<'a, 'b> AddMemoCpiBuilder<'a, 'b> {
203    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
204        let instruction = Box::new(AddMemoCpiBuilderInstruction {
205            __program: program,
206            memo: None,
207            __remaining_accounts: Vec::new(),
208        });
209        Self { instruction }
210    }
211    #[inline(always)]
212    pub fn memo(&mut self, memo: RemainderStr) -> &mut Self {
213        self.instruction.memo = Some(memo);
214        self
215    }
216    /// Add an additional account to the instruction.
217    #[inline(always)]
218    pub fn add_remaining_account(
219        &mut self,
220        account: &'b solana_program::account_info::AccountInfo<'a>,
221        is_writable: bool,
222        is_signer: bool,
223    ) -> &mut Self {
224        self.instruction
225            .__remaining_accounts
226            .push((account, is_writable, is_signer));
227        self
228    }
229    /// Add additional accounts to the instruction.
230    ///
231    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
232    /// and a `bool` indicating whether the account is a signer or not.
233    #[inline(always)]
234    pub fn add_remaining_accounts(
235        &mut self,
236        accounts: &[(
237            &'b solana_program::account_info::AccountInfo<'a>,
238            bool,
239            bool,
240        )],
241    ) -> &mut Self {
242        self.instruction
243            .__remaining_accounts
244            .extend_from_slice(accounts);
245        self
246    }
247    #[inline(always)]
248    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
249        self.invoke_signed(&[])
250    }
251    #[allow(clippy::clone_on_copy)]
252    #[allow(clippy::vec_init_then_push)]
253    pub fn invoke_signed(
254        &self,
255        signers_seeds: &[&[&[u8]]],
256    ) -> solana_program::entrypoint::ProgramResult {
257        let args = AddMemoInstructionArgs {
258            memo: self.instruction.memo.clone().expect("memo is not set"),
259        };
260        let instruction = AddMemoCpi {
261            __program: self.instruction.__program,
262            __args: args,
263        };
264        instruction.invoke_signed_with_remaining_accounts(
265            signers_seeds,
266            &self.instruction.__remaining_accounts,
267        )
268    }
269}
270
271#[derive(Clone, Debug)]
272struct AddMemoCpiBuilderInstruction<'a, 'b> {
273    __program: &'b solana_program::account_info::AccountInfo<'a>,
274    memo: Option<RemainderStr>,
275    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
276    __remaining_accounts: Vec<(
277        &'b solana_program::account_info::AccountInfo<'a>,
278        bool,
279        bool,
280    )>,
281}