[C#] Run tests against release library in determinism CI run
[ldk-java] / src / main / java / org / ldk / structs / Payee.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 java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * The recipient of a payment, differing based on whether they've hidden their identity with route
13  * blinding.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class Payee extends CommonBase {
17         private Payee(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.Payee_free(ptr); }
22         }
23         static Payee constr_from_ptr(long ptr) {
24                 bindings.LDKPayee raw_val = bindings.LDKPayee_ref_from_ptr(ptr);
25                 if (raw_val.getClass() == bindings.LDKPayee.Blinded.class) {
26                         return new Blinded(ptr, (bindings.LDKPayee.Blinded)raw_val);
27                 }
28                 if (raw_val.getClass() == bindings.LDKPayee.Clear.class) {
29                         return new Clear(ptr, (bindings.LDKPayee.Clear)raw_val);
30                 }
31                 assert false; return null; // Unreachable without extending the (internal) bindings interface
32         }
33
34         /**
35          * The recipient provided blinded paths and payinfo to reach them. The blinded paths themselves
36          * will be included in the final [`Route`].
37          */
38         public final static class Blinded extends Payee {
39                 /**
40                  * Aggregated routing info and blinded paths, for routing to the payee without knowing their
41                  * node id.
42                 */
43                 public final TwoTuple_BlindedPayInfoBlindedPathZ[] route_hints;
44                 /**
45                  * Features supported by the payee.
46                  * 
47                  * May be set from the payee's invoice. May be `None` if the invoice does not contain any
48                  * features.
49                  * 
50                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
51                 */
52                 @Nullable public final org.ldk.structs.Bolt12InvoiceFeatures features;
53                 private Blinded(long ptr, bindings.LDKPayee.Blinded obj) {
54                         super(null, ptr);
55                         long[] route_hints = obj.route_hints;
56                         int route_hints_conv_37_len = route_hints.length;
57                         TwoTuple_BlindedPayInfoBlindedPathZ[] route_hints_conv_37_arr = new TwoTuple_BlindedPayInfoBlindedPathZ[route_hints_conv_37_len];
58                         for (int l = 0; l < route_hints_conv_37_len; l++) {
59                                 long route_hints_conv_37 = route_hints[l];
60                                 TwoTuple_BlindedPayInfoBlindedPathZ route_hints_conv_37_hu_conv = new TwoTuple_BlindedPayInfoBlindedPathZ(null, route_hints_conv_37);
61                                 if (route_hints_conv_37_hu_conv != null) { route_hints_conv_37_hu_conv.ptrs_to.add(this); };
62                                 route_hints_conv_37_arr[l] = route_hints_conv_37_hu_conv;
63                         }
64                         this.route_hints = route_hints_conv_37_arr;
65                         long features = obj.features;
66                         org.ldk.structs.Bolt12InvoiceFeatures features_hu_conv = null; if (features < 0 || features > 4096) { features_hu_conv = new org.ldk.structs.Bolt12InvoiceFeatures(null, features); }
67                         if (features_hu_conv != null) { features_hu_conv.ptrs_to.add(this); };
68                         this.features = features_hu_conv;
69                 }
70         }
71         /**
72          * The recipient included these route hints in their BOLT11 invoice.
73          */
74         public final static class Clear extends Payee {
75                 /**
76                  * The node id of the payee.
77                 */
78                 public final byte[] node_id;
79                 /**
80                  * Hints for routing to the payee, containing channels connecting the payee to public nodes.
81                 */
82                 public final RouteHint[] route_hints;
83                 /**
84                  * Features supported by the payee.
85                  * 
86                  * May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
87                  * does not contain any features.
88                  * 
89                  * [`for_keysend`]: PaymentParameters::for_keysend
90                  * 
91                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
92                 */
93                 @Nullable public final org.ldk.structs.Bolt11InvoiceFeatures features;
94                 /**
95                  * The minimum CLTV delta at the end of the route. This value must not be zero.
96                 */
97                 public final int final_cltv_expiry_delta;
98                 private Clear(long ptr, bindings.LDKPayee.Clear obj) {
99                         super(null, ptr);
100                         this.node_id = obj.node_id;
101                         long[] route_hints = obj.route_hints;
102                         int route_hints_conv_11_len = route_hints.length;
103                         RouteHint[] route_hints_conv_11_arr = new RouteHint[route_hints_conv_11_len];
104                         for (int l = 0; l < route_hints_conv_11_len; l++) {
105                                 long route_hints_conv_11 = route_hints[l];
106                                 org.ldk.structs.RouteHint route_hints_conv_11_hu_conv = null; if (route_hints_conv_11 < 0 || route_hints_conv_11 > 4096) { route_hints_conv_11_hu_conv = new org.ldk.structs.RouteHint(null, route_hints_conv_11); }
107                                 if (route_hints_conv_11_hu_conv != null) { route_hints_conv_11_hu_conv.ptrs_to.add(this); };
108                                 route_hints_conv_11_arr[l] = route_hints_conv_11_hu_conv;
109                         }
110                         this.route_hints = route_hints_conv_11_arr;
111                         long features = obj.features;
112                         org.ldk.structs.Bolt11InvoiceFeatures features_hu_conv = null; if (features < 0 || features > 4096) { features_hu_conv = new org.ldk.structs.Bolt11InvoiceFeatures(null, features); }
113                         if (features_hu_conv != null) { features_hu_conv.ptrs_to.add(this); };
114                         this.features = features_hu_conv;
115                         this.final_cltv_expiry_delta = obj.final_cltv_expiry_delta;
116                 }
117         }
118         long clone_ptr() {
119                 long ret = bindings.Payee_clone_ptr(this.ptr);
120                 Reference.reachabilityFence(this);
121                 return ret;
122         }
123
124         /**
125          * Creates a copy of the Payee
126          */
127         public Payee clone() {
128                 long ret = bindings.Payee_clone(this.ptr);
129                 Reference.reachabilityFence(this);
130                 if (ret >= 0 && ret <= 4096) { return null; }
131                 org.ldk.structs.Payee ret_hu_conv = org.ldk.structs.Payee.constr_from_ptr(ret);
132                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
133                 return ret_hu_conv;
134         }
135
136         /**
137          * Utility method to constructs a new Blinded-variant Payee
138          */
139         public static Payee blinded(TwoTuple_BlindedPayInfoBlindedPathZ[] route_hints, org.ldk.structs.Bolt12InvoiceFeatures features) {
140                 long ret = bindings.Payee_blinded(route_hints != null ? Arrays.stream(route_hints).mapToLong(route_hints_conv_37 -> route_hints_conv_37.ptr).toArray() : null, features.ptr);
141                 Reference.reachabilityFence(route_hints);
142                 Reference.reachabilityFence(features);
143                 if (ret >= 0 && ret <= 4096) { return null; }
144                 org.ldk.structs.Payee ret_hu_conv = org.ldk.structs.Payee.constr_from_ptr(ret);
145                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
146                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(features); };
147                 return ret_hu_conv;
148         }
149
150         /**
151          * Utility method to constructs a new Clear-variant Payee
152          */
153         public static Payee clear(byte[] node_id, RouteHint[] route_hints, org.ldk.structs.Bolt11InvoiceFeatures features, int final_cltv_expiry_delta) {
154                 long ret = bindings.Payee_clear(InternalUtils.check_arr_len(node_id, 33), route_hints != null ? Arrays.stream(route_hints).mapToLong(route_hints_conv_11 -> route_hints_conv_11.ptr).toArray() : null, features.ptr, final_cltv_expiry_delta);
155                 Reference.reachabilityFence(node_id);
156                 Reference.reachabilityFence(route_hints);
157                 Reference.reachabilityFence(features);
158                 Reference.reachabilityFence(final_cltv_expiry_delta);
159                 if (ret >= 0 && ret <= 4096) { return null; }
160                 org.ldk.structs.Payee ret_hu_conv = org.ldk.structs.Payee.constr_from_ptr(ret);
161                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
162                 for (RouteHint route_hints_conv_11: route_hints) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(route_hints_conv_11); }; };
163                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(features); };
164                 return ret_hu_conv;
165         }
166
167         /**
168          * Generates a non-cryptographic 64-bit hash of the Payee.
169          */
170         public long hash() {
171                 long ret = bindings.Payee_hash(this.ptr);
172                 Reference.reachabilityFence(this);
173                 return ret;
174         }
175
176         @Override public int hashCode() {
177                 return (int)this.hash();
178         }
179         /**
180          * Checks if two Payees contain equal inner contents.
181          * This ignores pointers and is_owned flags and looks at the values in fields.
182          */
183         public boolean eq(org.ldk.structs.Payee b) {
184                 boolean ret = bindings.Payee_eq(this.ptr, b.ptr);
185                 Reference.reachabilityFence(this);
186                 Reference.reachabilityFence(b);
187                 return ret;
188         }
189
190         @Override public boolean equals(Object o) {
191                 if (!(o instanceof Payee)) return false;
192                 return this.eq((Payee)o);
193         }
194 }