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 * Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
13 * These include payments that have yet to find a successful path, or have unresolved HTLCs.
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class RecentPaymentDetails extends CommonBase {
17 private RecentPaymentDetails(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.RecentPaymentDetails_free(ptr); }
23 static RecentPaymentDetails constr_from_ptr(long ptr) {
24 bindings.LDKRecentPaymentDetails raw_val = bindings.LDKRecentPaymentDetails_ref_from_ptr(ptr);
25 if (raw_val.getClass() == bindings.LDKRecentPaymentDetails.AwaitingInvoice.class) {
26 return new AwaitingInvoice(ptr, (bindings.LDKRecentPaymentDetails.AwaitingInvoice)raw_val);
28 if (raw_val.getClass() == bindings.LDKRecentPaymentDetails.Pending.class) {
29 return new Pending(ptr, (bindings.LDKRecentPaymentDetails.Pending)raw_val);
31 if (raw_val.getClass() == bindings.LDKRecentPaymentDetails.Fulfilled.class) {
32 return new Fulfilled(ptr, (bindings.LDKRecentPaymentDetails.Fulfilled)raw_val);
34 if (raw_val.getClass() == bindings.LDKRecentPaymentDetails.Abandoned.class) {
35 return new Abandoned(ptr, (bindings.LDKRecentPaymentDetails.Abandoned)raw_val);
37 assert false; return null; // Unreachable without extending the (internal) bindings interface
41 * When an invoice was requested and thus a payment has not yet been sent.
43 public final static class AwaitingInvoice extends RecentPaymentDetails {
45 * A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
46 * a payment and ensure idempotency in LDK.
48 public final byte[] payment_id;
49 private AwaitingInvoice(long ptr, bindings.LDKRecentPaymentDetails.AwaitingInvoice obj) {
51 this.payment_id = obj.payment_id;
55 * When a payment is still being sent and awaiting successful delivery.
57 public final static class Pending extends RecentPaymentDetails {
59 * A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
60 * a payment and ensure idempotency in LDK.
62 public final byte[] payment_id;
64 * Hash of the payment that is currently being sent but has yet to be fulfilled or
67 public final byte[] payment_hash;
69 * Total amount (in msat, excluding fees) across all paths for this payment,
70 * not just the amount currently inflight.
72 public final long total_msat;
73 private Pending(long ptr, bindings.LDKRecentPaymentDetails.Pending obj) {
75 this.payment_id = obj.payment_id;
76 this.payment_hash = obj.payment_hash;
77 this.total_msat = obj.total_msat;
81 * When a pending payment is fulfilled, we continue tracking it until all pending HTLCs have
82 * been resolved. Upon receiving [`Event::PaymentSent`], we delay for a few minutes before the
83 * payment is removed from tracking.
85 public final static class Fulfilled extends RecentPaymentDetails {
87 * A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
88 * a payment and ensure idempotency in LDK.
90 public final byte[] payment_id;
92 * Hash of the payment that was claimed. `None` for serializations of [`ChannelManager`]
93 * made before LDK version 0.0.104.
95 public final org.ldk.structs.Option_ThirtyTwoBytesZ payment_hash;
96 private Fulfilled(long ptr, bindings.LDKRecentPaymentDetails.Fulfilled obj) {
98 this.payment_id = obj.payment_id;
99 long payment_hash = obj.payment_hash;
100 org.ldk.structs.Option_ThirtyTwoBytesZ payment_hash_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(payment_hash);
101 if (payment_hash_hu_conv != null) { payment_hash_hu_conv.ptrs_to.add(this); };
102 this.payment_hash = payment_hash_hu_conv;
106 * After a payment's retries are exhausted per the provided [`Retry`], or it is explicitly
107 * abandoned via [`ChannelManager::abandon_payment`], it is marked as abandoned until all
108 * pending HTLCs for this payment resolve and an [`Event::PaymentFailed`] is generated.
110 public final static class Abandoned extends RecentPaymentDetails {
112 * A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
113 * a payment and ensure idempotency in LDK.
115 public final byte[] payment_id;
117 * Hash of the payment that we have given up trying to send.
119 public final byte[] payment_hash;
120 private Abandoned(long ptr, bindings.LDKRecentPaymentDetails.Abandoned obj) {
122 this.payment_id = obj.payment_id;
123 this.payment_hash = obj.payment_hash;
127 long ret = bindings.RecentPaymentDetails_clone_ptr(this.ptr);
128 Reference.reachabilityFence(this);
133 * Creates a copy of the RecentPaymentDetails
135 public RecentPaymentDetails clone() {
136 long ret = bindings.RecentPaymentDetails_clone(this.ptr);
137 Reference.reachabilityFence(this);
138 if (ret >= 0 && ret <= 4096) { return null; }
139 org.ldk.structs.RecentPaymentDetails ret_hu_conv = org.ldk.structs.RecentPaymentDetails.constr_from_ptr(ret);
140 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
145 * Utility method to constructs a new AwaitingInvoice-variant RecentPaymentDetails
147 public static RecentPaymentDetails awaiting_invoice(byte[] payment_id) {
148 long ret = bindings.RecentPaymentDetails_awaiting_invoice(InternalUtils.check_arr_len(payment_id, 32));
149 Reference.reachabilityFence(payment_id);
150 if (ret >= 0 && ret <= 4096) { return null; }
151 org.ldk.structs.RecentPaymentDetails ret_hu_conv = org.ldk.structs.RecentPaymentDetails.constr_from_ptr(ret);
152 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
157 * Utility method to constructs a new Pending-variant RecentPaymentDetails
159 public static RecentPaymentDetails pending(byte[] payment_id, byte[] payment_hash, long total_msat) {
160 long ret = bindings.RecentPaymentDetails_pending(InternalUtils.check_arr_len(payment_id, 32), InternalUtils.check_arr_len(payment_hash, 32), total_msat);
161 Reference.reachabilityFence(payment_id);
162 Reference.reachabilityFence(payment_hash);
163 Reference.reachabilityFence(total_msat);
164 if (ret >= 0 && ret <= 4096) { return null; }
165 org.ldk.structs.RecentPaymentDetails ret_hu_conv = org.ldk.structs.RecentPaymentDetails.constr_from_ptr(ret);
166 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
171 * Utility method to constructs a new Fulfilled-variant RecentPaymentDetails
173 public static RecentPaymentDetails fulfilled(byte[] payment_id, org.ldk.structs.Option_ThirtyTwoBytesZ payment_hash) {
174 long ret = bindings.RecentPaymentDetails_fulfilled(InternalUtils.check_arr_len(payment_id, 32), payment_hash.ptr);
175 Reference.reachabilityFence(payment_id);
176 Reference.reachabilityFence(payment_hash);
177 if (ret >= 0 && ret <= 4096) { return null; }
178 org.ldk.structs.RecentPaymentDetails ret_hu_conv = org.ldk.structs.RecentPaymentDetails.constr_from_ptr(ret);
179 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
180 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_hash); };
185 * Utility method to constructs a new Abandoned-variant RecentPaymentDetails
187 public static RecentPaymentDetails abandoned(byte[] payment_id, byte[] payment_hash) {
188 long ret = bindings.RecentPaymentDetails_abandoned(InternalUtils.check_arr_len(payment_id, 32), InternalUtils.check_arr_len(payment_hash, 32));
189 Reference.reachabilityFence(payment_id);
190 Reference.reachabilityFence(payment_hash);
191 if (ret >= 0 && ret <= 4096) { return null; }
192 org.ldk.structs.RecentPaymentDetails ret_hu_conv = org.ldk.structs.RecentPaymentDetails.constr_from_ptr(ret);
193 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };