refactor(x/auth/tx): Provide DefaultTxDecoder (#23318)
This commit is contained in:
parent
8cc13ed2e2
commit
a6b0924ff5
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user