Skip to content

Commit

Permalink
[Commitment]: Add commitment vesting info query (#651)
Browse files Browse the repository at this point in the history
add commitment vesting info query
  • Loading branch information
amityadav0 authored Jul 15, 2024
1 parent 47717bc commit f38140f
Show file tree
Hide file tree
Showing 7 changed files with 1,137 additions and 69 deletions.
42 changes: 42 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39963,6 +39963,40 @@ paths:
additionalProperties: {}
tags:
- Query
/elys-network/elys/commitment/commitment_vesting_info/{address}:
get:
summary: Queries a list of CommitmentVestingInfo items.
operationId: ElysCommitmentCommitmentVestingInfo
responses:
'200':
description: A successful response.
schema:
type: object
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: address
in: path
required: true
type: string
tags:
- Query
/elys-network/elys/commitment/committed_tokens_locked/{address}:
get:
summary: Queries sum of committed tokens locked and not unlockable
Expand Down Expand Up @@ -45016,6 +45050,9 @@ paths:
description: A successful response.
schema:
type: object
properties:
price:
type: string
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -86492,6 +86529,8 @@ definitions:
type: string
format: uint64
description: Params defines the parameters for the module.
elys.commitment.QueryCommitmentVestingInfoResponse:
type: object
elys.commitment.QueryCommittedTokensLockedResponse:
type: object
properties:
Expand Down Expand Up @@ -89654,6 +89693,9 @@ definitions:
type: string
elys.tier.QueryGetConsolidatedPriceResponse:
type: object
properties:
price:
type: string
elys.tier.QueryGetPortfolioResponse:
type: object
properties:
Expand Down
60 changes: 50 additions & 10 deletions proto/elys/commitment/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package elys.commitment;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "elys/commitment/params.proto";
import "elys/commitment/commitments.proto";
Expand All @@ -14,31 +15,43 @@ option go_package = "github.com/elys-network/elys/x/commitment/types";

// Query defines the gRPC querier service.
service Query {

// Parameters queries the parameters of the module.
rpc Params (QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/elys-network/elys/commitment/params";

}

// Queries a Commitment item.
rpc ShowCommitments (QueryShowCommitmentsRequest) returns (QueryShowCommitmentsResponse) {
option (google.api.http).get = "/elys-network/elys/commitment/show_commitments/{creator}";

}

// Queries sum of committed tokens locked and not unlockable
rpc CommittedTokensLocked (QueryCommittedTokensLockedRequest) returns (QueryCommittedTokensLockedResponse) {
option (google.api.http).get = "/elys-network/elys/commitment/committed_tokens_locked/{address}";

}

// Queries the total number of commitment items.
rpc NumberOfCommitments (QueryNumberOfCommitmentsRequest) returns (QueryNumberOfCommitmentsResponse) {
option (google.api.http).get = "/elys-network/elys/commitment/number_of_commitments";

}

// Queries a list of CommitmentVestingInfo items.
rpc CommitmentVestingInfo (QueryCommitmentVestingInfoRequest) returns (QueryCommitmentVestingInfoResponse) {
option (google.api.http).get = "/elys-network/elys/commitment/commitment_vesting_info/{address}";

}
}
// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {

// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
}
Expand All @@ -62,13 +75,40 @@ message QueryCommittedTokensLockedRequest {
}

message QueryCommittedTokensLockedResponse {
string address = 1;
repeated cosmos.base.v1beta1.Coin locked_committed = 2 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
repeated cosmos.base.v1beta1.Coin total_committed = 3 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
}

message QueryCommitmentVestingInfoRequest {
string address = 1;
repeated cosmos.base.v1beta1.Coin locked_committed = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
repeated cosmos.base.v1beta1.Coin total_committed = 3 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

message QueryCommitmentVestingInfoResponse {
string total = 1 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
repeated VestingDetails vesting_details = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

message VestingDetails {
string id = 1;
string totalVesting = 2 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string claimed = 3 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string vestedSoFar = 4 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
int64 remaining_blocks = 5;
}
2 changes: 2 additions & 0 deletions x/commitment/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdNumberOfCommitments())
cmd.AddCommand(CmdCommittedTokensLocked())

cmd.AddCommand(CmdCommitmentVestingInfo())

// this line is used by starport scaffolding # 1

return cmd
Expand Down
46 changes: 46 additions & 0 deletions x/commitment/client/cli/query_commitment_vesting_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cli

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/elys-network/elys/x/commitment/types"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdCommitmentVestingInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "commitment-vesting-info [address]",
Short: "Query commitment-vesting-info",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqAddress := args[0]

clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryCommitmentVestingInfoRequest{

Address: reqAddress,
}

res, err := queryClient.CommitmentVestingInfo(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
41 changes: 41 additions & 0 deletions x/commitment/keeper/query_commitment_vesting_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package keeper

import (
"context"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/commitment/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (k Keeper) CommitmentVestingInfo(goCtx context.Context, req *types.QueryCommitmentVestingInfoRequest) (*types.QueryCommitmentVestingInfoResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)
commitment := k.GetCommitments(ctx, req.Address)
vestingTokens := commitment.GetVestingTokens()

totalVesting := sdk.ZeroInt()
vestingDetails := make([]types.VestingDetails, 0)
for i, vesting := range vestingTokens {
vestingDetail := types.VestingDetails{
Id: fmt.Sprintf("%d", i),
TotalVesting: vesting.TotalAmount,
Claimed: vesting.ClaimedAmount,
VestedSoFar: vesting.VestedSoFar(ctx),
RemainingBlocks: vesting.NumBlocks - (ctx.BlockHeight() - vesting.StartBlock),
}

vestingDetails = append(vestingDetails, vestingDetail)
totalVesting = totalVesting.Add(vesting.TotalAmount.Sub(vesting.ClaimedAmount))
}

return &types.QueryCommitmentVestingInfoResponse{
Total: totalVesting,
VestingDetails: vestingDetails,
}, nil
}
Loading

0 comments on commit f38140f

Please sign in to comment.