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 * Destroys the object, freeing associated resources. After this call, any access
28 * to this object may result in a SEGFAULT or worse.
30 * You should generally NEVER call this method. You should let the garbage collector
31 * do this for you when it finalizes objects. However, it may be useful for types
32 * which represent locks and should be closed immediately to avoid holding locks
35 public void destroy() {
36 if (ptr != 0) { bindings.Router_free(ptr); }
39 public static interface RouterInterface {
41 * Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
43 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
45 Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters route_params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs);
47 * Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
48 * `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
50 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
52 Result_RouteLightningErrorZ find_route_with_id(byte[] payer, RouteParameters route_params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs, byte[] _payment_hash, byte[] _payment_id);
54 private static class LDKRouterHolder { Router held; }
55 public static Router new_impl(RouterInterface arg) {
56 final LDKRouterHolder impl_holder = new LDKRouterHolder();
57 impl_holder.held = new Router(new bindings.LDKRouter() {
58 @Override public long find_route(byte[] payer, long route_params, long[] first_hops, long inflight_htlcs) {
59 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); }
60 int first_hops_conv_16_len = first_hops.length;
61 ChannelDetails[] first_hops_conv_16_arr = new ChannelDetails[first_hops_conv_16_len];
62 if (first_hops != null) {
63 for (int q = 0; q < first_hops_conv_16_len; q++) {
64 long first_hops_conv_16 = first_hops[q];
65 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); }
66 if (first_hops_conv_16_hu_conv != null) { first_hops_conv_16_hu_conv.ptrs_to.add(this); };
67 first_hops_conv_16_arr[q] = first_hops_conv_16_hu_conv;
70 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); }
71 Result_RouteLightningErrorZ ret = arg.find_route(payer, route_params_hu_conv, first_hops_conv_16_arr, inflight_htlcs_hu_conv);
72 Reference.reachabilityFence(arg);
73 long result = ret == null ? 0 : ret.clone_ptr();
76 @Override public long find_route_with_id(byte[] payer, long route_params, long[] first_hops, long inflight_htlcs, byte[] _payment_hash, byte[] _payment_id) {
77 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); }
78 int first_hops_conv_16_len = first_hops.length;
79 ChannelDetails[] first_hops_conv_16_arr = new ChannelDetails[first_hops_conv_16_len];
80 if (first_hops != null) {
81 for (int q = 0; q < first_hops_conv_16_len; q++) {
82 long first_hops_conv_16 = first_hops[q];
83 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); }
84 if (first_hops_conv_16_hu_conv != null) { first_hops_conv_16_hu_conv.ptrs_to.add(this); };
85 first_hops_conv_16_arr[q] = first_hops_conv_16_hu_conv;
88 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); }
89 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);
90 Reference.reachabilityFence(arg);
91 long result = ret == null ? 0 : ret.clone_ptr();
95 return impl_holder.held;
98 * Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
100 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
102 public Result_RouteLightningErrorZ find_route(byte[] payer, org.ldk.structs.RouteParameters route_params, @Nullable ChannelDetails[] first_hops, org.ldk.structs.InFlightHtlcs inflight_htlcs) {
103 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);
104 Reference.reachabilityFence(this);
105 Reference.reachabilityFence(payer);
106 Reference.reachabilityFence(route_params);
107 Reference.reachabilityFence(first_hops);
108 Reference.reachabilityFence(inflight_htlcs);
109 if (ret >= 0 && ret <= 4096) { return null; }
110 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
111 if (this != null) { this.ptrs_to.add(route_params); };
112 if (first_hops != null) { for (ChannelDetails first_hops_conv_16: first_hops) { if (this != null) { this.ptrs_to.add(first_hops_conv_16); }; } };
113 if (this != null) { this.ptrs_to.add(inflight_htlcs); };
118 * Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
119 * `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
121 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
123 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) {
124 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));
125 Reference.reachabilityFence(this);
126 Reference.reachabilityFence(payer);
127 Reference.reachabilityFence(route_params);
128 Reference.reachabilityFence(first_hops);
129 Reference.reachabilityFence(inflight_htlcs);
130 Reference.reachabilityFence(_payment_hash);
131 Reference.reachabilityFence(_payment_id);
132 if (ret >= 0 && ret <= 4096) { return null; }
133 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
134 if (this != null) { this.ptrs_to.add(route_params); };
135 if (first_hops != null) { for (ChannelDetails first_hops_conv_16: first_hops) { if (this != null) { this.ptrs_to.add(first_hops_conv_16); }; } };
136 if (this != null) { this.ptrs_to.add(inflight_htlcs); };