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 * Information about where a received HTLC('s onion) has indicated the HTLC should go.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class PendingHTLCRouting extends CommonBase {
16 private PendingHTLCRouting(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.PendingHTLCRouting_free(ptr); }
22 static PendingHTLCRouting constr_from_ptr(long ptr) {
23 bindings.LDKPendingHTLCRouting raw_val = bindings.LDKPendingHTLCRouting_ref_from_ptr(ptr);
24 if (raw_val.getClass() == bindings.LDKPendingHTLCRouting.Forward.class) {
25 return new Forward(ptr, (bindings.LDKPendingHTLCRouting.Forward)raw_val);
27 if (raw_val.getClass() == bindings.LDKPendingHTLCRouting.Receive.class) {
28 return new Receive(ptr, (bindings.LDKPendingHTLCRouting.Receive)raw_val);
30 if (raw_val.getClass() == bindings.LDKPendingHTLCRouting.ReceiveKeysend.class) {
31 return new ReceiveKeysend(ptr, (bindings.LDKPendingHTLCRouting.ReceiveKeysend)raw_val);
33 assert false; return null; // Unreachable without extending the (internal) bindings interface
37 * An HTLC which should be forwarded on to another node.
39 public final static class Forward extends PendingHTLCRouting {
41 * The onion which should be included in the forwarded HTLC, telling the next hop what to
44 public final org.ldk.structs.OnionPacket onion_packet;
46 * The short channel ID of the channel which we were instructed to forward this HTLC to.
48 * This could be a real on-chain SCID, an SCID alias, or some other SCID which has meaning
49 * to the receiving node, such as one returned from
50 * [`ChannelManager::get_intercept_scid`] or [`ChannelManager::get_phantom_scid`].
52 public final long short_channel_id;
54 * Set if this HTLC is being forwarded within a blinded path.
56 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
58 @Nullable public final org.ldk.structs.BlindedForward blinded;
59 private Forward(long ptr, bindings.LDKPendingHTLCRouting.Forward obj) {
61 long onion_packet = obj.onion_packet;
62 org.ldk.structs.OnionPacket onion_packet_hu_conv = null; if (onion_packet < 0 || onion_packet > 4096) { onion_packet_hu_conv = new org.ldk.structs.OnionPacket(null, onion_packet); }
63 if (onion_packet_hu_conv != null) { onion_packet_hu_conv.ptrs_to.add(this); };
64 this.onion_packet = onion_packet_hu_conv;
65 this.short_channel_id = obj.short_channel_id;
66 long blinded = obj.blinded;
67 org.ldk.structs.BlindedForward blinded_hu_conv = null; if (blinded < 0 || blinded > 4096) { blinded_hu_conv = new org.ldk.structs.BlindedForward(null, blinded); }
68 if (blinded_hu_conv != null) { blinded_hu_conv.ptrs_to.add(this); };
69 this.blinded = blinded_hu_conv;
73 * The onion indicates that this is a payment for an invoice (supposedly) generated by us.
75 * Note that at this point, we have not checked that the invoice being paid was actually
76 * generated by us, but rather it's claiming to pay an invoice of ours.
78 public final static class Receive extends PendingHTLCRouting {
80 * Information about the amount the sender intended to pay and (potential) proof that this
81 * is a payment for an invoice we generated. This proof of payment is is also used for
82 * linking MPP parts of a larger payment.
84 public final org.ldk.structs.FinalOnionHopData payment_data;
86 * Additional data which we (allegedly) instructed the sender to include in the onion.
88 * For HTLCs received by LDK, this will ultimately be exposed in
89 * [`Event::PaymentClaimable::onion_fields`] as
90 * [`RecipientOnionFields::payment_metadata`].
92 public final org.ldk.structs.Option_CVec_u8ZZ payment_metadata;
94 * CLTV expiry of the received HTLC.
96 * Used to track when we should expire pending HTLCs that go unclaimed.
98 public final int incoming_cltv_expiry;
100 * If the onion had forwarding instructions to one of our phantom node SCIDs, this will
101 * provide the onion shared secret used to decrypt the next level of forwarding
104 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
106 @Nullable public final byte[] phantom_shared_secret;
108 * Custom TLVs which were set by the sender.
110 * For HTLCs received by LDK, this will ultimately be exposed in
111 * [`Event::PaymentClaimable::onion_fields`] as
112 * [`RecipientOnionFields::custom_tlvs`].
114 public final TwoTuple_u64CVec_u8ZZ[] custom_tlvs;
116 * Set if this HTLC is the final hop in a multi-hop blinded path.
118 public final boolean requires_blinded_error;
119 private Receive(long ptr, bindings.LDKPendingHTLCRouting.Receive obj) {
121 long payment_data = obj.payment_data;
122 org.ldk.structs.FinalOnionHopData payment_data_hu_conv = null; if (payment_data < 0 || payment_data > 4096) { payment_data_hu_conv = new org.ldk.structs.FinalOnionHopData(null, payment_data); }
123 if (payment_data_hu_conv != null) { payment_data_hu_conv.ptrs_to.add(this); };
124 this.payment_data = payment_data_hu_conv;
125 long payment_metadata = obj.payment_metadata;
126 org.ldk.structs.Option_CVec_u8ZZ payment_metadata_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(payment_metadata);
127 if (payment_metadata_hu_conv != null) { payment_metadata_hu_conv.ptrs_to.add(this); };
128 this.payment_metadata = payment_metadata_hu_conv;
129 this.incoming_cltv_expiry = obj.incoming_cltv_expiry;
130 this.phantom_shared_secret = obj.phantom_shared_secret;
131 long[] custom_tlvs = obj.custom_tlvs;
132 int custom_tlvs_conv_23_len = custom_tlvs.length;
133 TwoTuple_u64CVec_u8ZZ[] custom_tlvs_conv_23_arr = new TwoTuple_u64CVec_u8ZZ[custom_tlvs_conv_23_len];
134 for (int x = 0; x < custom_tlvs_conv_23_len; x++) {
135 long custom_tlvs_conv_23 = custom_tlvs[x];
136 TwoTuple_u64CVec_u8ZZ custom_tlvs_conv_23_hu_conv = new TwoTuple_u64CVec_u8ZZ(null, custom_tlvs_conv_23);
137 if (custom_tlvs_conv_23_hu_conv != null) { custom_tlvs_conv_23_hu_conv.ptrs_to.add(this); };
138 custom_tlvs_conv_23_arr[x] = custom_tlvs_conv_23_hu_conv;
140 this.custom_tlvs = custom_tlvs_conv_23_arr;
141 this.requires_blinded_error = obj.requires_blinded_error;
145 * The onion indicates that this is for payment to us but which contains the preimage for
146 * claiming included, and is unrelated to any invoice we'd previously generated (aka a
147 * \"keysend\" or \"spontaneous\" payment).
149 public final static class ReceiveKeysend extends PendingHTLCRouting {
151 * Information about the amount the sender intended to pay and possibly a token to
152 * associate MPP parts of a larger payment.
154 * This will only be filled in if receiving MPP keysend payments is enabled, and it being
155 * present will cause deserialization to fail on versions of LDK prior to 0.0.116.
157 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
159 @Nullable public final org.ldk.structs.FinalOnionHopData payment_data;
161 * Preimage for this onion payment. This preimage is provided by the sender and will be
162 * used to settle the spontaneous payment.
164 public final byte[] payment_preimage;
166 * Additional data which we (allegedly) instructed the sender to include in the onion.
168 * For HTLCs received by LDK, this will ultimately bubble back up as
169 * [`RecipientOnionFields::payment_metadata`].
171 public final org.ldk.structs.Option_CVec_u8ZZ payment_metadata;
173 * CLTV expiry of the received HTLC.
175 * Used to track when we should expire pending HTLCs that go unclaimed.
177 public final int incoming_cltv_expiry;
179 * Custom TLVs which were set by the sender.
181 * For HTLCs received by LDK, these will ultimately bubble back up as
182 * [`RecipientOnionFields::custom_tlvs`].
184 public final TwoTuple_u64CVec_u8ZZ[] custom_tlvs;
185 private ReceiveKeysend(long ptr, bindings.LDKPendingHTLCRouting.ReceiveKeysend obj) {
187 long payment_data = obj.payment_data;
188 org.ldk.structs.FinalOnionHopData payment_data_hu_conv = null; if (payment_data < 0 || payment_data > 4096) { payment_data_hu_conv = new org.ldk.structs.FinalOnionHopData(null, payment_data); }
189 if (payment_data_hu_conv != null) { payment_data_hu_conv.ptrs_to.add(this); };
190 this.payment_data = payment_data_hu_conv;
191 this.payment_preimage = obj.payment_preimage;
192 long payment_metadata = obj.payment_metadata;
193 org.ldk.structs.Option_CVec_u8ZZ payment_metadata_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(payment_metadata);
194 if (payment_metadata_hu_conv != null) { payment_metadata_hu_conv.ptrs_to.add(this); };
195 this.payment_metadata = payment_metadata_hu_conv;
196 this.incoming_cltv_expiry = obj.incoming_cltv_expiry;
197 long[] custom_tlvs = obj.custom_tlvs;
198 int custom_tlvs_conv_23_len = custom_tlvs.length;
199 TwoTuple_u64CVec_u8ZZ[] custom_tlvs_conv_23_arr = new TwoTuple_u64CVec_u8ZZ[custom_tlvs_conv_23_len];
200 for (int x = 0; x < custom_tlvs_conv_23_len; x++) {
201 long custom_tlvs_conv_23 = custom_tlvs[x];
202 TwoTuple_u64CVec_u8ZZ custom_tlvs_conv_23_hu_conv = new TwoTuple_u64CVec_u8ZZ(null, custom_tlvs_conv_23);
203 if (custom_tlvs_conv_23_hu_conv != null) { custom_tlvs_conv_23_hu_conv.ptrs_to.add(this); };
204 custom_tlvs_conv_23_arr[x] = custom_tlvs_conv_23_hu_conv;
206 this.custom_tlvs = custom_tlvs_conv_23_arr;
210 long ret = bindings.PendingHTLCRouting_clone_ptr(this.ptr);
211 Reference.reachabilityFence(this);
216 * Creates a copy of the PendingHTLCRouting
218 public PendingHTLCRouting clone() {
219 long ret = bindings.PendingHTLCRouting_clone(this.ptr);
220 Reference.reachabilityFence(this);
221 if (ret >= 0 && ret <= 4096) { return null; }
222 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
223 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
228 * Utility method to constructs a new Forward-variant PendingHTLCRouting
230 public static PendingHTLCRouting forward(org.ldk.structs.OnionPacket onion_packet, long short_channel_id, org.ldk.structs.BlindedForward blinded) {
231 long ret = bindings.PendingHTLCRouting_forward(onion_packet == null ? 0 : onion_packet.ptr, short_channel_id, blinded == null ? 0 : blinded.ptr);
232 Reference.reachabilityFence(onion_packet);
233 Reference.reachabilityFence(short_channel_id);
234 Reference.reachabilityFence(blinded);
235 if (ret >= 0 && ret <= 4096) { return null; }
236 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
237 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
238 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(onion_packet); };
239 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(blinded); };
244 * Utility method to constructs a new Receive-variant PendingHTLCRouting
246 public static PendingHTLCRouting receive(org.ldk.structs.FinalOnionHopData payment_data, org.ldk.structs.Option_CVec_u8ZZ payment_metadata, int incoming_cltv_expiry, byte[] phantom_shared_secret, TwoTuple_u64CVec_u8ZZ[] custom_tlvs, boolean requires_blinded_error) {
247 long ret = bindings.PendingHTLCRouting_receive(payment_data == null ? 0 : payment_data.ptr, payment_metadata.ptr, incoming_cltv_expiry, InternalUtils.check_arr_len(phantom_shared_secret, 32), custom_tlvs != null ? Arrays.stream(custom_tlvs).mapToLong(custom_tlvs_conv_23 -> custom_tlvs_conv_23 != null ? custom_tlvs_conv_23.ptr : 0).toArray() : null, requires_blinded_error);
248 Reference.reachabilityFence(payment_data);
249 Reference.reachabilityFence(payment_metadata);
250 Reference.reachabilityFence(incoming_cltv_expiry);
251 Reference.reachabilityFence(phantom_shared_secret);
252 Reference.reachabilityFence(custom_tlvs);
253 Reference.reachabilityFence(requires_blinded_error);
254 if (ret >= 0 && ret <= 4096) { return null; }
255 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
256 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
257 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_data); };
258 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_metadata); };
263 * Utility method to constructs a new ReceiveKeysend-variant PendingHTLCRouting
265 public static PendingHTLCRouting receive_keysend(org.ldk.structs.FinalOnionHopData payment_data, byte[] payment_preimage, org.ldk.structs.Option_CVec_u8ZZ payment_metadata, int incoming_cltv_expiry, TwoTuple_u64CVec_u8ZZ[] custom_tlvs) {
266 long ret = bindings.PendingHTLCRouting_receive_keysend(payment_data == null ? 0 : payment_data.ptr, InternalUtils.check_arr_len(payment_preimage, 32), payment_metadata.ptr, incoming_cltv_expiry, custom_tlvs != null ? Arrays.stream(custom_tlvs).mapToLong(custom_tlvs_conv_23 -> custom_tlvs_conv_23 != null ? custom_tlvs_conv_23.ptr : 0).toArray() : null);
267 Reference.reachabilityFence(payment_data);
268 Reference.reachabilityFence(payment_preimage);
269 Reference.reachabilityFence(payment_metadata);
270 Reference.reachabilityFence(incoming_cltv_expiry);
271 Reference.reachabilityFence(custom_tlvs);
272 if (ret >= 0 && ret <= 4096) { return null; }
273 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
274 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
275 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_data); };
276 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_metadata); };
281 * Serialize the PendingHTLCRouting object into a byte array which can be read by PendingHTLCRouting_read
283 public byte[] write() {
284 byte[] ret = bindings.PendingHTLCRouting_write(this.ptr);
285 Reference.reachabilityFence(this);
290 * Read a PendingHTLCRouting from a byte array, created by PendingHTLCRouting_write
292 public static Result_PendingHTLCRoutingDecodeErrorZ read(byte[] ser) {
293 long ret = bindings.PendingHTLCRouting_read(ser);
294 Reference.reachabilityFence(ser);
295 if (ret >= 0 && ret <= 4096) { return null; }
296 Result_PendingHTLCRoutingDecodeErrorZ ret_hu_conv = Result_PendingHTLCRoutingDecodeErrorZ.constr_from_ptr(ret);