/
message_create_sequencer.go
85 lines (71 loc) · 2.33 KB
/
message_create_sequencer.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
package types
import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const TypeMsgCreateSequencer = "create_sequencer"
var (
_ sdk.Msg = &MsgCreateSequencer{}
_ codectypes.UnpackInterfacesMessage = (*MsgCreateSequencer)(nil)
)
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (msg MsgCreateSequencer) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
var pubKey cryptotypes.PubKey
return unpacker.UnpackAny(msg.FuryintPubKey, &pubKey)
}
func NewMsgCreateSequencer(creator string, pubkey cryptotypes.PubKey, rollappId string, description *Description) (*MsgCreateSequencer, error) {
var pkAny *codectypes.Any
if pubkey != nil {
var err error
if pkAny, err = codectypes.NewAnyWithValue(pubkey); err != nil {
return nil, err
}
}
return &MsgCreateSequencer{
Creator: creator,
FuryintPubKey: pkAny,
RollappId: rollappId,
Description: *description,
}, nil
}
func (msg *MsgCreateSequencer) Route() string {
return RouterKey
}
func (msg *MsgCreateSequencer) Type() string {
return TypeMsgCreateSequencer
}
func (msg *MsgCreateSequencer) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}
func (msg *MsgCreateSequencer) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgCreateSequencer) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
// public key also checked by the application logic
if msg.FuryintPubKey != nil {
// check it is a pubkey
if _, err = codectypes.NewAnyWithValue(msg.FuryintPubKey); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidPubKey, "invalid sequencer pubkey(%s)", err)
}
// cast to cryptotypes.PubKey type
pk, ok := msg.FuryintPubKey.GetCachedValue().(cryptotypes.PubKey)
if !ok {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "Expecting cryptotypes.PubKey, got %T", pk)
}
}
if _, err := msg.Description.EnsureLength(); err != nil {
return err
}
return nil
}