Extensions
Extensions là gì?
Token Extensions Program (Token 2022) cung cấp nhiều tính năng hơn thông qua các hướng dẫn bổ sung được gọi là extensions. Extensions là các tính năng tùy chọn mà bạn có thể thêm vào token mint hoặc token account. Bạn có thể tìm thấy việc triển khai các hướng dẫn extension này trong Token Extensions Program mã nguồn.
Mỗi extension thêm trạng thái cụ thể thường được khởi tạo trong quá trình tạo mint hoặc token account. Khi khởi tạo một trong hai loại tài khoản, bạn có thể kích hoạt các extension cụ thể đồng thời để có các chức năng khác nhau. Hầu hết các extension không thể được thêm vào sau khi tài khoản đã được khởi tạo. Đây là một điều quán trọng cần cân nhắc khi thiết kế token của bạn, vì bạn cần lên kế hoạch trước cho các tính năng mà bạn muốn token của mình hỗ trợ. Hướng dẫn tích hợp cho từng extension có sẵn trong Tài liệu dành cho nhà phát triển Token Extensions.
Một số extensions không tương thích với nhau và bạn không thể kích hoạt chúng
đồng thời trên cùng một token mint hoặc token account. Ví dụ, bạn không thể
kết hợp extension NonTransferable
với extension TransferFeeConfig
vì chúng có hành vi xung đột nhau.
Token Extensions Program định nghĩa một
ExtensionType
enum liệt kê tất cả các extensions có sẵn mà bạn có thể thêm vào token mint hoặc
token account. Mỗi biến thể đại diện cho một extension khác nhau với chức năng
riêng biệt.
Enum ExtensionType
được định nghĩa như sau:
/// 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/// multisigUninitialized,/// Includes transfer fee rate info and accompanying authorities to withdraw/// and set the feeTransferFeeConfig,/// Includes withheld transfer feesTransferFeeAmount,/// Includes an optional mint close authorityMintCloseAuthority,/// Auditor configuration for confidential transfersConfidentialTransferMint,/// State for confidential transfersConfidentialTransferAccount,/// Specifies the default Account::state for new AccountsDefaultAccountState,/// Indicates that the Account owner authority cannot be changedImmutableOwner,/// Require inbound transfers to have memoMemoTransfer,/// Indicates that the tokens from this mint can't be transferredNonTransferable,/// Tokens accrue interest over time,InterestBearingConfig,/// Locks privileged token operations from happening via CPICpiGuard,/// Includes an optional permanent delegatePermanentDelegate,/// Indicates that the tokens in this account belong to a non-transferable/// mintNonTransferableAccount,/// Mint requires a CPI to a program implementing the "transfer hook"/// interfaceTransferHook,/// Indicates that the tokens in this account belong to a mint with a/// transfer hookTransferHookAccount,/// Includes encrypted withheld fees and the encryption public that they are/// encrypted underConfidentialTransferFeeConfig,/// Includes confidential withheld transfer feesConfidentialTransferFeeAmount,/// Mint contains a pointer to another account (or the same account) that/// holds metadataMetadataPointer,/// Mint contains token-metadataTokenMetadata,/// Mint contains a pointer to another account (or the same account) that/// holds group configurationsGroupPointer,/// Mint contains token group configurationsTokenGroup,/// Mint contains a pointer to another account (or the same account) that/// holds group member configurationsGroupMemberPointer,/// Mint contains token group member configurationsTokenGroupMember,/// Mint allowing the minting and burning of confidential tokensConfidentialMintBurn,/// Tokens whose UI amount is scaled by a given amountScaledUiAmount,/// Tokens where minting / burning / transferring can be pausedPausable,/// Indicates that the account belongs to a pausable mintPausableAccount,/// 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,}
Mỗi extension thêm chức năng chuyên biệt bằng cách bao gồm trạng thái bổ sung
vào mint hoặc token account. Tất cả trạng thái đặc thù của extension được lưu
trữ trong trường
tlv_data
, theo sau kiểu dữ liệu tài khoản cơ sở. Bạn phải giải mã thêm tlv_data
(chứa
trạng thái extension) theo các loại extension cụ thể được kích hoạt cho tài
khoản đó.
/// 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 datapub base: &'data S,/// Slice of data containing all TLV data, deserialized on demandtlv_data: &'data [u8],}
Is this page helpful?