-
Notifications
You must be signed in to change notification settings - Fork 0
/
consensus.go
56 lines (53 loc) · 1.21 KB
/
consensus.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
package consensus
import (
"github.com/urfave/cli"
"fmt"
"os"
"github.com/icloudland/starchain/net/rpchttp"
"github.com/icloudland/starchain/client"
)
func consAction(c *cli.Context) error{
if c.NumFlags() == 0 {
cli.ShowSubcommandHelp(c)
return nil
}
switch {
case c.Bool("start"):
resp, err := rpchttp.Call(client.Address(), "startconsensus", 0, []interface{}{})
if err != nil {
fmt.Fprintln(os.Stderr, err)
return err
}
client.FormatOutput(resp)
case c.Bool("stop"):
resp, err := rpchttp.Call(client.Address(), "stopconsensus", 0, []interface{}{})
if err != nil {
fmt.Fprintln(os.Stderr, err)
return err
}
client.FormatOutput(resp)
}
return nil
}
func NewCommond() *cli.Command{
return &cli.Command{
Name:"consensus",
Usage:"start or stop consensus with args --start, --stop",
Description:"control consensus of node with console",
Flags:[]cli.Flag{
cli.BoolFlag{
Name:"start",
Usage:"start consensus",
},
cli.BoolFlag{
Name:"stop",
Usage:"stop consensus",
},
},
Action:consAction,
OnUsageError: func(context *cli.Context, err error, isSubcommand bool) error {
client.PrintError(context,err,"consensus")
return cli.NewExitError("",1)
},
}
}