mpl_token_metadata/generated/instructions/
update_metadata_account_v2.rs1use crate::generated::types::DataV2;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11use solana_program::pubkey::Pubkey;
12
13pub struct UpdateMetadataAccountV2 {
15 pub metadata: solana_program::pubkey::Pubkey,
17 pub update_authority: solana_program::pubkey::Pubkey,
19}
20
21impl UpdateMetadataAccountV2 {
22 pub fn instruction(
23 &self,
24 args: UpdateMetadataAccountV2InstructionArgs,
25 ) -> solana_program::instruction::Instruction {
26 self.instruction_with_remaining_accounts(args, &[])
27 }
28 #[allow(clippy::vec_init_then_push)]
29 pub fn instruction_with_remaining_accounts(
30 &self,
31 args: UpdateMetadataAccountV2InstructionArgs,
32 remaining_accounts: &[solana_program::instruction::AccountMeta],
33 ) -> solana_program::instruction::Instruction {
34 let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
35 accounts.push(solana_program::instruction::AccountMeta::new(
36 self.metadata,
37 false,
38 ));
39 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
40 self.update_authority,
41 true,
42 ));
43 accounts.extend_from_slice(remaining_accounts);
44 let mut data = UpdateMetadataAccountV2InstructionData::new()
45 .try_to_vec()
46 .unwrap();
47 let mut args = args.try_to_vec().unwrap();
48 data.append(&mut args);
49
50 solana_program::instruction::Instruction {
51 program_id: crate::MPL_TOKEN_METADATA_ID,
52 accounts,
53 data,
54 }
55 }
56}
57
58#[derive(BorshDeserialize, BorshSerialize)]
59struct UpdateMetadataAccountV2InstructionData {
60 discriminator: u8,
61}
62
63impl UpdateMetadataAccountV2InstructionData {
64 fn new() -> Self {
65 Self { discriminator: 15 }
66 }
67}
68
69#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
70#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
71pub struct UpdateMetadataAccountV2InstructionArgs {
72 pub data: Option<DataV2>,
73 pub new_update_authority: Option<Pubkey>,
74 pub primary_sale_happened: Option<bool>,
75 pub is_mutable: Option<bool>,
76}
77
78#[derive(Default)]
85pub struct UpdateMetadataAccountV2Builder {
86 metadata: Option<solana_program::pubkey::Pubkey>,
87 update_authority: Option<solana_program::pubkey::Pubkey>,
88 data: Option<DataV2>,
89 new_update_authority: Option<Pubkey>,
90 primary_sale_happened: Option<bool>,
91 is_mutable: Option<bool>,
92 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
93}
94
95impl UpdateMetadataAccountV2Builder {
96 pub fn new() -> Self {
97 Self::default()
98 }
99 #[inline(always)]
101 pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
102 self.metadata = Some(metadata);
103 self
104 }
105 #[inline(always)]
107 pub fn update_authority(
108 &mut self,
109 update_authority: solana_program::pubkey::Pubkey,
110 ) -> &mut Self {
111 self.update_authority = Some(update_authority);
112 self
113 }
114 #[inline(always)]
116 pub fn data(&mut self, data: DataV2) -> &mut Self {
117 self.data = Some(data);
118 self
119 }
120 #[inline(always)]
122 pub fn new_update_authority(&mut self, new_update_authority: Pubkey) -> &mut Self {
123 self.new_update_authority = Some(new_update_authority);
124 self
125 }
126 #[inline(always)]
128 pub fn primary_sale_happened(&mut self, primary_sale_happened: bool) -> &mut Self {
129 self.primary_sale_happened = Some(primary_sale_happened);
130 self
131 }
132 #[inline(always)]
134 pub fn is_mutable(&mut self, is_mutable: bool) -> &mut Self {
135 self.is_mutable = Some(is_mutable);
136 self
137 }
138 #[inline(always)]
140 pub fn add_remaining_account(
141 &mut self,
142 account: solana_program::instruction::AccountMeta,
143 ) -> &mut Self {
144 self.__remaining_accounts.push(account);
145 self
146 }
147 #[inline(always)]
149 pub fn add_remaining_accounts(
150 &mut self,
151 accounts: &[solana_program::instruction::AccountMeta],
152 ) -> &mut Self {
153 self.__remaining_accounts.extend_from_slice(accounts);
154 self
155 }
156 #[allow(clippy::clone_on_copy)]
157 pub fn instruction(&self) -> solana_program::instruction::Instruction {
158 let accounts = UpdateMetadataAccountV2 {
159 metadata: self.metadata.expect("metadata is not set"),
160 update_authority: self.update_authority.expect("update_authority is not set"),
161 };
162 let args = UpdateMetadataAccountV2InstructionArgs {
163 data: self.data.clone(),
164 new_update_authority: self.new_update_authority.clone(),
165 primary_sale_happened: self.primary_sale_happened.clone(),
166 is_mutable: self.is_mutable.clone(),
167 };
168
169 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
170 }
171}
172
173pub struct UpdateMetadataAccountV2CpiAccounts<'a, 'b> {
175 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
177 pub update_authority: &'b solana_program::account_info::AccountInfo<'a>,
179}
180
181pub struct UpdateMetadataAccountV2Cpi<'a, 'b> {
183 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
185 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
187 pub update_authority: &'b solana_program::account_info::AccountInfo<'a>,
189 pub __args: UpdateMetadataAccountV2InstructionArgs,
191}
192
193impl<'a, 'b> UpdateMetadataAccountV2Cpi<'a, 'b> {
194 pub fn new(
195 program: &'b solana_program::account_info::AccountInfo<'a>,
196 accounts: UpdateMetadataAccountV2CpiAccounts<'a, 'b>,
197 args: UpdateMetadataAccountV2InstructionArgs,
198 ) -> Self {
199 Self {
200 __program: program,
201 metadata: accounts.metadata,
202 update_authority: accounts.update_authority,
203 __args: args,
204 }
205 }
206 #[inline(always)]
207 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
208 self.invoke_signed_with_remaining_accounts(&[], &[])
209 }
210 #[inline(always)]
211 pub fn invoke_with_remaining_accounts(
212 &self,
213 remaining_accounts: &[(
214 &'b solana_program::account_info::AccountInfo<'a>,
215 bool,
216 bool,
217 )],
218 ) -> solana_program::entrypoint::ProgramResult {
219 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
220 }
221 #[inline(always)]
222 pub fn invoke_signed(
223 &self,
224 signers_seeds: &[&[&[u8]]],
225 ) -> solana_program::entrypoint::ProgramResult {
226 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
227 }
228 #[allow(clippy::clone_on_copy)]
229 #[allow(clippy::vec_init_then_push)]
230 pub fn invoke_signed_with_remaining_accounts(
231 &self,
232 signers_seeds: &[&[&[u8]]],
233 remaining_accounts: &[(
234 &'b solana_program::account_info::AccountInfo<'a>,
235 bool,
236 bool,
237 )],
238 ) -> solana_program::entrypoint::ProgramResult {
239 let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
240 accounts.push(solana_program::instruction::AccountMeta::new(
241 *self.metadata.key,
242 false,
243 ));
244 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
245 *self.update_authority.key,
246 true,
247 ));
248 remaining_accounts.iter().for_each(|remaining_account| {
249 accounts.push(solana_program::instruction::AccountMeta {
250 pubkey: *remaining_account.0.key,
251 is_signer: remaining_account.1,
252 is_writable: remaining_account.2,
253 })
254 });
255 let mut data = UpdateMetadataAccountV2InstructionData::new()
256 .try_to_vec()
257 .unwrap();
258 let mut args = self.__args.try_to_vec().unwrap();
259 data.append(&mut args);
260
261 let instruction = solana_program::instruction::Instruction {
262 program_id: crate::MPL_TOKEN_METADATA_ID,
263 accounts,
264 data,
265 };
266 let mut account_infos = Vec::with_capacity(2 + 1 + remaining_accounts.len());
267 account_infos.push(self.__program.clone());
268 account_infos.push(self.metadata.clone());
269 account_infos.push(self.update_authority.clone());
270 remaining_accounts
271 .iter()
272 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
273
274 if signers_seeds.is_empty() {
275 solana_program::program::invoke(&instruction, &account_infos)
276 } else {
277 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
278 }
279 }
280}
281
282pub struct UpdateMetadataAccountV2CpiBuilder<'a, 'b> {
289 instruction: Box<UpdateMetadataAccountV2CpiBuilderInstruction<'a, 'b>>,
290}
291
292impl<'a, 'b> UpdateMetadataAccountV2CpiBuilder<'a, 'b> {
293 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
294 let instruction = Box::new(UpdateMetadataAccountV2CpiBuilderInstruction {
295 __program: program,
296 metadata: None,
297 update_authority: None,
298 data: None,
299 new_update_authority: None,
300 primary_sale_happened: None,
301 is_mutable: None,
302 __remaining_accounts: Vec::new(),
303 });
304 Self { instruction }
305 }
306 #[inline(always)]
308 pub fn metadata(
309 &mut self,
310 metadata: &'b solana_program::account_info::AccountInfo<'a>,
311 ) -> &mut Self {
312 self.instruction.metadata = Some(metadata);
313 self
314 }
315 #[inline(always)]
317 pub fn update_authority(
318 &mut self,
319 update_authority: &'b solana_program::account_info::AccountInfo<'a>,
320 ) -> &mut Self {
321 self.instruction.update_authority = Some(update_authority);
322 self
323 }
324 #[inline(always)]
326 pub fn data(&mut self, data: DataV2) -> &mut Self {
327 self.instruction.data = Some(data);
328 self
329 }
330 #[inline(always)]
332 pub fn new_update_authority(&mut self, new_update_authority: Pubkey) -> &mut Self {
333 self.instruction.new_update_authority = Some(new_update_authority);
334 self
335 }
336 #[inline(always)]
338 pub fn primary_sale_happened(&mut self, primary_sale_happened: bool) -> &mut Self {
339 self.instruction.primary_sale_happened = Some(primary_sale_happened);
340 self
341 }
342 #[inline(always)]
344 pub fn is_mutable(&mut self, is_mutable: bool) -> &mut Self {
345 self.instruction.is_mutable = Some(is_mutable);
346 self
347 }
348 #[inline(always)]
350 pub fn add_remaining_account(
351 &mut self,
352 account: &'b solana_program::account_info::AccountInfo<'a>,
353 is_writable: bool,
354 is_signer: bool,
355 ) -> &mut Self {
356 self.instruction
357 .__remaining_accounts
358 .push((account, is_writable, is_signer));
359 self
360 }
361 #[inline(always)]
366 pub fn add_remaining_accounts(
367 &mut self,
368 accounts: &[(
369 &'b solana_program::account_info::AccountInfo<'a>,
370 bool,
371 bool,
372 )],
373 ) -> &mut Self {
374 self.instruction
375 .__remaining_accounts
376 .extend_from_slice(accounts);
377 self
378 }
379 #[inline(always)]
380 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
381 self.invoke_signed(&[])
382 }
383 #[allow(clippy::clone_on_copy)]
384 #[allow(clippy::vec_init_then_push)]
385 pub fn invoke_signed(
386 &self,
387 signers_seeds: &[&[&[u8]]],
388 ) -> solana_program::entrypoint::ProgramResult {
389 let args = UpdateMetadataAccountV2InstructionArgs {
390 data: self.instruction.data.clone(),
391 new_update_authority: self.instruction.new_update_authority.clone(),
392 primary_sale_happened: self.instruction.primary_sale_happened.clone(),
393 is_mutable: self.instruction.is_mutable.clone(),
394 };
395 let instruction = UpdateMetadataAccountV2Cpi {
396 __program: self.instruction.__program,
397
398 metadata: self.instruction.metadata.expect("metadata is not set"),
399
400 update_authority: self
401 .instruction
402 .update_authority
403 .expect("update_authority is not set"),
404 __args: args,
405 };
406 instruction.invoke_signed_with_remaining_accounts(
407 signers_seeds,
408 &self.instruction.__remaining_accounts,
409 )
410 }
411}
412
413struct UpdateMetadataAccountV2CpiBuilderInstruction<'a, 'b> {
414 __program: &'b solana_program::account_info::AccountInfo<'a>,
415 metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
416 update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
417 data: Option<DataV2>,
418 new_update_authority: Option<Pubkey>,
419 primary_sale_happened: Option<bool>,
420 is_mutable: Option<bool>,
421 __remaining_accounts: Vec<(
423 &'b solana_program::account_info::AccountInfo<'a>,
424 bool,
425 bool,
426 )>,
427}