[Java] Update auto-generated Java bindings
[ldk-java] / src / main / java / org / ldk / structs / PathFailure.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  * 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`].
14  * 
15  * [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
16  * [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
17  */
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 {
23                 super.finalize();
24                 if (ptr != 0) { bindings.PathFailure_free(ptr); }
25         }
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);
30                 }
31                 if (raw_val.getClass() == bindings.LDKPathFailure.OnPath.class) {
32                         return new OnPath(ptr, (bindings.LDKPathFailure.OnPath)raw_val);
33                 }
34                 assert false; return null; // Unreachable without extending the (internal) bindings interface
35         }
36
37         /**
38          * We failed to initially send the payment and no HTLC was committed to. Contains the relevant
39          * error.
40          */
41         public final static class InitialSend extends PathFailure {
42                 /**
43                  * The error surfaced from initial send.
44                 */
45                 public final org.ldk.structs.APIError err;
46                 private InitialSend(long ptr, bindings.LDKPathFailure.InitialSend obj) {
47                         super(null, ptr);
48                         long err = obj.err;
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;
52                 }
53         }
54         /**
55          * A hop on the path failed to forward our payment.
56          */
57         public final static class OnPath extends PathFailure {
58                 /**
59                  * If present, this [`NetworkUpdate`] should be applied to the [`NetworkGraph`] so that routing
60                  * decisions can take into account the update.
61                  * 
62                  * [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
63                  * [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
64                 */
65                 public final org.ldk.structs.Option_NetworkUpdateZ network_update;
66                 private OnPath(long ptr, bindings.LDKPathFailure.OnPath obj) {
67                         super(null, ptr);
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;
72                 }
73         }
74         long clone_ptr() {
75                 long ret = bindings.PathFailure_clone_ptr(this.ptr);
76                 Reference.reachabilityFence(this);
77                 return ret;
78         }
79
80         /**
81          * Creates a copy of the PathFailure
82          */
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); };
89                 return ret_hu_conv;
90         }
91
92         /**
93          * Utility method to constructs a new InitialSend-variant PathFailure
94          */
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); };
102                 return ret_hu_conv;
103         }
104
105         /**
106          * Utility method to constructs a new OnPath-variant PathFailure
107          */
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); };
115                 return ret_hu_conv;
116         }
117
118         /**
119          * Checks if two PathFailures contain equal inner contents.
120          * This ignores pointers and is_owned flags and looks at the values in fields.
121          */
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);
126                 return ret;
127         }
128
129         @Override public boolean equals(Object o) {
130                 if (!(o instanceof PathFailure)) return false;
131                 return this.eq((PathFailure)o);
132         }
133         /**
134          * Serialize the PathFailure object into a byte array which can be read by PathFailure_read
135          */
136         public byte[] write() {
137                 byte[] ret = bindings.PathFailure_write(this.ptr);
138                 Reference.reachabilityFence(this);
139                 return ret;
140         }
141
142 }