Update auto-generated bindings to 0.0.103
[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         public final static class InvoicePayment extends PaymentPurpose {
34                 /**
35                  * The preimage to the payment_hash, if the payment hash (and secret) were fetched via
36                  * [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
37                  * [`ChannelManager::claim_funds`].
38                  * 
39                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
40                  * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
41                  * 
42                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
43                 */
44                 @Nullable public final byte[] payment_preimage;
45                 /**
46                  * The \"payment secret\". This authenticates the sender to the recipient, preventing a
47                  * number of deanonymization attacks during the routing process.
48                  * It is provided here for your reference, however its accuracy is enforced directly by
49                  * [`ChannelManager`] using the values you previously provided to
50                  * [`ChannelManager::create_inbound_payment`] or
51                  * [`ChannelManager::create_inbound_payment_for_hash`].
52                  * 
53                  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
54                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
55                  * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
56                 */
57                 public final byte[] payment_secret;
58                 /**
59                  * This is the `user_payment_id` which was provided to
60                  * [`ChannelManager::create_inbound_payment_for_hash`] or
61                  * [`ChannelManager::create_inbound_payment`]. It has no meaning inside of LDK and is
62                  * simply copied here. It may be used to correlate PaymentReceived events with invoice
63                  * metadata stored elsewhere.
64                  * 
65                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
66                  * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
67                 */
68                 public final long user_payment_id;
69                 private InvoicePayment(long ptr, bindings.LDKPaymentPurpose.InvoicePayment obj) {
70                         super(null, ptr);
71                         this.payment_preimage = obj.payment_preimage;
72                         this.payment_secret = obj.payment_secret;
73                         this.user_payment_id = obj.user_payment_id;
74                 }
75         }
76         public final static class SpontaneousPayment extends PaymentPurpose {
77                 public final byte[] spontaneous_payment;
78                 private SpontaneousPayment(long ptr, bindings.LDKPaymentPurpose.SpontaneousPayment obj) {
79                         super(null, ptr);
80                         this.spontaneous_payment = obj.spontaneous_payment;
81                 }
82         }
83         /**
84          * Creates a copy of the PaymentPurpose
85          */
86         public PaymentPurpose clone() {
87                 long ret = bindings.PaymentPurpose_clone(this.ptr);
88                 if (ret >= 0 && ret <= 4096) { return null; }
89                 PaymentPurpose ret_hu_conv = PaymentPurpose.constr_from_ptr(ret);
90                 ret_hu_conv.ptrs_to.add(this);
91                 return ret_hu_conv;
92         }
93
94         /**
95          * Utility method to constructs a new InvoicePayment-variant PaymentPurpose
96          */
97         public static PaymentPurpose invoice_payment(byte[] payment_preimage, byte[] payment_secret, long user_payment_id) {
98                 long ret = bindings.PaymentPurpose_invoice_payment(payment_preimage, payment_secret, user_payment_id);
99                 if (ret >= 0 && ret <= 4096) { return null; }
100                 PaymentPurpose ret_hu_conv = PaymentPurpose.constr_from_ptr(ret);
101                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
102                 return ret_hu_conv;
103         }
104
105         /**
106          * Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
107          */
108         public static PaymentPurpose spontaneous_payment(byte[] a) {
109                 long ret = bindings.PaymentPurpose_spontaneous_payment(a);
110                 if (ret >= 0 && ret <= 4096) { return null; }
111                 PaymentPurpose ret_hu_conv = PaymentPurpose.constr_from_ptr(ret);
112                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
113                 return ret_hu_conv;
114         }
115
116 }