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
8
9 /**
10  * Represents the network as nodes and channels between them
11  */
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 {
17                 super.finalize();
18                 if (ptr != 0) { bindings.NetworkGraph_free(ptr); }
19         }
20
21         /**
22          * Creates a copy of the NetworkGraph
23          */
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);
29                 return ret_hu_conv;
30         }
31
32         /**
33          * Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
34          */
35         public byte[] write() {
36                 byte[] ret = bindings.NetworkGraph_write(this.ptr);
37                 return ret;
38         }
39
40         /**
41          * Read a NetworkGraph from a byte array, created by NetworkGraph_write
42          */
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);
47                 return ret_hu_conv;
48         }
49
50         /**
51          * Creates a new, empty, network graph.
52          */
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);
58                 return ret_hu_conv;
59         }
60
61         /**
62          * For an already known node (from channel announcements), update its stored properties from a
63          * given node announcement.
64          * 
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.
68          */
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);
74                 return ret_hu_conv;
75         }
76
77         /**
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
81          * peers.
82          */
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);
88                 return ret_hu_conv;
89         }
90
91         /**
92          * Store or update channel info from a channel announcement.
93          * 
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.
97          * 
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.
100          * 
101          * Note that chain_access (or a relevant inner pointer) may be NULL or all-0s to represent None
102          */
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);
109                 return ret_hu_conv;
110         }
111
112         /**
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.
116          * 
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.
119          * 
120          * Note that chain_access (or a relevant inner pointer) may be NULL or all-0s to represent None
121          */
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);
128                 return ret_hu_conv;
129         }
130
131         /**
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.
136          */
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);
139         }
140
141         /**
142          * For an already known (from announcement) channel, update info about one of the directions
143          * of the channel.
144          * 
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.
148          */
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);
154                 return ret_hu_conv;
155         }
156
157         /**
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.
161          */
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);
167                 return ret_hu_conv;
168         }
169
170 }