/
message.go
65 lines (58 loc) · 2.83 KB
/
message.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
/*
Copyright [2019] - [2020], PERSISTENCE TECHNOLOGIES PTE. LTD. and the persistenceSDK contributors
SPDX-License-Identifier: Apache-2.0
*/
package mint
import (
"github.com/asaskevich/govalidator"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
xprtErrors "github.com/persistenceOne/persistenceSDK/constants/errors"
"github.com/persistenceOne/persistenceSDK/schema/types"
)
type message struct {
From sdkTypes.AccAddress `json:"from" valid:"required~required field from missing matches(^commit[a-z0-9]{39}$)~invalid field from"`
FromID types.ID `json:"fromID" valid:"required~required field fromID missing"`
ToID types.ID `json:"toID" valid:"required~required field toID missing"`
ClassificationID types.ID `json:"classificationID" valid:"required~required field classificationID missing"`
ImmutableMetaProperties types.MetaProperties `json:"immutableMetaProperties" valid:"required~required field immutableMetaProperties missing"`
ImmutableProperties types.Properties `json:"immutableProperties" valid:"required~required field immutableProperties missing"`
MutableMetaProperties types.MetaProperties `json:"mutableMetaProperties" valid:"required~required field mutableMetaProperties missing"`
MutableProperties types.Properties `json:"mutableProperties" valid:"required~required field mutableProperties missing"`
}
var _ sdkTypes.Msg = message{}
func (message message) Route() string { return Transaction.GetModuleName() }
func (message message) Type() string { return Transaction.GetName() }
func (message message) ValidateBasic() error {
var _, Error = govalidator.ValidateStruct(message)
if Error != nil {
return errors.Wrap(xprtErrors.IncorrectMessage, Error.Error())
}
return nil
}
func (message message) GetSignBytes() []byte {
return sdkTypes.MustSortJSON(packageCodec.MustMarshalJSON(message))
}
func (message message) GetSigners() []sdkTypes.AccAddress {
return []sdkTypes.AccAddress{message.From}
}
func messageFromInterface(msg sdkTypes.Msg) message {
switch value := msg.(type) {
case message:
return value
default:
return message{}
}
}
func newMessage(from sdkTypes.AccAddress, fromID types.ID, toID types.ID, classificationID types.ID, immutableMetaProperties types.MetaProperties, immutableProperties types.Properties, mutableMetaProperties types.MetaProperties, mutableProperties types.Properties) sdkTypes.Msg {
return message{
From: from,
FromID: fromID,
ToID: toID,
ClassificationID: classificationID,
ImmutableMetaProperties: immutableMetaProperties,
ImmutableProperties: immutableProperties,
MutableMetaProperties: mutableMetaProperties,
MutableProperties: mutableProperties,
}
}