1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
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 {
20 if (ptr != 0) { bindings.HTLCDestination_free(ptr); }
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);
27 if (raw_val.getClass() == bindings.LDKHTLCDestination.UnknownNextHop.class) {
28 return new UnknownNextHop(ptr, (bindings.LDKHTLCDestination.UnknownNextHop)raw_val);
30 if (raw_val.getClass() == bindings.LDKHTLCDestination.FailedPayment.class) {
31 return new FailedPayment(ptr, (bindings.LDKHTLCDestination.FailedPayment)raw_val);
33 assert false; return null; // Unreachable without extending the (internal) bindings interface
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.
40 public final static class NextHopChannel extends HTLCDestination {
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.
46 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
48 @Nullable public final byte[] node_id;
50 * The outgoing `channel_id` between us and the next node.
52 public final byte[] channel_id;
53 private NextHopChannel(long ptr, bindings.LDKHTLCDestination.NextHopChannel obj) {
55 this.node_id = obj.node_id;
56 this.channel_id = obj.channel_id;
60 * Scenario where we are unsure of the next node to forward the HTLC to.
62 public final static class UnknownNextHop extends HTLCDestination {
64 * Short channel id we are requesting to forward an HTLC to.
66 public final long requested_forward_scid;
67 private UnknownNextHop(long ptr, bindings.LDKHTLCDestination.UnknownNextHop obj) {
69 this.requested_forward_scid = obj.requested_forward_scid;
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.
76 * Some of the reasons may include:
78 * Expected MPP amount to claim does not equal HTLC total
79 * Claimable amount does not match expected amount
81 public final static class FailedPayment extends HTLCDestination {
83 * The payment hash of the payment we attempted to process.
85 public final byte[] payment_hash;
86 private FailedPayment(long ptr, bindings.LDKHTLCDestination.FailedPayment obj) {
88 this.payment_hash = obj.payment_hash;
92 long ret = bindings.HTLCDestination_clone_ptr(this.ptr);
93 Reference.reachabilityFence(this);
98 * Creates a copy of the HTLCDestination
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 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
110 * Utility method to constructs a new NextHopChannel-variant HTLCDestination
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 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
123 * Utility method to constructs a new UnknownNextHop-variant HTLCDestination
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 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
135 * Utility method to constructs a new FailedPayment-variant HTLCDestination
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 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
147 * Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read
149 public byte[] write() {
150 byte[] ret = bindings.HTLCDestination_write(this.ptr);
151 Reference.reachabilityFence(this);