Skip to content

Commit

Permalink
state query
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Nov 29, 2023
1 parent 461f88c commit 11cf89a
Show file tree
Hide file tree
Showing 5 changed files with 468 additions and 13 deletions.
14 changes: 14 additions & 0 deletions proto/feemarket/feemarket/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ option go_package = "github.com/skip-mev/feemarket/x/feemarket/types";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "feemarket/feemarket/v1/params.proto";
import "feemarket/feemarket/v1/genesis.proto";

// Query Service for the feemarket module.
service Query {
Expand All @@ -15,10 +16,23 @@ service Query {
get : "/feemarket/v1/params"
};
};

// State returns the current feemarket module state.
rpc State(StateRequest) returns (StateResponse) {
option (google.api.http) = {
get : "/feemarket/v1/state"
};
};
}

// ParamsRequest is the request type for the Query/Params RPC method.
message ParamsRequest {}

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

// StateRequest is the request type for the Query/State RPC method.
message StateRequest {}

// StateResponse is the response type for the Query/State RPC method.
message StateResponse { State state = 1 [ (gogoproto.nullable) = false ]; }
28 changes: 28 additions & 0 deletions x/feemarket/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func GetQueryCmd() *cobra.Command {
// add sub-commands
cmd.AddCommand(
GetParamsCmd(),
GetStateCmd(),
)

return cmd
Expand Down Expand Up @@ -55,3 +56,30 @@ func GetParamsCmd() *cobra.Command {

return cmd
}

// GetStateCmd returns the cli-command that queries the current feemarket state.
func GetStateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "state",
Short: "Query for the current feemarket state",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
resp, err := queryClient.State(cmd.Context(), &types.StateRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(&resp.State)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
12 changes: 12 additions & 0 deletions x/feemarket/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,15 @@ func (q QueryServer) Params(goCtx context.Context, _ *types.ParamsRequest) (*typ

return &types.ParamsResponse{Params: params}, nil
}

// State defines a method that returns the current feemarket state.
func (q QueryServer) State(goCtx context.Context, _ *types.StateRequest) (*types.StateResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

state, err := q.k.GetState(ctx)
if err != nil {
return nil, err
}

return &types.StateResponse{State: state}, nil
}
Loading

0 comments on commit 11cf89a

Please sign in to comment.