forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…#427) Co-authored-by: Roman <roman@osmosis.team>
- Loading branch information
1 parent
f94c709
commit 8ee894c
Showing
9 changed files
with
845 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,42 @@ | ||
package node | ||
|
||
import ( | ||
context "context" | ||
|
||
gogogrpc "github.com/gogo/protobuf/grpc" | ||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// RegisterNodeService registers the node gRPC service on the provided gRPC router. | ||
func RegisterNodeService(clientCtx client.Context, server gogogrpc.Server) { | ||
RegisterServiceServer(server, NewQueryServer(clientCtx)) | ||
} | ||
|
||
// RegisterGRPCGatewayRoutes mounts the node gRPC service's GRPC-gateway routes | ||
// on the given mux object. | ||
func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) { | ||
_ = RegisterServiceHandlerClient(context.Background(), mux, NewServiceClient(clientConn)) | ||
} | ||
|
||
var _ ServiceServer = queryServer{} | ||
|
||
type queryServer struct { | ||
clientCtx client.Context | ||
} | ||
|
||
func NewQueryServer(clientCtx client.Context) ServiceServer { | ||
return queryServer{ | ||
clientCtx: clientCtx, | ||
} | ||
} | ||
|
||
func (s queryServer) Config(ctx context.Context, _ *ConfigRequest) (*ConfigResponse, error) { | ||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
|
||
return &ConfigResponse{ | ||
MinimumGasPrice: sdkCtx.MinGasPrices().String(), | ||
}, nil | ||
} |
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,23 @@ | ||
package node | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func TestServiceServer_Config(t *testing.T) { | ||
svr := NewQueryServer(client.Context{}) | ||
|
||
ctx := sdk.Context{}.WithContext(context.Background()).WithMinGasPrices(sdk.NewDecCoins(sdk.NewInt64DecCoin("stake", 15))) | ||
goCtx := sdk.WrapSDKContext(ctx) | ||
|
||
resp, err := svr.Config(goCtx, &ConfigRequest{}) | ||
require.NoError(t, err) | ||
require.NotNil(t, resp) | ||
require.Equal(t, ctx.MinGasPrices().String(), resp.MinimumGasPrice) | ||
} |
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,22 @@ | ||
syntax = "proto3"; | ||
package cosmos.base.node.v1beta1; | ||
|
||
import "google/api/annotations.proto"; | ||
|
||
option go_package = "github.com/cosmos/cosmos-sdk/client/grpc/node"; | ||
|
||
// Service defines the gRPC querier service for node related queries. | ||
service Service { | ||
// Config queries for the operator configuration. | ||
rpc Config(ConfigRequest) returns (ConfigResponse) { | ||
option (google.api.http).get = "/cosmos/base/node/v1beta1/config"; | ||
} | ||
} | ||
|
||
// ConfigRequest defines the request structure for the Config gRPC query. | ||
message ConfigRequest {} | ||
|
||
// ConfigResponse defines the response structure for the Config gRPC query. | ||
message ConfigResponse { | ||
string minimum_gas_price = 1; | ||
} |
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