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 * Features used within an invoice.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Bolt11InvoiceFeatures extends CommonBase {
16 Bolt11InvoiceFeatures(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.Bolt11InvoiceFeatures_free(ptr); }
24 * Serialize the Bolt11InvoiceFeatures object into a byte array which can be read by Bolt11InvoiceFeatures_read
26 public byte[] write() {
27 byte[] ret = bindings.Bolt11InvoiceFeatures_write(this.ptr);
28 Reference.reachabilityFence(this);
33 * Read a Bolt11InvoiceFeatures from a byte array, created by Bolt11InvoiceFeatures_write
35 public static Result_Bolt11InvoiceFeaturesDecodeErrorZ read(byte[] ser) {
36 long ret = bindings.Bolt11InvoiceFeatures_read(ser);
37 Reference.reachabilityFence(ser);
38 if (ret >= 0 && ret <= 4096) { return null; }
39 Result_Bolt11InvoiceFeaturesDecodeErrorZ ret_hu_conv = Result_Bolt11InvoiceFeaturesDecodeErrorZ.constr_from_ptr(ret);
44 * Checks if two Bolt11InvoiceFeaturess contain equal inner contents.
45 * This ignores pointers and is_owned flags and looks at the values in fields.
46 * Two objects with NULL inner values will be considered "equal" here.
48 public boolean eq(org.ldk.structs.Bolt11InvoiceFeatures b) {
49 boolean ret = bindings.Bolt11InvoiceFeatures_eq(this.ptr, b.ptr);
50 Reference.reachabilityFence(this);
51 Reference.reachabilityFence(b);
52 if (this != null) { this.ptrs_to.add(b); };
56 @Override public boolean equals(Object o) {
57 if (!(o instanceof Bolt11InvoiceFeatures)) return false;
58 return this.eq((Bolt11InvoiceFeatures)o);
61 long ret = bindings.Bolt11InvoiceFeatures_clone_ptr(this.ptr);
62 Reference.reachabilityFence(this);
67 * Creates a copy of the Bolt11InvoiceFeatures
69 public Bolt11InvoiceFeatures clone() {
70 long ret = bindings.Bolt11InvoiceFeatures_clone(this.ptr);
71 Reference.reachabilityFence(this);
72 if (ret >= 0 && ret <= 4096) { return null; }
73 org.ldk.structs.Bolt11InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Bolt11InvoiceFeatures(null, ret); }
74 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
79 * Generates a non-cryptographic 64-bit hash of the Bolt11InvoiceFeatures.
82 long ret = bindings.Bolt11InvoiceFeatures_hash(this.ptr);
83 Reference.reachabilityFence(this);
87 @Override public int hashCode() {
88 return (int)this.hash();
91 * Getting a route for a keysend payment to a private node requires providing the payee's
92 * features (since they were not announced in a node announcement). However, keysend payments
93 * don't have an invoice to pull the payee's features from, so this method is provided for use
94 * when a [`Bolt11InvoiceFeatures`] is required in a route.
96 * MPP keysend is not widely supported yet, so we parameterize support to allow the user to
97 * choose whether their router should find multi-part routes.
99 public static Bolt11InvoiceFeatures for_keysend(boolean allow_mpp) {
100 long ret = bindings.Bolt11InvoiceFeatures_for_keysend(allow_mpp);
101 Reference.reachabilityFence(allow_mpp);
102 if (ret >= 0 && ret <= 4096) { return null; }
103 org.ldk.structs.Bolt11InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Bolt11InvoiceFeatures(null, ret); }
104 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
109 * Create a blank Features with no features set
111 public static Bolt11InvoiceFeatures empty() {
112 long ret = bindings.Bolt11InvoiceFeatures_empty();
113 if (ret >= 0 && ret <= 4096) { return null; }
114 org.ldk.structs.Bolt11InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Bolt11InvoiceFeatures(null, ret); }
115 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
120 * Returns the feature set as a list of bytes, in little-endian. This is in reverse byte order
121 * from most on-the-wire encodings.
123 public byte[] le_flags() {
124 byte[] ret = bindings.Bolt11InvoiceFeatures_le_flags(this.ptr);
125 Reference.reachabilityFence(this);
130 * Returns true if this `Features` has any optional flags set
132 public boolean supports_any_optional_bits() {
133 boolean ret = bindings.Bolt11InvoiceFeatures_supports_any_optional_bits(this.ptr);
134 Reference.reachabilityFence(this);
139 * Returns true if this `Features` object contains required features unknown by `other`.
141 public boolean requires_unknown_bits_from(org.ldk.structs.Bolt11InvoiceFeatures other) {
142 boolean ret = bindings.Bolt11InvoiceFeatures_requires_unknown_bits_from(this.ptr, other.ptr);
143 Reference.reachabilityFence(this);
144 Reference.reachabilityFence(other);
145 if (this != null) { this.ptrs_to.add(other); };
150 * Returns the set of required features unknown by `other`, as their bit position.
152 public long[] required_unknown_bits_from(org.ldk.structs.Bolt11InvoiceFeatures other) {
153 long[] ret = bindings.Bolt11InvoiceFeatures_required_unknown_bits_from(this.ptr, other.ptr);
154 Reference.reachabilityFence(this);
155 Reference.reachabilityFence(other);
156 if (this != null) { this.ptrs_to.add(other); };
161 * Returns true if this `Features` object contains unknown feature flags which are set as
164 public boolean requires_unknown_bits() {
165 boolean ret = bindings.Bolt11InvoiceFeatures_requires_unknown_bits(this.ptr);
166 Reference.reachabilityFence(this);
171 * Returns true if this `Features` supports any bits which we do not know of
173 public boolean supports_unknown_bits() {
174 boolean ret = bindings.Bolt11InvoiceFeatures_supports_unknown_bits(this.ptr);
175 Reference.reachabilityFence(this);
180 * Sets a required feature bit. Errors if `bit` is outside the feature range as defined
183 * Note: Required bits are even. If an odd bit is given, then the corresponding even bit will
184 * be set instead (i.e., `bit - 1`).
186 * [BOLT 9]: https://github.com/lightning/bolts/blob/master/09-features.md
188 public Result_NoneNoneZ set_required_feature_bit(long bit) {
189 long ret = bindings.Bolt11InvoiceFeatures_set_required_feature_bit(this.ptr, bit);
190 Reference.reachabilityFence(this);
191 Reference.reachabilityFence(bit);
192 if (ret >= 0 && ret <= 4096) { return null; }
193 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
198 * Sets an optional feature bit. Errors if `bit` is outside the feature range as defined
201 * Note: Optional bits are odd. If an even bit is given, then the corresponding odd bit will be
202 * set instead (i.e., `bit + 1`).
204 * [BOLT 9]: https://github.com/lightning/bolts/blob/master/09-features.md
206 public Result_NoneNoneZ set_optional_feature_bit(long bit) {
207 long ret = bindings.Bolt11InvoiceFeatures_set_optional_feature_bit(this.ptr, bit);
208 Reference.reachabilityFence(this);
209 Reference.reachabilityFence(bit);
210 if (ret >= 0 && ret <= 4096) { return null; }
211 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
216 * Sets a required custom feature bit. Errors if `bit` is outside the custom range as defined
217 * by [bLIP 2] or if it is a known `T` feature.
219 * Note: Required bits are even. If an odd bit is given, then the corresponding even bit will
220 * be set instead (i.e., `bit - 1`).
222 * [bLIP 2]: https://github.com/lightning/blips/blob/master/blip-0002.md#feature-bits
224 public Result_NoneNoneZ set_required_custom_bit(long bit) {
225 long ret = bindings.Bolt11InvoiceFeatures_set_required_custom_bit(this.ptr, bit);
226 Reference.reachabilityFence(this);
227 Reference.reachabilityFence(bit);
228 if (ret >= 0 && ret <= 4096) { return null; }
229 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
234 * Sets an optional custom feature bit. Errors if `bit` is outside the custom range as defined
235 * by [bLIP 2] or if it is a known `T` feature.
237 * Note: Optional bits are odd. If an even bit is given, then the corresponding odd bit will be
238 * set instead (i.e., `bit + 1`).
240 * [bLIP 2]: https://github.com/lightning/blips/blob/master/blip-0002.md#feature-bits
242 public Result_NoneNoneZ set_optional_custom_bit(long bit) {
243 long ret = bindings.Bolt11InvoiceFeatures_set_optional_custom_bit(this.ptr, bit);
244 Reference.reachabilityFence(this);
245 Reference.reachabilityFence(bit);
246 if (ret >= 0 && ret <= 4096) { return null; }
247 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
252 * Set this feature as optional.
254 public void set_variable_length_onion_optional() {
255 bindings.Bolt11InvoiceFeatures_set_variable_length_onion_optional(this.ptr);
256 Reference.reachabilityFence(this);
260 * Set this feature as required.
262 public void set_variable_length_onion_required() {
263 bindings.Bolt11InvoiceFeatures_set_variable_length_onion_required(this.ptr);
264 Reference.reachabilityFence(this);
268 * Checks if this feature is supported.
270 public boolean supports_variable_length_onion() {
271 boolean ret = bindings.Bolt11InvoiceFeatures_supports_variable_length_onion(this.ptr);
272 Reference.reachabilityFence(this);
277 * Checks if this feature is required.
279 public boolean requires_variable_length_onion() {
280 boolean ret = bindings.Bolt11InvoiceFeatures_requires_variable_length_onion(this.ptr);
281 Reference.reachabilityFence(this);
286 * Set this feature as optional.
288 public void set_payment_secret_optional() {
289 bindings.Bolt11InvoiceFeatures_set_payment_secret_optional(this.ptr);
290 Reference.reachabilityFence(this);
294 * Set this feature as required.
296 public void set_payment_secret_required() {
297 bindings.Bolt11InvoiceFeatures_set_payment_secret_required(this.ptr);
298 Reference.reachabilityFence(this);
302 * Checks if this feature is supported.
304 public boolean supports_payment_secret() {
305 boolean ret = bindings.Bolt11InvoiceFeatures_supports_payment_secret(this.ptr);
306 Reference.reachabilityFence(this);
311 * Checks if this feature is required.
313 public boolean requires_payment_secret() {
314 boolean ret = bindings.Bolt11InvoiceFeatures_requires_payment_secret(this.ptr);
315 Reference.reachabilityFence(this);
320 * Set this feature as optional.
322 public void set_basic_mpp_optional() {
323 bindings.Bolt11InvoiceFeatures_set_basic_mpp_optional(this.ptr);
324 Reference.reachabilityFence(this);
328 * Set this feature as required.
330 public void set_basic_mpp_required() {
331 bindings.Bolt11InvoiceFeatures_set_basic_mpp_required(this.ptr);
332 Reference.reachabilityFence(this);
336 * Checks if this feature is supported.
338 public boolean supports_basic_mpp() {
339 boolean ret = bindings.Bolt11InvoiceFeatures_supports_basic_mpp(this.ptr);
340 Reference.reachabilityFence(this);
345 * Checks if this feature is required.
347 public boolean requires_basic_mpp() {
348 boolean ret = bindings.Bolt11InvoiceFeatures_requires_basic_mpp(this.ptr);
349 Reference.reachabilityFence(this);
354 * Set this feature as optional.
356 public void set_payment_metadata_optional() {
357 bindings.Bolt11InvoiceFeatures_set_payment_metadata_optional(this.ptr);
358 Reference.reachabilityFence(this);
362 * Set this feature as required.
364 public void set_payment_metadata_required() {
365 bindings.Bolt11InvoiceFeatures_set_payment_metadata_required(this.ptr);
366 Reference.reachabilityFence(this);
370 * Checks if this feature is supported.
372 public boolean supports_payment_metadata() {
373 boolean ret = bindings.Bolt11InvoiceFeatures_supports_payment_metadata(this.ptr);
374 Reference.reachabilityFence(this);
379 * Checks if this feature is required.
381 public boolean requires_payment_metadata() {
382 boolean ret = bindings.Bolt11InvoiceFeatures_requires_payment_metadata(this.ptr);
383 Reference.reachabilityFence(this);
388 * Set this feature as optional.
390 public void set_trampoline_routing_optional() {
391 bindings.Bolt11InvoiceFeatures_set_trampoline_routing_optional(this.ptr);
392 Reference.reachabilityFence(this);
396 * Set this feature as required.
398 public void set_trampoline_routing_required() {
399 bindings.Bolt11InvoiceFeatures_set_trampoline_routing_required(this.ptr);
400 Reference.reachabilityFence(this);
404 * Checks if this feature is supported.
406 public boolean supports_trampoline_routing() {
407 boolean ret = bindings.Bolt11InvoiceFeatures_supports_trampoline_routing(this.ptr);
408 Reference.reachabilityFence(this);
413 * Checks if this feature is required.
415 public boolean requires_trampoline_routing() {
416 boolean ret = bindings.Bolt11InvoiceFeatures_requires_trampoline_routing(this.ptr);
417 Reference.reachabilityFence(this);