Skip to content

Commit

Permalink
Merge pull request #145 from guggero/json-stubs
Browse files Browse the repository at this point in the history
frdrpc: add JSON/WASM client stubs for LNC, move server code into own package
  • Loading branch information
guggero authored May 3, 2022
2 parents d602082 + eb75383 commit cd1e569
Show file tree
Hide file tree
Showing 19 changed files with 338 additions and 101 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:

- name: run imports check
run: make imports

- name: run JS stubs check
run: make rpc-js-compile

########################
# lint code
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ rpc-format:
@$(call print, "Formatting protos.")
cd ./frdrpc; find . -name "*.proto" | xargs clang-format --style=file -i

rpc-js-compile:
@$(call print, "Compiling JSON/WASM stubs.")
GOOS=js GOARCH=wasm $(GOBUILD) $(PKG)/frdrpc

list:
@$(call print, "Listing commands.")
@$(MAKE) -qp | \
Expand Down
6 changes: 3 additions & 3 deletions faraday.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/lightningnetwork/lnd/signal"

"github.com/lightninglabs/faraday/chain"
"github.com/lightninglabs/faraday/frdrpc"
"github.com/lightninglabs/faraday/frdrpcserver"
)

// MinLndVersion is the minimum lnd version required. Note that apis that are
Expand Down Expand Up @@ -85,7 +85,7 @@ func Main() error {
defer client.Close()

// Instantiate the faraday gRPC server.
cfg := &frdrpc.Config{
cfg := &frdrpcserver.Config{
Lnd: client.LndServices,
RPCListen: config.RPCListen,
RESTListen: config.RESTListen,
Expand All @@ -104,7 +104,7 @@ func Main() error {
}
}

server := frdrpc.NewRPCServer(cfg)
server := frdrpcserver.NewRPCServer(cfg)

// Start the server.
if err := server.Start(); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions frdrpc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ARG PROTOBUF_VERSION
ARG GRPC_GATEWAY_VERSION

ENV PROTOC_GEN_GO_GRPC_VERSION="v1.1.0"
ENV FALAFEL_VERSION="v0.9.1"
ENV GOCACHE=/tmp/build/.cache
ENV GOMODCACHE=/tmp/build/.modcache

Expand All @@ -23,6 +24,7 @@ RUN cd /tmp \
&& go get google.golang.org/grpc/cmd/protoc-gen-go-grpc@${PROTOC_GEN_GO_GRPC_VERSION} \
&& go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@${GRPC_GATEWAY_VERSION} \
&& go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@${GRPC_GATEWAY_VERSION} \
&& go get github.com/lightninglabs/falafel@${FALAFEL_VERSION} \
&& chmod -R 777 /tmp/build/

WORKDIR /build
Expand Down
3 changes: 3 additions & 0 deletions frdrpc/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package frdrpc contains the proto files and generated code for faraday's
// grpc server which serves requests for close recommendations.
package frdrpc
200 changes: 200 additions & 0 deletions frdrpc/faradayserver.pb.json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions frdrpc/gen_protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ function generate() {
--openapiv2_opt grpc_api_configuration=faraday.yaml \
--openapiv2_opt json_names_for_fields=false \
faraday.proto

# Generate the JSON/WASM client stubs.
falafel=$(which falafel)
pkg="frdrpc"
opts="package_name=$pkg,api_prefix=1,js_stubs=1,build_tags=// +build js"
protoc -I/usr/local/include -I. -I.. \
--plugin=protoc-gen-custom=$falafel\
--custom_out=. \
--custom_opt="$opts" \
faraday.proto
}

# format formats the *.proto files with the clang-format utility.
Expand Down
11 changes: 6 additions & 5 deletions frdrpc/channel_insights.go → frdrpcserver/channel_insights.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package frdrpc
package frdrpcserver

import (
"context"
"time"

"github.com/lightninglabs/faraday/frdrpc"
"github.com/lightninglabs/faraday/insights"
"github.com/lightninglabs/faraday/lndwrap"
"github.com/lightninglabs/faraday/revenue"
Expand Down Expand Up @@ -41,12 +42,12 @@ func channelInsights(ctx context.Context,
}

func rpcChannelInsightsResponse(
insights []*insights.ChannelInfo) *ChannelInsightsResponse {
insights []*insights.ChannelInfo) *frdrpc.ChannelInsightsResponse {

rpcInsights := make([]*ChannelInsight, 0, len(insights))
rpcInsights := make([]*frdrpc.ChannelInsight, 0, len(insights))

for _, i := range insights {
insight := &ChannelInsight{
insight := &frdrpc.ChannelInsight{
ChanPoint: i.ChannelPoint,
MonitoredSeconds: uint64(i.MonitoredFor.Seconds()),
UptimeSeconds: uint64(i.Uptime.Seconds()),
Expand All @@ -60,5 +61,5 @@ func rpcChannelInsightsResponse(
rpcInsights = append(rpcInsights, insight)
}

return &ChannelInsightsResponse{ChannelInsights: rpcInsights}
return &frdrpc.ChannelInsightsResponse{ChannelInsights: rpcInsights}
}
Loading

0 comments on commit cd1e569

Please sign in to comment.