-
Notifications
You must be signed in to change notification settings - Fork 37
/
msgs.go
74 lines (60 loc) · 1.92 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
package v2
import (
"fmt"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
types "github.com/peggyjv/sommelier/v7/x/cork/types"
)
var (
_ sdk.Msg = &MsgScheduleCorkRequest{}
)
const (
TypeMsgSubmitCorkRequest = "cork_submit"
TypeMsgScheduleCorkRequest = "cork_schedule"
)
////////////////////////////
// MsgScheduleCorkRequest //
////////////////////////////
// NewMsgScheduleCorkRequest return a new MsgScheduleCorkRequest
func NewMsgScheduleCorkRequest(body []byte, address common.Address, blockHeight uint64, signer sdk.AccAddress) (*MsgScheduleCorkRequest, error) {
return &MsgScheduleCorkRequest{
Cork: &Cork{
EncodedContractCall: body,
TargetContractAddress: address.String(),
},
BlockHeight: blockHeight,
Signer: signer.String(),
}, nil
}
// Route implements sdk.Msg
func (m *MsgScheduleCorkRequest) Route() string { return types.ModuleName }
// Type implements sdk.Msg
func (m *MsgScheduleCorkRequest) Type() string { return TypeMsgScheduleCorkRequest }
// ValidateBasic implements sdk.Msg
func (m *MsgScheduleCorkRequest) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.Signer); err != nil {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, err.Error())
}
if m.BlockHeight == 0 {
return fmt.Errorf("block height must be non-zero")
}
return m.Cork.ValidateBasic()
}
// GetSignBytes implements sdk.Msg
func (m *MsgScheduleCorkRequest) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m))
}
// GetSigners implements sdk.Msg
func (m *MsgScheduleCorkRequest) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{m.MustGetSigner()}
}
// MustGetSigner returns the signer address
func (m *MsgScheduleCorkRequest) MustGetSigner() sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(m.Signer)
if err != nil {
panic(err)
}
return addr
}