2020-06-08 06:41:30 -07:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
gocontext "context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
gogogrpc "github.com/gogo/protobuf/grpc"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/encoding"
|
|
|
|
"google.golang.org/grpc/encoding/proto"
|
2020-07-06 10:03:45 -07:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
2020-06-08 06:41:30 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ gogogrpc.ClientConn = Context{}
|
|
|
|
|
|
|
|
var protoCodec = encoding.GetCodec(proto.Name)
|
|
|
|
|
|
|
|
// Invoke implements the grpc ClientConn.Invoke method
|
|
|
|
func (ctx Context) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error {
|
|
|
|
reqBz, err := protoCodec.Marshal(args)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
resBz, _, err := ctx.QueryWithData(method, reqBz)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-07-03 09:42:12 -07:00
|
|
|
|
|
|
|
err = protoCodec.Unmarshal(resBz, reply)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.InterfaceRegistry != nil {
|
|
|
|
return types.UnpackInterfaces(reply, ctx.InterfaceRegistry)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2020-06-08 06:41:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewStream implements the grpc ClientConn.NewStream method
|
|
|
|
func (Context) NewStream(gocontext.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) {
|
|
|
|
return nil, fmt.Errorf("streaming rpc not supported")
|
|
|
|
}
|