[Java] Update auto-generated Java bindings
[ldk-java] / src / main / java / org / ldk / structs / Score.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 java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10 /**
11  * An interface used to score payment channels for path finding.
12  * 
13  * \tScoring is in terms of fees willing to be paid in order to avoid routing through a channel.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class Score extends CommonBase {
17         final bindings.LDKScore bindings_instance;
18         Score(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
19         private Score(bindings.LDKScore arg) {
20                 super(bindings.LDKScore_new(arg));
21                 this.ptrs_to.add(arg);
22                 this.bindings_instance = arg;
23         }
24         @Override @SuppressWarnings("deprecation")
25         protected void finalize() throws Throwable {
26                 if (ptr != 0) { bindings.Score_free(ptr); } super.finalize();
27         }
28         /**
29          * Destroys the object, freeing associated resources. After this call, any access
30          * to this object may result in a SEGFAULT or worse.
31          *
32          * You should generally NEVER call this method. You should let the garbage collector
33          * do this for you when it finalizes objects. However, it may be useful for types
34          * which represent locks and should be closed immediately to avoid holding locks
35          * until the GC runs.
36          */
37         public void destroy() {
38                 if (ptr != 0) { bindings.Score_free(ptr); }
39                 ptr = 0;
40         }
41         public static interface ScoreInterface {
42                 /**
43                  * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
44                  * given channel in the direction from `source` to `target`.
45                  * 
46                  * The channel's capacity (less any other MPP parts that are also being considered for use in
47                  * the same payment) is given by `capacity_msat`. It may be determined from various sources
48                  * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
49                  * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
50                  * Thus, implementations should be overflow-safe.
51                  */
52                 long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage);
53                 /**
54                  * Handles updating channel penalties after failing to route through a channel.
55                  */
56                 void payment_path_failed(RouteHop[] path, long short_channel_id);
57                 /**
58                  * Handles updating channel penalties after successfully routing along a path.
59                  */
60                 void payment_path_successful(RouteHop[] path);
61                 /**
62                  * Handles updating channel penalties after a probe over the given path failed.
63                  */
64                 void probe_failed(RouteHop[] path, long short_channel_id);
65                 /**
66                  * Handles updating channel penalties after a probe over the given path succeeded.
67                  */
68                 void probe_successful(RouteHop[] path);
69                 /**
70                  * Serialize the object into a byte array
71                  */
72                 byte[] write();
73         }
74         private static class LDKScoreHolder { Score held; }
75         public static Score new_impl(ScoreInterface arg) {
76                 final LDKScoreHolder impl_holder = new LDKScoreHolder();
77                 impl_holder.held = new Score(new bindings.LDKScore() {
78                         @Override public long channel_penalty_msat(long short_channel_id, long source, long target, long usage) {
79                                 org.ldk.structs.NodeId source_hu_conv = null; if (source < 0 || source > 4096) { source_hu_conv = new org.ldk.structs.NodeId(null, source); }
80                                 org.ldk.structs.NodeId target_hu_conv = null; if (target < 0 || target > 4096) { target_hu_conv = new org.ldk.structs.NodeId(null, target); }
81                                 org.ldk.structs.ChannelUsage usage_hu_conv = null; if (usage < 0 || usage > 4096) { usage_hu_conv = new org.ldk.structs.ChannelUsage(null, usage); }
82                                 if (usage_hu_conv != null) { usage_hu_conv.ptrs_to.add(this); };
83                                 long ret = arg.channel_penalty_msat(short_channel_id, source_hu_conv, target_hu_conv, usage_hu_conv);
84                                 Reference.reachabilityFence(arg);
85                                 return ret;
86                         }
87                         @Override public void payment_path_failed(long[] path, long short_channel_id) {
88                                 int path_conv_10_len = path.length;
89                                 RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
90                                 for (int k = 0; k < path_conv_10_len; k++) {
91                                         long path_conv_10 = path[k];
92                                         org.ldk.structs.RouteHop path_conv_10_hu_conv = null; if (path_conv_10 < 0 || path_conv_10 > 4096) { path_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, path_conv_10); }
93                                         if (path_conv_10_hu_conv != null) { path_conv_10_hu_conv.ptrs_to.add(this); };
94                                         path_conv_10_arr[k] = path_conv_10_hu_conv;
95                                 }
96                                 arg.payment_path_failed(path_conv_10_arr, short_channel_id);
97                                 Reference.reachabilityFence(arg);
98                         }
99                         @Override public void payment_path_successful(long[] path) {
100                                 int path_conv_10_len = path.length;
101                                 RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
102                                 for (int k = 0; k < path_conv_10_len; k++) {
103                                         long path_conv_10 = path[k];
104                                         org.ldk.structs.RouteHop path_conv_10_hu_conv = null; if (path_conv_10 < 0 || path_conv_10 > 4096) { path_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, path_conv_10); }
105                                         if (path_conv_10_hu_conv != null) { path_conv_10_hu_conv.ptrs_to.add(this); };
106                                         path_conv_10_arr[k] = path_conv_10_hu_conv;
107                                 }
108                                 arg.payment_path_successful(path_conv_10_arr);
109                                 Reference.reachabilityFence(arg);
110                         }
111                         @Override public void probe_failed(long[] path, long short_channel_id) {
112                                 int path_conv_10_len = path.length;
113                                 RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
114                                 for (int k = 0; k < path_conv_10_len; k++) {
115                                         long path_conv_10 = path[k];
116                                         org.ldk.structs.RouteHop path_conv_10_hu_conv = null; if (path_conv_10 < 0 || path_conv_10 > 4096) { path_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, path_conv_10); }
117                                         if (path_conv_10_hu_conv != null) { path_conv_10_hu_conv.ptrs_to.add(this); };
118                                         path_conv_10_arr[k] = path_conv_10_hu_conv;
119                                 }
120                                 arg.probe_failed(path_conv_10_arr, short_channel_id);
121                                 Reference.reachabilityFence(arg);
122                         }
123                         @Override public void probe_successful(long[] path) {
124                                 int path_conv_10_len = path.length;
125                                 RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
126                                 for (int k = 0; k < path_conv_10_len; k++) {
127                                         long path_conv_10 = path[k];
128                                         org.ldk.structs.RouteHop path_conv_10_hu_conv = null; if (path_conv_10 < 0 || path_conv_10 > 4096) { path_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, path_conv_10); }
129                                         if (path_conv_10_hu_conv != null) { path_conv_10_hu_conv.ptrs_to.add(this); };
130                                         path_conv_10_arr[k] = path_conv_10_hu_conv;
131                                 }
132                                 arg.probe_successful(path_conv_10_arr);
133                                 Reference.reachabilityFence(arg);
134                         }
135                         @Override public byte[] write() {
136                                 byte[] ret = arg.write();
137                                 Reference.reachabilityFence(arg);
138                                 return ret;
139                         }
140                 });
141                 return impl_holder.held;
142         }
143         /**
144          * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
145          * given channel in the direction from `source` to `target`.
146          * 
147          * The channel's capacity (less any other MPP parts that are also being considered for use in
148          * the same payment) is given by `capacity_msat`. It may be determined from various sources
149          * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
150          * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
151          * Thus, implementations should be overflow-safe.
152          */
153         public long channel_penalty_msat(long short_channel_id, org.ldk.structs.NodeId source, org.ldk.structs.NodeId target, org.ldk.structs.ChannelUsage usage) {
154                 long ret = bindings.Score_channel_penalty_msat(this.ptr, short_channel_id, source == null ? 0 : source.ptr, target == null ? 0 : target.ptr, usage == null ? 0 : usage.ptr);
155                 Reference.reachabilityFence(this);
156                 Reference.reachabilityFence(short_channel_id);
157                 Reference.reachabilityFence(source);
158                 Reference.reachabilityFence(target);
159                 Reference.reachabilityFence(usage);
160                 if (this != null) { this.ptrs_to.add(source); };
161                 if (this != null) { this.ptrs_to.add(target); };
162                 if (this != null) { this.ptrs_to.add(usage); };
163                 return ret;
164         }
165
166         /**
167          * Handles updating channel penalties after failing to route through a channel.
168          */
169         public void payment_path_failed(RouteHop[] path, long short_channel_id) {
170                 bindings.Score_payment_path_failed(this.ptr, path != null ? Arrays.stream(path).mapToLong(path_conv_10 -> path_conv_10 == null ? 0 : path_conv_10.ptr).toArray() : null, short_channel_id);
171                 Reference.reachabilityFence(this);
172                 Reference.reachabilityFence(path);
173                 Reference.reachabilityFence(short_channel_id);
174                 for (RouteHop path_conv_10: path) { if (this != null) { this.ptrs_to.add(path_conv_10); }; };
175         }
176
177         /**
178          * Handles updating channel penalties after successfully routing along a path.
179          */
180         public void payment_path_successful(RouteHop[] path) {
181                 bindings.Score_payment_path_successful(this.ptr, path != null ? Arrays.stream(path).mapToLong(path_conv_10 -> path_conv_10 == null ? 0 : path_conv_10.ptr).toArray() : null);
182                 Reference.reachabilityFence(this);
183                 Reference.reachabilityFence(path);
184                 for (RouteHop path_conv_10: path) { if (this != null) { this.ptrs_to.add(path_conv_10); }; };
185         }
186
187         /**
188          * Handles updating channel penalties after a probe over the given path failed.
189          */
190         public void probe_failed(RouteHop[] path, long short_channel_id) {
191                 bindings.Score_probe_failed(this.ptr, path != null ? Arrays.stream(path).mapToLong(path_conv_10 -> path_conv_10 == null ? 0 : path_conv_10.ptr).toArray() : null, short_channel_id);
192                 Reference.reachabilityFence(this);
193                 Reference.reachabilityFence(path);
194                 Reference.reachabilityFence(short_channel_id);
195                 for (RouteHop path_conv_10: path) { if (this != null) { this.ptrs_to.add(path_conv_10); }; };
196         }
197
198         /**
199          * Handles updating channel penalties after a probe over the given path succeeded.
200          */
201         public void probe_successful(RouteHop[] path) {
202                 bindings.Score_probe_successful(this.ptr, path != null ? Arrays.stream(path).mapToLong(path_conv_10 -> path_conv_10 == null ? 0 : path_conv_10.ptr).toArray() : null);
203                 Reference.reachabilityFence(this);
204                 Reference.reachabilityFence(path);
205                 for (RouteHop path_conv_10: path) { if (this != null) { this.ptrs_to.add(path_conv_10); }; };
206         }
207
208         /**
209          * Serialize the object into a byte array
210          */
211         public byte[] write() {
212                 byte[] ret = bindings.Score_write(this.ptr);
213                 Reference.reachabilityFence(this);
214                 return ret;
215         }
216
217 }