-
Notifications
You must be signed in to change notification settings - Fork 41
/
tx_msg_create_resource_payload.go
47 lines (39 loc) · 1.37 KB
/
tx_msg_create_resource_payload.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
package types
import (
cheqdtypes "github.com/cheqd/cheqd-node/x/cheqd/types"
validation "github.com/go-ozzo/ozzo-validation/v4"
)
var _ cheqdtypes.IdentityMsg = &MsgCreateResourcePayload{}
func (msg *MsgCreateResourcePayload) GetSignBytes() []byte {
return ModuleCdc.MustMarshal(msg)
}
func (msg *MsgCreateResourcePayload) ToResource() Resource {
return Resource{
Header: &ResourceHeader{
CollectionId: msg.CollectionId,
Id: msg.Id,
Name: msg.Name,
ResourceType: msg.ResourceType,
},
Data: msg.Data,
}
}
// Validation
func (msg MsgCreateResourcePayload) Validate() error {
return validation.ValidateStruct(&msg,
validation.Field(&msg.CollectionId, validation.Required, cheqdtypes.IsID()),
validation.Field(&msg.Id, validation.Required, cheqdtypes.IsUUID()),
validation.Field(&msg.Name, validation.Required, validation.Length(1, 64)),
validation.Field(&msg.ResourceType, validation.Required, validation.Length(1, 64)),
validation.Field(&msg.Data, validation.Required, validation.Length(1, 200*1024)), // 200KB
)
}
func ValidMsgCreateResourcePayload() *cheqdtypes.CustomErrorRule {
return cheqdtypes.NewCustomErrorRule(func(value interface{}) error {
casted, ok := value.(*MsgCreateResourcePayload)
if !ok {
panic("ValidMsgCreateResourcePayload must be only applied on MsgCreateDidPayload properties")
}
return casted.Validate()
})
}