mpl_token_metadata/generated/instructions/
sign_metadata.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct SignMetadata {
13 pub metadata: solana_program::pubkey::Pubkey,
15 pub creator: solana_program::pubkey::Pubkey,
17}
18
19impl SignMetadata {
20 pub fn instruction(&self) -> solana_program::instruction::Instruction {
21 self.instruction_with_remaining_accounts(&[])
22 }
23 #[allow(clippy::vec_init_then_push)]
24 pub fn instruction_with_remaining_accounts(
25 &self,
26 remaining_accounts: &[solana_program::instruction::AccountMeta],
27 ) -> solana_program::instruction::Instruction {
28 let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
29 accounts.push(solana_program::instruction::AccountMeta::new(
30 self.metadata,
31 false,
32 ));
33 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
34 self.creator,
35 true,
36 ));
37 accounts.extend_from_slice(remaining_accounts);
38 let data = SignMetadataInstructionData::new().try_to_vec().unwrap();
39
40 solana_program::instruction::Instruction {
41 program_id: crate::MPL_TOKEN_METADATA_ID,
42 accounts,
43 data,
44 }
45 }
46}
47
48#[derive(BorshDeserialize, BorshSerialize)]
49struct SignMetadataInstructionData {
50 discriminator: u8,
51}
52
53impl SignMetadataInstructionData {
54 fn new() -> Self {
55 Self { discriminator: 7 }
56 }
57}
58
59#[derive(Default)]
66pub struct SignMetadataBuilder {
67 metadata: Option<solana_program::pubkey::Pubkey>,
68 creator: Option<solana_program::pubkey::Pubkey>,
69 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
70}
71
72impl SignMetadataBuilder {
73 pub fn new() -> Self {
74 Self::default()
75 }
76 #[inline(always)]
78 pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
79 self.metadata = Some(metadata);
80 self
81 }
82 #[inline(always)]
84 pub fn creator(&mut self, creator: solana_program::pubkey::Pubkey) -> &mut Self {
85 self.creator = Some(creator);
86 self
87 }
88 #[inline(always)]
90 pub fn add_remaining_account(
91 &mut self,
92 account: solana_program::instruction::AccountMeta,
93 ) -> &mut Self {
94 self.__remaining_accounts.push(account);
95 self
96 }
97 #[inline(always)]
99 pub fn add_remaining_accounts(
100 &mut self,
101 accounts: &[solana_program::instruction::AccountMeta],
102 ) -> &mut Self {
103 self.__remaining_accounts.extend_from_slice(accounts);
104 self
105 }
106 #[allow(clippy::clone_on_copy)]
107 pub fn instruction(&self) -> solana_program::instruction::Instruction {
108 let accounts = SignMetadata {
109 metadata: self.metadata.expect("metadata is not set"),
110 creator: self.creator.expect("creator is not set"),
111 };
112
113 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
114 }
115}
116
117pub struct SignMetadataCpiAccounts<'a, 'b> {
119 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
121 pub creator: &'b solana_program::account_info::AccountInfo<'a>,
123}
124
125pub struct SignMetadataCpi<'a, 'b> {
127 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
129 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
131 pub creator: &'b solana_program::account_info::AccountInfo<'a>,
133}
134
135impl<'a, 'b> SignMetadataCpi<'a, 'b> {
136 pub fn new(
137 program: &'b solana_program::account_info::AccountInfo<'a>,
138 accounts: SignMetadataCpiAccounts<'a, 'b>,
139 ) -> Self {
140 Self {
141 __program: program,
142 metadata: accounts.metadata,
143 creator: accounts.creator,
144 }
145 }
146 #[inline(always)]
147 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
148 self.invoke_signed_with_remaining_accounts(&[], &[])
149 }
150 #[inline(always)]
151 pub fn invoke_with_remaining_accounts(
152 &self,
153 remaining_accounts: &[(
154 &'b solana_program::account_info::AccountInfo<'a>,
155 bool,
156 bool,
157 )],
158 ) -> solana_program::entrypoint::ProgramResult {
159 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
160 }
161 #[inline(always)]
162 pub fn invoke_signed(
163 &self,
164 signers_seeds: &[&[&[u8]]],
165 ) -> solana_program::entrypoint::ProgramResult {
166 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
167 }
168 #[allow(clippy::clone_on_copy)]
169 #[allow(clippy::vec_init_then_push)]
170 pub fn invoke_signed_with_remaining_accounts(
171 &self,
172 signers_seeds: &[&[&[u8]]],
173 remaining_accounts: &[(
174 &'b solana_program::account_info::AccountInfo<'a>,
175 bool,
176 bool,
177 )],
178 ) -> solana_program::entrypoint::ProgramResult {
179 let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
180 accounts.push(solana_program::instruction::AccountMeta::new(
181 *self.metadata.key,
182 false,
183 ));
184 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
185 *self.creator.key,
186 true,
187 ));
188 remaining_accounts.iter().for_each(|remaining_account| {
189 accounts.push(solana_program::instruction::AccountMeta {
190 pubkey: *remaining_account.0.key,
191 is_signer: remaining_account.1,
192 is_writable: remaining_account.2,
193 })
194 });
195 let data = SignMetadataInstructionData::new().try_to_vec().unwrap();
196
197 let instruction = solana_program::instruction::Instruction {
198 program_id: crate::MPL_TOKEN_METADATA_ID,
199 accounts,
200 data,
201 };
202 let mut account_infos = Vec::with_capacity(2 + 1 + remaining_accounts.len());
203 account_infos.push(self.__program.clone());
204 account_infos.push(self.metadata.clone());
205 account_infos.push(self.creator.clone());
206 remaining_accounts
207 .iter()
208 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
209
210 if signers_seeds.is_empty() {
211 solana_program::program::invoke(&instruction, &account_infos)
212 } else {
213 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
214 }
215 }
216}
217
218pub struct SignMetadataCpiBuilder<'a, 'b> {
225 instruction: Box<SignMetadataCpiBuilderInstruction<'a, 'b>>,
226}
227
228impl<'a, 'b> SignMetadataCpiBuilder<'a, 'b> {
229 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
230 let instruction = Box::new(SignMetadataCpiBuilderInstruction {
231 __program: program,
232 metadata: None,
233 creator: None,
234 __remaining_accounts: Vec::new(),
235 });
236 Self { instruction }
237 }
238 #[inline(always)]
240 pub fn metadata(
241 &mut self,
242 metadata: &'b solana_program::account_info::AccountInfo<'a>,
243 ) -> &mut Self {
244 self.instruction.metadata = Some(metadata);
245 self
246 }
247 #[inline(always)]
249 pub fn creator(
250 &mut self,
251 creator: &'b solana_program::account_info::AccountInfo<'a>,
252 ) -> &mut Self {
253 self.instruction.creator = Some(creator);
254 self
255 }
256 #[inline(always)]
258 pub fn add_remaining_account(
259 &mut self,
260 account: &'b solana_program::account_info::AccountInfo<'a>,
261 is_writable: bool,
262 is_signer: bool,
263 ) -> &mut Self {
264 self.instruction
265 .__remaining_accounts
266 .push((account, is_writable, is_signer));
267 self
268 }
269 #[inline(always)]
274 pub fn add_remaining_accounts(
275 &mut self,
276 accounts: &[(
277 &'b solana_program::account_info::AccountInfo<'a>,
278 bool,
279 bool,
280 )],
281 ) -> &mut Self {
282 self.instruction
283 .__remaining_accounts
284 .extend_from_slice(accounts);
285 self
286 }
287 #[inline(always)]
288 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
289 self.invoke_signed(&[])
290 }
291 #[allow(clippy::clone_on_copy)]
292 #[allow(clippy::vec_init_then_push)]
293 pub fn invoke_signed(
294 &self,
295 signers_seeds: &[&[&[u8]]],
296 ) -> solana_program::entrypoint::ProgramResult {
297 let instruction = SignMetadataCpi {
298 __program: self.instruction.__program,
299
300 metadata: self.instruction.metadata.expect("metadata is not set"),
301
302 creator: self.instruction.creator.expect("creator is not set"),
303 };
304 instruction.invoke_signed_with_remaining_accounts(
305 signers_seeds,
306 &self.instruction.__remaining_accounts,
307 )
308 }
309}
310
311struct SignMetadataCpiBuilderInstruction<'a, 'b> {
312 __program: &'b solana_program::account_info::AccountInfo<'a>,
313 metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
314 creator: Option<&'b solana_program::account_info::AccountInfo<'a>>,
315 __remaining_accounts: Vec<(
317 &'b solana_program::account_info::AccountInfo<'a>,
318 bool,
319 bool,
320 )>,
321}