058daad0cd89ef630e676952d6b85dc0d6ca2780
[ldk-java] / src / main / java / org / ldk / structs / ReadOnlyNetworkGraph.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * A read-only view of [`NetworkGraph`].
13  */
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); }
19         }
20
21         /**
22          * Returns information on a channel with the given id.
23          * 
24          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
25          */
26         @Nullable
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);
34                 return ret_hu_conv;
35         }
36
37         /**
38          * Returns information on a node with the given id.
39          * 
40          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
41          */
42         @Nullable
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);
51                 return ret_hu_conv;
52         }
53
54         /**
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.
58          */
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);
66                 return ret_hu_conv;
67         }
68
69 }