diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b4aefb7ee50..93a9209d68de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +* (tx) [#\11533](https://github.com/cosmos/cosmos-sdk/pull/11533) Register [`EIP191`](https://eips.ethereum.org/EIPS/eip-191) as an available `SignMode` for chains to use. * [\#11430](https://github.com/cosmos/cosmos-sdk/pull/11430) Introduce a new `grpc-only` flag, such that when enabled, will start the node in a query-only mode. Note, gRPC MUST be enabled with this flag. * (x/bank) [\#11417](https://github.com/cosmos/cosmos-sdk/pull/11417) Introduce a new `SpendableBalances` gRPC query that retrieves an account's total (paginated) spendable balances. * (x/bank) [\#10771](https://github.com/cosmos/cosmos-sdk/pull/10771) Add safety check on bank module perms to allow module-specific mint restrictions (e.g. only minting a certain denom). diff --git a/client/cmd.go b/client/cmd.go index 29c1552a5cb7..4b5f5570aa70 100644 --- a/client/cmd.go +++ b/client/cmd.go @@ -305,15 +305,8 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err clientCtx = clientCtx.WithSignModeStr(flags.SignModeLegacyAminoJSON) } } - - if !clientCtx.IsAux || flagSet.Changed(flags.FlagAux) { - isAux, _ := flagSet.GetBool(flags.FlagAux) - clientCtx = clientCtx.WithAux(isAux) - if isAux { - // If the user didn't explicitly set an --output flag, use JSON by default. - if clientCtx.OutputFormat == "" || !flagSet.Changed(flags.FlagOutput) { - clientCtx = clientCtx.WithOutputFormat(flags.OutputFormatJSON) - } + return clientCtx, nil +} // GetClientQueryContext returns a Context from a command with fields set based on flags // defined in AddQueryFlagsToCmd. An error is returned if any flag query fails. diff --git a/client/flags/flags.go b/client/flags/flags.go index 2e2eff3285b3..d13ede97a949 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -32,10 +32,6 @@ const ( SignModeDirect = "direct" // SignModeLegacyAminoJSON is the value of the --sign-mode flag for SIGN_MODE_LEGACY_AMINO_JSON SignModeLegacyAminoJSON = "amino-json" - // SignModeDirectAux is the value of the --sign-mode flag for SIGN_MODE_DIRECT_AUX - SignModeDirectAux = "direct-aux" - // SignModeTextual is the value of the --sign-mode flag for SIGN_MODE_TEXTUAL. - SignModeTextual = "textual" // SignModeEIP191 is the value of the --sign-mode flag for SIGN_MODE_EIP_191 SignModeEIP191 = "eip-191" ) diff --git a/client/tx/factory.go b/client/tx/factory.go index 7547e2ba58ff..5def5e93f6e8 100644 --- a/client/tx/factory.go +++ b/client/tx/factory.go @@ -63,24 +63,10 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) (Factory, e signMode = signing.SignMode_SIGN_MODE_DIRECT case flags.SignModeLegacyAminoJSON: signMode = signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON - case flags.SignModeDirectAux: - signMode = signing.SignMode_SIGN_MODE_DIRECT_AUX - case flags.SignModeTextual: - signMode = signing.SignMode_SIGN_MODE_TEXTUAL case flags.SignModeEIP191: signMode = signing.SignMode_SIGN_MODE_EIP_191 } - var accNum, accSeq uint64 - if clientCtx.Offline { - if flagSet.Changed(flags.FlagAccountNumber) && flagSet.Changed(flags.FlagSequence) { - accNum = clientCtx.Viper.GetUint64(flags.FlagAccountNumber) - accSeq = clientCtx.Viper.GetUint64(flags.FlagSequence) - } else { - return Factory{}, errors.New("account-number and sequence must be set in offline mode") - } - } - gasAdj := clientCtx.Viper.GetFloat64(flags.FlagGasAdjustment) memo := clientCtx.Viper.GetString(flags.FlagNote) timestampUnix := clientCtx.Viper.GetInt64(flags.FlagTimeoutTimestamp) diff --git a/proto/cosmos/tx/signing/v1beta1/signing.proto b/proto/cosmos/tx/signing/v1beta1/signing.proto index 73b199815a0f..9625234ce68f 100644 --- a/proto/cosmos/tx/signing/v1beta1/signing.proto +++ b/proto/cosmos/tx/signing/v1beta1/signing.proto @@ -43,7 +43,7 @@ enum SignMode { // SIGN_MODE_EIP_191 specifies the sign mode for EIP 191 signing on the Cosmos // SDK. Ref: https://eips.ethereum.org/EIPS/eip-191 - // + // // Currently, SIGN_MODE_EIP_191 is registered as a SignMode enum variant, // but is not implemented on the SDK by default. To enable EIP-191, you need // to pass a custom `TxConfig` that has an implementation of @@ -51,12 +51,7 @@ enum SignMode { // EIP-191 in the future. // // Since: cosmos-sdk 0.45.2 - // Deprecated: post 0.47.x Sign mode refers to a method of encoding string data for - // signing, but in the SDK, it also refers to how to encode a transaction into a string. - // This opens the possibility for additional EIP191 sign modes, like SIGN_MODE_EIP_191_TEXTUAL, - // SIGN_MODE_EIP_191_LEGACY_JSON, and more. - // Each new EIP191 sign mode should be accompanied by an associated ADR. - SIGN_MODE_EIP_191 = 191 [deprecated = true]; + SIGN_MODE_EIP_191 = 191; } // SignatureDescriptors wraps multiple SignatureDescriptor's. diff --git a/types/tx/signing/signing.pb.go b/types/tx/signing/signing.pb.go index 7cbf43670814..8e62fab6bf8c 100644 --- a/types/tx/signing/signing.pb.go +++ b/types/tx/signing/signing.pb.go @@ -59,19 +59,8 @@ const ( // SIGN_MODE_EIP_191 specifies the sign mode for EIP 191 signing on the Cosmos // SDK. Ref: https://eips.ethereum.org/EIPS/eip-191 // - // Currently, SIGN_MODE_EIP_191 is registered as a SignMode enum variant, - // but is not implemented on the SDK by default. To enable EIP-191, you need - // to pass a custom `TxConfig` that has an implementation of - // `SignModeHandler` for EIP-191. The SDK may decide to fully support - // EIP-191 in the future. - // - // Since: cosmos-sdk 0.45.2 - // Deprecated: post 0.47.x Sign mode refers to a method of encoding string data for - // signing, but in the SDK, it also refers to how to encode a transaction into a string. - // This opens the possibility for additional EIP191 sign modes, like SIGN_MODE_EIP_191_TEXTUAL, - // SIGN_MODE_EIP_191_LEGACY_JSON, and more. - // Each new EIP191 sign mode should be accompanied by an associated ADR. - SignMode_SIGN_MODE_EIP_191 SignMode = 191 // Deprecated: Do not use. + // Since: cosmos-sdk 0.45 + SignMode_SIGN_MODE_EIP_191 SignMode = 191 ) var SignMode_name = map[int32]string{ @@ -428,42 +417,42 @@ func init() { var fileDescriptor_9a54958ff3d0b1b9 = []byte{ // 573 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x86, 0xb3, 0x49, 0x5a, 0xa5, 0x53, 0x84, 0xcc, 0x92, 0x4a, 0xa9, 0x41, 0xa6, 0x2a, 0x07, - 0x2a, 0xa4, 0xae, 0x95, 0xf6, 0x80, 0xca, 0xcd, 0x4d, 0x4c, 0x6a, 0xda, 0xa4, 0xc5, 0x4e, 0xa5, - 0xc2, 0xc5, 0xb2, 0x9d, 0xad, 0xb1, 0x1a, 0x7b, 0x8d, 0x77, 0x8d, 0xea, 0x13, 0xaf, 0xc0, 0x6b, - 0xf4, 0x29, 0x38, 0x70, 0xe1, 0xd8, 0x23, 0x47, 0xd4, 0x3e, 0x03, 0x77, 0x54, 0x3b, 0x4e, 0x02, - 0x2a, 0x42, 0xf4, 0x64, 0xcd, 0xcc, 0xbf, 0xdf, 0xfc, 0xab, 0x99, 0x35, 0x3c, 0xf3, 0x18, 0x0f, - 0x19, 0x57, 0xc5, 0xb9, 0xca, 0x03, 0x3f, 0x0a, 0x22, 0x5f, 0xfd, 0xd8, 0x76, 0xa9, 0x70, 0xda, - 0x65, 0x4c, 0xe2, 0x84, 0x09, 0x86, 0x57, 0x0b, 0x21, 0x11, 0xe7, 0xa4, 0x2c, 0x4c, 0x84, 0xf2, - 0xe6, 0x84, 0xe1, 0x25, 0x59, 0x2c, 0x98, 0x1a, 0xa6, 0x63, 0x11, 0xf0, 0x60, 0x06, 0x2a, 0x13, - 0x05, 0x49, 0x5e, 0xf5, 0x19, 0xf3, 0xc7, 0x54, 0xcd, 0x23, 0x37, 0x3d, 0x55, 0x9d, 0x28, 0x2b, - 0x4a, 0xeb, 0xa7, 0xd0, 0xb4, 0x02, 0x3f, 0x72, 0x44, 0x9a,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 0xd4, 0x25, 0x1e, 0x0b, 0xd5, 0xf2, 0xe9, 0xe7, 0x9f, - 0x4d, 0x3e, 0x3a, 0x53, 0x45, 0x16, 0xd3, 0xf9, 0xff, 0x89, 0xbb, 0x98, 0x3f, 0x9c, 0xed, 0x5f, - 0x01, 0x00, 0x00, 0xff, 0xff, 0xd3, 0xe2, 0x52, 0x45, 0x6b, 0x04, 0x00, 0x00, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xc1, 0x6e, 0xd3, 0x4c, + 0x10, 0xc7, 0xed, 0x26, 0xad, 0xda, 0xe9, 0xa7, 0x4f, 0x66, 0x49, 0x51, 0x6a, 0x90, 0xa9, 0xca, + 0x81, 0x0a, 0xa9, 0x6b, 0xa5, 0x3d, 0xa0, 0x72, 0x73, 0x13, 0x93, 0x9a, 0x36, 0x69, 0xb1, 0x53, + 0xa9, 0x70, 0xb1, 0x6c, 0x67, 0x6b, 0xac, 0xc6, 0x5e, 0xe3, 0x5d, 0xa3, 0xfa, 0xc4, 0x2b, 0xf0, + 0x12, 0x1c, 0x78, 0x0a, 0x0e, 0x5c, 0x38, 0xf6, 0xc8, 0x11, 0x25, 0xcf, 0xc0, 0x1d, 0xc5, 0x8e, + 0x93, 0x80, 0x8a, 0x10, 0x39, 0x59, 0x33, 0xf3, 0xdf, 0xdf, 0xfc, 0x57, 0x33, 0x6b, 0x78, 0xec, + 0x51, 0x16, 0x52, 0xa6, 0xf2, 0x6b, 0x95, 0x05, 0x7e, 0x14, 0x44, 0xbe, 0xfa, 0xae, 0xe1, 0x12, + 0xee, 0x34, 0xca, 0x18, 0xc7, 0x09, 0xe5, 0x14, 0x6d, 0x16, 0x42, 0xcc, 0xaf, 0x71, 0x59, 0x98, + 0x08, 0xe5, 0xdd, 0x09, 0xc3, 0x4b, 0xb2, 0x98, 0x53, 0x35, 0x4c, 0x07, 0x3c, 0x60, 0xc1, 0x0c, + 0x54, 0x26,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 0x88, + 0x37, 0x43, 0x45, 0xfc, 0x3e, 0x54, 0xc4, 0x0f, 0x23, 0x45, 0xb8, 0x19, 0x29, 0xc2, 0xb7, 0x91, + 0x22, 0xbc, 0xde, 0xf5, 0x03, 0xfe, 0x26, 0x75, 0xb1, 0x47, 0x43, 0xb5, 0x7c, 0xf6, 0xf9, 0x67, + 0x97, 0xf5, 0xaf, 0x54, 0x9e, 0xc5, 0x64, 0xfe, 0x5f, 0xe2, 0xae, 0xe4, 0x8f, 0x66, 0xff, 0x67, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x02, 0x3d, 0xad, 0x03, 0x67, 0x04, 0x00, 0x00, } func (m *SignatureDescriptors) Marshal() (dAtA []byte, err error) { diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 24cec22034cd..8f777f0ff212 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -69,105 +69,20 @@ var DefaultSignModes = []signingtypes.SignMode{ // NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and sign modes. The // first enabled sign mode will become the default sign mode. -// -// NOTE: Use NewTxConfigWithOptions to provide a custom signing handler in case the sign mode -// is not supported by default (eg: SignMode_SIGN_MODE_EIP_191), or to enable SIGN_MODE_TEXTUAL. -// -// 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.Codec, addressCodec, validatorAddressCodec address.Codec, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler, -) client.TxConfig { - txConfig, err := NewTxConfigWithOptions(protoCodec, ConfigOptions{ - EnabledSignModes: enabledSignModes, - CustomSignModes: customSignModes, - SigningOptions: &txsigning.Options{ - AddressCodec: addressCodec, - ValidatorAddressCodec: validatorAddressCodec, - }, - }) - if err != nil { - panic(err) - } - return txConfig -} - -// NewSigningOptions returns signing options used by x/tx. This includes account and -// validator address prefix enabled codecs. -func NewSigningOptions(addressCodec, validatorAddressCodec address.Codec) *txsigning.Options { - return &txsigning.Options{ - AddressCodec: addressCodec, - ValidatorAddressCodec: validatorAddressCodec, - } -} - -// NewSigningHandlerMap returns a new txsigning.HandlerMap using the provided ConfigOptions. -// It is recommended to use types.InterfaceRegistry in the field ConfigOptions.FileResolver as shown in -// NewTxConfigWithOptions but this fn does not enforce it. -func NewSigningHandlerMap(configOpts ConfigOptions) (*txsigning.HandlerMap, error) { - var err error - if configOpts.SigningOptions == nil { - return nil, errors.New("signing options not provided") - } - if configOpts.SigningContext == nil { - configOpts.SigningContext, err = txsigning.NewContext(*configOpts.SigningOptions) - if err != nil { - return nil, err - } - } - - signingOpts := configOpts.SigningOptions - - if len(configOpts.EnabledSignModes) == 0 { - configOpts.EnabledSignModes = DefaultSignModes - } - - lenSignModes := len(configOpts.EnabledSignModes) - handlers := make([]txsigning.SignModeHandler, lenSignModes+len(configOpts.CustomSignModes)) - for i, m := range configOpts.EnabledSignModes { - var err error - switch m { - case signingtypes.SignMode_SIGN_MODE_DIRECT: - handlers[i] = &direct.SignModeHandler{} - case signingtypes.SignMode_SIGN_MODE_DIRECT_AUX: - handlers[i], err = directaux.NewSignModeHandler(directaux.SignModeHandlerOptions{ - TypeResolver: signingOpts.TypeResolver, - SignersContext: configOpts.SigningContext, - }) - if err != nil { - return nil, err - } - case signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: - handlers[i] = aminojson.NewSignModeHandler(aminojson.SignModeHandlerOptions{ - FileResolver: signingOpts.FileResolver, - TypeResolver: signingOpts.TypeResolver, - }) - case signingtypes.SignMode_SIGN_MODE_TEXTUAL: - handlers[i], err = textual.NewSignModeHandler(textual.SignModeOptions{ - CoinMetadataQuerier: configOpts.TextualCoinMetadataQueryFn, - FileResolver: signingOpts.FileResolver, - TypeResolver: signingOpts.TypeResolver, - }) - if configOpts.TextualCoinMetadataQueryFn == nil { - return nil, errors.New("cannot enable SIGN_MODE_TEXTUAL without a TextualCoinMetadataQueryFn") - } - if err != nil { - return nil, err - } - } - } - for i, m := range configOpts.CustomSignModes { - handlers[i+lenSignModes] = m - } - - handler := txsigning.NewHandlerMap(handlers...) - return handler, nil -} - -// 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.Codec, configOptions ConfigOptions) (client.TxConfig, error) { - txConfig := &config{ +// NOTE: Use NewTxConfigWithHandler to provide a custom signing handler in case the sign mode +// is not supported by default (eg: SignMode_SIGN_MODE_EIP_191). +func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode) client.TxConfig { + return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes)) +} + +// NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and signing handler. +func NewTxConfigWithHandler(protoCodec codec.ProtoCodecMarshaler, handler signing.SignModeHandler) client.TxConfig { + return &config{ + handler: handler, + decoder: DefaultTxDecoder(protoCodec), + encoder: DefaultTxEncoder(), + jsonDecoder: DefaultJSONTxDecoder(protoCodec), + jsonEncoder: DefaultJSONTxEncoder(protoCodec), protoCodec: protoCodec, decoder: configOptions.ProtoDecoder, encoder: configOptions.ProtoEncoder,