-
Notifications
You must be signed in to change notification settings - Fork 12
/
msg.go
141 lines (119 loc) · 4.05 KB
/
msg.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
vctypes "github.com/allinbits/cosmos-cash/x/verifiable-credential/types"
)
// define message types
const (
TypeMsgIssueRegulatorCredential = "issuer-regulator-credential"
TypeMsgIssueRegistrationCredential = "issuer-registration-credential"
TypeMsgIssueLicenseCredential = "issuer-license-credential"
)
var (
_ sdk.Msg = &MsgIssueRegulatorCredential{}
_ sdk.Msg = &MsgIssueLicenseCredential{}
_ sdk.Msg = &MsgIssueRegistrationCredential{}
)
func NewMsgIssueRegulatorCredential(credential vctypes.VerifiableCredential, signerAccount string) *MsgIssueRegulatorCredential {
return &MsgIssueRegulatorCredential{
Owner: signerAccount,
Credential: &credential,
}
}
func (m *MsgIssueRegulatorCredential) Route() string {
return RouterKey
}
func (m *MsgIssueRegulatorCredential) Type() string {
return TypeMsgIssueRegulatorCredential
}
func (m *MsgIssueRegulatorCredential) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}
func (m *MsgIssueRegulatorCredential) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(m)
return sdk.MustSortJSON(bz)
}
func (m *MsgIssueRegulatorCredential) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
return nil
}
// NewMsgIssueLicenseCredential builds a new instance of a IssuerLicenceCredential message
func NewMsgIssueLicenseCredential(credential vctypes.VerifiableCredential, signerAccount string) *MsgIssueLicenseCredential {
return &MsgIssueLicenseCredential{
Credential: &credential,
Owner: signerAccount,
}
}
// Route returns the module router key
func (m *MsgIssueLicenseCredential) Route() string {
return RouterKey
}
// Type returns the string name of the message
func (m *MsgIssueLicenseCredential) Type() string {
return TypeMsgIssueLicenseCredential
}
// GetSigners returns the account addresses singing the message
func (m *MsgIssueLicenseCredential) GetSigners() []sdk.AccAddress {
owner, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
panic(err)
}
return []sdk.AccAddress{owner}
}
// GetSignBytes returns the bytes of the signed message
func (m *MsgIssueLicenseCredential) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(m)
return sdk.MustSortJSON(bz)
}
// ValidateBasic performs basic validation of the message
func (m *MsgIssueLicenseCredential) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
return nil
}
// NewMsgIssueRegistrationCredential builds a new instance of a the message
func NewMsgIssueRegistrationCredential(credential vctypes.VerifiableCredential, signerAccount string) *MsgIssueRegistrationCredential {
return &MsgIssueRegistrationCredential{
Credential: &credential,
Owner: signerAccount,
}
}
// Route returns the module router key
func (m *MsgIssueRegistrationCredential) Route() string {
return RouterKey
}
// Type returns the string name of the message
func (m *MsgIssueRegistrationCredential) Type() string {
return TypeMsgIssueRegistrationCredential
}
// GetSigners returns the account addresses singing the message
func (m *MsgIssueRegistrationCredential) GetSigners() []sdk.AccAddress {
owner, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
panic(err)
}
return []sdk.AccAddress{owner}
}
// GetSignBytes returns the bytes of the signed message
func (m *MsgIssueRegistrationCredential) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(m)
return sdk.MustSortJSON(bz)
}
// ValidateBasic performs basic validation of the message
func (m *MsgIssueRegistrationCredential) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
return nil
}