mukan-core/x/poj/keeper/keeper.go
Mukan Erkin Törük 02226c4bd9
Some checks are pending
/ might_release (push) Waiting to run
initial: sovereign Mukan Network fork
2026-05-11 03:18:23 +03:00

91 lines
2.1 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/poj/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]
MinerStates collections.Map[string, types.MinerState]
BlockWinners collections.Map[int64, string]
bankKeeper types.BankKeeper
authKeeper types.AuthKeeper
stakingKeeper types.StakingKeeper
}
func NewKeeper(
storeService corestore.KVStoreService,
cdc codec.Codec,
addressCodec address.Codec,
authority []byte,
bankKeeper types.BankKeeper,
authKeeper types.AuthKeeper,
stakingKeeper types.StakingKeeper,
) 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,
bankKeeper: bankKeeper,
authKeeper: authKeeper,
stakingKeeper: stakingKeeper,
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)),
MinerStates: collections.NewMap(
sb,
types.MinerStateKeyPrefix,
"miner_states",
collections.StringKey,
codec.CollValue[types.MinerState](cdc),
),
BlockWinners: collections.NewMap(
sb,
types.BlockWinnerKeyPrefix,
"block_winners",
collections.Int64Key,
collections.StringValue,
),
}
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
}
// GetAddressCodec returns the module's address codec.
func (k Keeper) GetAddressCodec() address.Codec {
return k.addressCodec
}