Skip to content

Commit

Permalink
feat(ln): initial version of ln-common-client modules
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Jul 19, 2023
1 parent 339e3c4 commit 042c1db
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions ln-common-client/ln-common-client-cln/build.gradle
Original file line number Diff line number Diff line change
@@ -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}"
}
Original file line number Diff line number Diff line change
@@ -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<GetinfoResponse> 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();
});
}
}
11 changes: 11 additions & 0 deletions ln-common-client/ln-common-client-core/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
Original file line number Diff line number Diff line change
@@ -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<GetinfoResponse> getInfo(GetinfoRequest request);

}
Original file line number Diff line number Diff line change
@@ -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"];
}
10 changes: 10 additions & 0 deletions ln-common-client/ln-common-client-lnd/build.gradle
Original file line number Diff line number Diff line change
@@ -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')
}
Original file line number Diff line number Diff line change
@@ -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<GetinfoResponse> 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();
});
}
}
2 changes: 1 addition & 1 deletion lnd-grpc-client/lnd-grpc-client-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
4 changes: 4 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 042c1db

Please sign in to comment.