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.
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 * Each attempt may be multiple HTLCs along multiple paths if the router decides to split up a
37 * retry, and may retry multiple failed HTLCs at once if they failed around the same time and
38 * were retried along a route from a single call to [`Router::find_route_with_id`].
40 public final static class Attempts extends Retry {
41 public final int attempts;
42 private Attempts(long ptr, bindings.LDKRetry.Attempts obj) {
44 this.attempts = obj.attempts;
48 * Time elapsed before abandoning retries for a payment. At least one attempt at payment is made;
49 * see [`PaymentParameters::expiry_time`] to avoid any attempt at payment after a specific time.
51 * [`PaymentParameters::expiry_time`]: crate::routing::router::PaymentParameters::expiry_time
53 public final static class Timeout extends Retry {
54 public final long timeout;
55 private Timeout(long ptr, bindings.LDKRetry.Timeout obj) {
57 this.timeout = obj.timeout;
61 long ret = bindings.Retry_clone_ptr(this.ptr);
62 Reference.reachabilityFence(this);
67 * Creates a copy of the Retry
69 public Retry clone() {
70 long ret = bindings.Retry_clone(this.ptr);
71 Reference.reachabilityFence(this);
72 if (ret >= 0 && ret <= 4096) { return null; }
73 org.ldk.structs.Retry ret_hu_conv = org.ldk.structs.Retry.constr_from_ptr(ret);
74 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
79 * Utility method to constructs a new Attempts-variant Retry
81 public static Retry attempts(int a) {
82 long ret = bindings.Retry_attempts(a);
83 Reference.reachabilityFence(a);
84 if (ret >= 0 && ret <= 4096) { return null; }
85 org.ldk.structs.Retry ret_hu_conv = org.ldk.structs.Retry.constr_from_ptr(ret);
86 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
91 * Utility method to constructs a new Timeout-variant Retry
93 public static Retry timeout(long a) {
94 long ret = bindings.Retry_timeout(a);
95 Reference.reachabilityFence(a);
96 if (ret >= 0 && ret <= 4096) { return null; }
97 org.ldk.structs.Retry ret_hu_conv = org.ldk.structs.Retry.constr_from_ptr(ret);
98 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
103 * Checks if two Retrys contain equal inner contents.
104 * This ignores pointers and is_owned flags and looks at the values in fields.
106 public boolean eq(org.ldk.structs.Retry b) {
107 boolean ret = bindings.Retry_eq(this.ptr, b == null ? 0 : b.ptr);
108 Reference.reachabilityFence(this);
109 Reference.reachabilityFence(b);
113 @Override public boolean equals(Object o) {
114 if (!(o instanceof Retry)) return false;
115 return this.eq((Retry)o);
118 * Generates a non-cryptographic 64-bit hash of the Retry.
121 long ret = bindings.Retry_hash(this.ptr);
122 Reference.reachabilityFence(this);
126 @Override public int hashCode() {
127 return (int)this.hash();
130 * Serialize the Retry object into a byte array which can be read by Retry_read
132 public byte[] write() {
133 byte[] ret = bindings.Retry_write(this.ptr);
134 Reference.reachabilityFence(this);
139 * Read a Retry from a byte array, created by Retry_write
141 public static Result_RetryDecodeErrorZ read(byte[] ser) {
142 long ret = bindings.Retry_read(ser);
143 Reference.reachabilityFence(ser);
144 if (ret >= 0 && ret <= 4096) { return null; }
145 Result_RetryDecodeErrorZ ret_hu_conv = Result_RetryDecodeErrorZ.constr_from_ptr(ret);