6 namespace org { namespace ldk { namespace structs {
9 * Information about where a received HTLC('s onion) has indicated the HTLC should go.
11 public class PendingHTLCRouting : CommonBase {
12 protected PendingHTLCRouting(object _dummy, long ptr) : base(ptr) { }
13 ~PendingHTLCRouting() {
14 if (ptr != 0) { bindings.PendingHTLCRouting_free(ptr); }
17 internal static PendingHTLCRouting constr_from_ptr(long ptr) {
18 long raw_ty = bindings.LDKPendingHTLCRouting_ty_from_ptr(ptr);
20 case 0: return new PendingHTLCRouting_Forward(ptr);
21 case 1: return new PendingHTLCRouting_Receive(ptr);
22 case 2: return new PendingHTLCRouting_ReceiveKeysend(ptr);
24 throw new ArgumentException("Impossible enum variant");
28 /** A PendingHTLCRouting of type Forward */
29 public class PendingHTLCRouting_Forward : PendingHTLCRouting {
31 * The onion which should be included in the forwarded HTLC, telling the next hop what to
34 public OnionPacket onion_packet;
36 * The short channel ID of the channel which we were instructed to forward this HTLC to.
38 * This could be a real on-chain SCID, an SCID alias, or some other SCID which has meaning
39 * to the receiving node, such as one returned from
40 * [`ChannelManager::get_intercept_scid`] or [`ChannelManager::get_phantom_scid`].
42 public long short_channel_id;
44 * Set if this HTLC is being forwarded within a blinded path.
46 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
48 public BlindedForward blinded;
49 internal PendingHTLCRouting_Forward(long ptr) : base(null, ptr) {
50 long onion_packet = bindings.LDKPendingHTLCRouting_Forward_get_onion_packet(ptr);
51 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); }
52 if (onion_packet_hu_conv != null) { onion_packet_hu_conv.ptrs_to.AddLast(this); };
53 this.onion_packet = onion_packet_hu_conv;
54 this.short_channel_id = bindings.LDKPendingHTLCRouting_Forward_get_short_channel_id(ptr);
55 long blinded = bindings.LDKPendingHTLCRouting_Forward_get_blinded(ptr);
56 org.ldk.structs.BlindedForward blinded_hu_conv = null; if (blinded < 0 || blinded > 4096) { blinded_hu_conv = new org.ldk.structs.BlindedForward(null, blinded); }
57 if (blinded_hu_conv != null) { blinded_hu_conv.ptrs_to.AddLast(this); };
58 this.blinded = blinded_hu_conv;
61 /** A PendingHTLCRouting of type Receive */
62 public class PendingHTLCRouting_Receive : PendingHTLCRouting {
64 * Information about the amount the sender intended to pay and (potential) proof that this
65 * is a payment for an invoice we generated. This proof of payment is is also used for
66 * linking MPP parts of a larger payment.
68 public FinalOnionHopData payment_data;
70 * Additional data which we (allegedly) instructed the sender to include in the onion.
72 * For HTLCs received by LDK, this will ultimately be exposed in
73 * [`Event::PaymentClaimable::onion_fields`] as
74 * [`RecipientOnionFields::payment_metadata`].
76 public Option_CVec_u8ZZ payment_metadata;
78 * The context of the payment included by the recipient in a blinded path, or `None` if a
79 * blinded path was not used.
81 * Used in part to determine the [`events::PaymentPurpose`].
83 public Option_PaymentContextZ payment_context;
85 * CLTV expiry of the received HTLC.
87 * Used to track when we should expire pending HTLCs that go unclaimed.
89 public int incoming_cltv_expiry;
91 * If the onion had forwarding instructions to one of our phantom node SCIDs, this will
92 * provide the onion shared secret used to decrypt the next level of forwarding
95 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
97 public byte[] phantom_shared_secret;
99 * Custom TLVs which were set by the sender.
101 * For HTLCs received by LDK, this will ultimately be exposed in
102 * [`Event::PaymentClaimable::onion_fields`] as
103 * [`RecipientOnionFields::custom_tlvs`].
105 public TwoTuple_u64CVec_u8ZZ[] custom_tlvs;
107 * Set if this HTLC is the final hop in a multi-hop blinded path.
109 public bool requires_blinded_error;
110 internal PendingHTLCRouting_Receive(long ptr) : base(null, ptr) {
111 long payment_data = bindings.LDKPendingHTLCRouting_Receive_get_payment_data(ptr);
112 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); }
113 if (payment_data_hu_conv != null) { payment_data_hu_conv.ptrs_to.AddLast(this); };
114 this.payment_data = payment_data_hu_conv;
115 long payment_metadata = bindings.LDKPendingHTLCRouting_Receive_get_payment_metadata(ptr);
116 org.ldk.structs.Option_CVec_u8ZZ payment_metadata_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(payment_metadata);
117 if (payment_metadata_hu_conv != null) { payment_metadata_hu_conv.ptrs_to.AddLast(this); };
118 this.payment_metadata = payment_metadata_hu_conv;
119 long payment_context = bindings.LDKPendingHTLCRouting_Receive_get_payment_context(ptr);
120 org.ldk.structs.Option_PaymentContextZ payment_context_hu_conv = org.ldk.structs.Option_PaymentContextZ.constr_from_ptr(payment_context);
121 if (payment_context_hu_conv != null) { payment_context_hu_conv.ptrs_to.AddLast(this); };
122 this.payment_context = payment_context_hu_conv;
123 this.incoming_cltv_expiry = bindings.LDKPendingHTLCRouting_Receive_get_incoming_cltv_expiry(ptr);
124 long phantom_shared_secret = bindings.LDKPendingHTLCRouting_Receive_get_phantom_shared_secret(ptr);
125 byte[] phantom_shared_secret_conv = InternalUtils.decodeUint8Array(phantom_shared_secret);
126 this.phantom_shared_secret = phantom_shared_secret_conv;
127 long custom_tlvs = bindings.LDKPendingHTLCRouting_Receive_get_custom_tlvs(ptr);
128 int custom_tlvs_conv_23_len = InternalUtils.getArrayLength(custom_tlvs);
129 TwoTuple_u64CVec_u8ZZ[] custom_tlvs_conv_23_arr = new TwoTuple_u64CVec_u8ZZ[custom_tlvs_conv_23_len];
130 for (int x = 0; x < custom_tlvs_conv_23_len; x++) {
131 long custom_tlvs_conv_23 = InternalUtils.getU64ArrayElem(custom_tlvs, x);
132 TwoTuple_u64CVec_u8ZZ custom_tlvs_conv_23_hu_conv = new TwoTuple_u64CVec_u8ZZ(null, custom_tlvs_conv_23);
133 if (custom_tlvs_conv_23_hu_conv != null) { custom_tlvs_conv_23_hu_conv.ptrs_to.AddLast(this); };
134 custom_tlvs_conv_23_arr[x] = custom_tlvs_conv_23_hu_conv;
136 bindings.free_buffer(custom_tlvs);
137 this.custom_tlvs = custom_tlvs_conv_23_arr;
138 this.requires_blinded_error = bindings.LDKPendingHTLCRouting_Receive_get_requires_blinded_error(ptr);
141 /** A PendingHTLCRouting of type ReceiveKeysend */
142 public class PendingHTLCRouting_ReceiveKeysend : PendingHTLCRouting {
144 * Information about the amount the sender intended to pay and possibly a token to
145 * associate MPP parts of a larger payment.
147 * This will only be filled in if receiving MPP keysend payments is enabled, and it being
148 * present will cause deserialization to fail on versions of LDK prior to 0.0.116.
150 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
152 public FinalOnionHopData payment_data;
154 * Preimage for this onion payment. This preimage is provided by the sender and will be
155 * used to settle the spontaneous payment.
157 public byte[] payment_preimage;
159 * Additional data which we (allegedly) instructed the sender to include in the onion.
161 * For HTLCs received by LDK, this will ultimately bubble back up as
162 * [`RecipientOnionFields::payment_metadata`].
164 public Option_CVec_u8ZZ payment_metadata;
166 * CLTV expiry of the received HTLC.
168 * Used to track when we should expire pending HTLCs that go unclaimed.
170 public int incoming_cltv_expiry;
172 * Custom TLVs which were set by the sender.
174 * For HTLCs received by LDK, these will ultimately bubble back up as
175 * [`RecipientOnionFields::custom_tlvs`].
177 public TwoTuple_u64CVec_u8ZZ[] custom_tlvs;
179 * Set if this HTLC is the final hop in a multi-hop blinded path.
181 public bool requires_blinded_error;
182 internal PendingHTLCRouting_ReceiveKeysend(long ptr) : base(null, ptr) {
183 long payment_data = bindings.LDKPendingHTLCRouting_ReceiveKeysend_get_payment_data(ptr);
184 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); }
185 if (payment_data_hu_conv != null) { payment_data_hu_conv.ptrs_to.AddLast(this); };
186 this.payment_data = payment_data_hu_conv;
187 long payment_preimage = bindings.LDKPendingHTLCRouting_ReceiveKeysend_get_payment_preimage(ptr);
188 byte[] payment_preimage_conv = InternalUtils.decodeUint8Array(payment_preimage);
189 this.payment_preimage = payment_preimage_conv;
190 long payment_metadata = bindings.LDKPendingHTLCRouting_ReceiveKeysend_get_payment_metadata(ptr);
191 org.ldk.structs.Option_CVec_u8ZZ payment_metadata_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(payment_metadata);
192 if (payment_metadata_hu_conv != null) { payment_metadata_hu_conv.ptrs_to.AddLast(this); };
193 this.payment_metadata = payment_metadata_hu_conv;
194 this.incoming_cltv_expiry = bindings.LDKPendingHTLCRouting_ReceiveKeysend_get_incoming_cltv_expiry(ptr);
195 long custom_tlvs = bindings.LDKPendingHTLCRouting_ReceiveKeysend_get_custom_tlvs(ptr);
196 int custom_tlvs_conv_23_len = InternalUtils.getArrayLength(custom_tlvs);
197 TwoTuple_u64CVec_u8ZZ[] custom_tlvs_conv_23_arr = new TwoTuple_u64CVec_u8ZZ[custom_tlvs_conv_23_len];
198 for (int x = 0; x < custom_tlvs_conv_23_len; x++) {
199 long custom_tlvs_conv_23 = InternalUtils.getU64ArrayElem(custom_tlvs, x);
200 TwoTuple_u64CVec_u8ZZ custom_tlvs_conv_23_hu_conv = new TwoTuple_u64CVec_u8ZZ(null, custom_tlvs_conv_23);
201 if (custom_tlvs_conv_23_hu_conv != null) { custom_tlvs_conv_23_hu_conv.ptrs_to.AddLast(this); };
202 custom_tlvs_conv_23_arr[x] = custom_tlvs_conv_23_hu_conv;
204 bindings.free_buffer(custom_tlvs);
205 this.custom_tlvs = custom_tlvs_conv_23_arr;
206 this.requires_blinded_error = bindings.LDKPendingHTLCRouting_ReceiveKeysend_get_requires_blinded_error(ptr);
209 internal long clone_ptr() {
210 long ret = bindings.PendingHTLCRouting_clone_ptr(this.ptr);
216 * Creates a copy of the PendingHTLCRouting
218 public PendingHTLCRouting clone() {
219 long ret = bindings.PendingHTLCRouting_clone(this.ptr);
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.AddLast(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.ptr, short_channel_id, blinded.ptr);
232 GC.KeepAlive(onion_packet);
233 GC.KeepAlive(short_channel_id);
234 GC.KeepAlive(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.AddLast(ret_hu_conv); };
238 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(onion_packet); };
239 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(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, org.ldk.structs.Option_PaymentContextZ payment_context, int incoming_cltv_expiry, byte[] phantom_shared_secret, TwoTuple_u64CVec_u8ZZ[] custom_tlvs, bool requires_blinded_error) {
247 long ret = bindings.PendingHTLCRouting_receive(payment_data.ptr, payment_metadata.ptr, payment_context.ptr, incoming_cltv_expiry, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(phantom_shared_secret, 32)), InternalUtils.encodeUint64Array(InternalUtils.mapArray(custom_tlvs, custom_tlvs_conv_23 => custom_tlvs_conv_23.ptr)), requires_blinded_error);
248 GC.KeepAlive(payment_data);
249 GC.KeepAlive(payment_metadata);
250 GC.KeepAlive(payment_context);
251 GC.KeepAlive(incoming_cltv_expiry);
252 GC.KeepAlive(phantom_shared_secret);
253 GC.KeepAlive(custom_tlvs);
254 GC.KeepAlive(requires_blinded_error);
255 if (ret >= 0 && ret <= 4096) { return null; }
256 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
257 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
258 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_data); };
259 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_metadata); };
260 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_context); };
265 * Utility method to constructs a new ReceiveKeysend-variant PendingHTLCRouting
267 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, bool requires_blinded_error) {
268 long ret = bindings.PendingHTLCRouting_receive_keysend(payment_data.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_preimage, 32)), payment_metadata.ptr, incoming_cltv_expiry, InternalUtils.encodeUint64Array(InternalUtils.mapArray(custom_tlvs, custom_tlvs_conv_23 => custom_tlvs_conv_23.ptr)), requires_blinded_error);
269 GC.KeepAlive(payment_data);
270 GC.KeepAlive(payment_preimage);
271 GC.KeepAlive(payment_metadata);
272 GC.KeepAlive(incoming_cltv_expiry);
273 GC.KeepAlive(custom_tlvs);
274 GC.KeepAlive(requires_blinded_error);
275 if (ret >= 0 && ret <= 4096) { return null; }
276 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
277 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
278 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_data); };
279 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_metadata); };
284 * Serialize the PendingHTLCRouting object into a byte array which can be read by PendingHTLCRouting_read
286 public byte[] write() {
287 long ret = bindings.PendingHTLCRouting_write(this.ptr);
289 if (ret >= 0 && ret <= 4096) { return null; }
290 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
295 * Read a PendingHTLCRouting from a byte array, created by PendingHTLCRouting_write
297 public static Result_PendingHTLCRoutingDecodeErrorZ read(byte[] ser) {
298 long ret = bindings.PendingHTLCRouting_read(InternalUtils.encodeUint8Array(ser));
300 if (ret >= 0 && ret <= 4096) { return null; }
301 Result_PendingHTLCRoutingDecodeErrorZ ret_hu_conv = Result_PendingHTLCRoutingDecodeErrorZ.constr_from_ptr(ret);