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 an incoming HTLC, including the [`PendingHTLCRouting`] describing where it
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class PendingHTLCInfo extends CommonBase {
17 PendingHTLCInfo(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.PendingHTLCInfo_free(ptr); }
25 * Further routing details based on whether the HTLC is being forwarded or received.
27 public PendingHTLCRouting get_routing() {
28 long ret = bindings.PendingHTLCInfo_get_routing(this.ptr);
29 Reference.reachabilityFence(this);
30 if (ret >= 0 && ret <= 4096) { return null; }
31 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
32 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
37 * Further routing details based on whether the HTLC is being forwarded or received.
39 public void set_routing(org.ldk.structs.PendingHTLCRouting val) {
40 bindings.PendingHTLCInfo_set_routing(this.ptr, val.ptr);
41 Reference.reachabilityFence(this);
42 Reference.reachabilityFence(val);
43 if (this != null) { this.ptrs_to.add(val); };
47 * The onion shared secret we build with the sender used to decrypt the onion.
49 * This is later used to encrypt failure packets in the event that the HTLC is failed.
51 public byte[] get_incoming_shared_secret() {
52 byte[] ret = bindings.PendingHTLCInfo_get_incoming_shared_secret(this.ptr);
53 Reference.reachabilityFence(this);
58 * The onion shared secret we build with the sender used to decrypt the onion.
60 * This is later used to encrypt failure packets in the event that the HTLC is failed.
62 public void set_incoming_shared_secret(byte[] val) {
63 bindings.PendingHTLCInfo_set_incoming_shared_secret(this.ptr, InternalUtils.check_arr_len(val, 32));
64 Reference.reachabilityFence(this);
65 Reference.reachabilityFence(val);
69 * Hash of the payment preimage, to lock the payment until the receiver releases the preimage.
71 public byte[] get_payment_hash() {
72 byte[] ret = bindings.PendingHTLCInfo_get_payment_hash(this.ptr);
73 Reference.reachabilityFence(this);
78 * Hash of the payment preimage, to lock the payment until the receiver releases the preimage.
80 public void set_payment_hash(byte[] val) {
81 bindings.PendingHTLCInfo_set_payment_hash(this.ptr, InternalUtils.check_arr_len(val, 32));
82 Reference.reachabilityFence(this);
83 Reference.reachabilityFence(val);
87 * Amount received in the incoming HTLC.
89 * This field was added in LDK 0.0.113 and will be `None` for objects written by prior
92 public Option_u64Z get_incoming_amt_msat() {
93 long ret = bindings.PendingHTLCInfo_get_incoming_amt_msat(this.ptr);
94 Reference.reachabilityFence(this);
95 if (ret >= 0 && ret <= 4096) { return null; }
96 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
97 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
102 * Amount received in the incoming HTLC.
104 * This field was added in LDK 0.0.113 and will be `None` for objects written by prior
107 public void set_incoming_amt_msat(org.ldk.structs.Option_u64Z val) {
108 bindings.PendingHTLCInfo_set_incoming_amt_msat(this.ptr, val.ptr);
109 Reference.reachabilityFence(this);
110 Reference.reachabilityFence(val);
111 if (this != null) { this.ptrs_to.add(val); };
115 * The amount the sender indicated should be forwarded on to the next hop or amount the sender
116 * intended for us to receive for received payments.
118 * If the received amount is less than this for received payments, an intermediary hop has
119 * attempted to steal some of our funds and we should fail the HTLC (the sender should retry
120 * it along another path).
122 * Because nodes can take less than their required fees, and because senders may wish to
123 * improve their own privacy, this amount may be less than [`Self::incoming_amt_msat`] for
124 * received payments. In such cases, recipients must handle this HTLC as if it had received
125 * [`Self::outgoing_amt_msat`].
127 public long get_outgoing_amt_msat() {
128 long ret = bindings.PendingHTLCInfo_get_outgoing_amt_msat(this.ptr);
129 Reference.reachabilityFence(this);
134 * The amount the sender indicated should be forwarded on to the next hop or amount the sender
135 * intended for us to receive for received payments.
137 * If the received amount is less than this for received payments, an intermediary hop has
138 * attempted to steal some of our funds and we should fail the HTLC (the sender should retry
139 * it along another path).
141 * Because nodes can take less than their required fees, and because senders may wish to
142 * improve their own privacy, this amount may be less than [`Self::incoming_amt_msat`] for
143 * received payments. In such cases, recipients must handle this HTLC as if it had received
144 * [`Self::outgoing_amt_msat`].
146 public void set_outgoing_amt_msat(long val) {
147 bindings.PendingHTLCInfo_set_outgoing_amt_msat(this.ptr, val);
148 Reference.reachabilityFence(this);
149 Reference.reachabilityFence(val);
153 * The CLTV the sender has indicated we should set on the forwarded HTLC (or has indicated
154 * should have been set on the received HTLC for received payments).
156 public int get_outgoing_cltv_value() {
157 int ret = bindings.PendingHTLCInfo_get_outgoing_cltv_value(this.ptr);
158 Reference.reachabilityFence(this);
163 * The CLTV the sender has indicated we should set on the forwarded HTLC (or has indicated
164 * should have been set on the received HTLC for received payments).
166 public void set_outgoing_cltv_value(int val) {
167 bindings.PendingHTLCInfo_set_outgoing_cltv_value(this.ptr, val);
168 Reference.reachabilityFence(this);
169 Reference.reachabilityFence(val);
173 * The fee taken for this HTLC in addition to the standard protocol HTLC fees.
175 * If this is a payment for forwarding, this is the fee we are taking before forwarding the
178 * If this is a received payment, this is the fee that our counterparty took.
180 * This is used to allow LSPs to take fees as a part of payments, without the sender having to
183 public Option_u64Z get_skimmed_fee_msat() {
184 long ret = bindings.PendingHTLCInfo_get_skimmed_fee_msat(this.ptr);
185 Reference.reachabilityFence(this);
186 if (ret >= 0 && ret <= 4096) { return null; }
187 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
188 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
193 * The fee taken for this HTLC in addition to the standard protocol HTLC fees.
195 * If this is a payment for forwarding, this is the fee we are taking before forwarding the
198 * If this is a received payment, this is the fee that our counterparty took.
200 * This is used to allow LSPs to take fees as a part of payments, without the sender having to
203 public void set_skimmed_fee_msat(org.ldk.structs.Option_u64Z val) {
204 bindings.PendingHTLCInfo_set_skimmed_fee_msat(this.ptr, val.ptr);
205 Reference.reachabilityFence(this);
206 Reference.reachabilityFence(val);
207 if (this != null) { this.ptrs_to.add(val); };
211 * Constructs a new PendingHTLCInfo given each field
213 public static PendingHTLCInfo of(org.ldk.structs.PendingHTLCRouting routing_arg, byte[] incoming_shared_secret_arg, byte[] payment_hash_arg, org.ldk.structs.Option_u64Z incoming_amt_msat_arg, long outgoing_amt_msat_arg, int outgoing_cltv_value_arg, org.ldk.structs.Option_u64Z skimmed_fee_msat_arg) {
214 long ret = bindings.PendingHTLCInfo_new(routing_arg.ptr, InternalUtils.check_arr_len(incoming_shared_secret_arg, 32), InternalUtils.check_arr_len(payment_hash_arg, 32), incoming_amt_msat_arg.ptr, outgoing_amt_msat_arg, outgoing_cltv_value_arg, skimmed_fee_msat_arg.ptr);
215 Reference.reachabilityFence(routing_arg);
216 Reference.reachabilityFence(incoming_shared_secret_arg);
217 Reference.reachabilityFence(payment_hash_arg);
218 Reference.reachabilityFence(incoming_amt_msat_arg);
219 Reference.reachabilityFence(outgoing_amt_msat_arg);
220 Reference.reachabilityFence(outgoing_cltv_value_arg);
221 Reference.reachabilityFence(skimmed_fee_msat_arg);
222 if (ret >= 0 && ret <= 4096) { return null; }
223 org.ldk.structs.PendingHTLCInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PendingHTLCInfo(null, ret); }
224 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
225 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(routing_arg); };
226 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(incoming_amt_msat_arg); };
227 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(skimmed_fee_msat_arg); };
232 long ret = bindings.PendingHTLCInfo_clone_ptr(this.ptr);
233 Reference.reachabilityFence(this);
238 * Creates a copy of the PendingHTLCInfo
240 public PendingHTLCInfo clone() {
241 long ret = bindings.PendingHTLCInfo_clone(this.ptr);
242 Reference.reachabilityFence(this);
243 if (ret >= 0 && ret <= 4096) { return null; }
244 org.ldk.structs.PendingHTLCInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PendingHTLCInfo(null, ret); }
245 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
250 * Serialize the PendingHTLCInfo object into a byte array which can be read by PendingHTLCInfo_read
252 public byte[] write() {
253 byte[] ret = bindings.PendingHTLCInfo_write(this.ptr);
254 Reference.reachabilityFence(this);
259 * Read a PendingHTLCInfo from a byte array, created by PendingHTLCInfo_write
261 public static Result_PendingHTLCInfoDecodeErrorZ read(byte[] ser) {
262 long ret = bindings.PendingHTLCInfo_read(ser);
263 Reference.reachabilityFence(ser);
264 if (ret >= 0 && ret <= 4096) { return null; }
265 Result_PendingHTLCInfoDecodeErrorZ ret_hu_conv = Result_PendingHTLCInfoDecodeErrorZ.constr_from_ptr(ret);