solana指令解析-address lookup table

solana指令解析-address lookup table

什么是address lookup table?

address lookup table称为地址查找表,用于存储地址的索引信息,为了快速查找和索引账户地址而存在的数据结构。它允许开发人员创建相关地址的集合,以便在单个事务中有效地加载更多地址,可以帮助快速查找账户的公钥,并提供与这些账户相关联的一些元数据,例如账户的所有者、状态等信息。这些信息可以被智能合约或其他程序用于执行特定的操作,例如检索数据、更新状态等。以便在处理交易和指令时快速查找和访问相关账户。
ProgramID: AddressLookupTab1e1111111111111111111111111

address_lookup_table指令汇总:

指令说明
CreateLookupTable0创建地址查找表
FreezeLookupTable1冻结地址查找表
ExtendLookupTable2扩展地址查找表
DeactivateLookupTable3停用地址查找表
CloseLookupTable4关闭地址查找表

源码地址:github.com/blocto/solana-go-sdk/program/address_lookup_table

1.CreateLookupTable 创建地址查找表

此指令用于在 Solana 区块链上创建新的地址查找表。创建地址查找表时需要指定所有者、支付创建费用等信息。

源码:
type CreateLookupTableParams struct {
	LookupTable common.PublicKey
	Authority   common.PublicKey
	Payer       common.PublicKey
	RecentSlot  uint64
	BumpSeed    uint8
}

func CreateLookupTable(params CreateLookupTableParams) types.Instruction {
	return types.Instruction{
		ProgramID: common.AddressLookupTableProgramID,
		Accounts: []types.AccountMeta{
			{
				PubKey:     params.LookupTable,
				IsSigner:   false,
				IsWritable: true,
			},
			{
				PubKey:     params.Authority,
				IsSigner:   true,
				IsWritable: false,
			},
			{
				PubKey:     params.Payer,
				IsSigner:   true,
				IsWritable: true,
			},
			{
				PubKey:     common.SystemProgramID,
				IsSigner:   false,
				IsWritable: false,
			},
		},
		Data: bincode.MustSerializeData(struct {
			Instruction Instruction
			RecentSlot  uint64
			BumpSeed    uint8
		}{
			Instruction: InstructionCreateLookupTable,
			RecentSlot:  params.RecentSlot,
			BumpSeed:    params.BumpSeed,
		}),
	}
}
指令参数:
  • LookupTable要创建的地址查找表的公钥,即新创建的地址查找表的标识符。这个公钥将用于唯一标识这个地址查找表。

  • Authority地址查找表的所有者或管理者的公钥。拥有这个公钥的账户将具有对地址查找表进行管理的权限,可以对其进行修改、更新或删除操作。

  • Payer支付创建地址查找表费用的账户的公钥。创建地址查找表需要支付一定的费用,这个费用将从此账户中扣除。

  • RecentSlot:最新的区块槽号。这个参数指定了当前的区块槽号,用于创建地址查找表时的安全性验证。

  • BumpSeed用于计算地址查找表的衍生公钥的种子值。这个值是一个字节,用于生成地址查找表的衍生公钥,确保每次创建的地址查找表都具有唯一的公钥标识符。

AccountMeta

  • PubKey: 账户的公钥
  • IsSigner :表示该账户是否需要签名验证。
  • IsWritable: 表示该账户是否可以被写入数据
PubKeyIsSignerIsWritable
LookupTablefalsetrue
Authoritytruefalse
Payertruetrue
SystemProgramIDfalsefalse
  • 其中SystemProgramID表示系统程序的公钥,用于执行 address_lookup_table 指令的程序。值为11111111111111111111111111111111

2.FreezeLookupTable 冻结查找表

此指令用于冻结指定的地址查找表,使其不可修改。一旦地址查找表被冻结,将无法对其进行更新或修改操作。

源码:
type FreezeLookupTableParams struct {
	LookupTable common.PublicKey
	Authority   common.PublicKey
}

func FreezeLookupTable(params FreezeLookupTableParams) types.Instruction {
	return types.Instruction{
		ProgramID: common.AddressLookupTableProgramID,
		Accounts: []types.AccountMeta{
			{
				PubKey:     params.LookupTable,
				IsSigner:   false,
				IsWritable: true,
			},
			{
				PubKey:     params.Authority,
				IsSigner:   true,
				IsWritable: false,
			},
		},
		Data: bincode.MustSerializeData(struct {
			Instruction Instruction
		}{
			Instruction: InstructionFreezeLookupTable,
		}),
	}
}

指令参数:
  • LookupTable:表示要冻结的地址查找表的公钥。
  • Authority:表示执行冻结操作的授权账户的公钥。

AccountMeta

PubKeyIsSignerIsWritable
LookupTablefalsetrue
Authoritytruefalse

3.ExtendLookupTable 扩展地址查找表

此指令用于扩展指定的地址查找表,增加其可容纳的地址数量。当地址查找表中的地址数量达到上限时,可以使用此指令进行扩展。

源码:
type ExtendLookupTableParams struct {
	LookupTable common.PublicKey
	Authority   common.PublicKey
	Payer       *common.PublicKey
	Addresses   []common.PublicKey
}

