Documentation
¶
Overview ¶
Package cmdutil holds the plumbing shared by every `polycli heimdall` command package: config-resolving client constructors, render.Options assembly, JSON decoding, hex normalization, the gRPC-gateway error envelope, and generic cobra command builders for the common "GET endpoint → render" and "CometBFT RPC → render" shapes.
Index ¶
- Constants
- func CallEmpty(ctx context.Context, rpc *client.RPCClient, method string) (json.RawMessage, error)
- func DecodeGeneric(raw json.RawMessage) (any, error)
- func DecodeJSONMap(raw []byte, label string) (map[string]any, error)
- func IsL1Unreachable(body []byte, err error) bool
- func IsTerminal(w io.Writer) bool
- func NormalizeAddress(raw string) (string, error)
- func NormalizeHex(raw string, byteLen int, label string) (string, error)
- func NormalizeHexBytes(raw, label string) (string, error)
- func NormalizeTxHash(raw string) (string, error)
- func RenderOpts(cmd *cobra.Command, cfg *config.Config, fields []string) render.Options
- func Truncate(b []byte, n int) string
- type GRPCErrorBody
- type Get
- type Pkg
- type RPC
Constants ¶
GRPCCodeUnavailable is the L1-unreachable code surfaced by the endpoints that fan out to L1 on the server side (clerk/topup sequence + is-old, stake is-old-tx, topup account-proof) when the Heimdall node lacks `eth_rpc_url`.
Variables ¶
This section is empty.
Functions ¶
func CallEmpty ¶
CallEmpty issues an RPC call with an explicit empty params object. CometBFT's reflect-based RPC layer rejects nil params on some methods with "reflect: Call with too few input arguments"; passing map[string]any{} avoids that trap while still producing a valid JSON-RPC envelope.
func DecodeGeneric ¶
func DecodeGeneric(raw json.RawMessage) (any, error)
DecodeGeneric unmarshals raw into any (map/slice/string). Used when we want to emit --json passthrough or pluck via --field.
func DecodeJSONMap ¶
DecodeJSONMap decodes raw into a map[string]any. Used by REST responses whose top-level shape is always an object.
func IsL1Unreachable ¶
IsL1Unreachable inspects a REST body / error pair and returns true if the response looks like "gRPC code 13 because L1 RPC isn't configured on this Heimdall". The body may come either from a successful 2xx response that still carries a gRPC-error envelope, or from an HTTPError (4xx/5xx). The transport layer surfaces "dial tcp" / "connection refused" when the REST gateway itself can't reach L1.
func IsTerminal ¶
IsTerminal returns true if w is an *os.File attached to a terminal.
func NormalizeAddress ¶
NormalizeAddress normalizes a 20-byte Ethereum address.
func NormalizeHex ¶
NormalizeHex accepts a fixed-length hex value with or without the `0x` prefix and returns the lower-case, `0x`-prefixed form expected by the Heimdall REST endpoints. label names the value in errors (e.g. "address", "signer", "tx hash").
func NormalizeHexBytes ¶
NormalizeHexBytes accepts a variable-length hex string with or without the `0x` prefix and returns the lower-case form WITHOUT the prefix (for use as a bare query param). Empty input is an error.
func NormalizeTxHash ¶
NormalizeTxHash normalizes a 32-byte transaction hash. The REST endpoints expect the `0x` prefix and will 500 without it, so we re-add it unconditionally.
func RenderOpts ¶
RenderOpts turns a resolved config into a render.Options instance, honouring --json, --field, --color, --raw, and TTY detection.
Types ¶
type GRPCErrorBody ¶
GRPCErrorBody is the standard gRPC-gateway error envelope returned on 4xx/5xx from Heimdall REST. Only `code` and `message` are used here.
type Get ¶
type Get struct {
Use string
Short string
Aliases []string
// Args defaults to cobra.NoArgs.
Args cobra.PositionalArgs
// Label names the response in decode/gRPC errors, e.g. "milestone params".
Label string
// Path is the fixed REST path. Mutually exclusive with Build.
Path string
// Build computes the path and query from the CLI args.
Build func(cmd *cobra.Command, args []string) (string, url.Values, error)
// L1Hint surfaces render.HintL1NotConfigured when the call fails
// with gRPC code 13 / a transport-level dial error, and checks the
// 2xx body for a gRPC error envelope before rendering.
L1Hint bool
// FieldsUsage overrides the --field usage string.
FieldsUsage string
// Flags registers extra command flags.
Flags func(fs *pflag.FlagSet)
// Opts post-processes the render options (e.g. a --base64 sugar flag).
Opts func(cmd *cobra.Command, opts *render.Options)
// Render renders the decoded map when --json is NOT set. nil falls
// back to RenderKV, after unwrapping UnwrapKey if present.
Render func(cmd *cobra.Command, m map[string]any, opts render.Options) error
// RenderBody takes over non-JSON rendering before map decoding
// (e.g. printing one bare field from a typed struct).
RenderBody func(cmd *cobra.Command, body []byte, opts render.Options) error
// UnwrapKey names a single-key envelope to unwrap for KV output.
UnwrapKey string
}
Get describes a REST GET command: fetch one endpoint, decode the JSON-object body, and render it as JSON or KV. The zero hooks cover the plain case; the optional ones absorb the per-command quirks.
type Pkg ¶
type Pkg struct {
// Name is the package label used in "not registered" errors.
Name string
// Flags is injected by the package's Register call.
Flags *config.Flags
}
Pkg carries the per-command-package registration state. Each command package declares one and points Flags at the shared flag struct in its Register function.
func (*Pkg) RESTClient ¶
RESTClient resolves the config and constructs a RESTClient. When --curl is set the HTTP call is replaced by a printed curl command.
type RPC ¶
type RPC struct {
Use string
Short string
Aliases []string
// Args defaults to cobra.NoArgs.
Args cobra.PositionalArgs
// Method is the CometBFT RPC method, e.g. "abci_info".
Method string
// FieldsUsage overrides the --field usage string.
FieldsUsage string
// Flags registers extra command flags.
Flags func(fs *pflag.FlagSet)
// Render renders the raw RPC result when --json is NOT set.
Render func(cmd *cobra.Command, raw json.RawMessage, opts render.Options) error
}
RPC describes a CometBFT JSON-RPC command: call one method with empty params, pass the raw result through for --json, and hand it to Render otherwise.