1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
11 * A trait defining behavior for routing a payment.
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class Router extends CommonBase {
15 final bindings.LDKRouter bindings_instance;
16 Router(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17 private Router(bindings.LDKRouter arg) {
18 super(bindings.LDKRouter_new(arg));
19 this.ptrs_to.add(arg);
20 this.bindings_instance = arg;
22 @Override @SuppressWarnings("deprecation")
23 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.Router_free(ptr); } super.finalize();
27 public static interface RouterInterface {
29 * Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
31 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
33 Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters route_params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs);
35 * Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
36 * `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
38 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
40 Result_RouteLightningErrorZ find_route_with_id(byte[] payer, RouteParameters route_params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs, byte[] _payment_hash, byte[] _payment_id);
42 * Lets the router know that payment through a specific path has failed.
44 void notify_payment_path_failed(RouteHop[] path, long short_channel_id);
46 * Lets the router know that payment through a specific path was successful.
48 void notify_payment_path_successful(RouteHop[] path);
50 * Lets the router know that a payment probe was successful.
52 void notify_payment_probe_successful(RouteHop[] path);
54 * Lets the router know that a payment probe failed.
56 void notify_payment_probe_failed(RouteHop[] path, long short_channel_id);
58 private static class LDKRouterHolder { Router held; }
59 public static Router new_impl(RouterInterface arg) {
60 final LDKRouterHolder impl_holder = new LDKRouterHolder();
61 impl_holder.held = new Router(new bindings.LDKRouter() {
62 @Override public long find_route(byte[] payer, long route_params, long[] first_hops, long inflight_htlcs) {
63 org.ldk.structs.RouteParameters route_params_hu_conv = null; if (route_params < 0 || route_params > 4096) { route_params_hu_conv = new org.ldk.structs.RouteParameters(null, route_params); }
64 int first_hops_conv_16_len = first_hops.length;
65 ChannelDetails[] first_hops_conv_16_arr = new ChannelDetails[first_hops_conv_16_len];
66 if (first_hops != null) {
67 for (int q = 0; q < first_hops_conv_16_len; q++) {
68 long first_hops_conv_16 = first_hops[q];
69 org.ldk.structs.ChannelDetails first_hops_conv_16_hu_conv = null; if (first_hops_conv_16 < 0 || first_hops_conv_16 > 4096) { first_hops_conv_16_hu_conv = new org.ldk.structs.ChannelDetails(null, first_hops_conv_16); }
70 if (first_hops_conv_16_hu_conv != null) { first_hops_conv_16_hu_conv.ptrs_to.add(this); };
71 first_hops_conv_16_arr[q] = first_hops_conv_16_hu_conv;
74 org.ldk.structs.InFlightHtlcs inflight_htlcs_hu_conv = null; if (inflight_htlcs < 0 || inflight_htlcs > 4096) { inflight_htlcs_hu_conv = new org.ldk.structs.InFlightHtlcs(null, inflight_htlcs); }
75 if (inflight_htlcs_hu_conv != null) { inflight_htlcs_hu_conv.ptrs_to.add(this); };
76 Result_RouteLightningErrorZ ret = arg.find_route(payer, route_params_hu_conv, first_hops_conv_16_arr, inflight_htlcs_hu_conv);
77 Reference.reachabilityFence(arg);
78 long result = ret == null ? 0 : ret.clone_ptr();
81 @Override public long find_route_with_id(byte[] payer, long route_params, long[] first_hops, long inflight_htlcs, byte[] _payment_hash, byte[] _payment_id) {
82 org.ldk.structs.RouteParameters route_params_hu_conv = null; if (route_params < 0 || route_params > 4096) { route_params_hu_conv = new org.ldk.structs.RouteParameters(null, route_params); }
83 int first_hops_conv_16_len = first_hops.length;
84 ChannelDetails[] first_hops_conv_16_arr = new ChannelDetails[first_hops_conv_16_len];
85 if (first_hops != null) {
86 for (int q = 0; q < first_hops_conv_16_len; q++) {
87 long first_hops_conv_16 = first_hops[q];
88 org.ldk.structs.ChannelDetails first_hops_conv_16_hu_conv = null; if (first_hops_conv_16 < 0 || first_hops_conv_16 > 4096) { first_hops_conv_16_hu_conv = new org.ldk.structs.ChannelDetails(null, first_hops_conv_16); }
89 if (first_hops_conv_16_hu_conv != null) { first_hops_conv_16_hu_conv.ptrs_to.add(this); };
90 first_hops_conv_16_arr[q] = first_hops_conv_16_hu_conv;
93 org.ldk.structs.InFlightHtlcs inflight_htlcs_hu_conv = null; if (inflight_htlcs < 0 || inflight_htlcs > 4096) { inflight_htlcs_hu_conv = new org.ldk.structs.InFlightHtlcs(null, inflight_htlcs); }
94 if (inflight_htlcs_hu_conv != null) { inflight_htlcs_hu_conv.ptrs_to.add(this); };
95 Result_RouteLightningErrorZ ret = arg.find_route_with_id(payer, route_params_hu_conv, first_hops_conv_16_arr, inflight_htlcs_hu_conv, _payment_hash, _payment_id);
96 Reference.reachabilityFence(arg);
97 long result = ret == null ? 0 : ret.clone_ptr();
100 @Override public void notify_payment_path_failed(long[] path, long short_channel_id) {
101 int path_conv_10_len = path.length;
102 RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
103 for (int k = 0; k < path_conv_10_len; k++) {
104 long path_conv_10 = path[k];
105 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); }
106 if (path_conv_10_hu_conv != null) { path_conv_10_hu_conv.ptrs_to.add(this); };
107 path_conv_10_arr[k] = path_conv_10_hu_conv;
109 arg.notify_payment_path_failed(path_conv_10_arr, short_channel_id);
110 Reference.reachabilityFence(arg);
112 @Override public void notify_payment_path_successful(long[] path) {
113 int path_conv_10_len = path.length;
114 RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
115 for (int k = 0; k < path_conv_10_len; k++) {
116 long path_conv_10 = path[k];
117 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); }
118 if (path_conv_10_hu_conv != null) { path_conv_10_hu_conv.ptrs_to.add(this); };
119 path_conv_10_arr[k] = path_conv_10_hu_conv;
121 arg.notify_payment_path_successful(path_conv_10_arr);
122 Reference.reachabilityFence(arg);
124 @Override public void notify_payment_probe_successful(long[] path) {
125 int path_conv_10_len = path.length;
126 RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
127 for (int k = 0; k < path_conv_10_len; k++) {
128 long path_conv_10 = path[k];
129 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); }
130 if (path_conv_10_hu_conv != null) { path_conv_10_hu_conv.ptrs_to.add(this); };
131 path_conv_10_arr[k] = path_conv_10_hu_conv;
133 arg.notify_payment_probe_successful(path_conv_10_arr);
134 Reference.reachabilityFence(arg);
136 @Override public void notify_payment_probe_failed(long[] path, long short_channel_id) {
137 int path_conv_10_len = path.length;
138 RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
139 for (int k = 0; k < path_conv_10_len; k++) {
140 long path_conv_10 = path[k];
141 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); }
142 if (path_conv_10_hu_conv != null) { path_conv_10_hu_conv.ptrs_to.add(this); };
143 path_conv_10_arr[k] = path_conv_10_hu_conv;
145 arg.notify_payment_probe_failed(path_conv_10_arr, short_channel_id);
146 Reference.reachabilityFence(arg);
149 return impl_holder.held;
152 * Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
154 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
156 public Result_RouteLightningErrorZ find_route(byte[] payer, org.ldk.structs.RouteParameters route_params, @Nullable ChannelDetails[] first_hops, org.ldk.structs.InFlightHtlcs inflight_htlcs) {
157 long ret = bindings.Router_find_route(this.ptr, InternalUtils.check_arr_len(payer, 33), route_params == null ? 0 : route_params.ptr, first_hops != null ? Arrays.stream(first_hops).mapToLong(first_hops_conv_16 -> first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr).toArray() : null, inflight_htlcs == null ? 0 : inflight_htlcs.ptr);
158 Reference.reachabilityFence(this);
159 Reference.reachabilityFence(payer);
160 Reference.reachabilityFence(route_params);
161 Reference.reachabilityFence(first_hops);
162 Reference.reachabilityFence(inflight_htlcs);
163 if (ret >= 0 && ret <= 4096) { return null; }
164 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
165 if (this != null) { this.ptrs_to.add(route_params); };
166 if (first_hops != null) { for (ChannelDetails first_hops_conv_16: first_hops) { if (this != null) { this.ptrs_to.add(first_hops_conv_16); }; } };
167 if (this != null) { this.ptrs_to.add(inflight_htlcs); };
172 * Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
173 * `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
175 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
177 public Result_RouteLightningErrorZ find_route_with_id(byte[] payer, org.ldk.structs.RouteParameters route_params, @Nullable ChannelDetails[] first_hops, org.ldk.structs.InFlightHtlcs inflight_htlcs, byte[] _payment_hash, byte[] _payment_id) {
178 long ret = bindings.Router_find_route_with_id(this.ptr, InternalUtils.check_arr_len(payer, 33), route_params == null ? 0 : route_params.ptr, first_hops != null ? Arrays.stream(first_hops).mapToLong(first_hops_conv_16 -> first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr).toArray() : null, inflight_htlcs == null ? 0 : inflight_htlcs.ptr, InternalUtils.check_arr_len(_payment_hash, 32), InternalUtils.check_arr_len(_payment_id, 32));
179 Reference.reachabilityFence(this);
180 Reference.reachabilityFence(payer);
181 Reference.reachabilityFence(route_params);
182 Reference.reachabilityFence(first_hops);
183 Reference.reachabilityFence(inflight_htlcs);
184 Reference.reachabilityFence(_payment_hash);
185 Reference.reachabilityFence(_payment_id);
186 if (ret >= 0 && ret <= 4096) { return null; }
187 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
188 if (this != null) { this.ptrs_to.add(route_params); };
189 if (first_hops != null) { for (ChannelDetails first_hops_conv_16: first_hops) { if (this != null) { this.ptrs_to.add(first_hops_conv_16); }; } };
190 if (this != null) { this.ptrs_to.add(inflight_htlcs); };
195 * Lets the router know that payment through a specific path has failed.
197 public void notify_payment_path_failed(RouteHop[] path, long short_channel_id) {
198 bindings.Router_notify_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);
199 Reference.reachabilityFence(this);
200 Reference.reachabilityFence(path);
201 Reference.reachabilityFence(short_channel_id);
202 for (RouteHop path_conv_10: path) { if (this != null) { this.ptrs_to.add(path_conv_10); }; };
206 * Lets the router know that payment through a specific path was successful.
208 public void notify_payment_path_successful(RouteHop[] path) {
209 bindings.Router_notify_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);
210 Reference.reachabilityFence(this);
211 Reference.reachabilityFence(path);
212 for (RouteHop path_conv_10: path) { if (this != null) { this.ptrs_to.add(path_conv_10); }; };
216 * Lets the router know that a payment probe was successful.
218 public void notify_payment_probe_successful(RouteHop[] path) {
219 bindings.Router_notify_payment_probe_successful(this.ptr, path != null ? Arrays.stream(path).mapToLong(path_conv_10 -> path_conv_10 == null ? 0 : path_conv_10.ptr).toArray() : null);
220 Reference.reachabilityFence(this);
221 Reference.reachabilityFence(path);
222 for (RouteHop path_conv_10: path) { if (this != null) { this.ptrs_to.add(path_conv_10); }; };
226 * Lets the router know that a payment probe failed.
228 public void notify_payment_probe_failed(RouteHop[] path, long short_channel_id) {
229 bindings.Router_notify_payment_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);
230 Reference.reachabilityFence(this);
231 Reference.reachabilityFence(path);
232 Reference.reachabilityFence(short_channel_id);
233 for (RouteHop path_conv_10: path) { if (this != null) { this.ptrs_to.add(path_conv_10); }; };