github.com/lino-network/lino@v0.6.11/x/price/types/msg.go (about) 1 package types 2 3 import ( 4 "fmt" 5 6 sdk "github.com/cosmos/cosmos-sdk/types" 7 8 "github.com/lino-network/lino/types" 9 ) 10 11 // FeedPriceMsg - Validastors need to send this message to feed price. 12 type FeedPriceMsg struct { 13 Username types.AccountKey `json:"username"` 14 Price types.MiniDollar `json:"price"` 15 } 16 17 var _ types.Msg = FeedPriceMsg{} 18 19 // Route - implements sdk.Msg 20 func (msg FeedPriceMsg) Route() string { return RouterKey } 21 22 // Type - implements sdk.Msg 23 func (msg FeedPriceMsg) Type() string { return "FeedPriceMsg" } 24 25 // ValidateBasic - implements sdk.Msg 26 func (msg FeedPriceMsg) ValidateBasic() sdk.Error { 27 if !msg.Username.IsValid() { 28 return types.ErrInvalidUsername(msg.Username) 29 } 30 if !msg.Price.IsPositive() { 31 return ErrInvalidPriceFeed(msg.Price) 32 } 33 return nil 34 } 35 36 func (msg FeedPriceMsg) String() string { 37 return fmt.Sprintf("FeedPriceMsg{%s, %s}", msg.Username, msg.Price) 38 } 39 40 func (msg FeedPriceMsg) GetPermission() types.Permission { 41 return types.TransactionPermission 42 } 43 44 // GetSignBytes - implements sdk.Msg 45 func (msg FeedPriceMsg) GetSignBytes() []byte { 46 return getSignBytes(msg) 47 } 48 49 // GetSigners - implements sdk.Msg 50 func (msg FeedPriceMsg) GetSigners() []sdk.AccAddress { 51 return []sdk.AccAddress{sdk.AccAddress(msg.Username)} 52 } 53 54 // GetConsumeAmount - implements types.Msg 55 func (msg FeedPriceMsg) GetConsumeAmount() types.Coin { 56 return types.NewCoinFromInt64(0) 57 } 58 59 // utils 60 func getSignBytes(msg sdk.Msg) []byte { 61 return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) 62 }