Skip to content

Commit

Permalink
Add staking tx to the creation event
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradStaniec committed Nov 18, 2024
1 parent 2d423a8 commit 4173251
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 242 deletions.
26 changes: 10 additions & 16 deletions proto/babylon/btcstaking/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -144,33 +144,27 @@ enum FinalityProviderStatus {
// EventBTCDelegationCreated is the event emitted when a BTC delegation is created
// on the Babylon chain
message EventBTCDelegationCreated {
// staking_tx_hash is the hash of the staking tx.
// It uniquely identifies a BTC delegation
string staking_tx_hash = 1 [(amino.dont_omitempty) = true];
// staking_output_pk_script is the hex encoded PK script of the staking output
string staking_output_pk_script = 2 [(amino.dont_omitempty) = true];
// staking_tx_hex is the hex encoded staking tx
string staking_tx_hex = 1 [(amino.dont_omitempty) = true];
// staking_output_index is the index of the staking output in the staking tx
string staking_output_index = 3 [(amino.dont_omitempty) = true];
string staking_output_index = 2 [(amino.dont_omitempty) = true];
// version of the params used to validate the delegation
string params_version = 4 [(amino.dont_omitempty) = true];
string params_version = 3 [(amino.dont_omitempty) = true];
// finality_provider_btc_pks_hex is the list of hex str of Bitcoin secp256k1 PK of
// the finality providers that this BTC delegation delegates to
// the PK follows encoding in BIP-340 spec
repeated string finality_provider_btc_pks_hex = 5 [(amino.dont_omitempty) = true];
repeated string finality_provider_btc_pks_hex = 4 [(amino.dont_omitempty) = true];
// staker_btc_pk_hex is the hex str of Bitcoin secp256k1 PK of the staker that
// creates this BTC delegation the PK follows encoding in BIP-340 spec
string staker_btc_pk_hex = 6 [(amino.dont_omitempty) = true];
string staker_btc_pk_hex = 5 [(amino.dont_omitempty) = true];
// staking_time is the timelock of the staking tx specified in the BTC script
string staking_time = 7 [(amino.dont_omitempty) = true];
// staking_amount is the total amount of BTC stake in this delegation
// quantified in satoshi
string staking_amount = 8 [(amino.dont_omitempty) = true];
string staking_time = 6 [(amino.dont_omitempty) = true];
// unbonding_time is the time is timelock on unbonding tx chosen by the staker
string unbonding_time = 9 [(amino.dont_omitempty) = true];
string unbonding_time = 7 [(amino.dont_omitempty) = true];
// unbonding_tx is hex encoded bytes of the unsigned unbonding tx
string unbonding_tx = 10 [(amino.dont_omitempty) = true];
string unbonding_tx = 8 [(amino.dont_omitempty) = true];
// new_state of the BTC delegation
string new_state = 11 [(amino.dont_omitempty) = true];
string new_state = 9 [(amino.dont_omitempty) = true];
}

// EventCovenantSignatureReceived is the event emitted when a covenant committee
Expand Down
1 change: 0 additions & 1 deletion x/btcstaking/keeper/btc_delegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (k Keeper) AddBTCDelegation(
k.setBTCDelegation(ctx, btcDel)

if err := ctx.EventManager().EmitTypedEvents(types.NewBtcDelCreationEvent(
stakingTxHash.String(),
btcDel,
)); err != nil {
panic(fmt.Errorf("failed to emit events for the new pending BTC delegation: %w", err))
Expand Down
5 changes: 1 addition & 4 deletions x/btcstaking/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,15 @@ func NewInclusionProofEvent(
}

func NewBtcDelCreationEvent(
stakingTxHash string,
btcDel *BTCDelegation,
) *EventBTCDelegationCreated {
return &EventBTCDelegationCreated{
StakingTxHash: stakingTxHash,
StakingOutputPkScript: hex.EncodeToString(btcDel.MustGetStakingTx().TxOut[btcDel.StakingOutputIdx].PkScript),
StakingTxHex: hex.EncodeToString(btcDel.StakingTx),
StakingOutputIndex: strconv.FormatUint(uint64(btcDel.StakingOutputIdx), 10),
ParamsVersion: strconv.FormatUint(uint64(btcDel.ParamsVersion), 10),
FinalityProviderBtcPksHex: btcDel.FinalityProviderKeys(),
StakerBtcPkHex: btcDel.BtcPk.MarshalHex(),
StakingTime: strconv.FormatUint(uint64(btcDel.StakingTime), 10),
StakingAmount: strconv.FormatUint(btcDel.TotalSat, 10),
UnbondingTime: strconv.FormatUint(uint64(btcDel.UnbondingTime), 10),
UnbondingTx: hex.EncodeToString(btcDel.BtcUndelegation.UnbondingTx),
NewState: BTCDelegationStatus_PENDING.String(),
Expand Down
Loading

0 comments on commit 4173251

Please sign in to comment.