mpl_token_metadata/generated/accounts/
master_edition.rs1use crate::generated::types::Key;
9#[cfg(feature = "anchor")]
10use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
11#[cfg(not(feature = "anchor"))]
12use borsh::{BorshDeserialize, BorshSerialize};
13use solana_program::pubkey::Pubkey;
14
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
17#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
18#[derive(Clone, Debug, Eq, PartialEq)]
19pub struct MasterEdition {
20 pub key: Key,
21 pub supply: u64,
22 pub max_supply: Option<u64>,
23}
24
25impl MasterEdition {
26 pub const PREFIX: (&'static [u8], &'static [u8]) =
35 ("metadata".as_bytes(), "edition".as_bytes());
36
37 pub fn create_pda(
38 mint: Pubkey,
39 bump: u8,
40 ) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> {
41 solana_program::pubkey::Pubkey::create_program_address(
42 &[
43 "metadata".as_bytes(),
44 crate::MPL_TOKEN_METADATA_ID.as_ref(),
45 mint.as_ref(),
46 "edition".as_bytes(),
47 &[bump],
48 ],
49 &crate::MPL_TOKEN_METADATA_ID,
50 )
51 }
52
53 pub fn find_pda(mint: &Pubkey) -> (solana_program::pubkey::Pubkey, u8) {
54 solana_program::pubkey::Pubkey::find_program_address(
55 &[
56 "metadata".as_bytes(),
57 crate::MPL_TOKEN_METADATA_ID.as_ref(),
58 mint.as_ref(),
59 "edition".as_bytes(),
60 ],
61 &crate::MPL_TOKEN_METADATA_ID,
62 )
63 }
64
65 #[inline(always)]
66 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
67 let mut data = data;
68 Self::deserialize(&mut data)
69 }
70}
71
72impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for MasterEdition {
73 type Error = std::io::Error;
74
75 fn try_from(
76 account_info: &solana_program::account_info::AccountInfo<'a>,
77 ) -> Result<Self, Self::Error> {
78 let mut data: &[u8] = &(*account_info.data).borrow();
79 Self::deserialize(&mut data)
80 }
81}