laconicd/x/onboarding/keeper/keeper.go
Isha Venikar 7369264f0a Create skeleton for onboarding module (#2)
* Add proto files for onboarding module

* Add general files for onboarding module

* Add keeper files for onboarding module

* Add module files for onboarding module

* Update proto files

* Add generated proto bindings

* Use Keeper pointer in depinject

* Fix lint errors
2024-07-16 09:25:39 +05:30

55 lines
1.3 KiB
Go

package keeper
import (
"fmt"
"cosmossdk.io/collections"
"cosmossdk.io/core/address"
storetypes "cosmossdk.io/core/store"
"github.com/cosmos/cosmos-sdk/codec"
"git.vdb.to/cerc-io/laconicd/x/onboarding"
)
type Keeper struct {
cdc codec.BinaryCodec
addressCodec address.Codec
// authority is the address capable of executing a MsgUpdateParams and other authority-gated message.
// typically, this should be the x/gov module account.
authority string
// state management
Schema collections.Schema
Params collections.Item[onboarding.Params]
}
// NewKeeper creates a new Keeper instance
func NewKeeper(cdc codec.BinaryCodec, addressCodec address.Codec, storeService storetypes.KVStoreService, authority string) *Keeper {
if _, err := addressCodec.StringToBytes(authority); err != nil {
panic(fmt.Errorf("invalid authority address: %w", err))
}
sb := collections.NewSchemaBuilder(storeService)
k := Keeper{
cdc: cdc,
addressCodec: addressCodec,
authority: authority,
Params: collections.NewItem(sb, onboarding.ParamsKey, "params", codec.CollValue[onboarding.Params](cdc)),
}
schema, err := sb.Build()
if err != nil {
panic(err)
}
k.Schema = schema
return &k
}
// GetAuthority returns the module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}