decoder

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

地址解析器:编解码、校验、WIF、多签、自定义创建地址。 各链嵌入 AddressDecoderBase 并仅实现需要的方法。

智能合约解析器:代币余额、ABI 调用/创建/广播、合约元数据;与 TransactionDecoder 并列,供链可选实现。

交易单解析器:创建、验证、广播(签名由外部 MPC 完成)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ABIDAI

type ABIDAI interface {
	GetABIInfo(address string) (*types.ABIInfo, error)
	SetABIInfo(address string, abi types.ABIInfo) error
}

ABIDAI ABI 数据访问接口,供 SmartContractDecoder 嵌入

type AddressDecoder

type AddressDecoder interface {
	// PrivateKeyToWIF 将私钥转为 WIF(BTC 系)。
	PrivateKeyToWIF(priv []byte, isTestnet bool) (string, error)
	// PublicKeyToAddress 公钥转链上地址。
	PublicKeyToAddress(pub []byte, isTestnet bool) (string, error)
	// WIFToPrivateKey WIF 转私钥(BTC 系)。
	WIFToPrivateKey(wif string, isTestnet bool) ([]byte, error)
	// RedeemScriptToAddress 赎回脚本转多签地址(BTC 系)。
	RedeemScriptToAddress(pubs [][]byte, required uint64, isTestnet bool) (string, error)
	// AddressDecode 地址解码为内部表示(如字节)。
	AddressDecode(addr string, opts ...interface{}) ([]byte, error)
	// AddressEncode 内部表示编码为链上地址。
	AddressEncode(pub []byte, opts ...interface{}) (string, error)
	// AddressVerify 校验地址格式是否合法。
	AddressVerify(addr string, opts ...interface{}) bool
	// CustomCreateAddress 按链规则派生新地址(可选)。
	CustomCreateAddress(account *types.AssetsAccount, newIndex uint64) (*types.Address, error)
	// SupportCustomCreateAddressFunction 是否支持 CustomCreateAddress。
	SupportCustomCreateAddressFunction() bool
}

AddressDecoder 地址解析器接口。通用方法:PublicKeyToAddress、AddressVerify、AddressDecode、AddressEncode;BTC 系可选 WIF、RedeemScript;可选 CustomCreateAddress。

type AddressDecoderBase

type AddressDecoderBase struct{}

AddressDecoderBase 地址解析器基类,未重写的方法返回“未实现”或 false,便于链只实现需要的方法。

func (AddressDecoderBase) AddressDecode

func (AddressDecoderBase) AddressDecode(string, ...interface{}) ([]byte, error)

func (AddressDecoderBase) AddressEncode

func (AddressDecoderBase) AddressEncode([]byte, ...interface{}) (string, error)

func (AddressDecoderBase) AddressVerify

func (AddressDecoderBase) AddressVerify(string, ...interface{}) bool

func (AddressDecoderBase) CustomCreateAddress

func (AddressDecoderBase) CustomCreateAddress(*types.AssetsAccount, uint64) (*types.Address, error)

func (AddressDecoderBase) PrivateKeyToWIF

func (AddressDecoderBase) PrivateKeyToWIF([]byte, bool) (string, error)

func (AddressDecoderBase) PublicKeyToAddress

func (AddressDecoderBase) PublicKeyToAddress([]byte, bool) (string, error)

func (AddressDecoderBase) RedeemScriptToAddress

func (AddressDecoderBase) RedeemScriptToAddress([][]byte, uint64, bool) (string, error)

func (AddressDecoderBase) SupportCustomCreateAddressFunction

func (AddressDecoderBase) SupportCustomCreateAddressFunction() bool

func (AddressDecoderBase) WIFToPrivateKey

func (AddressDecoderBase) WIFToPrivateKey(string, bool) ([]byte, error)

type SmartContractDecoder

type SmartContractDecoder interface {
	ABIDAI

	// GetTokenBalanceByAddress 查询地址代币余额列表
	GetTokenBalanceByAddress(contract types.SmartContract, address ...string) ([]*types.TokenBalance, error)
	// CallSmartContractABI 只读调用合约 ABI 方法,不产生链上交易
	CallSmartContractABI(wrapper wallet.WalletDAI, rawTx *types.SmartContractRawTransaction) (*types.SmartContractCallResult, *types.AdapterError)
	// CreateSmartContractRawTransaction 创建智能合约原始交易单(填充 Raw 等)
	CreateSmartContractRawTransaction(wrapper wallet.WalletDAI, rawTx *types.SmartContractRawTransaction) *types.AdapterError
	// SubmitSmartContractRawTransaction 广播智能合约交易单
	SubmitSmartContractRawTransaction(wrapper wallet.WalletDAI, rawTx *types.SmartContractRawTransaction) (*types.SmartContractReceipt, *types.AdapterError)
	// GetTokenMetadata 根据合约地址查询代币元数据
	GetTokenMetadata(contract string) (*types.SmartContract, error)
}

SmartContractDecoder 智能合约解析器接口,供支持合约的链实现(可选)。 与 TransactionDecoder 并列;ChainAdapter 通过 GetSmartContractDecoder() 返回,可为 nil。

type SmartContractDecoderBase

type SmartContractDecoderBase struct{}

SmartContractDecoderBase 默认未实现基类

func (SmartContractDecoderBase) CreateSmartContractRawTransaction

func (SmartContractDecoderBase) GetABIInfo

func (SmartContractDecoderBase) GetABIInfo(address string) (*types.ABIInfo, error)

func (SmartContractDecoderBase) GetTokenBalanceByAddress

func (SmartContractDecoderBase) GetTokenBalanceByAddress(contract types.SmartContract, address ...string) ([]*types.TokenBalance, error)

func (SmartContractDecoderBase) GetTokenMetadata

func (SmartContractDecoderBase) GetTokenMetadata(contract string) (*types.SmartContract, error)

func (SmartContractDecoderBase) SetABIInfo

func (SmartContractDecoderBase) SetABIInfo(address string, abi types.ABIInfo) error

type TransactionDecoder

type TransactionDecoder interface {
	// CreateRawTransaction 根据 rawTx 构建原始交易,填充 RawHex、Fees、Signatures 等。若 wrapper 非 nil,可回调查询(如 GetAddress/GetAssetsAccountByAddress、账户列表等)。
	CreateRawTransaction(wrapper wallet.WalletDAI, rawTx *types.RawTransaction) error
	// SignRawTransaction 对 rawTx 进行本地签名并写回 Signatures。签名由外部 MPC 完成时可不实现。
	SignRawTransaction(wrapper wallet.WalletDAI, rawTx *types.RawTransaction) error
	// SubmitRawTransaction 将已签名的 rawTx 提交到链上节点并返回交易结果;调用前应已通过 VerifyRawTransaction。若 wrapper 非 nil 可回调查询。
	SubmitRawTransaction(wrapper wallet.WalletDAI, rawTx *types.RawTransaction) (*types.Transaction, error)
	// VerifyRawTransaction 合并并校验 rawTx 的 Signatures;若 wrapper 非 nil,可回调查询(如校验地址归属)。
	VerifyRawTransaction(wrapper wallet.WalletDAI, rawTx *types.RawTransaction) error
	// GetRawTransactionFeeRate 返回当前链建议的费率与单位(如 "10"、"sat/vB")。若 wrapper 非 nil 可回调查询。
	GetRawTransactionFeeRate(wrapper wallet.WalletDAI) (feeRate, unit string, err error)
	// EstimateRawTransactionFee 根据 rawTx 估算手续费并写回 rawTx.Fees;若 wrapper 非 nil 可回调查询。
	EstimateRawTransactionFee(wrapper wallet.WalletDAI, rawTx *types.RawTransaction) error
	// CreateSummaryRawTransactionWithError 根据汇总参数生成多笔 RawTransactionWithError;若 wrapper 非 nil 可回调查询(如过滤非本业务地址)。
	CreateSummaryRawTransactionWithError(wrapper wallet.WalletDAI, sumRawTx *types.SummaryRawTransaction) ([]*types.RawTransactionWithError, error)
}

TransactionDecoder 交易单解析器,每条链实现此接口即可接入统一构建与广播流程;签名由外部 MPC 提供。 构建待签 PendingSignTx 的入口为 flow.BuildTransaction,decoder 只负责构建/验签/提交 rawTx。 wrapper 为 WalletDAI,可为 nil;非 nil 时实现层可回调查询钱包/账户/地址/交易等。

type TransactionDecoderBase

type TransactionDecoderBase struct{}

TransactionDecoderBase 交易单解析器基类,未重写的方法均返回“未实现”,便于链实现时只实现必要方法。

func (TransactionDecoderBase) CreateRawTransaction

CreateRawTransaction 基类默认返回未实现。

func (TransactionDecoderBase) CreateSummaryRawTransactionWithError

CreateSummaryRawTransactionWithError 基类默认返回未实现。

func (TransactionDecoderBase) EstimateRawTransactionFee

func (TransactionDecoderBase) EstimateRawTransactionFee(wallet.WalletDAI, *types.RawTransaction) error

EstimateRawTransactionFee 基类默认返回未实现。

func (TransactionDecoderBase) GetRawTransactionFeeRate

func (TransactionDecoderBase) GetRawTransactionFeeRate(wallet.WalletDAI) (string, string, error)

GetRawTransactionFeeRate 基类默认返回未实现。

func (TransactionDecoderBase) SignRawTransaction

SignRawTransaction 基类默认返回未实现(MPC 签名场景无需实现)。

func (TransactionDecoderBase) SubmitRawTransaction

SubmitRawTransaction 基类默认返回未实现。

func (TransactionDecoderBase) VerifyRawTransaction

VerifyRawTransaction 基类默认返回未实现。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL