-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added distributions query * added test cases --------- Signed-off-by: Jürgen Eckel <[email protected]> Signed-off-by: Julian Strobl <[email protected]> Co-authored-by: Julian Strobl <[email protected]>
- Loading branch information
Showing
8 changed files
with
1,036 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/planetmint/planetmint-go/x/dao/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var _ = strconv.Itoa(0) | ||
|
||
func GetCmdDistributions() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "distributions", | ||
Short: "Query distributions", | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
params := &types.QueryDistributionsRequest{} | ||
|
||
pageReq, err := client.ReadPageRequest(cmd.Flags()) | ||
if err != nil { | ||
return err | ||
} | ||
params.Pagination = pageReq | ||
|
||
res, err := queryClient.Distributions(cmd.Context(), params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddPaginationFlagsToCmd(cmd, cmd.Use) | ||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/query" | ||
"github.com/planetmint/planetmint-go/errormsg" | ||
"github.com/planetmint/planetmint-go/x/dao/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func (k Keeper) Distributions(goCtx context.Context, req *types.QueryDistributionsRequest) (*types.QueryDistributionsResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, errormsg.InvalidRequest) | ||
} | ||
|
||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
distributions := make([]types.DistributionOrder, 0) | ||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DistributionKey)) | ||
pageRes, err := query.Paginate(store, req.Pagination, func(_ []byte, value []byte) (err error) { | ||
var distribution types.DistributionOrder | ||
err = distribution.Unmarshal(value) | ||
distributions = append(distributions, distribution) | ||
return | ||
}) | ||
if err != nil { | ||
return nil, status.Errorf(codes.InvalidArgument, "paginate: %v", err) | ||
} | ||
|
||
return &types.QueryDistributionsResponse{Distributions: distributions, Pagination: pageRes}, nil | ||
} |
Oops, something went wrong.