Skip to content

Commit

Permalink
BTC staking: events for BTC validator/delegation programs (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis authored Jun 27, 2023
1 parent e917563 commit ab21136
Show file tree
Hide file tree
Showing 3 changed files with 728 additions and 0 deletions.
18 changes: 18 additions & 0 deletions proto/babylon/btcstaking/v1/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";
package babylon.btcstaking.v1;

import "babylon/btcstaking/v1/btcstaking.proto";

option go_package = "github.com/babylonchain/babylon/x/btcstaking/types";

// EventNewBTCValidator is the event emitted when a BTC validator is created
message EventNewBTCValidator { BTCValidator btc_val = 1; }

// EventNewBTCDelegation is the event emitted when a BTC delegation is created
// NOTE: the BTC delegation is not active thus does not have voting power yet
// only after it receives a jury signature it becomes activated and has voting power
message EventNewBTCDelegation { BTCDelegation btc_del = 1; }

// EventActivateBTCDelegation is the event emitted when jury activates a BTC delegation
// such that the BTC delegation starts to have voting power in its timelock period
message EventActivateBTCDelegation { BTCDelegation btc_del = 1; }
18 changes: 18 additions & 0 deletions x/btcstaking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func (ms msgServer) CreateBTCValidator(goCtx context.Context, req *types.MsgCrea
}
ms.setBTCValidator(ctx, &btcVal)

// notify subscriber
if err := ctx.EventManager().EmitTypedEvent(&types.EventNewBTCValidator{BtcVal: &btcVal}); err != nil {
return nil, err
}

return &types.MsgCreateBTCValidatorResponse{}, nil
}

Expand Down Expand Up @@ -134,6 +139,9 @@ func (ms msgServer) CreateBTCDelegation(goCtx context.Context, req *types.MsgCre
}

// all good, construct BTCDelegation and insert BTC delegation
// NOTE: the BTC delegation does not have voting power yet. It will
// have voting power only when 1) its corresponding staking tx is k-deep,
// and 2) it receives a jury signature
newBTCDel := &types.BTCDelegation{
BabylonPk: req.BabylonPk,
BtcPk: delBTCPK,
Expand All @@ -149,6 +157,11 @@ func (ms msgServer) CreateBTCDelegation(goCtx context.Context, req *types.MsgCre
}
ms.setBTCDelegation(ctx, newBTCDel)

// notify subscriber
if err := ctx.EventManager().EmitTypedEvent(&types.EventNewBTCDelegation{BtcDel: newBTCDel}); err != nil {
return nil, err
}

return &types.MsgCreateBTCDelegationResponse{}, nil
}

Expand Down Expand Up @@ -193,5 +206,10 @@ func (ms msgServer) AddJurySig(goCtx context.Context, req *types.MsgAddJurySig)
btcDel.JurySig = req.Sig
ms.setBTCDelegation(ctx, btcDel)

// notify subscriber
if err := ctx.EventManager().EmitTypedEvent(&types.EventActivateBTCDelegation{BtcDel: btcDel}); err != nil {
return nil, err
}

return &types.MsgAddJurySigResponse{}, nil
}
Loading

0 comments on commit ab21136

Please sign in to comment.