Java gRPC proto issue
Background
Following the Java tutorial here: https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/java.md I have followed all the steps and following imports from the example Main.java are missing:
import lnrpc.Rpc.GetInfoRequest; import lnrpc.Rpc.GetInfoResponse;
Your environment
Maven, pom.xml & file structure is replica of https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/java.md
Steps to reproduce
Copy https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/java.md exactly and you won't be able to import those 2 methods.
Expected behaviour
Those methods should import when the proto file is compiled into Java. (Maybe the lightning.proto file included in https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/java.md isn't correct?)
Actual behaviour
The lnrpc.Rpc.GetInfoRequest & lnrpc.Rpc.GetInfoReponse don't exist. As a matter if fact, there is no lnrpc.Rpc class that is compiled.

Did you generate the java proto classes first? By default make rpc only generates the code for go and js.
You can find more info about how to configure it for gradel/maven here
If not you can edit the lnrpc/gen_protos.sh and add something like
protoc -I/usr/local/include -I. \
--plugin=protoc-gen-grpc-java \
--java_out . \
--java-grpc_out . \
"${file}"
remember to install the protoc-gen-grpc-java first.
You could also use the LightningJ library which compiles them for you.
Did you generate the java proto classes first? By default
make rpconly generates the code for go and js.You can find more info about how to configure it for gradel/maven here
If not you can edit the
lnrpc/gen_protos.shand add something likeprotoc -I/usr/local/include -I. \ --plugin=protoc-gen-grpc-java \ --java_out . \ --java-grpc_out . \ "${file}"remember to install the
protoc-gen-grpc-javafirst.
I already had the things in the pom.xml and the proto file compiles just fine (in java).
This is the LightningGrpc.java file that gets compiled: https://pastebin.com/0Etqq4ti It also generated a LightningOuterClass.java, but it is too large (5.47 MB) to paste.
Some of the methods in the proto file are present (lnrpc.LightningGrpc & lnrpc.LightningGrpc.LightningBlockingStub), however the Rpc methods are absent.
Would you be able to try it yourself and see if the issue is with me or the proto file?
You could also use the LightningJ library which compiles them for you.
I'll take a look at this, but I think that connecting to the gRPC API directly may still be useful for me.
(Maybe the lightning.proto file included in https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/java.md isn't correct?)
It's possible that things are out of date. We accept updates to the documentation periodically to keep things up to date, but we're mostly dependent on the community/contributors for that, since we don't use all these languages in production ourselves. The last update to this section by a contributor was a bit over a year ago: https://github.com/lightningnetwork/lnd/pull/5094.
I'll take a look at this, but I think that connecting to the gRPC API directly may still be useful for me.
That allows you to connect to the gRPC API directly. LightningJ is just a packaged up version of the compiled protos, so just the step you're currently struggling with.
I'll take a look at this, but I think that connecting to the gRPC API directly may still be useful for me.
That allows you to connect to the gRPC API directly. LightningJ is just a packaged up version of the compiled protos, so just the step you're currently struggling with.
I see, I tried to use LightningJ and just copying over the example class seems to cause Runtime errors. Would you mind taking a look at this issue I created on the LightningJ repo? https://github.com/lightningj-org/lightningj/issues/74
You could have a look at https://github.com/C-Otto/lnd-manageJ/tree/main/grpc-client. Maybe option java_multiple_files = true; is what you're missing?
There is a scala version in bitcoin-s if this will help as well
https://github.com/bitcoin-s/bitcoin-s/tree/master/lnd-rpc