[Java] Update auto-generated Java bindings for 0.0.113
[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          * Expected MPP amount to claim does not equal HTLC total
96          * Claimable amount does not match expected amount
97          */
98         public final static class FailedPayment extends HTLCDestination {
99                 /**
100                  * The payment hash of the payment we attempted to process.
101                 */
102                 public final byte[] payment_hash;
103                 private FailedPayment(long ptr, bindings.LDKHTLCDestination.FailedPayment obj) {
104                         super(null, ptr);
105                         this.payment_hash = obj.payment_hash;
106                 }
107         }
108         long clone_ptr() {
109                 long ret = bindings.HTLCDestination_clone_ptr(this.ptr);
110                 Reference.reachabilityFence(this);
111                 return ret;
112         }
113
114         /**
115          * Creates a copy of the HTLCDestination
116          */
117         public HTLCDestination clone() {
118                 long ret = bindings.HTLCDestination_clone(this.ptr);
119                 Reference.reachabilityFence(this);
120                 if (ret >= 0 && ret <= 4096) { return null; }
121                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
122                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
123                 return ret_hu_conv;
124         }
125
126         /**
127          * Utility method to constructs a new NextHopChannel-variant HTLCDestination
128          */
129         public static HTLCDestination next_hop_channel(byte[] node_id, byte[] channel_id) {
130                 long ret = bindings.HTLCDestination_next_hop_channel(InternalUtils.check_arr_len(node_id, 33), InternalUtils.check_arr_len(channel_id, 32));
131                 Reference.reachabilityFence(node_id);
132                 Reference.reachabilityFence(channel_id);
133                 if (ret >= 0 && ret <= 4096) { return null; }
134                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
135                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
136                 return ret_hu_conv;
137         }
138
139         /**
140          * Utility method to constructs a new UnknownNextHop-variant HTLCDestination
141          */
142         public static HTLCDestination unknown_next_hop(long requested_forward_scid) {
143                 long ret = bindings.HTLCDestination_unknown_next_hop(requested_forward_scid);
144                 Reference.reachabilityFence(requested_forward_scid);
145                 if (ret >= 0 && ret <= 4096) { return null; }
146                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
147                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
148                 return ret_hu_conv;
149         }
150
151         /**
152          * Utility method to constructs a new InvalidForward-variant HTLCDestination
153          */
154         public static HTLCDestination invalid_forward(long requested_forward_scid) {
155                 long ret = bindings.HTLCDestination_invalid_forward(requested_forward_scid);
156                 Reference.reachabilityFence(requested_forward_scid);
157                 if (ret >= 0 && ret <= 4096) { return null; }
158                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
159                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
160                 return ret_hu_conv;
161         }
162
163         /**
164          * Utility method to constructs a new FailedPayment-variant HTLCDestination
165          */
166         public static HTLCDestination failed_payment(byte[] payment_hash) {
167                 long ret = bindings.HTLCDestination_failed_payment(InternalUtils.check_arr_len(payment_hash, 32));
168                 Reference.reachabilityFence(payment_hash);
169                 if (ret >= 0 && ret <= 4096) { return null; }
170                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
171                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
172                 return ret_hu_conv;
173         }
174
175         /**
176          * Checks if two HTLCDestinations contain equal inner contents.
177          * This ignores pointers and is_owned flags and looks at the values in fields.
178          */
179         public boolean eq(org.ldk.structs.HTLCDestination b) {
180                 boolean ret = bindings.HTLCDestination_eq(this.ptr, b == null ? 0 : b.ptr);
181                 Reference.reachabilityFence(this);
182                 Reference.reachabilityFence(b);
183                 return ret;
184         }
185
186         @Override public boolean equals(Object o) {
187                 if (!(o instanceof HTLCDestination)) return false;
188                 return this.eq((HTLCDestination)o);
189         }
190         /**
191          * Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read
192          */
193         public byte[] write() {
194                 byte[] ret = bindings.HTLCDestination_write(this.ptr);
195                 Reference.reachabilityFence(this);
196                 return ret;
197         }
198
199 }