From a6b0924ff59590d9be89dcabb38f68033b96a39a Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 10 Jan 2025 05:50:05 -0600 Subject: [PATCH] refactor(x/auth/tx): Provide DefaultTxDecoder (#23318) --- x/auth/tx/config.go | 27 ++++++++------------------- x/auth/tx/decoder.go | 11 +++++++++++ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 9b10f645a621..42a0760d9781 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -189,16 +189,15 @@ func NewTxConfigWithOptions(protoCodec codec.Codec, configOptions ConfigOptions) } } + txConfig.txDecoder, err = txdecode.NewDecoder(txdecode.Options{ + SigningContext: configOptions.SigningContext, + ProtoCodec: protoCodec, + }) + if err != nil { + return nil, err + } if configOptions.ProtoDecoder == nil { - dec, err := txdecode.NewDecoder(txdecode.Options{ - SigningContext: configOptions.SigningContext, - ProtoCodec: protoCodec, - }) - if err != nil { - return nil, err - } - txConfig.decoder = txV2toInterface(configOptions.SigningOptions.AddressCodec, protoCodec, dec) - txConfig.txDecoder = dec + txConfig.decoder = DefaultTxDecoder(configOptions.SigningOptions.AddressCodec, protoCodec, txConfig.txDecoder) } if configOptions.ProtoEncoder == nil { txConfig.encoder = DefaultTxEncoder() @@ -262,13 +261,3 @@ func (g config) TxJSONDecoder() sdk.TxDecoder { func (g config) SigningContext() *txsigning.Context { return g.signingContext } - -func txV2toInterface(addrCodec address.Codec, cdc codec.BinaryCodec, decoder *txdecode.Decoder) func([]byte) (sdk.Tx, error) { - return func(txBytes []byte) (sdk.Tx, error) { - decodedTx, err := decoder.Decode(txBytes) - if err != nil { - return nil, err - } - return newWrapperFromDecodedTx(addrCodec, cdc, decodedTx) - } -} diff --git a/x/auth/tx/decoder.go b/x/auth/tx/decoder.go index 74b20621690b..93474a6bb5b7 100644 --- a/x/auth/tx/decoder.go +++ b/x/auth/tx/decoder.go @@ -14,6 +14,17 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx" ) +// DefaultTxDecoder returns a default protobuf TxDecoder. +func DefaultTxDecoder(addrCodec address.Codec, cdc codec.BinaryCodec, decoder *decode.Decoder) func([]byte) (sdk.Tx, error) { + return func(txBytes []byte) (sdk.Tx, error) { + decodedTx, err := decoder.Decode(txBytes) + if err != nil { + return nil, err + } + return newWrapperFromDecodedTx(addrCodec, cdc, decodedTx) + } +} + // DefaultJSONTxDecoder returns a default protobuf JSON TxDecoder using the provided Marshaler. func DefaultJSONTxDecoder(addrCodec address.Codec, cdc codec.Codec, decoder *decode.Decoder) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) {