Update codec
This commit is contained in:
parent
8f131e2e0c
commit
081e62cb2d
|
@ -5,7 +5,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
|
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EvidenceCodec defines the interface required to serialize evidence
|
// Codec defines the interface required to serialize evidence
|
||||||
type Codec interface {
|
type Codec interface {
|
||||||
codec.Marshaler
|
codec.Marshaler
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Codec defines the interface required to serialize custom x/gov types.
|
||||||
type Codec interface {
|
type Codec interface {
|
||||||
codec.Marshaler
|
codec.Marshaler
|
||||||
|
|
||||||
|
@ -11,48 +12,39 @@ type Codec interface {
|
||||||
UnmarshalProposal(bz []byte, ptr *Proposal) error
|
UnmarshalProposal(bz []byte, ptr *Proposal) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// module codec
|
// RegisterCodec registers all the necessary types and interfaces for the
|
||||||
var ModuleCdc = codec.New()
|
// governance module.
|
||||||
|
|
||||||
// RegisterCodec registers all the necessary types and interfaces for
|
|
||||||
// governance.
|
|
||||||
func RegisterCodec(cdc *codec.Codec) {
|
func RegisterCodec(cdc *codec.Codec) {
|
||||||
cdc.RegisterInterface((*Content)(nil), nil)
|
cdc.RegisterInterface((*Content)(nil), nil)
|
||||||
|
|
||||||
cdc.RegisterConcrete(MsgSubmitProposal{}, "cosmos-sdk/MsgSubmitProposal", nil)
|
cdc.RegisterConcrete(MsgSubmitProposal{}, "cosmos-sdk/MsgSubmitProposal", nil)
|
||||||
cdc.RegisterConcrete(MsgDeposit{}, "cosmos-sdk/MsgDeposit", nil)
|
cdc.RegisterConcrete(MsgDeposit{}, "cosmos-sdk/MsgDeposit", nil)
|
||||||
cdc.RegisterConcrete(MsgVote{}, "cosmos-sdk/MsgVote", nil)
|
cdc.RegisterConcrete(MsgVote{}, "cosmos-sdk/MsgVote", nil)
|
||||||
|
|
||||||
cdc.RegisterConcrete(TextProposal{}, "cosmos-sdk/TextProposal", nil)
|
cdc.RegisterConcrete(TextProposal{}, "cosmos-sdk/TextProposal", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterProposalTypeCodec registers an external proposal content type defined
|
// RegisterProposalTypeCodec registers an external proposal content type defined
|
||||||
// in another module for the internal ModuleCdc. This allows the MsgSubmitProposal
|
// in another module for the internal ModuleCdc. This allows the MsgSubmitProposal
|
||||||
// to be correctly Amino encoded and decoded.
|
// to be correctly Amino encoded and decoded.
|
||||||
|
//
|
||||||
|
// NOTE: This should only be used for applications that are still using a concrete
|
||||||
|
// Amino codec for serialization.
|
||||||
func RegisterProposalTypeCodec(o interface{}, name string) {
|
func RegisterProposalTypeCodec(o interface{}, name string) {
|
||||||
ModuleCdc.RegisterConcrete(o, name, nil)
|
amino.RegisterConcrete(o, name, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO determine a good place to seal this codec
|
var (
|
||||||
|
amino = codec.New()
|
||||||
|
|
||||||
|
// ModuleCdc references the global x/gov module codec. Note, the codec should
|
||||||
|
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
|
||||||
|
// still used for that purpose.
|
||||||
|
//
|
||||||
|
// The actual codec used for serialization should be provided to x/gov and
|
||||||
|
// defined at the application level.
|
||||||
|
ModuleCdc = codec.NewHybridCodec(amino)
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterCodec(ModuleCdc)
|
RegisterCodec(amino)
|
||||||
|
codec.RegisterCrypto(amino)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AminoGovCodec struct {
|
|
||||||
codec.Marshaler
|
|
||||||
amino *codec.Codec
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAminoGovCodec(amino *codec.Codec) AminoGovCodec {
|
|
||||||
return AminoGovCodec{Marshaler: codec.NewHybridCodec(amino), amino: amino}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AminoGovCodec) MarshalProposal(p Proposal) ([]byte, error) {
|
|
||||||
return a.amino.MarshalBinaryBare(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AminoGovCodec) UnmarshalProposal(bz []byte, ptr *Proposal) error {
|
|
||||||
return a.amino.UnmarshalBinaryBare(bz, ptr)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ Codec = AminoGovCodec{}
|
|
||||||
|
|
Loading…
Reference in New Issue