Skip to content

Commit

Permalink
Removed unnecessary methods from subscription keeper
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Aug 12, 2021
1 parent dc299e9 commit 0fdab06
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 88 deletions.
1 change: 1 addition & 0 deletions cmd/sentinelhub/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
keys.Commands(hub.DefaultNodeHome),
)
}

func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
}
Expand Down
3 changes: 1 addition & 2 deletions export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"encoding/json"
"log"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

func (a *App) ExportAppStateAndValidators(
Expand Down
5 changes: 1 addition & 4 deletions x/plan/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, state types.GenesisState) {
}
}

var (
count uint64 = 0
)

count := uint64(0)
for _, item := range state {
if item.Plan.Id > count {
count = item.Plan.Id
Expand Down
1 change: 0 additions & 1 deletion x/session/expected/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type NodeKeeper interface {
}

type SubscriptionKeeper interface {
HasSubscriptionForNode(ctx sdk.Context, address hubtypes.NodeAddress, id uint64) bool
GetSubscription(ctx sdk.Context, id uint64) (subscriptiontypes.Subscription, bool)
GetActiveSubscriptionsForAddress(ctx sdk.Context, address sdk.AccAddress, skip, limit int64) subscriptiontypes.Subscriptions

Expand Down
4 changes: 0 additions & 4 deletions x/session/keeper/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ func (k *Keeper) GetNode(ctx sdk.Context, address hubtypes.NodeAddress) (nodetyp
return k.node.GetNode(ctx, address)
}

func (k *Keeper) HasSubscriptionForNode(ctx sdk.Context, address hubtypes.NodeAddress, id uint64) bool {
return k.subscription.HasSubscriptionForNode(ctx, address, id)
}

func (k *Keeper) GetSubscription(ctx sdk.Context, id uint64) (subscriptiontypes.Subscription, bool) {
return k.subscription.GetSubscription(ctx, id)
}
Expand Down
7 changes: 1 addition & 6 deletions x/subscription/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ import (

func InitGenesis(ctx sdk.Context, k keeper.Keeper, state *types.GenesisState) {
k.SetParams(ctx, state.Params)

for _, item := range state.Subscriptions {
k.SetSubscription(ctx, item.Subscription)

if item.Subscription.Id == 0 {
k.SetSubscriptionForNode(ctx, item.Subscription.GetNode(), item.Subscription.Id)
} else {
k.SetSubscriptionForPlan(ctx, item.Subscription.Plan, item.Subscription.Id)
}

for _, quota := range item.Quotas {
k.SetQuota(ctx, item.Subscription.Id, quota)

Expand Down
3 changes: 0 additions & 3 deletions x/subscription/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ func (k *msgServer) MsgSubscribeToNode(c context.Context, msg *types.MsgSubscrib
Status: hubtypes.StatusActive,
StatusAt: ctx.BlockTime(),
}
subscriptionNode = subscription.GetNode()
)

k.SetSubscription(ctx, subscription)
k.SetSubscriptionForNode(ctx, subscriptionNode, subscription.Id)
ctx.EventManager().EmitTypedEvent(
&types.EventSubscribeToNode{
Id: subscription.Id,
Expand Down Expand Up @@ -159,7 +157,6 @@ func (k *msgServer) MsgSubscribeToPlan(c context.Context, msg *types.MsgSubscrib
)

k.SetSubscription(ctx, subscription)
k.SetSubscriptionForPlan(ctx, subscription.Plan, subscription.Id)
k.SetInactiveSubscriptionAt(ctx, subscription.Expiry, subscription.Id)
ctx.EventManager().EmitTypedEvent(
&types.EventSubscribeToPlan{
Expand Down
68 changes: 0 additions & 68 deletions x/subscription/keeper/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,74 +74,6 @@ func (k *Keeper) GetSubscriptions(ctx sdk.Context, skip, limit int64) (items typ
return items
}

func (k *Keeper) SetSubscriptionForNode(ctx sdk.Context, address hubtypes.NodeAddress, id uint64) {
key := types.SubscriptionForNodeKey(address, id)
value := k.cdc.MustMarshalBinaryBare(&protobuf.BoolValue{Value: true})

store := k.Store(ctx)
store.Set(key, value)
}

func (k *Keeper) HasSubscriptionForNode(ctx sdk.Context, address hubtypes.NodeAddress, id uint64) bool {
key := types.SubscriptionForNodeKey(address, id)

store := k.Store(ctx)
return store.Has(key)
}

func (k *Keeper) GetSubscriptionsForNode(ctx sdk.Context, address hubtypes.NodeAddress, skip, limit int64) (items types.Subscriptions) {
var (
store = k.Store(ctx)
iter = hubtypes.NewPaginatedIterator(
sdk.KVStorePrefixIterator(store, types.GetSubscriptionForNodeKeyPrefix(address)),
)
)

defer iter.Close()

iter.Skip(skip)
iter.Limit(limit, func(iter sdk.Iterator) {
item, _ := k.GetSubscription(ctx, types.IDFromSubscriptionForNodeKey(iter.Key()))
items = append(items, item)
})

return items
}

func (k *Keeper) SetSubscriptionForPlan(ctx sdk.Context, plan, id uint64) {
key := types.SubscriptionForPlanKey(plan, id)
value := k.cdc.MustMarshalBinaryBare(&protobuf.BoolValue{Value: true})

store := k.Store(ctx)
store.Set(key, value)
}

func (k *Keeper) HasSubscriptionForPlan(ctx sdk.Context, plan, id uint64) bool {
key := types.SubscriptionForPlanKey(plan, id)

store := k.Store(ctx)
return store.Has(key)
}

func (k *Keeper) GetSubscriptionsForPlan(ctx sdk.Context, plan uint64, skip, limit int64) (items types.Subscriptions) {
var (
store = k.Store(ctx)
iter = hubtypes.NewPaginatedIterator(
sdk.KVStorePrefixIterator(store, sdk.Uint64ToBigEndian(plan)),
)
)

defer iter.Close()

iter.Skip(skip)
iter.Limit(limit, func(iter sdk.Iterator) {
item, _ := k.GetSubscription(ctx, types.IDFromSubscriptionForPlanKey(iter.Key()))
items = append(items, item)
})

return items
}

func (k *Keeper) SetActiveSubscriptionForAddress(ctx sdk.Context, address sdk.AccAddress, id uint64) {
key := types.ActiveSubscriptionForAddressKey(address, id)
value := k.cdc.MustMarshalBinaryBare(&protobuf.BoolValue{Value: true})
Expand Down

0 comments on commit 0fdab06

Please sign in to comment.