Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed Apr 21, 2023
1 parent 2cc424f commit b4aeece
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
21 changes: 4 additions & 17 deletions x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import (

errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
"cosmossdk.io/x/tx/decode"
txsigning "cosmossdk.io/x/tx/signing"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/registry"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
Expand Down Expand Up @@ -300,22 +298,11 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
Value: anyPk.Value,
},
}
decodeCtx, err := decode.NewDecoder(decode.Options{ProtoFiles: registry.MergedProtoRegistry()})
if err != nil {
return ctx, err
}
// note: this is performance hit is temporary. Ultimately, the tx will be decoded once in BaseApp,
// but for now we need double decoding to support both SignModeHandlers.
decodedTx, err := decodeCtx.Decode(ctx.TxBytes())
if err != nil {
return ctx, err
}
txData := txsigning.TxData{
Body: decodedTx.Tx.Body,
AuthInfo: decodedTx.Tx.AuthInfo,
AuthInfoBytes: decodedTx.TxRaw.AuthInfoBytes,
BodyBytes: decodedTx.TxRaw.BodyBytes,
adaptableTx, ok := tx.(authsigning.V2AdaptableTx)
if !ok {
return ctx, fmt.Errorf("expected tx to implement V2AdaptableTx, got %T", tx)
}
txData := authsigning.AdapterToTxData(adaptableTx)
err = authsigning.VerifySignature(ctx, pubKey, signerData, sig.Data, svd.signModeHandler, txData)
if err != nil {
var errMsg string
Expand Down
11 changes: 8 additions & 3 deletions x/auth/tx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signin
customSignModes ...txsigning.SignModeHandler,
) client.TxConfig {
typeResolver := protoregistry.GlobalTypes
signingContext := protoCodec.InterfaceRegistry().SigningContext()
protoFiles := protoCodec.InterfaceRegistry()
signersContext, err := txsigning.NewGetSignersContext(txsigning.GetSignersOptions{ProtoFiles: protoFiles})
if err != nil {
panic(err)
}

signModeOptions := &SignModeOptions{}
for _, m := range enabledSignModes {
Expand All @@ -49,13 +53,14 @@ func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signin
signModeOptions.Direct = &direct.SignModeHandler{}
case signingtypes.SignMode_SIGN_MODE_DIRECT_AUX:
signModeOptions.DirectAux = &directaux.SignModeHandlerOptions{
FileResolver: protoFiles,
TypeResolver: typeResolver,
SignersContext: signingContext,
SignersContext: signersContext,
}
case signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON:
aminoJSONEncoder := aminojson.NewAminoJSON()
signModeOptions.AminoJSON = &aminojson.SignModeHandlerOptions{
FileResolver: protoCodec.InterfaceRegistry(),
FileResolver: protoFiles,
TypeResolver: typeResolver,
Encoder: &aminoJSONEncoder,
}
Expand Down

0 comments on commit b4aeece

Please sign in to comment.