Skip to content

Commit

Permalink
add subscription genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
Yarom Swisa authored and Yarom Swisa committed Jun 18, 2023
1 parent 5cec4d9 commit ee7b1b7
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 12 deletions.
2 changes: 2 additions & 0 deletions proto/subscription/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package lavanet.lava.subscription;

import "gogoproto/gogo.proto";
import "subscription/params.proto";
import "subscription/subscription.proto";
// this line is used by starport scaffolding # genesis/proto/import

option go_package = "github.com/lavanet/lava/x/subscription/types";

// GenesisState defines the subscription module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated Subscription subscriptions = 2 [(gogoproto.nullable) = false];
// this line is used by starport scaffolding # genesis/proto/state
}
3 changes: 2 additions & 1 deletion x/subscription/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
// this line is used by starport scaffolding # genesis/module/init
k.SetParams(ctx, genState.Params)
k.SetSubscriptions(ctx, genState.Subscriptions)
}

// ExportGenesis returns the capability module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)

genesis.Subscriptions = k.GetAllSubscription(ctx)
// this line is used by starport scaffolding # genesis/module/export

return genesis
Expand Down
7 changes: 7 additions & 0 deletions x/subscription/keeper/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func (k Keeper) SetSubscription(ctx sdk.Context, sub types.Subscription) {
store.Set(types.SubscriptionKey(sub.Consumer), b)
}

// SetSubscriptions sets subscriptions (of a consumer) in the store
func (k Keeper) SetSubscriptions(ctx sdk.Context, subs []types.Subscription) {
for _, s := range subs {
k.SetSubscription(ctx, s)
}
}

// GetSubscription returns the subscription of a given consumer
func (k Keeper) GetSubscription(ctx sdk.Context, consumer string) (val types.Subscription, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.SubscriptionKeyPrefix))
Expand Down
86 changes: 75 additions & 11 deletions x/subscription/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ee7b1b7

Please sign in to comment.