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