[Java] Update auto-generated Java bindings to LDK 0.0.121
[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                 public final org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage;
47                 /**
48                  * The \"payment secret\". This authenticates the sender to the recipient, preventing a
49                  * number of deanonymization attacks during the routing process.
50                  * It is provided here for your reference, however its accuracy is enforced directly by
51                  * [`ChannelManager`] using the values you previously provided to
52                  * [`ChannelManager::create_inbound_payment`] or
53                  * [`ChannelManager::create_inbound_payment_for_hash`].
54                  * 
55                  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
56                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
57                  * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
58                 */
59                 public final byte[] payment_secret;
60                 private InvoicePayment(long ptr, bindings.LDKPaymentPurpose.InvoicePayment obj) {
61                         super(null, ptr);
62                         long payment_preimage = obj.payment_preimage;
63                         org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(payment_preimage);
64                         if (payment_preimage_hu_conv != null) { payment_preimage_hu_conv.ptrs_to.add(this); };
65                         this.payment_preimage = payment_preimage_hu_conv;
66                         this.payment_secret = obj.payment_secret;
67                 }
68         }
69         /**
70          * Because this is a spontaneous payment, the payer generated their own preimage rather than us
71          * (the payee) providing a preimage.
72          */
73         public final static class SpontaneousPayment extends PaymentPurpose {
74                 public final byte[] spontaneous_payment;
75                 private SpontaneousPayment(long ptr, bindings.LDKPaymentPurpose.SpontaneousPayment obj) {
76                         super(null, ptr);
77                         this.spontaneous_payment = obj.spontaneous_payment;
78                 }
79         }
80         long clone_ptr() {
81                 long ret = bindings.PaymentPurpose_clone_ptr(this.ptr);
82                 Reference.reachabilityFence(this);
83                 return ret;
84         }
85
86         /**
87          * Creates a copy of the PaymentPurpose
88          */
89         public PaymentPurpose clone() {
90                 long ret = bindings.PaymentPurpose_clone(this.ptr);
91                 Reference.reachabilityFence(this);
92                 if (ret >= 0 && ret <= 4096) { return null; }
93                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
94                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
95                 return ret_hu_conv;
96         }
97
98         /**
99          * Utility method to constructs a new InvoicePayment-variant PaymentPurpose
100          */
101         public static PaymentPurpose invoice_payment(org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, byte[] payment_secret) {
102                 long ret = bindings.PaymentPurpose_invoice_payment(payment_preimage.ptr, InternalUtils.check_arr_len(payment_secret, 32));
103                 Reference.reachabilityFence(payment_preimage);
104                 Reference.reachabilityFence(payment_secret);
105                 if (ret >= 0 && ret <= 4096) { return null; }
106                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
107                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
108                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_preimage); };
109                 return ret_hu_conv;
110         }
111
112         /**
113          * Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
114          */
115         public static PaymentPurpose spontaneous_payment(byte[] a) {
116                 long ret = bindings.PaymentPurpose_spontaneous_payment(InternalUtils.check_arr_len(a, 32));
117                 Reference.reachabilityFence(a);
118                 if (ret >= 0 && ret <= 4096) { return null; }
119                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
120                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
121                 return ret_hu_conv;
122         }
123
124         /**
125          * Checks if two PaymentPurposes contain equal inner contents.
126          * This ignores pointers and is_owned flags and looks at the values in fields.
127          */
128         public boolean eq(org.ldk.structs.PaymentPurpose b) {
129                 boolean ret = bindings.PaymentPurpose_eq(this.ptr, b == null ? 0 : b.ptr);
130                 Reference.reachabilityFence(this);
131                 Reference.reachabilityFence(b);
132                 return ret;
133         }
134
135         @Override public boolean equals(Object o) {
136                 if (!(o instanceof PaymentPurpose)) return false;
137                 return this.eq((PaymentPurpose)o);
138         }
139         /**
140          * Returns the preimage for this payment, if it is known.
141          */
142         public Option_ThirtyTwoBytesZ preimage() {
143                 long ret = bindings.PaymentPurpose_preimage(this.ptr);
144                 Reference.reachabilityFence(this);
145                 if (ret >= 0 && ret <= 4096) { return null; }
146                 org.ldk.structs.Option_ThirtyTwoBytesZ ret_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(ret);
147                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
148                 return ret_hu_conv;
149         }
150
151         /**
152          * Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
153          */
154         public byte[] write() {
155                 byte[] ret = bindings.PaymentPurpose_write(this.ptr);
156                 Reference.reachabilityFence(this);
157                 return ret;
158         }
159
160         /**
161          * Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
162          */
163         public static Result_PaymentPurposeDecodeErrorZ read(byte[] ser) {
164                 long ret = bindings.PaymentPurpose_read(ser);
165                 Reference.reachabilityFence(ser);
166                 if (ret >= 0 && ret <= 4096) { return null; }
167                 Result_PaymentPurposeDecodeErrorZ ret_hu_conv = Result_PaymentPurposeDecodeErrorZ.constr_from_ptr(ret);
168                 return ret_hu_conv;
169         }
170
171 }