एक्सटेंशन्स

Token Extensions क्या हैं?

Token Extensions Program (Token 2022) अतिरिक्त निर्देशों के माध्यम से अधिक सुविधाएँ प्रदान करता है जिन्हें एक्सटेंशन्स कहा जाता है। एक्सटेंशन्स वैकल्पिक सुविधाएँ हैं जिन्हें आप टोकन मिंट या टोकन अकाउंट में जोड़ सकते हैं। आप इन एक्सटेंशन निर्देशों का कार्यान्वयन Token Extensions Program के सोर्स कोड में पा सकते हैं।

प्रत्येक एक्सटेंशन विशिष्ट स्टेट जोड़ता है जो आमतौर पर मिंट या टोकन अकाउंट बनाते समय इनिशियलाइज़ किया जाता है। किसी भी अकाउंट को इनिशियलाइज़ करते समय, आप विभिन्न कार्यक्षमताओं के लिए एक साथ विशिष्ट एक्सटेंशन्स को सक्षम कर सकते हैं। अधिकांश एक्सटेंशन्स को अकाउंट इनिशियलाइज़ होने के बाद नहीं जोड़ा जा सकता। यह आपके टोकन को डिज़ाइन करते समय एक महत्वपूर्ण विचार है, क्योंकि आपको पहले से योजना बनानी होगी कि आप अपने टोकन में कौन सी सुविधाएँ चाहते हैं। प्रत्येक एक्सटेंशन के लिए इंटीग्रेशन गाइड Token Extensions डेवलपर डॉक्यूमेंटेशन में उपलब्ध हैं।

कुछ एक्सटेंशन्स एक-दूसरे के साथ असंगत हैं और आप उन्हें एक ही टोकन मिंट या टोकन अकाउंट पर एक साथ सक्षम नहीं कर सकते। उदाहरण के लिए, आप NonTransferable एक्सटेंशन को TransferFeeConfig एक्सटेंशन के साथ नहीं जोड़ सकते, क्योंकि उनके व्यवहार में विरोधाभास है।

Token Extensions Program एक ExtensionType एनम परिभाषित करता है जो सभी उपलब्ध एक्सटेंशन्स को सूचीबद्ध करता है जिन्हें आप टोकन मिंट या टोकन अकाउंट में जोड़ सकते हैं। प्रत्येक वेरिएंट एक अलग एक्सटेंशन का प्रतिनिधित्व करता है जिसमें अद्वितीय कार्यक्षमता होती है।

ExtensionType एनम को निम्नानुसार परिभाषित किया गया है:

Token Extensions
/// Extensions that can be applied to mints or accounts. Mint extensions must
/// only be applied to mint accounts, and account extensions must only be
/// applied to token holding accounts.
#[repr(u16)]
#[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))]
#[derive(Clone, Copy, Debug, PartialEq, TryFromPrimitive, IntoPrimitive)]
pub enum ExtensionType {
/// Used as padding if the account size would otherwise be 355, same as a
/// multisig
Uninitialized,
/// Includes transfer fee rate info and accompanying authorities to withdraw
/// and set the fee
TransferFeeConfig,
/// Includes withheld transfer fees
TransferFeeAmount,
/// Includes an optional mint close authority
MintCloseAuthority,
/// Auditor configuration for confidential transfers
ConfidentialTransferMint,
/// State for confidential transfers
ConfidentialTransferAccount,
/// Specifies the default Account::state for new Accounts
DefaultAccountState,
/// Indicates that the Account owner authority cannot be changed
ImmutableOwner,
/// Require inbound transfers to have memo
MemoTransfer,
/// Indicates that the tokens from this mint can't be transferred
NonTransferable,
/// Tokens accrue interest over time,
InterestBearingConfig,
/// Locks privileged token operations from happening via CPI
CpiGuard,
/// Includes an optional permanent delegate
PermanentDelegate,
/// Indicates that the tokens in this account belong to a non-transferable
/// mint
NonTransferableAccount,
/// Mint requires a CPI to a program implementing the "transfer hook"
/// interface
TransferHook,
/// Indicates that the tokens in this account belong to a mint with a
/// transfer hook
TransferHookAccount,
/// Includes encrypted withheld fees and the encryption public that they are
/// encrypted under
ConfidentialTransferFeeConfig,
/// Includes confidential withheld transfer fees
ConfidentialTransferFeeAmount,
/// Mint contains a pointer to another account (or the same account) that
/// holds metadata
MetadataPointer,
/// Mint contains token-metadata
TokenMetadata,
/// Mint contains a pointer to another account (or the same account) that
/// holds group configurations
GroupPointer,
/// Mint contains token group configurations
TokenGroup,
/// Mint contains a pointer to another account (or the same account) that
/// holds group member configurations
GroupMemberPointer,
/// Mint contains token group member configurations
TokenGroupMember,
/// Mint allowing the minting and burning of confidential tokens
ConfidentialMintBurn,
/// Tokens whose UI amount is scaled by a given amount
ScaledUiAmount,
/// Tokens where minting / burning / transferring can be paused
Pausable,
/// Indicates that the account belongs to a pausable mint
PausableAccount,
/// Test variable-length mint extension
#[cfg(test)]
VariableLenMintTest = u16::MAX - 2,
/// Padding extension used to make an account exactly Multisig::LEN, used
/// for testing
#[cfg(test)]
AccountPaddingTest,
/// Padding extension used to make a mint exactly Multisig::LEN, used for
/// testing
#[cfg(test)]
MintPaddingTest,
}

प्रत्येक एक्सटेंशन मिंट या टोकन अकाउंट में अतिरिक्त स्टेट शामिल करके विशेष कार्यक्षमता जोड़ता है। सभी एक्सटेंशन विशिष्ट स्टेट tlv_data फील्ड में संग्रहीत किया जाता है, जो बेस अकाउंट डेटा टाइप के बाद आता है। आपको उस अकाउंट के लिए सक्षम किए गए विशिष्ट एक्सटेंशन प्रकारों के अनुसार tlv_data (जिसमें एक्सटेंशन स्टेट शामिल है) को आगे डीसीरियलाइज़ करना होगा।

Token Extensions
/// Encapsulates immutable base state data (mint or account) with possible
/// extensions, where the base state is Pod for zero-copy serde.
#[derive(Debug, PartialEq)]
pub struct PodStateWithExtensions<'data, S: BaseState + Pod> {
/// Unpacked base data
pub base: &'data S,
/// Slice of data containing all TLV data, deserialized on demand
tlv_data: &'data [u8],
}

Is this page helpful?

सामग्री तालिका

पृष्ठ संपादित करें