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}
53
54impl MetadataInstruction {
55 /// Unpack a byte array into a MetadataInstruction
56 pub fn unpack(input: &[u8]) -> Result<Self, ProgramError> {
57 borsh::from_slice(input).map_err(|_| ProgramError::InvalidInstructionData)
58 }
59
60 /// Pack the MetadataInstruction into a byte array
61 pub fn pack(&self) -> Vec<u8> {
62 borsh::to_vec(self).unwrap()
63 }
64}