Add GRPCBlockHeightHeader in clientCtx gRPC requests (#7021)

* Add header in client context grpc

* Second try

* Make headers work

* Use QueryABCI

* Put header in types

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
Amaury Martiny
2020-08-12 14:42:10 +00:00
committed by GitHub
co-authored by Alexander Bezobchuk
parent 4891cc0748
commit b08f160adb
7 changed files with 121 additions and 18 deletions
+1 -2
View File
@@ -3,14 +3,13 @@ package baseapp
import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec/types"
gogogrpc "github.com/gogo/protobuf/grpc"
abci "github.com/tendermint/tendermint/abci/types"
"google.golang.org/grpc"
"google.golang.org/grpc/encoding"
"google.golang.org/grpc/encoding/proto"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
+3 -3
View File
@@ -10,8 +10,8 @@ import (
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
servergrpc "github.com/cosmos/cosmos-sdk/server/grpc"
sdk "github.com/cosmos/cosmos-sdk/types"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
)
// GRPCQueryRouter returns the GRPCQueryRouter of a BaseApp.
@@ -30,7 +30,7 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) {
// Get height header from the request context, if present.
var height int64
if heightHeaders := md.Get(servergrpc.GRPCBlockHeightHeader); len(heightHeaders) > 0 {
if heightHeaders := md.Get(grpctypes.GRPCBlockHeightHeader); len(heightHeaders) > 0 {
height, err = strconv.ParseInt(heightHeaders[0], 10, 64)
if err != nil {
return nil, err
@@ -51,7 +51,7 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) {
if height == 0 {
height = sdkCtx.BlockHeight() // If height was not set in the request, set it to the latest
}
md = metadata.Pairs(servergrpc.GRPCBlockHeightHeader, strconv.FormatInt(height, 10))
md = metadata.Pairs(grpctypes.GRPCBlockHeightHeader, strconv.FormatInt(height, 10))
grpc.SetHeader(grpcCtx, md)
return handler(grpcCtx, req)