-
Notifications
You must be signed in to change notification settings - Fork 28
/
messages_house.go
99 lines (81 loc) · 3.06 KB
/
messages_house.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package types
import (
"strings"
sdkmath "cosmossdk.io/math"
"github.com/spf13/cast"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
"github.com/sge-network/sge/utils"
)
const (
// typeMsgHouseDeposit is type of message MsgHouseDeposit
typeMsgHouseDeposit = "subacc_house_deposit"
// typeHouseWithdraw is type of message MsgHouseWithdraw
typeHouseWithdraw = "subacc_house_withdraw"
)
var (
_ sdk.Msg = &MsgHouseDeposit{}
_ sdk.Msg = &MsgHouseWithdraw{}
)
// Route returns the module's message router key.
func (*MsgHouseDeposit) Route() string { return RouterKey }
// Type returns type of its message
func (*MsgHouseDeposit) Type() string { return typeMsgHouseDeposit }
func (msg *MsgHouseDeposit) GetSigners() []sdk.AccAddress {
return msg.Msg.GetSigners()
}
// GetSignBytes returns sortJson form of its message
func (msg *MsgHouseDeposit) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgHouseDeposit) ValidateBasic() error {
if msg.Msg == nil {
return errors.ErrInvalidRequest.Wrap("msg is nil")
}
return msg.Msg.ValidateBasic()
}
// EmitEvent emits the event for the message success.
func (msg *MsgHouseDeposit) EmitEvent(ctx *sdk.Context, subAccAddr string, participationIndex uint64, feeAmount sdkmath.Int) {
emitter := utils.NewEventEmitter(ctx, attributeValueCategory)
emitter.AddMsg(typeMsgHouseDeposit, msg.Msg.Creator,
sdk.NewAttribute(attributeKeyDepositCreator, msg.Msg.Creator),
sdk.NewAttribute(attributeKeySubAccDepositor, subAccAddr),
sdk.NewAttribute(attributeKeySubAccDepositFee, feeAmount.String()),
sdk.NewAttribute(attributeKeyDepositMarketUIDParticipantIndex,
strings.Join([]string{msg.Msg.MarketUID, cast.ToString(participationIndex)}, "#"),
),
)
emitter.Emit()
}
// Route returns the module's message router key.
func (*MsgHouseWithdraw) Route() string { return RouterKey }
// Type returns type of its message
func (*MsgHouseWithdraw) Type() string { return typeHouseWithdraw }
func (msg *MsgHouseWithdraw) GetSigners() []sdk.AccAddress {
return msg.Msg.GetSigners()
}
// GetSignBytes returns sortJson form of its message
func (msg *MsgHouseWithdraw) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgHouseWithdraw) ValidateBasic() error {
if msg.Msg == nil {
return errors.ErrInvalidRequest.Wrap("msg is nil")
}
return msg.Msg.ValidateBasic()
}
// EmitEvent emits the event for the message success.
func (msg *MsgHouseWithdraw) EmitEvent(ctx *sdk.Context, subAccAddr string, withdrawalID uint64) {
emitter := utils.NewEventEmitter(ctx, attributeValueCategory)
emitter.AddMsg(typeHouseWithdraw, msg.Msg.Creator,
sdk.NewAttribute(attributeKeyDepositCreator, msg.Msg.Creator),
sdk.NewAttribute(attributeKeySubAccDepositor, subAccAddr),
sdk.NewAttribute(attributeKeyWithdrawalID, cast.ToString(withdrawalID)),
sdk.NewAttribute(attributeKeyWithdrawMarketUIDParticipantIndex,
strings.Join([]string{msg.Msg.MarketUID, cast.ToString(msg.Msg.ParticipationIndex)}, "#"),
),
)
emitter.Emit()
}