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 * When the payment path failure took place and extra details about it. [`PathFailure::OnPath`] may
13 * contain a [`NetworkUpdate`] that needs to be applied to the [`NetworkGraph`].
15 * [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
16 * [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
18 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class PathFailure extends CommonBase {
20 private PathFailure(Object _dummy, long ptr) { super(ptr); }
21 @Override @SuppressWarnings("deprecation")
22 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.PathFailure_free(ptr); }
26 static PathFailure constr_from_ptr(long ptr) {
27 bindings.LDKPathFailure raw_val = bindings.LDKPathFailure_ref_from_ptr(ptr);
28 if (raw_val.getClass() == bindings.LDKPathFailure.InitialSend.class) {
29 return new InitialSend(ptr, (bindings.LDKPathFailure.InitialSend)raw_val);
31 if (raw_val.getClass() == bindings.LDKPathFailure.OnPath.class) {
32 return new OnPath(ptr, (bindings.LDKPathFailure.OnPath)raw_val);
34 assert false; return null; // Unreachable without extending the (internal) bindings interface
38 * We failed to initially send the payment and no HTLC was committed to. Contains the relevant
41 public final static class InitialSend extends PathFailure {
43 * The error surfaced from initial send.
45 public final org.ldk.structs.APIError err;
46 private InitialSend(long ptr, bindings.LDKPathFailure.InitialSend obj) {
49 org.ldk.structs.APIError err_hu_conv = org.ldk.structs.APIError.constr_from_ptr(err);
50 if (err_hu_conv != null) { err_hu_conv.ptrs_to.add(this); };
51 this.err = err_hu_conv;
55 * A hop on the path failed to forward our payment.
57 public final static class OnPath extends PathFailure {
59 * If present, this [`NetworkUpdate`] should be applied to the [`NetworkGraph`] so that routing
60 * decisions can take into account the update.
62 * [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
63 * [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
65 public final org.ldk.structs.Option_NetworkUpdateZ network_update;
66 private OnPath(long ptr, bindings.LDKPathFailure.OnPath obj) {
68 long network_update = obj.network_update;
69 org.ldk.structs.Option_NetworkUpdateZ network_update_hu_conv = org.ldk.structs.Option_NetworkUpdateZ.constr_from_ptr(network_update);
70 if (network_update_hu_conv != null) { network_update_hu_conv.ptrs_to.add(this); };
71 this.network_update = network_update_hu_conv;
75 long ret = bindings.PathFailure_clone_ptr(this.ptr);
76 Reference.reachabilityFence(this);
81 * Creates a copy of the PathFailure
83 public PathFailure clone() {
84 long ret = bindings.PathFailure_clone(this.ptr);
85 Reference.reachabilityFence(this);
86 if (ret >= 0 && ret <= 4096) { return null; }
87 org.ldk.structs.PathFailure ret_hu_conv = org.ldk.structs.PathFailure.constr_from_ptr(ret);
88 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
93 * Utility method to constructs a new InitialSend-variant PathFailure
95 public static PathFailure initial_send(org.ldk.structs.APIError err) {
96 long ret = bindings.PathFailure_initial_send(err.ptr);
97 Reference.reachabilityFence(err);
98 if (ret >= 0 && ret <= 4096) { return null; }
99 org.ldk.structs.PathFailure ret_hu_conv = org.ldk.structs.PathFailure.constr_from_ptr(ret);
100 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
101 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(err); };
106 * Utility method to constructs a new OnPath-variant PathFailure
108 public static PathFailure on_path(org.ldk.structs.Option_NetworkUpdateZ network_update) {
109 long ret = bindings.PathFailure_on_path(network_update.ptr);
110 Reference.reachabilityFence(network_update);
111 if (ret >= 0 && ret <= 4096) { return null; }
112 org.ldk.structs.PathFailure ret_hu_conv = org.ldk.structs.PathFailure.constr_from_ptr(ret);
113 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
114 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(network_update); };
119 * Checks if two PathFailures contain equal inner contents.
120 * This ignores pointers and is_owned flags and looks at the values in fields.
122 public boolean eq(org.ldk.structs.PathFailure b) {
123 boolean ret = bindings.PathFailure_eq(this.ptr, b == null ? 0 : b.ptr);
124 Reference.reachabilityFence(this);
125 Reference.reachabilityFence(b);
129 @Override public boolean equals(Object o) {
130 if (!(o instanceof PathFailure)) return false;
131 return this.eq((PathFailure)o);
134 * Serialize the PathFailure object into a byte array which can be read by PathFailure_read
136 public byte[] write() {
137 byte[] ret = bindings.PathFailure_write(this.ptr);
138 Reference.reachabilityFence(this);