diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 7ae5cda888c..443ebc44503 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -76,7 +76,6 @@ func TestBaseApp_BlockGas(t *testing.T) { appBuilder *runtime.AppBuilder txConfig client.TxConfig cdc codec.Codec - pcdc codec.ProtoCodecMarshaler interfaceRegistry codectypes.InterfaceRegistry err error ) @@ -97,7 +96,6 @@ func TestBaseApp_BlockGas(t *testing.T) { &interfaceRegistry, &txConfig, &cdc, - &pcdc, &appBuilder) require.NoError(t, err) diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index 23acbe99409..4d8cff45a4d 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -91,7 +91,7 @@ func TestMsgService(t *testing.T) { var ( appBuilder *runtime.AppBuilder - cdc codec.ProtoCodecMarshaler + cdc codec.Codec interfaceRegistry codectypes.InterfaceRegistry ) err := depinject.Inject( diff --git a/client/tx/factory.go b/client/tx/factory.go index 52e3abf0420..f21d861f3bb 100644 --- a/client/tx/factory.go +++ b/client/tx/factory.go @@ -298,10 +298,10 @@ func (f Factory) WithExtensionOptions(extOpts ...*codectypes.Any) Factory { func (f Factory) BuildUnsignedTx(msgs ...sdk.Msg) (client.TxBuilder, error) { if f.offline && f.generateOnly { if f.chainID != "" { - return nil, fmt.Errorf("chain ID cannot be used when offline and generate-only flags are set") + return nil, errors.New("chain ID cannot be used when offline and generate-only flags are set") } } else if f.chainID == "" { - return nil, fmt.Errorf("chain ID required but not specified") + return nil, errors.New("chain ID required but not specified") } fees := f.fees @@ -379,7 +379,12 @@ func (f Factory) PrintUnsignedTx(clientCtx client.Context, msgs ...sdk.Msg) erro return err } - json, err := clientCtx.TxConfig.TxJSONEncoder()(unsignedTx.GetTx()) + encoder := f.txConfig.TxJSONEncoder() + if encoder == nil { + return errors.New("cannot print unsigned tx: tx json encoder is nil") + } + + json, err := encoder(unsignedTx.GetTx()) if err != nil { return err } diff --git a/client/tx/tx.go b/client/tx/tx.go index c3b678b6392..b7c66536235 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -100,7 +100,12 @@ func BroadcastTx(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error { } if !clientCtx.SkipConfirm { - txBytes, err := clientCtx.TxConfig.TxJSONEncoder()(tx.GetTx()) + encoder := txf.txConfig.TxJSONEncoder() + if encoder == nil { + return errors.New("failed to encode transaction: tx json encoder is nil") + } + + txBytes, err := encoder(tx.GetTx()) if err != nil { return err } diff --git a/codec/proto_codec.go b/codec/proto_codec.go index ea8f2e2593e..26259cf06f7 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -23,9 +23,9 @@ import ( // ProtoCodecMarshaler defines an interface for codecs that utilize Protobuf for both // binary and JSON encoding. +// Deprecated: Use Codec instead. type ProtoCodecMarshaler interface { Codec - InterfaceRegistry() types.InterfaceRegistry } // ProtoCodec defines a codec that utilizes Protobuf for both binary and JSON @@ -34,10 +34,7 @@ type ProtoCodec struct { interfaceRegistry types.InterfaceRegistry } -var ( - _ Codec = &ProtoCodec{} - _ ProtoCodecMarshaler = &ProtoCodec{} -) +var _ Codec = (*ProtoCodec)(nil) // NewProtoCodec returns a reference to a new ProtoCodec func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec { diff --git a/runtime/module.go b/runtime/module.go index 44b019f5809..4440b3b8a31 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -82,7 +82,6 @@ func ProvideApp(interfaceRegistry codectypes.InterfaceRegistry) ( codec.Codec, *codec.LegacyAmino, *AppBuilder, - codec.ProtoCodecMarshaler, *baseapp.MsgServiceRouter, appmodule.AppModule, protodesc.Resolver, @@ -116,7 +115,7 @@ func ProvideApp(interfaceRegistry codectypes.InterfaceRegistry) ( } appBuilder := &AppBuilder{app} - return cdc, amino, appBuilder, cdc, msgServiceRouter, appModule{app}, protoFiles, protoTypes, nil + return cdc, amino, appBuilder, msgServiceRouter, appModule{app}, protoFiles, protoTypes, nil } type AppInputs struct { diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 1f0a05f48dc..58b536cb6ce 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -22,7 +22,7 @@ type config struct { encoder sdk.TxEncoder jsonDecoder sdk.TxDecoder jsonEncoder sdk.TxEncoder - protoCodec codec.ProtoCodecMarshaler + protoCodec codec.Codec signingContext *txsigning.Context } @@ -73,7 +73,7 @@ var DefaultSignModes = []signingtypes.SignMode{ // We prefer to use depinject to provide client.TxConfig, but we permit this constructor usage. Within the SDK, // this constructor is primarily used in tests, but also sees usage in app chains like: // https://github.com/evmos/evmos/blob/719363fbb92ff3ea9649694bd088e4c6fe9c195f/encoding/config.go#L37 -func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode, +func NewTxConfig(protoCodec codec.Codec, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler, ) client.TxConfig { txConfig, err := NewTxConfigWithOptions(protoCodec, ConfigOptions{ @@ -165,9 +165,13 @@ func NewSigningHandlerMap(configOptions ConfigOptions) (*txsigning.HandlerMap, e // NewTxConfigWithOptions returns a new protobuf TxConfig using the provided ProtoCodec, ConfigOptions and // custom sign mode handlers. If ConfigOptions is an empty struct then default values will be used. -func NewTxConfigWithOptions(protoCodec codec.ProtoCodecMarshaler, configOptions ConfigOptions) (client.TxConfig, error) { +func NewTxConfigWithOptions(protoCodec codec.Codec, configOptions ConfigOptions) (client.TxConfig, error) { txConfig := &config{ - protoCodec: protoCodec, + protoCodec: protoCodec, + decoder: configOptions.ProtoDecoder, + encoder: configOptions.ProtoEncoder, + jsonDecoder: configOptions.JSONDecoder, + jsonEncoder: configOptions.JSONEncoder, } if configOptions.ProtoDecoder == nil { txConfig.decoder = DefaultTxDecoder(protoCodec) diff --git a/x/auth/tx/config/config.go b/x/auth/tx/config/config.go index 6fb7dba5014..7759530a28b 100644 --- a/x/auth/tx/config/config.go +++ b/x/auth/tx/config/config.go @@ -42,7 +42,7 @@ type ModuleInputs struct { Config *txconfigv1.Config AddressCodec address.Codec ValidatorAddressCodec runtime.ValidatorAddressCodec - ProtoCodecMarshaler codec.ProtoCodecMarshaler + Codec codec.Codec ProtoFileResolver txsigning.ProtoFileResolver // BankKeeper is the expected bank keeper to be passed to AnteHandlers BankKeeper authtypes.BankKeeper `optional:"true"` @@ -86,7 +86,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { txConfigOptions.TextualCoinMetadataQueryFn = NewBankKeeperCoinMetadataQueryFn(in.MetadataBankKeeper) } - txConfig, err := tx.NewTxConfigWithOptions(in.ProtoCodecMarshaler, txConfigOptions) + txConfig, err := tx.NewTxConfigWithOptions(in.Codec, txConfigOptions) if err != nil { panic(err) } diff --git a/x/auth/tx/decoder.go b/x/auth/tx/decoder.go index 16253a4ba15..d74c7f20659 100644 --- a/x/auth/tx/decoder.go +++ b/x/auth/tx/decoder.go @@ -15,7 +15,7 @@ import ( ) // DefaultTxDecoder returns a default protobuf TxDecoder using the provided Marshaler. -func DefaultTxDecoder(cdc codec.ProtoCodecMarshaler) sdk.TxDecoder { +func DefaultTxDecoder(cdc codec.Codec) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { // Make sure txBytes follow ADR-027. err := rejectNonADR027TxRaw(txBytes) @@ -79,7 +79,7 @@ func DefaultTxDecoder(cdc codec.ProtoCodecMarshaler) sdk.TxDecoder { } // DefaultJSONTxDecoder returns a default protobuf JSON TxDecoder using the provided Marshaler. -func DefaultJSONTxDecoder(cdc codec.ProtoCodecMarshaler) sdk.TxDecoder { +func DefaultJSONTxDecoder(cdc codec.Codec) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { var theTx tx.Tx err := cdc.UnmarshalJSON(txBytes, &theTx) diff --git a/x/auth/tx/encoder.go b/x/auth/tx/encoder.go index e98106a89a8..fc60b6a04e0 100644 --- a/x/auth/tx/encoder.go +++ b/x/auth/tx/encoder.go @@ -29,7 +29,7 @@ func DefaultTxEncoder() sdk.TxEncoder { } // DefaultJSONTxEncoder returns a default protobuf JSON TxEncoder using the provided Marshaler. -func DefaultJSONTxEncoder(cdc codec.ProtoCodecMarshaler) sdk.TxEncoder { +func DefaultJSONTxEncoder(cdc codec.Codec) sdk.TxEncoder { return func(tx sdk.Tx) ([]byte, error) { txWrapper, ok := tx.(*wrapper) if ok {