Documentation
¶
Index ¶
- Constants
- func PubToAddress(publicKey string) string
- type Client
- func (c *Client) Account(address sdk.AccAddress) (client.Account, error)
- func (c *Client) AccountNumberSequence(addr sdk.AccAddress) (uint64, uint64, error)
- func (c *Client) Address(name string) (sdk.AccAddress, error)
- func (c *Client) Balance(ctx context.Context, addr sdk.AccAddress, denom string) (sdk.Coin, error)
- func (c *Client) BroadcastRawTx(ctx context.Context, txBytes []byte) (*txtypes.BroadcastTxResponse, error)
- func (c *Client) BroadcastTx(ctx context.Context, senderName string, msgs ...sdk.Msg) (*txtypes.BroadcastTxResponse, error)
- func (c *Client) Close() error
- func (c *Client) EncodeTxBytes(txBuilder client.TxBuilder) ([]byte, error)
- func (c *Client) LatestHeight(ctx context.Context) (int64, error)
- func (c *Client) Ping(timeout time.Duration) error
- func (c *Client) SendCoins(ctx context.Context, signerName string, fromAddr, toAddr sdk.AccAddress, ...) (*txtypes.BroadcastTxResponse, error)
- func (c *Client) SignTxWith(signerName string, txBuilder client.TxBuilder, accNum, seq uint64) error
- func (c *Client) SimulateGas(ctx context.Context, txBuilder client.TxBuilder) (uint64, error)
- func (c *Client) Status() (*coretypes.ResultStatus, error)
- func (c *Client) TxBuilder(msgs ...sdk.Msg) (client.TxBuilder, error)
- func (c *Client) TxFactory() (sdktx.Factory, error)
- func (c *Client) WaitForTx(ctx context.Context, txHash string, timeout, interval time.Duration) (*txtypes.GetTxResponse, error)
- type Config
- type KeyRing
Constants ¶
View Source
const ( DefaultHDPath = "m/44'/118'/0/0/0" DefaultAddressPrefix = "cosmos" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// 核心对象
Encoding moduletestutil.TestEncodingConfig
ClientCtx client.Context
KeyRing keyring.Keyring
Config Config
// contains filtered or unexported fields
}
Client 区块链客户端
func (*Client) AccountNumberSequence ¶ added in v0.0.25
AccountNumberSequence 通过地址查询账户号/序列号(支持各种账户类型)
func (*Client) Address ¶
func (c *Client) Address(name string) (sdk.AccAddress, error)
Address 通过 keyring 名称获取地址
func (*Client) BroadcastRawTx ¶ added in v0.0.26
func (c *Client) BroadcastRawTx(ctx context.Context, txBytes []byte) (*txtypes.BroadcastTxResponse, error)
BroadcastRawTx 通过 gRPC 广播已签名交易字节
func (*Client) BroadcastTx ¶ added in v0.0.25
func (c *Client) BroadcastTx( ctx context.Context, senderName string, msgs ...sdk.Msg, ) (*txtypes.BroadcastTxResponse, error)
BroadcastTx 通过 gRPC 广播 自动签名一步到位:构建->签名->广播
func (*Client) EncodeTxBytes ¶ added in v0.0.25
EncodeTxBytes 编码为 protobuf bytes
func (*Client) LatestHeight ¶ added in v0.0.25
LatestHeight 获取最新区块高度
func (*Client) SendCoins ¶ added in v0.0.25
func (c *Client) SendCoins( ctx context.Context, signerName string, fromAddr, toAddr sdk.AccAddress, amounts ...string, ) (*txtypes.BroadcastTxResponse, error)
SendCoins 使用指定 signer 从 from -> to 转账 amounts: ["10stake","10token"]
func (*Client) SignTxWith ¶ added in v0.0.25
func (c *Client) SignTxWith(signerName string, txBuilder client.TxBuilder, accNum, seq uint64) error
SignTxWith 显式给定 accNum/seq 的签名(并发压测推荐用)
func (*Client) SimulateGas ¶ added in v0.0.25
SimulateGas 使用 gRPC TxService.Simulate 估算 gas(返回 GasUsed)
type Config ¶ added in v0.0.25
type Config struct {
// 基础设置
ChainID string // 链 ID, node id
NodeRPC string // 节点 RPC 地址 e.g. "http://127.0.0.1:26657"
NodeGRPC string // 节点 gRPC 地址 e.g. "127.0.0.1:9090"
HomeDir string // 数据目录
KeyringBackend string // "test" | "file" | "os"
BroadcastMode txtypes.BroadcastMode // 广播模式
// 发送交易相关设置
Fee string // e.g. "{amount0}{denomination},...,{amountN}{denominationN}"
GasLimit uint64
// gRPC 限制/保活
GRPCMaxRecvBytes int
GRPCMaxSendBytes int
KeepaliveTime time.Duration
KeepaliveTimeout time.Duration
// 调试 / 其他
SkipConfirmation bool
// 自定义模块注册(可选,覆盖默认:auth + bank)
// 用于自定义 encoding config(注册更多模块)
RegisterModules func() moduletestutil.TestEncodingConfig
}
Config 客户端的配置参数
func DefaultConfig ¶ added in v0.0.25
func DefaultConfig(chainid, homedir string, modules ...module.AppModuleBasic) Config
DefaultConfig 获取默认配置 modules yourmodule.AppModule{} (通过go.mod引入yourmodule "module/x/module/foo")
type KeyRing ¶
type KeyRing struct {
Address string `json:"address"` // cosmos地址
Mnemonic string `json:"mnemonic"` // 24词助记词
Private *secp256k1.PrivKey `json:"private"` // 私钥
Public *secp256k1.PubKey `json:"public"` // 公钥
HDPath string `json:"hd_path"` // HD路径
}
KeyRing 包含区块链账户的密钥信息
func NewDefaultKey ¶
NewDefaultKey 创建一个使用默认前缀和HD路径的新密钥 返回生成的密钥信息和可能的错误
Click to show internal directories.
Click to hide internal directories.