60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package keeper
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"cosmossdk.io/collections"
|
|
"cosmossdk.io/core/address"
|
|
corestore "cosmossdk.io/core/store"
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
"mukan/x/mukan/types"
|
|
)
|
|
|
|
type Keeper struct {
|
|
storeService corestore.KVStoreService
|
|
cdc codec.Codec
|
|
addressCodec address.Codec
|
|
// Address capable of executing a MsgUpdateParams message.
|
|
// Typically, this should be the x/gov module account.
|
|
authority []byte
|
|
|
|
Schema collections.Schema
|
|
Params collections.Item[types.Params]
|
|
}
|
|
|
|
func NewKeeper(
|
|
storeService corestore.KVStoreService,
|
|
cdc codec.Codec,
|
|
addressCodec address.Codec,
|
|
authority []byte,
|
|
|
|
) Keeper {
|
|
if _, err := addressCodec.BytesToString(authority); err != nil {
|
|
panic(fmt.Sprintf("invalid authority address %s: %s", authority, err))
|
|
}
|
|
|
|
sb := collections.NewSchemaBuilder(storeService)
|
|
|
|
k := Keeper{
|
|
storeService: storeService,
|
|
cdc: cdc,
|
|
addressCodec: addressCodec,
|
|
authority: authority,
|
|
|
|
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.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() []byte {
|
|
return k.authority
|
|
}
|