Skip to content

Commit

Permalink
Add pagination for querying issuers/users/verifications (#85)
Browse files Browse the repository at this point in the history
* Add pagination for querying issuers/users/verifications

* Commands for querying all records

* Regenerate goproto
  • Loading branch information
deep-quality-dev authored May 9, 2024
1 parent 896a721 commit b9f1910
Show file tree
Hide file tree
Showing 7 changed files with 2,062 additions and 167 deletions.
70 changes: 64 additions & 6 deletions proto/swisstronik/compliance/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,31 @@ service Query {
}

rpc OperatorDetails(QueryOperatorDetailsRequest) returns (QueryOperatorDetailsResponse) {
option (google.api.http).get = "/swisstronik/compliance/operator/{address}";
option (google.api.http).get = "/swisstronik/compliance/operator/{operatorAddress}";
}

rpc AddressDetails(QueryAddressDetailsRequest) returns (QueryAddressDetailsResponse) {
option (google.api.http).get = "/swisstronik/compliance/{address}";
option (google.api.http).get = "/swisstronik/compliance/address/{address}";
}

rpc AddressesDetails(QueryAddressesDetailsRequest) returns (QueryAddressesDetailsResponse) {
option (google.api.http).get = "/swisstronik/compliance/addresses";
}

rpc IssuerDetails(QueryIssuerDetailsRequest) returns (QueryIssuerDetailsResponse) {
option (google.api.http).get = "/swisstronik/compliance/issuer/{issuerAddress}";
}

rpc IssuersDetails(QueryIssuersDetailsRequest) returns (QueryIssuersDetailsResponse) {
option (google.api.http).get = "/swisstronik/compliance/issuers";
}

rpc VerificationDetails(QueryVerificationDetailsRequest) returns (QueryVerificationDetailsResponse) {
option (google.api.http).get = "/swisstronik/compliance/details/{verificationID}";
option (google.api.http).get = "/swisstronik/compliance/verification/{verificationID}";
}

rpc VerificationsDetails(QueryVerificationsDetailsRequest) returns (QueryVerificationsDetailsResponse) {
option (google.api.http).get = "/swisstronik/compliance/verifications";
}
}

