apl_token_metadata/instruction.rs
1//! Instruction types
2
3use {
4 arch_program::{program_error::ProgramError, pubkey::Pubkey},
5 borsh::{BorshDeserialize, BorshSerialize},
6};
7
8/// Instructions supported by the token metadata program.
9#[derive(BorshSerialize, BorshDeserialize, Debug, Clone, PartialEq)]
10pub enum MetadataInstruction {
11 /// Create core metadata for a token
12 CreateMetadata {
13 /// The name of the token
14 name: String,
15 /// The symbol of the token
16 symbol: String,
17 /// The image URI for the token
18 image: String,
19 /// The description of the token
20 description: String,
21 /// If true, metadata is immutable (no updates allowed)
22 immutable: bool,
23 },
24 /// Update core metadata
25 UpdateMetadata {
26 /// Optional new name for the token
27 name: Option<String>,
28 /// Optional new symbol for the token
29 symbol: Option<String>,
30 /// Optional new image URI for the token
31 image: Option<String>,
32 /// Optional new description for the token
33 description: Option<String>,
34 },
35 /// Create metadata attributes
36 CreateAttributes {
37 /// Key-value pairs for extensible attributes
38 data: Vec<(String, String)>,
39 },
40 /// Replace metadata attributes
41 ReplaceAttributes {
42 /// Key-value pairs for extensible attributes
43 data: Vec<(String, String)>,
44 },
45 /// Transfer update authority (must provide a new authority)
46 TransferAuthority {
47 /// New authority to transfer to
48 new_authority: Pubkey,
49 },
50 /// Make metadata immutable (revoke update authority)
51 MakeImmutable,
52 /// Sign a Bitcoin transaction input for an account owned by this program.
53 ///
54 /// Works for metadata accounts. Reads the pending Bitcoin transaction via
55 /// `get_transaction_to_sign`, computes its txid, validates the
56 /// update_authority, and registers the specified input for signing.
57 ///
58 /// Accounts expected by this instruction:
59 ///
60 /// 0. `[writable]` The metadata account
61 /// 1. `[signer]` The update authority
62 Anchor {
63 /// Index of the input in the Bitcoin transaction to sign
64 input_index: u32,
65 /// The public key of the signer for this input
66 input_signer: Pubkey,
67 },
68}
69
70impl MetadataInstruction {
71 /// Unpack a byte array into a MetadataInstruction
72 pub fn unpack(input: &[u8]) -> Result<Self, ProgramError> {
73 borsh::from_slice(input).map_err(|_| ProgramError::InvalidInstructionData)
74 }
75
76 /// Pack the MetadataInstruction into a byte array
77 pub fn pack(&self) -> Vec<u8> {
78 borsh::to_vec(self).unwrap()
79 }
80}