This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
go-monero/cmd/monero/commands/daemon/mining_status.go
2022-10-05 09:40:23 +02:00

78 lines
1.9 KiB
Go

package daemon
import (
"fmt"
"github.com/spf13/cobra"
"git.gammaspectra.live/P2Pool/go-monero/cmd/monero/display"
"git.gammaspectra.live/P2Pool/go-monero/cmd/monero/options"
"git.gammaspectra.live/P2Pool/go-monero/pkg/rpc/daemon"
)
type miningStatusCommand struct {
JSON bool
}
func (c *miningStatusCommand) Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "mining-status",
Short: "information about this daemon's mining activity",
RunE: c.RunE,
}
cmd.Flags().BoolVar(&c.JSON, "json",
false, "whether or not to output the result as json")
return cmd
}
func (c *miningStatusCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOpts.Client()
if err != nil {
return fmt.Errorf("client: %w", err)
}
resp, err := client.MiningStatus(ctx)
if err != nil {
return fmt.Errorf("get bans: %w", err)
}
if c.JSON {
return display.JSON(resp)
}
c.pretty(resp)
return nil
}
// nolint:forbidigo
func (c *miningStatusCommand) pretty(v *daemon.MiningStatusResult) {
table := display.NewTable()
table.AddRow("Active:", v.Active)
table.AddRow("Address:", v.Address)
table.AddRow("Background Idle Threshold:", v.BgIdleThreshold)
table.AddRow("Background Ignore Battery:", v.BgIgnoreBattery)
table.AddRow("Background Minimum Idle Seconds:", v.BgMinIdleSeconds)
table.AddRow("Background Target:", v.BgTarget)
table.AddRow("Block Reward:", v.BlockReward)
table.AddRow("Block Target:", v.BlockTarget)
table.AddRow("Difficulty:", v.Difficulty)
table.AddRow("Difficulty Top64:", v.DifficultyTop64)
table.AddRow("Background Mining Enabled:", v.IsBackgroundMiningEnabled)
table.AddRow("Proof-of-Work Algorithm:", v.PowAlgorithm)
table.AddRow("Speed", v.Speed)
table.AddRow("Threads:", v.ThreadsCount)
table.AddRow("Wide Difficulty:", v.WideDifficulty)
fmt.Println(table)
}
func init() {
RootCommand.AddCommand((&miningStatusCommand{}).Cmd())
}