mukan-ibc/docs/versioned_docs/version-v8.5.x/01-ibc/03-apps/04-keeper.md
Mukan Erkin Törük 6852832fe8
Some checks failed
CodeQL / Analyze (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
Buf-Push / push (push) Has been cancelled
initial: sovereign Mukan Network fork
2026-05-11 03:18:28 +03:00

2.9 KiB

title sidebar_label sidebar_position slug
Keeper Keeper 4 /ibc/apps/keeper

Keeper

:::note Synopsis Learn how to implement the IBC Module keeper. :::

:::note

Pre-requisite readings

::: In the previous sections, on channel handshake callbacks and port binding in InitGenesis, a reference was made to keeper methods that need to be implemented when creating a custom IBC module. Below is an overview of how to define an IBC module's keeper.

Note that some code has been left out for clarity, to get a full code overview, please refer to the transfer module's keeper in the ibc-go repo.

// Keeper defines the IBC app module keeper
type Keeper struct {
  storeKey   sdk.StoreKey
  cdc        codec.BinaryCodec
  paramSpace paramtypes.Subspace

  channelKeeper types.ChannelKeeper
  portKeeper    types.PortKeeper
  scopedKeeper  capabilitykeeper.ScopedKeeper

  // ... additional according to custom logic
}

// NewKeeper creates a new IBC app module Keeper instance
func NewKeeper(
  // args
) Keeper {
  // ...

  return Keeper{
    cdc:           cdc,
    storeKey:      key,
    paramSpace:    paramSpace,

    channelKeeper: channelKeeper,
    portKeeper:    portKeeper,
    scopedKeeper:  scopedKeeper,

    // ... additional according to custom logic
  }
}

// hasCapability checks if the IBC app module owns the port capability for the desired port
func (k Keeper) hasCapability(ctx sdk.Context, portID string) bool {
  _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID))
  return ok
}

// BindPort defines a wrapper function for the port Keeper's function in
// order to expose it to module's InitGenesis function
func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
  cap := k.portKeeper.BindPort(ctx, portID)
  return k.ClaimCapability(ctx, cap, host.PortPath(portID))
}

// GetPort returns the portID for the IBC app module. Used in ExportGenesis
func (k Keeper) GetPort(ctx sdk.Context) string {
  store := ctx.KVStore(k.storeKey)
  return string(store.Get(types.PortKey))
}

// SetPort sets the portID for the IBC app module. Used in InitGenesis
func (k Keeper) SetPort(ctx sdk.Context, portID string) {
  store := ctx.KVStore(k.storeKey)
  store.Set(types.PortKey, []byte(portID))
}

// AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function
func (k Keeper) AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool {
  return k.scopedKeeper.AuthenticateCapability(ctx, cap, name)
}

// ClaimCapability allows the IBC app module to claim a capability that core IBC
// passes to it
func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error {
  return k.scopedKeeper.ClaimCapability(ctx, cap, name)
}

// ... additional according to custom logic