Require proto.Message in client.Context.PrintOutput (#6999)

* Enable proto JSON json for cli tx & query

* WIP on tests

* Test fixes, cleanup

* Cleanup

* Address review comments

* Update client/context.go

Co-authored-by: Anil Kumar Kammari <anil@vitwit.com>

* Fixes

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Anil Kumar Kammari <anil@vitwit.com>
This commit is contained in:
Aaron Craelius
2020-08-11 03:19:49 -04:00
committed by GitHub
co-authored by Anil Kumar Kammari Federico Kunze
parent 20c80cfd44
commit 7de8ef75b3
19 changed files with 95 additions and 99 deletions
+13 -1
View File
@@ -5,6 +5,8 @@ import (
"io"
"os"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
rpcclient "github.com/tendermint/tendermint/rpc/client"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
@@ -209,7 +211,17 @@ func (ctx Context) PrintString(str string) error {
// PrintOutput outputs toPrint to the ctx.Output based on ctx.OutputFormat which is
// either text or json. If text, toPrint will be YAML encoded. Otherwise, toPrint
// will be JSON encoded using ctx.JSONMarshaler. An error is returned upon failure.
func (ctx Context) PrintOutput(toPrint interface{}) error {
func (ctx Context) PrintOutput(toPrint proto.Message) error {
return ctx.printOutput(toPrint)
}
// PrintOutputLegacy is a variant of PrintOutput that doesn't require a proto type
// and uses amino JSON encoding. It will be removed in the near future!
func (ctx Context) PrintOutputLegacy(toPrint interface{}) error {
return ctx.WithJSONMarshaler(ctx.LegacyAmino).printOutput(toPrint)
}
func (ctx Context) printOutput(toPrint interface{}) error {
// always serialize JSON initially because proto json can't be directly YAML encoded
out, err := ctx.JSONMarshaler.MarshalJSON(toPrint)
if err != nil {
+1 -1
View File
@@ -50,7 +50,7 @@ func ValidatorCommand() *cobra.Command {
return err
}
return clientCtx.PrintOutput(result)
return clientCtx.PrintOutputLegacy(result)
},
}