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