Skip to content

Commit

Permalink
Add TotalPools() query
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunnini committed May 6, 2021
1 parent 330c572 commit d412659
Show file tree
Hide file tree
Showing 8 changed files with 514 additions and 92 deletions.
10 changes: 10 additions & 0 deletions proto/osmosis/gamm/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ service Query {
rpc Pools(QueryPoolsRequest) returns (QueryPoolsResponse) {
option (google.api.http).get = "/osmosis/gamm/v1beta1/pools/all";
}
rpc TotalPools(QueryTotalPoolsRequest) returns (QueryTotalPoolsResponse) {
option (google.api.http).get = "/osmosis/gamm/v1beta1/pools/total_pools";
}
rpc PoolParams(QueryPoolParamsRequest) returns (QueryPoolParamsResponse) {
option (google.api.http).get = "/osmosis/gamm/v1beta1/{poolId}/params";
}
Expand Down Expand Up @@ -67,6 +70,13 @@ message QueryPoolsResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

//=============================== TotalPools
message QueryTotalPoolsRequest {
}
message QueryTotalPoolsResponse {
uint64 totalPools = 1 [ (gogoproto.moretags) = "yaml:\"total_pools\"" ];
}

//=============================== PoolParams
message QueryPoolParamsRequest {
uint64 poolId = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
Expand Down
4 changes: 2 additions & 2 deletions x/epochs/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions x/gamm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ func (k Keeper) Pools(
}, nil
}

func (k Keeper) TotalPools(
ctx context.Context,
req *types.QueryTotalPoolsRequest,
) (*types.QueryTotalPoolsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

sdkCtx := sdk.UnwrapSDKContext(ctx)

return &types.QueryTotalPoolsResponse{
TotalPools: k.getNextPoolNumber(sdkCtx) - 1,
}, nil
}

func (k Keeper) PoolParams(ctx context.Context, req *types.QueryPoolParamsRequest) (*types.QueryPoolParamsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
Expand Down
16 changes: 16 additions & 0 deletions x/gamm/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ func (suite *KeeperTestSuite) TestQueryPools() {
}
}

func (suite *KeeperTestSuite) TestQueryTotalPools1() {
res, err := suite.queryClient.TotalPools(gocontext.Background(), &types.QueryTotalPoolsRequest{})
suite.Require().NoError(err)
suite.Require().Equal(uint64(0), res.TotalPools)
}

func (suite *KeeperTestSuite) TestQueryTotalPools2() {
for i := 0; i < 10; i++ {
suite.preparePool()
}

res, err := suite.queryClient.TotalPools(gocontext.Background(), &types.QueryTotalPoolsRequest{})
suite.Require().NoError(err)
suite.Require().Equal(uint64(10), res.TotalPools)
}

func (suite *KeeperTestSuite) TestQueryPoolParams() {
queryClient := suite.queryClient

Expand Down
493 changes: 406 additions & 87 deletions x/gamm/types/query.pb.go

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions x/gamm/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions x/incentives/types/pot.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/incentives/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d412659

Please sign in to comment.