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 * Strategies available to retry payment path failures for an [`Invoice`].
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Retry extends CommonBase {
16 private Retry(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.Retry_free(ptr); }
22 static Retry constr_from_ptr(long ptr) {
23 bindings.LDKRetry raw_val = bindings.LDKRetry_ref_from_ptr(ptr);
24 if (raw_val.getClass() == bindings.LDKRetry.Attempts.class) {
25 return new Attempts(ptr, (bindings.LDKRetry.Attempts)raw_val);
27 if (raw_val.getClass() == bindings.LDKRetry.Timeout.class) {
28 return new Timeout(ptr, (bindings.LDKRetry.Timeout)raw_val);
30 assert false; return null; // Unreachable without extending the (internal) bindings interface
34 * Max number of attempts to retry payment.
36 * Note that this is the number of *path* failures, not full payment retries. For multi-path
37 * payments, if this is less than the total number of paths, we will never even retry all of the
40 public final static class Attempts extends Retry {
41 public final long attempts;
42 private Attempts(long ptr, bindings.LDKRetry.Attempts obj) {
44 this.attempts = obj.attempts;
48 * Time elapsed before abandoning retries for a payment.
50 public final static class Timeout extends Retry {
51 public final long timeout;
52 private Timeout(long ptr, bindings.LDKRetry.Timeout obj) {
54 this.timeout = obj.timeout;
58 long ret = bindings.Retry_clone_ptr(this.ptr);
59 Reference.reachabilityFence(this);
64 * Creates a copy of the Retry
66 public Retry clone() {
67 long ret = bindings.Retry_clone(this.ptr);
68 Reference.reachabilityFence(this);
69 if (ret >= 0 && ret <= 4096) { return null; }
70 org.ldk.structs.Retry ret_hu_conv = org.ldk.structs.Retry.constr_from_ptr(ret);
71 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
76 * Utility method to constructs a new Attempts-variant Retry
78 public static Retry attempts(long a) {
79 long ret = bindings.Retry_attempts(a);
80 Reference.reachabilityFence(a);
81 if (ret >= 0 && ret <= 4096) { return null; }
82 org.ldk.structs.Retry ret_hu_conv = org.ldk.structs.Retry.constr_from_ptr(ret);
83 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
88 * Utility method to constructs a new Timeout-variant Retry
90 public static Retry timeout(long a) {
91 long ret = bindings.Retry_timeout(a);
92 Reference.reachabilityFence(a);
93 if (ret >= 0 && ret <= 4096) { return null; }
94 org.ldk.structs.Retry ret_hu_conv = org.ldk.structs.Retry.constr_from_ptr(ret);
95 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
100 * Checks if two Retrys contain equal inner contents.
101 * This ignores pointers and is_owned flags and looks at the values in fields.
103 public boolean eq(Retry b) {
104 boolean ret = bindings.Retry_eq(this.ptr, b == null ? 0 : b.ptr);
105 Reference.reachabilityFence(this);
106 Reference.reachabilityFence(b);
110 @Override public boolean equals(Object o) {
111 if (!(o instanceof Retry)) return false;
112 return this.eq((Retry)o);
115 * Checks if two Retrys contain equal inner contents.
118 long ret = bindings.Retry_hash(this.ptr);
119 Reference.reachabilityFence(this);
123 @Override public int hashCode() {
124 return (int)this.hash();