[aergocli] fix consensusinfo error lead by empty field
@@ -8,6 +8,7 @@ package cmd
import (
"context"
"encoding/json"
+
aergorpc "github.com/aergoio/aergo/types"
"github.com/spf13/cobra"
)
@@ -27,27 +28,31 @@ var getConsensusInfoCmd = &cobra.Command{
}
type outInfo struct {
- Type string
- Info *json.RawMessage
- Bps []*json.RawMessage
+ Type string `json:",omitempty"`
+ Info *json.RawMessage `json:",omitempty"`
+ Bps []*json.RawMessage `json:",omitempty"`
}
var out = &outInfo{}
out.Type = msg.Type
//cmd.Println(fmt.Sprintf("consensus:%s, leader:%d", msg.Type, uinfo.Leader))
+ if len(msg.Info) > 0 {
infoB := json.RawMessage(msg.Info)
out.Info = &infoB
+ }
+ if len(msg.Bps) > 0 {
out.Bps = make([]*json.RawMessage, len(msg.Bps))
for i, bpstr := range msg.Bps {
b := json.RawMessage([]byte(bpstr))
out.Bps[i] = &b
}
+ }
jsonout, err := json.Marshal(out)
if err != nil {
- cmd.Println("failed decode consensus info")
+ cmd.Printf("failed decode consensus info: %v\n", err)
return
}
