refactor(x/tx): use dynamicpb instead of type resolver in any marshal (#16048)

Co-authored-by: Aaron Craelius <aaron@regen.network>
This commit is contained in:
Matt Kocubinski
2023-05-08 19:20:23 +00:00
committed by GitHub
co-authored by Aaron Craelius
parent 12923c33ed
commit 2f21cb5050
17 changed files with 181 additions and 49 deletions
+9 -5
View File
@@ -2,14 +2,15 @@ package simulation
import (
"encoding/json"
"fmt"
"math/rand"
"time"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
)
// Deprecated: Use WeightedProposalMsg instead.
@@ -94,12 +95,15 @@ func NewOperationMsg(msg sdk.Msg, ok bool, comment string, cdc *codec.ProtoCodec
if moduleName == "" {
moduleName = msgType
}
if legacyMsg, okType := msg.(legacytx.LegacyMsg); okType {
return NewOperationMsgBasic(moduleName, msgType, comment, ok, legacyMsg.GetSignBytes())
if cdc == nil {
cdc = codec.NewProtoCodec(types.NewInterfaceRegistry())
}
jsonBytes, err := cdc.MarshalAminoJSON(msg)
if err != nil {
panic(fmt.Errorf("failed to marshal aminon JSON: %w", err))
}
return NewOperationMsgBasic(moduleName, msgType, comment, ok, cdc.MustMarshalJSON(msg))
return NewOperationMsgBasic(moduleName, msgType, comment, ok, jsonBytes)
}
// NoOpMsg - create a no-operation message