forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msgs.go
223 lines (196 loc) · 7.19 KB
/
msgs.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package group
import (
"github.com/cosmos/gogoproto/proto"
"github.com/T-ragon/cosmos-sdk/codec/types"
sdk "github.com/T-ragon/cosmos-sdk/types"
sdkerrors "github.com/T-ragon/cosmos-sdk/types/errors"
"github.com/T-ragon/cosmos-sdk/types/tx"
)
var (
_ sdk.Msg = &MsgCreateGroup{}
_ sdk.Msg = &MsgUpdateGroupAdmin{}
_ sdk.Msg = &MsgUpdateGroupMetadata{}
_ sdk.Msg = &MsgUpdateGroupMembers{}
_ sdk.Msg = &MsgUpdateGroupMembers{}
_ sdk.Msg = &MsgCreateGroupWithPolicy{}
_ sdk.Msg = &MsgCreateGroupPolicy{}
_ sdk.Msg = &MsgUpdateGroupPolicyAdmin{}
_ sdk.Msg = &MsgUpdateGroupPolicyDecisionPolicy{}
_ sdk.Msg = &MsgUpdateGroupPolicyMetadata{}
_ sdk.Msg = &MsgLeaveGroup{}
_ sdk.Msg = &MsgExec{}
_ sdk.Msg = &MsgVote{}
_ sdk.Msg = &MsgWithdrawProposal{}
_ sdk.Msg = &MsgSubmitProposal{}
_ sdk.Msg = &MsgCreateGroupPolicy{}
_ types.UnpackInterfacesMessage = MsgCreateGroupPolicy{}
_ types.UnpackInterfacesMessage = MsgUpdateGroupPolicyDecisionPolicy{}
_ types.UnpackInterfacesMessage = MsgCreateGroupWithPolicy{}
)
// GetGroupID gets the group id of the MsgUpdateGroupMetadata.
func (m *MsgUpdateGroupMetadata) GetGroupID() uint64 {
return m.GroupId
}
// GetGroupID gets the group id of the MsgUpdateGroupMembers.
func (m *MsgUpdateGroupMembers) GetGroupID() uint64 {
return m.GroupId
}
// GetGroupID gets the group id of the MsgUpdateGroupAdmin.
func (m *MsgUpdateGroupAdmin) GetGroupID() uint64 {
return m.GroupId
}
// NewMsgCreateGroupWithPolicy creates a new MsgCreateGroupWithPolicy.
func NewMsgCreateGroupWithPolicy(admin string, members []MemberRequest, groupMetadata, groupPolicyMetadata string, groupPolicyAsAdmin bool, decisionPolicy DecisionPolicy) (*MsgCreateGroupWithPolicy, error) {
m := &MsgCreateGroupWithPolicy{
Admin: admin,
Members: members,
GroupMetadata: groupMetadata,
GroupPolicyMetadata: groupPolicyMetadata,
GroupPolicyAsAdmin: groupPolicyAsAdmin,
}
err := m.SetDecisionPolicy(decisionPolicy)
if err != nil {
return nil, err
}
return m, nil
}
// GetDecisionPolicy gets the decision policy of MsgCreateGroupWithPolicy.
func (m *MsgCreateGroupWithPolicy) GetDecisionPolicy() (DecisionPolicy, error) {
decisionPolicy, ok := m.DecisionPolicy.GetCachedValue().(DecisionPolicy)
if !ok {
return nil, sdkerrors.ErrInvalidType.Wrapf("expected %T, got %T", (DecisionPolicy)(nil), m.DecisionPolicy.GetCachedValue())
}
return decisionPolicy, nil
}
// SetDecisionPolicy sets the decision policy for MsgCreateGroupWithPolicy.
func (m *MsgCreateGroupWithPolicy) SetDecisionPolicy(decisionPolicy DecisionPolicy) error {
any, err := types.NewAnyWithValue(decisionPolicy)
if err != nil {
return err
}
m.DecisionPolicy = any
return nil
}
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (m MsgCreateGroupWithPolicy) UnpackInterfaces(unpacker types.AnyUnpacker) error {
var decisionPolicy DecisionPolicy
return unpacker.UnpackAny(m.DecisionPolicy, &decisionPolicy)
}
// NewMsgUpdateGroupPolicyDecisionPolicy creates a new MsgUpdateGroupPolicyDecisionPolicy.
func NewMsgUpdateGroupPolicyDecisionPolicy(admin, address sdk.AccAddress, decisionPolicy DecisionPolicy) (*MsgUpdateGroupPolicyDecisionPolicy, error) {
m := &MsgUpdateGroupPolicyDecisionPolicy{
Admin: admin.String(),
GroupPolicyAddress: address.String(),
}
err := m.SetDecisionPolicy(decisionPolicy)
if err != nil {
return nil, err
}
return m, nil
}
// SetDecisionPolicy sets the decision policy for MsgUpdateGroupPolicyDecisionPolicy.
func (m *MsgUpdateGroupPolicyDecisionPolicy) SetDecisionPolicy(decisionPolicy DecisionPolicy) error {
msg, ok := decisionPolicy.(proto.Message)
if !ok {
return sdkerrors.ErrInvalidType.Wrapf("can't proto marshal %T", msg)
}
any, err := types.NewAnyWithValue(msg)
if err != nil {
return err
}
m.DecisionPolicy = any
return nil
}
// GetDecisionPolicy gets the decision policy of MsgUpdateGroupPolicyDecisionPolicy.
func (m *MsgUpdateGroupPolicyDecisionPolicy) GetDecisionPolicy() (DecisionPolicy, error) {
decisionPolicy, ok := m.DecisionPolicy.GetCachedValue().(DecisionPolicy)
if !ok {
return nil, sdkerrors.ErrInvalidType.Wrapf("expected %T, got %T", (DecisionPolicy)(nil), m.DecisionPolicy.GetCachedValue())
}
return decisionPolicy, nil
}
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (m MsgUpdateGroupPolicyDecisionPolicy) UnpackInterfaces(unpacker types.AnyUnpacker) error {
var decisionPolicy DecisionPolicy
return unpacker.UnpackAny(m.DecisionPolicy, &decisionPolicy)
}
// NewMsgCreateGroupPolicy creates a new MsgCreateGroupPolicy.
func NewMsgCreateGroupPolicy(admin sdk.AccAddress, group uint64, metadata string, decisionPolicy DecisionPolicy) (*MsgCreateGroupPolicy, error) {
m := &MsgCreateGroupPolicy{
Admin: admin.String(),
GroupId: group,
Metadata: metadata,
}
err := m.SetDecisionPolicy(decisionPolicy)
if err != nil {
return nil, err
}
return m, nil
}
// GetAdmin gets the admin of MsgCreateGroupPolicy.
func (m *MsgCreateGroupPolicy) GetAdmin() string {
return m.Admin
}
// GetGroupID gets the group id of MsgCreateGroupPolicy.
func (m *MsgCreateGroupPolicy) GetGroupID() uint64 {
return m.GroupId
}
// GetMetadata gets the metadata of MsgCreateGroupPolicy.
func (m *MsgCreateGroupPolicy) GetMetadata() string {
return m.Metadata
}
// GetDecisionPolicy gets the decision policy of MsgCreateGroupPolicy.
func (m *MsgCreateGroupPolicy) GetDecisionPolicy() (DecisionPolicy, error) {
decisionPolicy, ok := m.DecisionPolicy.GetCachedValue().(DecisionPolicy)
if !ok {
return nil, sdkerrors.ErrInvalidType.Wrapf("expected %T, got %T", (DecisionPolicy)(nil), m.DecisionPolicy.GetCachedValue())
}
return decisionPolicy, nil
}
// SetDecisionPolicy sets the decision policy of MsgCreateGroupPolicy.
func (m *MsgCreateGroupPolicy) SetDecisionPolicy(decisionPolicy DecisionPolicy) error {
any, err := types.NewAnyWithValue(decisionPolicy)
if err != nil {
return err
}
m.DecisionPolicy = any
return nil
}
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (m MsgCreateGroupPolicy) UnpackInterfaces(unpacker types.AnyUnpacker) error {
var decisionPolicy DecisionPolicy
return unpacker.UnpackAny(m.DecisionPolicy, &decisionPolicy)
}
// NewMsgSubmitProposal creates a new MsgSubmitProposal.
func NewMsgSubmitProposal(address string, proposers []string, msgs []sdk.Msg, metadata string, exec Exec, title, summary string) (*MsgSubmitProposal, error) {
m := &MsgSubmitProposal{
GroupPolicyAddress: address,
Proposers: proposers,
Metadata: metadata,
Exec: exec,
Title: title,
Summary: summary,
}
err := m.SetMsgs(msgs)
if err != nil {
return nil, err
}
return m, nil
}
// SetMsgs packs msgs into Any's
func (m *MsgSubmitProposal) SetMsgs(msgs []sdk.Msg) error {
anys, err := tx.SetMsgs(msgs)
if err != nil {
return err
}
m.Messages = anys
return nil
}
// GetMsgs unpacks m.Messages Any's into sdk.Msg's
func (m MsgSubmitProposal) GetMsgs() ([]sdk.Msg, error) {
return tx.GetMsgs(m.Messages, "proposal")
}
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (m MsgSubmitProposal) UnpackInterfaces(unpacker types.AnyUnpacker) error {
return tx.UnpackInterfaces(unpacker, m.Messages)
}