forked from iost-official/go-iost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.go
38 lines (34 loc) · 901 Bytes
/
state.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
package iwallet
import (
"fmt"
"strings"
"github.com/iost-official/go-iost/sdk"
"github.com/spf13/cobra"
)
// stateCmd prints the state of blockchain.
var stateCmd = &cobra.Command{
Use: "state",
Short: "Get blockchain and node state",
Long: `Get blockchain and node state`,
Example: ` iwallet state`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := iwalletSDK.Connect(); err != nil {
return err
}
defer iwalletSDK.CloseConn()
n, err := iwalletSDK.GetNodeInfo()
if err != nil {
return fmt.Errorf("cannot get node info: %v", err)
}
fmt.Print(strings.TrimRight(sdk.MarshalTextString(n), "}"))
c, err := iwalletSDK.GetChainInfo()
if err != nil {
return fmt.Errorf("cannot get chain info: %v", err)
}
fmt.Println(strings.Replace(sdk.MarshalTextString(c), "{\n", "", 1))
return nil
},
}
func init() {
rootCmd.AddCommand(stateCmd)
}