Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"TotalBurn" method remove unit convert #97

Merged
merged 5 commits into from
Feb 1, 2021
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
20 changes: 3 additions & 17 deletions modules/token/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,7 @@ func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types
// TotalBurn return the all burn coin
func (k Keeper) TotalBurn(c context.Context, req *types.QueryTotalBurnRequest) (*types.QueryTotalBurnResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
burnCoins := k.GetAllBurnCoin(ctx)

coins := make([]sdk.DecCoin, len(burnCoins))
for i, coin := range burnCoins {
token, err := k.GetToken(ctx, coin.Denom)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}

mainCoin, err := token.ToMainCoin(coin)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}

coins[i] = mainCoin
}
return &types.QueryTotalBurnResponse{BurnedCoins: coins}, nil
return &types.QueryTotalBurnResponse{
BurnedCoins: k.GetAllBurnCoin(ctx),
}, nil
}
5 changes: 1 addition & 4 deletions modules/token/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryTotalBurn() {
buinCoin := sdk.NewInt64Coin("satoshi", 1000000000000000000)
app.TokenKeeper.AddBurnCoin(ctx, buinCoin)

expCoin, err := token.ToMainCoin(buinCoin)
suite.Require().NoError(err)

resp, err := queryClient.TotalBurn(gocontext.Background(), &types.QueryTotalBurnRequest{})
suite.Require().NoError(err)
suite.Len(resp.BurnedCoins, 1)
suite.EqualValues(expCoin, resp.BurnedCoins[0])
suite.EqualValues(buinCoin, resp.BurnedCoins[0])
}
106 changes: 53 additions & 53 deletions modules/token/types/query.pb.go

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

94 changes: 45 additions & 49 deletions proto/token/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,89 +13,85 @@ option go_package = "github.com/irisnet/irismod/modules/token/types";

// Query creates service with token as rpc
service Query {
// Token returns token with token name
rpc Token(QueryTokenRequest) returns (QueryTokenResponse) {
option (google.api.http).get = "/irismod/token/tokens/{denom}";
}
// Tokens returns the token list
rpc Tokens(QueryTokensRequest) returns (QueryTokensResponse) {
option (google.api.http).get = "/irismod/token/tokens";
}
// Fees returns the fees to issue or mint a token
rpc Fees(QueryFeesRequest) returns (QueryFeesResponse) {
option (google.api.http).get = "/irismod/token/tokens/{symbol}/fees";
}
// Params queries the token parameters
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/irismod/token/params";
}
// Params queries the token parameters
rpc TotalBurn(QueryTotalBurnRequest) returns (QueryTotalBurnResponse) {
option (google.api.http).get = "/irismod/token/total_burn";
}
// Token returns token with token name
rpc Token(QueryTokenRequest) returns (QueryTokenResponse) {
option (google.api.http).get = "/irismod/token/tokens/{denom}";
}
// Tokens returns the token list
rpc Tokens(QueryTokensRequest) returns (QueryTokensResponse) {
option (google.api.http).get = "/irismod/token/tokens";
}
// Fees returns the fees to issue or mint a token
rpc Fees(QueryFeesRequest) returns (QueryFeesResponse) {
option (google.api.http).get = "/irismod/token/tokens/{symbol}/fees";
}
// Params queries the token parameters
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/irismod/token/params";
}
// Params queries the token parameters
rpc TotalBurn(QueryTotalBurnRequest) returns (QueryTotalBurnResponse) {
option (google.api.http).get = "/irismod/token/total_burn";
}
}

// QueryTokenRequest is request type for the Query/Token RPC method
message QueryTokenRequest {
string denom = 1;
}
message QueryTokenRequest { string denom = 1; }

// QueryTokenResponse is response type for the Query/Token RPC method
message QueryTokenResponse {
google.protobuf.Any Token = 1
[ (cosmos_proto.accepts_interface) = "ContentI" ];
google.protobuf.Any Token = 1
[ (cosmos_proto.accepts_interface) = "ContentI" ];
}

// QueryTokensRequest is request type for the Query/Tokens RPC method
message QueryTokensRequest {
string owner = 1;
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
string owner = 1;
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QueryTokensResponse is response type for the Query/Tokens RPC method
message QueryTokensResponse {
repeated google.protobuf.Any Tokens = 1
[ (cosmos_proto.accepts_interface) = "ContentI" ];
repeated google.protobuf.Any Tokens = 1
[ (cosmos_proto.accepts_interface) = "ContentI" ];

cosmos.base.query.v1beta1.PageResponse pagination = 2;
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryFeesRequest is request type for the Query/Fees RPC method
message QueryFeesRequest {
string symbol = 1;
}
message QueryFeesRequest { string symbol = 1; }

// QueryFeesResponse is response type for the Query/Fees RPC method
message QueryFeesResponse {
bool exist = 1;
cosmos.base.v1beta1.Coin issue_fee = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"issue_fee\"",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
cosmos.base.v1beta1.Coin mint_fee = 3 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"mint_fee\"",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
bool exist = 1;
cosmos.base.v1beta1.Coin issue_fee = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"issue_fee\"",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
cosmos.base.v1beta1.Coin mint_fee = 3 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"mint_fee\"",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
}

// QueryParametersRequest is request type for the Query/Parameters RPC method
message QueryParamsRequest {}

// QueryParametersResponse is response type for the Query/Parameters RPC method
message QueryParamsResponse {
token.Params params = 1 [ (gogoproto.nullable) = false ];
token.Params params = 1 [ (gogoproto.nullable) = false ];

cosmos.base.query.v1beta1.PageResponse res = 2;
cosmos.base.query.v1beta1.PageResponse res = 2;
}

// QueryTokenRequest is request type for the Query/TotalBurn RPC method
message QueryTotalBurnRequest {}

// QueryTotalBurnResponse is response type for the Query/TotalBurn RPC method
message QueryTotalBurnResponse {
repeated cosmos.base.v1beta1.DecCoin burned_coins = 1
[ (gogoproto.nullable) = false ];
repeated cosmos.base.v1beta1.Coin burned_coins = 1
[ (gogoproto.nullable) = false ];
}