mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
Renames LUX_-prefixed env vars to canonical, non-noisy forms: - LUX_MNEMONIC -> MNEMONIC (deploy script + LLM doc) - LUX_PRIVATE_KEY -> PRIVATE_KEY (deploy script + LLM doc) - LUX_INSECURE_TLS -> INSECURE_TLS - LUX_NODE_ENDPOINT -> NODE_ENDPOINT - LUX_NETWORK_TYPE -> NETWORK_TYPE (backend gRPC server selector) - LUX_RPC_URL -> RPC_URL - LUX_NODE_ROOT -> NODE_ROOT - LUX_CHART_PATH -> CHART_PATH - LUX_CHAINS_FILE -> CHAINS_FILE - LUX_KMS_ROOT_KEY -> KMS_ROOT_KEY - LUX_WC_PROJECT_ID -> WC_PROJECT_ID (WalletConnect) - LUX_BLS_KEY -> BLS_KEY (was already supported via getEnv()) - LUX_KEY_INDEX -> KEY_INDEX (was already supported via getEnv()) pkg/key/backend_env.go: removed the LUX_-prefix-stripping getEnv() helper (now reads env vars by exact name) and dropped the broken "MNEMONIC / MNEMONIC" / "PRIVATE_KEY / PRIVATE_KEY" doc comments which were a previous incomplete rename. NOT renamed (defined in upstream luxfi/constants — separate concern): - LUX_NODE_PATH (constants.EnvNodePath) - LUX_NETRUNNER_PATH (constants.EnvNetrunnerPath) - LUX_EVM_PATH (constants.EnvEVMPath) - LUX_PLUGINS_DIR (constants.EnvPluginsDir) Doc comments referencing those env vars (cmd/root.go, cmd/networkcmd/start.go, cmd/nodecmd/link.go) describe the constants-defined names accurately and are left alone. NOT renamed (script-local variables, not env vars): - LUX_ZONE in scripts/update-cloudflare-dns.sh (Cloudflare DNS zone ID) - LUX_BIN_DIR in scripts/install.sh (~/.lux/bin path constant) BREAKING: external callers/operators must update env var names. Per CLAUDE.md no-backwards-compatibility rule, the old forms are removed.
99 lines
3.0 KiB
Go
99 lines
3.0 KiB
Go
// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package backendcmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/luxfi/cli/pkg/application"
|
|
"github.com/luxfi/cli/pkg/binutils"
|
|
"github.com/luxfi/constants"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var app *application.Lux
|
|
|
|
// NewCmd creates the lux-server command (formerly cli-backend).
|
|
// This is the gRPC server that manages local network nodes.
|
|
// The network type is determined by NETWORK_TYPE environment variable.
|
|
func NewCmd(injectedApp *application.Lux) *cobra.Command {
|
|
app = injectedApp
|
|
|
|
// Create base command
|
|
baseCmd := &cobra.Command{
|
|
Use: constants.LuxServerCmd,
|
|
Short: "Run the Lux gRPC server",
|
|
Long: `The Lux gRPC server manages local network nodes.
|
|
|
|
This command is normally invoked automatically by 'lux network start'.
|
|
Each network type (mainnet, testnet, local) runs its own server on a dedicated port:
|
|
- mainnet: 8097
|
|
- testnet: 8098
|
|
- local: 8099
|
|
|
|
The network type is determined by the NETWORK_TYPE environment variable.`,
|
|
RunE: startBackend,
|
|
Args: cobra.ExactArgs(0),
|
|
Hidden: true,
|
|
}
|
|
|
|
return baseCmd
|
|
}
|
|
|
|
// NewNetworkCmd creates network-specific gRPC server commands.
|
|
// These commands allow easy identification of running network servers.
|
|
func NewNetworkCmd(injectedApp *application.Lux, networkType string) *cobra.Command {
|
|
app = injectedApp
|
|
cmdName := constants.GetServerCmdForNetwork(networkType)
|
|
|
|
return &cobra.Command{
|
|
Use: cmdName,
|
|
Short: fmt.Sprintf("Run the Lux gRPC server for %s", networkType),
|
|
Long: fmt.Sprintf("The Lux gRPC server for %s network. Invoked automatically by 'lux network start'.", networkType),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
// Override the environment variable with the command's network type
|
|
_ = os.Setenv("NETWORK_TYPE", networkType)
|
|
return startBackend(cmd, args)
|
|
},
|
|
Args: cobra.ExactArgs(0),
|
|
Hidden: true,
|
|
}
|
|
}
|
|
|
|
// NewAllNetworkCmds creates all network-specific gRPC server commands.
|
|
// Call this from root.go to register all network commands.
|
|
func NewAllNetworkCmds(injectedApp *application.Lux) []*cobra.Command {
|
|
networks := []string{"mainnet", "testnet", "devnet", "local"}
|
|
cmds := make([]*cobra.Command, len(networks))
|
|
for i, network := range networks {
|
|
cmds[i] = NewNetworkCmd(injectedApp, network)
|
|
}
|
|
return cmds
|
|
}
|
|
|
|
func startBackend(_ *cobra.Command, _ []string) error {
|
|
// Get network type from environment variable (set by StartServerProcessForNetwork)
|
|
// Defaults to "mainnet" for backward compatibility
|
|
networkType := os.Getenv("NETWORK_TYPE")
|
|
if networkType == "" {
|
|
networkType = "mainnet"
|
|
}
|
|
|
|
s, err := binutils.NewGRPCServerForNetwork(app.GetSnapshotsDir(), networkType)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
serverCtx, serverCancel := context.WithCancel(context.Background())
|
|
errc := make(chan error)
|
|
ports := binutils.GetGRPCPorts(networkType)
|
|
fmt.Printf("starting server for %s network on port %d\n", networkType, ports.Server)
|
|
go binutils.WatchServerProcess(serverCancel, errc, app.Log)
|
|
errc <- s.Run(serverCtx)
|
|
|
|
return nil
|
|
}
|