-
Notifications
You must be signed in to change notification settings - Fork 28
/
msg_create_validator.go
71 lines (58 loc) · 2.09 KB
/
msg_create_validator.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
package event
import (
"bytes"
"github.com/crypto-com/chain-indexing/usecase/coin"
"github.com/crypto-com/chain-indexing/usecase/model"
entity_event "github.com/crypto-com/chain-indexing/entity/event"
jsoniter "github.com/json-iterator/go"
"github.com/luci/go-render/render"
)
const MSG_CREATE_VALIDATOR = "/cosmos.staking.v1beta1.MsgCreateValidator"
const MSG_CREATE_VALIDATOR_CREATED = "/cosmos.staking.v1beta1.MsgCreateValidator.Created"
const MSG_CREATE_VALIDATOR_FAILED = "/cosmos.staking.v1beta1.MsgCreateValidator.Failed"
type MsgCreateValidator struct {
MsgBase
Description model.ValidatorDescription `json:"description"`
CommissionRates model.ValidatorCommission `json:"commissionRates"`
MinSelfDelegation string `json:"minSelfDelegation"`
DelegatorAddress string `json:"delegatorAddress"`
ValidatorAddress string `json:"validatorAddress"`
TendermintPubkey string `json:"tendermintPubkey"`
Amount coin.Coin `json:"amount"`
}
func NewMsgCreateValidator(msgCommonParams MsgCommonParams, params model.MsgCreateValidatorParams) *MsgCreateValidator {
return &MsgCreateValidator{
NewMsgBase(MsgBaseParams{
MsgName: MSG_CREATE_VALIDATOR,
Version: 1,
MsgCommonParams: msgCommonParams,
}),
params.Description,
params.Commission,
params.MinSelfDelegation,
params.DelegatorAddress,
params.ValidatorAddress,
params.TendermintPubkey,
params.Amount,
}
}
// ToJSON encodes the event into JSON string payload
func (event *MsgCreateValidator) ToJSON() (string, error) {
encoded, err := jsoniter.Marshal(event)
if err != nil {
return "", err
}
return string(encoded), nil
}
func (event *MsgCreateValidator) String() string {
return render.Render(event)
}
func DecodeMsgCreateValidator(encoded []byte) (entity_event.Event, error) {
jsonDecoder := jsoniter.NewDecoder(bytes.NewReader(encoded))
jsonDecoder.DisallowUnknownFields()
var event *MsgCreateValidator
if err := jsonDecoder.Decode(&event); err != nil {
return nil, err
}
return event, nil
}