Skip to content

Commit

Permalink
refactor: remove seed getter and setter
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Apr 24, 2024
1 parent 4636f64 commit ec8cb6b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
4 changes: 2 additions & 2 deletions x/randomness/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (

// InitGenesis puts data from genesis state into store.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) {
err := k.SetSeed(ctx, data.Seed)
err := k.Seeds.Set(ctx, data.Seed)
if err != nil {
panic(err)
}
}

// ExportGenesis extracts data from store to genesis state.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
seed, err := k.GetSeed(ctx)
seed, err := k.Seeds.Get(ctx)
if err != nil {
return types.GenesisState{}
}
Expand Down
19 changes: 2 additions & 17 deletions x/randomness/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,19 @@ func GetValidatorVRFKeyPrefixFull(consensusAddr sdk.ConsAddress) []byte {

type Keeper struct {
Schema collections.Schema
Seeds collections.Item[string]
Seed collections.Item[string]
ValidatorVRFPubKeys collections.Map[string, cryptotypes.PubKey]
}

func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService) *Keeper {
sb := collections.NewSchemaBuilder(storeService)

return &Keeper{
Seeds: collections.NewItem(sb, SeedPrefix, "seeds", collections.StringValue),
Seed: collections.NewItem(sb, SeedPrefix, "seed", collections.StringValue),
ValidatorVRFPubKeys: collections.NewMap(sb, ValidatorVRFPrefix, "validator-vrf-pubkeys", collections.StringKey, codec.CollInterfaceValue[cryptotypes.PubKey](cdc)),
}
}

// GetSeed returns the seed.
func (k Keeper) GetSeed(ctx sdk.Context) (string, error) {
seed, err := k.Seeds.Get(ctx)
if err != nil {
return "", err
}

return seed, nil
}

// SetSeed stores the seed.
func (k Keeper) SetSeed(ctx sdk.Context, seed string) error {
return k.Seeds.Set(ctx, seed)
}

// GetValidatorVRFPubKey retrieves from the store the VRF public key
// corresponding to the given validator consensus address.
func (k Keeper) GetValidatorVRFPubKey(ctx sdk.Context, consensusAddr string) (cryptotypes.PubKey, error) {
Expand Down
2 changes: 1 addition & 1 deletion x/randomness/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ types.MsgServer = msgServer{}

func (k msgServer) NewSeed(goCtx context.Context, msg *types.MsgNewSeed) (*types.MsgNewSeedResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(goCtx)
err := k.Keeper.SetSeed(sdkCtx, msg.Beta)
err := k.Keeper.Seed.Set(sdkCtx, msg.Beta)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/randomness/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewQuerierImpl(keeper Keeper) *Querier {

func (q Querier) Seed(c context.Context, _ *types.QuerySeedRequest) (*types.QuerySeedResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
seed, err := q.GetSeed(ctx)
seed, err := q.Keeper.Seed.Get(ctx)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ec8cb6b

Please sign in to comment.