Skip to content

Commit 9befc6c

Browse files
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>
1 parent 48c7223 commit 9befc6c

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

codec/proto_codec.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,21 @@ import (
1111
"github.com/gogo/protobuf/proto"
1212
)
1313

14+
// ProtoCodecMarshaler defines an interface for codecs that utilize Protobuf for both
15+
// binary and JSON encoding.
16+
type ProtoCodecMarshaler interface {
17+
Marshaler
18+
InterfaceRegistry() types.InterfaceRegistry
19+
}
20+
1421
// ProtoCodec defines a codec that utilizes Protobuf for both binary and JSON
1522
// encoding.
1623
type ProtoCodec struct {
1724
interfaceRegistry types.InterfaceRegistry
1825
}
1926

2027
var _ Marshaler = &ProtoCodec{}
28+
var _ ProtoCodecMarshaler = &ProtoCodec{}
2129

2230
// NewProtoCodec returns a reference to a new ProtoCodec
2331
func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec {

x/auth/tx/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ type config struct {
1818
encoder sdk.TxEncoder
1919
jsonDecoder sdk.TxDecoder
2020
jsonEncoder sdk.TxEncoder
21-
protoCodec *codec.ProtoCodec
21+
protoCodec codec.ProtoCodecMarshaler
2222
}
2323

2424
// NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and sign modes. The
2525
// first enabled sign mode will become the default sign mode.
26-
func NewTxConfig(protoCodec *codec.ProtoCodec, enabledSignModes []signingtypes.SignMode) client.TxConfig {
26+
func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode) client.TxConfig {
2727
return &config{
2828
handler: makeSignModeHandler(enabledSignModes),
2929
decoder: DefaultTxDecoder(protoCodec),

x/auth/tx/decoder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
// DefaultTxDecoder returns a default protobuf TxDecoder using the provided Marshaler.
12-
func DefaultTxDecoder(cdc *codec.ProtoCodec) sdk.TxDecoder {
12+
func DefaultTxDecoder(cdc codec.ProtoCodecMarshaler) sdk.TxDecoder {
1313
return func(txBytes []byte) (sdk.Tx, error) {
1414
var raw tx.TxRaw
1515

@@ -66,7 +66,7 @@ func DefaultTxDecoder(cdc *codec.ProtoCodec) sdk.TxDecoder {
6666
}
6767

6868
// DefaultJSONTxDecoder returns a default protobuf JSON TxDecoder using the provided Marshaler.
69-
func DefaultJSONTxDecoder(cdc *codec.ProtoCodec) sdk.TxDecoder {
69+
func DefaultJSONTxDecoder(cdc codec.ProtoCodecMarshaler) sdk.TxDecoder {
7070
return func(txBytes []byte) (sdk.Tx, error) {
7171
var theTx tx.Tx
7272
err := cdc.UnmarshalJSON(txBytes, &theTx)

x/auth/tx/encoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func DefaultTxEncoder() sdk.TxEncoder {
2929
}
3030

3131
// DefaultJSONTxEncoder returns a default protobuf JSON TxEncoder using the provided Marshaler.
32-
func DefaultJSONTxEncoder(cdc *codec.ProtoCodec) sdk.TxEncoder {
32+
func DefaultJSONTxEncoder(cdc codec.ProtoCodecMarshaler) sdk.TxEncoder {
3333
return func(tx sdk.Tx) ([]byte, error) {
3434
txWrapper, ok := tx.(*wrapper)
3535
if ok {

x/ibc/core/03-connection/types/codec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var (
3939
// SubModuleCdc references the global x/ibc/core/03-connection module codec. Note, the codec should
4040
// ONLY be used in certain instances of tests and for JSON encoding.
4141
//
42-
// The actual codec used for serialization should be provided to x/ibc/core/03-connectionl and
42+
// The actual codec used for serialization should be provided to x/ibc/core/03-connection and
4343
// defined at the application level.
4444
SubModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
4545
)

0 commit comments

Comments
 (0)