func ExtendLookupTable(params ExtendLookupTableParams) types.Instruction {
	accounts := make([]types.AccountMeta, 0, 4)
	accounts = append(accounts,
		types.AccountMeta{
			PubKey:     params.LookupTable,
			IsSigner:   false,
			IsWritable: true,
		},
		types.AccountMeta{
			PubKey:     params.Authority,
			IsSigner:   true,
			IsWritable: false,
		},
	)
	if params.Payer != nil {
		accounts = append(accounts,
			types.AccountMeta{
				PubKey:     *params.Payer,
				IsSigner:   true,
				IsWritable: true,
			},
			types.AccountMeta{
				PubKey:     common.SystemProgramID,
				IsSigner:   false,
				IsWritable: false,
			},
		)
	}

	return types.Instruction{
		ProgramID: common.AddressLookupTableProgramID,
		Accounts:  accounts,
		Data: bincode.MustSerializeData(struct {
			Instruction  Instruction
			NewAddresses []common.PublicKey
		}{
			Instruction:  InstructionExtendLookupTable,
			NewAddresses: params.Addresses,
		}),
	}
}
参数指令
  • LookupTable:要扩展的地址查找表的公钥。
  • Authority:执行扩展操作的授权账户的公钥。
  • Payer:(可选)支付交易费用的账户的公钥。如果为nil,则表示交易费用由执行交易的账户承担。
  • Addresses:要添加到地址查找表的新地址列表。

AccountMeta

PubKeyIsSignerIsWritable
LookupTablefalsetrue
Authoritytruefalse
Payertruetrue
SystemProgramIDfalsefalse

4.DeactivateLookupTable 停用地址查找表

此指令用于停用指定的地址查找表,使其无效。停用地址查找表后,将无法再对其进行任何操作。

源码:
type DeactivateLookupTableParams struct {
	LookupTable common.PublicKey
	Authority   common.PublicKey
}

func DeactivateLookupTable(params DeactivateLookupTableParams) types.Instruction {
	return types.Instruction{
		ProgramID: common.AddressLookupTableProgramID,
		Accounts: []types.AccountMeta{
			{
				PubKey:     params.LookupTable,
				IsSigner:   false,
				IsWritable: true,
			},
			{
				PubKey:     params.Authority,
				IsSigner:   true,
				IsWritable: false,
			},
		},
		Data: bincode.MustSerializeData(struct {
			Instruction Instruction
		}{
			Instruction: InstructionDeactivateLookupTable,
		}),
	}
}
指令参数:
  • LookupTable:表示要停用的地址查找表的公钥。
  • Authority:表示执行停用操作的授权账户的公钥。

AccountMeta

PubKeyIsSignerIsWritable
LookupTablefalsetrue
Authoritytruefalse
DeactivateLookupTable 和FreezeLookupTable的区别

DeactivateLookupTableFreezeLookupTable 都是用于处理地址查找表的指令,但它们有不同的功能和目的。

DeactivateLookupTable:这个指令用于停用(或关闭)地址查找表。停用地址查找表意味着不再允许对其进行修改或使用。一旦地址查找表被停用,它将不能再添加新的地址或执行查找操作。 这个指令一般在不再需要使用某个地址查找表时调用,以释放资源或避免进一步的操作。

FreezeLookupTable: 这个指令用于冻结地址查找表。冻结地址查找表意味着对其进行的修改操作被限制,但仍然可以使用已有的地址进行查找操作。这个指令通常用于在不需要对地址查找表进行修改时,保护其内容不被更改。 例如,当一个地址查找表已经被创建并填充了一些地址后,可以将其冻结,以防止意外的修改或误操作。

总的来说,DeactivateLookupTable 用于完全停用一个地址查找表,而 FreezeLookupTable 则是限制对地址查找表的修改操作,保持其内容的不可变性。

5.CloseLookupTable 关闭地址查找表

关闭地址查找表。此指令用于关闭指定的地址查找表,释放其占用的资源并彻底删除。一旦地址查找表被关闭,将无法再使用该表进行任何操作,也无法再恢复其状态。

源码:
type CloseLookupTableParams struct {
	LookupTable common.PublicKey
	Authority   common.PublicKey
	Recipient   common.PublicKey
}

func CloseLookupTable(params CloseLookupTableParams) types.Instruction {
	return types.Instruction{
		ProgramID: common.AddressLookupTableProgramID,
		Accounts: []types.AccountMeta{
			{
				PubKey:     params.LookupTable,
				IsSigner:   false,
				IsWritable: true,
			},
			{
				PubKey:     params.Authority,
				IsSigner:   true,
				IsWritable: false,
			},
			{
				PubKey:     params.Recipient,
				IsSigner:   false,
				IsWritable: true,
			},
		},
		Data: bincode.MustSerializeData(struct {
			Instruction Instruction
		}{
			Instruction: InstructionCloseLookupTable,
		}),
	}
}
指令参数:
  • LookupTable: 要关闭的地址查找表的公钥。
  • Authority: 有权关闭地址查找表的账户的公钥。
  • Recipient: 用于接收关闭地址查找表操作结果的账户的公钥。

AccountMeta

PubKeyIsSignerIsWritable
LookupTablefalsetrue
Authoritytruefalse
Recipientfalsetrue
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值