Expand All @@ -44,37 +56,83 @@ message QueryParamsResponse {

// QueryOperatorDetailsRequest is request type for Query/OperatorDetails RPC method.
message QueryOperatorDetailsRequest {
string address = 1;
string operatorAddress = 1;
}

// QueryOperatorDetailsResponse is response type for Query/OperatorDetails RPC method.
message QueryOperatorDetailsResponse {
OperatorDetails details = 1;
}

// QueryAddressDetailsRequest is request type for the Query/VerificationData RPC method.
// QueryAddressDetailsRequest is request type for the Query/AddressDetails RPC method.
message QueryAddressDetailsRequest {
string address = 1;
}

// QueryAddressDetailsResponse is response type for the Query/VerificationData RPC method.
// QueryAddressDetailsResponse is response type for the Query/AddressDetails RPC method.
message QueryAddressDetailsResponse {
// data holds all the verification data for provided address
AddressDetails data = 1;
}

// QueryAddressesDetailsRequest is request type for the Query/AddressesDetails RPC method.
message QueryAddressesDetailsRequest {
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

// QueryAddressesDetailsResponse is response type for the Query/AddressesDetails RPC method.
message QueryAddressesDetailsResponse {
// addresses is a slice of registered addresses for the compliance module
repeated AddressDetails addresses = 1 [(gogoproto.nullable) = false];
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryIssuerDetailsRequest is request type for the Query/IssuerDetails RPC method.
message QueryIssuerDetailsRequest {
string issuerAddress = 1;
}

// QueryIssuerDetailsResponse is response type for the Query/IssuerDetails RPC method.
message QueryIssuerDetailsResponse {
IssuerDetails details = 1;
}

// QueryIssuersDetailsRequest is request type for the Query/IssuersDetails RPC method.
message QueryIssuersDetailsRequest {
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

// QueryIssuersDetailsResponse is response type for the Query/IssuersDetails RPC method.
message QueryIssuersDetailsResponse {
// issuers is a slice of registered issuers for the compliance module
repeated IssuerDetails issuers = 1 [(gogoproto.nullable) = false];
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryVerificationDetailsRequest is request type for the Query/VerificationDetails RPC method.
message QueryVerificationDetailsRequest {
string verificationID = 1;
}

// QueryVerificationDetailsResponse is response type for the Query/VerificationDetails RPC method.
message QueryVerificationDetailsResponse {
VerificationDetails details = 1;
}

// QueryVerificationDetailsRequest is request type for the Query/VerificationsDetails RPC method.
message QueryVerificationsDetailsRequest {
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

// QueryVerificationsDetailsResponse is response type for the Query/VerificationsDetails RPC method.
message QueryVerificationsDetailsResponse {
// verifications is a slice of registered verifications for the compliance module
repeated VerificationDetails verifications = 1 [(gogoproto.nullable) = false];
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
115 changes: 107 additions & 8 deletions x/compliance/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"

"swisstronik/x/compliance/types"
)

Expand All @@ -23,19 +23,22 @@ func GetQueryCmd() *cobra.Command {

cmd.AddCommand(
CmdQueryParams(),
CmdGetOperators(),
CmdGetOperator(),
CmdGetAddressInfo(),
CmdGetAddressesInfo(),
CmdGetIssuerDetails(),
CmdGetIssuersDetails(),
CmdGetVerificationDetails(),
CmdGetVerificationsDetails(),
)

return cmd
}

func CmdGetOperators() *cobra.Command {
func CmdGetOperator() *cobra.Command {
cmd := &cobra.Command{
Use: "get-operator [bech32-or-hex-address]",
Short: "Returns OperatorDetails associated with provided address",
Short: "Returns operator details associated with provided address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
Expand All @@ -47,7 +50,7 @@ func CmdGetOperators() *cobra.Command {
}

req := &types.QueryOperatorDetailsRequest{
Address: address.String(),
OperatorAddress: address.String(),
}

resp, err := queryClient.OperatorDetails(context.Background(), req)
Expand All @@ -67,7 +70,7 @@ func CmdGetOperators() *cobra.Command {
func CmdGetAddressInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "get-address-details [bech32-or-hex-address]",
Short: "Returns AddressDetails associated with provided address",
Short: "Returns address details associated with provided address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
Expand Down Expand Up @@ -96,10 +99,42 @@ func CmdGetAddressInfo() *cobra.Command {
return cmd
}

func CmdGetAddressesInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "get-addresses-details",
Short: "Returns all the address details",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

req := &types.QueryAddressesDetailsRequest{
Pagination: pageReq,
}

resp, err := queryClient.AddressesDetails(context.Background(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(resp)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "address details")

return cmd
}

func CmdGetIssuerDetails() *cobra.Command {
cmd := &cobra.Command{
Use: "get-issuer-details [bech32-or-hex-address]",
Short: "Returns details of provided address",
Short: "Returns issuer details associated with provided address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
Expand Down Expand Up @@ -128,10 +163,42 @@ func CmdGetIssuerDetails() *cobra.Command {
return cmd
}

func CmdGetIssuersDetails() *cobra.Command {
cmd := &cobra.Command{
Use: "get-issuers-details",
Short: "Returns all the issuer details",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

req := &types.QueryIssuersDetailsRequest{
Pagination: pageReq,
}

resp, err := queryClient.IssuersDetails(context.Background(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(resp)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "issuer details")

return cmd
}

func CmdGetVerificationDetails() *cobra.Command {
cmd := &cobra.Command{
Use: "get-verification-details [verification-id]",
Short: "Returns details of provided address",
Short: "Returns verification details associated with provided address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
Expand All @@ -154,3 +221,35 @@ func CmdGetVerificationDetails() *cobra.Command {

return cmd
}

func CmdGetVerificationsDetails() *cobra.Command {
cmd := &cobra.Command{
Use: "get-verifications-details",
Short: "Returns all the verification details",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

req := &types.QueryVerificationsDetailsRequest{
Pagination: pageReq,
}

resp, err := queryClient.VerificationsDetails(context.Background(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(resp)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "verification details")

return cmd
}
1 change: 1 addition & 0 deletions x/compliance/client/cli/query_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"

"swisstronik/x/compliance/types"
)

Expand Down
4 changes: 2 additions & 2 deletions x/compliance/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func CmdSetIssuerVerificationStatus() *cobra.Command {
// CmdSetIssuerDetails command sets provided issuer details.
func CmdSetIssuerDetails() *cobra.Command {
cmd := &cobra.Command{
Use: "set-issuer-details [issuer-address] [name] [description] [url] [logo-url] [legalEntity]",
Use: "set-issuer-details [issuer-address] [name] [description] [url] [logo-url] [legal-entity]",
Short: "Sets issuer details",
Args: cobra.ExactArgs(6),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -186,7 +186,7 @@ func CmdSetIssuerDetails() *cobra.Command {
// CmdUpdateIssuerDetails command updates existing issuer details.
func CmdUpdateIssuerDetails() *cobra.Command {
cmd := &cobra.Command{
Use: "update-issuer-details [issuer-address] [name] [description] [url] [logo-url] [legalEntity]",
Use: "update-issuer-details [issuer-address] [name] [description] [url] [logo-url] [legal-entity]",
Short: "Update issuer details",
Args: cobra.ExactArgs(7),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
Loading

0 comments on commit b9f1910

Please sign in to comment.