mpl_token_metadata/generated/instructions/
puff_metadata.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct PuffMetadata {
13 pub metadata: solana_program::pubkey::Pubkey,
15}
16
17impl PuffMetadata {
18 pub fn instruction(&self) -> solana_program::instruction::Instruction {
19 self.instruction_with_remaining_accounts(&[])
20 }
21 #[allow(clippy::vec_init_then_push)]
22 pub fn instruction_with_remaining_accounts(
23 &self,
24 remaining_accounts: &[solana_program::instruction::AccountMeta],
25 ) -> solana_program::instruction::Instruction {
26 let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
27 accounts.push(solana_program::instruction::AccountMeta::new(
28 self.metadata,
29 false,
30 ));
31 accounts.extend_from_slice(remaining_accounts);
32 let data = PuffMetadataInstructionData::new().try_to_vec().unwrap();
33
34 solana_program::instruction::Instruction {
35 program_id: crate::MPL_TOKEN_METADATA_ID,
36 accounts,
37 data,
38 }
39 }
40}
41
42#[derive(BorshDeserialize, BorshSerialize)]
43struct PuffMetadataInstructionData {
44 discriminator: u8,
45}
46
47impl PuffMetadataInstructionData {
48 fn new() -> Self {
49 Self { discriminator: 14 }
50 }
51}
52
53#[derive(Default)]
59pub struct PuffMetadataBuilder {
60 metadata: Option<solana_program::pubkey::Pubkey>,
61 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
62}
63
64impl PuffMetadataBuilder {
65 pub fn new() -> Self {
66 Self::default()
67 }
68 #[inline(always)]
70 pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
71 self.metadata = Some(metadata);
72 self
73 }
74 #[inline(always)]
76 pub fn add_remaining_account(
77 &mut self,
78 account: solana_program::instruction::AccountMeta,
79 ) -> &mut Self {
80 self.__remaining_accounts.push(account);
81 self
82 }
83 #[inline(always)]
85 pub fn add_remaining_accounts(
86 &mut self,
87 accounts: &[solana_program::instruction::AccountMeta],
88 ) -> &mut Self {
89 self.__remaining_accounts.extend_from_slice(accounts);
90 self
91 }
92 #[allow(clippy::clone_on_copy)]
93 pub fn instruction(&self) -> solana_program::instruction::Instruction {
94 let accounts = PuffMetadata {
95 metadata: self.metadata.expect("metadata is not set"),
96 };
97
98 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
99 }
100}
101
102pub struct PuffMetadataCpiAccounts<'a, 'b> {
104 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
106}
107
108pub struct PuffMetadataCpi<'a, 'b> {
110 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
112 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
114}
115
116impl<'a, 'b> PuffMetadataCpi<'a, 'b> {
117 pub fn new(
118 program: &'b solana_program::account_info::AccountInfo<'a>,
119 accounts: PuffMetadataCpiAccounts<'a, 'b>,
120 ) -> Self {
121 Self {
122 __program: program,
123 metadata: accounts.metadata,
124 }
125 }
126 #[inline(always)]
127 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
128 self.invoke_signed_with_remaining_accounts(&[], &[])
129 }
130 #[inline(always)]
131 pub fn invoke_with_remaining_accounts(
132 &self,
133 remaining_accounts: &[(
134 &'b solana_program::account_info::AccountInfo<'a>,
135 bool,
136 bool,
137 )],
138 ) -> solana_program::entrypoint::ProgramResult {
139 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
140 }
141 #[inline(always)]
142 pub fn invoke_signed(
143 &self,
144 signers_seeds: &[&[&[u8]]],
145 ) -> solana_program::entrypoint::ProgramResult {
146 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
147 }
148 #[allow(clippy::clone_on_copy)]
149 #[allow(clippy::vec_init_then_push)]
150 pub fn invoke_signed_with_remaining_accounts(
151 &self,
152 signers_seeds: &[&[&[u8]]],
153 remaining_accounts: &[(
154 &'b solana_program::account_info::AccountInfo<'a>,
155 bool,
156 bool,
157 )],
158 ) -> solana_program::entrypoint::ProgramResult {
159 let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
160 accounts.push(solana_program::instruction::AccountMeta::new(
161 *self.metadata.key,
162 false,
163 ));
164 remaining_accounts.iter().for_each(|remaining_account| {
165 accounts.push(solana_program::instruction::AccountMeta {
166 pubkey: *remaining_account.0.key,
167 is_signer: remaining_account.1,
168 is_writable: remaining_account.2,
169 })
170 });
171 let data = PuffMetadataInstructionData::new().try_to_vec().unwrap();
172
173 let instruction = solana_program::instruction::Instruction {
174 program_id: crate::MPL_TOKEN_METADATA_ID,
175 accounts,
176 data,
177 };
178 let mut account_infos = Vec::with_capacity(1 + 1 + remaining_accounts.len());
179 account_infos.push(self.__program.clone());
180 account_infos.push(self.metadata.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
193pub struct PuffMetadataCpiBuilder<'a, 'b> {
199 instruction: Box<PuffMetadataCpiBuilderInstruction<'a, 'b>>,
200}
201
202impl<'a, 'b> PuffMetadataCpiBuilder<'a, 'b> {
203 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
204 let instruction = Box::new(PuffMetadataCpiBuilderInstruction {
205 __program: program,
206 metadata: None,
207 __remaining_accounts: Vec::new(),
208 });
209 Self { instruction }
210 }
211 #[inline(always)]
213 pub fn metadata(
214 &mut self,
215 metadata: &'b solana_program::account_info::AccountInfo<'a>,
216 ) -> &mut Self {
217 self.instruction.metadata = Some(metadata);
218 self
219 }
220 #[inline(always)]
222 pub fn add_remaining_account(
223 &mut self,
224 account: &'b solana_program::account_info::AccountInfo<'a>,
225 is_writable: bool,
226 is_signer: bool,
227 ) -> &mut Self {
228 self.instruction
229 .__remaining_accounts
230 .push((account, is_writable, is_signer));
231 self
232 }
233 #[inline(always)]
238 pub fn add_remaining_accounts(
239 &mut self,
240 accounts: &[(
241 &'b solana_program::account_info::AccountInfo<'a>,
242 bool,
243 bool,
244 )],
245 ) -> &mut Self {
246 self.instruction
247 .__remaining_accounts
248 .extend_from_slice(accounts);
249 self
250 }
251 #[inline(always)]
252 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
253 self.invoke_signed(&[])
254 }
255 #[allow(clippy::clone_on_copy)]
256 #[allow(clippy::vec_init_then_push)]
257 pub fn invoke_signed(
258 &self,
259 signers_seeds: &[&[&[u8]]],
260 ) -> solana_program::entrypoint::ProgramResult {
261 let instruction = PuffMetadataCpi {
262 __program: self.instruction.__program,
263
264 metadata: self.instruction.metadata.expect("metadata is not set"),
265 };
266 instruction.invoke_signed_with_remaining_accounts(
267 signers_seeds,
268 &self.instruction.__remaining_accounts,
269 )
270 }
271}
272
273struct PuffMetadataCpiBuilderInstruction<'a, 'b> {
274 __program: &'b solana_program::account_info::AccountInfo<'a>,
275 metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
276 __remaining_accounts: Vec<(
278 &'b solana_program::account_info::AccountInfo<'a>,
279 bool,
280 bool,
281 )>,
282}