Skip to content

Commit

Permalink
Fixed store query issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Jul 27, 2023
1 parent fe7faaf commit fff3c14
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions x/node/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ func (q *queryServer) QueryNodesForPlan(c context.Context, req *types.QueryNodes
var (
items types.Nodes
ctx = sdk.UnwrapSDKContext(c)
store = prefix.NewStore(q.Store(ctx), types.GetNodeForPlanKeyPrefix(req.Id))
)

store := prefix.NewStore(q.Store(ctx), types.GetNodeForPlanKeyPrefix(req.Id))
pagination, err := query.FilteredPaginate(store, req.Pagination, func(key, _ []byte, accumulate bool) (bool, error) {
if !accumulate {
return false, nil
Expand All @@ -105,7 +105,7 @@ func (q *queryServer) QueryNodesForPlan(c context.Context, req *types.QueryNodes
return false, fmt.Errorf("node for key %X does not exist", key)
}

if req.Status.IsOneOf(item.Status, hubtypes.StatusUnspecified) {
if req.Status.Equal(hubtypes.StatusUnspecified) || item.Status.Equal(req.Status) {
items = append(items, item)
return true, nil
}
Expand Down
4 changes: 2 additions & 2 deletions x/plan/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ func (q *queryServer) QueryPlansForProvider(c context.Context, req *types.QueryP
var (
items types.Plans
ctx = sdk.UnwrapSDKContext(c)
store = prefix.NewStore(q.Store(ctx), types.GetPlanForProviderKeyPrefix(addr))
)

store := prefix.NewStore(q.Store(ctx), types.GetPlanForProviderKeyPrefix(addr))
pagination, err := query.FilteredPaginate(store, req.Pagination, func(key, _ []byte, accumulate bool) (bool, error) {
if !accumulate {
return false, nil
Expand All @@ -105,7 +105,7 @@ func (q *queryServer) QueryPlansForProvider(c context.Context, req *types.QueryP
return false, fmt.Errorf("plan for key %X does not exist", key)
}

if req.Status.IsOneOf(item.Status, hubtypes.StatusUnspecified) {
if req.Status.Equal(hubtypes.StatusUnspecified) || item.Status.Equal(req.Status) {
items = append(items, item)
return true, nil
}
Expand Down
8 changes: 4 additions & 4 deletions x/session/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (q *queryServer) QuerySessionsForAccount(c context.Context, req *types.Quer
)

pagination, err := query.Paginate(store, req.Pagination, func(key, _ []byte) error {
item, found := q.GetSession(ctx, types.IDFromSessionForAccountKey(key))
item, found := q.GetSession(ctx, sdk.BigEndianToUint64(key))
if !found {
return fmt.Errorf("session for key %X does not exist", key)
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func (q *queryServer) QuerySessionsForNode(c context.Context, req *types.QuerySe
)

pagination, err := query.Paginate(store, req.Pagination, func(key, _ []byte) error {
item, found := q.GetSession(ctx, types.IDFromSessionForNodeKey(key))
item, found := q.GetSession(ctx, sdk.BigEndianToUint64(key))
if !found {
return fmt.Errorf("session for key %X does not exist", key)
}
Expand Down Expand Up @@ -147,7 +147,7 @@ func (q *queryServer) QuerySessionsForSubscription(c context.Context, req *types
)

pagination, err := query.Paginate(store, req.Pagination, func(key, _ []byte) error {
item, found := q.GetSession(ctx, types.IDFromSessionForSubscriptionKey(key))
item, found := q.GetSession(ctx, sdk.BigEndianToUint64(key))
if !found {
return fmt.Errorf("session for key %X does not exist", key)
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func (q *queryServer) QuerySessionsForAllocation(c context.Context, req *types.Q
)

pagination, err := query.Paginate(store, req.Pagination, func(key, _ []byte) error {
item, found := q.GetSession(ctx, types.IDFromSessionForAllocationKey(key))
item, found := q.GetSession(ctx, sdk.BigEndianToUint64(key))
if !found {
return fmt.Errorf("session for key %X does not exist", key)
}
Expand Down
12 changes: 6 additions & 6 deletions x/subscription/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (q *queryServer) QuerySubscriptionsForAccount(c context.Context, req *types
)

pagination, err := query.Paginate(store, req.Pagination, func(key, _ []byte) error {
v, found := q.GetSubscription(ctx, types.IDFromSubscriptionForAccountKey(key))
v, found := q.GetSubscription(ctx, sdk.BigEndianToUint64(key))
if !found {
return fmt.Errorf("subscription for key %X does not exist", key)
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func (q *queryServer) QuerySubscriptionsForNode(c context.Context, req *types.Qu
)

pagination, err := query.Paginate(store, req.Pagination, func(key, _ []byte) error {
v, found := q.GetSubscription(ctx, types.IDFromSubscriptionForNodeKey(key))
v, found := q.GetSubscription(ctx, sdk.BigEndianToUint64(key))
if !found {
return fmt.Errorf("subscription for key %X does not exist", key)
}
Expand Down Expand Up @@ -168,7 +168,7 @@ func (q *queryServer) QuerySubscriptionsForPlan(c context.Context, req *types.Qu
)

pagination, err := query.Paginate(store, req.Pagination, func(key, _ []byte) error {
v, found := q.GetSubscription(ctx, types.IDFromSubscriptionForPlanKey(key))
v, found := q.GetSubscription(ctx, sdk.BigEndianToUint64(key))
if !found {
return fmt.Errorf("subscription for key %X does not exist", key)
}
Expand Down Expand Up @@ -260,9 +260,9 @@ func (q *queryServer) QueryPayouts(c context.Context, req *types.QueryPayoutsReq
var (
items types.Payouts
ctx = sdk.UnwrapSDKContext(c)
store = prefix.NewStore(q.Store(ctx), types.PayoutKeyPrefix)
)

store := prefix.NewStore(q.Store(ctx), types.PayoutKeyPrefix)
pagination, err := query.Paginate(store, req.Pagination, func(_, value []byte) error {
var item types.Payout
if err := q.cdc.Unmarshal(value, &item); err != nil {
Expand Down Expand Up @@ -293,9 +293,9 @@ func (q *queryServer) QueryPayoutsForAccount(c context.Context, req *types.Query
var (
items types.Payouts
ctx = sdk.UnwrapSDKContext(c)
store = prefix.NewStore(q.Store(ctx), types.GetPayoutForAccountKeyPrefix(addr))
)

store := prefix.NewStore(q.Store(ctx), types.GetPayoutForAccountKeyPrefix(addr))
pagination, err := query.Paginate(store, req.Pagination, func(key, _ []byte) error {
item, found := q.GetPayout(ctx, sdk.BigEndianToUint64(key))
if !found {
Expand Down Expand Up @@ -326,9 +326,9 @@ func (q *queryServer) QueryPayoutsForNode(c context.Context, req *types.QueryPay
var (
items types.Payouts
ctx = sdk.UnwrapSDKContext(c)
store = prefix.NewStore(q.Store(ctx), types.GetPayoutForNodeKeyPrefix(addr))
)

store := prefix.NewStore(q.Store(ctx), types.GetPayoutForNodeKeyPrefix(addr))
pagination, err := query.Paginate(store, req.Pagination, func(key, _ []byte) error {
item, found := q.GetPayout(ctx, sdk.BigEndianToUint64(key))
if !found {
Expand Down

0 comments on commit fff3c14

Please sign in to comment.