carbon_token_2022_decoder/instructions/
update_token_metadata_field.rs

1//! This code was AUTOGENERATED using the Codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun Codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7use crate::types::TokenMetadataField;
8use carbon_core::account_utils::next_account;
9use carbon_core::borsh;
10use carbon_core::deserialize::ArrangeAccounts;
11use carbon_core::deserialize::CarbonDeserialize;
12use carbon_core::CarbonDeserialize;
13
14/// Updates a field in a token-metadata account.
15///
16/// The field can be one of the required fields (name, symbol, URI), or a
17/// totally new field denoted by a "key" string.
18///
19/// By the end of the instruction, the metadata account must be properly
20/// resized based on the new size of the TLV entry.
21///   * If the new size is larger, the program must first reallocate to
22///     avoid overwriting other TLV entries.
23///   * If the new size is smaller, the program must reallocate at the end
24///     so that it's possible to iterate over TLV entries
25#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
26#[derive(Debug, Clone, borsh::BorshSerialize, CarbonDeserialize, PartialEq)]
27pub struct UpdateTokenMetadataField {
28    /// Field to update in the metadata.
29    pub field: TokenMetadataField,
30    /// Value to write for the field.
31    pub value: String,
32}
33
34#[derive(Debug, Clone, PartialEq)]
35#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
36pub struct UpdateTokenMetadataFieldInstructionAccounts {
37    pub metadata: solana_pubkey::Pubkey,
38    pub update_authority: solana_pubkey::Pubkey,
39    pub remaining: Vec<solana_instruction::AccountMeta>,
40}
41
42impl UpdateTokenMetadataField {
43    pub fn decode(data: &[u8]) -> Option<Self> {
44        if data.len() < 8 {
45            return None;
46        }
47        let discriminator = &data[0..8];
48        if discriminator != [221, 233, 49, 45, 181, 202, 220, 200] {
49            return None;
50        }
51
52        let data_slice = data;
53
54        let data_slice = &data_slice[8..];
55
56        Self::deserialize(data_slice)
57    }
58}
59
60impl ArrangeAccounts for UpdateTokenMetadataField {
61    type ArrangedAccounts = UpdateTokenMetadataFieldInstructionAccounts;
62
63    fn arrange_accounts(
64        accounts: &[solana_instruction::AccountMeta],
65    ) -> Option<Self::ArrangedAccounts> {
66        let mut iter = accounts.iter();
67
68        let metadata = next_account(&mut iter)?;
69        let update_authority = next_account(&mut iter)?;
70
71        let remaining = iter.as_slice();
72
73        Some(UpdateTokenMetadataFieldInstructionAccounts {
74            metadata,
75            update_authority,
76            remaining: remaining.to_vec(),
77        })
78    }
79}