-
Notifications
You must be signed in to change notification settings - Fork 368
/
msgs.go
71 lines (60 loc) · 1.79 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
package types
import (
"errors"
"fmt"
"strings"
time "time"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const (
// TypeMsgPostPrice type of PostPrice msg
TypeMsgPostPrice = "post_price"
// MaxExpiry defines the max expiry time defined as UNIX time (9999-12-31 23:59:59 +0000 UTC)
MaxExpiry = 253402300799
)
// ensure Msg interface compliance at compile time
var _ sdk.Msg = &MsgPostPrice{}
// NewMsgPostPrice returns a new MsgPostPrice
func NewMsgPostPrice(from string, marketID string, price sdk.Dec, expiry time.Time) *MsgPostPrice {
return &MsgPostPrice{
From: from,
MarketID: marketID,
Price: price,
Expiry: expiry,
}
}
// Route Implements Msg.
func (msg MsgPostPrice) Route() string { return RouterKey }
// Type Implements Msg
func (msg MsgPostPrice) Type() string { return TypeMsgPostPrice }
// GetSignBytes Implements Msg.
func (msg MsgPostPrice) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// GetSigners Implements Msg.
func (msg MsgPostPrice) GetSigners() []sdk.AccAddress {
from, err := sdk.AccAddressFromBech32(msg.From)
if err != nil {
panic(err)
}
return []sdk.AccAddress{from}
}
// ValidateBasic does a simple validation check that doesn't require access to any other information.
func (msg MsgPostPrice) ValidateBasic() error {
if len(msg.From) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "sender address cannot be empty")
}
if strings.TrimSpace(msg.MarketID) == "" {
return errors.New("market id cannot be blank")
}
if msg.Price.IsNegative() {
return fmt.Errorf("price cannot be negative: %s", msg.Price.String())
}
if msg.Expiry.Unix() <= 0 {
return errors.New("must set an expiration time")
}
return nil
}