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 * CLTV expiry of the received HTLC.
80 * Used to track when we should expire pending HTLCs that go unclaimed.
82 public int incoming_cltv_expiry;
84 * If the onion had forwarding instructions to one of our phantom node SCIDs, this will
85 * provide the onion shared secret used to decrypt the next level of forwarding
88 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
90 public byte[] phantom_shared_secret;
92 * Custom TLVs which were set by the sender.
94 * For HTLCs received by LDK, this will ultimately be exposed in
95 * [`Event::PaymentClaimable::onion_fields`] as
96 * [`RecipientOnionFields::custom_tlvs`].
98 public TwoTuple_u64CVec_u8ZZ[] custom_tlvs;
100 * Set if this HTLC is the final hop in a multi-hop blinded path.
102 public bool requires_blinded_error;
103 internal PendingHTLCRouting_Receive(long ptr) : base(null, ptr) {
104 long payment_data = bindings.LDKPendingHTLCRouting_Receive_get_payment_data(ptr);
105 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); }
106 if (payment_data_hu_conv != null) { payment_data_hu_conv.ptrs_to.AddLast(this); };
107 this.payment_data = payment_data_hu_conv;
108 long payment_metadata = bindings.LDKPendingHTLCRouting_Receive_get_payment_metadata(ptr);
109 org.ldk.structs.Option_CVec_u8ZZ payment_metadata_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(payment_metadata);
110 if (payment_metadata_hu_conv != null) { payment_metadata_hu_conv.ptrs_to.AddLast(this); };
111 this.payment_metadata = payment_metadata_hu_conv;
112 this.incoming_cltv_expiry = bindings.LDKPendingHTLCRouting_Receive_get_incoming_cltv_expiry(ptr);
113 long phantom_shared_secret = bindings.LDKPendingHTLCRouting_Receive_get_phantom_shared_secret(ptr);
114 byte[] phantom_shared_secret_conv = InternalUtils.decodeUint8Array(phantom_shared_secret);
115 this.phantom_shared_secret = phantom_shared_secret_conv;
116 long custom_tlvs = bindings.LDKPendingHTLCRouting_Receive_get_custom_tlvs(ptr);
117 int custom_tlvs_conv_23_len = InternalUtils.getArrayLength(custom_tlvs);
118 TwoTuple_u64CVec_u8ZZ[] custom_tlvs_conv_23_arr = new TwoTuple_u64CVec_u8ZZ[custom_tlvs_conv_23_len];
119 for (int x = 0; x < custom_tlvs_conv_23_len; x++) {
120 long custom_tlvs_conv_23 = InternalUtils.getU64ArrayElem(custom_tlvs, x);
121 TwoTuple_u64CVec_u8ZZ custom_tlvs_conv_23_hu_conv = new TwoTuple_u64CVec_u8ZZ(null, custom_tlvs_conv_23);
122 if (custom_tlvs_conv_23_hu_conv != null) { custom_tlvs_conv_23_hu_conv.ptrs_to.AddLast(this); };
123 custom_tlvs_conv_23_arr[x] = custom_tlvs_conv_23_hu_conv;
125 bindings.free_buffer(custom_tlvs);
126 this.custom_tlvs = custom_tlvs_conv_23_arr;
127 this.requires_blinded_error = bindings.LDKPendingHTLCRouting_Receive_get_requires_blinded_error(ptr);
130 /** A PendingHTLCRouting of type ReceiveKeysend */
131 public class PendingHTLCRouting_ReceiveKeysend : PendingHTLCRouting {
133 * Information about the amount the sender intended to pay and possibly a token to
134 * associate MPP parts of a larger payment.
136 * This will only be filled in if receiving MPP keysend payments is enabled, and it being
137 * present will cause deserialization to fail on versions of LDK prior to 0.0.116.
139 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
141 public FinalOnionHopData payment_data;
143 * Preimage for this onion payment. This preimage is provided by the sender and will be
144 * used to settle the spontaneous payment.
146 public byte[] payment_preimage;
148 * Additional data which we (allegedly) instructed the sender to include in the onion.
150 * For HTLCs received by LDK, this will ultimately bubble back up as
151 * [`RecipientOnionFields::payment_metadata`].
153 public Option_CVec_u8ZZ payment_metadata;
155 * CLTV expiry of the received HTLC.
157 * Used to track when we should expire pending HTLCs that go unclaimed.
159 public int incoming_cltv_expiry;
161 * Custom TLVs which were set by the sender.
163 * For HTLCs received by LDK, these will ultimately bubble back up as
164 * [`RecipientOnionFields::custom_tlvs`].
166 public TwoTuple_u64CVec_u8ZZ[] custom_tlvs;
167 internal PendingHTLCRouting_ReceiveKeysend(long ptr) : base(null, ptr) {
168 long payment_data = bindings.LDKPendingHTLCRouting_ReceiveKeysend_get_payment_data(ptr);
169 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); }
170 if (payment_data_hu_conv != null) { payment_data_hu_conv.ptrs_to.AddLast(this); };
171 this.payment_data = payment_data_hu_conv;
172 long payment_preimage = bindings.LDKPendingHTLCRouting_ReceiveKeysend_get_payment_preimage(ptr);
173 byte[] payment_preimage_conv = InternalUtils.decodeUint8Array(payment_preimage);
174 this.payment_preimage = payment_preimage_conv;
175 long payment_metadata = bindings.LDKPendingHTLCRouting_ReceiveKeysend_get_payment_metadata(ptr);
176 org.ldk.structs.Option_CVec_u8ZZ payment_metadata_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(payment_metadata);
177 if (payment_metadata_hu_conv != null) { payment_metadata_hu_conv.ptrs_to.AddLast(this); };
178 this.payment_metadata = payment_metadata_hu_conv;
179 this.incoming_cltv_expiry = bindings.LDKPendingHTLCRouting_ReceiveKeysend_get_incoming_cltv_expiry(ptr);
180 long custom_tlvs = bindings.LDKPendingHTLCRouting_ReceiveKeysend_get_custom_tlvs(ptr);
181 int custom_tlvs_conv_23_len = InternalUtils.getArrayLength(custom_tlvs);
182 TwoTuple_u64CVec_u8ZZ[] custom_tlvs_conv_23_arr = new TwoTuple_u64CVec_u8ZZ[custom_tlvs_conv_23_len];
183 for (int x = 0; x < custom_tlvs_conv_23_len; x++) {
184 long custom_tlvs_conv_23 = InternalUtils.getU64ArrayElem(custom_tlvs, x);
185 TwoTuple_u64CVec_u8ZZ custom_tlvs_conv_23_hu_conv = new TwoTuple_u64CVec_u8ZZ(null, custom_tlvs_conv_23);
186 if (custom_tlvs_conv_23_hu_conv != null) { custom_tlvs_conv_23_hu_conv.ptrs_to.AddLast(this); };
187 custom_tlvs_conv_23_arr[x] = custom_tlvs_conv_23_hu_conv;
189 bindings.free_buffer(custom_tlvs);
190 this.custom_tlvs = custom_tlvs_conv_23_arr;
193 internal long clone_ptr() {
194 long ret = bindings.PendingHTLCRouting_clone_ptr(this.ptr);
200 * Creates a copy of the PendingHTLCRouting
202 public PendingHTLCRouting clone() {
203 long ret = bindings.PendingHTLCRouting_clone(this.ptr);
205 if (ret >= 0 && ret <= 4096) { return null; }
206 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
207 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
212 * Utility method to constructs a new Forward-variant PendingHTLCRouting
214 public static PendingHTLCRouting forward(org.ldk.structs.OnionPacket onion_packet, long short_channel_id, org.ldk.structs.BlindedForward blinded) {
215 long ret = bindings.PendingHTLCRouting_forward(onion_packet == null ? 0 : onion_packet.ptr, short_channel_id, blinded == null ? 0 : blinded.ptr);
216 GC.KeepAlive(onion_packet);
217 GC.KeepAlive(short_channel_id);
218 GC.KeepAlive(blinded);
219 if (ret >= 0 && ret <= 4096) { return null; }
220 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
221 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
222 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(onion_packet); };
223 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(blinded); };
228 * Utility method to constructs a new Receive-variant PendingHTLCRouting
230 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, bool requires_blinded_error) {
231 long ret = bindings.PendingHTLCRouting_receive(payment_data == null ? 0 : payment_data.ptr, payment_metadata.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 != null ? custom_tlvs_conv_23.ptr : 0)), requires_blinded_error);
232 GC.KeepAlive(payment_data);
233 GC.KeepAlive(payment_metadata);
234 GC.KeepAlive(incoming_cltv_expiry);
235 GC.KeepAlive(phantom_shared_secret);
236 GC.KeepAlive(custom_tlvs);
237 GC.KeepAlive(requires_blinded_error);
238 if (ret >= 0 && ret <= 4096) { return null; }
239 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
240 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
241 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_data); };
242 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_metadata); };
247 * Utility method to constructs a new ReceiveKeysend-variant PendingHTLCRouting
249 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) {
250 long ret = bindings.PendingHTLCRouting_receive_keysend(payment_data == null ? 0 : 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 != null ? custom_tlvs_conv_23.ptr : 0)));
251 GC.KeepAlive(payment_data);
252 GC.KeepAlive(payment_preimage);
253 GC.KeepAlive(payment_metadata);
254 GC.KeepAlive(incoming_cltv_expiry);
255 GC.KeepAlive(custom_tlvs);
256 if (ret >= 0 && ret <= 4096) { return null; }
257 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
258 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
259 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_data); };
260 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_metadata); };
265 * Serialize the PendingHTLCRouting object into a byte array which can be read by PendingHTLCRouting_read
267 public byte[] write() {
268 long ret = bindings.PendingHTLCRouting_write(this.ptr);
270 if (ret >= 0 && ret <= 4096) { return null; }
271 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
276 * Read a PendingHTLCRouting from a byte array, created by PendingHTLCRouting_write
278 public static Result_PendingHTLCRoutingDecodeErrorZ read(byte[] ser) {
279 long ret = bindings.PendingHTLCRouting_read(InternalUtils.encodeUint8Array(ser));
281 if (ret >= 0 && ret <= 4096) { return null; }
282 Result_PendingHTLCRoutingDecodeErrorZ ret_hu_conv = Result_PendingHTLCRoutingDecodeErrorZ.constr_from_ptr(ret);