Use EmitUnpopulated so that kaspactl prints all fields, even the default ones (#1561)

Co-authored-by: Elichai Turkel <elichai.turkel@gmail.com>
This commit is contained in:
Svarog 2021-03-01 14:47:34 +02:00 committed by GitHub
parent 103edf97d0
commit df19bdfaf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -2,10 +2,11 @@ package main
import (
"fmt"
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver/protowire"
"os"
"time"
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/server/grpcserver/protowire"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"
@ -67,7 +68,7 @@ func postCommand(cfg *configFlags, client *grpcclient.GRPCClient, responseChan c
if err != nil {
printErrorAndExit(fmt.Sprintf("error posting the request to the RPC server: %s", err))
}
responseBytes, err := protojson.Marshal(response)
responseBytes, err := protojson.MarshalOptions{EmitUnpopulated: true}.Marshal(response)
if err != nil {
printErrorAndExit(errors.Wrapf(err, "error parsing the response from the RPC server").Error())
}
@ -92,6 +93,7 @@ func prettifyResponse(response string) string {
marshalOptions := &protojson.MarshalOptions{}
marshalOptions.Indent = " "
marshalOptions.EmitUnpopulated = true
return marshalOptions.Format(kaspadMessage)
}

View File

@ -21,7 +21,7 @@ func (c *GRPCClient) PostJSON(requestJSON string) (string, error) {
if err != nil {
return "", err
}
responseBytes, err := protojson.Marshal(response)
responseBytes, err := protojson.MarshalOptions{EmitUnpopulated: true}.Marshal(response)
if err != nil {
return "", errors.Wrapf(err, "error parsing the response from the RPC server")
}