From b22eba2d456a42bc3844216b9687ec4aac14d1a6 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 03:04:05 +0100 Subject: [PATCH] feat: chain status command + wallet info + core/api SSE tracking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- cmd_status.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ cmd_wallet.go | 42 ++++++++++++++++++++++++++++++++++++++++ commands.go | 1 + 3 files changed, 96 insertions(+) create mode 100644 cmd_status.go diff --git a/cmd_status.go b/cmd_status.go new file mode 100644 index 0000000..bbc081d --- /dev/null +++ b/cmd_status.go @@ -0,0 +1,53 @@ +// 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" + + "dappco.re/go/core/blockchain/rpc" + "github.com/spf13/cobra" +) + +func newStatusCmd(dataDir, seed *string, testnet *bool) *cobra.Command { + return &cobra.Command{ + Use: "status", + Short: "Show chain and network status", + RunE: func(cmd *cobra.Command, args []string) error { + return runStatus(*seed, *testnet) + }, + } +} + +func runStatus(seed string, testnet bool) error { + rpcURL := seedToRPC(seed, testnet) + client := rpc.NewClient(rpcURL) + + info, err := client.GetInfo() + if err != nil { + core.Print(nil, "Daemon unreachable at %s", rpcURL) + return err + } + + core.Print(nil, "Lethean Chain Status") + core.Print(nil, " Height: %d", info.Height) + core.Print(nil, " Difficulty: %d", info.PowDifficulty) + core.Print(nil, " Aliases: %d", info.AliasCount) + core.Print(nil, " TX Pool: %d", info.TxPoolSize) + core.Print(nil, " PoS: %v", info.PosAllowed) + core.Print(nil, " Synced: %v", info.DaemonNetworkState == 2) + core.Print(nil, "") + + // Hardfork status + + hf5Remaining := int64(11500) - int64(info.Height) + if hf5Remaining > 0 { + core.Print(nil, "") + core.Print(nil, " HF5 in %d blocks (~%.1f hours)", hf5Remaining, float64(hf5Remaining)*2/60) + } + + return nil +} diff --git a/cmd_wallet.go b/cmd_wallet.go index 5dd0367..8e2b28c 100644 --- a/cmd_wallet.go +++ b/cmd_wallet.go @@ -43,6 +43,7 @@ func AddWalletCommands(root *cobra.Command) { newWalletScanCmd(&walletFile), newWalletRestoreCmd(&walletFile), newWalletTransferCmd(&walletFile), + newWalletInfoCmd(&walletFile), ) root.AddCommand(walletCmd) @@ -431,3 +432,44 @@ func runWalletTransfer(walletRPC, destination string, amount float64, paymentID return nil } + +func newWalletInfoCmd(walletFile *string) *cobra.Command { + return &cobra.Command{ + Use: "info", + Short: "Show full wallet information", + RunE: func(cmd *cobra.Command, args []string) error { + return runWalletInfo(*walletFile) + }, + } +} + +func runWalletInfo(walletFile string) error { + if walletFile == "" { + walletFile = core.JoinPath(defaultDataDir(), "wallet.db") + } + + s, err := store.New(walletFile) + if err != nil { + return coreerr.E("runWalletInfo", "open wallet store", err) + } + defer s.Close() + + account, err := wallet.LoadAccount(s, "") + if err != nil { + return coreerr.E("runWalletInfo", "load wallet", err) + } + + addr := account.Address() + seed, _ := account.ToSeed() + + core.Print(nil, "Wallet Information") + core.Print(nil, " File: %s", walletFile) + core.Print(nil, " Address: %s", addr.Encode(0x1eaf7)) + core.Print(nil, " Integrated: %s", addr.Encode(0xdeaf7)) + core.Print(nil, " Auditable: %s", addr.Encode(0x3ceff7)) + core.Print(nil, " Spend Key: %x", account.SpendPublicKey[:]) + core.Print(nil, " View Key: %x", account.ViewPublicKey[:]) + core.Print(nil, " Seed: %s", seed) + + return nil +} diff --git a/commands.go b/commands.go index f497b21..97f30ef 100644 --- a/commands.go +++ b/commands.go @@ -38,6 +38,7 @@ func AddChainCommands(root *cobra.Command) { newExplorerCmd(&dataDir, &seed, &testnet), newSyncCmd(&dataDir, &seed, &testnet), newServeCmd(&dataDir, &seed, &testnet), + newStatusCmd(&dataDir, &seed, &testnet), ) root.AddCommand(chainCmd)