-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ln): initial version of ln-common-client modules
- Loading branch information
1 parent
d148b9f
commit 0bdf4c2
Showing
10 changed files
with
169 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | ||
} |
39 changes: 39 additions & 0 deletions
39
...-common-client-cln/src/main/java/org/tbk/lightning/client/common/cln/ClnCommonClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
11 changes: 11 additions & 0 deletions
11
...common-client-core/src/main/java/org/tbk/lightning/client/common/core/LnCommonClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...lient/ln-common-client-core/src/main/java/org/tbk/lightning/client/common/core/core.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} |
45 changes: 45 additions & 0 deletions
45
...-common-client-lnd/src/main/java/org/tbk/lightning/client/common/lnd/LndCommonClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters