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 NetworkGraph ret_hu_conv = new NetworkGraph(null, ret);
27 ret_hu_conv.ptrs_to.add(this);
32 * Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
34 public byte[] write() {
35 byte[] ret = bindings.NetworkGraph_write(this.ptr);
40 * Read a NetworkGraph from a byte array, created by NetworkGraph_write
42 public static Result_NetworkGraphDecodeErrorZ constructor_read(byte[] ser) {
43 long ret = bindings.NetworkGraph_read(ser);
44 Result_NetworkGraphDecodeErrorZ ret_hu_conv = Result_NetworkGraphDecodeErrorZ.constr_from_ptr(ret);
49 * Creates a new, empty, network graph.
51 public static NetworkGraph constructor_new(byte[] genesis_hash) {
52 long ret = bindings.NetworkGraph_new(genesis_hash);
53 NetworkGraph ret_hu_conv = new NetworkGraph(null, ret);
54 ret_hu_conv.ptrs_to.add(ret_hu_conv);
59 * For an already known node (from channel announcements), update its stored properties from a
60 * given node announcement.
62 * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
63 * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
64 * routing messages from a source using a protocol other than the lightning P2P protocol.
66 public Result_NoneLightningErrorZ update_node_from_announcement(NodeAnnouncement msg) {
67 long ret = bindings.NetworkGraph_update_node_from_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
68 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
69 this.ptrs_to.add(msg);
74 * For an already known node (from channel announcements), update its stored properties from a
75 * given node announcement without verifying the associated signatures. Because we aren't
76 * given the associated signatures here we cannot relay the node announcement to any of our
79 public Result_NoneLightningErrorZ update_node_from_unsigned_announcement(UnsignedNodeAnnouncement msg) {
80 long ret = bindings.NetworkGraph_update_node_from_unsigned_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
81 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
82 this.ptrs_to.add(msg);
87 * Store or update channel info from a channel announcement.
89 * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
90 * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
91 * routing messages from a source using a protocol other than the lightning P2P protocol.
93 * If a `chain::Access` object is provided via `chain_access`, it will be called to verify
94 * the corresponding UTXO exists on chain and is correctly-formatted.
96 public Result_NoneLightningErrorZ update_channel_from_announcement(ChannelAnnouncement msg, Access chain_access) {
97 long ret = bindings.NetworkGraph_update_channel_from_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1, chain_access == null ? 0 : chain_access.ptr);
98 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
99 this.ptrs_to.add(msg);
100 this.ptrs_to.add(chain_access);
105 * Store or update channel info from a channel announcement without verifying the associated
106 * signatures. Because we aren't given the associated signatures here we cannot relay the
107 * channel announcement to any of our peers.
109 * If a `chain::Access` object is provided via `chain_access`, it will be called to verify
110 * the corresponding UTXO exists on chain and is correctly-formatted.
112 public Result_NoneLightningErrorZ update_channel_from_unsigned_announcement(UnsignedChannelAnnouncement msg, Access chain_access) {
113 long ret = bindings.NetworkGraph_update_channel_from_unsigned_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1, chain_access == null ? 0 : chain_access.ptr);
114 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
115 this.ptrs_to.add(msg);
116 this.ptrs_to.add(chain_access);
121 * Close a channel if a corresponding HTLC fail was sent.
122 * If permanent, removes a channel from the local storage.
123 * May cause the removal of nodes too, if this was their last channel.
124 * If not permanent, makes channels unavailable for routing.
126 public void close_channel_from_update(long short_channel_id, boolean is_permanent) {
127 bindings.NetworkGraph_close_channel_from_update(this.ptr, short_channel_id, is_permanent);
131 * For an already known (from announcement) channel, update info about one of the directions
134 * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
135 * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
136 * routing messages from a source using a protocol other than the lightning P2P protocol.
138 public Result_NoneLightningErrorZ update_channel(ChannelUpdate msg) {
139 long ret = bindings.NetworkGraph_update_channel(this.ptr, msg == null ? 0 : msg.ptr & ~1);
140 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
141 this.ptrs_to.add(msg);
146 * For an already known (from announcement) channel, update info about one of the directions
147 * of the channel without verifying the associated signatures. Because we aren't given the
148 * associated signatures here we cannot relay the channel update to any of our peers.
150 public Result_NoneLightningErrorZ update_channel_unsigned(UnsignedChannelUpdate msg) {
151 long ret = bindings.NetworkGraph_update_channel_unsigned(this.ptr, msg == null ? 0 : msg.ptr & ~1);
152 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
153 this.ptrs_to.add(msg);