-
Notifications
You must be signed in to change notification settings - Fork 367
/
msgs.go
70 lines (59 loc) · 1.89 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
package types
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// TypeMsgPostPrice type of PostPrice msg
TypeMsgPostPrice = "post_price"
)
// ensure Msg interface compliance at compile time
var _ sdk.Msg = &MsgPostPrice{}
// MsgPostPrice struct representing a posted price message.
// Used by oracles to input prices to the pricefeed
type MsgPostPrice struct {
From sdk.AccAddress `json:"from" yaml:"from"` // client that sent in this address
MarketID string `json:"market_id" yaml:"market_id"` // asset code used by exchanges/api
Price sdk.Dec `json:"price" yaml:"price"` // price in decimal (max precision 18)
Expiry time.Time `json:"expiry" yaml:"expiry"` // expiry time
}
// NewMsgPostPrice creates a new post price msg
func NewMsgPostPrice(
from sdk.AccAddress,
assetCode string,
price sdk.Dec,
expiry time.Time) MsgPostPrice {
return MsgPostPrice{
From: from,
MarketID: assetCode,
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 {
return []sdk.AccAddress{msg.From}
}
// ValidateBasic does a simple validation check that doesn't require access to any other information.
func (msg MsgPostPrice) ValidateBasic() sdk.Error {
if msg.From.Empty() {
return sdk.ErrInternal("invalid (empty) from address")
}
if len(msg.MarketID) == 0 {
return sdk.ErrInternal("invalid (empty) market id")
}
if msg.Price.LT(sdk.ZeroDec()) {
return sdk.ErrInternal("invalid (negative) price")
}
// TODO check coin denoms
return nil
}