/
message_broadcast_tx_refund.go
58 lines (48 loc) · 1.49 KB
/
message_broadcast_tx_refund.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/twilight-project/nyks/x/forks/types"
)
const TypeMsgBroadcastTxRefund = "broadcast_tx_refund"
var _ sdk.Msg = &MsgBroadcastTxRefund{}
func NewMsgBroadcastTxRefund(reserveId uint64, roundId uint64, signedRefundTx string, judgeAddress string) *MsgBroadcastTxRefund {
return &MsgBroadcastTxRefund{
ReserveId: reserveId,
RoundId: roundId,
SignedRefundTx: signedRefundTx,
JudgeAddress: judgeAddress,
}
}
func (msg *MsgBroadcastTxRefund) Route() string {
return RouterKey
}
func (msg *MsgBroadcastTxRefund) Type() string {
return TypeMsgBroadcastTxRefund
}
func (msg *MsgBroadcastTxRefund) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.JudgeAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}
func (msg *MsgBroadcastTxRefund) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgBroadcastTxRefund) ValidateBasic() error {
// Validate ReserveId
if msg.ReserveId == 0 {
return sdkerrors.Wrapf(types.ErrInvalid, "Reserve address cannot be empty")
}
// Validate RoundId
if msg.RoundId == 0 {
return sdkerrors.Wrapf(types.ErrInvalid, "Round ID cannot be empty")
}
_, err := sdk.AccAddressFromBech32(msg.JudgeAddress)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
return nil
}