-
Notifications
You must be signed in to change notification settings - Fork 364
/
codec.go
117 lines (101 loc) · 4.57 KB
/
codec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package types
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
proposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
kavadisttypes "github.com/kava-labs/kava/x/kavadist/types"
)
var (
amino = codec.NewLegacyAmino()
// ModuleCdc references the global x/committee 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/committee and
// defined at the application level.
ModuleCdc = codec.NewAminoCodec(amino)
)
func init() {
RegisterLegacyAminoCodec(amino)
cryptocodec.RegisterCrypto(amino)
// amino is not sealed so that other modules can register their own pubproposal and/or permission types.
// Register external module pubproposal types. Ideally these would be registered within the modules' types pkg init function.
// However registration happens here as a work-around.
RegisterProposalTypeCodec(distrtypes.CommunityPoolSpendProposal{}, "cosmos-sdk/CommunityPoolSpendProposal")
RegisterProposalTypeCodec(proposaltypes.ParameterChangeProposal{}, "cosmos-sdk/ParameterChangeProposal")
RegisterProposalTypeCodec(govtypes.TextProposal{}, "cosmos-sdk/TextProposal")
RegisterProposalTypeCodec(upgradetypes.SoftwareUpgradeProposal{}, "cosmos-sdk/SoftwareUpgradeProposal")
RegisterProposalTypeCodec(upgradetypes.CancelSoftwareUpgradeProposal{}, "cosmos-sdk/CancelSoftwareUpgradeProposal")
}
// RegisterLegacyAminoCodec registers all the necessary types and interfaces for the module.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
// Proposals
cdc.RegisterInterface((*PubProposal)(nil), nil)
cdc.RegisterConcrete(CommitteeChangeProposal{}, "kava/CommitteeChangeProposal", nil)
cdc.RegisterConcrete(CommitteeDeleteProposal{}, "kava/CommitteeDeleteProposal", nil)
// Committees
cdc.RegisterInterface((*Committee)(nil), nil)
cdc.RegisterConcrete(BaseCommittee{}, "kava/BaseCommittee", nil)
cdc.RegisterConcrete(MemberCommittee{}, "kava/MemberCommittee", nil)
cdc.RegisterConcrete(TokenCommittee{}, "kava/TokenCommittee", nil)
// Permissions
cdc.RegisterInterface((*Permission)(nil), nil)
cdc.RegisterConcrete(GodPermission{}, "kava/GodPermission", nil)
cdc.RegisterConcrete(TextPermission{}, "kava/TextPermission", nil)
cdc.RegisterConcrete(SoftwareUpgradePermission{}, "kava/SoftwareUpgradePermission", nil)
cdc.RegisterConcrete(ParamsChangePermission{}, "kava/ParamsChangePermission", nil)
// Msgs
cdc.RegisterConcrete(&MsgSubmitProposal{}, "kava/MsgSubmitProposal", nil)
cdc.RegisterConcrete(&MsgVote{}, "kava/MsgVote", nil)
}
// RegisterProposalTypeCodec allows external modules to register their own pubproposal types on the
// internal ModuleCdc. This allows the MsgSubmitProposal to be correctly Amino encoded and decoded.
func RegisterProposalTypeCodec(o interface{}, name string) {
ModuleCdc.RegisterConcrete(o, name, nil)
}
func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgSubmitProposal{},
&MsgVote{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
registry.RegisterInterface(
"kava.committee.v1beta1.Committee",
(*Committee)(nil),
&BaseCommittee{},
&TokenCommittee{},
&MemberCommittee{},
)
registry.RegisterInterface(
"kava.committee.v1beta1.Permission",
(*Permission)(nil),
&GodPermission{},
&TextPermission{},
&SoftwareUpgradePermission{},
&ParamsChangePermission{},
)
// Need to register PubProposal here since we use this as alias for the x/gov Content interface for all the proposal implementations used in this module.
// Note that all proposals supported by x/committee needed to be registered here, including the proposals from x/gov.
registry.RegisterInterface(
"kava.committee.v1beta1.PubProposal",
(*PubProposal)(nil),
&Proposal{},
&distrtypes.CommunityPoolSpendProposal{},
&govtypes.TextProposal{},
&kavadisttypes.CommunityPoolMultiSpendProposal{},
&proposaltypes.ParameterChangeProposal{},
&upgradetypes.SoftwareUpgradeProposal{},
&upgradetypes.CancelSoftwareUpgradeProposal{},
)
registry.RegisterImplementations(
(*govtypes.Content)(nil),
&CommitteeChangeProposal{},
&CommitteeDeleteProposal{},
)
}