mpl_token_metadata/state/
asset_data.rs

1use borsh::{BorshDeserialize, BorshSerialize};
2use solana_program::pubkey::Pubkey;
3
4use super::*;
5
6/// Data representation of an asset.
7#[repr(C)]
8#[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))]
9#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
10pub struct AssetData {
11    /// The name of the asset.
12    pub name: String,
13    /// The symbol for the asset.
14    pub symbol: String,
15    /// URI pointing to JSON representing the asset.
16    pub uri: String,
17    /// Royalty basis points that goes to creators in secondary sales (0-10000).
18    pub seller_fee_basis_points: u16,
19    /// Array of creators.
20    pub creators: Option<Vec<Creator>>,
21    // Immutable, once flipped, all sales of this metadata are considered secondary.
22    pub primary_sale_happened: bool,
23    // Whether or not the data struct is mutable (default is not).
24    pub is_mutable: bool,
25    /// Type of the token.
26    pub token_standard: TokenStandard,
27    /// Collection information.
28    pub collection: Option<Collection>,
29    /// Uses information.
30    pub uses: Option<Uses>,
31    /// Collection item details.
32    pub collection_details: Option<CollectionDetails>,
33    /// Programmable rule set for the asset.
34    #[cfg_attr(
35        feature = "serde-feature",
36        serde(
37            deserialize_with = "deser_option_pubkey",
38            serialize_with = "ser_option_pubkey"
39        )
40    )]
41    pub rule_set: Option<Pubkey>,
42}
43
44impl AssetData {
45    pub fn new(token_standard: TokenStandard, name: String, symbol: String, uri: String) -> Self {
46        Self {
47            name,
48            symbol,
49            uri,
50            seller_fee_basis_points: 0,
51            creators: None,
52            primary_sale_happened: false,
53            is_mutable: true,
54            token_standard,
55            collection: None,
56            uses: None,
57            collection_details: None,
58            rule_set: None,
59        }
60    }
61
62    pub fn as_data_v2(&self) -> DataV2 {
63        DataV2 {
64            collection: self.collection.clone(),
65            creators: self.creators.clone(),
66            name: self.name.clone(),
67            seller_fee_basis_points: self.seller_fee_basis_points,
68            symbol: self.symbol.clone(),
69            uri: self.uri.clone(),
70            uses: self.uses.clone(),
71        }
72    }
73
74    pub fn as_data(&self) -> Data {
75        Data {
76            name: self.name.clone(),
77            symbol: self.symbol.clone(),
78            uri: self.uri.clone(),
79            seller_fee_basis_points: self.seller_fee_basis_points,
80            creators: self.creators.clone(),
81        }
82    }
83}