Skip to content

Commit

Permalink
Update sudo handlers call
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Oct 9, 2024
1 parent 9f5390e commit 7706fff
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions x/babylon/keeper/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,37 @@ func (k Keeper) getBTCStakingContractAddr(ctx sdk.Context) sdk.AccAddress {
return addr
}

// SendBeginBlockMsg sends a BeginBlock sudo message to the BTC staking contract via sudo
func (k Keeper) getBTCFinalityContractAddr(ctx sdk.Context) sdk.AccAddress {
// get address of the BTC finality contract
addrStr := k.GetParams(ctx).BtcFinalityContractAddress
if len(addrStr) == 0 {
// the BTC finality contract address is not set yet, skip sending BeginBlockMsg
return nil
}
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 finality 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 finality contract address is not on-chain", "contract", addrStr)
return nil
}

return addr
}

// SendBeginBlockMsg sends a BeginBlock sudo message to the BTC finality 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)
// try to get and parse BTC finality contract
addr := k.getBTCFinalityContractAddr(ctx)
if addr == nil {
return nil
}
Expand All @@ -58,12 +83,12 @@ func (k Keeper) SendBeginBlockMsg(c context.Context) error {
return k.doSudoCall(ctx, addr, msg)
}

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

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

0 comments on commit 7706fff

Please sign in to comment.