Wrap ProtoCodec in interface (#7637)
* WIP encoding change * Add test that describes issue * WIP debugging * remove extra code * Update codec/proto_codec.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
This commit is contained in:
parent
48c72230f0
commit
9befc6ced8
@ -11,6 +11,13 @@ import (
|
||||
"github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
// ProtoCodecMarshaler defines an interface for codecs that utilize Protobuf for both
|
||||
// binary and JSON encoding.
|
||||
type ProtoCodecMarshaler interface {
|
||||
Marshaler
|
||||
InterfaceRegistry() types.InterfaceRegistry
|
||||
}
|
||||
|
||||
// ProtoCodec defines a codec that utilizes Protobuf for both binary and JSON
|
||||
// encoding.
|
||||
type ProtoCodec struct {
|
||||
@ -18,6 +25,7 @@ type ProtoCodec struct {
|
||||
}
|
||||
|
||||
var _ Marshaler = &ProtoCodec{}
|
||||
var _ ProtoCodecMarshaler = &ProtoCodec{}
|
||||
|
||||
// NewProtoCodec returns a reference to a new ProtoCodec
|
||||
func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec {
|
||||
|
||||
@ -18,12 +18,12 @@ type config struct {
|
||||
encoder sdk.TxEncoder
|
||||
jsonDecoder sdk.TxDecoder
|
||||
jsonEncoder sdk.TxEncoder
|
||||
protoCodec *codec.ProtoCodec
|
||||
protoCodec codec.ProtoCodecMarshaler
|
||||
}
|
||||
|
||||
// NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and sign modes. The
|
||||
// first enabled sign mode will become the default sign mode.
|
||||
func NewTxConfig(protoCodec *codec.ProtoCodec, enabledSignModes []signingtypes.SignMode) client.TxConfig {
|
||||
func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode) client.TxConfig {
|
||||
return &config{
|
||||
handler: makeSignModeHandler(enabledSignModes),
|
||||
decoder: DefaultTxDecoder(protoCodec),
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// DefaultTxDecoder returns a default protobuf TxDecoder using the provided Marshaler.
|
||||
func DefaultTxDecoder(cdc *codec.ProtoCodec) sdk.TxDecoder {
|
||||
func DefaultTxDecoder(cdc codec.ProtoCodecMarshaler) sdk.TxDecoder {
|
||||
return func(txBytes []byte) (sdk.Tx, error) {
|
||||
var raw tx.TxRaw
|
||||
|
||||
@ -66,7 +66,7 @@ func DefaultTxDecoder(cdc *codec.ProtoCodec) sdk.TxDecoder {
|
||||
}
|
||||
|
||||
// DefaultJSONTxDecoder returns a default protobuf JSON TxDecoder using the provided Marshaler.
|
||||
func DefaultJSONTxDecoder(cdc *codec.ProtoCodec) sdk.TxDecoder {
|
||||
func DefaultJSONTxDecoder(cdc codec.ProtoCodecMarshaler) sdk.TxDecoder {
|
||||
return func(txBytes []byte) (sdk.Tx, error) {
|
||||
var theTx tx.Tx
|
||||
err := cdc.UnmarshalJSON(txBytes, &theTx)
|
||||
|
||||
@ -29,7 +29,7 @@ func DefaultTxEncoder() sdk.TxEncoder {
|
||||
}
|
||||
|
||||
// DefaultJSONTxEncoder returns a default protobuf JSON TxEncoder using the provided Marshaler.
|
||||
func DefaultJSONTxEncoder(cdc *codec.ProtoCodec) sdk.TxEncoder {
|
||||
func DefaultJSONTxEncoder(cdc codec.ProtoCodecMarshaler) sdk.TxEncoder {
|
||||
return func(tx sdk.Tx) ([]byte, error) {
|
||||
txWrapper, ok := tx.(*wrapper)
|
||||
if ok {
|
||||
|
||||
@ -39,7 +39,7 @@ var (
|
||||
// SubModuleCdc references the global x/ibc/core/03-connection module codec. Note, the codec should
|
||||
// ONLY be used in certain instances of tests and for JSON encoding.
|
||||
//
|
||||
// The actual codec used for serialization should be provided to x/ibc/core/03-connectionl and
|
||||
// The actual codec used for serialization should be provided to x/ibc/core/03-connection and
|
||||
// defined at the application level.
|
||||
SubModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user