diff --git a/client/v2/autocli/flag/builder.go b/client/v2/autocli/flag/builder.go index c595f5590802..bb2b7a0b530e 100644 --- a/client/v2/autocli/flag/builder.go +++ b/client/v2/autocli/flag/builder.go @@ -30,7 +30,10 @@ type Builder struct { // FileResolver specifies how protobuf file descriptors will be resolved. If it is // nil protoregistry.GlobalFiles will be used. - FileResolver protodesc.Resolver + FileResolver interface { + protodesc.Resolver + RangeFiles(func(protoreflect.FileDescriptor) bool) + } messageFlagTypes map[protoreflect.FullName]Type scalarFlagTypes map[string]Type diff --git a/client/v2/autocli/query.go b/client/v2/autocli/query.go index acad36e9ff40..da88d5b0d25a 100644 --- a/client/v2/autocli/query.go +++ b/client/v2/autocli/query.go @@ -2,11 +2,13 @@ package autocli import ( "fmt" + "io" + "time" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "cosmossdk.io/x/tx/signing/aminojson" "github.com/cockroachdb/errors" "github.com/spf13/cobra" - "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/reflect/protoreflect" "cosmossdk.io/client/v2/internal/util" @@ -101,17 +103,16 @@ func (b *Builder) BuildQueryMethodCommand(descriptor protoreflect.MethodDescript serviceDescriptor := descriptor.Parent().(protoreflect.ServiceDescriptor) methodName := fmt.Sprintf("/%s/%s", serviceDescriptor.FullName(), descriptor.Name()) outputType := util.ResolveMessageType(b.TypeResolver, descriptor.Output()) - jsonMarshalOptions := protojson.MarshalOptions{ + encoderOptions := aminojson.EncoderOptions{ Indent: " ", - UseProtoNames: true, - UseEnumNumbers: false, - EmitUnpopulated: true, - Resolver: b.TypeResolver, + DoNotSortFields: true, + TypeResolver: b.TypeResolver, + FileResolver: b.FileResolver, } cmd, err := b.buildMethodCommandCommon(descriptor, options, func(cmd *cobra.Command, input protoreflect.Message) error { - if noIdent, _ := cmd.Flags().GetBool(flagNoIndent); noIdent { - jsonMarshalOptions.Indent = "" + if noIndent, _ := cmd.Flags().GetBool(flagNoIndent); noIndent { + encoderOptions.Indent = "" } clientConn, err := getClientConn(cmd) @@ -124,7 +125,8 @@ func (b *Builder) BuildQueryMethodCommand(descriptor protoreflect.MethodDescript return err } - bz, err := jsonMarshalOptions.Marshal(output.Interface()) + enc := encoder(aminojson.NewEncoder(encoderOptions)) + bz, err := enc.Marshal(output.Interface()) if err != nil { return fmt.Errorf("cannot marshal response %v: %w", output.Interface(), err) } @@ -143,3 +145,30 @@ func (b *Builder) BuildQueryMethodCommand(descriptor protoreflect.MethodDescript return cmd, nil } + +func encoder(encoder aminojson.Encoder) aminojson.Encoder { + return encoder.DefineTypeEncoding("google.protobuf.Duration", func(_ *aminojson.Encoder, msg protoreflect.Message, w io.Writer) error { + var ( + secondsName protoreflect.Name = "seconds" + nanosName protoreflect.Name = "nanos" + ) + + fields := msg.Descriptor().Fields() + secondsField := fields.ByName(secondsName) + if secondsField == nil { + return fmt.Errorf("expected seconds field") + } + + seconds := msg.Get(secondsField).Int() + + nanosField := fields.ByName(nanosName) + if nanosField == nil { + return fmt.Errorf("expected nanos field") + } + + nanos := msg.Get(nanosField).Int() + + _, err := fmt.Fprintf(w, `"%s"`, (time.Duration(seconds)*time.Second + (time.Duration(nanos) * time.Nanosecond)).String()) + return err + }) +} diff --git a/client/v2/go.mod b/client/v2/go.mod index 12986377093a..0fd978cec0a5 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -7,6 +7,7 @@ require ( cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 cosmossdk.io/log v1.2.1 + cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 github.com/cockroachdb/errors v1.11.1 github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230718211500-1d74652f6021 @@ -24,7 +25,6 @@ require ( cosmossdk.io/errors v1.0.0 // indirect cosmossdk.io/math v1.1.2 // indirect cosmossdk.io/store v1.0.0-rc.0 // indirect - cosmossdk.io/x/tx v0.9.1 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/client/v2/go.sum b/client/v2/go.sum index 5f5e4a82ea3f..5e930c04cc0d 100644 --- a/client/v2/go.sum +++ b/client/v2/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM= cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= cosmossdk.io/store v1.0.0-rc.0 h1:9DwOjuUYxDtYxn/REkTxGQAmxlIGfRroB35MQ8TrxF4= cosmossdk.io/store v1.0.0-rc.0/go.mod h1:FtBDOJmwtOZfmKKF65bKZbTYgS3bDNjjo3nP76dAegk= -cosmossdk.io/x/tx v0.9.1 h1:9pmmXA9Vs4qdouOFnzhsdsff2mif0f0kylMq5xTGhRI= -cosmossdk.io/x/tx v0.9.1/go.mod h1:/YFGTXG6+kyihd8YbfuJiXHV4R/mIMm2uvVzo80CIhA= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 h1:p/wyc5pVTMtx2/RsKP0fUpOKGbDfy6q6WswJtmARdbg= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382/go.mod h1:MKo9/b5wsoL8dd9y9pvD2yOP1CMvzHIWYxi1l2oLPFo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/simapp/go.mod b/simapp/go.mod index dbac48dbfda9..b02a27b0dcff 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -16,7 +16,7 @@ require ( cosmossdk.io/x/evidence v0.0.0-20230613133644-0a778132a60f cosmossdk.io/x/feegrant v0.0.0-20230613133644-0a778132a60f cosmossdk.io/x/nft v0.0.0-20230613133644-0a778132a60f - cosmossdk.io/x/tx v0.9.1 + cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 cosmossdk.io/x/upgrade v0.0.0-20230613133644-0a778132a60f github.com/cometbft/cometbft v0.38.0 github.com/cosmos/cosmos-db v1.0.0 diff --git a/simapp/go.sum b/simapp/go.sum index 1e6a0cbba5d9..4b84461be0e2 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -203,8 +203,8 @@ cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM= cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= cosmossdk.io/store v1.0.0-rc.0 h1:9DwOjuUYxDtYxn/REkTxGQAmxlIGfRroB35MQ8TrxF4= cosmossdk.io/store v1.0.0-rc.0/go.mod h1:FtBDOJmwtOZfmKKF65bKZbTYgS3bDNjjo3nP76dAegk= -cosmossdk.io/x/tx v0.9.1 h1:9pmmXA9Vs4qdouOFnzhsdsff2mif0f0kylMq5xTGhRI= -cosmossdk.io/x/tx v0.9.1/go.mod h1:/YFGTXG6+kyihd8YbfuJiXHV4R/mIMm2uvVzo80CIhA= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 h1:p/wyc5pVTMtx2/RsKP0fUpOKGbDfy6q6WswJtmARdbg= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382/go.mod h1:MKo9/b5wsoL8dd9y9pvD2yOP1CMvzHIWYxi1l2oLPFo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/simapp/gomod2nix.toml b/simapp/gomod2nix.toml index bd22df6353d8..f5a9b232c8a4 100644 --- a/simapp/gomod2nix.toml +++ b/simapp/gomod2nix.toml @@ -41,8 +41,8 @@ schema = 3 version = "v1.0.0-rc.0" hash = "sha256-DgW4ZrDwmgsPtEXajPyAsrQuPjXekw5PfsYFvA5yuiE=" [mod."cosmossdk.io/x/tx"] - version = "v0.9.1" - hash = "sha256-/fopDRDbfIUr8Ub0qqu3k0y6FsLKTAwf51PJaCL18Bk=" + version = "v0.9.2-0.20230913111958-e394604f8382" + hash = "sha256-am/+/mfQR+xqjQSTFh2X/AiC6EQZvZ7te6d8MIwd/EA=" [mod."filippo.io/edwards25519"] version = "v1.0.0" hash = "sha256-APnPAcmItvtJ5Zsy863lzR2TjEBF9Y66TY1e4M1ap98=" diff --git a/tests/go.mod b/tests/go.mod index a7599db8d58e..a15233d2b35a 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -15,7 +15,7 @@ require ( cosmossdk.io/x/evidence v0.0.0-20230613133644-0a778132a60f cosmossdk.io/x/feegrant v0.0.0-20230613133644-0a778132a60f cosmossdk.io/x/nft v0.0.0-20230613133644-0a778132a60f // indirect - cosmossdk.io/x/tx v0.9.1 + cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 cosmossdk.io/x/upgrade v0.0.0-20230613133644-0a778132a60f github.com/cometbft/cometbft v0.38.0 github.com/cosmos/cosmos-db v1.0.0 diff --git a/tests/go.sum b/tests/go.sum index 871cb9ad4428..decea2f6f889 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -203,8 +203,8 @@ cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM= cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= cosmossdk.io/store v1.0.0-rc.0 h1:9DwOjuUYxDtYxn/REkTxGQAmxlIGfRroB35MQ8TrxF4= cosmossdk.io/store v1.0.0-rc.0/go.mod h1:FtBDOJmwtOZfmKKF65bKZbTYgS3bDNjjo3nP76dAegk= -cosmossdk.io/x/tx v0.9.1 h1:9pmmXA9Vs4qdouOFnzhsdsff2mif0f0kylMq5xTGhRI= -cosmossdk.io/x/tx v0.9.1/go.mod h1:/YFGTXG6+kyihd8YbfuJiXHV4R/mIMm2uvVzo80CIhA= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 h1:p/wyc5pVTMtx2/RsKP0fUpOKGbDfy6q6WswJtmARdbg= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382/go.mod h1:MKo9/b5wsoL8dd9y9pvD2yOP1CMvzHIWYxi1l2oLPFo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tests/starship/tests/go.mod b/tests/starship/tests/go.mod index 0a5b7d6870eb..f6391b7839d7 100644 --- a/tests/starship/tests/go.mod +++ b/tests/starship/tests/go.mod @@ -49,7 +49,7 @@ require ( cosmossdk.io/x/evidence v0.0.0-20230613133644-0a778132a60f // indirect cosmossdk.io/x/feegrant v0.0.0-20230613133644-0a778132a60f // indirect cosmossdk.io/x/nft v0.0.0-20230613133644-0a778132a60f // indirect - cosmossdk.io/x/tx v0.9.1 // indirect + cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 // indirect cosmossdk.io/x/upgrade v0.0.0-20230613133644-0a778132a60f // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect diff --git a/tests/starship/tests/go.sum b/tests/starship/tests/go.sum index a51c20608f7d..82d3add518e6 100644 --- a/tests/starship/tests/go.sum +++ b/tests/starship/tests/go.sum @@ -203,8 +203,8 @@ cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM= cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= cosmossdk.io/store v1.0.0-rc.0 h1:9DwOjuUYxDtYxn/REkTxGQAmxlIGfRroB35MQ8TrxF4= cosmossdk.io/store v1.0.0-rc.0/go.mod h1:FtBDOJmwtOZfmKKF65bKZbTYgS3bDNjjo3nP76dAegk= -cosmossdk.io/x/tx v0.9.1 h1:9pmmXA9Vs4qdouOFnzhsdsff2mif0f0kylMq5xTGhRI= -cosmossdk.io/x/tx v0.9.1/go.mod h1:/YFGTXG6+kyihd8YbfuJiXHV4R/mIMm2uvVzo80CIhA= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 h1:p/wyc5pVTMtx2/RsKP0fUpOKGbDfy6q6WswJtmARdbg= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382/go.mod h1:MKo9/b5wsoL8dd9y9pvD2yOP1CMvzHIWYxi1l2oLPFo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=