-
Notifications
You must be signed in to change notification settings - Fork 45
/
msgs_treasury.go
137 lines (108 loc) · 4.38 KB
/
msgs_treasury.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
package types
import (
"fmt"
"strings"
"time"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
"github.com/cosmos/cosmos-sdk/x/authz"
)
var (
_ sdk.Msg = &MsgGrantTreasuryAuthorization{}
_ sdk.Msg = &MsgRevokeTreasuryAuthorization{}
_ legacytx.LegacyMsg = &MsgGrantTreasuryAuthorization{}
_ legacytx.LegacyMsg = &MsgRevokeTreasuryAuthorization{}
_ ManageSubspaceMsg = &MsgGrantTreasuryAuthorization{}
_ ManageSubspaceMsg = &MsgRevokeTreasuryAuthorization{}
_ codectypes.UnpackInterfacesMessage = &MsgGrantTreasuryAuthorization{}
)
func NewMsgGrantTreasuryAuthorization(subspaceID uint64, granter string, grantee string, authorization authz.Authorization, expiration *time.Time) *MsgGrantTreasuryAuthorization {
grant, err := authz.NewGrant(time.Time{}, authorization, expiration)
if err != nil {
panic("failed to pack authorization to grant")
}
return &MsgGrantTreasuryAuthorization{
SubspaceID: subspaceID,
Granter: granter,
Grantee: grantee,
Grant: grant,
}
}
// Route implements legacytx.LegacyMsg
func (msg *MsgGrantTreasuryAuthorization) Route() string { return RouterKey }
// Type implements legacytx.LegacyMsg
func (msg *MsgGrantTreasuryAuthorization) Type() string { return ActionGrantTreasuryAuthorization }
// ValidateBasic implements sdk.Msg
func (msg *MsgGrantTreasuryAuthorization) ValidateBasic() error {
if msg.SubspaceID == 0 {
return sdkerrors.ErrInvalidRequest.Wrap("invalid subspace id")
}
_, err := sdk.AccAddressFromBech32(msg.Granter)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid granter address: %s", msg.Granter)
}
_, err = sdk.AccAddressFromBech32(msg.Grantee)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid grantee address: %s", msg.Grantee)
}
return msg.Grant.ValidateBasic()
}
// GetSignBytes implements legacytx.LegacyMsg
func (msg *MsgGrantTreasuryAuthorization) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}
// GetSigners implements sdk.Msg
func (msg *MsgGrantTreasuryAuthorization) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Granter)
return []sdk.AccAddress{addr}
}
// UnpackInterfaces implements codectypes.UnpackInterfacesMessage
func (msg *MsgGrantTreasuryAuthorization) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return msg.Grant.UnpackInterfaces(unpacker)
}
// IsManageSubspaceMsg implements subspacestypes.ManageSubspaceMsg
func (msg *MsgGrantTreasuryAuthorization) IsManageSubspaceMsg() {}
// --------------------------------------------------------------------------------------------------------------------
func NewMsgRevokeTreasuryAuthorization(subspaceID uint64, granter string, grantee string, msgTypeUrl string) *MsgRevokeTreasuryAuthorization {
return &MsgRevokeTreasuryAuthorization{
SubspaceID: subspaceID,
Granter: granter,
Grantee: grantee,
MsgTypeUrl: msgTypeUrl,
}
}
// GetSignBytes implements legacytx.LegacyMsg
func (msg *MsgRevokeTreasuryAuthorization) Route() string { return RouterKey }
// GetSignBytes implements legacytx.LegacyMsg
func (msg *MsgRevokeTreasuryAuthorization) Type() string { return ActionRevokeTreasuryAuthorization }
// ValidateBasic implements sdk.Msg
func (msg *MsgRevokeTreasuryAuthorization) ValidateBasic() error {
if msg.SubspaceID == 0 {
return fmt.Errorf("invalid subspace id")
}
_, err := sdk.AccAddressFromBech32(msg.Granter)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid granter address: %s", msg.Granter)
}
_, err = sdk.AccAddressFromBech32(msg.Grantee)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid grantee address: %s", msg.Grantee)
}
if strings.TrimSpace(msg.MsgTypeUrl) == "" {
return sdkerrors.ErrInvalidRequest.Wrap("missing method name")
}
return nil
}
// GetSignBytes implements legacytx.LegacyMsg
func (msg *MsgRevokeTreasuryAuthorization) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}
// GetSigners implements sdk.Msg
func (msg *MsgRevokeTreasuryAuthorization) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Granter)
return []sdk.AccAddress{addr}
}
// IsManageSubspaceMsg implements subspacestypes.ManageSubspaceMsg
func (msg *MsgRevokeTreasuryAuthorization) IsManageSubspaceMsg() {}