-
Notifications
You must be signed in to change notification settings - Fork 31
/
msgs.go
62 lines (52 loc) · 1.56 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
package types
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const (
TypeMsgRequestRandom = "request_random" // type for MsgRequestRandom
DefaultBlockInterval = uint64(10) // DefaultBlockInterval is the default block interval
)
var _ sdk.Msg = &MsgRequestRandom{}
// NewMsgRequestRandom constructs a new MsgRequestRandom instance
func NewMsgRequestRandom(
consumer string,
blockInterval uint64,
oracle bool,
serviceFeeCap sdk.Coins,
) *MsgRequestRandom {
return &MsgRequestRandom{
Consumer: consumer,
BlockInterval: blockInterval,
Oracle: oracle,
ServiceFeeCap: serviceFeeCap,
}
}
// Route implements Msg.
func (msg MsgRequestRandom) Route() string { return RouterKey }
// Type implements Msg.
func (msg MsgRequestRandom) Type() string { return TypeMsgRequestRandom }
// ValidateBasic implements Msg.
func (msg MsgRequestRandom) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Consumer); err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid consumer address (%s)", err)
}
return ValidateServiceFeeCap(msg.ServiceFeeCap)
}
// GetSignBytes implements Msg.
func (msg MsgRequestRandom) GetSignBytes() []byte {
b, err := ModuleCdc.MarshalJSON(&msg)
if err != nil {
panic(err)
}
return sdk.MustSortJSON(b)
}
// GetSigners implements Msg.
func (msg MsgRequestRandom) GetSigners() []sdk.AccAddress {
consumer, err := sdk.AccAddressFromBech32(msg.Consumer)
if err != nil {
panic(err)
}
return []sdk.AccAddress{consumer}
}