Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Jun 27, 2024
1 parent 1a7a7a4 commit e5b144d
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions x/babylon/keeper/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,40 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// SendBeginBlockMsg sends a BeginBlock sudo message to the BTC staking contract via sudo
func (k Keeper) SendBeginBlockMsg(c context.Context) error {
ctx := sdk.UnwrapSDKContext(c)

func (k Keeper) getBTCStakingContractAddr(ctx sdk.Context) sdk.AccAddress {
// get address of the BTC staking contract
addrStr := k.GetParams(ctx).BtcStakingContractAddress
if len(addrStr) == 0 {
// the BTC staking contract address is not set yet, skip sending BeginBlockMsg
return nil
}
addr := sdk.MustAccAddressFromBech32(addrStr)
addr, err := sdk.AccAddressFromBech32(addrStr)
if err != nil {
// Although this is a programming error so we should panic, we emit
// a warning message to minimise the impact on the consumer chain's operation
k.Logger(ctx).Warn("the BTC staking contract address is malformed", "contract", addrStr, "error", err)
return nil
}
if k.wasm.HasContractInfo(ctx, addr) {
// NOTE: it's possible that the default contract address does not correspond to
// any contract. We emit a warning message rather than panic to minimise the
// impact on the consumer chain's operation
k.Logger(ctx).Warn("the BTC staking contract address is not on-chain", "contract", addrStr)
return nil
}

return addr
}

// SendBeginBlockMsg sends a BeginBlock sudo message to the BTC staking contract via sudo
func (k Keeper) SendBeginBlockMsg(c context.Context) error {
ctx := sdk.UnwrapSDKContext(c)

// try to get and parse BTC staking contract
addr := k.getBTCStakingContractAddr(ctx)
if addr == nil {
return nil
}

// construct the sudo message
headerInfo := ctx.HeaderInfo()
Expand All @@ -39,13 +62,11 @@ func (k Keeper) SendBeginBlockMsg(c context.Context) error {
func (k Keeper) SendEndBlockMsg(c context.Context) error {
ctx := sdk.UnwrapSDKContext(c)

// get address of the BTC staking contract
addrStr := k.GetParams(ctx).BtcStakingContractAddress
if len(addrStr) == 0 {
// the BTC staking contract address is not set yet, skip sending EndBlockMsg
// try to get and parse BTC staking contract
addr := k.getBTCStakingContractAddr(ctx)
if addr == nil {
return nil
}
addr := sdk.MustAccAddressFromBech32(addrStr)

// construct the sudo message
headerInfo := ctx.HeaderInfo()
Expand Down

0 comments on commit e5b144d

Please sign in to comment.