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 ret_hu_conv.ptrs_to.add(this);
38 * Returns information on a node with the given id.
40 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
43 public NodeInfo node(NodeId node_id) {
44 long ret = bindings.ReadOnlyNetworkGraph_node(this.ptr, node_id == null ? 0 : node_id.ptr & ~1);
45 Reference.reachabilityFence(this);
46 Reference.reachabilityFence(node_id);
47 if (ret >= 0 && ret <= 4096) { return null; }
48 org.ldk.structs.NodeInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeInfo(null, ret); }
49 ret_hu_conv.ptrs_to.add(this);
50 this.ptrs_to.add(node_id);
55 * Get network addresses by node id.
56 * Returns None if the requested node is completely unknown,
57 * or if node announcement for the node was never received.
59 public Option_CVec_NetAddressZZ get_addresses(byte[] pubkey) {
60 long ret = bindings.ReadOnlyNetworkGraph_get_addresses(this.ptr, InternalUtils.check_arr_len(pubkey, 33));
61 Reference.reachabilityFence(this);
62 Reference.reachabilityFence(pubkey);
63 if (ret >= 0 && ret <= 4096) { return null; }
64 org.ldk.structs.Option_CVec_NetAddressZZ ret_hu_conv = org.ldk.structs.Option_CVec_NetAddressZZ.constr_from_ptr(ret);
65 ret_hu_conv.ptrs_to.add(this);