Update auto-generated bindings
[ldk-java] / src / main / java / org / ldk / structs / PaymentPurpose.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  * Some information provided on receipt of payment depends on whether the payment received is a
12  * spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class PaymentPurpose extends CommonBase {
16         private PaymentPurpose(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.PaymentPurpose_free(ptr); }
21         }
22         static PaymentPurpose constr_from_ptr(long ptr) {
23                 bindings.LDKPaymentPurpose raw_val = bindings.LDKPaymentPurpose_ref_from_ptr(ptr);
24                 if (raw_val.getClass() == bindings.LDKPaymentPurpose.InvoicePayment.class) {
25                         return new InvoicePayment(ptr, (bindings.LDKPaymentPurpose.InvoicePayment)raw_val);
26                 }
27                 if (raw_val.getClass() == bindings.LDKPaymentPurpose.SpontaneousPayment.class) {
28                         return new SpontaneousPayment(ptr, (bindings.LDKPaymentPurpose.SpontaneousPayment)raw_val);
29                 }
30                 assert false; return null; // Unreachable without extending the (internal) bindings interface
31         }
32
33         /**
34          * Information for receiving a payment that we generated an invoice for.
35          */
36         public final static class InvoicePayment extends PaymentPurpose {
37                 /**
38                  * The preimage to the payment_hash, if the payment hash (and secret) were fetched via
39                  * [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
40                  * [`ChannelManager::claim_funds`].
41                  * 
42                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
43                  * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
44                  * 
45                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
46                 */
47                 @Nullable public final byte[] payment_preimage;
48                 /**
49                  * The \"payment secret\". This authenticates the sender to the recipient, preventing a
50                  * number of deanonymization attacks during the routing process.
51                  * It is provided here for your reference, however its accuracy is enforced directly by
52                  * [`ChannelManager`] using the values you previously provided to
53                  * [`ChannelManager::create_inbound_payment`] or
54                  * [`ChannelManager::create_inbound_payment_for_hash`].
55                  * 
56                  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
57                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
58                  * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
59                 */
60                 public final byte[] payment_secret;
61                 /**
62                  * This is the `user_payment_id` which was provided to
63                  * [`ChannelManager::create_inbound_payment_for_hash`] or
64                  * [`ChannelManager::create_inbound_payment`]. It has no meaning inside of LDK and is
65                  * simply copied here. It may be used to correlate PaymentReceived events with invoice
66                  * metadata stored elsewhere.
67                  * 
68                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
69                  * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
70                 */
71                 public final long user_payment_id;
72                 private InvoicePayment(long ptr, bindings.LDKPaymentPurpose.InvoicePayment obj) {
73                         super(null, ptr);
74                         this.payment_preimage = obj.payment_preimage;
75                         this.payment_secret = obj.payment_secret;
76                         this.user_payment_id = obj.user_payment_id;
77                 }
78         }
79         /**
80          * Because this is a spontaneous payment, the payer generated their own preimage rather than us
81          * (the payee) providing a preimage.
82          */
83         public final static class SpontaneousPayment extends PaymentPurpose {
84                 public final byte[] spontaneous_payment;
85                 private SpontaneousPayment(long ptr, bindings.LDKPaymentPurpose.SpontaneousPayment obj) {
86                         super(null, ptr);
87                         this.spontaneous_payment = obj.spontaneous_payment;
88                 }
89         }
90         long clone_ptr() {
91                 long ret = bindings.PaymentPurpose_clone_ptr(this.ptr);
92                 return ret;
93         }
94
95         /**
96          * Creates a copy of the PaymentPurpose
97          */
98         public PaymentPurpose clone() {
99                 long ret = bindings.PaymentPurpose_clone(this.ptr);
100                 if (ret >= 0 && ret <= 4096) { return null; }
101                 PaymentPurpose ret_hu_conv = PaymentPurpose.constr_from_ptr(ret);
102                 ret_hu_conv.ptrs_to.add(this);
103                 return ret_hu_conv;
104         }
105
106         /**
107          * Utility method to constructs a new InvoicePayment-variant PaymentPurpose
108          */
109         public static PaymentPurpose invoice_payment(byte[] payment_preimage, byte[] payment_secret, long user_payment_id) {
110                 long ret = bindings.PaymentPurpose_invoice_payment(InternalUtils.check_arr_len(payment_preimage, 32), InternalUtils.check_arr_len(payment_secret, 32), user_payment_id);
111                 if (ret >= 0 && ret <= 4096) { return null; }
112                 PaymentPurpose ret_hu_conv = PaymentPurpose.constr_from_ptr(ret);
113                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
114                 return ret_hu_conv;
115         }
116
117         /**
118          * Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
119          */
120         public static PaymentPurpose spontaneous_payment(byte[] a) {
121                 long ret = bindings.PaymentPurpose_spontaneous_payment(InternalUtils.check_arr_len(a, 32));
122                 if (ret >= 0 && ret <= 4096) { return null; }
123                 PaymentPurpose ret_hu_conv = PaymentPurpose.constr_from_ptr(ret);
124                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
125                 return ret_hu_conv;
126         }
127
128 }