摘要
本文档说明 Cosmos SDK 的x/auth/tx 包。
该包是 Cosmos SDK 对 client.TxConfig、client.TxBuilder、client.TxEncoder 和 client.TxDecoder 接口的实现。
目录
交易
TxConfig
client.TxConfig 定义了一个接口,客户端可利用它生成由应用定义的具体交易类型。
该接口定义了一组用于创建 client.TxBuilder 的方法。
client.TxConfig 的默认实现由 x/auth/tx 模块中的 NewTxConfig 实例化。
TxBuilder
client.TxBuilder 接口同样由 x/auth/tx 实现。
可通过 TxConfig.NewTxBuilder() 获取 client.TxBuilder。
TxEncoder/ TxDecoder
有关 TxEncoder 和 TxDecoder 的更多信息,请参见这里。
客户端
CLI
查询
x/auth/tx 模块提供了一个 CLI 命令,用于根据交易哈希、交易序列号或签名查询任意交易。
在不带任何参数的情况下,该命令将使用交易哈希查询交易。
--type=acc_seq 标志:
--type=signature 标志:
--type=events 标志:
x/auth/block 模块提供了一个 CLI 命令,用于根据区块哈希、高度或事件查询任意区块。
当根据区块哈希查询时,使用 --type=hash 标志:
--type=height 标志:
--query 标志:
交易
x/auth/tx 模块提供了便捷的 CLI 命令,用于解码和编码交易。
encode
encode 命令可对使用 --generate-only 标志创建的交易,或通过 sign 命令签名的交易进行编码。
交易会被序列化为 Protobuf,并以 base64 形式返回。
encode 命令的更多信息,可运行 simd tx encode --help 查看。
decode
decode 命令可解码由 encode 命令编码的交易。
decode 命令的更多信息,可运行 simd tx decode --help 查看。
gRPC
用户可以通过 gRPC 端点查询x/auth/tx 模块。
TxDecode
TxDecode 端点可用于解码交易。
TxEncode
TxEncode 端点可用于编码交易。
TxDecodeAmino
TxDecode 端点可用于解码 amino 交易。
TxEncodeAmino
TxEncodeAmino 端点可用于编码 amino 交易。
Prerequisite Readings
Abstract
This document specifies thex/auth/tx package of the Cosmos SDK.
This package represents the Cosmos SDK implementation of the client.TxConfig, client.TxBuilder, client.TxEncoder and client.TxDecoder interfaces.
Contents
Transactions
TxConfig
client.TxConfig defines an interface a client can utilize to generate an application-defined concrete transaction type.
The interface defines a set of methods for creating a client.TxBuilder.
client.TxConfig is instantiated by NewTxConfig in x/auth/tx module.
TxBuilder
client.TxBuilder interface is as well implemented by x/auth/tx.
A client.TxBuilder can be accessed with TxConfig.NewTxBuilder().
TxEncoder/ TxDecoder
More information about TxEncoder and TxDecoder can be found here.
Client
CLI
Query
Thex/auth/tx module provides a CLI command to query any transaction, given its hash, transaction sequence or signature.
Without any argument, the command will query the transaction using the transaction hash.
--type=acc_seq flag:
--type=signature flag:
--type=events flag:
x/auth/block module provides a CLI command to query any block, given its hash, height, or events.
When querying a block by its hash, use the --type=hash flag:
--type=height flag:
--query flag:
Transactions
Thex/auth/tx module provides a convenient CLI command for decoding and encoding transactions.
encode
The encode command encodes a transaction created with the --generate-only flag or signed with the sign command.
The transaction is serialized to Protobuf and returned as base64.
encode command can be found running simd tx encode --help.
decode
The decode command decodes a transaction encoded with the encode command.
decode command can be found running simd tx decode --help.
gRPC
A user can query thex/auth/tx module using gRPC endpoints.
TxDecode
The TxDecode endpoint allows to decode a transaction.
TxEncode
The TxEncode endpoint allows to encode a transaction.
TxDecodeAmino
The TxDecode endpoint allows to decode an amino transaction.
TxEncodeAmino
The TxEncodeAmino endpoint allows to encode an amino transaction.