Skip to content

Commit 0965bf1

Browse files
committed
Separate the instructions for metadata pointer
1 parent f7d7cfd commit 0965bf1

4 files changed

Lines changed: 29 additions & 24 deletions

File tree

doc/en/markdown/content/spl_detail_create.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def spl_create(self, name: str, symbol: str, uri: str, decimals: int) -> pxsol.c
2323
r0.data = pxsol.program.System.create_account(mint_lamports, mint_size, pxsol.program.Token.pubkey)
2424
r1 = pxsol.core.Requisition(pxsol.program.Token.pubkey, [], bytearray())
2525
r1.account.append(pxsol.core.AccountMeta(mint_pubkey, 1))
26-
r1.data = pxsol.program.Token.metadata_pointer_extension_initialize(self.pubkey, mint_pubkey)
26+
r1.data = pxsol.program.TokenExtensionMetadataPointer.initialize(self.pubkey, mint_pubkey)
2727
r2 = pxsol.core.Requisition(pxsol.program.Token.pubkey, [], bytearray())
2828
r2.account.append(pxsol.core.AccountMeta(mint_pubkey, 1))
2929
r2.account.append(pxsol.core.AccountMeta(pxsol.program.SysvarRent.pubkey, 0))
@@ -62,7 +62,7 @@ This code allocates a rent-exempt account for the new SPL token. The account siz
6262
```py
6363
r1 = pxsol.core.Requisition(pxsol.program.Token.pubkey, [], bytearray())
6464
r1.account.append(pxsol.core.AccountMeta(mint_pubkey, 1))
65-
r1.data = pxsol.program.Token.metadata_pointer_extension_initialize(self.pubkey, mint_pubkey)
65+
r1.data = pxsol.program.TokenExtensionMetadataPointer.initialize(self.pubkey, mint_pubkey)
6666
```
6767

6868
This enables the Token-2022 extension: metadata pointer. It's a Token-2022 feature that allows additional metadata structures to be attached to the mint account. Later instructions will populate this metadata; this one merely declares its existence. Token-2022 actually supports dozens of such extensions, you can learn more [here](https://spl.solana.com/token-2022/extensions).

doc/zh/markdown/content/spl_detail_create.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def spl_create(self, name: str, symbol: str, uri: str, decimals: int) -> pxsol.c
2323
r0.data = pxsol.program.System.create_account(mint_lamports, mint_size, pxsol.program.Token.pubkey)
2424
r1 = pxsol.core.Requisition(pxsol.program.Token.pubkey, [], bytearray())
2525
r1.account.append(pxsol.core.AccountMeta(mint_pubkey, 1))
26-
r1.data = pxsol.program.Token.metadata_pointer_extension_initialize(self.pubkey, mint_pubkey)
26+
r1.data = pxsol.program.TokenExtensionMetadataPointer.initialize(self.pubkey, mint_pubkey)
2727
r2 = pxsol.core.Requisition(pxsol.program.Token.pubkey, [], bytearray())
2828
r2.account.append(pxsol.core.AccountMeta(mint_pubkey, 1))
2929
r2.account.append(pxsol.core.AccountMeta(pxsol.program.SysvarRent.pubkey, 0))
@@ -62,7 +62,7 @@ r0.data = pxsol.program.System.create_account(mint_lamports, mint_size, pxsol.pr
6262
```py
6363
r1 = pxsol.core.Requisition(pxsol.program.Token.pubkey, [], bytearray())
6464
r1.account.append(pxsol.core.AccountMeta(mint_pubkey, 1))
65-
r1.data = pxsol.program.Token.metadata_pointer_extension_initialize(self.pubkey, mint_pubkey)
65+
r1.data = pxsol.program.TokenExtensionMetadataPointer.initialize(self.pubkey, mint_pubkey)
6666
```
6767

6868
上述代码启用 token-2022 的扩展字段: metadata pointer. 这是 token-2022 的一个特性, 允许你在铸造账户上挂载额外的元数据结构. 在稍后的指令中, 我们将实际去挂载数据, 该指令当前仅做申明使用. 除此扩展之外, token-2022 实际上还支持另外几十个不同的扩展, 您可以在[此页面](https://spl.solana.com/token-2022/extensions)了解更多.

pxsol/program.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -738,25 +738,6 @@ def unwrap_lamports(cls, amount: typing.Optional[int]) -> bytearray:
738738
# 2. sr The source account's owner/delegate.
739739
return pxsol.borsh.Enum.encode(0x2d) + pxsol.borsh.Option(pxsol.borsh.U64).encode(amount)
740740

741-
@classmethod
742-
def metadata_pointer_extension_initialize(cls, auth: pxsol.core.PubKey, mint: pxsol.core.PubKey) -> bytearray:
743-
# Initialize a new mint with a metadata pointer. Account references:
744-
# 0. -w the mint to initialize.
745-
return pxsol.borsh.Enum.encode(0x27) + pxsol.borsh.Enum.encode(0x00) + pxsol.borsh.Struct([
746-
pxsol.borsh.Array(pxsol.borsh.U8, 32),
747-
pxsol.borsh.Array(pxsol.borsh.U8, 32),
748-
]).encode([auth.p, mint.p])
749-
750-
@classmethod
751-
def metadata_pointer_extension_update(cls, mint: pxsol.core.PubKey) -> bytearray:
752-
# Update the metadata pointer address. Only supported for mints that include the metadata pointer extension.
753-
# Account references:
754-
# 0. -w the mint.
755-
# 1. sr the metadata pointer authority.
756-
return pxsol.borsh.Enum.encode(0x27) + pxsol.borsh.Enum.encode(0x01) + pxsol.borsh.Struct([
757-
pxsol.borsh.Array(pxsol.borsh.U8, 32),
758-
]).encode([mint.p])
759-
760741
@classmethod
761742
def metadata_initialize(cls, name: str, symbol: str, uri: str) -> bytearray:
762743
# Initializes a tlv entry with the basic token-metadata fields. Account references:
@@ -839,3 +820,27 @@ def metadata_emit(cls) -> bytearray:
839820
pxsol.borsh.Option(pxsol.borsh.U64),
840821
pxsol.borsh.Option(pxsol.borsh.U64),
841822
]).encode([discriminator, None, None])
823+
824+
825+
class TokenExtensionMetadataPointer:
826+
# Solana spl token metadata pointer extension.
827+
# See: https://github.com/solana-program/token-2022/tree/main/interface/src/extension/metadata_pointer
828+
829+
@classmethod
830+
def initialize(cls, auth: pxsol.core.PubKey, mint: pxsol.core.PubKey) -> bytearray:
831+
# Initialize a new mint with a metadata pointer. Account references:
832+
# 0. -w the mint to initialize.
833+
return Token.metadata_pointer_extension() + pxsol.borsh.Enum.encode(0x00) + pxsol.borsh.Struct([
834+
pxsol.borsh.Array(pxsol.borsh.U8, 32),
835+
pxsol.borsh.Array(pxsol.borsh.U8, 32),
836+
]).encode([auth.p, mint.p])
837+
838+
@classmethod
839+
def update(cls, mint: pxsol.core.PubKey) -> bytearray:
840+
# Update the metadata pointer address. Only supported for mints that include the metadata pointer extension.
841+
# Account references:
842+
# 0. -w the mint.
843+
# 1. sr the metadata pointer authority.
844+
return Token.metadata_pointer_extension() + pxsol.borsh.Enum.encode(0x01) + pxsol.borsh.Struct([
845+
pxsol.borsh.Array(pxsol.borsh.U8, 32),
846+
]).encode([mint.p])

pxsol/wallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def spl_create(self, name: str, symbol: str, uri: str, decimals: int) -> pxsol.c
208208
r0.data = pxsol.program.System.create_account(mint_lamports, mint_size, pxsol.program.Token.pubkey)
209209
r1 = pxsol.core.Requisition(pxsol.program.Token.pubkey, [], bytearray())
210210
r1.account.append(pxsol.core.AccountMeta(mint_pubkey, 1))
211-
r1.data = pxsol.program.Token.metadata_pointer_extension_initialize(self.pubkey, mint_pubkey)
211+
r1.data = pxsol.program.TokenExtensionMetadataPointer.initialize(self.pubkey, mint_pubkey)
212212
r2 = pxsol.core.Requisition(pxsol.program.Token.pubkey, [], bytearray())
213213
r2.account.append(pxsol.core.AccountMeta(mint_pubkey, 1))
214214
r2.account.append(pxsol.core.AccountMeta(pxsol.program.SysvarRent.pubkey, 0))

0 commit comments

Comments
 (0)