Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.

Commit 627e4e5

Browse files
committed
feat: android listing nodes and querying list of nodes in graph
fix: linting
1 parent 2625923 commit 627e4e5

4 files changed

Lines changed: 23 additions & 9 deletions

File tree

example/App.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,7 @@ const App = (): ReactElement => {
424424
return setMessage(decode.error.message);
425425
}
426426

427-
const { recover_payee_pub_key, amount_satoshis, description } =
428-
decode.value;
427+
const { amount_satoshis, description } = decode.value;
429428

430429
const ownAmountSats = 1000;
431430
Alert.alert(
@@ -467,7 +466,7 @@ const App = (): ReactElement => {
467466
return setMessage(nodesRes.error.message);
468467
}
469468

470-
let msg = 'Nodes: \n';
469+
let msg = `Nodes (${nodesRes.value.length}): \n`;
471470

472471
const nodes = await ldk.networkGraphNodes(nodesRes.value);
473472
if (nodes.isOk()) {
@@ -478,7 +477,7 @@ const App = (): ReactElement => {
478477
lowest_inbound_channel_fees_base_sat,
479478
announcement_info_last_update,
480479
} = node;
481-
let time = new Date(announcement_info_last_update);
480+
const time = new Date(announcement_info_last_update);
482481

483482
msg += `\n\n${id}\nChannels: ${shortChannelIds.length}\n`;
484483
msg += `Lowest inbound fee: ${lowest_inbound_channel_fees_base_sat} sat\n`;

lib/android/src/main/java/com/reactnativeldk/Helpers.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ val NodeInfo.asJson: WritableMap
146146

147147
val shortChannelIds = Arguments.createArray()
148148
_channels.iterator().forEach { shortChannelIds.pushString(it.toString()) }
149-
result.putArray("channels", shortChannelIds)
150-
149+
result.putArray("shortChannelIds", shortChannelIds)
150+
result.putInt("lowest_inbound_channel_fees_base_sat", (_lowest_inbound_channel_fees?._base_msat ?: 0) / 1000)
151+
result.putInt("lowest_inbound_channel_fees_proportional_millionths", _lowest_inbound_channel_fees?._proportional_millionths ?: 0)
152+
result.putDouble("announcement_info_last_update", (_announcement_info?._last_update ?: 0).toDouble() * 1000)
151153
return result
152154
}
153155

lib/android/src/main/java/com/reactnativeldk/LdkModule.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,20 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
820820
fun networkGraphNodes(nodeIds: ReadableArray, promise: Promise) {
821821
val graph = networkGraph?.read_only() ?: return handleReject(promise, LdkErrors.init_network_graph)
822822

823+
val graphNodes = graph.list_nodes().map { it.as_slice().hexEncodedString() }
824+
825+
//Filter out nodes we don't know about as querying unknown nodes will cause a crash
826+
val includedList: List<String> = nodeIds.toArrayList().map { it as String }.filter { graphNodes.contains(it) }
827+
823828
val list = Arguments.createArray()
824-
//TODO
825-
// val id = NodeId.from_pubkey(nodeId.hexa())
829+
includedList.forEach {
830+
val node = graph.node(NodeId.from_pubkey(it.hexa()))?.asJson
831+
if (node != null) {
832+
node.putString("id", it)
833+
list.pushMap(node)
834+
}
835+
}
836+
826837
promise.resolve(list)
827838
}
828839

lib/ios/Ldk.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,11 @@ class Ldk: NSObject {
852852
return handleReject(reject, .init_network_graph)
853853
}
854854

855+
let graphNodes = networkGraph.list_nodes().map { Data($0.as_slice()).hexEncodedString() }
856+
855857
//Filter out nodes we don't know about as querying unknown nodes will cause a crash
856858
let includedList = nodeIds.map({ $0 as! String }).filter { id in
857-
return networkGraph.list_nodes().contains { id == Data($0.as_slice()).hexEncodedString() }
859+
return graphNodes.contains { id == $0 }
858860
}
859861

860862
return resolve(includedList.map({ id in

0 commit comments

Comments
 (0)