2021-01-15 13:44:50 +01:00
|
|
|
#!/bin/bash
|
2015-12-30 21:19:09 +01:00
|
|
|
|
2021-01-15 13:44:50 +01:00
|
|
|
set -e
|
2018-10-31 05:14:48 +01:00
|
|
|
|
2021-01-15 13:44:50 +01:00
|
|
|
# generate compiles the *.pb.go stubs from the *.proto files.
|
|
|
|
function generate() {
|
|
|
|
echo "Generating root gRPC server protos"
|
2021-07-27 12:59:59 +02:00
|
|
|
|
2021-07-27 12:59:56 +02:00
|
|
|
PROTOS="lightning.proto walletunlocker.proto stateservice.proto **/*.proto"
|
2021-07-27 12:59:59 +02:00
|
|
|
|
2021-01-15 13:44:50 +01:00
|
|
|
# For each of the sub-servers, we then generate their protos, but a restricted
|
|
|
|
# set as they don't yet require REST proxies, or swagger docs.
|
|
|
|
for file in $PROTOS; do
|
|
|
|
DIRECTORY=$(dirname "${file}")
|
|
|
|
echo "Generating protos from ${file}, into ${DIRECTORY}"
|
2021-07-27 12:59:59 +02:00
|
|
|
|
2021-01-15 13:44:50 +01:00
|
|
|
# Generate the protos.
|
|
|
|
protoc -I/usr/local/include -I. \
|
2021-07-27 12:59:59 +02:00
|
|
|
--go_out . --go_opt paths=source_relative \
|
|
|
|
--go-grpc_out . --go-grpc_opt paths=source_relative \
|
2021-01-15 13:44:50 +01:00
|
|
|
"${file}"
|
2021-07-27 12:59:59 +02:00
|
|
|
|
2021-01-15 13:44:50 +01:00
|
|
|
# Generate the REST reverse proxy.
|
2021-07-27 12:59:52 +02:00
|
|
|
annotationsFile=${file//proto/yaml}
|
2021-01-15 13:44:50 +01:00
|
|
|
protoc -I/usr/local/include -I. \
|
2021-07-27 12:59:59 +02:00
|
|
|
--grpc-gateway_out . \
|
|
|
|
--grpc-gateway_opt logtostderr=true \
|
|
|
|
--grpc-gateway_opt paths=source_relative \
|
|
|
|
--grpc-gateway_opt grpc_api_configuration=${annotationsFile} \
|
2021-01-15 13:44:50 +01:00
|
|
|
"${file}"
|
2021-07-27 12:59:59 +02:00
|
|
|
|
2021-07-26 19:00:45 +02:00
|
|
|
# Generate the swagger file which describes the REST API in detail.
|
2021-01-15 13:44:50 +01:00
|
|
|
protoc -I/usr/local/include -I. \
|
2021-07-27 12:59:59 +02:00
|
|
|
--openapiv2_out . \
|
|
|
|
--openapiv2_opt logtostderr=true \
|
|
|
|
--openapiv2_opt grpc_api_configuration=${annotationsFile} \
|
|
|
|
--openapiv2_opt json_names_for_fields=false \
|
2021-01-15 13:44:50 +01:00
|
|
|
"${file}"
|
|
|
|
done
|
2021-07-26 19:00:45 +02:00
|
|
|
|
|
|
|
# Generate the JSON/WASM client stubs.
|
|
|
|
falafel=$(which falafel)
|
|
|
|
pkg="lnrpc"
|
2022-09-08 00:32:05 +02:00
|
|
|
opts="package_name=$pkg,js_stubs=1"
|
2021-07-26 19:00:45 +02:00
|
|
|
protoc -I/usr/local/include -I. -I.. \
|
|
|
|
--plugin=protoc-gen-custom=$falafel\
|
|
|
|
--custom_out=. \
|
|
|
|
--custom_opt="$opts" \
|
|
|
|
lightning.proto stateservice.proto walletunlocker.proto
|
|
|
|
|
2021-08-23 04:59:06 +02:00
|
|
|
PACKAGES="autopilotrpc chainrpc invoicesrpc neutrinorpc peersrpc routerrpc signrpc verrpc walletrpc watchtowerrpc wtclientrpc devrpc"
|
2021-07-26 19:00:45 +02:00
|
|
|
for package in $PACKAGES; do
|
|
|
|
# Special import for the wallet kit.
|
|
|
|
manual_import=""
|
|
|
|
if [[ "$package" == "walletrpc" ]]; then
|
|
|
|
manual_import="github.com/lightningnetwork/lnd/lnrpc/signrpc"
|
|
|
|
fi
|
|
|
|
|
2022-01-19 20:51:10 +01:00
|
|
|
# Special import for devrpc.
|
|
|
|
if [[ "$package" == "devrpc" ]]; then
|
|
|
|
manual_import="github.com/lightningnetwork/lnd/lnrpc"
|
|
|
|
fi
|
|
|
|
|
2022-09-08 00:32:05 +02:00
|
|
|
opts="package_name=$package,manual_import=$manual_import,js_stubs=1"
|
2021-07-26 19:00:45 +02:00
|
|
|
pushd $package
|
|
|
|
protoc -I/usr/local/include -I. -I.. \
|
|
|
|
--plugin=protoc-gen-custom=$falafel\
|
|
|
|
--custom_out=. \
|
|
|
|
--custom_opt="$opts" \
|
2022-11-22 20:17:02 +01:00
|
|
|
$(find . -name '*.proto')
|
2021-07-26 19:00:45 +02:00
|
|
|
popd
|
|
|
|
done
|
2021-01-15 13:44:50 +01:00
|
|
|
}
|
2018-10-31 05:14:48 +01:00
|
|
|
|
2021-01-15 13:44:50 +01:00
|
|
|
# format formats the *.proto files with the clang-format utility.
|
|
|
|
function format() {
|
|
|
|
find . -name "*.proto" -print0 | xargs -0 clang-format --style=file -i
|
|
|
|
}
|
2020-05-06 16:43:56 +02:00
|
|
|
|
2021-01-15 13:44:50 +01:00
|
|
|
# Compile and format the lnrpc package.
|
|
|
|
pushd lnrpc
|
|
|
|
format
|
|
|
|
generate
|
|
|
|
popd
|
2021-01-15 13:44:54 +01:00
|
|
|
|
|
|
|
if [[ "$COMPILE_MOBILE" == "1" ]]; then
|
|
|
|
pushd mobile
|
|
|
|
./gen_bindings.sh $FALAFEL_VERSION
|
|
|
|
popd
|
|
|
|
fi
|