-
Notifications
You must be signed in to change notification settings - Fork 28
/
messages_subaccount.go
67 lines (54 loc) · 1.75 KB
/
messages_subaccount.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
package types
import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/sge-network/sge/utils"
)
const (
// typeMsgCreate is type of message MsgCreate
typeMsgCreate = "subacc_create"
)
var _ sdk.Msg = &MsgCreate{}
// Route returns the module's message router key.
func (*MsgCreate) Route() string { return RouterKey }
// Type returns type of its message
func (*MsgCreate) Type() string { return typeMsgCreate }
func (msg *MsgCreate) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{signer}
}
// GetSignBytes returns sortJson form of its message
func (msg *MsgCreate) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
// ValidateBasic performs a basic validation of the MsgCreate fields.
func (msg *MsgCreate) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err)
}
_, err = sdk.AccAddressFromBech32(msg.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err)
}
for _, balanceUnlock := range msg.LockedBalances {
if err = balanceUnlock.Validate(); err != nil {
return sdkerrors.Wrapf(ErrInvalidLockedBalance, "%s", err)
}
}
return nil
}
// EmitEvent emits the event for the message success.
func (msg *MsgCreate) EmitEvent(ctx *sdk.Context, subAccAddr string) {
emitter := utils.NewEventEmitter(ctx, attributeValueCategory)
emitter.AddMsg(typeMsgCreate, msg.Creator,
sdk.NewAttribute(attributeKeySubAccOwner, msg.Owner),
sdk.NewAttribute(attributeKeySubAcc, subAccAddr),
)
emitter.Emit()
}