forked from babylonchain/babylon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_server.go
55 lines (41 loc) · 1.49 KB
/
msg_server.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
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
epochingtypes "github.com/babylonchain/babylon/x/epoching/types"
"github.com/babylonchain/babylon/x/checkpointing/types"
)
type msgServer struct {
k Keeper
}
// NewMsgServerImpl returns an implementation of the MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{keeper}
}
var _ types.MsgServer = msgServer{}
// WrappedCreateValidator registers validator's BLS public key
// and forwards corresponding MsgCreateValidator message to
// the epoching module
func (m msgServer) WrappedCreateValidator(goCtx context.Context, msg *types.MsgWrappedCreateValidator) (*types.MsgWrappedCreateValidatorResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
// stateless checks on the inside `MsgCreateValidator` msg
if err := m.k.epochingKeeper.CheckMsgCreateValidator(ctx, msg.MsgCreateValidator); err != nil {
return nil, err
}
valAddr, err := sdk.ValAddressFromBech32(msg.MsgCreateValidator.ValidatorAddress)
if err != nil {
return nil, err
}
// store BLS public key
err = m.k.CreateRegistration(ctx, *msg.Key.Pubkey, valAddr)
if err != nil {
return nil, err
}
// enqueue the msg into the epoching module
queueMsg := epochingtypes.QueuedMessage{
Msg: &epochingtypes.QueuedMessage_MsgCreateValidator{MsgCreateValidator: msg.MsgCreateValidator},
}
m.k.epochingKeeper.EnqueueMsg(ctx, queueMsg)
return &types.MsgWrappedCreateValidatorResponse{}, err
}