Skip to content

Commit

Permalink
Add query key in compliance pagination (#87)
Browse files Browse the repository at this point in the history
* Add key for pagination query

* Fix query key conversion
  • Loading branch information
deep-quality-dev authored May 10, 2024
1 parent 80d8afd commit 8a1f397
Show file tree
Hide file tree
Showing 3 changed files with 816 additions and 81 deletions.
21 changes: 18 additions & 3 deletions proto/swisstronik/compliance/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ message QueryAddressesDetailsRequest {

// QueryAddressesDetailsResponse is response type for the Query/AddressesDetails RPC method.
message QueryAddressesDetailsResponse {
message AddressDetailsWithKey {
string address = 1;
AddressDetails addressDetails = 2;
}

// addresses is a slice of registered addresses for the compliance module
repeated AddressDetails addresses = 1 [(gogoproto.nullable) = false];
repeated AddressDetailsWithKey addresses = 1 [(gogoproto.nullable) = false];
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
Expand All @@ -107,8 +112,13 @@ message QueryIssuersDetailsRequest {

// QueryIssuersDetailsResponse is response type for the Query/IssuersDetails RPC method.
message QueryIssuersDetailsResponse {
message IssuerDetailsWithKey {
string issuerAddress = 1;
IssuerDetails issuerDetails = 2;
}

// issuers is a slice of registered issuers for the compliance module
repeated IssuerDetails issuers = 1 [(gogoproto.nullable) = false];
repeated IssuerDetailsWithKey issuers = 1 [(gogoproto.nullable) = false];
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
Expand All @@ -131,8 +141,13 @@ message QueryVerificationsDetailsRequest {

// QueryVerificationsDetailsResponse is response type for the Query/VerificationsDetails RPC method.
message QueryVerificationsDetailsResponse {
message VerificationDetailsWithKey {
bytes verificationID = 1;
VerificationDetails verificationDetails = 2;
}

// verifications is a slice of registered verifications for the compliance module
repeated VerificationDetails verifications = 1 [(gogoproto.nullable) = false];
repeated VerificationDetailsWithKey verifications = 1 [(gogoproto.nullable) = false];
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
36 changes: 23 additions & 13 deletions x/compliance/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/cosmos/gogoproto/proto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"swisstronik/x/compliance/types"
)

Expand Down Expand Up @@ -64,15 +65,18 @@ func (k Querier) AddressesDetails(goCtx context.Context, req *types.QueryAddress
}
ctx := sdk.UnwrapSDKContext(goCtx)

var addresses []types.AddressDetails
var addresses []types.QueryAddressesDetailsResponse_AddressDetailsWithKey
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixAddressDetails)

pageRes, err := query.Paginate(store, req.Pagination, func(_, value []byte) error {
pageRes, err := query.Paginate(store, req.Pagination, func(key []byte, value []byte) error {
var addressDetails types.AddressDetails
if err := proto.Unmarshal(value, &addressDetails); err != nil {
return err
}
addresses = append(addresses, addressDetails)
addresses = append(addresses, types.QueryAddressesDetailsResponse_AddressDetailsWithKey{
Address: sdk.AccAddress(key).String(),
AddressDetails: &addressDetails,
})
// NOTE, DO NOT FILTER VERIFICATIONS BY ISSUERS' EXISTENCE BECAUSE OF QUERY PERFORMANCE
return nil
})
Expand Down Expand Up @@ -111,15 +115,18 @@ func (k Querier) IssuersDetails(goCtx context.Context, req *types.QueryIssuersDe
}
ctx := sdk.UnwrapSDKContext(goCtx)

var issuers []types.IssuerDetails
var issuers []types.QueryIssuersDetailsResponse_IssuerDetailsWithKey
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixIssuerDetails)

pageRes, err := query.Paginate(store, req.Pagination, func(_, value []byte) error {
var issuer types.IssuerDetails
if err := proto.Unmarshal(value, &issuer); err != nil {
pageRes, err := query.Paginate(store, req.Pagination, func(key []byte, value []byte) error {
var issuerDetails types.IssuerDetails
if err := proto.Unmarshal(value, &issuerDetails); err != nil {
return err
}
issuers = append(issuers, issuer)
issuers = append(issuers, types.QueryIssuersDetailsResponse_IssuerDetailsWithKey{
IssuerAddress: sdk.AccAddress(key).String(),
IssuerDetails: &issuerDetails,
})
return nil
})
if err != nil {
Expand Down Expand Up @@ -160,15 +167,18 @@ func (k Querier) VerificationsDetails(goCtx context.Context, req *types.QueryVer
}
ctx := sdk.UnwrapSDKContext(goCtx)

var verifications []types.VerificationDetails
var verifications []types.QueryVerificationsDetailsResponse_VerificationDetailsWithKey
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixVerificationDetails)

pageRes, err := query.Paginate(store, req.Pagination, func(_, value []byte) error {
var verification types.VerificationDetails
if err := proto.Unmarshal(value, &verification); err != nil {
pageRes, err := query.Paginate(store, req.Pagination, func(key []byte, value []byte) error {
var verificationDetails types.VerificationDetails
if err := proto.Unmarshal(value, &verificationDetails); err != nil {
return err
}
verifications = append(verifications, verification)
verifications = append(verifications, types.QueryVerificationsDetailsResponse_VerificationDetailsWithKey{
VerificationID: key,
VerificationDetails: &verificationDetails,
})
// NOTE, DO NOT FILTER VERIFICATIONS BY ISSUERS' EXISTENCE BECAUSE OF QUERY PERFORMANCE
return nil
})
Expand Down
Loading

0 comments on commit 8a1f397

Please sign in to comment.