1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * A read-only view of [`NetworkGraph`].
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ReadOnlyNetworkGraph extends CommonBase implements AutoCloseable {
16 ReadOnlyNetworkGraph(Object _dummy, long ptr) { super(ptr); }
17 @Override public void close() {
18 if (ptr != 0) { bindings.ReadOnlyNetworkGraph_free(ptr); }
22 * Returns information on a channel with the given id.
24 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
27 public ChannelInfo channel(long short_channel_id) {
28 long ret = bindings.ReadOnlyNetworkGraph_channel(this.ptr, short_channel_id);
29 Reference.reachabilityFence(this);
30 Reference.reachabilityFence(short_channel_id);
31 if (ret >= 0 && ret <= 4096) { return null; }
32 org.ldk.structs.ChannelInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelInfo(null, ret); }
33 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
38 * Returns the list of channels in the graph
40 public long[] list_channels() {
41 long[] ret = bindings.ReadOnlyNetworkGraph_list_channels(this.ptr);
42 Reference.reachabilityFence(this);
47 * Returns information on a node with the given id.
49 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
52 public NodeInfo node(NodeId node_id) {
53 long ret = bindings.ReadOnlyNetworkGraph_node(this.ptr, node_id == null ? 0 : node_id.ptr);
54 Reference.reachabilityFence(this);
55 Reference.reachabilityFence(node_id);
56 if (ret >= 0 && ret <= 4096) { return null; }
57 org.ldk.structs.NodeInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeInfo(null, ret); }
58 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
59 if (this != null) { this.ptrs_to.add(node_id); };
64 * Returns the list of nodes in the graph
66 public NodeId[] list_nodes() {
67 long[] ret = bindings.ReadOnlyNetworkGraph_list_nodes(this.ptr);
68 Reference.reachabilityFence(this);
69 int ret_conv_8_len = ret.length;
70 NodeId[] ret_conv_8_arr = new NodeId[ret_conv_8_len];
71 for (int i = 0; i < ret_conv_8_len; i++) {
72 long ret_conv_8 = ret[i];
73 org.ldk.structs.NodeId ret_conv_8_hu_conv = null; if (ret_conv_8 < 0 || ret_conv_8 > 4096) { ret_conv_8_hu_conv = new org.ldk.structs.NodeId(null, ret_conv_8); }
74 if (ret_conv_8_hu_conv != null) { ret_conv_8_hu_conv.ptrs_to.add(this); };
75 ret_conv_8_arr[i] = ret_conv_8_hu_conv;
77 return ret_conv_8_arr;
81 * Get network addresses by node id.
82 * Returns None if the requested node is completely unknown,
83 * or if node announcement for the node was never received.
85 public Option_CVec_NetAddressZZ get_addresses(byte[] pubkey) {
86 long ret = bindings.ReadOnlyNetworkGraph_get_addresses(this.ptr, InternalUtils.check_arr_len(pubkey, 33));
87 Reference.reachabilityFence(this);
88 Reference.reachabilityFence(pubkey);
89 if (ret >= 0 && ret <= 4096) { return null; }
90 org.ldk.structs.Option_CVec_NetAddressZZ ret_hu_conv = org.ldk.structs.Option_CVec_NetAddressZZ.constr_from_ptr(ret);
91 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };