Documentation
¶
Overview ¶
Package common provides shared domain types and value objects.
Index ¶
- Constants
- Variables
- func GetErrorCode(err error) string
- func GetHomeDir() string
- func GetRecoveryHint(err error) string
- func GetUserMessage(err error) string
- func NormalizeImageURL(image string) string
- func SetHomeDir(dir string)
- func ShouldSilenceUsage(err error) bool
- type ChainID
- type DockerImageSelectionResult
- type ExecutionMode
- type FailedNodeJSON
- type NetworkSource
- type NodeResult
- type PortConfig
- type RecoverableError
- type SilenceUsageError
- type UserFacingError
- type Version
Constants ¶
const ( // DefaultRPCPort is the Tendermint/CometBFT RPC port. DefaultRPCPort = 26657 // DefaultP2PPort is the peer-to-peer networking port. DefaultP2PPort = 26656 // DefaultProxyPort is the ABCI proxy application port. DefaultProxyPort = 26658 // DefaultGRPCPort is the gRPC server port. DefaultGRPCPort = 9090 // DefaultGRPCWebPort is the gRPC-Web server port. DefaultGRPCWebPort = 9091 // DefaultAPIPort is the REST API (LCD) port. DefaultAPIPort = 1317 // DefaultEVMRPCPort is the EVM JSON-RPC port. DefaultEVMRPCPort = 8545 // DefaultEVMWSPort is the EVM WebSocket port. DefaultEVMWSPort = 8546 // DefaultPProfPort is the pprof debugging port. DefaultPProfPort = 6060 // DefaultRosettaPort is the Rosetta API port. DefaultRosettaPort = 8080 // DefaultPortOffset is the port offset multiplier per node. // Node 0: base ports, Node 1: base + 10000, Node 2: base + 20000, etc. DefaultPortOffset = 10000 )
Port default values - Single Source of Truth for all port constants. These constants are used throughout the codebase for node configuration.
const DefaultDockerPackage = "stable"
DefaultDockerPackage is the default container package name for docker images.
const DefaultGHCRImage = "ghcr.io/stablelabs/stable"
DefaultGHCRImage is the default GHCR image for stable.
const (
ExecutionModeCtxKey = "execution_mode"
)
Variables ¶
var (
HomeDir string = ""
)
Functions ¶
func GetErrorCode ¶
getErrorCode returns an error code string based on the error message.
func GetHomeDir ¶
func GetHomeDir() string
func GetRecoveryHint ¶
GetRecoveryHint extracts a recovery hint from an error. Returns empty string if no hint is available.
func GetUserMessage ¶
GetUserMessage extracts a user-friendly message from an error. Returns the UserMessage if the error implements UserFacingError, otherwise returns the standard Error() message.
func NormalizeImageURL ¶
NormalizeImageURL converts a tag-only input to a full GHCR URL. If the input already contains a registry (contains "/" or ":"), it returns as-is. Otherwise, it constructs: ghcr.io/stablelabs/stable:{tag}
func SetHomeDir ¶
func SetHomeDir(dir string)
func ShouldSilenceUsage ¶
ShouldSilenceUsage checks if an error should silence CLI usage output. Returns true if the error implements SilenceUsageError and returns true.
Types ¶
type ChainID ¶
type ChainID string
ChainID represents a Cosmos chain identifier.
func NewChainID ¶
NewChainID creates a new ChainID with validation.
type DockerImageSelectionResult ¶
type DockerImageSelectionResult struct {
ImageTag string // Selected image tag or full custom URL
IsCustom bool // True if user entered a custom image URL
FromCache bool // True if versions were loaded from cache
}
DockerImageSelectionResult holds the result of docker image selection.
type ExecutionMode ¶
type ExecutionMode string
ExecutionMode defines how nodes are executed.
var ( ExecutionModeDocker ExecutionMode = "docker" ExecutionModeLocal ExecutionMode = "local" )
func (ExecutionMode) IsValid ¶
func (m ExecutionMode) IsValid() bool
IsValid checks if the execution mode is valid.
func (ExecutionMode) String ¶
func (m ExecutionMode) String() string
String returns the string representation.
type FailedNodeJSON ¶
type FailedNodeJSON struct {
Index int `json:"index"`
Error string `json:"error"`
LogPath string `json:"log_path"`
LogTail []string `json:"log_tail,omitempty"`
}
FailedNodeJSON represents a failed node in JSON output.
type NetworkSource ¶
type NetworkSource string
NetworkSource represents the source network for snapshots.
const ( NetworkSourceMainnet NetworkSource = "mainnet" NetworkSourceTestnet NetworkSource = "testnet" )
func (NetworkSource) IsValid ¶
func (n NetworkSource) IsValid() bool
IsValid checks if the network source is valid.
func (NetworkSource) String ¶
func (n NetworkSource) String() string
String returns the string representation.
type NodeResult ¶
type NodeResult struct {
Index int `json:"index"`
RPC string `json:"rpc"`
EVMRPC string `json:"evm_rpc"`
Status string `json:"status"`
}
NodeResult represents a node in the JSON output.
type PortConfig ¶
type PortConfig struct {
// RPC is the Tendermint/CometBFT RPC port (default: 26657)
RPC int `json:"rpc"`
// P2P is the peer-to-peer network port (default: 26656)
P2P int `json:"p2p"`
// Proxy is the ABCI proxy application port (default: 26658)
Proxy int `json:"proxy,omitempty"`
// GRPC is the gRPC server port (default: 9090)
GRPC int `json:"grpc"`
// GRPCWeb is the gRPC-Web server port (default: 9091)
GRPCWeb int `json:"grpc_web,omitempty"`
// API is the REST API (LCD) port (default: 1317)
API int `json:"api"`
// EVMRPC is the EVM JSON-RPC port (default: 8545)
// Only applicable to EVM-compatible networks.
EVMRPC int `json:"evm_rpc"`
// EVMWS is the EVM WebSocket port (default: 8546)
// Only applicable to EVM-compatible networks.
EVMWS int `json:"evm_ws,omitempty"`
// PProf is the pprof debugging port (default: 6060)
PProf int `json:"pprof,omitempty"`
// Rosetta is the Rosetta API port (default: 8080)
Rosetta int `json:"rosetta,omitempty"`
}
PortConfig contains network port configuration for a node. This is the canonical type used throughout the codebase. All infrastructure packages should convert to/from this type.
func DefaultPortConfig ¶
func DefaultPortConfig() PortConfig
DefaultPortConfig returns a PortConfig with all default values.
func PortConfigForNode ¶
func PortConfigForNode(index int) PortConfig
PortConfigForNode returns the port configuration for a node at the given index. Each node has a port offset of DefaultPortOffset * index. Node 0 uses default ports, Node 1 adds 10000, Node 2 adds 20000, etc.
func (PortConfig) APIURL ¶
func (p PortConfig) APIURL(host string) string
APIURL returns the full REST API URL for this port configuration.
func (PortConfig) EVMRPCURL ¶
func (p PortConfig) EVMRPCURL(host string) string
EVMRPCURL returns the full EVM JSON-RPC URL for this port configuration.
func (PortConfig) RPCURL ¶
func (p PortConfig) RPCURL(host string) string
RPCURL returns the full RPC URL for this port configuration.
func (PortConfig) WithOffset ¶
func (p PortConfig) WithOffset(offset int) PortConfig
WithOffset returns a new PortConfig with all ports offset by the given amount. Useful for running multiple nodes on the same machine.
type RecoverableError ¶
RecoverableError is implemented by errors that suggest a recovery action. The presentation layer can use this to provide actionable guidance.
type SilenceUsageError ¶
SilenceUsageError is implemented by errors that should NOT trigger CLI usage information. This is useful for operational errors where the user's command syntax was correct, but something else failed.
Examples:
- Authentication failures (user knows the command, just needs a token)
- Network connectivity issues
- Resource not found (but the command was used correctly)
Usage in Cobra command:
if _, ok := err.(SilenceUsageError); ok && err.ShouldSilenceUsage() {
cmd.SilenceUsage = true
}
type UserFacingError ¶
UserFacingError is implemented by errors that have a user-friendly message that should be displayed directly to the user.
This allows infrastructure errors to provide guidance on how to fix the issue (e.g., "run this command to configure authentication").