Update auto-generated bindings
[ldk-java] / src / main / java / org / ldk / structs / NetworkGraph.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 javax.annotation.Nullable;
8
9
10 /**
11  * Represents the network as nodes and channels between them
12  */
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 {
18                 super.finalize();
19                 if (ptr != 0) { bindings.NetworkGraph_free(ptr); }
20         }
21
22         long clone_ptr() {
23                 long ret = bindings.NetworkGraph_clone_ptr(this.ptr);
24                 return ret;
25         }
26
27         /**
28          * Creates a copy of the NetworkGraph
29          */
30         public NetworkGraph clone() {
31                 long ret = bindings.NetworkGraph_clone(this.ptr);
32                 if (ret >= 0 && ret <= 4096) { return null; }
33                 NetworkGraph ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new NetworkGraph(null, ret); }
34                 ret_hu_conv.ptrs_to.add(this);
35                 return ret_hu_conv;
36         }
37
38         /**
39          * Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
40          */
41         public byte[] write() {
42                 byte[] ret = bindings.NetworkGraph_write(this.ptr);
43                 return ret;
44         }
45
46         /**
47          * Read a NetworkGraph from a byte array, created by NetworkGraph_write
48          */
49         public static Result_NetworkGraphDecodeErrorZ read(byte[] ser) {
50                 long ret = bindings.NetworkGraph_read(ser);
51                 if (ret >= 0 && ret <= 4096) { return null; }
52                 Result_NetworkGraphDecodeErrorZ ret_hu_conv = Result_NetworkGraphDecodeErrorZ.constr_from_ptr(ret);
53                 return ret_hu_conv;
54         }
55
56         /**
57          * Creates a new, empty, network graph.
58          */
59         public static NetworkGraph of(byte[] genesis_hash) {
60                 long ret = bindings.NetworkGraph_new(InternalUtils.check_arr_len(genesis_hash, 32));
61                 if (ret >= 0 && ret <= 4096) { return null; }
62                 NetworkGraph ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new NetworkGraph(null, ret); }
63                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
64                 return ret_hu_conv;
65         }
66
67         /**
68          * Returns a read-only view of the network graph.
69          */
70         public ReadOnlyNetworkGraph read_only() {
71                 long ret = bindings.NetworkGraph_read_only(this.ptr);
72                 if (ret >= 0 && ret <= 4096) { return null; }
73                 ReadOnlyNetworkGraph ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ReadOnlyNetworkGraph(null, ret); }
74                 ret_hu_conv.ptrs_to.add(this);
75                 return ret_hu_conv;
76         }
77
78         /**
79          * For an already known node (from channel announcements), update its stored properties from a
80          * given node announcement.
81          * 
82          * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
83          * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
84          * routing messages from a source using a protocol other than the lightning P2P protocol.
85          */
86         public Result_NoneLightningErrorZ update_node_from_announcement(NodeAnnouncement msg) {
87                 long ret = bindings.NetworkGraph_update_node_from_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
88                 if (ret >= 0 && ret <= 4096) { return null; }
89                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
90                 this.ptrs_to.add(msg);
91                 return ret_hu_conv;
92         }
93
94         /**
95          * For an already known node (from channel announcements), update its stored properties from a
96          * given node announcement without verifying the associated signatures. Because we aren't
97          * given the associated signatures here we cannot relay the node announcement to any of our
98          * peers.
99          */
100         public Result_NoneLightningErrorZ update_node_from_unsigned_announcement(UnsignedNodeAnnouncement msg) {
101                 long ret = bindings.NetworkGraph_update_node_from_unsigned_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
102                 if (ret >= 0 && ret <= 4096) { return null; }
103                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
104                 this.ptrs_to.add(msg);
105                 return ret_hu_conv;
106         }
107
108         /**
109          * Store or update channel info from a channel announcement.
110          * 
111          * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
112          * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
113          * routing messages from a source using a protocol other than the lightning P2P protocol.
114          * 
115          * If a `chain::Access` object is provided via `chain_access`, it will be called to verify
116          * the corresponding UTXO exists on chain and is correctly-formatted.
117          */
118         public Result_NoneLightningErrorZ update_channel_from_announcement(ChannelAnnouncement msg, Option_AccessZ chain_access) {
119                 long ret = bindings.NetworkGraph_update_channel_from_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1, chain_access.ptr);
120                 if (ret >= 0 && ret <= 4096) { return null; }
121                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
122                 this.ptrs_to.add(msg);
123                 this.ptrs_to.add(chain_access);
124                 return ret_hu_conv;
125         }
126
127         /**
128          * Store or update channel info from a channel announcement without verifying the associated
129          * signatures. Because we aren't given the associated signatures here we cannot relay the
130          * channel announcement to any of our peers.
131          * 
132          * If a `chain::Access` object is provided via `chain_access`, it will be called to verify
133          * the corresponding UTXO exists on chain and is correctly-formatted.
134          */
135         public Result_NoneLightningErrorZ update_channel_from_unsigned_announcement(UnsignedChannelAnnouncement msg, Option_AccessZ chain_access) {
136                 long ret = bindings.NetworkGraph_update_channel_from_unsigned_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1, chain_access.ptr);
137                 if (ret >= 0 && ret <= 4096) { return null; }
138                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
139                 this.ptrs_to.add(msg);
140                 this.ptrs_to.add(chain_access);
141                 return ret_hu_conv;
142         }
143
144         /**
145          * Close a channel if a corresponding HTLC fail was sent.
146          * If permanent, removes a channel from the local storage.
147          * May cause the removal of nodes too, if this was their last channel.
148          * If not permanent, makes channels unavailable for routing.
149          */
150         public void close_channel_from_update(long short_channel_id, boolean is_permanent) {
151                 bindings.NetworkGraph_close_channel_from_update(this.ptr, short_channel_id, is_permanent);
152         }
153
154         /**
155          * Marks a node in the graph as failed.
156          */
157         public void fail_node(byte[] _node_id, boolean is_permanent) {
158                 bindings.NetworkGraph_fail_node(this.ptr, InternalUtils.check_arr_len(_node_id, 33), is_permanent);
159         }
160
161         /**
162          * For an already known (from announcement) channel, update info about one of the directions
163          * of the channel.
164          * 
165          * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
166          * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
167          * routing messages from a source using a protocol other than the lightning P2P protocol.
168          */
169         public Result_NoneLightningErrorZ update_channel(ChannelUpdate msg) {
170                 long ret = bindings.NetworkGraph_update_channel(this.ptr, msg == null ? 0 : msg.ptr & ~1);
171                 if (ret >= 0 && ret <= 4096) { return null; }
172                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
173                 this.ptrs_to.add(msg);
174                 return ret_hu_conv;
175         }
176
177         /**
178          * For an already known (from announcement) channel, update info about one of the directions
179          * of the channel without verifying the associated signatures. Because we aren't given the
180          * associated signatures here we cannot relay the channel update to any of our peers.
181          */
182         public Result_NoneLightningErrorZ update_channel_unsigned(UnsignedChannelUpdate msg) {
183                 long ret = bindings.NetworkGraph_update_channel_unsigned(this.ptr, msg == null ? 0 : msg.ptr & ~1);
184                 if (ret >= 0 && ret <= 4096) { return null; }
185                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
186                 this.ptrs_to.add(msg);
187                 return ret_hu_conv;
188         }
189
190 }