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