[Java] Update auto-generated Java bindings to LDK 0.0.110
[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.FailedPayment.class) {
31                         return new FailedPayment(ptr, (bindings.LDKHTLCDestination.FailedPayment)raw_val);
32                 }
33                 assert false; return null; // Unreachable without extending the (internal) bindings interface
34         }
35
36         /**
37          * We tried forwarding to a channel but failed to do so. An example of such an instance is when
38          * there is insufficient capacity in our outbound channel.
39          */
40         public final static class NextHopChannel extends HTLCDestination {
41                 /**
42                  * The `node_id` of the next node. For backwards compatibility, this field is
43                  * marked as optional, versions prior to 0.0.110 may not always be able to provide
44                  * counterparty node information.
45                  * 
46                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
47                 */
48                 @Nullable public final byte[] node_id;
49                 /**
50                  * The outgoing `channel_id` between us and the next node.
51                 */
52                 public final byte[] channel_id;
53                 private NextHopChannel(long ptr, bindings.LDKHTLCDestination.NextHopChannel obj) {
54                         super(null, ptr);
55                         this.node_id = obj.node_id;
56                         this.channel_id = obj.channel_id;
57                 }
58         }
59         /**
60          * Scenario where we are unsure of the next node to forward the HTLC to.
61          */
62         public final static class UnknownNextHop extends HTLCDestination {
63                 /**
64                  * Short channel id we are requesting to forward an HTLC to.
65                 */
66                 public final long requested_forward_scid;
67                 private UnknownNextHop(long ptr, bindings.LDKHTLCDestination.UnknownNextHop obj) {
68                         super(null, ptr);
69                         this.requested_forward_scid = obj.requested_forward_scid;
70                 }
71         }
72         /**
73          * Failure scenario where an HTLC may have been forwarded to be intended for us,
74          * but is invalid for some reason, so we reject it.
75          * 
76          * Some of the reasons may include:
77          * HTLC Timeouts
78          * Expected MPP amount to claim does not equal HTLC total
79          * Claimable amount does not match expected amount
80          */
81         public final static class FailedPayment extends HTLCDestination {
82                 /**
83                  * The payment hash of the payment we attempted to process.
84                 */
85                 public final byte[] payment_hash;
86                 private FailedPayment(long ptr, bindings.LDKHTLCDestination.FailedPayment obj) {
87                         super(null, ptr);
88                         this.payment_hash = obj.payment_hash;
89                 }
90         }
91         long clone_ptr() {
92                 long ret = bindings.HTLCDestination_clone_ptr(this.ptr);
93                 Reference.reachabilityFence(this);
94                 return ret;
95         }
96
97         /**
98          * Creates a copy of the HTLCDestination
99          */
100         public HTLCDestination clone() {
101                 long ret = bindings.HTLCDestination_clone(this.ptr);
102                 Reference.reachabilityFence(this);
103                 if (ret >= 0 && ret <= 4096) { return null; }
104                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
105                 ret_hu_conv.ptrs_to.add(this);
106                 return ret_hu_conv;
107         }
108
109         /**
110          * Utility method to constructs a new NextHopChannel-variant HTLCDestination
111          */
112         public static HTLCDestination next_hop_channel(byte[] node_id, byte[] channel_id) {
113                 long ret = bindings.HTLCDestination_next_hop_channel(InternalUtils.check_arr_len(node_id, 33), InternalUtils.check_arr_len(channel_id, 32));
114                 Reference.reachabilityFence(node_id);
115                 Reference.reachabilityFence(channel_id);
116                 if (ret >= 0 && ret <= 4096) { return null; }
117                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
118                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
119                 return ret_hu_conv;
120         }
121
122         /**
123          * Utility method to constructs a new UnknownNextHop-variant HTLCDestination
124          */
125         public static HTLCDestination unknown_next_hop(long requested_forward_scid) {
126                 long ret = bindings.HTLCDestination_unknown_next_hop(requested_forward_scid);
127                 Reference.reachabilityFence(requested_forward_scid);
128                 if (ret >= 0 && ret <= 4096) { return null; }
129                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
130                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
131                 return ret_hu_conv;
132         }
133
134         /**
135          * Utility method to constructs a new FailedPayment-variant HTLCDestination
136          */
137         public static HTLCDestination failed_payment(byte[] payment_hash) {
138                 long ret = bindings.HTLCDestination_failed_payment(InternalUtils.check_arr_len(payment_hash, 32));
139                 Reference.reachabilityFence(payment_hash);
140                 if (ret >= 0 && ret <= 4096) { return null; }
141                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
142                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
143                 return ret_hu_conv;
144         }
145
146         /**
147          * Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read
148          */
149         public byte[] write() {
150                 byte[] ret = bindings.HTLCDestination_write(this.ptr);
151                 Reference.reachabilityFence(this);
152                 return ret;
153         }
154
155 }