lnd icon indicating copy to clipboard operation
lnd copied to clipboard

Java gRPC proto issue

Open theobong opened this issue 4 years ago • 9 comments

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.

image

theobong avatar Jul 03 '22 17:07 theobong

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.

positiveblue avatar Jul 05 '22 19:07 positiveblue

You could also use the LightningJ library which compiles them for you.

guggero avatar Jul 05 '22 19:07 guggero

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.

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?

theobong avatar Jul 05 '22 23:07 theobong

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.

theobong avatar Jul 05 '22 23:07 theobong

(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.

Roasbeef avatar Jul 05 '22 23:07 Roasbeef

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.

guggero avatar Jul 06 '22 08:07 guggero

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

theobong avatar Jul 06 '22 23:07 theobong

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?

C-Otto avatar Jul 27 '22 17:07 C-Otto

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

benthecarman avatar Aug 05 '22 05:08 benthecarman