msgs

package
v0.1.118-dev Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package msgs wires the per-Msg subcommands shared by `polycli heimdall mktx`, `polycli heimdall send`, and `polycli heimdall estimate`. The package owns the shared flag bag (TxOpts), the msg-subcommand registry, and the common build/sign/broadcast/simulate pipeline.

For W3 the only implemented Msg is `withdraw` (MsgWithdrawFeeTx). Additional Msg types land alongside their subcommands in W4 by calling RegisterFactory in an init or Register call — see msgs/registry.go for the contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildChildren

func BuildChildren(mode Mode, globalFlags *config.Flags) []*cobra.Command

BuildChildren invokes every registered factory for the given mode and returns the resulting cobra subcommands in registry order. The umbrella command then AddCommand's them onto its own cobra tree.

A fresh slice of *cobra.Command is returned on every call so each umbrella owns independent children. Cobra's command tree is not thread-safe and a single *cobra.Command can only have one parent.

func Execute

func Execute(cmd *cobra.Command, opts *TxOpts, mode Mode, plan *Plan) error

Execute runs the full mktx/send/estimate pipeline for the given mode. Msg subcommands build their plan via Planner and hand it to Execute; everything else — account fetch, signing, broadcast, simulate — lives here so the mode-specific branches stay short.

Output is written to cmd.OutOrStdout(). Errors propagate; callers should not wrap them in a generic "failed" message because the tx/client packages already attach context.

func Names

func Names() []string

Names returns the sorted list of registered msg subcommands. Used by tests to assert the registry shape and by the umbrella commands to build their `Long` usage hints.

func RegisterFactory

func RegisterFactory(name string, factory Factory)

RegisterFactory adds a msg factory to the package-level registry. W3 registers `withdraw` via an init() in msgs/withdraw.go; W4 registers additional msg subcommands the same way. Duplicate names panic during init so the error is caught at startup.

name is the cobra subcommand verb (e.g. "withdraw"); it must be non-empty and unique across the registry.

func RegisterFlags

func RegisterFlags(cmd *cobra.Command, opts *TxOpts, mode Mode)

RegisterFlags attaches the shared tx flags to cmd. Call exactly once per msg-subcommand instance; both mktx/send/estimate share the same flag surface but each owns its own TxOpts so cobra can parse distinct invocations correctly.

Flag names follow the cast-style dash-separated convention from the heimdall CLAUDE.md. No leading articles, lowercase usage strings, no ending punctuation. Global/network flags (--rest-url, --rpc-url, --chain-id, --timeout, --json) are inherited from the heimdall parent command via its PersistentFlags.

Types

type Clients

type Clients struct {
	Cfg  *config.Config
	REST *client.RESTClient
	RPC  *client.RPCClient
}

Clients bundles the REST + RPC clients a msg subcommand needs to talk to Heimdall. Resolved per-invocation (not per-registration) so each run can honour the network flags.

func ResolveClients

func ResolveClients(cmd *cobra.Command, opts *TxOpts) (*Clients, error)

ResolveClients builds REST + RPC clients from opts.Global. Returns a UsageError when the global config is missing or malformed.

type Factory

type Factory func(mode Mode, globalFlags *config.Flags) *cobra.Command

Factory builds one instance of a single msg subcommand. Every msg supported by mktx/send/estimate registers one Factory; the umbrella commands call each factory with their mode so each umbrella owns its own command tree (cobra commands can only have one parent).

The factory returns a *cobra.Command that is fully wired: shared tx flags are attached via RegisterFlags, per-msg flags bound, and the RunE closure assembles and executes the builder using Execute.

type Mode

type Mode int

Mode is the action performed by an umbrella command: build only, build + broadcast, or build + simulate. Each Msg subcommand inspects the mode to tune output (e.g. skip broadcasting in `mktx`) and to skip fetching account info when inputs are sufficient without it.

const (
	// ModeMkTx builds a TxRaw and prints it. Never broadcasts.
	ModeMkTx Mode = iota
	// ModeSend builds, signs, broadcasts, and waits for inclusion.
	ModeSend
	// ModeEstimate builds, signs, and calls /cosmos/tx/v1beta1/simulate.
	ModeEstimate
)

func (Mode) String

func (m Mode) String() string

String returns the umbrella command name for a mode. Used in usage/error strings.

type Plan

type Plan struct {
	Msgs         []htx.Msg
	MsgShortType string
	// SignerAddress is the address used to fetch account
	// number/sequence and to populate Msg.Proposer-like fields when
	// the msg subcommand did not set them explicitly. Typically equal
	// to the resolved signer's Eth address.
	SignerAddress string
}

Plan carries the msg-subcommand's parsed output into Execute: the list of Msgs to include in the TxBody and the signer's on-chain identifier (used as the from / proposer field and as the account lookup key). MsgShortType is the short msg name (e.g. "MsgWithdrawFeeTx") used by the L1-mirroring force guard.

type ResolvedSigner

type ResolvedSigner struct {
	Key     *ecdsa.PrivateKey
	Address common.Address
}

ResolvedSigner carries everything a msg subcommand needs to sign and address a Msg: the secp256k1 private key plus the derived 20-byte Ethereum-style address used as the signer identifier on Heimdall messages.

func ResolveSigningKey

func ResolveSigningKey(opts *TxOpts, stdin io.Reader) (*ResolvedSigner, error)

ResolveSigningKey returns the signing key for the current TxOpts. Precedence (highest first):

  1. --private-key (hex). Logs a warning because the key is visible in shell history / `ps`.
  2. --mnemonic plus --mnemonic-index / --derivation-path.
  3. --keystore-file (explicit JSON path).
  4. --account / --from against the resolved keystore directory.

At least one source must be provided; otherwise a UsageError is returned so the command exits with rc=3 per §2.1.

BIP-39/32 derivation and keystore access are delegated to internal/heimdall/wallet so this path stays consistent with `polycli heimdall wallet`. Keystore-dir resolution is called with createDefault=false because signing is not a keystore-management operation — if the default dir does not exist, the caller should see a clear "account not found" error rather than have polycli silently materialise an empty keystore dir.

type TxOpts

type TxOpts struct {
	// Shared flags injected from the parent heimdall command. We keep
	// the pointer so each msg subcommand can resolve the network
	// config at run time.
	Global *config.Flags

	// Wallet: how to obtain the signing key.
	From           string
	KeystoreDir    string
	KeystoreFile   string
	Account        string
	Password       string
	PasswordFile   string
	PrivateKey     string
	Mnemonic       string
	MnemonicIndex  uint32
	DerivationPath string

	// Gas / fee.
	Gas           uint64
	GasAdjustment float64
	GasPrice      float64
	Fee           string
	Memo          string

	// Account overrides. Non-zero values skip the auto-fetch via
	// /cosmos/auth/v1beta1/accounts.
	AccountNumber uint64
	Sequence      uint64

	// Sign / broadcast.
	SignMode      string
	DryRun        bool
	Async         bool
	Confirmations uint64
	Force         bool

	// Output.
	JSONOut bool
}

TxOpts is the shared flag bag every msg subcommand receives. The fields are populated by cobra via RegisterFlags; a single TxOpts is allocated per (mode, msg) pair because cobra flag variables must be addressable and persist across the command's lifetime.

TxOpts intentionally carries only the "how to build/sign/broadcast" knobs — per-message fields (e.g. `--amount` on withdraw) live on the msg subcommand itself.

Jump to

Keyboard shortcuts

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