-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec.go
141 lines (123 loc) · 6.21 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package types
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"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"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
proposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
communitytypes "github.com/incubus-network/nemo/x/community/types"
nemodisttypes "github.com/incubus-network/nemo/x/nemodist/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 all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
RegisterLegacyAminoCodec(authzcodec.Amino)
// CommitteeChange/Delete proposals along with Permission types are
// registered on gov's ModuleCdc
RegisterLegacyAminoCodec(govv1beta1.ModuleCdc.LegacyAmino)
// 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(govv1beta1.TextProposal{}, "cosmos-sdk/TextProposal")
RegisterProposalTypeCodec(upgradetypes.SoftwareUpgradeProposal{}, "cosmos-sdk/SoftwareUpgradeProposal")
RegisterProposalTypeCodec(upgradetypes.CancelSoftwareUpgradeProposal{}, "cosmos-sdk/CancelSoftwareUpgradeProposal")
RegisterProposalTypeCodec(communitytypes.CommunityCDPRepayDebtProposal{}, "nemo/CommunityCDPRepayDebtProposal")
RegisterProposalTypeCodec(communitytypes.CommunityCDPWithdrawCollateralProposal{}, "nemo/CommunityCDPWithdrawCollateralProposal")
RegisterProposalTypeCodec(communitytypes.CommunityPoolLendWithdrawProposal{}, "nemo/CommunityPoolLendWithdrawProposal")
RegisterProposalTypeCodec(nemodisttypes.CommunityPoolMultiSpendProposal{}, "nemo/CommunityPoolMultiSpendProposal")
}
// 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{}, "nemo/CommitteeChangeProposal", nil)
cdc.RegisterConcrete(CommitteeDeleteProposal{}, "nemo/CommitteeDeleteProposal", nil)
// Committees
cdc.RegisterInterface((*Committee)(nil), nil)
cdc.RegisterConcrete(BaseCommittee{}, "nemo/BaseCommittee", nil)
cdc.RegisterConcrete(MemberCommittee{}, "nemo/MemberCommittee", nil)
cdc.RegisterConcrete(TokenCommittee{}, "nemo/TokenCommittee", nil)
// Permissions
cdc.RegisterInterface((*Permission)(nil), nil)
cdc.RegisterConcrete(GodPermission{}, "nemo/GodPermission", nil)
cdc.RegisterConcrete(TextPermission{}, "nemo/TextPermission", nil)
cdc.RegisterConcrete(SoftwareUpgradePermission{}, "nemo/SoftwareUpgradePermission", nil)
cdc.RegisterConcrete(ParamsChangePermission{}, "nemo/ParamsChangePermission", nil)
cdc.RegisterConcrete(CommunityCDPRepayDebtPermission{}, "nemo/CommunityCDPRepayDebtPermission", nil)
cdc.RegisterConcrete(CommunityCDPWithdrawCollateralPermission{}, "nemo/CommunityCDPWithdrawCollateralPermission", nil)
cdc.RegisterConcrete(CommunityPoolLendWithdrawPermission{}, "nemo/CommunityPoolLendWithdrawPermission", nil)
// Msgs
legacy.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "nemo/MsgSubmitProposal")
legacy.RegisterAminoMsg(cdc, &MsgVote{}, "nemo/MsgVote")
}
// 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(
"nemo.committee.v1beta1.Committee",
(*Committee)(nil),
&BaseCommittee{},
&TokenCommittee{},
&MemberCommittee{},
)
registry.RegisterInterface(
"nemo.committee.v1beta1.Permission",
(*Permission)(nil),
&GodPermission{},
&TextPermission{},
&SoftwareUpgradePermission{},
&ParamsChangePermission{},
&CommunityCDPRepayDebtPermission{},
&CommunityCDPWithdrawCollateralPermission{},
&CommunityPoolLendWithdrawPermission{},
)
// 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(
"nemo.committee.v1beta1.PubProposal",
(*PubProposal)(nil),
&Proposal{},
&distrtypes.CommunityPoolSpendProposal{},
&govv1beta1.TextProposal{},
&nemodisttypes.CommunityPoolMultiSpendProposal{},
&proposaltypes.ParameterChangeProposal{},
&upgradetypes.SoftwareUpgradeProposal{},
&upgradetypes.CancelSoftwareUpgradeProposal{},
&communitytypes.CommunityCDPRepayDebtProposal{},
&communitytypes.CommunityCDPWithdrawCollateralProposal{},
&communitytypes.CommunityPoolLendWithdrawProposal{},
)
registry.RegisterImplementations(
(*govv1beta1.Content)(nil),
&CommitteeChangeProposal{},
&CommitteeDeleteProposal{},
)
}