2021-05-25 16:33:44 +02:00
|
|
|
#!/bin/bash
|
2019-03-06 21:13:50 +01:00
|
|
|
|
2025-05-21 14:08:54 +02:00
|
|
|
# The script uses the following env var:
|
|
|
|
|
# LND_DIR - the place where it can find LND of the pinned version, to use its
|
|
|
|
|
# lnrpc/ subdir for .proto imports.
|
|
|
|
|
|
2019-03-12 15:34:45 -07:00
|
|
|
set -e
|
|
|
|
|
|
2021-05-25 16:33:44 +02:00
|
|
|
# generate compiles the *.pb.go stubs from the *.proto files.
|
|
|
|
|
function generate() {
|
2025-05-21 14:08:54 +02:00
|
|
|
proto_paths=(-I/usr/local/include -I. -I.. -I"$LND_DIR")
|
|
|
|
|
|
2021-05-25 16:33:44 +02:00
|
|
|
# Generate the gRPC bindings for all proto files.
|
|
|
|
|
for file in ./*.proto
|
|
|
|
|
do
|
2025-05-21 14:08:54 +02:00
|
|
|
protoc "${proto_paths[@]}" \
|
2021-07-29 13:32:53 +02:00
|
|
|
--go_out . --go_opt paths=source_relative \
|
|
|
|
|
--go-grpc_out . --go-grpc_opt paths=source_relative \
|
2021-05-25 16:33:44 +02:00
|
|
|
"${file}"
|
|
|
|
|
done
|
2025-05-21 14:08:54 +02:00
|
|
|
|
2021-05-25 16:33:44 +02:00
|
|
|
# Generate the REST reverse proxy for the client only.
|
2025-05-21 14:08:54 +02:00
|
|
|
protoc "${proto_paths[@]}" \
|
2021-07-29 13:32:53 +02:00
|
|
|
--grpc-gateway_out . \
|
|
|
|
|
--grpc-gateway_opt logtostderr=true \
|
|
|
|
|
--grpc-gateway_opt paths=source_relative \
|
|
|
|
|
--grpc-gateway_opt grpc_api_configuration=client.yaml \
|
|
|
|
|
client.proto
|
2019-03-12 15:34:45 -07:00
|
|
|
|
2021-05-25 16:33:44 +02:00
|
|
|
# Finally, generate the swagger file which describes the REST API in detail.
|
2025-05-21 14:08:54 +02:00
|
|
|
protoc "${proto_paths[@]}" \
|
2021-07-29 13:32:53 +02:00
|
|
|
--openapiv2_out . \
|
|
|
|
|
--openapiv2_opt logtostderr=true \
|
|
|
|
|
--openapiv2_opt grpc_api_configuration=client.yaml \
|
|
|
|
|
--openapiv2_opt json_names_for_fields=false \
|
|
|
|
|
client.proto
|
2021-07-26 18:44:31 +02:00
|
|
|
|
|
|
|
|
# Generate the JSON/WASM client stubs.
|
|
|
|
|
falafel=$(which falafel)
|
|
|
|
|
pkg="looprpc"
|
2022-09-08 10:31:04 -04:00
|
|
|
opts="package_name=$pkg,js_stubs=1"
|
2025-05-21 14:08:54 +02:00
|
|
|
protoc "${proto_paths[@]}" \
|
2021-07-26 18:44:31 +02:00
|
|
|
--plugin=protoc-gen-custom=$falafel\
|
|
|
|
|
--custom_out=. \
|
|
|
|
|
--custom_opt="$opts" \
|
|
|
|
|
client.proto
|
2021-05-25 16:33:44 +02:00
|
|
|
}
|
2019-03-06 15:38:36 -08:00
|
|
|
|
2021-05-25 16:33:44 +02:00
|
|
|
# format formats the *.proto files with the clang-format utility.
|
|
|
|
|
function format() {
|
|
|
|
|
find . -name "*.proto" -print0 | xargs -0 clang-format --style=file -i
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Compile and format the looprpc package.
|
2025-05-21 14:08:54 +02:00
|
|
|
# Check if we're already in the looprpc directory.
|
|
|
|
|
if [[ $(basename "$PWD") == "looprpc" ]]; then
|
|
|
|
|
format
|
|
|
|
|
generate
|
|
|
|
|
else
|
|
|
|
|
pushd looprpc
|
|
|
|
|
format
|
|
|
|
|
generate
|
|
|
|
|
popd
|
|
|
|
|
fi
|