2019-04-30 09:31:38 -07:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
)
|
|
|
|
|
2020-03-02 08:54:43 -08:00
|
|
|
// Codec defines the interface required to serialize custom x/gov types.
|
2020-02-17 11:21:07 -08:00
|
|
|
type Codec interface {
|
|
|
|
codec.Marshaler
|
|
|
|
|
2020-03-02 09:44:55 -08:00
|
|
|
MarshalProposal(Proposal) ([]byte, error)
|
|
|
|
UnmarshalProposal([]byte) (Proposal, error)
|
2020-02-17 11:21:07 -08:00
|
|
|
}
|
|
|
|
|
2020-03-02 08:54:43 -08:00
|
|
|
// RegisterCodec registers all the necessary types and interfaces for the
|
|
|
|
// governance module.
|
2019-04-30 09:31:38 -07:00
|
|
|
func RegisterCodec(cdc *codec.Codec) {
|
|
|
|
cdc.RegisterInterface((*Content)(nil), nil)
|
|
|
|
cdc.RegisterConcrete(MsgSubmitProposal{}, "cosmos-sdk/MsgSubmitProposal", nil)
|
|
|
|
cdc.RegisterConcrete(MsgDeposit{}, "cosmos-sdk/MsgDeposit", nil)
|
|
|
|
cdc.RegisterConcrete(MsgVote{}, "cosmos-sdk/MsgVote", nil)
|
|
|
|
cdc.RegisterConcrete(TextProposal{}, "cosmos-sdk/TextProposal", nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterProposalTypeCodec registers an external proposal content type defined
|
2019-05-16 08:25:32 -07:00
|
|
|
// in another module for the internal ModuleCdc. This allows the MsgSubmitProposal
|
2019-04-30 09:31:38 -07:00
|
|
|
// to be correctly Amino encoded and decoded.
|
2020-03-02 08:54:43 -08:00
|
|
|
//
|
|
|
|
// NOTE: This should only be used for applications that are still using a concrete
|
|
|
|
// Amino codec for serialization.
|
2019-04-30 09:31:38 -07:00
|
|
|
func RegisterProposalTypeCodec(o interface{}, name string) {
|
2020-03-02 08:54:43 -08:00
|
|
|
amino.RegisterConcrete(o, name, nil)
|
2020-01-28 13:30:28 -08:00
|
|
|
}
|
|
|
|
|
2020-03-02 08:54:43 -08:00
|
|
|
var (
|
|
|
|
amino = codec.New()
|
2020-01-28 13:30:28 -08:00
|
|
|
|
2020-03-02 08:54:43 -08:00
|
|
|
// 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)
|
|
|
|
)
|
2020-01-28 13:30:28 -08:00
|
|
|
|
2020-03-02 08:54:43 -08:00
|
|
|
func init() {
|
|
|
|
RegisterCodec(amino)
|
|
|
|
codec.RegisterCrypto(amino)
|
2020-01-28 13:30:28 -08:00
|
|
|
}
|