fix(x/auth): properly populate tx config options and deprecate ProtoCodecMarshaler (backport #17946) (#17952)

This commit is contained in:
mergify[bot] 2023-10-04 23:49:07 +02:00 committed by GitHub
parent 31e603ac8d
commit 3da9f9c9ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 31 additions and 23 deletions

View File

@ -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
)
@ -98,7 +97,6 @@ func TestBaseApp_BlockGas(t *testing.T) {
&interfaceRegistry,
&txConfig,
&cdc,
&pcdc,
&appBuilder)
require.NoError(t, err)

View File

@ -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(

View File

@ -289,10 +289,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
@ -370,7 +370,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
}

View File

@ -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
}

View File

@ -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 {

View File

@ -85,7 +85,6 @@ func ProvideApp(interfaceRegistry codectypes.InterfaceRegistry) (
codec.Codec,
*codec.LegacyAmino,
*AppBuilder,
codec.ProtoCodecMarshaler,
*baseapp.MsgServiceRouter,
appmodule.AppModule,
protodesc.Resolver,
@ -119,7 +118,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 {

View File

@ -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)

View File

@ -43,7 +43,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"`
@ -87,7 +87,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)
}

View File

@ -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)

View File

@ -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 {