[Java] Update auto-generated Java bindings to LDK 0.0.110
[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         public static interface ScoreInterface {
30                 /**
31                  * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
32                  * given channel in the direction from `source` to `target`.
33                  * 
34                  * The channel's capacity (less any other MPP parts that are also being considered for use in
35                  * the same payment) is given by `capacity_msat`. It may be determined from various sources
36                  * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
37                  * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
38                  * Thus, implementations should be overflow-safe.
39                  */
40                 long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage);
41                 /**
42                  * Handles updating channel penalties after failing to route through a channel.
43                  */
44                 void payment_path_failed(RouteHop[] path, long short_channel_id);
45                 /**
46                  * Handles updating channel penalties after successfully routing along a path.
47                  */
48                 void payment_path_successful(RouteHop[] path);
49                 /**
50                  * Handles updating channel penalties after a probe over the given path failed.
51                  */
52                 void probe_failed(RouteHop[] path, long short_channel_id);
53                 /**
54                  * Handles updating channel penalties after a probe over the given path succeeded.
55                  */
56                 void probe_successful(RouteHop[] path);
57                 /**
58                  * Serialize the object into a byte array
59                  */
60                 byte[] write();
61         }
62         private static class LDKScoreHolder { Score held; }
63         public static Score new_impl(ScoreInterface arg) {
64                 final LDKScoreHolder impl_holder = new LDKScoreHolder();
65                 impl_holder.held = new Score(new bindings.LDKScore() {
66                         @Override public long channel_penalty_msat(long short_channel_id, long source, long target, long usage) {
67                                 org.ldk.structs.NodeId source_hu_conv = null; if (source < 0 || source > 4096) { source_hu_conv = new org.ldk.structs.NodeId(null, source); }
68                                 org.ldk.structs.NodeId target_hu_conv = null; if (target < 0 || target > 4096) { target_hu_conv = new org.ldk.structs.NodeId(null, target); }
69                                 org.ldk.structs.ChannelUsage usage_hu_conv = null; if (usage < 0 || usage > 4096) { usage_hu_conv = new org.ldk.structs.ChannelUsage(null, usage); }
70                                 usage_hu_conv.ptrs_to.add(this);
71                                 long ret = arg.channel_penalty_msat(short_channel_id, source_hu_conv, target_hu_conv, usage_hu_conv);
72                                 Reference.reachabilityFence(arg);
73                                 return ret;
74                         }
75                         @Override public void payment_path_failed(long[] path, long short_channel_id) {
76                                 int path_conv_10_len = path.length;
77                                 RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
78                                 for (int k = 0; k < path_conv_10_len; k++) {
79                                         long path_conv_10 = path[k];
80                                         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); }
81                                         path_conv_10_hu_conv.ptrs_to.add(this);
82                                         path_conv_10_arr[k] = path_conv_10_hu_conv;
83                                 }
84                                 arg.payment_path_failed(path_conv_10_arr, short_channel_id);
85                                 Reference.reachabilityFence(arg);
86                         }
87                         @Override public void payment_path_successful(long[] path) {
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                                         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_successful(path_conv_10_arr);
97                                 Reference.reachabilityFence(arg);
98                         }
99                         @Override public void probe_failed(long[] path, long short_channel_id) {
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                                         path_conv_10_hu_conv.ptrs_to.add(this);
106                                         path_conv_10_arr[k] = path_conv_10_hu_conv;
107                                 }
108                                 arg.probe_failed(path_conv_10_arr, short_channel_id);
109                                 Reference.reachabilityFence(arg);
110                         }
111                         @Override public void probe_successful(long[] path) {
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                                         path_conv_10_hu_conv.ptrs_to.add(this);
118                                         path_conv_10_arr[k] = path_conv_10_hu_conv;
119                                 }
120                                 arg.probe_successful(path_conv_10_arr);
121                                 Reference.reachabilityFence(arg);
122                         }
123                         @Override public byte[] write() {
124                                 byte[] ret = arg.write();
125                                 Reference.reachabilityFence(arg);
126                                 return ret;
127                         }
128                 });
129                 return impl_holder.held;
130         }
131         /**
132          * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
133          * given channel in the direction from `source` to `target`.
134          * 
135          * The channel's capacity (less any other MPP parts that are also being considered for use in
136          * the same payment) is given by `capacity_msat`. It may be determined from various sources
137          * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
138          * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
139          * Thus, implementations should be overflow-safe.
140          */
141         public long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage) {
142                 long ret = bindings.Score_channel_penalty_msat(this.ptr, short_channel_id, source == null ? 0 : source.ptr & ~1, target == null ? 0 : target.ptr & ~1, usage == null ? 0 : usage.ptr & ~1);
143                 Reference.reachabilityFence(this);
144                 Reference.reachabilityFence(short_channel_id);
145                 Reference.reachabilityFence(source);
146                 Reference.reachabilityFence(target);
147                 Reference.reachabilityFence(usage);
148                 this.ptrs_to.add(source);
149                 this.ptrs_to.add(target);
150                 return ret;
151         }
152
153         /**
154          * Handles updating channel penalties after failing to route through a channel.
155          */
156         public void payment_path_failed(RouteHop[] path, long short_channel_id) {
157                 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 & ~1).toArray() : null, short_channel_id);
158                 Reference.reachabilityFence(this);
159                 Reference.reachabilityFence(path);
160                 Reference.reachabilityFence(short_channel_id);
161         }
162
163         /**
164          * Handles updating channel penalties after successfully routing along a path.
165          */
166         public void payment_path_successful(RouteHop[] path) {
167                 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 & ~1).toArray() : null);
168                 Reference.reachabilityFence(this);
169                 Reference.reachabilityFence(path);
170         }
171
172         /**
173          * Handles updating channel penalties after a probe over the given path failed.
174          */
175         public void probe_failed(RouteHop[] path, long short_channel_id) {
176                 bindings.Score_probe_failed(this.ptr, path != null ? Arrays.stream(path).mapToLong(path_conv_10 -> path_conv_10 == null ? 0 : path_conv_10.ptr & ~1).toArray() : null, short_channel_id);
177                 Reference.reachabilityFence(this);
178                 Reference.reachabilityFence(path);
179                 Reference.reachabilityFence(short_channel_id);
180         }
181
182         /**
183          * Handles updating channel penalties after a probe over the given path succeeded.
184          */
185         public void probe_successful(RouteHop[] path) {
186                 bindings.Score_probe_successful(this.ptr, path != null ? Arrays.stream(path).mapToLong(path_conv_10 -> path_conv_10 == null ? 0 : path_conv_10.ptr & ~1).toArray() : null);
187                 Reference.reachabilityFence(this);
188                 Reference.reachabilityFence(path);
189         }
190
191         /**
192          * Serialize the object into a byte array
193          */
194         public byte[] write() {
195                 byte[] ret = bindings.Score_write(this.ptr);
196                 Reference.reachabilityFence(this);
197                 return ret;
198         }
199
200 }