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 an [`Invoice`] 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, byte[] payment_hash, ChannelDetails[] first_hops, Score scorer);
35 private static class LDKRouterHolder { Router held; }
36 public static Router new_impl(RouterInterface arg) {
37 final LDKRouterHolder impl_holder = new LDKRouterHolder();
38 impl_holder.held = new Router(new bindings.LDKRouter() {
39 @Override public long find_route(byte[] payer, long route_params, byte[] payment_hash, long[] first_hops, long scorer) {
40 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); }
41 int first_hops_conv_16_len = first_hops.length;
42 ChannelDetails[] first_hops_conv_16_arr = new ChannelDetails[first_hops_conv_16_len];
43 for (int q = 0; q < first_hops_conv_16_len; q++) {
44 long first_hops_conv_16 = first_hops[q];
45 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); }
46 first_hops_conv_16_hu_conv.ptrs_to.add(this);
47 first_hops_conv_16_arr[q] = first_hops_conv_16_hu_conv;
49 Score ret_hu_conv = new Score(null, scorer);
50 ret_hu_conv.ptrs_to.add(this);
51 Result_RouteLightningErrorZ ret = arg.find_route(payer, route_params_hu_conv, payment_hash, first_hops_conv_16_arr, ret_hu_conv);
52 Reference.reachabilityFence(arg);
53 long result = ret == null ? 0 : ret.clone_ptr();
57 return impl_holder.held;
60 * Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
62 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
64 public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters route_params, byte[] payment_hash, @Nullable ChannelDetails[] first_hops, Score scorer) {
65 long ret = bindings.Router_find_route(this.ptr, InternalUtils.check_arr_len(payer, 33), route_params == null ? 0 : route_params.ptr & ~1, InternalUtils.check_arr_len(payment_hash, 32), first_hops != null ? Arrays.stream(first_hops).mapToLong(first_hops_conv_16 -> first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr & ~1).toArray() : null, scorer == null ? 0 : scorer.ptr);
66 Reference.reachabilityFence(this);
67 Reference.reachabilityFence(payer);
68 Reference.reachabilityFence(route_params);
69 Reference.reachabilityFence(payment_hash);
70 Reference.reachabilityFence(first_hops);
71 Reference.reachabilityFence(scorer);
72 if (ret >= 0 && ret <= 4096) { return null; }
73 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
74 this.ptrs_to.add(route_params);
75 for (ChannelDetails first_hops_conv_16: first_hops) { this.ptrs_to.add(first_hops_conv_16); };
76 this.ptrs_to.add(scorer);