mpl_token_metadata/generated/accounts/
metadata.rs

1//! This code was AUTOGENERATED using the kinobi library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun kinobi to update it.
4//!
5//! [https://github.com/metaplex-foundation/kinobi]
6//!
7
8use crate::generated::types::Collection;
9use crate::generated::types::CollectionDetails;
10use crate::generated::types::Creator;
11use crate::generated::types::Key;
12use crate::generated::types::ProgrammableConfig;
13use crate::generated::types::TokenStandard;
14use crate::generated::types::Uses;
15#[cfg(feature = "anchor")]
16use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
17#[cfg(not(feature = "anchor"))]
18use borsh::{BorshDeserialize, BorshSerialize};
19use solana_program::pubkey::Pubkey;
20
21#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
22#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
23#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
24#[derive(Clone, Debug, Eq, PartialEq)]
25pub struct Metadata {
26    pub key: Key,
27    #[cfg_attr(
28        feature = "serde",
29        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
30    )]
31    pub update_authority: Pubkey,
32    #[cfg_attr(
33        feature = "serde",
34        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
35    )]
36    pub mint: Pubkey,
37    pub name: String,
38    pub symbol: String,
39    pub uri: String,
40    pub seller_fee_basis_points: u16,
41    pub creators: Option<Vec<Creator>>,
42    pub primary_sale_happened: bool,
43    pub is_mutable: bool,
44    pub edition_nonce: Option<u8>,
45    pub token_standard: Option<TokenStandard>,
46    pub collection: Option<Collection>,
47    pub uses: Option<Uses>,
48    pub collection_details: Option<CollectionDetails>,
49    pub programmable_config: Option<ProgrammableConfig>,
50}
51
52impl Metadata {
53    /// Prefix values used to generate a PDA for this account.
54    ///
55    /// Values are positional and appear in the following order:
56    ///
57    ///   0. `Metadata::PREFIX`
58    ///   1. `crate::MPL_TOKEN_METADATA_ID`
59    ///   2. mint (`Pubkey`)
60    pub const PREFIX: &'static [u8] = "metadata".as_bytes();
61
62    pub fn create_pda(
63        mint: Pubkey,
64        bump: u8,
65    ) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> {
66        solana_program::pubkey::Pubkey::create_program_address(
67            &[
68                "metadata".as_bytes(),
69                crate::MPL_TOKEN_METADATA_ID.as_ref(),
70                mint.as_ref(),
71                &[bump],
72            ],
73            &crate::MPL_TOKEN_METADATA_ID,
74        )
75    }
76
77    pub fn find_pda(mint: &Pubkey) -> (solana_program::pubkey::Pubkey, u8) {
78        solana_program::pubkey::Pubkey::find_program_address(
79            &[
80                "metadata".as_bytes(),
81                crate::MPL_TOKEN_METADATA_ID.as_ref(),
82                mint.as_ref(),
83            ],
84            &crate::MPL_TOKEN_METADATA_ID,
85        )
86    }
87
88    #[inline(always)]
89    pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
90        let mut data = data;
91        Self::deserialize(&mut data)
92    }
93}
94
95impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Metadata {
96    type Error = std::io::Error;
97
98    fn try_from(
99        account_info: &solana_program::account_info::AccountInfo<'a>,
100    ) -> Result<Self, Self::Error> {
101        let mut data: &[u8] = &(*account_info.data).borrow();
102        Self::deserialize(&mut data)
103    }
104}