fix(x/tx)!: unexpected cast of interface to concrete type in GetSignersContext (#15581)

This commit is contained in:
Aaron Craelius 2023-03-28 18:55:52 -04:00 committed by GitHub
parent a5ad307ae6
commit 0b0db0867c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 14 deletions

View File

@ -29,15 +29,22 @@ Ref: https://keepachangelog.com/en/1.0.0/
# Changelog
## [Unreleased]
## Unreleased
## API Breaking
### API Breaking
* [#15581](https://github.com/cosmos/cosmos-sdk/pull/15581) `GetSignersOptions` and `directaux.SignModeHandlerOptions` now
require a `signing.ProtoFileResolver` interface instead of `protodesc.Resolver`.
## v0.4.0
### API Breaking
* [#13793](https://github.com/cosmos/cosmos-sdk/pull/13793) `direct_aux.NewSignModeHandler` constructor function now returns an additional error argument.
* [#15278](https://github.com/cosmos/cosmos-sdk/pull/15278) Move `x/tx/{textual,aminojson}` into `x/tx/signing`.
* [#15302](https://github.com/cosmos/cosmos-sdk/pull/15302) `textual.NewSignModeHandler` now takes an options struct instead of a simple coin querier argument. It also returns an error.
## Improvements
### Improvements
* [#15302](https://github.com/cosmos/cosmos-sdk/pull/15302) Add support for a custom registry (e.g. gogo's MergedRegistry) to be plugged into SIGN_MODE_TEXTUAL.
* [#15557](https://github.com/cosmos/cosmos-sdk/pull/15557) Implement unknown field filtering.

View File

@ -6,25 +6,25 @@ import (
"github.com/cosmos/cosmos-proto/anyutil"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoregistry"
signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1"
"cosmossdk.io/x/tx/signing"
)
// SignModeHandler is the SIGN_MODE_DIRECT_AUX implementation of signing.SignModeHandler.
type SignModeHandler struct {
signersContext *signing.GetSignersContext
fileResolver protodesc.Resolver
fileResolver signing.ProtoFileResolver
typeResolver protoregistry.MessageTypeResolver
}
// SignModeHandlerOptions are the options for the SignModeHandler.
type SignModeHandlerOptions struct {
// FileResolver is the protodesc.Resolver to use for resolving proto files when unpacking any messages.
FileResolver protodesc.Resolver
FileResolver signing.ProtoFileResolver
// TypeResolver is the protoregistry.MessageTypeResolver to use for resolving proto types when unpacking any messages.
TypeResolver protoregistry.MessageTypeResolver

View File

@ -17,7 +17,7 @@ import (
// message where signers are specified by the cosmos.msg.v1.signer protobuf
// option.
type GetSignersContext struct {
protoFiles protodesc.Resolver
protoFiles ProtoFileResolver
getSignersFuncs map[protoreflect.FullName]getSignersFunc
}
@ -25,7 +25,14 @@ type GetSignersContext struct {
type GetSignersOptions struct {
// ProtoFiles are the protobuf files to use for resolving message descriptors.
// If it is nil, the global protobuf registry will be used.
ProtoFiles protodesc.Resolver
ProtoFiles ProtoFileResolver
}
// ProtoFileResolver is a protodesc.Resolver that also allows iterating over all
// files descriptors. It is a subset of the methods supported by protoregistry.Files.
type ProtoFileResolver interface {
protodesc.Resolver
RangeFiles(func(protoreflect.FileDescriptor) bool)
}
// NewGetSignersContext creates a new GetSignersContext using the provided options.
@ -60,13 +67,8 @@ func getSignersFieldNames(descriptor protoreflect.MessageDescriptor) ([]string,
// - it will pre-populate the context's internal cache for getSignersFuncs
// so that calling it in antehandlers will be faster.
func (c *GetSignersContext) init() error {
fs, ok := c.protoFiles.(*protoregistry.Files)
if !ok {
return fmt.Errorf("expected *protoregistry.Files in GetSignersContext, got %T", c.protoFiles)
}
var errs []error
fs.RangeFiles(func(fd protoreflect.FileDescriptor) bool {
c.protoFiles.RangeFiles(func(fd protoreflect.FileDescriptor) bool {
for i := 0; i < fd.Services().Len(); i++ {
sd := fd.Services().Get(i)
// We use the heuristic that services named "Msg" are exactly the