Skip to content

Commit

Permalink
Add script to generate LND ruby GRPC service files
Browse files Browse the repository at this point in the history
  • Loading branch information
bumi committed Aug 28, 2020
1 parent 404ed3b commit fbf38c2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,11 @@ see [rubygems](https://rubygems.org/gems/lnrpc) for all available releases.

### Update service definitions

1. Generate `prc_pb.rb` and `rpc_services_pb.rb`
The script `generate-grpc-service-files.sh` can be used to generate the GRPC ruby files.
The files will be stored in `lib/grpc_services`

$ grpc_tools_ruby_protoc -I/usr/local/include -I. -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --ruby_out=plugins=grpc,paths=source_relative:. --grpc_out=. rpc.proto
$ ./generate-grpc-service-files.sh

2. Copy `rpc.proto`, `rpc_pb.rb` and `rpc_services_pb.rb` to `lib`

3. Update `rpc_services_pb.rb` to use `require_relative` to load `rpc_pb`

4. Generate `router_pb.rb` and `router_services_pb.rb`

$ grpc_tools_ruby_protoc -I/usr/local/include -I. -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I$GOPATH/src/github.com/lightningnetwork/lnd/lnrpc --ruby_out=plugins=grpc,paths=source_relative:. --grpc_out=. router.proto

5. Copy `router.proto`, `router_pb.rb` and `router_services_pb.rb` to `lib`

6. Update `router_services_pb.rb` to use `require_relative` to load `router_pb`

## Other resources

Expand Down
30 changes: 30 additions & 0 deletions generate-grpc-service-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
set -o xtrace

FULL_PATH=$(realpath $0)
GEM_DIR=$(dirname $FULL_PATH)
LNRPC_TARGET_DIR="$GEM_DIR/lib/grpc_services"
CURRENT_DIR=$(pwd)
echo $CURRENT_DIR
cd $GOPATH/src/github.com/lightningnetwork/lnd/lnrpc

echo "Generating Ruby GRPC Service Files"

PROTOS="rpc.proto walletunlocker.proto **/*.proto"

# generate files for each proto
for file in $PROTOS; do
DIRECTORY=$(dirname "${file}")
echo "Generating protos from ${file}, into ${LNRPC_TARGET_DIR}/${DIRECTORY}"

# writes all ruby files in the ruby directory
grpc_tools_ruby_protoc -I/usr/local/include \
-I. \
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
-I$GOPATH/src/github.com/lightningnetwork/lnd/lnrpc \
--ruby_out=plugins=grpc,paths=source_relative:${LNRPC_TARGET_DIR} \
--grpc_out=${LNRPC_TARGET_DIR} "${file}"

done

cd $CURRENT_DIR

0 comments on commit fbf38c2

Please sign in to comment.