-
Notifications
You must be signed in to change notification settings - Fork 55
/
msgs.go
109 lines (92 loc) · 2.77 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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
var (
_ sdk.Msg = (*MsgApplyMarketMaker)(nil)
_ sdk.Msg = (*MsgClaimIncentives)(nil)
)
// Message types for the marketmaker module
const (
TypeMsgApplyMarketMaker = "apply_market_maker"
TypeMsgClaimIncentives = "claim_incentives"
)
// NewMsgApplyMarketMaker creates a new MsgApplyMarketMaker.
func NewMsgApplyMarketMaker(
marketMaker sdk.AccAddress,
pairIds []uint64,
) *MsgApplyMarketMaker {
return &MsgApplyMarketMaker{
Address: marketMaker.String(),
PairIds: pairIds,
}
}
func (msg MsgApplyMarketMaker) Route() string { return RouterKey }
func (msg MsgApplyMarketMaker) Type() string { return TypeMsgApplyMarketMaker }
func (msg MsgApplyMarketMaker) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Address); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid address %q: %v", msg.Address, err)
}
if len(msg.PairIds) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "pair ids must not be empty")
}
pairMap := make(map[uint64]struct{})
for _, pair := range msg.PairIds {
if _, ok := pairMap[pair]; ok {
return sdkerrors.Wrapf(ErrInvalidPairId, "duplicated pair id %d", pair)
}
pairMap[pair] = struct{}{}
}
return nil
}
func (msg MsgApplyMarketMaker) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
func (msg MsgApplyMarketMaker) GetSigners() []sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
panic(err)
}
return []sdk.AccAddress{addr}
}
func (msg MsgApplyMarketMaker) GetAddress() sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
panic(err)
}
return addr
}
// NewMsgClaimIncentives creates a new MsgClaimIncentives.
func NewMsgClaimIncentives(
marketMaker sdk.AccAddress,
) *MsgClaimIncentives {
return &MsgClaimIncentives{
Address: marketMaker.String(),
}
}
func (msg MsgClaimIncentives) Route() string { return RouterKey }
func (msg MsgClaimIncentives) Type() string { return TypeMsgClaimIncentives }
func (msg MsgClaimIncentives) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Address); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid address %q: %v", msg.Address, err)
}
return nil
}
func (msg MsgClaimIncentives) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
func (msg MsgClaimIncentives) GetSigners() []sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
panic(err)
}
return []sdk.AccAddress{addr}
}
func (msg MsgClaimIncentives) GetAddress() sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
panic(err)
}
return addr
}