Skip to content

Commit

Permalink
refactor: miscellaneous changes
Browse files Browse the repository at this point in the history
  • Loading branch information
johnletey committed Jul 22, 2024
1 parent 8cd9987 commit 62d4565
Show file tree
Hide file tree
Showing 13 changed files with 1,344 additions and 514 deletions.
2 changes: 1 addition & 1 deletion proto/halo/entitlements/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ message GenesisState {
bool paused = 2;
map<string, bool> public_capabilities = 3;
repeated RoleCapability role_capabilities = 4 [(gogoproto.nullable) = false];
repeated UserRole user_roles = 5;
repeated UserRole user_roles = 5 [(gogoproto.nullable) = false];
}

//
Expand Down
36 changes: 23 additions & 13 deletions proto/halo/entitlements/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ syntax = "proto3";

package halo.entitlements.v1;

import "cosmos/base/query/v1beta1/pagination.proto";
import "google/api/annotations.proto";
import "halo/entitlements/v1/entitlements.proto";

option go_package = "github.com/noble-assets/halo/x/halo/types/entitlements";

Expand All @@ -16,14 +16,17 @@ service Query {
option (google.api.http).get = "/halo/entitlements/v1/paused";
}

rpc PublicCapabilities(QueryPublicCapabilities) returns (QueryPublicCapabilitiesResponse) {
option (google.api.http).get = "/halo/entitlements/v1/public_capabilities";
}
rpc PublicCapability(QueryPublicCapability) returns (QueryPublicCapabilityResponse) {
option (google.api.http).get = "/halo/entitlements/v1/public_capability/{method}";
}

// TODO: Add missing queries.
rpc RoleCapability(QueryRoleCapability) returns (QueryRoleCapabilityResponse) {
option (google.api.http).get = "/halo/entitlements/v1/role_capability/{method}";
}

rpc UserCapability(QueryUserCapability) returns (QueryUserCapabilityResponse) {
option (google.api.http).get = "/halo/entitlements/v1/user_capability/{address}";
}
}

//
Expand All @@ -40,19 +43,26 @@ message QueryPausedResponse {
bool paused = 1;
}

message QueryPublicCapabilities {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
message QueryPublicCapability {
string method = 1;
}

message QueryPublicCapabilitiesResponse {
map<string, bool> public_capabilities = 1;
cosmos.base.query.v1beta1.PageResponse pagination = 2;
message QueryPublicCapabilityResponse {
bool enabled = 1;
}

message QueryPublicCapability {
message QueryRoleCapability {
string method = 1;
}

message QueryPublicCapabilityResponse {
bool enabled = 1;
message QueryRoleCapabilityResponse {
repeated Role roles = 1;
}

message QueryUserCapability {
string address = 1;
}

message QueryUserCapabilityResponse {
repeated Role roles = 1;
}
47 changes: 33 additions & 14 deletions x/halo/client/cli/query_entitlements.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func GetEntitlementsQueryCmd() *cobra.Command {

cmd.AddCommand(QueryEntitlementsOwner())
cmd.AddCommand(QueryPaused())
cmd.AddCommand(QueryPublicCapabilities())
cmd.AddCommand(QueryPublicCapability())
cmd.AddCommand(QueryRoleCapability())

return cmd
}
Expand Down Expand Up @@ -72,22 +72,42 @@ func QueryPaused() *cobra.Command {
return cmd
}

func QueryPublicCapabilities() *cobra.Command {
func QueryPublicCapability() *cobra.Command {
cmd := &cobra.Command{
Use: "public-capabilities",
Short: "Query for all public capabilities",
Args: cobra.NoArgs,
Use: "public-capability [method]",
Short: "Query if a method is public",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := entitlements.NewQueryClient(clientCtx)

pagination, err := client.ReadPageRequest(cmd.Flags())
res, err := queryClient.PublicCapability(context.Background(), &entitlements.QueryPublicCapability{
Method: args[0],
})
if err != nil {
return err
}

res, err := queryClient.PublicCapabilities(context.Background(), &entitlements.QueryPublicCapabilities{
Pagination: pagination,
return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func QueryRoleCapability() *cobra.Command {
cmd := &cobra.Command{
Use: "role-capability [method]",
Short: "Query roles for a specific method",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := entitlements.NewQueryClient(clientCtx)

res, err := queryClient.RoleCapability(context.Background(), &entitlements.QueryRoleCapability{
Method: args[0],
})
if err != nil {
return err
Expand All @@ -98,22 +118,21 @@ func QueryPublicCapabilities() *cobra.Command {
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "public capabilities")

return cmd
}

func QueryPublicCapability() *cobra.Command {
func QueryUserCapability() *cobra.Command {
cmd := &cobra.Command{
Use: "public-capability [method]",
Short: "Query if a method is public",
Use: "user-capability [address]",
Short: "Query roles for a specific address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := entitlements.NewQueryClient(clientCtx)

res, err := queryClient.PublicCapability(context.Background(), &entitlements.QueryPublicCapability{
Method: args[0],
res, err := queryClient.UserCapability(context.Background(), &entitlements.QueryUserCapability{
Address: args[0],
})
if err != nil {
return err
Expand Down
Loading

0 comments on commit 62d4565

Please sign in to comment.