/
message_market.go
108 lines (88 loc) · 2.7 KB
/
message_market.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const typeMsgAddMarket = "add_market"
var _ sdk.Msg = &MsgAddMarket{}
// NewMsgAddMarket creates the new input for adding an market to blockchain
func NewMsgAddMarket(creator string, ticket string) *MsgAddMarket {
return &MsgAddMarket{
Creator: creator,
Ticket: ticket,
}
}
// Route return the message route for slashing
func (msg *MsgAddMarket) Route() string {
return RouterKey
}
// Type returns the msg add market type
func (msg *MsgAddMarket) Type() string {
return typeMsgAddMarket
}
// GetSigners return the creators address
func (msg *MsgAddMarket) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}
// GetSignBytes return the marshalled bytes of the msg
func (msg *MsgAddMarket) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
// ValidateBasic validates the input creation market
func (msg *MsgAddMarket) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
if msg.Ticket == "" {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid ticket param")
}
return nil
}
// typeMsgUpdateMarket is the market name of update market
const typeMsgUpdateMarket = "update_market"
var _ sdk.Msg = &MsgUpdateMarket{}
// NewMsgUpdateMarket accepts the params to create new update body
func NewMsgUpdateMarket(creator, ticket string) *MsgUpdateMarket {
return &MsgUpdateMarket{
Creator: creator,
Ticket: ticket,
}
}
// Route return the message route for slashing
func (msg *MsgUpdateMarket) Route() string {
return RouterKey
}
// Type return the update market type
func (msg *MsgUpdateMarket) Type() string {
return typeMsgUpdateMarket
}
// GetSigners return the creators address
func (msg *MsgUpdateMarket) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}
// GetSignBytes return the marshalled bytes of the msg
func (msg *MsgUpdateMarket) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
// ValidateBasic validates the input update market
func (msg *MsgUpdateMarket) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
if msg.Ticket == "" {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid ticket param")
}
return nil
}