forked from NebulousLabs/Sia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minercmd.go
69 lines (60 loc) · 1.51 KB
/
minercmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"github.com/spf13/cobra"
)
var (
minerCmd = &cobra.Command{
Use: "miner",
Short: "Perform miner actions",
Long: "Perform miner actions and view miner status.",
Run: wrap(minercmd),
}
minerStartCmd = &cobra.Command{
Use: "start",
Short: "Start cpu mining",
Long: "Start cpu mining, if the miner is already running, this command does nothing",
Run: wrap(minerstartcmd),
}
minerStopCmd = &cobra.Command{
Use: "stop",
Short: "Stop mining",
Long: "Stop mining (this may take a few moments).",
Run: wrap(minerstopcmd),
}
)
// minerstartcmd is the handler for the command `siac miner start`.
// Starts the CPU miner.
func minerstartcmd() {
err := httpClient.MinerStartGet()
if err != nil {
die("Could not start miner:", err)
}
fmt.Println("CPU Miner is now running.")
}
// minercmd is the handler for the command `siac miner`.
// Prints the status of the miner.
func minercmd() {
status, err := httpClient.MinerGet()
if err != nil {
die("Could not get miner status:", err)
}
miningStr := "off"
if status.CPUMining {
miningStr = "on"
}
fmt.Printf(`Miner status:
CPU Mining: %s
CPU Hashrate: %v KH/s
Blocks Mined: %d (%d stale)
`, miningStr, status.CPUHashrate/1000, status.BlocksMined, status.StaleBlocksMined)
}
// minerstopcmd is the handler for the command `siac miner stop`.
// Stops the CPU miner.
func minerstopcmd() {
err := httpClient.MinerStopGet()
if err != nil {
die("Could not stop miner:", err)
}
fmt.Println("Stopped mining.")
}