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;
12 * Routing hints for the tail of the route.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Hints extends CommonBase {
16 private Hints(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.Hints_free(ptr); }
22 static Hints constr_from_ptr(long ptr) {
23 bindings.LDKHints raw_val = bindings.LDKHints_ref_from_ptr(ptr);
24 if (raw_val.getClass() == bindings.LDKHints.Blinded.class) {
25 return new Blinded(ptr, (bindings.LDKHints.Blinded)raw_val);
27 if (raw_val.getClass() == bindings.LDKHints.Clear.class) {
28 return new Clear(ptr, (bindings.LDKHints.Clear)raw_val);
30 assert false; return null; // Unreachable without extending the (internal) bindings interface
34 * The recipient provided blinded paths and payinfo to reach them. The blinded paths themselves
35 * will be included in the final [`Route`].
37 public final static class Blinded extends Hints {
38 public final TwoTuple_BlindedPayInfoBlindedPathZ[] blinded;
39 private Blinded(long ptr, bindings.LDKHints.Blinded obj) {
41 long[] blinded = obj.blinded;
42 int blinded_conv_37_len = blinded.length;
43 TwoTuple_BlindedPayInfoBlindedPathZ[] blinded_conv_37_arr = new TwoTuple_BlindedPayInfoBlindedPathZ[blinded_conv_37_len];
44 for (int l = 0; l < blinded_conv_37_len; l++) {
45 long blinded_conv_37 = blinded[l];
46 TwoTuple_BlindedPayInfoBlindedPathZ blinded_conv_37_hu_conv = new TwoTuple_BlindedPayInfoBlindedPathZ(null, blinded_conv_37);
47 if (blinded_conv_37_hu_conv != null) { blinded_conv_37_hu_conv.ptrs_to.add(this); };
48 blinded_conv_37_arr[l] = blinded_conv_37_hu_conv;
50 this.blinded = blinded_conv_37_arr;
54 * The recipient included these route hints in their BOLT11 invoice.
56 public final static class Clear extends Hints {
57 public final RouteHint[] clear;
58 private Clear(long ptr, bindings.LDKHints.Clear obj) {
60 long[] clear = obj.clear;
61 int clear_conv_11_len = clear.length;
62 RouteHint[] clear_conv_11_arr = new RouteHint[clear_conv_11_len];
63 for (int l = 0; l < clear_conv_11_len; l++) {
64 long clear_conv_11 = clear[l];
65 org.ldk.structs.RouteHint clear_conv_11_hu_conv = null; if (clear_conv_11 < 0 || clear_conv_11 > 4096) { clear_conv_11_hu_conv = new org.ldk.structs.RouteHint(null, clear_conv_11); }
66 if (clear_conv_11_hu_conv != null) { clear_conv_11_hu_conv.ptrs_to.add(this); };
67 clear_conv_11_arr[l] = clear_conv_11_hu_conv;
69 this.clear = clear_conv_11_arr;
73 long ret = bindings.Hints_clone_ptr(this.ptr);
74 Reference.reachabilityFence(this);
79 * Creates a copy of the Hints
81 public Hints clone() {
82 long ret = bindings.Hints_clone(this.ptr);
83 Reference.reachabilityFence(this);
84 if (ret >= 0 && ret <= 4096) { return null; }
85 org.ldk.structs.Hints ret_hu_conv = org.ldk.structs.Hints.constr_from_ptr(ret);
86 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
91 * Utility method to constructs a new Blinded-variant Hints
93 public static Hints blinded(TwoTuple_BlindedPayInfoBlindedPathZ[] a) {
94 long ret = bindings.Hints_blinded(a != null ? Arrays.stream(a).mapToLong(a_conv_37 -> a_conv_37 != null ? a_conv_37.ptr : 0).toArray() : null);
95 Reference.reachabilityFence(a);
96 if (ret >= 0 && ret <= 4096) { return null; }
97 org.ldk.structs.Hints ret_hu_conv = org.ldk.structs.Hints.constr_from_ptr(ret);
98 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
103 * Utility method to constructs a new Clear-variant Hints
105 public static Hints clear(RouteHint[] a) {
106 long ret = bindings.Hints_clear(a != null ? Arrays.stream(a).mapToLong(a_conv_11 -> a_conv_11 == null ? 0 : a_conv_11.ptr).toArray() : null);
107 Reference.reachabilityFence(a);
108 if (ret >= 0 && ret <= 4096) { return null; }
109 org.ldk.structs.Hints ret_hu_conv = org.ldk.structs.Hints.constr_from_ptr(ret);
110 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
111 for (RouteHint a_conv_11: a) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a_conv_11); }; };
116 * Generates a non-cryptographic 64-bit hash of the Hints.
119 long ret = bindings.Hints_hash(this.ptr);
120 Reference.reachabilityFence(this);
124 @Override public int hashCode() {
125 return (int)this.hash();
128 * Checks if two Hintss contain equal inner contents.
129 * This ignores pointers and is_owned flags and looks at the values in fields.
131 public boolean eq(org.ldk.structs.Hints b) {
132 boolean ret = bindings.Hints_eq(this.ptr, b == null ? 0 : b.ptr);
133 Reference.reachabilityFence(this);
134 Reference.reachabilityFence(b);
138 @Override public boolean equals(Object o) {
139 if (!(o instanceof Hints)) return false;
140 return this.eq((Hints)o);