6 namespace org { namespace ldk { namespace structs {
10 * A utility for paying [`Invoice`]s and sending spontaneous payments.
12 * See [module-level documentation] for details.
14 * [module-level documentation]: crate::payment
16 public class InvoicePayer : CommonBase {
17 internal InvoicePayer(object _dummy, long ptr) : base(ptr) { }
19 if (ptr != 0) { bindings.InvoicePayer_free(ptr); }
23 * Creates an invoice payer that retries failed payment paths.
25 * Will forward any [`Event::PaymentPathFailed`] events to the decorated `event_handler` once
26 * `retry` has been exceeded for a given [`Invoice`].
28 public static InvoicePayer of(org.ldk.structs.Payer payer, org.ldk.structs.Router router, org.ldk.structs.Logger logger, org.ldk.structs.EventHandler event_handler, org.ldk.structs.Retry retry) {
29 long ret = bindings.InvoicePayer_new(payer == null ? 0 : payer.ptr, router == null ? 0 : router.ptr, logger == null ? 0 : logger.ptr, event_handler == null ? 0 : event_handler.ptr, retry.ptr);
33 GC.KeepAlive(event_handler);
35 if (ret >= 0 && ret <= 4096) { return null; }
36 org.ldk.structs.InvoicePayer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InvoicePayer(null, ret); }
37 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
38 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payer); };
39 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(router); };
40 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
41 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(event_handler); };
46 * Pays the given [`Invoice`], caching it for later use in case a retry is needed.
48 * [`Invoice::payment_hash`] is used as the [`PaymentId`], which ensures idempotency as long
49 * as the payment is still pending. Once the payment completes or fails, you must ensure that
50 * a second payment with the same [`PaymentHash`] is never sent.
52 * If you wish to use a different payment idempotency token, see
53 * [`Self::pay_invoice_with_id`].
55 public Result_PaymentIdPaymentErrorZ pay_invoice(org.ldk.structs.Invoice invoice) {
56 long ret = bindings.InvoicePayer_pay_invoice(this.ptr, invoice == null ? 0 : invoice.ptr);
58 GC.KeepAlive(invoice);
59 if (ret >= 0 && ret <= 4096) { return null; }
60 Result_PaymentIdPaymentErrorZ ret_hu_conv = Result_PaymentIdPaymentErrorZ.constr_from_ptr(ret);
61 if (this != null) { this.ptrs_to.AddLast(invoice); };
66 * Pays the given [`Invoice`] with a custom idempotency key, caching the invoice for later use
67 * in case a retry is needed.
69 * Note that idempotency is only guaranteed as long as the payment is still pending. Once the
70 * payment completes or fails, no idempotency guarantees are made.
72 * You should ensure that the [`Invoice::payment_hash`] is unique and the same [`PaymentHash`]
73 * has never been paid before.
75 * See [`Self::pay_invoice`] for a variant which uses the [`PaymentHash`] for the idempotency
78 public Result_NonePaymentErrorZ pay_invoice_with_id(org.ldk.structs.Invoice invoice, byte[] payment_id) {
79 long ret = bindings.InvoicePayer_pay_invoice_with_id(this.ptr, invoice == null ? 0 : invoice.ptr, InternalUtils.check_arr_len(payment_id, 32));
81 GC.KeepAlive(invoice);
82 GC.KeepAlive(payment_id);
83 if (ret >= 0 && ret <= 4096) { return null; }
84 Result_NonePaymentErrorZ ret_hu_conv = Result_NonePaymentErrorZ.constr_from_ptr(ret);
85 if (this != null) { this.ptrs_to.AddLast(invoice); };
90 * Pays the given zero-value [`Invoice`] using the given amount, caching it for later use in
91 * case a retry is needed.
93 * [`Invoice::payment_hash`] is used as the [`PaymentId`], which ensures idempotency as long
94 * as the payment is still pending. Once the payment completes or fails, you must ensure that
95 * a second payment with the same [`PaymentHash`] is never sent.
97 * If you wish to use a different payment idempotency token, see
98 * [`Self::pay_zero_value_invoice_with_id`].
100 public Result_PaymentIdPaymentErrorZ pay_zero_value_invoice(org.ldk.structs.Invoice invoice, long amount_msats) {
101 long ret = bindings.InvoicePayer_pay_zero_value_invoice(this.ptr, invoice == null ? 0 : invoice.ptr, amount_msats);
103 GC.KeepAlive(invoice);
104 GC.KeepAlive(amount_msats);
105 if (ret >= 0 && ret <= 4096) { return null; }
106 Result_PaymentIdPaymentErrorZ ret_hu_conv = Result_PaymentIdPaymentErrorZ.constr_from_ptr(ret);
107 if (this != null) { this.ptrs_to.AddLast(invoice); };
112 * Pays the given zero-value [`Invoice`] using the given amount and custom idempotency key,
113 * caching the invoice for later use in case a retry is needed.
115 * Note that idempotency is only guaranteed as long as the payment is still pending. Once the
116 * payment completes or fails, no idempotency guarantees are made.
118 * You should ensure that the [`Invoice::payment_hash`] is unique and the same [`PaymentHash`]
119 * has never been paid before.
121 * See [`Self::pay_zero_value_invoice`] for a variant which uses the [`PaymentHash`] for the
124 public Result_NonePaymentErrorZ pay_zero_value_invoice_with_id(org.ldk.structs.Invoice invoice, long amount_msats, byte[] payment_id) {
125 long ret = bindings.InvoicePayer_pay_zero_value_invoice_with_id(this.ptr, invoice == null ? 0 : invoice.ptr, amount_msats, InternalUtils.check_arr_len(payment_id, 32));
127 GC.KeepAlive(invoice);
128 GC.KeepAlive(amount_msats);
129 GC.KeepAlive(payment_id);
130 if (ret >= 0 && ret <= 4096) { return null; }
131 Result_NonePaymentErrorZ ret_hu_conv = Result_NonePaymentErrorZ.constr_from_ptr(ret);
132 if (this != null) { this.ptrs_to.AddLast(invoice); };
137 * Pays `pubkey` an amount using the hash of the given preimage, caching it for later use in
138 * case a retry is needed.
140 * The hash of the [`PaymentPreimage`] is used as the [`PaymentId`], which ensures idempotency
141 * as long as the payment is still pending. Once the payment completes or fails, you must
142 * ensure that a second payment with the same [`PaymentPreimage`] is never sent.
144 public Result_PaymentIdPaymentErrorZ pay_pubkey(byte[] pubkey, byte[] payment_preimage, long amount_msats, int final_cltv_expiry_delta) {
145 long ret = bindings.InvoicePayer_pay_pubkey(this.ptr, InternalUtils.check_arr_len(pubkey, 33), InternalUtils.check_arr_len(payment_preimage, 32), amount_msats, final_cltv_expiry_delta);
147 GC.KeepAlive(pubkey);
148 GC.KeepAlive(payment_preimage);
149 GC.KeepAlive(amount_msats);
150 GC.KeepAlive(final_cltv_expiry_delta);
151 if (ret >= 0 && ret <= 4096) { return null; }
152 Result_PaymentIdPaymentErrorZ ret_hu_conv = Result_PaymentIdPaymentErrorZ.constr_from_ptr(ret);
157 * Pays `pubkey` an amount using the hash of the given preimage and a custom idempotency key,
158 * caching the invoice for later use in case a retry is needed.
160 * Note that idempotency is only guaranteed as long as the payment is still pending. Once the
161 * payment completes or fails, no idempotency guarantees are made.
163 * You should ensure that the [`PaymentPreimage`] is unique and the corresponding
164 * [`PaymentHash`] has never been paid before.
166 public Result_NonePaymentErrorZ pay_pubkey_with_id(byte[] pubkey, byte[] payment_preimage, byte[] payment_id, long amount_msats, int final_cltv_expiry_delta) {
167 long ret = bindings.InvoicePayer_pay_pubkey_with_id(this.ptr, InternalUtils.check_arr_len(pubkey, 33), InternalUtils.check_arr_len(payment_preimage, 32), InternalUtils.check_arr_len(payment_id, 32), amount_msats, final_cltv_expiry_delta);
169 GC.KeepAlive(pubkey);
170 GC.KeepAlive(payment_preimage);
171 GC.KeepAlive(payment_id);
172 GC.KeepAlive(amount_msats);
173 GC.KeepAlive(final_cltv_expiry_delta);
174 if (ret >= 0 && ret <= 4096) { return null; }
175 Result_NonePaymentErrorZ ret_hu_conv = Result_NonePaymentErrorZ.constr_from_ptr(ret);
180 * Removes the payment cached by the given payment hash.
182 * Should be called once a payment has failed or succeeded if not using [`InvoicePayer`] as an
183 * [`EventHandler`]. Otherwise, calling this method is unnecessary.
185 public void remove_cached_payment(byte[] payment_hash) {
186 bindings.InvoicePayer_remove_cached_payment(this.ptr, InternalUtils.check_arr_len(payment_hash, 32));
188 GC.KeepAlive(payment_hash);
192 * Constructs a new EventHandler which calls the relevant methods on this_arg.
193 * This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is
195 public EventHandler as_EventHandler() {
196 long ret = bindings.InvoicePayer_as_EventHandler(this.ptr);
198 if (ret >= 0 && ret <= 4096) { return null; }
199 EventHandler ret_hu_conv = new EventHandler(null, ret);
200 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };