/
msg_server_sign_sweep.go
59 lines (48 loc) · 1.91 KB
/
msg_server_sign_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
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) SignSweep(goCtx context.Context, msg *types.MsgSignSweep) (*types.MsgSignSweepResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
btcOracleAddress, e1 := sdk.AccAddressFromBech32(msg.BtcOracleAddress)
// Check if oracle is registered and active
errOracle := k.NyksKeeper.CheckOrchestratorValidatorInSet(ctx, msg.BtcOracleAddress)
if errOracle != nil {
return nil, sdkerrors.Wrap(errOracle, "Could not check orchstrator validator inset")
}
// Check registered reserve address
// _, errReserve := k.VoltKeeper.GetBtcReserveIdByAddress(ctx, msg.ReserveAddress)
// if errReserve != nil {
// return nil, sdkerrors.Wrapf(volttypes.ErrBtcReserveNotFound, fmt.Sprint(msg.ReserveAddress))
// }
sweepSigValue := types.ValidateSignatures(msg.SweepSignature)
if e1 != nil {
return nil, sdkerrors.Wrap(types.ErrInvalid, e1.Error())
} else if sweepSigValue == false {
return nil, sdkerrors.Wrap(types.ErrInvalid, "invalid sweep signature")
}
// check if this signed btc sweep msg is already registered
_, found := k.GetBtcSignSweepMsgWithOracleAddress(ctx, msg.ReserveId, msg.RoundId, btcOracleAddress)
if found {
return nil, sdkerrors.Wrap(types.ErrDuplicate, "Duplicate sweep Request")
}
// set signed btc sweep msg
err := k.SetBtcSignSweepMsg(ctx, btcOracleAddress, msg.ReserveId, msg.RoundId, msg.SignerPublicKey, msg.SweepSignature)
if err != nil {
return nil, err
}
ctx.EventManager().EmitTypedEvent(
&types.EventSignSweep{
Message: msg.Type(),
ReserveId: msg.ReserveId,
RoundId: msg.RoundId,
SignerPublicKey: msg.SignerPublicKey,
SweepSignature: msg.SweepSignature,
BtcOracleAddress: msg.BtcOracleAddress,
},
)
return &types.MsgSignSweepResponse{}, nil
}