Skip to content

Commit

Permalink
Eckelj/distributions query (#491)
Browse files Browse the repository at this point in the history
* 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
eckelj and jmastr authored Nov 28, 2024
1 parent 75cb64d commit 41b5bf5
Show file tree
Hide file tree
Showing 8 changed files with 1,036 additions and 76 deletions.
230 changes: 230 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46902,6 +46902,164 @@ paths:
format: int64
tags:
- Query
/planetmint/dao/distributions:
get:
summary: Queries a list of Distributions items.
operationId: PlanetmintgoDaoDistributions
responses:
'200':
description: A successful response.
schema:
type: object
properties:
distributions:
type: array
items:
type: object
properties:
daoAddr:
type: string
daoAmount:
type: string
daoTxID:
type: string
investorAddr:
type: string
investorAmount:
type: string
investorTxID:
type: string
popAddr:
type: string
popAmount:
type: string
popTxID:
type: string
firstPop:
type: string
format: int64
lastPop:
type: string
format: int64
proposer:
type: string
earlyInvAddr:
type: string
earlyInvAmount:
type: string
earlyInvTxID:
type: string
strategicAddr:
type: string
strategicAmount:
type: string
strategicTxID:
type: string
pagination:
type: object
properties:
next_key:
type: string
format: byte
description: |-
next_key is the key to be passed to PageRequest.key to
query the next page most efficiently. It will be empty if
there are no more results.
total:
type: string
format: uint64
title: >-
total is total number of results available if
PageRequest.count_total

was set, its value is undefined otherwise
description: >-
PageResponse is to be embedded in gRPC response messages where
the

corresponding request message has used PageRequest.

message SomeResponse {
repeated Bar results = 1;
PageResponse page = 2;
}
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
parameters:
- name: pagination.key
description: |-
key is a value returned in PageResponse.next_key to begin
querying the next page most efficiently. Only one of offset or key
should be set.
in: query
required: false
type: string
format: byte
- name: pagination.offset
description: >-
offset is a numeric offset that can be used when key is unavailable.

It is less efficient than using key. Only one of offset or key
should

be set.
in: query
required: false
type: string
format: uint64
- name: pagination.limit
description: >-
limit is the total number of results to be returned in the result
page.

If left empty it will default to a value to be set by each app.
in: query
required: false
type: string
format: uint64
- name: pagination.count_total
description: >-
count_total is set to true to indicate that the result set should
include

a count of the total number of items available for pagination in
UIs.

count_total is only respected when offset is used. It is ignored
when key

is set.
in: query
required: false
type: boolean
- name: pagination.reverse
description: >-
reverse is set to true if results are to be returned in the
descending order.


Since: cosmos-sdk 0.43
in: query
required: false
type: boolean
tags:
- Query
/planetmint/dao/mint_requests/address/{address}:
get:
summary: Queries a list of MintRequestsByAddress items.
Expand Down Expand Up @@ -76890,6 +77048,78 @@ definitions:
repeated Bar results = 1;
PageResponse page = 2;
}
planetmintgo.dao.QueryDistributionsResponse:
type: object
properties:
distributions:
type: array
items:
type: object
properties:
daoAddr:
type: string
daoAmount:
type: string
daoTxID:
type: string
investorAddr:
type: string
investorAmount:
type: string
investorTxID:
type: string
popAddr:
type: string
popAmount:
type: string
popTxID:
type: string
firstPop:
type: string
format: int64
lastPop:
type: string
format: int64
proposer:
type: string
earlyInvAddr:
type: string
earlyInvAmount:
type: string
earlyInvTxID:
type: string
strategicAddr:
type: string
strategicAmount:
type: string
strategicTxID:
type: string
pagination:
type: object
properties:
next_key:
type: string
format: byte
description: |-
next_key is the key to be passed to PageRequest.key to
query the next page most efficiently. It will be empty if
there are no more results.
total:
type: string
format: uint64
title: >-
total is total number of results available if
PageRequest.count_total

was set, its value is undefined otherwise
description: |-
PageResponse is to be embedded in gRPC response messages where the
corresponding request message has used PageRequest.

message SomeResponse {
repeated Bar results = 1;
PageResponse page = 2;
}
planetmintgo.dao.QueryGetChallengeResponse:
type: object
properties:
Expand Down
15 changes: 15 additions & 0 deletions proto/planetmintgo/dao/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ service Query {
option (google.api.http).get = "/planetmint/dao/redeem_claim_by_liquid_tx_hash/{liquidTxHash}";

}

// Queries a list of Distributions items.
rpc Distributions (QueryDistributionsRequest) returns (QueryDistributionsResponse) {
option (google.api.http).get = "/planetmint/dao/distributions";

}
}
// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}
Expand Down Expand Up @@ -177,3 +183,12 @@ message QueryRedeemClaimByLiquidTxHashResponse {
RedeemClaim redeemClaim = 1;
}

message QueryDistributionsRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryDistributionsResponse {
repeated DistributionOrder distributions = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

1 change: 1 addition & 0 deletions x/dao/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func GetQueryCmd(_ string) *cobra.Command {
GetCmdChallenge(),
GetCmdChallenges(),
GetCmdDistribution(),
GetCmdDistributions(),
GetCmdListRedeemClaim(),
GetCmdMintRequests(),
GetCmdQueryParams(),
Expand Down
48 changes: 48 additions & 0 deletions x/dao/client/cli/query_distributions.go
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
}
35 changes: 35 additions & 0 deletions x/dao/keeper/query_distributions.go
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
}
Loading

0 comments on commit 41b5bf5

Please sign in to comment.