Skip to content

Commit

Permalink
feat: grpcreflect and grpchealth handlers (#240)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <[email protected]>
  • Loading branch information
wolf31o2 authored Sep 3, 2024
1 parent 0d0d310 commit c62f67c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ toolchain go1.21.6

require (
connectrpc.com/connect v1.16.2
connectrpc.com/grpchealth v1.3.0
connectrpc.com/grpcreflect v1.2.0
github.com/blinklabs-io/adder v0.23.1
github.com/blinklabs-io/gouroboros v0.93.2
github.com/blinklabs-io/tx-submit-api v0.17.4
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
connectrpc.com/connect v1.16.2 h1:ybd6y+ls7GOlb7Bh5C8+ghA6SvCBajHwxssO2CGFjqE=
connectrpc.com/connect v1.16.2/go.mod h1:n2kgwskMHXC+lVqb18wngEpF95ldBHXjZYJussz5FRc=
connectrpc.com/grpchealth v1.3.0 h1:FA3OIwAvuMokQIXQrY5LbIy8IenftksTP/lG4PbYN+E=
connectrpc.com/grpchealth v1.3.0/go.mod h1:3vpqmX25/ir0gVgW6RdnCPPZRcR6HvqtXX5RNPmDXHM=
connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U=
connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
Expand Down
20 changes: 20 additions & 0 deletions internal/utxorpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"fmt"
"net/http"

"connectrpc.com/connect"
"connectrpc.com/grpchealth"
"connectrpc.com/grpcreflect"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/query/queryconnect"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/submit/submitconnect"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/sync/syncconnect"
Expand All @@ -30,22 +33,39 @@ import (

func Start(cfg *config.Config) error {
mux := http.NewServeMux()
compress1KB := connect.WithCompressMinBytes(1024)
queryPath, queryHandler := queryconnect.NewQueryServiceHandler(
&queryServiceServer{},
compress1KB,
)
submitPath, submitHandler := submitconnect.NewSubmitServiceHandler(
&submitServiceServer{},
compress1KB,
)
syncPath, syncHandler := syncconnect.NewSyncServiceHandler(
&chainSyncServiceServer{},
compress1KB,
)
watchPath, watchHandler := watchconnect.NewWatchServiceHandler(
&watchServiceServer{},
compress1KB,
)
mux.Handle(queryPath, queryHandler)
mux.Handle(submitPath, submitHandler)
mux.Handle(syncPath, syncHandler)
mux.Handle(watchPath, watchHandler)
mux.Handle(grpchealth.NewHandler(grpchealth.NewStaticChecker(queryconnect.QueryServiceName), compress1KB))
mux.Handle(grpchealth.NewHandler(grpchealth.NewStaticChecker(submitconnect.SubmitServiceName), compress1KB))
mux.Handle(grpchealth.NewHandler(grpchealth.NewStaticChecker(syncconnect.SyncServiceName), compress1KB))
mux.Handle(grpchealth.NewHandler(grpchealth.NewStaticChecker(watchconnect.WatchServiceName), compress1KB))
mux.Handle(grpcreflect.NewHandlerV1(grpcreflect.NewStaticReflector(queryconnect.QueryServiceName), compress1KB))
mux.Handle(grpcreflect.NewHandlerV1(grpcreflect.NewStaticReflector(submitconnect.SubmitServiceName), compress1KB))
mux.Handle(grpcreflect.NewHandlerV1(grpcreflect.NewStaticReflector(syncconnect.SyncServiceName), compress1KB))
mux.Handle(grpcreflect.NewHandlerV1(grpcreflect.NewStaticReflector(watchconnect.WatchServiceName), compress1KB))
mux.Handle(grpcreflect.NewHandlerV1Alpha(grpcreflect.NewStaticReflector(queryconnect.QueryServiceName), compress1KB))
mux.Handle(grpcreflect.NewHandlerV1Alpha(grpcreflect.NewStaticReflector(submitconnect.SubmitServiceName), compress1KB))
mux.Handle(grpcreflect.NewHandlerV1Alpha(grpcreflect.NewStaticReflector(syncconnect.SyncServiceName), compress1KB))
mux.Handle(grpcreflect.NewHandlerV1Alpha(grpcreflect.NewStaticReflector(watchconnect.WatchServiceName), compress1KB))
if cfg.Tls.CertFilePath != "" && cfg.Tls.KeyFilePath != "" {
err := http.ListenAndServeTLS(fmt.Sprintf("%s:%d", cfg.Utxorpc.ListenAddress, cfg.Utxorpc.ListenPort),
cfg.Tls.CertFilePath,
Expand Down

0 comments on commit c62f67c

Please sign in to comment.