Skip to content

Commit

Permalink
Merge pull request #59 from smartcontractkit/feature/BCF-2872-mercury…
Browse files Browse the repository at this point in the history
…-grpc-dial

Support wsrpc --> grpc for Mercury
  • Loading branch information
patrickhuie19 authored May 14, 2024
2 parents dc1e649 + 516d98a commit 32fc9d1
Show file tree
Hide file tree
Showing 11 changed files with 408 additions and 25 deletions.
5 changes: 3 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"github.com/google/uuid"
"google.golang.org/protobuf/proto"

"github.com/smartcontractkit/wsrpc/connectivity"
"github.com/smartcontractkit/wsrpc/internal/backoff"
"github.com/smartcontractkit/wsrpc/internal/message"
"github.com/smartcontractkit/wsrpc/internal/transport"
"github.com/smartcontractkit/wsrpc/internal/wsrpcsync"
"google.golang.org/grpc/connectivity"
)

var (
Expand Down Expand Up @@ -354,7 +354,7 @@ func (cc *ClientConn) register(sd *ServiceDesc, ss interface{}) {
}

// Close tears down the ClientConn and all underlying connections.
func (cc *ClientConn) Close() {
func (cc *ClientConn) Close() error {
cc.cancel()
cc.mu.Lock()
addrConn := cc.addrConn
Expand All @@ -364,6 +364,7 @@ func (cc *ClientConn) Close() {
addrConn.teardown() //closes lower level

cc.wg.Wait()
return nil
}

// Invoke sends the RPC request on the wire and returns after response is
Expand Down
67 changes: 67 additions & 0 deletions cmd/protoc-gen-go-wsrpcgrpc/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// protoc-gen-go-wsrpcgrpc is a plugin for the Google protocol buffer compiler to
// generate Go code. Install it by building this program and making it
// accessible within your PATH with the name:
//
// protoc-gen-go-wsrpcgrpc
//
// The 'go-wsrpcgrpc' suffix becomes part of the argument for the protocol compiler,
// such that it can be invoked as:
//
// protoc --go-wsrpcgrpc_out=. path/to/file.proto
//
// This generates Go service definitions for the protocol buffer defined by
// file.proto. With that input, the output will be written to:
//
// path/to/file_wsrpc_grpc.pb.go
package main

import (
"flag"
"fmt"

"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/pluginpb"
)

type strFlags []string

func (f *strFlags) String() string {
return fmt.Sprintf("%s", *f)
}

func (f *strFlags) Set(value string) error {
*f = append(*f, value)

return nil
}

const version = "0.0.1"

var clientServices strFlags

func main() {
showVersion := flag.Bool("version", false, "print the version and exit")
flag.Parse()
if *showVersion {
fmt.Printf("protoc-gen-go-wsrpcgrpc %v\n", version)

return
}

var flags flag.FlagSet
flags.Var(&clientServices, "client-services", "Generate Client RPC services for these services")

protogen.Options{
ParamFunc: flags.Set,
}.Run(func(gen *protogen.Plugin) error {
gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
for _, f := range gen.Files {
if !f.Generate {
continue
}
generateFile(gen, f)
}

return nil
})
}
Loading

0 comments on commit 32fc9d1

Please sign in to comment.