/
msgs.go
69 lines (59 loc) · 1.98 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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// RouterKey is the module name router key
const RouterKey = ModuleName // this was defined in your key.go file
/// Rx
// MsgCreateRx defines a create rx message
type MsgPrescribe struct {
From sdk.AccAddress `json:"from"`
Doctor string `json:"doctor"`
Patient string `json:"patient"`
Encrypted string `json:"encrypted"` // 处方上链前需加密
Envelope string `json:"envelope"`
Memo string `json:"memo"`
}
// NewMsgRegisterDrugStore is a constructor function for MsgRegisterDrugStore
func NewMsgPrescribe(from sdk.AccAddress, doctor string, patient string, encrypted string, envelope string, memo string) MsgPrescribe {
return MsgPrescribe{
From: from,
Doctor: doctor,
Patient: patient,
Encrypted: encrypted,
Envelope: envelope,
Memo: memo,
}
}
// Route should return the name of the module
func (msg MsgPrescribe) Route() string { return RouterKey }
// Type should return the action
func (msg MsgPrescribe) Type() string { return "prescribe" }
// ValidateBasic runs stateless checks on the message
func (msg MsgPrescribe) ValidateBasic() error {
if msg.From.Empty() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.From.String())
}
if len(msg.Doctor) < 1 {
return sdkerrors.Wrap(ErrInputInvalid, msg.Doctor)
}
if len(msg.Patient) < 1 {
return sdkerrors.Wrap(ErrInputInvalid, msg.Patient)
}
if len(msg.Encrypted) < 1 {
return sdkerrors.Wrap(ErrInputInvalid, msg.Encrypted)
}
if len(msg.Envelope) < 1 {
return sdkerrors.Wrap(ErrInputInvalid, msg.Envelope)
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgPrescribe) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgPrescribe) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.From}
}