-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_broadcast_tx_sweep.go
64 lines (52 loc) · 1.62 KB
/
message_broadcast_tx_sweep.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
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 TypeMsgBroadcastTxSweep = "broadcast_refund"
var _ sdk.Msg = &MsgBroadcastTxSweep{}
func NewMsgBroadcastTxSweep(reserveId uint64, roundId uint64, signedSweepTx string, judgeAddress string) *MsgBroadcastTxSweep {
return &MsgBroadcastTxSweep{
ReserveId: reserveId,
RoundId: roundId,
SignedSweepTx: signedSweepTx,
JudgeAddress: judgeAddress,
}
}
func (msg *MsgBroadcastTxSweep) Route() string {
return RouterKey
}
func (msg *MsgBroadcastTxSweep) Type() string {
return TypeMsgBroadcastTxSweep
}
func (msg *MsgBroadcastTxSweep) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.JudgeAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}
func (msg *MsgBroadcastTxSweep) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgBroadcastTxSweep) 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 judge address (%s)", err)
}
err = ValidateBtcTransaction(msg.SignedSweepTx)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid signed sweep tx (%s)", err)
}
return nil
}