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