/
msg_register_account.go
62 lines (48 loc) · 1.47 KB
/
msg_register_account.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
package event
import (
"bytes"
icaauthmodel "github.com/crypto-com/chain-indexing/usecase/model/icaauth"
entity_event "github.com/crypto-com/chain-indexing/entity/event"
jsoniter "github.com/json-iterator/go"
"github.com/luci/go-render/render"
)
const MSG_REGISTER_ACCOUNT = "/icaauth.v1.MsgRegisterAccount"
const MSG_REGISTER_ACCOUNT_CREATED = "/icaauth.v1.MsgRegisterAccount.Created"
const MSG_REGISTER_ACCOUNT_FAILED = "/icaauth.v1.MsgRegisterAccount.Failed"
type MsgRegisterAccount struct {
MsgBase
Params icaauthmodel.MsgRegisterAccountParams `json:"params"`
}
func NewMsgRegisterAccount(
msgCommonParams MsgCommonParams,
params icaauthmodel.MsgRegisterAccountParams,
) *MsgRegisterAccount {
return &MsgRegisterAccount{
NewMsgBase(MsgBaseParams{
MsgName: MSG_REGISTER_ACCOUNT,
Version: 1,
MsgCommonParams: msgCommonParams,
}),
params,
}
}
// ToJSON encodes the event into JSON string payload
func (event *MsgRegisterAccount) ToJSON() (string, error) {
encoded, err := jsoniter.Marshal(event)
if err != nil {
return "", err
}
return string(encoded), nil
}
func (event *MsgRegisterAccount) String() string {
return render.Render(event)
}
func DecodeMsgRegisterAccount(encoded []byte) (entity_event.Event, error) {
jsonDecoder := jsoniter.NewDecoder(bytes.NewReader(encoded))
jsonDecoder.DisallowUnknownFields()
var event *MsgRegisterAccount
if err := jsonDecoder.Decode(&event); err != nil {
return nil, err
}
return event, nil
}