/
msgs.go
53 lines (45 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
package servicesdk
import (
cosmostypes "github.com/cosmos/cosmos-sdk/types"
"github.com/mesg-foundation/engine/codec"
"github.com/mesg-foundation/engine/protobuf/api"
"github.com/mesg-foundation/engine/x/xvalidator"
)
// msgCreateService defines a state transition to create a service.
type msgCreateService struct {
Request *api.CreateServiceRequest `json:"request" validate:"required"`
Owner cosmostypes.AccAddress `json:"owner" validate:"required,accaddress"`
}
// newMsgCreateService is a constructor function for msgCreateService.
func newMsgCreateService(req *api.CreateServiceRequest, owner cosmostypes.AccAddress) *msgCreateService {
return &msgCreateService{
Request: req,
Owner: owner,
}
}
// Route should return the name of the module.
func (msg msgCreateService) Route() string {
return ModuleName
}
// Type returns the action.
func (msg msgCreateService) Type() string {
return "create_service"
}
// ValidateBasic runs stateless checks on the message.
func (msg msgCreateService) ValidateBasic() cosmostypes.Error {
if err := xvalidator.Validate.Struct(msg); err != nil {
return cosmostypes.ErrInternal(err.Error())
}
if msg.Owner.Empty() {
return cosmostypes.ErrInvalidAddress("owner is missing")
}
return nil
}
// GetSignBytes encodes the message for signing.
func (msg msgCreateService) GetSignBytes() []byte {
return cosmostypes.MustSortJSON(codec.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required.
func (msg msgCreateService) GetSigners() []cosmostypes.AccAddress {
return []cosmostypes.AccAddress{msg.Owner}
}