Update auto-generated bindings to 0.0.103
[ldk-java] / src / main / java / org / ldk / structs / InvoicePayer.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
8
9
10 /**
11  * A utility for paying [`Invoice]`s.
12  */
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class InvoicePayer extends CommonBase {
15         InvoicePayer(Object _dummy, long ptr) { super(ptr); }
16         @Override @SuppressWarnings("deprecation")
17         protected void finalize() throws Throwable {
18                 super.finalize();
19                 if (ptr != 0) { bindings.InvoicePayer_free(ptr); }
20         }
21
22         /**
23          * Creates an invoice payer that retries failed payment paths.
24          * 
25          * Will forward any [`Event::PaymentPathFailed`] events to the decorated `event_handler` once
26          * `retry_attempts` has been exceeded for a given [`Invoice`].
27          */
28         public static InvoicePayer of(Payer payer, Router router, LockableScore scorer, Logger logger, EventHandler event_handler, RetryAttempts retry_attempts) {
29                 long ret = bindings.InvoicePayer_new(payer == null ? 0 : payer.ptr, router == null ? 0 : router.ptr, scorer == null ? 0 : scorer.ptr & ~1, logger == null ? 0 : logger.ptr, event_handler == null ? 0 : event_handler.ptr, retry_attempts == null ? 0 : retry_attempts.ptr & ~1);
30                 if (ret >= 0 && ret <= 4096) { return null; }
31                 InvoicePayer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new InvoicePayer(null, ret); }
32                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
33                 ret_hu_conv.ptrs_to.add(payer);
34                 ret_hu_conv.ptrs_to.add(router);
35                 ret_hu_conv.ptrs_to.add(scorer);
36                 ret_hu_conv.ptrs_to.add(logger);
37                 ret_hu_conv.ptrs_to.add(event_handler);
38                 return ret_hu_conv;
39         }
40
41         /**
42          * Pays the given [`Invoice`], caching it for later use in case a retry is needed.
43          * 
44          * You should ensure that the `invoice.payment_hash()` is unique and the same payment_hash has
45          * never been paid before. Because [`InvoicePayer`] is stateless no effort is made to do so
46          * for you.
47          */
48         public Result_PaymentIdPaymentErrorZ pay_invoice(Invoice invoice) {
49                 long ret = bindings.InvoicePayer_pay_invoice(this.ptr, invoice == null ? 0 : invoice.ptr & ~1);
50                 if (ret >= 0 && ret <= 4096) { return null; }
51                 Result_PaymentIdPaymentErrorZ ret_hu_conv = Result_PaymentIdPaymentErrorZ.constr_from_ptr(ret);
52                 this.ptrs_to.add(invoice);
53                 return ret_hu_conv;
54         }
55
56         /**
57          * Pays the given zero-value [`Invoice`] using the given amount, caching it for later use in
58          * case a retry is needed.
59          * 
60          * You should ensure that the `invoice.payment_hash()` is unique and the same payment_hash has
61          * never been paid before. Because [`InvoicePayer`] is stateless no effort is made to do so
62          * for you.
63          */
64         public Result_PaymentIdPaymentErrorZ pay_zero_value_invoice(Invoice invoice, long amount_msats) {
65                 long ret = bindings.InvoicePayer_pay_zero_value_invoice(this.ptr, invoice == null ? 0 : invoice.ptr & ~1, amount_msats);
66                 if (ret >= 0 && ret <= 4096) { return null; }
67                 Result_PaymentIdPaymentErrorZ ret_hu_conv = Result_PaymentIdPaymentErrorZ.constr_from_ptr(ret);
68                 this.ptrs_to.add(invoice);
69                 return ret_hu_conv;
70         }
71
72         /**
73          * Removes the payment cached by the given payment hash.
74          * 
75          * Should be called once a payment has failed or succeeded if not using [`InvoicePayer`] as an
76          * [`EventHandler`]. Otherwise, calling this method is unnecessary.
77          */
78         public void remove_cached_payment(byte[] payment_hash) {
79                 bindings.InvoicePayer_remove_cached_payment(this.ptr, payment_hash);
80         }
81
82         /**
83          * Constructs a new EventHandler which calls the relevant methods on this_arg.
84          * This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is
85          */
86         public EventHandler as_EventHandler() {
87                 long ret = bindings.InvoicePayer_as_EventHandler(this.ptr);
88                 if (ret >= 0 && ret <= 4096) { return null; }
89                 EventHandler ret_hu_conv = new EventHandler(null, ret);
90                 ret_hu_conv.ptrs_to.add(this);
91                 return ret_hu_conv;
92         }
93
94 }