diff --git a/changelog.md b/changelog.md index d2cf7aa49..25db5aabe 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - autoconfig property prefix of bitcoin jsonrpc cache changed from "jsonrpc.cache" to "jsonrpc-cache" - bitcoin-regtest-starter does not import testcontainer dependencies for bitcoin, electrumx and electrum-daemon automatically anymore +### Added +- module: initial version of modules `ln-common-client-cln` and `ln-common-client-lnd` + ### Changed - improved default specs for bitcoin jsonrpc client caches - upgrade: update spring-boot from v3.1.0 to v3.1.1 diff --git a/ln-common-client/ln-common-client-cln/build.gradle b/ln-common-client/ln-common-client-cln/build.gradle new file mode 100644 index 000000000..1a3371d9e --- /dev/null +++ b/ln-common-client/ln-common-client-cln/build.gradle @@ -0,0 +1,10 @@ +plugins { + id 'java' +} + +description = 'ln common client cln package' + +dependencies { + api project(':ln-common-client:ln-common-client-core') + api "io.github.theborakompanioni:cln-grpc-client-core:${clnGrpcClientVersion}" +} diff --git a/ln-common-client/ln-common-client-cln/src/main/java/org/tbk/lightning/client/common/cln/ClnCommonClient.java b/ln-common-client/ln-common-client-cln/src/main/java/org/tbk/lightning/client/common/cln/ClnCommonClient.java new file mode 100644 index 000000000..0fb5d694f --- /dev/null +++ b/ln-common-client/ln-common-client-cln/src/main/java/org/tbk/lightning/client/common/cln/ClnCommonClient.java @@ -0,0 +1,39 @@ +package org.tbk.lightning.client.common.cln; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.tbk.lightning.client.common.core.LnCommonClient; +import org.tbk.lightning.client.common.core.proto.Chain; +import org.tbk.lightning.client.common.core.proto.GetinfoRequest; +import org.tbk.lightning.client.common.core.proto.GetinfoResponse; +import org.tbk.lightning.cln.grpc.client.NodeGrpc; +import reactor.core.publisher.Mono; + +@RequiredArgsConstructor +public class ClnCommonClient implements LnCommonClient { + + @NonNull + private final NodeGrpc.NodeBlockingStub client; + + @Override + public Mono getInfo(GetinfoRequest request) { + return Mono.fromCallable(() -> { + org.tbk.lightning.cln.grpc.client.GetinfoResponse response = client.getinfo(org.tbk.lightning.cln.grpc.client.GetinfoRequest.newBuilder().build()); + return GetinfoResponse.newBuilder() + .setIdentityPubkey(response.getId()) + .setAlias(response.getAlias()) + .setColor(response.getColor()) + .setNumPeers(response.getNumPeers()) + .setNumPendingChannels(response.getNumActiveChannels()) + .setNumActiveChannels(response.getNumActiveChannels()) + .setNumInactiveChannels(response.getNumInactiveChannels()) + .setVersion(response.getVersion()) + .addChain(Chain.newBuilder() + .setChain("bitcoin") + .setNetwork(response.getNetwork()) + .build()) + .setBlockheight(response.getBlockheight()) + .build(); + }); + } +} diff --git a/ln-common-client/ln-common-client-core/build.gradle b/ln-common-client/ln-common-client-core/build.gradle new file mode 100644 index 000000000..20a7aef41 --- /dev/null +++ b/ln-common-client/ln-common-client-core/build.gradle @@ -0,0 +1,11 @@ +plugins { + id 'java' +} + +apply from: "${project.rootDir}/proto.gradle" + +description = 'ln common client core package' + +dependencies { + api 'io.projectreactor:reactor-core' +} diff --git a/ln-common-client/ln-common-client-core/src/main/java/org/tbk/lightning/client/common/core/LnCommonClient.java b/ln-common-client/ln-common-client-core/src/main/java/org/tbk/lightning/client/common/core/LnCommonClient.java new file mode 100644 index 000000000..f413873aa --- /dev/null +++ b/ln-common-client/ln-common-client-core/src/main/java/org/tbk/lightning/client/common/core/LnCommonClient.java @@ -0,0 +1,11 @@ +package org.tbk.lightning.client.common.core; + +import org.tbk.lightning.client.common.core.proto.GetinfoRequest; +import org.tbk.lightning.client.common.core.proto.GetinfoResponse; +import reactor.core.publisher.Mono; + +public interface LnCommonClient { + + Mono getInfo(GetinfoRequest request); + +} diff --git a/ln-common-client/ln-common-client-core/src/main/java/org/tbk/lightning/client/common/core/core.proto b/ln-common-client/ln-common-client-core/src/main/java/org/tbk/lightning/client/common/core/core.proto new file mode 100644 index 000000000..f80e21b0a --- /dev/null +++ b/ln-common-client/ln-common-client-core/src/main/java/org/tbk/lightning/client/common/core/core.proto @@ -0,0 +1,35 @@ +syntax = "proto3"; + +package lncommonclient; + +import "google/protobuf/any.proto"; +import "google/protobuf/struct.proto"; + +option java_package = "org.tbk.lightning.client.common.core.proto"; +option java_outer_classname = "LnCommonClientProtos"; +option java_multiple_files = true; + +message GetinfoRequest { +} + +message GetinfoResponse { + bytes identityPubkey = 1 [json_name = "identityPubkey"]; + optional string alias = 2 [json_name = "alias"]; + bytes color = 3 [json_name = "color"]; + uint32 num_peers = 4 [json_name = "num_peers"]; + uint32 num_pending_channels = 5 [json_name = "num_pending_channels"]; + uint32 num_active_channels = 6 [json_name = "num_active_channels"]; + uint32 num_inactive_channels = 7 [json_name = "num_inactive_channels"]; + string version = 8 [json_name = "version"]; + // A list of active chains the node is connected to + repeated Chain chain = 9 [json_name = "chains"]; + uint32 blockheight = 10 [json_name = "blockheight"]; +} + +message Chain { + // The blockchain the node is on (i.e. bitcoin) + string chain = 1 [json_name = "chain"]; + + // The network the node is on (e.g. regtest, testnet, mainnet, etc.) + string network = 2 [json_name = "network"]; +} diff --git a/ln-common-client/ln-common-client-lnd/build.gradle b/ln-common-client/ln-common-client-lnd/build.gradle new file mode 100644 index 000000000..b377e95f2 --- /dev/null +++ b/ln-common-client/ln-common-client-lnd/build.gradle @@ -0,0 +1,10 @@ +plugins { + id 'java' +} + +description = 'ln common client lnd package' + +dependencies { + api project(':ln-common-client:ln-common-client-core') + api project(':lnd-grpc-client:lnd-grpc-client-core') +} diff --git a/ln-common-client/ln-common-client-lnd/src/main/java/org/tbk/lightning/client/common/lnd/LndCommonClient.java b/ln-common-client/ln-common-client-lnd/src/main/java/org/tbk/lightning/client/common/lnd/LndCommonClient.java new file mode 100644 index 000000000..6d19a5e4f --- /dev/null +++ b/ln-common-client/ln-common-client-lnd/src/main/java/org/tbk/lightning/client/common/lnd/LndCommonClient.java @@ -0,0 +1,45 @@ +package org.tbk.lightning.client.common.lnd; + +import com.google.protobuf.ByteString; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.lightningj.lnd.proto.LightningApi; +import org.lightningj.lnd.wrapper.SynchronousLndAPI; +import org.lightningj.lnd.wrapper.message.GetInfoRequest; +import org.lightningj.lnd.wrapper.message.GetInfoResponse; +import org.tbk.lightning.client.common.core.LnCommonClient; +import org.tbk.lightning.client.common.core.proto.Chain; +import org.tbk.lightning.client.common.core.proto.GetinfoRequest; +import org.tbk.lightning.client.common.core.proto.GetinfoResponse; +import reactor.core.publisher.Mono; + +@RequiredArgsConstructor +public class LndCommonClient implements LnCommonClient { + + @NonNull + private final SynchronousLndAPI client; + + @Override + public Mono getInfo(GetinfoRequest request) { + return Mono.fromCallable(() -> { + GetInfoResponse response = client.getInfo(new GetInfoRequest(LightningApi.GetInfoRequest.newBuilder().build())); + return GetinfoResponse.newBuilder() + .setIdentityPubkey(ByteString.fromHex(response.getIdentityPubkey())) + .setAlias(response.getAlias()) + .setColor(ByteString.fromHex(response.getColor())) + .setNumPeers(response.getNumPeers()) + .setNumPendingChannels(response.getNumActiveChannels()) + .setNumActiveChannels(response.getNumActiveChannels()) + .setNumInactiveChannels(response.getNumInactiveChannels()) + .setVersion(response.getVersion()) + .addAllChain(response.getChains().stream() + .map(it -> Chain.newBuilder() + .setChain(it.getChain()) + .setNetwork(it.getNetwork()) + .build()) + .toList()) + .setBlockheight(response.getBlockHeight()) + .build(); + }); + } +} diff --git a/lnd-grpc-client/lnd-grpc-client-core/build.gradle b/lnd-grpc-client/lnd-grpc-client-core/build.gradle index 0db3f87e7..85716d451 100644 --- a/lnd-grpc-client/lnd-grpc-client-core/build.gradle +++ b/lnd-grpc-client/lnd-grpc-client-core/build.gradle @@ -8,7 +8,7 @@ dependencies { api "org.lightningj:lightningj:${lightningjVersion}" api "io.grpc:grpc-protobuf:${grpcVersion}" - api "io.grpc:grpc-stub:$grpcVersion" + api "io.grpc:grpc-stub:${grpcVersion}" api 'javax.json:javax.json-api:1.1.4' api 'org.glassfish:javax.json:1.1.4' } diff --git a/settings.gradle b/settings.gradle index 5b9f4ec3c..412da17a2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -20,6 +20,10 @@ include 'bitcoin-zeromq-client:bitcoin-zeromq-client-autoconfigure' include 'bitcoin-zeromq-client:bitcoin-zeromq-client-starter' include 'bitcoin-zeromq-client:bitcoin-zeromq-client-example-application' +include 'ln-common-client:ln-common-client-core' +include 'ln-common-client:ln-common-client-cln' +include 'ln-common-client:ln-common-client-lnd' + include 'lnd-grpc-client:lnd-grpc-client-core' include 'lnd-grpc-client:lnd-grpc-client-autoconfigure' include 'lnd-grpc-client:lnd-grpc-client-starter'