-
Notifications
You must be signed in to change notification settings - Fork 44
/
message_activate_account.go
77 lines (62 loc) · 2 KB
/
message_activate_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package v1beta1
import (
errorsmod "cosmossdk.io/errors"
smartaccounttypes "github.com/aura-nw/aura/x/smartaccount/types"
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 TypeMsgActivateAccount = "activate_account"
var (
_ sdk.Msg = &MsgActivateAccount{}
_ codectypes.UnpackInterfacesMessage = (*MsgActivateAccount)(nil)
)
func (msg *MsgActivateAccount) Route() string {
return smartaccounttypes.RouterKey
}
func (msg *MsgActivateAccount) Type() string {
return TypeMsgActivateAccount
}
func (msg *MsgActivateAccount) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.AccountAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}
func (msg *MsgActivateAccount) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgActivateAccount) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.AccountAddress)
if err != nil {
return errorsmod.Wrapf(smartaccounttypes.ErrInvalidAddress, "invalid smart account address (%s)", err)
}
if len(msg.Salt) < 1 {
return sdkerrors.ErrInvalidRequest.Wrap("length of salt can't be zero")
}
if len(msg.Salt) > 64 {
return sdkerrors.ErrInvalidRequest.Wrap("length of salt too long")
}
_, err = PubKeyDecode(msg.PubKey)
if err != nil {
return err
}
if msg.CodeID == 0 {
return sdkerrors.ErrInvalidRequest.Wrap("code id cannot be zero")
}
if err := msg.InitMsg.ValidateBasic(); err != nil {
return sdkerrors.ErrInvalidRequest.Wrapf("invalid init msg: %s", err.Error())
}
return nil
}
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (msg MsgActivateAccount) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
if msg.PubKey == nil {
return nil
}
var pubKey cryptotypes.PubKey
return unpacker.UnpackAny(msg.PubKey, &pubKey)
}