Path: blob/main/docs/versioned_docs/version-v0.25/guide/04-nameservice/04-keeper.md
1709 views
------Keeper
The main core of a Cosmos SDK module is a piece called the keeper. The keeper handles interactions with the store, has references to other keepers for cross-module interactions, and contains most of the core functionality of a module.
Define Keepers for the Nameservice Module
Keepers are module-specific. Keeper is part of the Cosmos SDK that is responsible for writing data to the store. Each module uses its own keeper.
In this section, define the keepers that are required by the nameservice module:
Buy name
Set name
Delete name
Buy Name
To define the keeper for the buy name transaction, add this code to the x/nameservice/keeper/msg_server_buy_name.go file:
When you scaffolded the nameservice module you used --dep bank to specify a dependency between the nameservice and bank modules.
This dependency automatically created an expected_keepers.go file with a BankKeeper interface.
The BuyName transaction uses SendCoins and SendCoinsFromAccountToModule methods from the bank module.
Edit the x/nameservice/types/expected_keepers.go file to add SendCoins and SendCoinsFromAccountToModule to be able to use it in the keeper methods of the nameservice module.
Set Name
To define the keeper for the set name transaction, add this code to the x/nameservice/keeper/msg_server_set_name.go file:
Delete Name
To define the keeper for the delete name transaction, add this code to the x/nameservice/keeper/msg_server_delete_name.go file: