1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
10 * Represents the network as nodes and channels between them
12 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
13 public class NetworkGraph extends CommonBase {
14 NetworkGraph(Object _dummy, long ptr) { super(ptr); }
15 @Override @SuppressWarnings("deprecation")
16 protected void finalize() throws Throwable {
18 if (ptr != 0) { bindings.NetworkGraph_free(ptr); }
22 * Creates a copy of the NetworkGraph
24 public NetworkGraph clone() {
25 long ret = bindings.NetworkGraph_clone(this.ptr);
26 if (ret < 1024) { return null; }
27 NetworkGraph ret_hu_conv = new NetworkGraph(null, ret);
28 ret_hu_conv.ptrs_to.add(this);
33 * Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
35 public byte[] write() {
36 byte[] ret = bindings.NetworkGraph_write(this.ptr);
41 * Read a NetworkGraph from a byte array, created by NetworkGraph_write
43 public static Result_NetworkGraphDecodeErrorZ read(byte[] ser) {
44 long ret = bindings.NetworkGraph_read(ser);
45 if (ret < 1024) { return null; }
46 Result_NetworkGraphDecodeErrorZ ret_hu_conv = Result_NetworkGraphDecodeErrorZ.constr_from_ptr(ret);
51 * Creates a new, empty, network graph.
53 public static NetworkGraph of(byte[] genesis_hash) {
54 long ret = bindings.NetworkGraph_new(genesis_hash);
55 if (ret < 1024) { return null; }
56 NetworkGraph ret_hu_conv = new NetworkGraph(null, ret);
57 ret_hu_conv.ptrs_to.add(ret_hu_conv);
62 * For an already known node (from channel announcements), update its stored properties from a
63 * given node announcement.
65 * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
66 * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
67 * routing messages from a source using a protocol other than the lightning P2P protocol.
69 public Result_NoneLightningErrorZ update_node_from_announcement(NodeAnnouncement msg) {
70 long ret = bindings.NetworkGraph_update_node_from_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
71 if (ret < 1024) { return null; }
72 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
73 this.ptrs_to.add(msg);
78 * For an already known node (from channel announcements), update its stored properties from a
79 * given node announcement without verifying the associated signatures. Because we aren't
80 * given the associated signatures here we cannot relay the node announcement to any of our
83 public Result_NoneLightningErrorZ update_node_from_unsigned_announcement(UnsignedNodeAnnouncement msg) {
84 long ret = bindings.NetworkGraph_update_node_from_unsigned_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
85 if (ret < 1024) { return null; }
86 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
87 this.ptrs_to.add(msg);
92 * Store or update channel info from a channel announcement.
94 * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
95 * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
96 * routing messages from a source using a protocol other than the lightning P2P protocol.
98 * If a `chain::Access` object is provided via `chain_access`, it will be called to verify
99 * the corresponding UTXO exists on chain and is correctly-formatted.
101 * Note that chain_access (or a relevant inner pointer) may be NULL or all-0s to represent None
103 public Result_NoneLightningErrorZ update_channel_from_announcement(ChannelAnnouncement msg, @Nullable Access chain_access) {
104 long ret = bindings.NetworkGraph_update_channel_from_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1, chain_access == null ? 0 : chain_access.ptr);
105 if (ret < 1024) { return null; }
106 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
107 this.ptrs_to.add(msg);
108 this.ptrs_to.add(chain_access);
113 * Store or update channel info from a channel announcement without verifying the associated
114 * signatures. Because we aren't given the associated signatures here we cannot relay the
115 * channel announcement to any of our peers.
117 * If a `chain::Access` object is provided via `chain_access`, it will be called to verify
118 * the corresponding UTXO exists on chain and is correctly-formatted.
120 * Note that chain_access (or a relevant inner pointer) may be NULL or all-0s to represent None
122 public Result_NoneLightningErrorZ update_channel_from_unsigned_announcement(UnsignedChannelAnnouncement msg, @Nullable Access chain_access) {
123 long ret = bindings.NetworkGraph_update_channel_from_unsigned_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1, chain_access == null ? 0 : chain_access.ptr);
124 if (ret < 1024) { return null; }
125 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
126 this.ptrs_to.add(msg);
127 this.ptrs_to.add(chain_access);
132 * Close a channel if a corresponding HTLC fail was sent.
133 * If permanent, removes a channel from the local storage.
134 * May cause the removal of nodes too, if this was their last channel.
135 * If not permanent, makes channels unavailable for routing.
137 public void close_channel_from_update(long short_channel_id, boolean is_permanent) {
138 bindings.NetworkGraph_close_channel_from_update(this.ptr, short_channel_id, is_permanent);
142 * For an already known (from announcement) channel, update info about one of the directions
145 * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
146 * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
147 * routing messages from a source using a protocol other than the lightning P2P protocol.
149 public Result_NoneLightningErrorZ update_channel(ChannelUpdate msg) {
150 long ret = bindings.NetworkGraph_update_channel(this.ptr, msg == null ? 0 : msg.ptr & ~1);
151 if (ret < 1024) { return null; }
152 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
153 this.ptrs_to.add(msg);
158 * For an already known (from announcement) channel, update info about one of the directions
159 * of the channel without verifying the associated signatures. Because we aren't given the
160 * associated signatures here we cannot relay the channel update to any of our peers.
162 public Result_NoneLightningErrorZ update_channel_unsigned(UnsignedChannelUpdate msg) {
163 long ret = bindings.NetworkGraph_update_channel_unsigned(this.ptr, msg == null ? 0 : msg.ptr & ~1);
164 if (ret < 1024) { return null; }
165 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
166 this.ptrs_to.add(msg);