Update auto-generated bindings
[ldk-java] / src / main / java / org / ldk / structs / Router.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 javax.annotation.Nullable;
8
9 /**
10  * A trait defining behavior for routing an [`Invoice`] payment.
11  */
12 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
13 public class Router extends CommonBase {
14         final bindings.LDKRouter bindings_instance;
15         Router(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
16         private Router(bindings.LDKRouter arg) {
17                 super(bindings.LDKRouter_new(arg));
18                 this.ptrs_to.add(arg);
19                 this.bindings_instance = arg;
20         }
21         @Override @SuppressWarnings("deprecation")
22         protected void finalize() throws Throwable {
23                 if (ptr != 0) { bindings.Router_free(ptr); } super.finalize();
24         }
25
26         public static interface RouterInterface {
27                 /**
28                  * Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
29                  * 
30                  * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
31                  */
32                 Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, ChannelDetails[] first_hops, Score scorer);
33         }
34         private static class LDKRouterHolder { Router held; }
35         public static Router new_impl(RouterInterface arg) {
36                 final LDKRouterHolder impl_holder = new LDKRouterHolder();
37                 impl_holder.held = new Router(new bindings.LDKRouter() {
38                         @Override public long find_route(byte[] payer, long params, long[] first_hops, long scorer) {
39                                 RouteParameters params_hu_conv = null; if (params < 0 || params > 4096) { params_hu_conv = new RouteParameters(null, params); }
40                                 ChannelDetails[] first_hops_conv_16_arr = new ChannelDetails[first_hops.length];
41                                 for (int q = 0; q < first_hops.length; q++) {
42                                         long first_hops_conv_16 = first_hops[q];
43                                         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 ChannelDetails(null, first_hops_conv_16); }
44                                         first_hops_conv_16_hu_conv.ptrs_to.add(this);
45                                         first_hops_conv_16_arr[q] = first_hops_conv_16_hu_conv;
46                                 }
47                                 Score ret_hu_conv = new Score(null, scorer);
48                                 ret_hu_conv.ptrs_to.add(this);
49                                 Result_RouteLightningErrorZ ret = arg.find_route(payer, params_hu_conv, first_hops_conv_16_arr, ret_hu_conv);
50                                 long result = ret == null ? 0 : ret.clone_ptr();
51                                 return result;
52                         }
53                 });
54                 return impl_holder.held;
55         }
56         /**
57          * Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
58          * 
59          * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
60          */
61         public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, @Nullable ChannelDetails[] first_hops, Score scorer) {
62                 long ret = bindings.Router_find_route(this.ptr, InternalUtils.check_arr_len(payer, 33), params == null ? 0 : params.ptr & ~1, 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);
63                 if (ret >= 0 && ret <= 4096) { return null; }
64                 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
65                 this.ptrs_to.add(params);
66                 for (ChannelDetails first_hops_conv_16: first_hops) { this.ptrs_to.add(first_hops_conv_16); };
67                 this.ptrs_to.add(scorer);
68                 return ret_hu_conv;
69         }
70
71 }