Path: blob/main/docs/versioned_docs/version-v0.25/guide/05-scavenge/07-keeper.md
1007 views
---
---
Keeper
Keepers are a Cosmos SDK abstraction whose role is to manage access to the subset of the state defined by various modules.
Create scavenge
Make the required changes in the x/scavenge/keeper/msg_server_submit_scavenge.go
file so the create scavenge method can manage the following:
Check that a scavenge with a given solution hash doesn't exist
Send tokens from the scavenge creator account to a module account
Write the scavenge to the store
Notice the use of moduleAcct
. This account is not controlled by a public key pair, but is a reference to an account that is owned by this actual module. moduleAcct
is used to hold the bounty reward that is attached to a scavenge until that scavenge has been solved, at which point the bounty is paid to the account who solved the scavenge.
SubmitScavenge
uses the SendCoins
method from the bank
module. When you scaffolded the scavenge module, you used --dep bank
to specify a dependency between the scavenge
and bank
modules. This dependency automatically created an expected_keepers.go
file with a BankKeeper
interface.
To use the BankKeeper
interface in the keeper methods of the scavenge
module, add SendCoins
to the x/scavenge/types/expected_keepers.go
file:
Commit Solution
Make the required changes in the x/scavenge/keeper/msg_server_commit_solution.go
file so the commit solution method can manage the following:
Check that commit with a given hash doesn't exist in the store
Write a new commit to the store
Reveal Solution
Make the required changes in the x/scavenge/keeper/msg_server_reveal_solution.go
file so the reveal solution method can manage the following:
Check that a commit with a given hash exists in the store
Check that a scavenge with a given solution hash exists in the store
Check that the scavenge hasn't already been solved
Send tokens from the module account to the account that revealed the correct anwer
Write the updated scavenge to the store