[TS] Update auto-generated bindings to LDK-C-Bindings 0.0.123.1
[ldk-java] / src / main / java / org / ldk / structs / HTLCDestination.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  * Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class HTLCDestination extends CommonBase {
16         private HTLCDestination(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.HTLCDestination_free(ptr); }
21         }
22         static HTLCDestination constr_from_ptr(long ptr) {
23                 bindings.LDKHTLCDestination raw_val = bindings.LDKHTLCDestination_ref_from_ptr(ptr);
24                 if (raw_val.getClass() == bindings.LDKHTLCDestination.NextHopChannel.class) {
25                         return new NextHopChannel(ptr, (bindings.LDKHTLCDestination.NextHopChannel)raw_val);
26                 }
27                 if (raw_val.getClass() == bindings.LDKHTLCDestination.UnknownNextHop.class) {
28                         return new UnknownNextHop(ptr, (bindings.LDKHTLCDestination.UnknownNextHop)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKHTLCDestination.InvalidForward.class) {
31                         return new InvalidForward(ptr, (bindings.LDKHTLCDestination.InvalidForward)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKHTLCDestination.InvalidOnion.class) {
34                         return new InvalidOnion(ptr, (bindings.LDKHTLCDestination.InvalidOnion)raw_val);
35                 }
36                 if (raw_val.getClass() == bindings.LDKHTLCDestination.FailedPayment.class) {
37                         return new FailedPayment(ptr, (bindings.LDKHTLCDestination.FailedPayment)raw_val);
38                 }
39                 assert false; return null; // Unreachable without extending the (internal) bindings interface
40         }
41
42         /**
43          * We tried forwarding to a channel but failed to do so. An example of such an instance is when
44          * there is insufficient capacity in our outbound channel.
45          */
46         public final static class NextHopChannel extends HTLCDestination {
47                 /**
48                  * The `node_id` of the next node. For backwards compatibility, this field is
49                  * marked as optional, versions prior to 0.0.110 may not always be able to provide
50                  * counterparty node information.
51                  * 
52                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
53                 */
54                 @Nullable public final byte[] node_id;
55                 /**
56                  * The outgoing `channel_id` between us and the next node.
57                 */
58                 public final org.ldk.structs.ChannelId channel_id;
59                 private NextHopChannel(long ptr, bindings.LDKHTLCDestination.NextHopChannel obj) {
60                         super(null, ptr);
61                         this.node_id = obj.node_id;
62                         long channel_id = obj.channel_id;
63                         org.ldk.structs.ChannelId channel_id_hu_conv = null; if (channel_id < 0 || channel_id > 4096) { channel_id_hu_conv = new org.ldk.structs.ChannelId(null, channel_id); }
64                         if (channel_id_hu_conv != null) { channel_id_hu_conv.ptrs_to.add(this); };
65                         this.channel_id = channel_id_hu_conv;
66                 }
67         }
68         /**
69          * Scenario where we are unsure of the next node to forward the HTLC to.
70          */
71         public final static class UnknownNextHop extends HTLCDestination {
72                 /**
73                  * Short channel id we are requesting to forward an HTLC to.
74                 */
75                 public final long requested_forward_scid;
76                 private UnknownNextHop(long ptr, bindings.LDKHTLCDestination.UnknownNextHop obj) {
77                         super(null, ptr);
78                         this.requested_forward_scid = obj.requested_forward_scid;
79                 }
80         }
81         /**
82          * We couldn't forward to the outgoing scid. An example would be attempting to send a duplicate
83          * intercept HTLC.
84          */
85         public final static class InvalidForward extends HTLCDestination {
86                 /**
87                  * Short channel id we are requesting to forward an HTLC to.
88                 */
89                 public final long requested_forward_scid;
90                 private InvalidForward(long ptr, bindings.LDKHTLCDestination.InvalidForward obj) {
91                         super(null, ptr);
92                         this.requested_forward_scid = obj.requested_forward_scid;
93                 }
94         }
95         /**
96          * We couldn't decode the incoming onion to obtain the forwarding details.
97          */
98         public final static class InvalidOnion extends HTLCDestination {
99                 private InvalidOnion(long ptr, bindings.LDKHTLCDestination.InvalidOnion obj) {
100                         super(null, ptr);
101                 }
102         }
103         /**
104          * Failure scenario where an HTLC may have been forwarded to be intended for us,
105          * but is invalid for some reason, so we reject it.
106          * 
107          * Some of the reasons may include:
108          * HTLC Timeouts
109          * Excess HTLCs for a payment that we have already fully received, over-paying for the
110          * payment,
111          * The counterparty node modified the HTLC in transit,
112          * A probing attack where an intermediary node is trying to detect if we are the ultimate
113          * recipient for a payment.
114          */
115         public final static class FailedPayment extends HTLCDestination {
116                 /**
117                  * The payment hash of the payment we attempted to process.
118                 */
119                 public final byte[] payment_hash;
120                 private FailedPayment(long ptr, bindings.LDKHTLCDestination.FailedPayment obj) {
121                         super(null, ptr);
122                         this.payment_hash = obj.payment_hash;
123                 }
124         }
125         long clone_ptr() {
126                 long ret = bindings.HTLCDestination_clone_ptr(this.ptr);
127                 Reference.reachabilityFence(this);
128                 return ret;
129         }
130
131         /**
132          * Creates a copy of the HTLCDestination
133          */
134         public HTLCDestination clone() {
135                 long ret = bindings.HTLCDestination_clone(this.ptr);
136                 Reference.reachabilityFence(this);
137                 if (ret >= 0 && ret <= 4096) { return null; }
138                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
139                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
140                 return ret_hu_conv;
141         }
142
143         /**
144          * Utility method to constructs a new NextHopChannel-variant HTLCDestination
145          */
146         public static HTLCDestination next_hop_channel(byte[] node_id, org.ldk.structs.ChannelId channel_id) {
147                 long ret = bindings.HTLCDestination_next_hop_channel(InternalUtils.check_arr_len(node_id, 33), channel_id.ptr);
148                 Reference.reachabilityFence(node_id);
149                 Reference.reachabilityFence(channel_id);
150                 if (ret >= 0 && ret <= 4096) { return null; }
151                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
152                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
153                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_id); };
154                 return ret_hu_conv;
155         }
156
157         /**
158          * Utility method to constructs a new UnknownNextHop-variant HTLCDestination
159          */
160         public static HTLCDestination unknown_next_hop(long requested_forward_scid) {
161                 long ret = bindings.HTLCDestination_unknown_next_hop(requested_forward_scid);
162                 Reference.reachabilityFence(requested_forward_scid);
163                 if (ret >= 0 && ret <= 4096) { return null; }
164                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
165                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
166                 return ret_hu_conv;
167         }
168
169         /**
170          * Utility method to constructs a new InvalidForward-variant HTLCDestination
171          */
172         public static HTLCDestination invalid_forward(long requested_forward_scid) {
173                 long ret = bindings.HTLCDestination_invalid_forward(requested_forward_scid);
174                 Reference.reachabilityFence(requested_forward_scid);
175                 if (ret >= 0 && ret <= 4096) { return null; }
176                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
177                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
178                 return ret_hu_conv;
179         }
180
181         /**
182          * Utility method to constructs a new InvalidOnion-variant HTLCDestination
183          */
184         public static HTLCDestination invalid_onion() {
185                 long ret = bindings.HTLCDestination_invalid_onion();
186                 if (ret >= 0 && ret <= 4096) { return null; }
187                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
188                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
189                 return ret_hu_conv;
190         }
191
192         /**
193          * Utility method to constructs a new FailedPayment-variant HTLCDestination
194          */
195         public static HTLCDestination failed_payment(byte[] payment_hash) {
196                 long ret = bindings.HTLCDestination_failed_payment(InternalUtils.check_arr_len(payment_hash, 32));
197                 Reference.reachabilityFence(payment_hash);
198                 if (ret >= 0 && ret <= 4096) { return null; }
199                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
200                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
201                 return ret_hu_conv;
202         }
203
204         /**
205          * Checks if two HTLCDestinations contain equal inner contents.
206          * This ignores pointers and is_owned flags and looks at the values in fields.
207          */
208         public boolean eq(org.ldk.structs.HTLCDestination b) {
209                 boolean ret = bindings.HTLCDestination_eq(this.ptr, b.ptr);
210                 Reference.reachabilityFence(this);
211                 Reference.reachabilityFence(b);
212                 return ret;
213         }
214
215         @Override public boolean equals(Object o) {
216                 if (!(o instanceof HTLCDestination)) return false;
217                 return this.eq((HTLCDestination)o);
218         }
219         /**
220          * Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read
221          */
222         public byte[] write() {
223                 byte[] ret = bindings.HTLCDestination_write(this.ptr);
224                 Reference.reachabilityFence(this);
225                 return ret;
226         }
227
228 }