-
Notifications
You must be signed in to change notification settings - Fork 10
/
msgs.go
82 lines (65 loc) · 1.99 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
72
73
74
75
76
77
78
79
80
81
82
package types
import (
fmt "fmt"
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var (
_ sdk.Msg = &MsgUpdateParams{}
_ sdk.Msg = &MsgAuctionBid{}
)
// GetSignBytes implements the LegacyMsg interface.
func (m MsgUpdateParams) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
// GetSigners returns the expected signers for a MsgUpdateParams message.
func (m MsgUpdateParams) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
}
// ValidateBasic does a sanity check on the provided data.
func (m MsgUpdateParams) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil {
return errors.Wrap(err, "invalid authority address")
}
return m.Params.Validate()
}
func NewMsgAuctionBid(bidder sdk.AccAddress, bid sdk.Coin, transactions [][]byte) *MsgAuctionBid {
return &MsgAuctionBid{
Bidder: bidder.String(),
Bid: bid,
Transactions: transactions,
}
}
// GetSignBytes implements the LegacyMsg interface.
func (m MsgAuctionBid) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
// GetSigners returns the expected signers for a MsgAuctionBid message.
func (m MsgAuctionBid) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Bidder)
return []sdk.AccAddress{addr}
}
// ValidateBasic does a sanity check on the provided data.
func (m MsgAuctionBid) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.Bidder); err != nil {
return errors.Wrap(err, "invalid bidder address")
}
// Validate the bid.
if m.Bid.IsNil() {
return fmt.Errorf("no bid included")
}
if err := m.Bid.Validate(); err != nil {
return errors.Wrap(err, "invalid bid")
}
// Validate the transactions.
if len(m.Transactions) == 0 {
return fmt.Errorf("no transactions included")
}
for _, tx := range m.Transactions {
if len(tx) == 0 {
return fmt.Errorf("empty transaction included")
}
}
return nil
}