go-blockchain/commands.go
Claude b22eba2d45
Some checks failed
Security Scan / security (push) Successful in 15s
Test / Test (push) Failing after 36s
feat: chain status command + wallet info + core/api SSE tracking
chain status: live chain data from daemon RPC
  height, difficulty, aliases, sync state, HF5 countdown

wallet info: full wallet dump
  standard/integrated/auditable addresses, spend/view keys, seed

core/api now has WithSSEPath() for configurable SSE — ready for
go-blockchain integration when wiring as core/api service.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 03:04:05 +01:00

70 lines
1.8 KiB
Go

// Copyright (c) 2017-2026 Lethean (https://lt.hn)
//
// Licensed under the European Union Public Licence (EUPL) version 1.2.
// SPDX-License-Identifier: EUPL-1.2
package blockchain
import (
"dappco.re/go/core"
coreio "dappco.re/go/core/io"
coreerr "dappco.re/go/core/log"
"dappco.re/go/core/blockchain/config"
"github.com/spf13/cobra"
)
// AddChainCommands registers the "chain" command group with explorer
// and sync subcommands.
// Usage: blockchain.AddChainCommands(...)
func AddChainCommands(root *cobra.Command) {
var (
dataDir string
seed string
testnet bool
)
chainCmd := &cobra.Command{
Use: "chain",
Short: "Lethean blockchain node",
Long: "Manage the Lethean blockchain — sync, explore, and mine.",
}
chainCmd.PersistentFlags().StringVar(&dataDir, "data-dir", defaultDataDir(), "blockchain data directory")
chainCmd.PersistentFlags().StringVar(&seed, "seed", "seeds.lthn.io:36942", "seed peer address (host:port)")
chainCmd.PersistentFlags().BoolVar(&testnet, "testnet", false, "use testnet")
chainCmd.AddCommand(
newExplorerCmd(&dataDir, &seed, &testnet),
newSyncCmd(&dataDir, &seed, &testnet),
newServeCmd(&dataDir, &seed, &testnet),
newStatusCmd(&dataDir, &seed, &testnet),
)
root.AddCommand(chainCmd)
}
func resolveConfig(testnet bool, seed *string) (config.ChainConfig, []config.HardFork) {
if testnet {
if *seed == "seeds.lthn.io:36942" {
*seed = "localhost:46942"
}
return config.Testnet, config.TestnetForks
}
return config.Mainnet, config.MainnetForks
}
func defaultDataDir() string {
home := core.Env("DIR_HOME")
if home == "" {
return ".lethean"
}
return core.JoinPath(home, ".lethean", "chain")
}
func ensureDataDir(dataDir string) error {
if err := coreio.Local.EnsureDir(dataDir); err != nil {
return coreerr.E("ensureDataDir", "create data dir", err)
}
return nil
}