Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions client/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package client

import (
b64 "encoding/base64"

"github.com/cosmos/cosmos-sdk/client/flags"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/spf13/pflag"
)

// ReadPageRequest reads and builds the necessary page request flags for pagination.
func ReadPageRequest(flagSet *pflag.FlagSet) (*query.PageRequest, error) {
pageKeyStr, _ := flagSet.GetString(flags.FlagPageKey)
offset, _ := flagSet.GetUint64(flags.FlagOffset)
limit, _ := flagSet.GetUint64(flags.FlagLimit)
countTotal, _ := flagSet.GetBool(flags.FlagCountTotal)
page, _ := flagSet.GetUint64(flags.FlagPage)
reverse, _ := flagSet.GetBool(flags.FlagReverse)

if page > 1 && offset > 0 {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "page and offset cannot be used together")
}

// Clear page key if using page numbers (page and key are mutually exclusive)
if page > 1 {
offset = (page - 1) * limit
}

var pageKey []byte
if pageKeyStr != "" {
var err error
pageKey, err = b64.StdEncoding.DecodeString(pageKeyStr)
if err != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid pagination key")
}
}

return &query.PageRequest{
Key: pageKey,
Offset: offset,
Limit: limit,
CountTotal: countTotal,
Reverse: reverse,
}, nil
}
3 changes: 2 additions & 1 deletion x/audit/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
types "github.com/akash-network/akash-api/go/node/audit/v1beta3"

aclient "github.com/akash-network/node/client"
clientutils "github.com/akash-network/node/client"
)

func GetQueryCmd() *cobra.Command {
Expand Down Expand Up @@ -46,7 +47,7 @@ func cmdGetProviders() *cobra.Command {
return err
}

pageReq, err := sdkclient.ReadPageRequest(cmd.Flags())
pageReq, err := clientutils.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion x/cert/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
types "github.com/akash-network/akash-api/go/node/cert/v1beta3"

aclient "github.com/akash-network/node/client"
clientutils "github.com/akash-network/node/client"
)

const (
Expand Down Expand Up @@ -52,7 +53,7 @@ func cmdGetCertificates() *cobra.Command {
return err
}

pageReq, err := sdkclient.ReadPageRequest(cmd.Flags())
pageReq, err := clientutils.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion x/deployment/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
types "github.com/akash-network/akash-api/go/node/deployment/v1beta3"

aclient "github.com/akash-network/node/client"
clientutils "github.com/akash-network/node/client"
)

// GetQueryCmd returns the query commands for the deployment module
Expand Down Expand Up @@ -53,7 +54,7 @@ func cmdDeployments() *cobra.Command {
return err
}

pageReq, err := sdkclient.ReadPageRequest(cmd.Flags())
pageReq, err := clientutils.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion x/market/client/cli/bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
types "github.com/akash-network/akash-api/go/node/market/v1beta4"

aclient "github.com/akash-network/node/client"
clientutils "github.com/akash-network/node/client"
)

func cmdGetBids() *cobra.Command {
Expand All @@ -32,7 +33,7 @@ func cmdGetBids() *cobra.Command {
return err
}

pageReq, err := sdkclient.ReadPageRequest(cmd.Flags())
pageReq, err := clientutils.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion x/market/client/cli/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
types "github.com/akash-network/akash-api/go/node/market/v1beta4"

aclient "github.com/akash-network/node/client"
clientutils "github.com/akash-network/node/client"
)

func cmdGetLeases() *cobra.Command {
Expand All @@ -32,7 +33,7 @@ func cmdGetLeases() *cobra.Command {
return err
}

pageReq, err := sdkclient.ReadPageRequest(cmd.Flags())
pageReq, err := clientutils.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion x/market/client/cli/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
types "github.com/akash-network/akash-api/go/node/market/v1beta4"

aclient "github.com/akash-network/node/client"
clientutils "github.com/akash-network/node/client"
)

func cmdGetOrders() *cobra.Command {
Expand All @@ -32,7 +33,7 @@ func cmdGetOrders() *cobra.Command {
return err
}

pageReq, err := sdkclient.ReadPageRequest(cmd.Flags())
pageReq, err := clientutils.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion x/provider/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
types "github.com/akash-network/akash-api/go/node/provider/v1beta3"

aclient "github.com/akash-network/node/client"
clientutils "github.com/akash-network/node/client"
)

// GetQueryCmd returns the transaction commands for the provider module
Expand Down Expand Up @@ -45,7 +46,7 @@ func cmdGetProviders() *cobra.Command {
return err
}

pageReq, err := sdkclient.ReadPageRequest(cmd.Flags())
pageReq, err := clientutils.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
Expand Down
Loading