error: incompatible types building asynchronous API example
Closed this issue · 2 comments
yayitswei commented
I'm having trouble building your asynchronous API example:
package test;
import org.lightningj.lnd.wrapper.AsynchronousLndAPI;
import io.grpc.stub.StreamObserver;
import org.lightningj.lnd.proto.LightningApi.WalletBalanceResponse;
import org.lightningj.lnd.proto.LightningApi.Invoice;
import java.io.File;
public class ApiTest {
public static void main(String[] args) throws Exception{
AsynchronousLndAPI asynchronousLndAPI = new AsynchronousLndAPI("localhost",10001,
new File("tls.cert"),
new File("admin.macaroon"));
try {
asynchronousLndAPI.subscribeInvoices(new StreamObserver<Invoice>() {
@Override
public void onNext(Invoice value) {
System.out.println("Received Invoice");
}
@Override
public void onError(Throwable t) {
System.err.println("Error occurred during subscribeInvoices call: " + t.getMessage());
t.printStackTrace(System.err);
}
@Override
public void onCompleted() {
System.out.println("subscribeInvoices call closed.");
}
});
while (true) {
Thread.sleep(1000);
}
} finally {
asynchronousLndAPI.close();
}
}
}
The error is
/.../ApiTest.java:14: error: incompatible types: <anonymous StreamObserver<org.lightningj.lnd.proto.LightningApi.Invoice>> cannot be converted to StreamObserver<org.lightningj.lnd.wrapper.message.Invoice>
asynchronousLndAPI.subscribeInvoices(new StreamObserver<Invoice>() {
Am I importing the wrong files? Thanks!
yayitswei commented
Nevermind, got it working! Needed to change these lines:
import org.lightningj.lnd.wrapper.message.WalletBalanceResponse;
import org.lightningj.lnd.wrapper.message.Invoice;
Guessing that's a gRPC thing?
herrvendil commented
Hi
Yes the proto class is the "low-level" api generated by the grpc java library. The wrapper classes are the "high-level" api with added support for JSON, XML etc. So generally use "wrapper" imports instead of "proto".