-
Notifications
You must be signed in to change notification settings - Fork 83
/
message_update_market_prices.go
52 lines (45 loc) · 1.56 KB
/
message_update_market_prices.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
var _ sdk.Msg = &MsgUpdateMarketPrices{}
func NewMarketPriceUpdate(id uint32, price uint64) *MsgUpdateMarketPrices_MarketPrice {
return &MsgUpdateMarketPrices_MarketPrice{
MarketId: id,
Price: price,
}
}
func NewMsgUpdateMarketPrices(updates []*MsgUpdateMarketPrices_MarketPrice) *MsgUpdateMarketPrices {
return &MsgUpdateMarketPrices{
MarketPriceUpdates: updates,
}
}
func (msg *MsgUpdateMarketPrices) GetSigners() []sdk.AccAddress {
// Return empty slice because app-injected msg is not expected to be signed.
return []sdk.AccAddress{}
}
// ValidateBasic performs stateless validations on the message. Specifically:
// - Update prices are non-zero.
// - Updates are sorted by market id in ascending order.
// - Updates do not contain duplicate markets.
func (msg *MsgUpdateMarketPrices) ValidateBasic() error {
for i, marketPriceUpdate := range msg.MarketPriceUpdates {
// Check price is not 0.
if marketPriceUpdate.Price == uint64(0) {
return sdkerrors.Wrapf(
ErrInvalidMarketPriceUpdateStateless,
"price cannot be 0 for market id (%d)",
marketPriceUpdate.MarketId,
)
}
// Check updates are sorted by market id and there are no duplicates.
if i > 0 && msg.MarketPriceUpdates[i-1].MarketId >= marketPriceUpdate.MarketId {
return sdkerrors.Wrap(
ErrInvalidMarketPriceUpdateStateless,
"market price updates must be sorted by market id in ascending order and cannot contain duplicates",
)
}
}
return nil
}