From 393f86e611f8d9a525562342cceaf7d7c416afb4 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Wed, 8 Mar 2023 12:25:13 +0100 Subject: [PATCH 01/25] feat(x/tx): Support gogo registry in Textual --- go.mod | 4 + go.sum | 2 - simapp/go.mod | 1 + simapp/go.sum | 2 - simapp/simd/cmd/root.go | 6 +- x/auth/ante/sigverify_test.go | 8 +- x/auth/tx/config/config.go | 5 +- x/auth/tx/config/textual.go | 89 +++++++++++-------- x/tx/signing/std/handler_map.go | 13 ++- x/tx/signing/textual/any.go | 35 ++++++-- x/tx/signing/textual/any_test.go | 7 +- x/tx/signing/textual/bytes_test.go | 3 +- x/tx/signing/textual/coin_test.go | 17 ++-- x/tx/signing/textual/coins_test.go | 3 +- x/tx/signing/textual/dec_test.go | 3 +- x/tx/signing/textual/e2e_test.go | 3 +- x/tx/signing/textual/enum_test.go | 3 +- .../textual/{valuerenderer.go => handler.go} | 43 +++++++-- ...{valuerenderer_test.go => handler_test.go} | 3 +- x/tx/signing/textual/int_test.go | 3 +- x/tx/signing/textual/message_test.go | 2 +- x/tx/signing/textual/repeated_test.go | 2 +- x/tx/signing/textual/tx_test.go | 2 +- 23 files changed, 176 insertions(+), 83 deletions(-) rename x/tx/signing/textual/{valuerenderer.go => handler.go} (84%) rename x/tx/signing/textual/{valuerenderer_test.go => handler_test.go} (92%) diff --git a/go.mod b/go.mod index 44067b9ee33f..d3864ed5e6f5 100644 --- a/go.mod +++ b/go.mod @@ -154,6 +154,10 @@ require ( nhooyr.io/websocket v1.8.6 // indirect ) +// Here are the short-lived replace for the Cosmos SDK +// Replace here are pending PRs, or version to be tagged. +replace cosmossdk.io/x/tx => ./x/tx + // Below are the long-lived replace of the Cosmos SDK replace ( // use cosmos fork of keyring diff --git a/go.sum b/go.sum index 218a0243fd72..029d2e9635d3 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,6 @@ cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44/go.mod h1:flrxUykloEW1asE9p+Q+d8LSuNI3fBRdzISg9HTpYlQ= -cosmossdk.io/x/tx v0.2.2 h1:pD4TEbzOOerVQNI+M9anQIncl+4wFELpGds3N7RzPiQ= -cosmossdk.io/x/tx v0.2.2/go.mod h1:cur19OSg8P6ifrZ00yJOyY6HT75FEhLBX2Ir3Sl0ubY= 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 febf642ffc53..9631f8fd89b9 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -196,6 +196,7 @@ replace ( cosmossdk.io/x/evidence => ../x/evidence cosmossdk.io/x/feegrant => ../x/feegrant cosmossdk.io/x/nft => ../x/nft + cosmossdk.io/x/tx => ../x/tx cosmossdk.io/x/upgrade => ../x/upgrade ) diff --git a/simapp/go.sum b/simapp/go.sum index 69f00a56a9ea..306743115647 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -206,8 +206,6 @@ cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44/go.mod h1:flrxUykloEW1asE9p+Q+d8LSuNI3fBRdzISg9HTpYlQ= -cosmossdk.io/x/tx v0.2.2 h1:pD4TEbzOOerVQNI+M9anQIncl+4wFELpGds3N7RzPiQ= -cosmossdk.io/x/tx v0.2.2/go.mod h1:cur19OSg8P6ifrZ00yJOyY6HT75FEhLBX2Ir3Sl0ubY= 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/simd/cmd/root.go b/simapp/simd/cmd/root.go index f572b81545f7..f98002d6ad5f 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -85,10 +85,14 @@ func NewRootCmd() *cobra.Command { // TODO Currently, the TxConfig below doesn't include Textual, so // an error will arise when using the --textual flag. // ref: https://github.com/cosmos/cosmos-sdk/issues/11970 + txt, err := txmodule.NewTextualWithGRPCConn(initClientCtx) + if err != nil { + return err + } txConfigWithTextual := tx.NewTxConfigWithTextual( codec.NewProtoCodec(encodingConfig.InterfaceRegistry), encodingConfig.TxConfig.SignModeHandler().Modes(), - txmodule.NewTextualWithGRPCConn(initClientCtx), + txt, ) initClientCtx = initClientCtx.WithTxConfig(txConfigWithTextual) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 33f9270fd208..256ad46a0836 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -132,10 +132,12 @@ func TestSigVerification(t *testing.T) { enabledSignModes := []signing.SignMode{signing.SignMode_SIGN_MODE_DIRECT, signing.SignMode_SIGN_MODE_TEXTUAL, signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON} // Since TEXTUAL is not enabled by default, we create a custom TxConfig // here which includes it. + txt, err := txmodule.NewTextualWithGRPCConn(suite.clientCtx) + require.NoError(t, err) suite.clientCtx.TxConfig = authtx.NewTxConfigWithTextual( codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), enabledSignModes, - txmodule.NewTextualWithGRPCConn(suite.clientCtx), + txt, ) suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() @@ -162,10 +164,12 @@ func TestSigVerification(t *testing.T) { gasLimit := testdata.NewTestGasLimit() spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper) + txt, err = txmodule.NewTextualWithGRPCConn(suite.clientCtx) + require.NoError(t, err) anteTxConfig := authtx.NewTxConfigWithTextual( codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), enabledSignModes, - txmodule.NewTextualWithBankKeeper(suite.txBankKeeper), + txt, ) svd := ante.NewSigVerificationDecorator(suite.accountKeeper, anteTxConfig.SignModeHandler()) antehandler := sdk.ChainAnteDecorators(spkd, svd) diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index cbb55b92c9f6..346c9d0eebd8 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -50,7 +50,10 @@ type TxOutputs struct { } func ProvideModule(in TxInputs) TxOutputs { - textual := NewTextualWithBankKeeper(in.TxBankKeeper) + textual, err := NewTextualWithBankKeeper(in.TxBankKeeper) + if err != nil { + panic(err) + } var txConfig client.TxConfig if in.CustomSignModeHandlers == nil { txConfig = tx.NewTxConfigWithTextual(in.ProtoCodecMarshaler, tx.DefaultSignModes, textual) diff --git a/x/auth/tx/config/textual.go b/x/auth/tx/config/textual.go index 28d1f39e6f92..348a2b54b0f9 100644 --- a/x/auth/tx/config/textual.go +++ b/x/auth/tx/config/textual.go @@ -3,6 +3,7 @@ package tx import ( "context" + gogoproto "github.com/cosmos/gogoproto/proto" "google.golang.org/grpc" "google.golang.org/grpc/codes" grpcstatus "google.golang.org/grpc/status" @@ -21,17 +22,25 @@ import ( // // clientCtx := client.GetClientContextFromCmd(cmd) // txt := tx.NewTextualWithGRPCConn(clientCtxx) -func NewTextualWithGRPCConn(grpcConn grpc.ClientConnInterface) *textual.SignModeHandler { - return textual.NewSignModeHandler(func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { - bankQueryClient := bankv1beta1.NewQueryClient(grpcConn) - res, err := bankQueryClient.DenomMetadata(ctx, &bankv1beta1.QueryDenomMetadataRequest{ - Denom: denom, - }) - if err != nil { - return nil, metadataExists(err) - } +func NewTextualWithGRPCConn(grpcConn grpc.ClientConnInterface) (*textual.SignModeHandler, error) { + protoFiles, err := gogoproto.MergedRegistry() + if err != nil { + return nil, err + } + + return textual.NewSignModeHandler(textual.SignModeOptions{ + CoinMetadataQuerier: func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { + bankQueryClient := bankv1beta1.NewQueryClient(grpcConn) + res, err := bankQueryClient.DenomMetadata(ctx, &bankv1beta1.QueryDenomMetadataRequest{ + Denom: denom, + }) + if err != nil { + return nil, metadataExists(err) + } - return res.Metadata, nil + return res.Metadata, nil + }, + ProtoFiles: protoFiles, }) } @@ -41,37 +50,43 @@ func NewTextualWithGRPCConn(grpcConn grpc.ClientConnInterface) *textual.SignMode // Note: Once we switch to ADR-033, and keepers become ADR-033 clients to each // other, this function could probably be deprecated in favor of // `NewTextualWithGRPCConn`. -func NewTextualWithBankKeeper(bk BankKeeper) *textual.SignModeHandler { - textual := textual.NewSignModeHandler(func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { - res, err := bk.DenomMetadata(ctx, &types.QueryDenomMetadataRequest{Denom: denom}) - if err != nil { - return nil, metadataExists(err) - } +func NewTextualWithBankKeeper(bk BankKeeper) (*textual.SignModeHandler, error) { + protoFiles, err := gogoproto.MergedRegistry() + if err != nil { + return nil, err + } - m := &bankv1beta1.Metadata{ - Base: res.Metadata.Base, - Display: res.Metadata.Display, - // fields below are not strictly needed by Textual - // but added here for completeness. - Description: res.Metadata.Description, - Name: res.Metadata.Name, - Symbol: res.Metadata.Symbol, - Uri: res.Metadata.URI, - UriHash: res.Metadata.URIHash, - } - m.DenomUnits = make([]*bankv1beta1.DenomUnit, len(res.Metadata.DenomUnits)) - for i, d := range res.Metadata.DenomUnits { - m.DenomUnits[i] = &bankv1beta1.DenomUnit{ - Denom: d.Denom, - Exponent: d.Exponent, - Aliases: d.Aliases, + return textual.NewSignModeHandler(textual.SignModeOptions{ + CoinMetadataQuerier: func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { + res, err := bk.DenomMetadata(ctx, &types.QueryDenomMetadataRequest{Denom: denom}) + if err != nil { + return nil, metadataExists(err) } - } - return m, nil - }) + m := &bankv1beta1.Metadata{ + Base: res.Metadata.Base, + Display: res.Metadata.Display, + // fields below are not strictly needed by Textual + // but added here for completeness. + Description: res.Metadata.Description, + Name: res.Metadata.Name, + Symbol: res.Metadata.Symbol, + Uri: res.Metadata.URI, + UriHash: res.Metadata.URIHash, + } + m.DenomUnits = make([]*bankv1beta1.DenomUnit, len(res.Metadata.DenomUnits)) + for i, d := range res.Metadata.DenomUnits { + m.DenomUnits[i] = &bankv1beta1.DenomUnit{ + Denom: d.Denom, + Exponent: d.Exponent, + Aliases: d.Aliases, + } + } - return textual + return m, nil + }, + ProtoFiles: protoFiles, + }) } // metadataExists parses the error, and only propagates the error if it's diff --git a/x/tx/signing/std/handler_map.go b/x/tx/signing/std/handler_map.go index c94ca036871d..db889be2de0f 100644 --- a/x/tx/signing/std/handler_map.go +++ b/x/tx/signing/std/handler_map.go @@ -1,8 +1,6 @@ package std import ( - "fmt" - "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/tx/signing/direct" "cosmossdk.io/x/tx/signing/textual" @@ -10,19 +8,20 @@ import ( // SignModeOptions are options for configuring the standard sign mode handler map. type SignModeOptions struct { - // CoinMetadataQueryFn is the CoinMetadataQueryFn required for SIGN_MODE_TEXTUAL. - CoinMetadataQueryFn textual.CoinMetadataQueryFn + // Textual are options for SIGN_MODE_TEXTUAL + Textual textual.SignModeOptions } // HandlerMap returns a sign mode handler map that Cosmos SDK apps can use out // of the box to support all "standard" sign modes. func (s SignModeOptions) HandlerMap() (*signing.HandlerMap, error) { - if s.CoinMetadataQueryFn == nil { - return nil, fmt.Errorf("missing %T needed for SIGN_MODE_TEXTUAL", s.CoinMetadataQueryFn) + txt, err := textual.NewSignModeHandler(s.Textual) + if err != nil { + return nil, err } return signing.NewHandlerMap( direct.SignModeHandler{}, - textual.NewSignModeHandler(s.CoinMetadataQueryFn), + txt, ), nil } diff --git a/x/tx/signing/textual/any.go b/x/tx/signing/textual/any.go index f2be86c6559b..5aba5ecaa9a8 100644 --- a/x/tx/signing/textual/any.go +++ b/x/tx/signing/textual/any.go @@ -3,10 +3,12 @@ package textual import ( "context" "fmt" + "strings" "github.com/cosmos/cosmos-proto/any" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoregistry" + "google.golang.org/protobuf/types/dynamicpb" "google.golang.org/protobuf/types/known/anypb" ) @@ -31,16 +33,37 @@ func (ar anyValueRenderer) Format(ctx context.Context, v protoreflect.Value) ([] return nil, fmt.Errorf("expected Any, got %T", msg) } - internalMsg, err := anymsg.UnmarshalNew() - if err != nil { + packedMsg, err := anymsg.UnmarshalNew() + if err == protoregistry.NotFound { + // If the proto v2 registry doesn't have this message, then we use + // protoFiles (which can e.g. be initialized to gogo's MergedRegistry) + // to retrieve the message descriptor, and then use dynamicpb on that + // message descriptor to create a proto.Message + typeURL := strings.TrimPrefix(anymsg.TypeUrl, "/") + + msgDesc, err := ar.tr.protoFiles.FindDescriptorByName(protoreflect.FullName(typeURL)) + if err != nil { + return nil, fmt.Errorf("textual protoFiles does not have descriptor %s: %w", anymsg.TypeUrl, err) + } + + typ := dynamicpb.NewMessageType(msgDesc.(protoreflect.MessageDescriptor)) + msg := typ.New().Interface() + err = anymsg.UnmarshalTo(msg) + if err != nil { + return nil, fmt.Errorf("cannot unmarshal msg %s into dynamicpb generated type: %w", anymsg.TypeUrl, err) + } + + packedMsg = msg + } else if err != nil { return nil, fmt.Errorf("error unmarshalling any %s: %w", anymsg.TypeUrl, err) } - vr, err := ar.tr.GetMessageValueRenderer(internalMsg.ProtoReflect().Descriptor()) + + vr, err := ar.tr.GetMessageValueRenderer(packedMsg.ProtoReflect().Descriptor()) if err != nil { return nil, err } - subscreens, err := vr.Format(ctx, protoreflect.ValueOfMessage(internalMsg.ProtoReflect())) + subscreens, err := vr.Format(ctx, protoreflect.ValueOfMessage(packedMsg.ProtoReflect())) if err != nil { return nil, err } @@ -82,12 +105,12 @@ func (ar anyValueRenderer) Parse(ctx context.Context, screens []Screen) (protore subscreens[i-1].Indent-- } - internalMsg, err := vr.Parse(ctx, subscreens) + packedMsg, err := vr.Parse(ctx, subscreens) if err != nil { return nilValue, err } - anyMsg, err := any.New(internalMsg.Message().Interface()) + anyMsg, err := any.New(packedMsg.Message().Interface()) if err != nil { return nilValue, err } diff --git a/x/tx/signing/textual/any_test.go b/x/tx/signing/textual/any_test.go index 6a8f289ea1ec..0efa8b395043 100644 --- a/x/tx/signing/textual/any_test.go +++ b/x/tx/signing/textual/any_test.go @@ -31,7 +31,8 @@ func TestAny(t *testing.T) { err = json.Unmarshal(raw, &testcases) require.NoError(t, err) - tr := textual.NewSignModeHandler(EmptyCoinMetadataQuerier) + tr, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: EmptyCoinMetadataQuerier}) + require.NoError(t, err) for i, tc := range testcases { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { anyMsg := anypb.Any{} @@ -55,3 +56,7 @@ func TestAny(t *testing.T) { }) } } + +func TestCustomProtoFiles(t *testing.T) { + +} diff --git a/x/tx/signing/textual/bytes_test.go b/x/tx/signing/textual/bytes_test.go index 5ca1dcacdd68..1f9fae13a8b3 100644 --- a/x/tx/signing/textual/bytes_test.go +++ b/x/tx/signing/textual/bytes_test.go @@ -21,7 +21,8 @@ func TestBytesJsonTestCases(t *testing.T) { err = json.Unmarshal(raw, &testcases) require.NoError(t, err) - textual := textual.NewSignModeHandler(nil) + textual, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: EmptyCoinMetadataQuerier}) + require.NoError(t, err) for _, tc := range testcases { t.Run(tc.hex, func(t *testing.T) { diff --git a/x/tx/signing/textual/coin_test.go b/x/tx/signing/textual/coin_test.go index 85160cacbfe0..492e5d2705c8 100644 --- a/x/tx/signing/textual/coin_test.go +++ b/x/tx/signing/textual/coin_test.go @@ -52,18 +52,18 @@ func addMetadataToContext(ctx context.Context, metadata *bankv1beta1.Metadata) c func TestMetadataQuerier(t *testing.T) { // Errors on nil metadata querier - txt := textual.NewSignModeHandler(nil) - vr, err := txt.GetFieldValueRenderer(fieldDescriptorFromName("COIN")) - require.NoError(t, err) - _, err = vr.Format(context.Background(), protoreflect.ValueOf((&basev1beta1.Coin{}).ProtoReflect())) + _, err := textual.NewSignModeHandler(textual.SignModeOptions{}) require.Error(t, err) // Errors if metadata querier returns an error expErr := fmt.Errorf("mock error") - txt = textual.NewSignModeHandler(func(_ context.Context, _ string) (*bankv1beta1.Metadata, error) { - return nil, expErr + txt, err := textual.NewSignModeHandler(textual.SignModeOptions{ + CoinMetadataQuerier: func(_ context.Context, _ string) (*bankv1beta1.Metadata, error) { + return nil, expErr + }, }) - vr, err = txt.GetFieldValueRenderer(fieldDescriptorFromName("COIN")) + require.NoError(t, err) + vr, err := txt.GetFieldValueRenderer(fieldDescriptorFromName("COIN")) require.NoError(t, err) _, err = vr.Format(context.Background(), protoreflect.ValueOf((&basev1beta1.Coin{}).ProtoReflect())) require.ErrorIs(t, err, expErr) @@ -78,7 +78,8 @@ func TestCoinJsonTestcases(t *testing.T) { err = json.Unmarshal(raw, &testcases) require.NoError(t, err) - textual := textual.NewSignModeHandler(mockCoinMetadataQuerier) + textual, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: mockCoinMetadataQuerier}) + require.NoError(t, err) vr, err := textual.GetFieldValueRenderer(fieldDescriptorFromName("COIN")) require.NoError(t, err) diff --git a/x/tx/signing/textual/coins_test.go b/x/tx/signing/textual/coins_test.go index e7fdf12d0d03..55ff78482cba 100644 --- a/x/tx/signing/textual/coins_test.go +++ b/x/tx/signing/textual/coins_test.go @@ -22,7 +22,8 @@ func TestCoinsJsonTestcases(t *testing.T) { err = json.Unmarshal(raw, &testcases) require.NoError(t, err) - txt := textual.NewSignModeHandler(mockCoinMetadataQuerier) + txt, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: mockCoinMetadataQuerier}) + require.NoError(t, err) vr, err := txt.GetFieldValueRenderer(fieldDescriptorFromName("COINS")) vrr := vr.(textual.RepeatedValueRenderer) require.NoError(t, err) diff --git a/x/tx/signing/textual/dec_test.go b/x/tx/signing/textual/dec_test.go index a3204afdf0fa..1ee1615a7b21 100644 --- a/x/tx/signing/textual/dec_test.go +++ b/x/tx/signing/textual/dec_test.go @@ -23,7 +23,8 @@ func TestDecJsonTestcases(t *testing.T) { err = json.Unmarshal(raw, &testcases) require.NoError(t, err) - textual := textual.NewSignModeHandler(nil) + textual, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: EmptyCoinMetadataQuerier}) + require.NoError(t, err) for _, tc := range testcases { tc := tc diff --git a/x/tx/signing/textual/e2e_test.go b/x/tx/signing/textual/e2e_test.go index 168e157e8e55..e2260b21dbf9 100644 --- a/x/tx/signing/textual/e2e_test.go +++ b/x/tx/signing/textual/e2e_test.go @@ -39,7 +39,8 @@ func TestE2EJsonTestcases(t *testing.T) { t.Run(tc.Name, func(t *testing.T) { _, bodyBz, _, authInfoBz, signerData := createTextualData(t, tc.Proto, tc.SignerData) - tr := textual.NewSignModeHandler(mockCoinMetadataQuerier) + tr, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: mockCoinMetadataQuerier}) + require.NoError(t, err) rend := textual.NewTxValueRenderer(tr) ctx := addMetadataToContext(context.Background(), tc.Metadata) diff --git a/x/tx/signing/textual/enum_test.go b/x/tx/signing/textual/enum_test.go index ce109c607eb7..21daf7541a2d 100644 --- a/x/tx/signing/textual/enum_test.go +++ b/x/tx/signing/textual/enum_test.go @@ -29,7 +29,8 @@ func TestEnumJsonTestcases(t *testing.T) { err = json.Unmarshal(raw, &testcases) require.NoError(t, err) - textual := textual.NewSignModeHandler(nil) + textual, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: EmptyCoinMetadataQuerier}) + require.NoError(t, err) for _, tc := range testcases { t.Run(tc.Text, func(t *testing.T) { diff --git a/x/tx/signing/textual/valuerenderer.go b/x/tx/signing/textual/handler.go similarity index 84% rename from x/tx/signing/textual/valuerenderer.go rename to x/tx/signing/textual/handler.go index 11a3774158af..fb499ce9c627 100644 --- a/x/tx/signing/textual/valuerenderer.go +++ b/x/tx/signing/textual/handler.go @@ -8,6 +8,7 @@ import ( signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/types/known/anypb" "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" @@ -27,13 +28,28 @@ type CoinMetadataQueryFn func(ctx context.Context, denom string) (*bankv1beta1.M // ValueRendererCreator is a function returning a textual. type ValueRendererCreator func(protoreflect.FieldDescriptor) ValueRenderer -// SignModeHandler holds the configuration for dispatching -// to specific value renderers for SIGN_MODE_TEXTUAL. -type SignModeHandler struct { +// SignModeOptions are options to be passed to Textual's sign mode handler. +type SignModeOptions struct { // coinMetadataQuerier defines a function to query the coin metadata from // state. It should use bank module's `DenomsMetadata` gRPC query to fetch // each denom's associated metadata, either using the bank keeper (for // server-side code) or a gRPC query client (for client-side code). + CoinMetadataQuerier CoinMetadataQueryFn + + // ProtoFiles are the protobuf files to use for resolving message + // descriptors. If it is nil, the global protobuf registry will be used. + ProtoFiles *protoregistry.Files + + // ProtoTypes are the protobuf type resolvers to use for resolving message + // types. If it is nil, then a dynamicpb will be used on top of ProtoFiles. + ProtoTypes protoregistry.MessageTypeResolver +} + +// SignModeHandler holds the configuration for dispatching +// to specific value renderers for SIGN_MODE_TEXTUAL. +type SignModeHandler struct { + protoFiles *protoregistry.Files + protoTypes protoregistry.MessageTypeResolver coinMetadataQuerier CoinMetadataQueryFn // scalars defines a registry for Cosmos scalars. scalars map[string]ValueRendererCreator @@ -47,10 +63,25 @@ type SignModeHandler struct { } // NewSignModeHandler returns a new SignModeHandler which generates sign bytes and provides value renderers. -func NewSignModeHandler(q CoinMetadataQueryFn) *SignModeHandler { - t := &SignModeHandler{coinMetadataQuerier: q} +func NewSignModeHandler(o SignModeOptions) (*SignModeHandler, error) { + if o.CoinMetadataQuerier == nil { + return nil, fmt.Errorf("coinMetadataQuerier must be non-empty") + } + if o.ProtoFiles == nil { + o.ProtoFiles = protoregistry.GlobalFiles + } + if o.ProtoTypes == nil { + o.ProtoTypes = protoregistry.GlobalTypes + } + + t := &SignModeHandler{ + coinMetadataQuerier: o.CoinMetadataQuerier, + protoFiles: o.ProtoFiles, + protoTypes: o.ProtoTypes, + } t.init() - return t + + return t, nil } // GetFieldValueRenderer returns the value renderer for the given FieldDescriptor. diff --git a/x/tx/signing/textual/valuerenderer_test.go b/x/tx/signing/textual/handler_test.go similarity index 92% rename from x/tx/signing/textual/valuerenderer_test.go rename to x/tx/signing/textual/handler_test.go index a9e22e6770e6..70c2ea124a9f 100644 --- a/x/tx/signing/textual/valuerenderer_test.go +++ b/x/tx/signing/textual/handler_test.go @@ -34,7 +34,8 @@ func TestDispatcher(t *testing.T) { for _, tc := range testcases { tc := tc t.Run(tc.name, func(t *testing.T) { - textual := textual.NewSignModeHandler(nil) + textual, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: EmptyCoinMetadataQuerier}) + require.NoError(t, err) rend, err := textual.GetFieldValueRenderer(fieldDescriptorFromName(tc.name)) if tc.expErr { diff --git a/x/tx/signing/textual/int_test.go b/x/tx/signing/textual/int_test.go index e67eb3b3bf70..33dbdb4fecb1 100644 --- a/x/tx/signing/textual/int_test.go +++ b/x/tx/signing/textual/int_test.go @@ -23,7 +23,8 @@ func TestIntJsonTestcases(t *testing.T) { err = json.Unmarshal(raw, &testcases) require.NoError(t, err) - textual := textual.NewSignModeHandler(nil) + textual, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: EmptyCoinMetadataQuerier}) + require.NoError(t, err) for _, tc := range testcases { t.Run(tc[0], func(t *testing.T) { diff --git a/x/tx/signing/textual/message_test.go b/x/tx/signing/textual/message_test.go index 446a80b94bbc..b4d04b27f977 100644 --- a/x/tx/signing/textual/message_test.go +++ b/x/tx/signing/textual/message_test.go @@ -36,7 +36,7 @@ func TestMessageJsonTestcases(t *testing.T) { err = json.Unmarshal(raw, &testcases) require.NoError(t, err) - tr := textual.NewSignModeHandler(EmptyCoinMetadataQuerier) + tr, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: EmptyCoinMetadataQuerier}) for i, tc := range testcases { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { rend := textual.NewMessageValueRenderer(tr, (&testpb.Foo{}).ProtoReflect().Descriptor()) diff --git a/x/tx/signing/textual/repeated_test.go b/x/tx/signing/textual/repeated_test.go index 50a66968c573..b2a6a98318b9 100644 --- a/x/tx/signing/textual/repeated_test.go +++ b/x/tx/signing/textual/repeated_test.go @@ -29,7 +29,7 @@ func TestRepeatedJsonTestcases(t *testing.T) { err = json.Unmarshal(raw, &testcases) require.NoError(t, err) - tr := textual.NewSignModeHandler(mockCoinMetadataQuerier) + tr, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: mockCoinMetadataQuerier}) for i, tc := range testcases { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { // Create a context.Context containing all coins metadata, to simulate diff --git a/x/tx/signing/textual/tx_test.go b/x/tx/signing/textual/tx_test.go index 60c1cad64a7c..d990366087e3 100644 --- a/x/tx/signing/textual/tx_test.go +++ b/x/tx/signing/textual/tx_test.go @@ -56,7 +56,7 @@ func TestTxJsonTestcases(t *testing.T) { t.Run(tc.Name, func(t *testing.T) { txBody, bodyBz, txAuthInfo, authInfoBz, signerData := createTextualData(t, tc.Proto, tc.SignerData) - tr := textual.NewSignModeHandler(mockCoinMetadataQuerier) + tr, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: mockCoinMetadataQuerier}) rend := textual.NewTxValueRenderer(tr) ctx := addMetadataToContext(context.Background(), tc.Metadata) From ed40758a2527d6f1acf984ab502393effb1b2cff Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Wed, 8 Mar 2023 12:27:49 +0100 Subject: [PATCH 02/25] Add changelog --- x/tx/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x/tx/CHANGELOG.md b/x/tx/CHANGELOG.md index 5ef56140548c..fbf674c28bec 100644 --- a/x/tx/CHANGELOG.md +++ b/x/tx/CHANGELOG.md @@ -34,3 +34,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## API Breaking * [#15278](https://github.com/cosmos/cosmos-sdk/pull/15278) Move `x/tx/{textual,aminojson}` into `x/tx/signing`. +* [#15302](https://github.com/cosmos/cosmos-sdk/pull/15302) `textual.NewSignModeHandler` now takes an options struct instead of a simple coin querier argument. It also returns an error. + +## Improvements + +* [#15302](https://github.com/cosmos/cosmos-sdk/pull/15302) Add support for a custom registry (e.g. gogo's MergedRegistry) to be plugged into SIGN_MODE_TEXTUAL. + From c056b1f0800585167f671ea08e2de2e9f51b0e53 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Wed, 8 Mar 2023 12:32:03 +0100 Subject: [PATCH 03/25] Add in parsing too --- x/tx/signing/textual/any.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/x/tx/signing/textual/any.go b/x/tx/signing/textual/any.go index 5aba5ecaa9a8..c97156bb966a 100644 --- a/x/tx/signing/textual/any.go +++ b/x/tx/signing/textual/any.go @@ -87,8 +87,22 @@ func (ar anyValueRenderer) Parse(ctx context.Context, screens []Screen) (protore return nilValue, fmt.Errorf("bad indentation: want 0, got %d", screens[0].Indent) } - msgType, err := protoregistry.GlobalTypes.FindMessageByURL(screens[0].Content) - if err != nil { + typeURL := screens[0].Content + msgType, err := ar.tr.protoTypes.FindMessageByURL(typeURL) + if err == protoregistry.NotFound { + // If the proto v2 registry doesn't have this message, then we use + // protoFiles (which can e.g. be initialized to gogo's MergedRegistry) + // to retrieve the message descriptor, and then use dynamicpb on that + // message descriptor to create a proto.Message + typeURL := strings.TrimPrefix(typeURL, "/") + + msgDesc, err := ar.tr.protoFiles.FindDescriptorByName(protoreflect.FullName(typeURL)) + if err != nil { + return nilValue, fmt.Errorf("textual protoFiles does not have descriptor %s: %w", typeURL, err) + } + + msgType = dynamicpb.NewMessageType(msgDesc.(protoreflect.MessageDescriptor)) + } else if err != nil { return nilValue, err } vr, err := ar.tr.GetMessageValueRenderer(msgType.Descriptor()) From 2a17c3417deb7743a28f593a1a6f993dcb015f4d Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Wed, 8 Mar 2023 12:38:15 +0100 Subject: [PATCH 04/25] replace --- tests/go.mod | 1 + tests/go.sum | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/go.mod b/tests/go.mod index 2ca0af54e141..c1092595df08 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -192,6 +192,7 @@ replace ( cosmossdk.io/x/evidence => ../x/evidence cosmossdk.io/x/feegrant => ../x/feegrant cosmossdk.io/x/nft => ../x/nft + cosmossdk.io/x/tx => ../x/tx cosmossdk.io/x/upgrade => ../x/upgrade ) diff --git a/tests/go.sum b/tests/go.sum index 744da4580f76..9d18042b207f 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -204,8 +204,6 @@ cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44/go.mod h1:flrxUykloEW1asE9p+Q+d8LSuNI3fBRdzISg9HTpYlQ= -cosmossdk.io/x/tx v0.2.2 h1:pD4TEbzOOerVQNI+M9anQIncl+4wFELpGds3N7RzPiQ= -cosmossdk.io/x/tx v0.2.2/go.mod h1:cur19OSg8P6ifrZ00yJOyY6HT75FEhLBX2Ir3Sl0ubY= 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= From ea2444c4c9929825d85772a20176145cd30e2b7a Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Mon, 13 Mar 2023 11:49:18 +0100 Subject: [PATCH 05/25] Add dynamicpb test --- x/auth/ante/sigverify_test.go | 2 +- x/tx/signing/textual/any_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 256ad46a0836..7e42df9cb6af 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -164,7 +164,7 @@ func TestSigVerification(t *testing.T) { gasLimit := testdata.NewTestGasLimit() spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper) - txt, err = txmodule.NewTextualWithGRPCConn(suite.clientCtx) + txt, err = txmodule.NewTextualWithBankKeeper(suite.txBankKeeper) require.NoError(t, err) anteTxConfig := authtx.NewTxConfigWithTextual( codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), diff --git a/x/tx/signing/textual/any_test.go b/x/tx/signing/textual/any_test.go index 0efa8b395043..750958a20949 100644 --- a/x/tx/signing/textual/any_test.go +++ b/x/tx/signing/textual/any_test.go @@ -10,10 +10,12 @@ import ( "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" "cosmossdk.io/x/tx/signing/textual" "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/testing/protocmp" "google.golang.org/protobuf/types/known/anypb" ) @@ -58,5 +60,21 @@ func TestAny(t *testing.T) { } func TestCustomProtoFiles(t *testing.T) { + tr, err := textual.NewSignModeHandler(textual.SignModeOptions{ + CoinMetadataQuerier: EmptyCoinMetadataQuerier, + ProtoTypes: &protoregistry.Types{}, // Set to empty to force using dynamicpb + }) + require.NoError(t, err) + msg := bankv1beta1.MsgSend{FromAddress: "foo"} + vr, err := tr.GetMessageValueRenderer(msg.ProtoReflect().Descriptor()) + require.NoError(t, err) + screens, err := vr.Format(context.Background(), protoreflect.ValueOf(msg.ProtoReflect())) + require.NoError(t, err) + + expScreens := []textual.Screen{ + {Content: "MsgSend object"}, + {Title: "From address", Content: "foo", Indent: 1}, + } + require.Equal(t, expScreens, screens) } From 5cd56e102066ad203e54638b6f500e72cf461d03 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Mon, 13 Mar 2023 12:11:44 +0100 Subject: [PATCH 06/25] Use commit hash for x/tx --- go.mod | 2 +- go.sum | 4 ++-- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- tests/go.mod | 2 +- tests/go.sum | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index acd1ba102151..2d3e7f038ff1 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v0.0.0-20230306220716-5e55f56d39d5 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 - cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba + cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index e6566d3cc93f..2e8135af117c 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44/go.mod h1:flrxUykloEW1asE9p+Q+d8LSuNI3fBRdzISg9HTpYlQ= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba h1:NmWXkl0voj3dN96Qmk4rfrze6dLLLxB4qTCxXZTXBpM= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba/go.mod h1:dhIxZhZF2glIA9hkkildy/JmSqVH3FIU/OhSU8is7PM= +cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5 h1:dPa+m+FwSSbgAcLEifmO5dYMwwCoy6Nht6I9uDvmV9s= +cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5/go.mod h1:rdZJ9lBASrqH2qfZRAu6dXrvbPqaS0XDOmkaqUYymLk= 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 f4837898c07b..489266b29b05 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.29.0 // indirect cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba // indirect + cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5 // 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/simapp/go.sum b/simapp/go.sum index f6a637dad438..c26343b1c84b 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba h1:63dnRBywQLvo/Ke0zljksFlWg5tAMTwOiuv6yZ3X0sM= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba/go.mod h1:sf0uPZvsgXqXy2ydRXJmsM+sNHSZLZN6xZZkh7c3+t0= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba h1:NmWXkl0voj3dN96Qmk4rfrze6dLLLxB4qTCxXZTXBpM= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba/go.mod h1:dhIxZhZF2glIA9hkkildy/JmSqVH3FIU/OhSU8is7PM= +cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5 h1:dPa+m+FwSSbgAcLEifmO5dYMwwCoy6Nht6I9uDvmV9s= +cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5/go.mod h1:rdZJ9lBASrqH2qfZRAu6dXrvbPqaS0XDOmkaqUYymLk= 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/go.mod b/tests/go.mod index a0b1943ef7c5..6d5cf122c117 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba + cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5 cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.0 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/tests/go.sum b/tests/go.sum index ec377b1f17ea..a3970a833f21 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba h1:63dnRBywQLvo/Ke0zljksFlWg5tAMTwOiuv6yZ3X0sM= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba/go.mod h1:sf0uPZvsgXqXy2ydRXJmsM+sNHSZLZN6xZZkh7c3+t0= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba h1:NmWXkl0voj3dN96Qmk4rfrze6dLLLxB4qTCxXZTXBpM= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba/go.mod h1:dhIxZhZF2glIA9hkkildy/JmSqVH3FIU/OhSU8is7PM= +cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5 h1:dPa+m+FwSSbgAcLEifmO5dYMwwCoy6Nht6I9uDvmV9s= +cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5/go.mod h1:rdZJ9lBASrqH2qfZRAu6dXrvbPqaS0XDOmkaqUYymLk= 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= From 29e651e56e2db59b02af67dea317880ba945adef Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Tue, 14 Mar 2023 11:14:51 +0100 Subject: [PATCH 07/25] Support dynamicpb --- x/tx/signing/textual/coins.go | 23 ++++++++++++++++++++++- x/tx/signing/textual/duration.go | 24 +++++++++++++++++++++--- x/tx/signing/textual/handler.go | 8 ++++++++ x/tx/signing/textual/timestamp.go | 29 +++++++++++++++++++++-------- 4 files changed, 72 insertions(+), 12 deletions(-) diff --git a/x/tx/signing/textual/coins.go b/x/tx/signing/textual/coins.go index 305b70138762..60e25dd78f8b 100644 --- a/x/tx/signing/textual/coins.go +++ b/x/tx/signing/textual/coins.go @@ -5,7 +5,9 @@ import ( "fmt" "strings" + "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/dynamicpb" bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" @@ -37,7 +39,10 @@ func (vr coinsValueRenderer) Format(ctx context.Context, v protoreflect.Value) ( // Since this value renderer has a FormatRepeated method, the Format one // here only handles single coin. - coin := v.Interface().(protoreflect.Message).Interface().(*basev1beta1.Coin) + coin, err := toCoin(v.Interface().(protoreflect.Message).Interface()) + if err != nil { + return nil, err + } metadata, err := vr.coinMetadataQuerier(ctx, coin.Denom) if err != nil { @@ -210,3 +215,19 @@ func parseCoin(coinStr string, metadata *bankv1beta1.Metadata) (*basev1beta1.Coi Denom: baseDenom, }, nil } + +// toCoin converts the proto Message to a Coin. +// The input msg can be: +// - either a Coin already (in which case there's nothing to do), +// - or a dynamicpb.Message. +func toCoin(msg proto.Message) (*basev1beta1.Coin, error) { + switch msg := msg.(type) { + case *basev1beta1.Coin: + return msg, nil + case *dynamicpb.Message: + a, d := getFieldValue(msg, "amount").String(), getFieldValue(msg, "denom").String() + return &basev1beta1.Coin{Amount: a, Denom: d}, nil + default: + return nil, fmt.Errorf("expected timestamppb.Timestamp or dynamicpb.Message, got %T", msg) + } +} diff --git a/x/tx/signing/textual/duration.go b/x/tx/signing/textual/duration.go index c32241b95784..09768cc4137e 100644 --- a/x/tx/signing/textual/duration.go +++ b/x/tx/signing/textual/duration.go @@ -7,7 +7,9 @@ import ( "strconv" "strings" + "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/dynamicpb" dpb "google.golang.org/protobuf/types/known/durationpb" ) @@ -67,9 +69,9 @@ func formatSeconds(seconds int64, nanos int32) string { func (dr durationValueRenderer) Format(_ context.Context, v protoreflect.Value) ([]Screen, error) { // Reify the reflected message as a proto Duration msg := v.Message().Interface() - duration, ok := msg.(*dpb.Duration) - if !ok { - return nil, fmt.Errorf("expected Duration, got %T", msg) + duration, err := toDuration(msg) + if err != nil { + return nil, err } // Bypass use of time.Duration, as the range is more limited than that of dpb.Duration. @@ -184,3 +186,19 @@ func (dr durationValueRenderer) Parse(_ context.Context, screens []Screen) (prot msg := dur.ProtoReflect() return protoreflect.ValueOfMessage(msg), nil } + +// toDurations converts the proto Message to a durationpb.Duration. +// The input msg can be: +// - either a durationpb.Duration already (in which case there's nothing to do), +// - or a dynamicpb.Message. +func toDuration(msg proto.Message) (*dpb.Duration, error) { + switch msg := msg.(type) { + case *dpb.Duration: + return msg, nil + case *dynamicpb.Message: + s, n := getFieldValue(msg, "seconds").Int(), getFieldValue(msg, "nanos").Int() + return &dpb.Duration{Seconds: s, Nanos: int32(n)}, nil + default: + return nil, fmt.Errorf("expected dpb.Duration or dynamicpb.Message, got %T", msg) + } +} diff --git a/x/tx/signing/textual/handler.go b/x/tx/signing/textual/handler.go index fb499ce9c627..2f53e5b0ade0 100644 --- a/x/tx/signing/textual/handler.go +++ b/x/tx/signing/textual/handler.go @@ -217,3 +217,11 @@ func (r *SignModeHandler) Mode() signingv1beta1.SignMode { } var _ signing.SignModeHandler = &SignModeHandler{} + +// getFieldValue is an utility function to get the protoreflect.Value of a +// proto Message from its field name. +func getFieldValue(m proto.Message, fieldName string) protoreflect.Value { + fd := m.ProtoReflect().Descriptor().Fields().ByName(protoreflect.Name(fieldName)) + + return m.ProtoReflect().Get(fd) +} diff --git a/x/tx/signing/textual/timestamp.go b/x/tx/signing/textual/timestamp.go index 9e02c0d21946..4f14c3ee9181 100644 --- a/x/tx/signing/textual/timestamp.go +++ b/x/tx/signing/textual/timestamp.go @@ -6,6 +6,7 @@ import ( "time" "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/dynamicpb" tspb "google.golang.org/protobuf/types/known/timestamppb" ) @@ -20,15 +21,11 @@ func NewTimestampValueRenderer() ValueRenderer { // Format implements the ValueRenderer interface. func (vr timestampValueRenderer) Format(_ context.Context, v protoreflect.Value) ([]Screen, error) { - // Reify the reflected message as a proto Timestamp - msg := v.Message().Interface() - timestamp, ok := msg.(*tspb.Timestamp) - if !ok { - return nil, fmt.Errorf("expected Timestamp, got %T", msg) + ts, err := toProtoTimestamp(v.Message().Interface()) + if err != nil { + return nil, err } - - // Convert proto timestamp to a Go Time. - t := timestamp.AsTime() + t := ts.AsTime() // Format the Go Time as RFC 3339. s := t.Format(time.RFC3339Nano) @@ -53,3 +50,19 @@ func (vr timestampValueRenderer) Parse(_ context.Context, screens []Screen) (pro msg := timestamp.ProtoReflect() return protoreflect.ValueOfMessage(msg), nil } + +// convertToGoTime converts the proto Message to a timestamppb.Timestamp. +// The input msg can be: +// - either a timestamppb.Timestamp (in which case there's nothing to do), +// - or a dynamicpb.Message. +func toProtoTimestamp(msg protoreflect.ProtoMessage) (*tspb.Timestamp, error) { + switch msg := msg.(type) { + case *tspb.Timestamp: + return msg, nil + case *dynamicpb.Message: + s, n := getFieldValue(msg, "seconds").Int(), getFieldValue(msg, "nanos").Int() + return &tspb.Timestamp{Seconds: s, Nanos: int32(n)}, nil + default: + return nil, fmt.Errorf("expected timestamppb.Timestamp or dynamicpb.Message, got %T", msg) + } +} From 4b10e48f376be2bd5e08d39ca5203612b5ac2e1a Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Tue, 14 Mar 2023 11:17:59 +0100 Subject: [PATCH 08/25] Update commit hash --- go.mod | 2 +- go.sum | 4 ++-- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- tests/go.mod | 2 +- tests/go.sum | 4 ++-- x/tx/signing/textual/timestamp.go | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 2d3e7f038ff1..efa10394a5ca 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v0.0.0-20230306220716-5e55f56d39d5 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 - cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5 + cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index 2e8135af117c..2c9ef2f4cf78 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44/go.mod h1:flrxUykloEW1asE9p+Q+d8LSuNI3fBRdzISg9HTpYlQ= -cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5 h1:dPa+m+FwSSbgAcLEifmO5dYMwwCoy6Nht6I9uDvmV9s= -cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5/go.mod h1:rdZJ9lBASrqH2qfZRAu6dXrvbPqaS0XDOmkaqUYymLk= +cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d h1:kwSl5UsBYKFMxqfvAu/kfEJUsrGYCU2XGG7O4/XsCe4= +cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d/go.mod h1:rdZJ9lBASrqH2qfZRAu6dXrvbPqaS0XDOmkaqUYymLk= 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 489266b29b05..366eb87401eb 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.29.0 // indirect cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5 // indirect + cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d // 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/simapp/go.sum b/simapp/go.sum index c26343b1c84b..c104b91b6d00 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba h1:63dnRBywQLvo/Ke0zljksFlWg5tAMTwOiuv6yZ3X0sM= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba/go.mod h1:sf0uPZvsgXqXy2ydRXJmsM+sNHSZLZN6xZZkh7c3+t0= -cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5 h1:dPa+m+FwSSbgAcLEifmO5dYMwwCoy6Nht6I9uDvmV9s= -cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5/go.mod h1:rdZJ9lBASrqH2qfZRAu6dXrvbPqaS0XDOmkaqUYymLk= +cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d h1:kwSl5UsBYKFMxqfvAu/kfEJUsrGYCU2XGG7O4/XsCe4= +cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d/go.mod h1:rdZJ9lBASrqH2qfZRAu6dXrvbPqaS0XDOmkaqUYymLk= 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/go.mod b/tests/go.mod index 6d5cf122c117..064a4d65b24d 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5 + cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.0 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/tests/go.sum b/tests/go.sum index a3970a833f21..ee6543629e71 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba h1:63dnRBywQLvo/Ke0zljksFlWg5tAMTwOiuv6yZ3X0sM= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba/go.mod h1:sf0uPZvsgXqXy2ydRXJmsM+sNHSZLZN6xZZkh7c3+t0= -cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5 h1:dPa+m+FwSSbgAcLEifmO5dYMwwCoy6Nht6I9uDvmV9s= -cosmossdk.io/x/tx v0.2.3-0.20230313105016-a22a75ca3de5/go.mod h1:rdZJ9lBASrqH2qfZRAu6dXrvbPqaS0XDOmkaqUYymLk= +cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d h1:kwSl5UsBYKFMxqfvAu/kfEJUsrGYCU2XGG7O4/XsCe4= +cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d/go.mod h1:rdZJ9lBASrqH2qfZRAu6dXrvbPqaS0XDOmkaqUYymLk= 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/x/tx/signing/textual/timestamp.go b/x/tx/signing/textual/timestamp.go index 4f14c3ee9181..1a8b6a6cc9c0 100644 --- a/x/tx/signing/textual/timestamp.go +++ b/x/tx/signing/textual/timestamp.go @@ -21,7 +21,7 @@ func NewTimestampValueRenderer() ValueRenderer { // Format implements the ValueRenderer interface. func (vr timestampValueRenderer) Format(_ context.Context, v protoreflect.Value) ([]Screen, error) { - ts, err := toProtoTimestamp(v.Message().Interface()) + ts, err := toTimestamp(v.Message().Interface()) if err != nil { return nil, err } @@ -55,7 +55,7 @@ func (vr timestampValueRenderer) Parse(_ context.Context, screens []Screen) (pro // The input msg can be: // - either a timestamppb.Timestamp (in which case there's nothing to do), // - or a dynamicpb.Message. -func toProtoTimestamp(msg protoreflect.ProtoMessage) (*tspb.Timestamp, error) { +func toTimestamp(msg protoreflect.ProtoMessage) (*tspb.Timestamp, error) { switch msg := msg.(type) { case *tspb.Timestamp: return msg, nil From 5a78b7ede406b2d3f6f769a32ecfaeee6604b28b Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Tue, 14 Mar 2023 11:20:48 +0100 Subject: [PATCH 09/25] Update hash --- go.mod | 2 +- go.sum | 4 ++-- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- tests/go.mod | 2 +- tests/go.sum | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index dfb2354ac80f..7c4e09d424d1 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v0.1.0 cosmossdk.io/math v1.0.0-rc.0 cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 - cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d + cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index 1696c23e3c14..75e27136f0a5 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44/go.mod h1:flrxUykloEW1asE9p+Q+d8LSuNI3fBRdzISg9HTpYlQ= -cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d h1:kwSl5UsBYKFMxqfvAu/kfEJUsrGYCU2XGG7O4/XsCe4= -cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d/go.mod h1:rdZJ9lBASrqH2qfZRAu6dXrvbPqaS0XDOmkaqUYymLk= +cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6 h1:Us1KeRPbFQxdyVc728kH6SErAmXbhFPfftyzWL8nliM= +cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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 86ebd1fc7885..c5415f9d5765 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.29.0 // indirect cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d // indirect + cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6 // 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/simapp/go.sum b/simapp/go.sum index dd2d0c1ddc10..f856f303f43c 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba h1:63dnRBywQLvo/Ke0zljksFlWg5tAMTwOiuv6yZ3X0sM= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba/go.mod h1:sf0uPZvsgXqXy2ydRXJmsM+sNHSZLZN6xZZkh7c3+t0= -cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d h1:kwSl5UsBYKFMxqfvAu/kfEJUsrGYCU2XGG7O4/XsCe4= -cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d/go.mod h1:rdZJ9lBASrqH2qfZRAu6dXrvbPqaS0XDOmkaqUYymLk= +cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6 h1:Us1KeRPbFQxdyVc728kH6SErAmXbhFPfftyzWL8nliM= +cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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/go.mod b/tests/go.mod index c7f32490a8fd..ac02517d1f6c 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d + cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6 cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.0 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/tests/go.sum b/tests/go.sum index 0734543e475b..a4d6d7f5d5d2 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba h1:63dnRBywQLvo/Ke0zljksFlWg5tAMTwOiuv6yZ3X0sM= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba/go.mod h1:sf0uPZvsgXqXy2ydRXJmsM+sNHSZLZN6xZZkh7c3+t0= -cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d h1:kwSl5UsBYKFMxqfvAu/kfEJUsrGYCU2XGG7O4/XsCe4= -cosmossdk.io/x/tx v0.2.3-0.20230314101518-29e651e56e2d/go.mod h1:rdZJ9lBASrqH2qfZRAu6dXrvbPqaS0XDOmkaqUYymLk= +cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6 h1:Us1KeRPbFQxdyVc728kH6SErAmXbhFPfftyzWL8nliM= +cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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= From 13f3e5e83186ed66f4fceb81fc628bb2da9e8312 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Tue, 14 Mar 2023 11:27:59 +0100 Subject: [PATCH 10/25] Fix any --- x/tx/signing/textual/any.go | 26 +++++++++++++++++++++----- x/tx/signing/textual/duration.go | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/x/tx/signing/textual/any.go b/x/tx/signing/textual/any.go index bc7d57cd8357..31bf8b0b3e26 100644 --- a/x/tx/signing/textual/any.go +++ b/x/tx/signing/textual/any.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/cosmos/cosmos-proto/anyutil" + "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/types/dynamicpb" @@ -28,11 +29,9 @@ func NewAnyValueRenderer(t *SignModeHandler) ValueRenderer { // Format implements the ValueRenderer interface. func (ar anyValueRenderer) Format(ctx context.Context, v protoreflect.Value) ([]Screen, error) { msg := v.Message().Interface() - omitHeader := 0 - - anymsg, ok := msg.(*anypb.Any) - if !ok { - return nil, fmt.Errorf("expected Any, got %T", msg) + anymsg, err := toAny(msg) + if err != nil { + return nil, err } internalMsg, err := anyutil.Unpack(anymsg, ar.tr.protoFiles, ar.tr.protoTypes) @@ -51,6 +50,7 @@ func (ar anyValueRenderer) Format(ctx context.Context, v protoreflect.Value) ([] } // The Any value renderer suppresses emission of the object header + omitHeader := 0 _, isMsgRenderer := vr.(*messageValueRenderer) if isMsgRenderer && subscreens[0].Content == fmt.Sprintf("%s object", internalMsg.ProtoReflect().Descriptor().Name()) { omitHeader = 1 @@ -130,3 +130,19 @@ func (ar anyValueRenderer) Parse(ctx context.Context, screens []Screen) (protore return protoreflect.ValueOfMessage(anyMsg.ProtoReflect()), nil } + +// toAny converts the proto Message to a anypb.Any. +// The input msg can be: +// - either a durationpb.Duration already (in which case there's nothing to do), +// - or a dynamicpb.Message. +func toAny(msg proto.Message) (*anypb.Any, error) { + switch msg := msg.(type) { + case *anypb.Any: + return msg, nil + case *dynamicpb.Message: + t, v := getFieldValue(msg, "type_url").String(), getFieldValue(msg, "v").Bytes() + return &anypb.Any{TypeUrl: t, Value: v}, nil + default: + return nil, fmt.Errorf("expected dpb.Duration or dynamicpb.Message, got %T", msg) + } +} diff --git a/x/tx/signing/textual/duration.go b/x/tx/signing/textual/duration.go index 09768cc4137e..ba333cb76eaa 100644 --- a/x/tx/signing/textual/duration.go +++ b/x/tx/signing/textual/duration.go @@ -187,7 +187,7 @@ func (dr durationValueRenderer) Parse(_ context.Context, screens []Screen) (prot return protoreflect.ValueOfMessage(msg), nil } -// toDurations converts the proto Message to a durationpb.Duration. +// toDuration converts the proto Message to a durationpb.Duration. // The input msg can be: // - either a durationpb.Duration already (in which case there's nothing to do), // - or a dynamicpb.Message. From 39918aa44309c0386eca997449f77a61e7a08af0 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Tue, 14 Mar 2023 11:31:58 +0100 Subject: [PATCH 11/25] commit hash update --- go.mod | 2 +- go.sum | 4 ++-- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- tests/go.mod | 2 +- tests/go.sum | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 7c4e09d424d1..7847a1c54ed9 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v0.1.0 cosmossdk.io/math v1.0.0-rc.0 cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 - cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6 + cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index 75e27136f0a5..dc3a84fce137 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44/go.mod h1:flrxUykloEW1asE9p+Q+d8LSuNI3fBRdzISg9HTpYlQ= -cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6 h1:Us1KeRPbFQxdyVc728kH6SErAmXbhFPfftyzWL8nliM= -cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= +cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186 h1:3N9o9zNIdR6fUwNijO/dWgOi6lsvgwc3oe+KowDqgzI= +cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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 c5415f9d5765..ba85febf5881 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.29.0 // indirect cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6 // indirect + cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186 // 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/simapp/go.sum b/simapp/go.sum index f856f303f43c..08206d85d696 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba h1:63dnRBywQLvo/Ke0zljksFlWg5tAMTwOiuv6yZ3X0sM= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba/go.mod h1:sf0uPZvsgXqXy2ydRXJmsM+sNHSZLZN6xZZkh7c3+t0= -cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6 h1:Us1KeRPbFQxdyVc728kH6SErAmXbhFPfftyzWL8nliM= -cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= +cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186 h1:3N9o9zNIdR6fUwNijO/dWgOi6lsvgwc3oe+KowDqgzI= +cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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/go.mod b/tests/go.mod index ac02517d1f6c..e6b16d9a77ff 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6 + cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186 cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.0 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/tests/go.sum b/tests/go.sum index a4d6d7f5d5d2..fb9be4410a83 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba h1:63dnRBywQLvo/Ke0zljksFlWg5tAMTwOiuv6yZ3X0sM= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba/go.mod h1:sf0uPZvsgXqXy2ydRXJmsM+sNHSZLZN6xZZkh7c3+t0= -cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6 h1:Us1KeRPbFQxdyVc728kH6SErAmXbhFPfftyzWL8nliM= -cosmossdk.io/x/tx v0.2.3-0.20230314101855-5bb0b9515cf6/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= +cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186 h1:3N9o9zNIdR6fUwNijO/dWgOi6lsvgwc3oe+KowDqgzI= +cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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= From 201825b2ff5d273df134049497619c62b5df87ad Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Tue, 14 Mar 2023 11:32:51 +0100 Subject: [PATCH 12/25] fix any --- x/tx/signing/textual/any.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/tx/signing/textual/any.go b/x/tx/signing/textual/any.go index 31bf8b0b3e26..54608bb18a55 100644 --- a/x/tx/signing/textual/any.go +++ b/x/tx/signing/textual/any.go @@ -140,7 +140,7 @@ func toAny(msg proto.Message) (*anypb.Any, error) { case *anypb.Any: return msg, nil case *dynamicpb.Message: - t, v := getFieldValue(msg, "type_url").String(), getFieldValue(msg, "v").Bytes() + t, v := getFieldValue(msg, "type_url").String(), getFieldValue(msg, "value").Bytes() return &anypb.Any{TypeUrl: t, Value: v}, nil default: return nil, fmt.Errorf("expected dpb.Duration or dynamicpb.Message, got %T", msg) From 2abc5dba623da48934b746ae44f7cfeae2e04a82 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Tue, 14 Mar 2023 11:35:03 +0100 Subject: [PATCH 13/25] Fix error message --- x/tx/signing/textual/any.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/tx/signing/textual/any.go b/x/tx/signing/textual/any.go index 54608bb18a55..f893338458d9 100644 --- a/x/tx/signing/textual/any.go +++ b/x/tx/signing/textual/any.go @@ -143,6 +143,6 @@ func toAny(msg proto.Message) (*anypb.Any, error) { t, v := getFieldValue(msg, "type_url").String(), getFieldValue(msg, "value").Bytes() return &anypb.Any{TypeUrl: t, Value: v}, nil default: - return nil, fmt.Errorf("expected dpb.Duration or dynamicpb.Message, got %T", msg) + return nil, fmt.Errorf("expected anypb.Any or dynamicpb.Message, got %T", msg) } } From b7072d6280867a17d741247c7c576b478015b45d Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Tue, 14 Mar 2023 11:36:42 +0100 Subject: [PATCH 14/25] Update hashes --- go.mod | 2 +- go.sum | 4 ++-- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- tests/go.mod | 2 +- tests/go.sum | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 7847a1c54ed9..658562839c40 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v0.1.0 cosmossdk.io/math v1.0.0-rc.0 cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 - cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186 + cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index dc3a84fce137..a6315204de43 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44/go.mod h1:flrxUykloEW1asE9p+Q+d8LSuNI3fBRdzISg9HTpYlQ= -cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186 h1:3N9o9zNIdR6fUwNijO/dWgOi6lsvgwc3oe+KowDqgzI= -cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= +cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d h1:lcRBot6pUPhTsKBtbSPxxihC+IIrvJMkoL9fc7G9umM= +cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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 ba85febf5881..eced3c322224 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.29.0 // indirect cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186 // indirect + cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d // 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/simapp/go.sum b/simapp/go.sum index 08206d85d696..2cfa4dbcbed6 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba h1:63dnRBywQLvo/Ke0zljksFlWg5tAMTwOiuv6yZ3X0sM= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba/go.mod h1:sf0uPZvsgXqXy2ydRXJmsM+sNHSZLZN6xZZkh7c3+t0= -cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186 h1:3N9o9zNIdR6fUwNijO/dWgOi6lsvgwc3oe+KowDqgzI= -cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= +cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d h1:lcRBot6pUPhTsKBtbSPxxihC+IIrvJMkoL9fc7G9umM= +cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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/go.mod b/tests/go.mod index e6b16d9a77ff..787a750c693d 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186 + cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.0 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/tests/go.sum b/tests/go.sum index fb9be4410a83..9cb6e8084dcd 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba h1:63dnRBywQLvo/Ke0zljksFlWg5tAMTwOiuv6yZ3X0sM= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba/go.mod h1:sf0uPZvsgXqXy2ydRXJmsM+sNHSZLZN6xZZkh7c3+t0= -cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186 h1:3N9o9zNIdR6fUwNijO/dWgOi6lsvgwc3oe+KowDqgzI= -cosmossdk.io/x/tx v0.2.3-0.20230314102759-13f3e5e83186/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= +cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d h1:lcRBot6pUPhTsKBtbSPxxihC+IIrvJMkoL9fc7G9umM= +cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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= From 66a409f70a2477dc347a08b851758f530b3774ce Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Tue, 14 Mar 2023 11:59:21 +0100 Subject: [PATCH 15/25] Add dynamicpb tests --- x/tx/signing/textual/any.go | 2 +- x/tx/signing/textual/any_test.go | 56 ++++++++++++++++++++++++------- x/tx/signing/textual/duration.go | 2 +- x/tx/signing/textual/handler.go | 4 +-- x/tx/signing/textual/timestamp.go | 2 +- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/x/tx/signing/textual/any.go b/x/tx/signing/textual/any.go index f893338458d9..988b606c56b5 100644 --- a/x/tx/signing/textual/any.go +++ b/x/tx/signing/textual/any.go @@ -140,7 +140,7 @@ func toAny(msg proto.Message) (*anypb.Any, error) { case *anypb.Any: return msg, nil case *dynamicpb.Message: - t, v := getFieldValue(msg, "type_url").String(), getFieldValue(msg, "value").Bytes() + t, v := getValueFromFieldName(msg, "type_url").String(), getValueFromFieldName(msg, "value").Bytes() return &anypb.Any{TypeUrl: t, Value: v}, nil default: return nil, fmt.Errorf("expected anypb.Any or dynamicpb.Message, got %T", msg) diff --git a/x/tx/signing/textual/any_test.go b/x/tx/signing/textual/any_test.go index 750958a20949..d12287882ff1 100644 --- a/x/tx/signing/textual/any_test.go +++ b/x/tx/signing/textual/any_test.go @@ -6,18 +6,24 @@ import ( "fmt" "os" "testing" + "time" + "github.com/cosmos/cosmos-proto/anyutil" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" - - bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" - "cosmossdk.io/x/tx/signing/textual" - "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/testing/protocmp" "google.golang.org/protobuf/types/known/anypb" + "google.golang.org/protobuf/types/known/durationpb" + "google.golang.org/protobuf/types/known/timestamppb" + + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" + basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + "cosmossdk.io/x/tx/internal/testpb" + "cosmossdk.io/x/tx/signing/textual" ) type anyJsonTest struct { @@ -59,22 +65,46 @@ func TestAny(t *testing.T) { } } -func TestCustomProtoFiles(t *testing.T) { +func TestDynamicpb(t *testing.T) { tr, err := textual.NewSignModeHandler(textual.SignModeOptions{ CoinMetadataQuerier: EmptyCoinMetadataQuerier, ProtoTypes: &protoregistry.Types{}, // Set to empty to force using dynamicpb }) require.NoError(t, err) - msg := bankv1beta1.MsgSend{FromAddress: "foo"} - vr, err := tr.GetMessageValueRenderer(msg.ProtoReflect().Descriptor()) - require.NoError(t, err) - screens, err := vr.Format(context.Background(), protoreflect.ValueOf(msg.ProtoReflect())) + testAny, err := anyutil.New(&testpb.Foo{FullName: "foobar"}) require.NoError(t, err) - expScreens := []textual.Screen{ - {Content: "MsgSend object"}, - {Title: "From address", Content: "foo", Indent: 1}, + testcases := []struct { + name string + msg proto.Message + }{ + {"coin", &basev1beta1.Coin{Denom: "stake", Amount: "1"}}, + {"nested coins", &bankv1beta1.MsgSend{Amount: []*basev1beta1.Coin{{Denom: "stake", Amount: "1"}}}}, + {"any", testAny}, + {"nested any", &testpb.A{ANY: testAny}}, + {"duration", durationpb.New(time.Hour)}, + {"timestamp", timestamppb.New(time.Now())}, + } + + for _, tc := range testcases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + any, err := anyutil.New(tc.msg) + require.NoError(t, err) + val := &testpb.A{ + ANY: any, + } + vr, err := tr.GetMessageValueRenderer(val.ProtoReflect().Descriptor()) + require.NoError(t, err) + + // Round trip. + screens, err := vr.Format(context.Background(), protoreflect.ValueOf(val.ProtoReflect())) + require.NoError(t, err) + parsedVal, err := vr.Parse(context.Background(), screens) + require.NoError(t, err) + diff := cmp.Diff(val, parsedVal.Message().Interface(), protocmp.Transform()) + require.Empty(t, diff) + }) } - require.Equal(t, expScreens, screens) } diff --git a/x/tx/signing/textual/duration.go b/x/tx/signing/textual/duration.go index ba333cb76eaa..06c65a349474 100644 --- a/x/tx/signing/textual/duration.go +++ b/x/tx/signing/textual/duration.go @@ -196,7 +196,7 @@ func toDuration(msg proto.Message) (*dpb.Duration, error) { case *dpb.Duration: return msg, nil case *dynamicpb.Message: - s, n := getFieldValue(msg, "seconds").Int(), getFieldValue(msg, "nanos").Int() + s, n := getValueFromFieldName(msg, "seconds").Int(), getValueFromFieldName(msg, "nanos").Int() return &dpb.Duration{Seconds: s, Nanos: int32(n)}, nil default: return nil, fmt.Errorf("expected dpb.Duration or dynamicpb.Message, got %T", msg) diff --git a/x/tx/signing/textual/handler.go b/x/tx/signing/textual/handler.go index 2f53e5b0ade0..3963df99b6cb 100644 --- a/x/tx/signing/textual/handler.go +++ b/x/tx/signing/textual/handler.go @@ -218,9 +218,9 @@ func (r *SignModeHandler) Mode() signingv1beta1.SignMode { var _ signing.SignModeHandler = &SignModeHandler{} -// getFieldValue is an utility function to get the protoreflect.Value of a +// getValueFromFieldName is an utility function to get the protoreflect.Value of a // proto Message from its field name. -func getFieldValue(m proto.Message, fieldName string) protoreflect.Value { +func getValueFromFieldName(m proto.Message, fieldName string) protoreflect.Value { fd := m.ProtoReflect().Descriptor().Fields().ByName(protoreflect.Name(fieldName)) return m.ProtoReflect().Get(fd) diff --git a/x/tx/signing/textual/timestamp.go b/x/tx/signing/textual/timestamp.go index 1a8b6a6cc9c0..62c4aacb2d5c 100644 --- a/x/tx/signing/textual/timestamp.go +++ b/x/tx/signing/textual/timestamp.go @@ -60,7 +60,7 @@ func toTimestamp(msg protoreflect.ProtoMessage) (*tspb.Timestamp, error) { case *tspb.Timestamp: return msg, nil case *dynamicpb.Message: - s, n := getFieldValue(msg, "seconds").Int(), getFieldValue(msg, "nanos").Int() + s, n := getValueFromFieldName(msg, "seconds").Int(), getValueFromFieldName(msg, "nanos").Int() return &tspb.Timestamp{Seconds: s, Nanos: int32(n)}, nil default: return nil, fmt.Errorf("expected timestamppb.Timestamp or dynamicpb.Message, got %T", msg) From be1067a113ea46202437b2a6e059de7128b8689e Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Tue, 14 Mar 2023 12:00:22 +0100 Subject: [PATCH 16/25] Fix coins --- x/tx/signing/textual/coins.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/x/tx/signing/textual/coins.go b/x/tx/signing/textual/coins.go index 60e25dd78f8b..b02e9c2e4d42 100644 --- a/x/tx/signing/textual/coins.go +++ b/x/tx/signing/textual/coins.go @@ -66,7 +66,10 @@ func (vr coinsValueRenderer) FormatRepeated(ctx context.Context, v protoreflect. coins, metadatas := make([]*basev1beta1.Coin, protoCoins.Len()), make([]*bankv1beta1.Metadata, protoCoins.Len()) var err error for i := 0; i < protoCoins.Len(); i++ { - coin := protoCoins.Get(i).Interface().(protoreflect.Message).Interface().(*basev1beta1.Coin) + coin, err := toCoin(protoCoins.Get(i).Interface().(protoreflect.Message).Interface()) + if err != nil { + return nil, err + } coins[i] = coin metadatas[i], err = vr.coinMetadataQuerier(ctx, coin.Denom) if err != nil { @@ -225,7 +228,7 @@ func toCoin(msg proto.Message) (*basev1beta1.Coin, error) { case *basev1beta1.Coin: return msg, nil case *dynamicpb.Message: - a, d := getFieldValue(msg, "amount").String(), getFieldValue(msg, "denom").String() + a, d := getValueFromFieldName(msg, "amount").String(), getValueFromFieldName(msg, "denom").String() return &basev1beta1.Coin{Amount: a, Denom: d}, nil default: return nil, fmt.Errorf("expected timestamppb.Timestamp or dynamicpb.Message, got %T", msg) From b50a78c3f73fea29aed0d1194f1430dbd4b341cd Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Tue, 14 Mar 2023 12:03:23 +0100 Subject: [PATCH 17/25] Update hashes --- go.mod | 2 +- go.sum | 4 ++-- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- tests/go.mod | 2 +- tests/go.sum | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 658562839c40..f3181c6ed491 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v0.1.0 cosmossdk.io/math v1.0.0-rc.0 cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 - cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d + cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index a6315204de43..a308935b041a 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44/go.mod h1:flrxUykloEW1asE9p+Q+d8LSuNI3fBRdzISg9HTpYlQ= -cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d h1:lcRBot6pUPhTsKBtbSPxxihC+IIrvJMkoL9fc7G9umM= -cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= +cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea h1:YbD4bUTQXFgyig7UjO7x8ThoCfKKTy/pgfdUgWS+QWY= +cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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 eced3c322224..8d0557ebefd3 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.29.0 // indirect cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d // indirect + cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea // 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/simapp/go.sum b/simapp/go.sum index 2cfa4dbcbed6..502642559fec 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba h1:63dnRBywQLvo/Ke0zljksFlWg5tAMTwOiuv6yZ3X0sM= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba/go.mod h1:sf0uPZvsgXqXy2ydRXJmsM+sNHSZLZN6xZZkh7c3+t0= -cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d h1:lcRBot6pUPhTsKBtbSPxxihC+IIrvJMkoL9fc7G9umM= -cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= +cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea h1:YbD4bUTQXFgyig7UjO7x8ThoCfKKTy/pgfdUgWS+QWY= +cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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/go.mod b/tests/go.mod index 787a750c693d..9bf177eced47 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d + cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.0 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/tests/go.sum b/tests/go.sum index 9cb6e8084dcd..57b8757b3984 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba h1:63dnRBywQLvo/Ke0zljksFlWg5tAMTwOiuv6yZ3X0sM= cosmossdk.io/store v0.0.0-20230309163709-87da587416ba/go.mod h1:sf0uPZvsgXqXy2ydRXJmsM+sNHSZLZN6xZZkh7c3+t0= -cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d h1:lcRBot6pUPhTsKBtbSPxxihC+IIrvJMkoL9fc7G9umM= -cosmossdk.io/x/tx v0.2.3-0.20230314103251-201825b2ff5d/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= +cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea h1:YbD4bUTQXFgyig7UjO7x8ThoCfKKTy/pgfdUgWS+QWY= +cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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= From 9a83c202cd545265f54d15090c6b150dc692f0f6 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Tue, 14 Mar 2023 12:07:05 +0100 Subject: [PATCH 18/25] Fix error message --- x/tx/signing/textual/any.go | 2 +- x/tx/signing/textual/coins.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x/tx/signing/textual/any.go b/x/tx/signing/textual/any.go index 988b606c56b5..3a344935f928 100644 --- a/x/tx/signing/textual/any.go +++ b/x/tx/signing/textual/any.go @@ -133,7 +133,7 @@ func (ar anyValueRenderer) Parse(ctx context.Context, screens []Screen) (protore // toAny converts the proto Message to a anypb.Any. // The input msg can be: -// - either a durationpb.Duration already (in which case there's nothing to do), +// - either a anypb.Any already (in which case there's nothing to do), // - or a dynamicpb.Message. func toAny(msg proto.Message) (*anypb.Any, error) { switch msg := msg.(type) { diff --git a/x/tx/signing/textual/coins.go b/x/tx/signing/textual/coins.go index b02e9c2e4d42..dc979ae319c6 100644 --- a/x/tx/signing/textual/coins.go +++ b/x/tx/signing/textual/coins.go @@ -231,6 +231,6 @@ func toCoin(msg proto.Message) (*basev1beta1.Coin, error) { a, d := getValueFromFieldName(msg, "amount").String(), getValueFromFieldName(msg, "denom").String() return &basev1beta1.Coin{Amount: a, Denom: d}, nil default: - return nil, fmt.Errorf("expected timestamppb.Timestamp or dynamicpb.Message, got %T", msg) + return nil, fmt.Errorf("expected Coin or dynamicpb.Message, got %T", msg) } } From fbe2ce682c6912f659d1e654edd8285aaea7f2f3 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Thu, 16 Mar 2023 09:48:10 +0100 Subject: [PATCH 19/25] coerceToMessage --- x/tx/signing/textual/any.go | 20 ++-------------- x/tx/signing/textual/coins.go | 24 ++++--------------- x/tx/signing/textual/duration.go | 21 ++--------------- x/tx/signing/textual/handler.go | 38 +++++++++++++++++++++++++++++++ x/tx/signing/textual/timestamp.go | 20 ++-------------- 5 files changed, 48 insertions(+), 75 deletions(-) diff --git a/x/tx/signing/textual/any.go b/x/tx/signing/textual/any.go index 3a344935f928..11561d765fe9 100644 --- a/x/tx/signing/textual/any.go +++ b/x/tx/signing/textual/any.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/cosmos/cosmos-proto/anyutil" - "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/types/dynamicpb" @@ -29,7 +28,8 @@ func NewAnyValueRenderer(t *SignModeHandler) ValueRenderer { // Format implements the ValueRenderer interface. func (ar anyValueRenderer) Format(ctx context.Context, v protoreflect.Value) ([]Screen, error) { msg := v.Message().Interface() - anymsg, err := toAny(msg) + anymsg := &anypb.Any{} + err := coerceToMessage(msg, anymsg) if err != nil { return nil, err } @@ -130,19 +130,3 @@ func (ar anyValueRenderer) Parse(ctx context.Context, screens []Screen) (protore return protoreflect.ValueOfMessage(anyMsg.ProtoReflect()), nil } - -// toAny converts the proto Message to a anypb.Any. -// The input msg can be: -// - either a anypb.Any already (in which case there's nothing to do), -// - or a dynamicpb.Message. -func toAny(msg proto.Message) (*anypb.Any, error) { - switch msg := msg.(type) { - case *anypb.Any: - return msg, nil - case *dynamicpb.Message: - t, v := getValueFromFieldName(msg, "type_url").String(), getValueFromFieldName(msg, "value").Bytes() - return &anypb.Any{TypeUrl: t, Value: v}, nil - default: - return nil, fmt.Errorf("expected anypb.Any or dynamicpb.Message, got %T", msg) - } -} diff --git a/x/tx/signing/textual/coins.go b/x/tx/signing/textual/coins.go index dc979ae319c6..addd95ca8bf2 100644 --- a/x/tx/signing/textual/coins.go +++ b/x/tx/signing/textual/coins.go @@ -5,9 +5,7 @@ import ( "fmt" "strings" - "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/types/dynamicpb" bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" @@ -39,7 +37,8 @@ func (vr coinsValueRenderer) Format(ctx context.Context, v protoreflect.Value) ( // Since this value renderer has a FormatRepeated method, the Format one // here only handles single coin. - coin, err := toCoin(v.Interface().(protoreflect.Message).Interface()) + coin := &basev1beta1.Coin{} + err := coerceToMessage(v.Interface().(protoreflect.Message).Interface(), coin) if err != nil { return nil, err } @@ -66,7 +65,8 @@ func (vr coinsValueRenderer) FormatRepeated(ctx context.Context, v protoreflect. coins, metadatas := make([]*basev1beta1.Coin, protoCoins.Len()), make([]*bankv1beta1.Metadata, protoCoins.Len()) var err error for i := 0; i < protoCoins.Len(); i++ { - coin, err := toCoin(protoCoins.Get(i).Interface().(protoreflect.Message).Interface()) + coin := &basev1beta1.Coin{} + err := coerceToMessage(protoCoins.Get(i).Interface().(protoreflect.Message).Interface(), coin) if err != nil { return nil, err } @@ -218,19 +218,3 @@ func parseCoin(coinStr string, metadata *bankv1beta1.Metadata) (*basev1beta1.Coi Denom: baseDenom, }, nil } - -// toCoin converts the proto Message to a Coin. -// The input msg can be: -// - either a Coin already (in which case there's nothing to do), -// - or a dynamicpb.Message. -func toCoin(msg proto.Message) (*basev1beta1.Coin, error) { - switch msg := msg.(type) { - case *basev1beta1.Coin: - return msg, nil - case *dynamicpb.Message: - a, d := getValueFromFieldName(msg, "amount").String(), getValueFromFieldName(msg, "denom").String() - return &basev1beta1.Coin{Amount: a, Denom: d}, nil - default: - return nil, fmt.Errorf("expected Coin or dynamicpb.Message, got %T", msg) - } -} diff --git a/x/tx/signing/textual/duration.go b/x/tx/signing/textual/duration.go index 06c65a349474..7afe077571de 100644 --- a/x/tx/signing/textual/duration.go +++ b/x/tx/signing/textual/duration.go @@ -7,9 +7,7 @@ import ( "strconv" "strings" - "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/types/dynamicpb" dpb "google.golang.org/protobuf/types/known/durationpb" ) @@ -69,7 +67,8 @@ func formatSeconds(seconds int64, nanos int32) string { func (dr durationValueRenderer) Format(_ context.Context, v protoreflect.Value) ([]Screen, error) { // Reify the reflected message as a proto Duration msg := v.Message().Interface() - duration, err := toDuration(msg) + duration := &dpb.Duration{} + err := coerceToMessage(msg, duration) if err != nil { return nil, err } @@ -186,19 +185,3 @@ func (dr durationValueRenderer) Parse(_ context.Context, screens []Screen) (prot msg := dur.ProtoReflect() return protoreflect.ValueOfMessage(msg), nil } - -// toDuration converts the proto Message to a durationpb.Duration. -// The input msg can be: -// - either a durationpb.Duration already (in which case there's nothing to do), -// - or a dynamicpb.Message. -func toDuration(msg proto.Message) (*dpb.Duration, error) { - switch msg := msg.(type) { - case *dpb.Duration: - return msg, nil - case *dynamicpb.Message: - s, n := getValueFromFieldName(msg, "seconds").Int(), getValueFromFieldName(msg, "nanos").Int() - return &dpb.Duration{Seconds: s, Nanos: int32(n)}, nil - default: - return nil, fmt.Errorf("expected dpb.Duration or dynamicpb.Message, got %T", msg) - } -} diff --git a/x/tx/signing/textual/handler.go b/x/tx/signing/textual/handler.go index 3963df99b6cb..73de7eb2db7b 100644 --- a/x/tx/signing/textual/handler.go +++ b/x/tx/signing/textual/handler.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "reflect" signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "google.golang.org/protobuf/proto" @@ -225,3 +226,40 @@ func getValueFromFieldName(m proto.Message, fieldName string) protoreflect.Value return m.ProtoReflect().Get(fd) } + +// coerceToMessage initializes the given desiredMsg (presented as a protov2 +// concrete message) with the values of givenMsg. +// +// If givenMsg is a protov2 concrete message of the same type, then it will +// fast-path to be initialized to the same value. +// For a dynamicpb message it checks that the names match then uses proto +// reflection to initialize the fields of desiredMsg. +// Otherwise throws an error. +// +// Example: +// +// // Assume `givenCoin` is a dynamicpb.Message representing a Coin +// coin := &basev1beta1.Coin{} +// err := coerceToMessage(givenCoin, coin) +// if err != nil { /* handler error */ } +// fmt.Println(coin) // Will have the same field values as `givenCoin` +func coerceToMessage(givenMsg, desiredMsg proto.Message) error { + if reflect.TypeOf(givenMsg) == reflect.TypeOf(desiredMsg) { + // Below is a way of saying "*desiredMsg = *givenMsg" using go reflect + reflect.Indirect(reflect.ValueOf(desiredMsg)).Set(reflect.Indirect(reflect.ValueOf(givenMsg))) + return nil + } + + givenName, desiredName := givenMsg.ProtoReflect().Descriptor().FullName(), desiredMsg.ProtoReflect().Descriptor().FullName() + if givenName != desiredName { + return fmt.Errorf("expected dynamicpb.Message with FullName %s, got %s", desiredName, givenName) + } + + desiredFields := desiredMsg.ProtoReflect().Descriptor().Fields() + for i := 0; i < desiredFields.Len(); i++ { + fd := desiredFields.Get(i) + desiredMsg.ProtoReflect().Set(fd, getValueFromFieldName(givenMsg, string(fd.Name()))) + } + + return nil +} diff --git a/x/tx/signing/textual/timestamp.go b/x/tx/signing/textual/timestamp.go index 62c4aacb2d5c..b4114fd9fd2c 100644 --- a/x/tx/signing/textual/timestamp.go +++ b/x/tx/signing/textual/timestamp.go @@ -6,7 +6,6 @@ import ( "time" "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/types/dynamicpb" tspb "google.golang.org/protobuf/types/known/timestamppb" ) @@ -21,7 +20,8 @@ func NewTimestampValueRenderer() ValueRenderer { // Format implements the ValueRenderer interface. func (vr timestampValueRenderer) Format(_ context.Context, v protoreflect.Value) ([]Screen, error) { - ts, err := toTimestamp(v.Message().Interface()) + ts := &tspb.Timestamp{} + err := coerceToMessage(v.Message().Interface(), ts) if err != nil { return nil, err } @@ -50,19 +50,3 @@ func (vr timestampValueRenderer) Parse(_ context.Context, screens []Screen) (pro msg := timestamp.ProtoReflect() return protoreflect.ValueOfMessage(msg), nil } - -// convertToGoTime converts the proto Message to a timestamppb.Timestamp. -// The input msg can be: -// - either a timestamppb.Timestamp (in which case there's nothing to do), -// - or a dynamicpb.Message. -func toTimestamp(msg protoreflect.ProtoMessage) (*tspb.Timestamp, error) { - switch msg := msg.(type) { - case *tspb.Timestamp: - return msg, nil - case *dynamicpb.Message: - s, n := getValueFromFieldName(msg, "seconds").Int(), getValueFromFieldName(msg, "nanos").Int() - return &tspb.Timestamp{Seconds: s, Nanos: int32(n)}, nil - default: - return nil, fmt.Errorf("expected timestamppb.Timestamp or dynamicpb.Message, got %T", msg) - } -} From 064c7c041216bef0cc2dd50a90d6257ffa871b5d Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Thu, 16 Mar 2023 09:50:53 +0100 Subject: [PATCH 20/25] go mod tidy --- simapp/go.sum | 4 ++-- tests/go.sum | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/simapp/go.sum b/simapp/go.sum index 62cf00b56e8c..dfd97be4071c 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f h1:nyRTC4KpgDJDVAEujx0CgXvDeDppEVFSbdvY8RlzL04= cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f/go.mod h1:Q+g1TMKWsDvGYCAri6amJ6otL5HqN3RMNsg+fBKh8AY= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba h1:NmWXkl0voj3dN96Qmk4rfrze6dLLLxB4qTCxXZTXBpM= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba/go.mod h1:dhIxZhZF2glIA9hkkildy/JmSqVH3FIU/OhSU8is7PM= +cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea h1:YbD4bUTQXFgyig7UjO7x8ThoCfKKTy/pgfdUgWS+QWY= +cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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/go.sum b/tests/go.sum index 7c79bb8ed4cf..cb2d63ce8109 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f h1:nyRTC4KpgDJDVAEujx0CgXvDeDppEVFSbdvY8RlzL04= cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f/go.mod h1:Q+g1TMKWsDvGYCAri6amJ6otL5HqN3RMNsg+fBKh8AY= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba h1:NmWXkl0voj3dN96Qmk4rfrze6dLLLxB4qTCxXZTXBpM= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba/go.mod h1:dhIxZhZF2glIA9hkkildy/JmSqVH3FIU/OhSU8is7PM= +cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea h1:YbD4bUTQXFgyig7UjO7x8ThoCfKKTy/pgfdUgWS+QWY= +cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= 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= From d031fe28e32871326d1f50cb9caa64c742ca1f3c Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Thu, 16 Mar 2023 09:52:27 +0100 Subject: [PATCH 21/25] Update hashes --- go.mod | 2 +- go.sum | 4 ++-- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- tests/go.mod | 2 +- tests/go.sum | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index fcf50ef4d08a..ee44d10ae2f8 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v0.1.0 cosmossdk.io/math v1.0.0-rc.0 cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f - cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba + cosmossdk.io/x/tx v0.3.1-0.20230316085053-064c7c041216 github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index 6045d6f2da1a..5268fff9575c 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f h1:nyRTC4KpgDJDVAEujx0CgXvDeDppEVFSbdvY8RlzL04= cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f/go.mod h1:Q+g1TMKWsDvGYCAri6amJ6otL5HqN3RMNsg+fBKh8AY= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba h1:NmWXkl0voj3dN96Qmk4rfrze6dLLLxB4qTCxXZTXBpM= -cosmossdk.io/x/tx v0.2.3-0.20230309163709-87da587416ba/go.mod h1:dhIxZhZF2glIA9hkkildy/JmSqVH3FIU/OhSU8is7PM= +cosmossdk.io/x/tx v0.3.1-0.20230316085053-064c7c041216 h1:QYIVmUtzrdLOgptRcWPMk0RtwBt8mBy+ss07QlFL+rc= +cosmossdk.io/x/tx v0.3.1-0.20230316085053-064c7c041216/go.mod h1:ELY0bP2SmOqyffJFp00g979xsI1zBdmc55A6JCi1Qe8= 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 a9cbedbf65f0..1396d558254b 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.29.0 // indirect cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea // indirect + cosmossdk.io/x/tx v0.3.1-0.20230316085053-064c7c041216 // 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/simapp/go.sum b/simapp/go.sum index dfd97be4071c..71e1e25cee63 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f h1:nyRTC4KpgDJDVAEujx0CgXvDeDppEVFSbdvY8RlzL04= cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f/go.mod h1:Q+g1TMKWsDvGYCAri6amJ6otL5HqN3RMNsg+fBKh8AY= -cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea h1:YbD4bUTQXFgyig7UjO7x8ThoCfKKTy/pgfdUgWS+QWY= -cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= +cosmossdk.io/x/tx v0.3.1-0.20230316085053-064c7c041216 h1:QYIVmUtzrdLOgptRcWPMk0RtwBt8mBy+ss07QlFL+rc= +cosmossdk.io/x/tx v0.3.1-0.20230316085053-064c7c041216/go.mod h1:ELY0bP2SmOqyffJFp00g979xsI1zBdmc55A6JCi1Qe8= 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/go.mod b/tests/go.mod index af14e08cfe77..ab8176c93de4 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea + cosmossdk.io/x/tx v0.3.1-0.20230316085053-064c7c041216 cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.0 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/tests/go.sum b/tests/go.sum index cb2d63ce8109..3b066b7ca387 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f h1:nyRTC4KpgDJDVAEujx0CgXvDeDppEVFSbdvY8RlzL04= cosmossdk.io/store v0.0.0-20230314205129-d50cb1ef349f/go.mod h1:Q+g1TMKWsDvGYCAri6amJ6otL5HqN3RMNsg+fBKh8AY= -cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea h1:YbD4bUTQXFgyig7UjO7x8ThoCfKKTy/pgfdUgWS+QWY= -cosmossdk.io/x/tx v0.2.3-0.20230314110022-be1067a113ea/go.mod h1:LFuT69zWHehsPm58kiVAmDgLfoTmd2XGD3IvD04MfcM= +cosmossdk.io/x/tx v0.3.1-0.20230316085053-064c7c041216 h1:QYIVmUtzrdLOgptRcWPMk0RtwBt8mBy+ss07QlFL+rc= +cosmossdk.io/x/tx v0.3.1-0.20230316085053-064c7c041216/go.mod h1:ELY0bP2SmOqyffJFp00g979xsI1zBdmc55A6JCi1Qe8= 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= From f793269f01937d30cc7cd9d844939e906d9cd25d Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Thu, 16 Mar 2023 09:57:51 +0100 Subject: [PATCH 22/25] Comments --- x/tx/signing/textual/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/tx/signing/textual/handler.go b/x/tx/signing/textual/handler.go index 73de7eb2db7b..1a51f4bff973 100644 --- a/x/tx/signing/textual/handler.go +++ b/x/tx/signing/textual/handler.go @@ -231,7 +231,7 @@ func getValueFromFieldName(m proto.Message, fieldName string) protoreflect.Value // concrete message) with the values of givenMsg. // // If givenMsg is a protov2 concrete message of the same type, then it will -// fast-path to be initialized to the same value. +// fast-path to be initialized to the same pointer value. // For a dynamicpb message it checks that the names match then uses proto // reflection to initialize the fields of desiredMsg. // Otherwise throws an error. From 34d913858fe75627bed28c04461ea51f72036d90 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Thu, 16 Mar 2023 10:11:13 +0100 Subject: [PATCH 23/25] More consistent naming --- x/tx/signing/textual/any.go | 6 +++--- x/tx/signing/textual/any_test.go | 2 +- x/tx/signing/textual/handler.go | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/x/tx/signing/textual/any.go b/x/tx/signing/textual/any.go index 11561d765fe9..516496f9fce9 100644 --- a/x/tx/signing/textual/any.go +++ b/x/tx/signing/textual/any.go @@ -34,7 +34,7 @@ func (ar anyValueRenderer) Format(ctx context.Context, v protoreflect.Value) ([] return nil, err } - internalMsg, err := anyutil.Unpack(anymsg, ar.tr.protoFiles, ar.tr.protoTypes) + internalMsg, err := anyutil.Unpack(anymsg, ar.tr.fileResolver, ar.tr.typeResolver) if err != nil { return nil, err } @@ -76,7 +76,7 @@ func (ar anyValueRenderer) Parse(ctx context.Context, screens []Screen) (protore } typeURL := screens[0].Content - msgType, err := ar.tr.protoTypes.FindMessageByURL(typeURL) + msgType, err := ar.tr.typeResolver.FindMessageByURL(typeURL) if err == protoregistry.NotFound { // If the proto v2 registry doesn't have this message, then we use // protoFiles (which can e.g. be initialized to gogo's MergedRegistry) @@ -84,7 +84,7 @@ func (ar anyValueRenderer) Parse(ctx context.Context, screens []Screen) (protore // message descriptor to create a proto.Message typeURL := strings.TrimPrefix(typeURL, "/") - msgDesc, err := ar.tr.protoFiles.FindDescriptorByName(protoreflect.FullName(typeURL)) + msgDesc, err := ar.tr.fileResolver.FindDescriptorByName(protoreflect.FullName(typeURL)) if err != nil { return nilValue, fmt.Errorf("textual protoFiles does not have descriptor %s: %w", typeURL, err) } diff --git a/x/tx/signing/textual/any_test.go b/x/tx/signing/textual/any_test.go index d12287882ff1..b15d63355ecd 100644 --- a/x/tx/signing/textual/any_test.go +++ b/x/tx/signing/textual/any_test.go @@ -68,7 +68,7 @@ func TestAny(t *testing.T) { func TestDynamicpb(t *testing.T) { tr, err := textual.NewSignModeHandler(textual.SignModeOptions{ CoinMetadataQuerier: EmptyCoinMetadataQuerier, - ProtoTypes: &protoregistry.Types{}, // Set to empty to force using dynamicpb + TypeResolver: &protoregistry.Types{}, // Set to empty to force using dynamicpb }) require.NoError(t, err) diff --git a/x/tx/signing/textual/handler.go b/x/tx/signing/textual/handler.go index 1a51f4bff973..3aeaf7423a96 100644 --- a/x/tx/signing/textual/handler.go +++ b/x/tx/signing/textual/handler.go @@ -37,20 +37,20 @@ type SignModeOptions struct { // server-side code) or a gRPC query client (for client-side code). CoinMetadataQuerier CoinMetadataQueryFn - // ProtoFiles are the protobuf files to use for resolving message + // FileResolver are the protobuf files to use for resolving message // descriptors. If it is nil, the global protobuf registry will be used. - ProtoFiles *protoregistry.Files + FileResolver *protoregistry.Files - // ProtoTypes are the protobuf type resolvers to use for resolving message - // types. If it is nil, then a dynamicpb will be used on top of ProtoFiles. - ProtoTypes protoregistry.MessageTypeResolver + // TypeResolver are the protobuf type resolvers to use for resolving message + // types. If it is nil, then a dynamicpb will be used on top of FileResolver. + TypeResolver protoregistry.MessageTypeResolver } // SignModeHandler holds the configuration for dispatching // to specific value renderers for SIGN_MODE_TEXTUAL. type SignModeHandler struct { - protoFiles *protoregistry.Files - protoTypes protoregistry.MessageTypeResolver + fileResolver *protoregistry.Files + typeResolver protoregistry.MessageTypeResolver coinMetadataQuerier CoinMetadataQueryFn // scalars defines a registry for Cosmos scalars. scalars map[string]ValueRendererCreator @@ -68,17 +68,17 @@ func NewSignModeHandler(o SignModeOptions) (*SignModeHandler, error) { if o.CoinMetadataQuerier == nil { return nil, fmt.Errorf("coinMetadataQuerier must be non-empty") } - if o.ProtoFiles == nil { - o.ProtoFiles = protoregistry.GlobalFiles + if o.FileResolver == nil { + o.FileResolver = protoregistry.GlobalFiles } - if o.ProtoTypes == nil { - o.ProtoTypes = protoregistry.GlobalTypes + if o.TypeResolver == nil { + o.TypeResolver = protoregistry.GlobalTypes } t := &SignModeHandler{ coinMetadataQuerier: o.CoinMetadataQuerier, - protoFiles: o.ProtoFiles, - protoTypes: o.ProtoTypes, + fileResolver: o.FileResolver, + typeResolver: o.TypeResolver, } t.init() From 725d6460f3f23c5804a96a4c2c9dad03e7eff956 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Mon, 20 Mar 2023 08:30:03 +0100 Subject: [PATCH 24/25] Update hash --- go.mod | 2 +- go.sum | 4 ++-- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- tests/go.mod | 2 +- tests/go.sum | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index ce1772a315bb..88baa36aa2cb 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( cosmossdk.io/log v0.1.0 cosmossdk.io/math v1.0.0-rc.0 cosmossdk.io/store v0.1.0-alpha.1 - cosmossdk.io/x/tx v0.3.0 + cosmossdk.io/x/tx v0.3.1-0.20230320072322-5fceb7c0495f github.com/99designs/keyring v1.2.1 github.com/armon/go-metrics v0.4.1 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 diff --git a/go.sum b/go.sum index bfec3fca3b26..db3eaeccf0b1 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1 h1:NGomhLUXzAxvK4OF8+yP6eNUG5i4LwzOzx+S494pTCg= cosmossdk.io/store v0.1.0-alpha.1/go.mod h1:kmCMbhrleCZ6rDZPY/EGNldNvPebFNyVPFYp+pv05/k= -cosmossdk.io/x/tx v0.3.0 h1:AgVYy6bxL3XqEV7RLyxFh1uT+wywsrbgVMmYnL3FgWM= -cosmossdk.io/x/tx v0.3.0/go.mod h1:ELY0bP2SmOqyffJFp00g979xsI1zBdmc55A6JCi1Qe8= +cosmossdk.io/x/tx v0.3.1-0.20230320072322-5fceb7c0495f h1:yXEE3D6L0Ykwlp4FuS1SoHgT9vZ8brBJ/dkHezXBU9o= +cosmossdk.io/x/tx v0.3.1-0.20230320072322-5fceb7c0495f/go.mod h1:V/7DjCSReJ7LBBYrNtVFUec7t63hVNyFh0vBXOBK2Yg= 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 40550ead9486..260d64d69a8f 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/storage v1.29.0 // indirect cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect cosmossdk.io/errors v1.0.0-beta.7 // indirect - cosmossdk.io/x/tx v0.3.0 // indirect + cosmossdk.io/x/tx v0.3.1-0.20230320072322-5fceb7c0495f // 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/simapp/go.sum b/simapp/go.sum index 0fbb348305e5..e9f583e52f80 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1 h1:NGomhLUXzAxvK4OF8+yP6eNUG5i4LwzOzx+S494pTCg= cosmossdk.io/store v0.1.0-alpha.1/go.mod h1:kmCMbhrleCZ6rDZPY/EGNldNvPebFNyVPFYp+pv05/k= -cosmossdk.io/x/tx v0.3.0 h1:AgVYy6bxL3XqEV7RLyxFh1uT+wywsrbgVMmYnL3FgWM= -cosmossdk.io/x/tx v0.3.0/go.mod h1:ELY0bP2SmOqyffJFp00g979xsI1zBdmc55A6JCi1Qe8= +cosmossdk.io/x/tx v0.3.1-0.20230320072322-5fceb7c0495f h1:yXEE3D6L0Ykwlp4FuS1SoHgT9vZ8brBJ/dkHezXBU9o= +cosmossdk.io/x/tx v0.3.1-0.20230320072322-5fceb7c0495f/go.mod h1:V/7DjCSReJ7LBBYrNtVFUec7t63hVNyFh0vBXOBK2Yg= 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/go.mod b/tests/go.mod index 3bb7cfd3357a..f94ea97cea77 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc - cosmossdk.io/x/tx v0.3.0 + cosmossdk.io/x/tx v0.3.1-0.20230320072322-5fceb7c0495f cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.0 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/tests/go.sum b/tests/go.sum index ec773768cbb4..66b38c50ba74 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -206,8 +206,8 @@ cosmossdk.io/math v1.0.0-rc.0 h1:ml46ukocrAAoBpYKMidF0R2tQJ1Uxfns0yH8wqgMAFc= cosmossdk.io/math v1.0.0-rc.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1 h1:NGomhLUXzAxvK4OF8+yP6eNUG5i4LwzOzx+S494pTCg= cosmossdk.io/store v0.1.0-alpha.1/go.mod h1:kmCMbhrleCZ6rDZPY/EGNldNvPebFNyVPFYp+pv05/k= -cosmossdk.io/x/tx v0.3.0 h1:AgVYy6bxL3XqEV7RLyxFh1uT+wywsrbgVMmYnL3FgWM= -cosmossdk.io/x/tx v0.3.0/go.mod h1:ELY0bP2SmOqyffJFp00g979xsI1zBdmc55A6JCi1Qe8= +cosmossdk.io/x/tx v0.3.1-0.20230320072322-5fceb7c0495f h1:yXEE3D6L0Ykwlp4FuS1SoHgT9vZ8brBJ/dkHezXBU9o= +cosmossdk.io/x/tx v0.3.1-0.20230320072322-5fceb7c0495f/go.mod h1:V/7DjCSReJ7LBBYrNtVFUec7t63hVNyFh0vBXOBK2Yg= 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= From c422196e622fd524849a54907f24c4f95aa1ce5e Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Mon, 20 Mar 2023 08:37:23 +0100 Subject: [PATCH 25/25] Fix --- x/auth/tx/config/textual.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/auth/tx/config/textual.go b/x/auth/tx/config/textual.go index 348a2b54b0f9..3a93cb689d17 100644 --- a/x/auth/tx/config/textual.go +++ b/x/auth/tx/config/textual.go @@ -40,7 +40,7 @@ func NewTextualWithGRPCConn(grpcConn grpc.ClientConnInterface) (*textual.SignMod return res.Metadata, nil }, - ProtoFiles: protoFiles, + FileResolver: protoFiles, }) } @@ -85,7 +85,7 @@ func NewTextualWithBankKeeper(bk BankKeeper) (*textual.SignModeHandler, error) { return m, nil }, - ProtoFiles: protoFiles, + FileResolver: protoFiles, }) }