-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,537 additions
and
210 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,50 @@ | ||
syntax = "proto3"; | ||
package seiprotocol.seichain.confidentialtransfers; | ||
|
||
import "cosmos/base/query/v1beta1/pagination.proto"; | ||
import "gogoproto/gogo.proto"; | ||
import "google/api/annotations.proto"; | ||
import "confidentialtransfers/confidential.proto"; | ||
|
||
option go_package = "github.com/sei-protocol/sei-chain/x/confidentialtransfers/types"; | ||
|
||
// TODO: Define any query messages here | ||
// Query defines the gRPC querier service. | ||
service Query { | ||
// TODO: This is a mock method. Remove when we add real queries | ||
rpc TestQuery (TestQueryRequest) returns (TestQueryResponse) { | ||
rpc GetCtAccount (GetCtAccountRequest) returns (GetCtAccountResponse) { | ||
option (google.api.http) = { | ||
get: "/seichain/confidentialtransfers/test_query" | ||
get: "/seichain/confidentialtransfers/account/{address}/{denom}" | ||
}; | ||
} | ||
|
||
rpc GetAllCtAccounts (GetAllCtAccountsRequest) returns (GetAllCtAccountsResponse) { | ||
option (google.api.http) = { | ||
get: "/seichain/confidentialtransfers/account/{address}" | ||
}; | ||
} | ||
} | ||
|
||
message GetCtAccountRequest { | ||
string address = 1; | ||
string denom = 2; | ||
} | ||
|
||
// TODO: This is a mock method. Remove when we add real queries | ||
message TestQueryRequest { | ||
string test_field = 1; | ||
message GetCtAccountResponse { | ||
CtAccount account = 1; | ||
} | ||
|
||
// TODO: This is a mock method. Remove when we add real queries | ||
message TestQueryResponse { | ||
string test_field = 1; | ||
message GetAllCtAccountsRequest { | ||
option (gogoproto.equal) = false; | ||
option (gogoproto.goproto_getters) = false; | ||
|
||
string address = 1; | ||
|
||
// pagination defines an optional pagination for the request. | ||
cosmos.base.query.v1beta1.PageRequest pagination = 2; | ||
} | ||
|
||
message GetAllCtAccountsResponse { | ||
repeated CtAccountWithDenom accounts = 1 [(gogoproto.nullable) = false]; | ||
|
||
// pagination defines the pagination in the response. | ||
cosmos.base.query.v1beta1.PageResponse pagination = 2; | ||
} |
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,80 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/query" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
var _ types.QueryServer = BaseKeeper{} | ||
|
||
func (k BaseKeeper) GetCtAccount(ctx context.Context, req *types.GetCtAccountRequest) (*types.GetCtAccountResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "empty request") | ||
} | ||
|
||
if req.Address == "" { | ||
return nil, status.Error(codes.InvalidArgument, "address cannot be empty") | ||
} | ||
|
||
address, err := sdk.AccAddressFromBech32(req.Address) | ||
if err != nil { | ||
return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) | ||
} | ||
|
||
if req.Denom == "" { | ||
return nil, status.Error(codes.InvalidArgument, "invalid denom") | ||
} | ||
|
||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
|
||
ctAccount, found := k.getCtAccount(sdkCtx, address, req.Denom) | ||
if !found { | ||
return nil, status.Errorf(codes.NotFound, "account not found for account %s and denom %s", | ||
req.Address, req.Denom) | ||
} | ||
|
||
return &types.GetCtAccountResponse{Account: &ctAccount}, nil | ||
} | ||
|
||
func (k BaseKeeper) GetAllCtAccounts(ctx context.Context, req *types.GetAllCtAccountsRequest) (*types.GetAllCtAccountsResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "empty request") | ||
} | ||
|
||
if req.Address == "" { | ||
return nil, status.Error(codes.InvalidArgument, "address cannot be empty") | ||
} | ||
|
||
address, err := sdk.AccAddressFromBech32(req.Address) | ||
if err != nil { | ||
return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) | ||
} | ||
|
||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
|
||
store := k.getAccountStoreForAddress(sdkCtx, address) | ||
accounts := make([]types.CtAccountWithDenom, 0) | ||
pageRes, err := query.Paginate(store, req.Pagination, func(denom, value []byte) error { | ||
|
||
var ctAccount types.CtAccount | ||
err = k.cdc.Unmarshal(value, &ctAccount) | ||
if err != nil { | ||
return err | ||
} | ||
accounts = append(accounts, types.CtAccountWithDenom{Denom: string(denom), Account: ctAccount}) | ||
return nil | ||
}) | ||
|
||
if err != nil { | ||
return nil, status.Errorf(codes.InvalidArgument, "paginate: %v", err) | ||
} | ||
|
||
return &types.GetAllCtAccountsResponse{Accounts: accounts, Pagination: pageRes}, nil | ||
|
||
} |
Oops, something went wrong.