/
msg_server_broadcast_tx_sweep.go
47 lines (38 loc) · 1.4 KB
/
msg_server_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
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/twilight-project/nyks/x/bridge/types"
)
func (k msgServer) BroadcastTxSweep(goCtx context.Context, msg *types.MsgBroadcastTxSweep) (*types.MsgBroadcastTxSweepResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
judgeAddress, err := sdk.AccAddressFromBech32(msg.JudgeAddress)
if err != nil {
return nil, sdkerrors.Wrap(err, "Could not parse judge address")
}
// check if this broadcast sweep message is already registered
_, foundDuplicate := k.GetBtcBroadcastTxSweepMsg(ctx, msg.ReserveId, msg.RoundId)
if foundDuplicate {
return nil, sdkerrors.Wrap(types.ErrDuplicate, "Duplicate broadcast sweep request")
}
found := k.CheckJudgeValidatorInSet(ctx, judgeAddress)
if found == false {
return nil, sdkerrors.Wrap(types.ErrJudgeValidatorNotFound, "Could not check judge validator inset")
}
// set broadcast refund message
errSet := k.SetBtcBroadcastTxSweepMsg(ctx, msg.ReserveId, msg.RoundId, judgeAddress, msg.SignedSweepTx)
if errSet != nil {
return nil, errSet
}
ctx.EventManager().EmitTypedEvent(
&types.EventBroadcastTxSweep{
Message: msg.Type(),
ReserveId: msg.ReserveId,
RoundId: msg.RoundId,
SignedSweepTx: msg.SignedSweepTx,
JudgeAddress: msg.JudgeAddress,
},
)
return &types.MsgBroadcastTxSweepResponse{}, nil
}