Skip to main content

mpl_token_metadata/generated/accounts/
holder_delegate_record.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::Key;
9use crate::hooked::HolderDelegateRoleSeed;
10use borsh::BorshDeserialize;
11use borsh::BorshSerialize;
12use solana_program::pubkey::Pubkey;
13
14#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16pub struct HolderDelegateRecord {
17    pub key: Key,
18    pub bump: u8,
19    #[cfg_attr(
20        feature = "serde",
21        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
22    )]
23    pub mint: Pubkey,
24    #[cfg_attr(
25        feature = "serde",
26        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
27    )]
28    pub delegate: Pubkey,
29    #[cfg_attr(
30        feature = "serde",
31        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
32    )]
33    pub update_authority: Pubkey,
34}
35
36impl HolderDelegateRecord {
37    pub const LEN: usize = 98;
38
39    /// Prefix values used to generate a PDA for this account.
40    ///
41    /// Values are positional and appear in the following order:
42    ///
43    ///   0. `HolderDelegateRecord::PREFIX`
44    ///   1. `crate::MPL_TOKEN_METADATA_ID`
45    ///   2. mint (`Pubkey`)
46    ///   3. delegate_role (`HolderDelegateRoleSeed`)
47    ///   4. owner (`Pubkey`)
48    ///   5. delegate (`Pubkey`)
49    pub const PREFIX: &'static [u8] = "metadata".as_bytes();
50
51    pub fn create_pda(
52        mint: Pubkey,
53        delegate_role: HolderDelegateRoleSeed,
54        owner: Pubkey,
55        delegate: Pubkey,
56        bump: u8,
57    ) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> {
58        solana_program::pubkey::Pubkey::create_program_address(
59            &[
60                "metadata".as_bytes(),
61                crate::MPL_TOKEN_METADATA_ID.as_ref(),
62                mint.as_ref(),
63                delegate_role.to_string().as_ref(),
64                owner.as_ref(),
65                delegate.as_ref(),
66                &[bump],
67            ],
68            &crate::MPL_TOKEN_METADATA_ID,
69        )
70    }
71
72    pub fn find_pda(
73        mint: &Pubkey,
74        delegate_role: HolderDelegateRoleSeed,
75        owner: &Pubkey,
76        delegate: &Pubkey,
77    ) -> (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                delegate_role.to_string().as_ref(),
84                owner.as_ref(),
85                delegate.as_ref(),
86            ],
87            &crate::MPL_TOKEN_METADATA_ID,
88        )
89    }
90
91    #[inline(always)]
92    pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
93        let mut data = data;
94        Self::deserialize(&mut data)
95    }
96}
97
98impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for HolderDelegateRecord {
99    type Error = std::io::Error;
100
101    fn try_from(
102        account_info: &solana_program::account_info::AccountInfo<'a>,
103    ) -> Result<Self, Self::Error> {
104        let mut data: &[u8] = &(*account_info.data).borrow();
105        Self::deserialize(&mut data)
106    }
107}