Skip to content

Commit

Permalink
Add aliased types from gogoproto
Browse files Browse the repository at this point in the history
  • Loading branch information
raynaudoe committed Mar 28, 2024
1 parent 50271e5 commit 3e3106b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
9 changes: 4 additions & 5 deletions codec/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"io"

cmttypes "github.com/cometbft/cometbft/types"
gogoprototypes "github.com/cosmos/gogoproto/types/any"
amino "github.com/tendermint/go-amino"

"github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -62,19 +61,19 @@ func MustMarshalJSONIndent(cdc *LegacyAmino, obj interface{}) []byte {
}

func (cdc *LegacyAmino) marshalAnys(o interface{}) error {
return types.UnpackInterfaces(o, gogoprototypes.AminoPacker{Cdc: cdc.Amino})
return types.UnpackInterfaces(o, types.AminoPacker{Cdc: cdc.Amino})
}

func (cdc *LegacyAmino) unmarshalAnys(o interface{}) error {
return types.UnpackInterfaces(o, gogoprototypes.AminoUnpacker{Cdc: cdc.Amino})
return types.UnpackInterfaces(o, types.AminoUnpacker{Cdc: cdc.Amino})
}

func (cdc *LegacyAmino) jsonMarshalAnys(o interface{}) error {
return types.UnpackInterfaces(o, gogoprototypes.AminoJSONPacker{Cdc: cdc.Amino})
return types.UnpackInterfaces(o, types.AminoJSONPacker{Cdc: cdc.Amino})
}

func (cdc *LegacyAmino) jsonUnmarshalAnys(o interface{}) error {
return types.UnpackInterfaces(o, gogoprototypes.AminoJSONUnpacker{Cdc: cdc.Amino})
return types.UnpackInterfaces(o, types.AminoJSONUnpacker{Cdc: cdc.Amino})
}

func (cdc *LegacyAmino) Marshal(o interface{}) ([]byte, error) {
Expand Down
3 changes: 1 addition & 2 deletions codec/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/cosmos/gogoproto/jsonpb"
"github.com/cosmos/gogoproto/proto"
gogoprototypes "github.com/cosmos/gogoproto/types/any"

"github.com/cosmos/cosmos-sdk/codec/types"
)
Expand All @@ -21,7 +20,7 @@ func ProtoMarshalJSON(msg proto.Message, resolver jsonpb.AnyResolver) ([]byte, e
if resolver != nil {
jm = &jsonpb.Marshaler{OrigName: true, EmitDefaults: true, AnyResolver: resolver}
}
err := types.UnpackInterfaces(msg, gogoprototypes.ProtoJSONPacker{JSONPBMarshaler: jm})
err := types.UnpackInterfaces(msg, types.ProtoJSONPacker{JSONPBMarshaler: jm})
if err != nil {
return nil, err
}
Expand Down
28 changes: 28 additions & 0 deletions codec/types/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,36 @@ import (
gogoproto "github.com/cosmos/gogoproto/types/any"
)

// Any is an alias for gogoproto.Any. It represents a protocol buffer message
// that can contain any arbitrary data. This is used for encoding and decoding
// unknown or dynamic content in a type-safe manner.
type Any = gogoproto.Any

// AminoPacker is an alias for gogoproto.AminoPacker. It provides functionality
// for packing and unpacking data using the Amino encoding.
type AminoPacker = gogoproto.AminoPacker

// AminoUnpacker is an alias for gogoproto.AminoUnpacker. It is used for
// unpacking Amino-encoded data into Go types.
type AminoUnpacker = gogoproto.AminoUnpacker

// AminoJSONPacker is an alias for gogoproto.AminoJSONPacker. It allows for
// packing data into a JSON format using Amino encoding rules.
type AminoJSONPacker = gogoproto.AminoJSONPacker

// AminoJSONUnpacker is an alias for gogoproto.AminoJSONUnpacker. It provides
// the ability to unpack JSON data encoded with Amino encoding rules.
type AminoJSONUnpacker = gogoproto.AminoJSONUnpacker

// ProtoJSONPacker is an alias for gogoproto.ProtoJSONPacker. This is used for
// packing protocol buffer messages into a JSON format.
type ProtoJSONPacker = gogoproto.ProtoJSONPacker

// NewAnyWithValue is an alias for gogoproto.NewAnyWithCacheWithValue. This function
// creates a new Any instance containing the provided value, with caching
// mechanisms to improve performance.
var NewAnyWithValue = gogoproto.NewAnyWithCacheWithValue

// UnsafePackAny is an alias for gogoproto.UnsafePackAnyWithCache. This function
// packs a given message into an Any type without performing safety checks.
var UnsafePackAny = gogoproto.UnsafePackAnyWithCache

0 comments on commit 3e3106b

Please sign in to comment.