[Java] Update auto-generated Java bindings to LDK 0.0.121
[ldk-java] / src / main / java / org / ldk / structs / Offer.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  * An `Offer` is a potentially long-lived proposal for payment of a good or service.
13  * 
14  * An offer is a precursor to an [`InvoiceRequest`]. A merchant publishes an offer from which a
15  * customer may request an [`Bolt12Invoice`] for a specific quantity and using an amount sufficient
16  * to cover that quantity (i.e., at least `quantity * amount`). See [`Offer::amount`].
17  * 
18  * Offers may be denominated in currency other than bitcoin but are ultimately paid using the
19  * latter.
20  * 
21  * Through the use of [`BlindedPath`]s, offers provide recipient privacy.
22  * 
23  * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
24  * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
25  */
26 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
27 public class Offer extends CommonBase {
28         Offer(Object _dummy, long ptr) { super(ptr); }
29         @Override @SuppressWarnings("deprecation")
30         protected void finalize() throws Throwable {
31                 super.finalize();
32                 if (ptr != 0) { bindings.Offer_free(ptr); }
33         }
34
35         long clone_ptr() {
36                 long ret = bindings.Offer_clone_ptr(this.ptr);
37                 Reference.reachabilityFence(this);
38                 return ret;
39         }
40
41         /**
42          * Creates a copy of the Offer
43          */
44         public Offer clone() {
45                 long ret = bindings.Offer_clone(this.ptr);
46                 Reference.reachabilityFence(this);
47                 if (ret >= 0 && ret <= 4096) { return null; }
48                 org.ldk.structs.Offer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Offer(null, ret); }
49                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
50                 return ret_hu_conv;
51         }
52
53         /**
54          * The chains that may be used when paying a requested invoice (e.g., bitcoin mainnet).
55          * Payments must be denominated in units of the minimal lightning-payable unit (e.g., msats)
56          * for the selected chain.
57          */
58         public byte[][] chains() {
59                 byte[][] ret = bindings.Offer_chains(this.ptr);
60                 Reference.reachabilityFence(this);
61                 return ret;
62         }
63
64         /**
65          * Opaque bytes set by the originator. Useful for authentication and validating fields since it
66          * is reflected in `invoice_request` messages along with all the other fields from the `offer`.
67          */
68         public Option_CVec_u8ZZ metadata() {
69                 long ret = bindings.Offer_metadata(this.ptr);
70                 Reference.reachabilityFence(this);
71                 if (ret >= 0 && ret <= 4096) { return null; }
72                 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
73                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
74                 return ret_hu_conv;
75         }
76
77         /**
78          * The minimum amount required for a successful payment of a single item.
79          * 
80          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
81          */
82         @Nullable
83         public Amount amount() {
84                 long ret = bindings.Offer_amount(this.ptr);
85                 Reference.reachabilityFence(this);
86                 if (ret >= 0 && ret <= 4096) { return null; }
87                 org.ldk.structs.Amount ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Amount(null, ret); }
88                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
89                 return ret_hu_conv;
90         }
91
92         /**
93          * A complete description of the purpose of the payment. Intended to be displayed to the user
94          * but with the caveat that it has not been verified in any way.
95          */
96         public PrintableString description() {
97                 long ret = bindings.Offer_description(this.ptr);
98                 Reference.reachabilityFence(this);
99                 if (ret >= 0 && ret <= 4096) { return null; }
100                 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
101                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
102                 return ret_hu_conv;
103         }
104
105         /**
106          * Features pertaining to the offer.
107          */
108         public OfferFeatures offer_features() {
109                 long ret = bindings.Offer_offer_features(this.ptr);
110                 Reference.reachabilityFence(this);
111                 if (ret >= 0 && ret <= 4096) { return null; }
112                 org.ldk.structs.OfferFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OfferFeatures(null, ret); }
113                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
114                 return ret_hu_conv;
115         }
116
117         /**
118          * Duration since the Unix epoch when an invoice should no longer be requested.
119          * 
120          * If `None`, the offer does not expire.
121          */
122         public Option_u64Z absolute_expiry() {
123                 long ret = bindings.Offer_absolute_expiry(this.ptr);
124                 Reference.reachabilityFence(this);
125                 if (ret >= 0 && ret <= 4096) { return null; }
126                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
127                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
128                 return ret_hu_conv;
129         }
130
131         /**
132          * The issuer of the offer, possibly beginning with `user@domain` or `domain`. Intended to be
133          * displayed to the user but with the caveat that it has not been verified in any way.
134          * 
135          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
136          */
137         @Nullable
138         public PrintableString issuer() {
139                 long ret = bindings.Offer_issuer(this.ptr);
140                 Reference.reachabilityFence(this);
141                 if (ret >= 0 && ret <= 4096) { return null; }
142                 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
143                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
144                 return ret_hu_conv;
145         }
146
147         /**
148          * Paths to the recipient originating from publicly reachable nodes. Blinded paths provide
149          * recipient privacy by obfuscating its node id.
150          */
151         public BlindedPath[] paths() {
152                 long[] ret = bindings.Offer_paths(this.ptr);
153                 Reference.reachabilityFence(this);
154                 int ret_conv_13_len = ret.length;
155                 BlindedPath[] ret_conv_13_arr = new BlindedPath[ret_conv_13_len];
156                 for (int n = 0; n < ret_conv_13_len; n++) {
157                         long ret_conv_13 = ret[n];
158                         org.ldk.structs.BlindedPath ret_conv_13_hu_conv = null; if (ret_conv_13 < 0 || ret_conv_13 > 4096) { ret_conv_13_hu_conv = new org.ldk.structs.BlindedPath(null, ret_conv_13); }
159                         if (ret_conv_13_hu_conv != null) { ret_conv_13_hu_conv.ptrs_to.add(this); };
160                         ret_conv_13_arr[n] = ret_conv_13_hu_conv;
161                 }
162                 return ret_conv_13_arr;
163         }
164
165         /**
166          * The quantity of items supported.
167          */
168         public Quantity supported_quantity() {
169                 long ret = bindings.Offer_supported_quantity(this.ptr);
170                 Reference.reachabilityFence(this);
171                 if (ret >= 0 && ret <= 4096) { return null; }
172                 org.ldk.structs.Quantity ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Quantity(null, ret); }
173                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
174                 return ret_hu_conv;
175         }
176
177         /**
178          * The public key used by the recipient to sign invoices.
179          */
180         public byte[] signing_pubkey() {
181                 byte[] ret = bindings.Offer_signing_pubkey(this.ptr);
182                 Reference.reachabilityFence(this);
183                 return ret;
184         }
185
186         /**
187          * Returns whether the given chain is supported by the offer.
188          */
189         public boolean supports_chain(byte[] chain) {
190                 boolean ret = bindings.Offer_supports_chain(this.ptr, InternalUtils.check_arr_len(chain, 32));
191                 Reference.reachabilityFence(this);
192                 Reference.reachabilityFence(chain);
193                 return ret;
194         }
195
196         /**
197          * Whether the offer has expired.
198          */
199         public boolean is_expired() {
200                 boolean ret = bindings.Offer_is_expired(this.ptr);
201                 Reference.reachabilityFence(this);
202                 return ret;
203         }
204
205         /**
206          * Whether the offer has expired given the duration since the Unix epoch.
207          */
208         public boolean is_expired_no_std(long duration_since_epoch) {
209                 boolean ret = bindings.Offer_is_expired_no_std(this.ptr, duration_since_epoch);
210                 Reference.reachabilityFence(this);
211                 Reference.reachabilityFence(duration_since_epoch);
212                 return ret;
213         }
214
215         /**
216          * Returns whether the given quantity is valid for the offer.
217          */
218         public boolean is_valid_quantity(long quantity) {
219                 boolean ret = bindings.Offer_is_valid_quantity(this.ptr, quantity);
220                 Reference.reachabilityFence(this);
221                 Reference.reachabilityFence(quantity);
222                 return ret;
223         }
224
225         /**
226          * Returns whether a quantity is expected in an [`InvoiceRequest`] for the offer.
227          * 
228          * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
229          */
230         public boolean expects_quantity() {
231                 boolean ret = bindings.Offer_expects_quantity(this.ptr);
232                 Reference.reachabilityFence(this);
233                 return ret;
234         }
235
236         /**
237          * Serialize the Offer object into a byte array which can be read by Offer_read
238          */
239         public byte[] write() {
240                 byte[] ret = bindings.Offer_write(this.ptr);
241                 Reference.reachabilityFence(this);
242                 return ret;
243         }
244
245         /**
246          * Read a Offer object from a string
247          */
248         public static Result_OfferBolt12ParseErrorZ from_str(java.lang.String s) {
249                 long ret = bindings.Offer_from_str(s);
250                 Reference.reachabilityFence(s);
251                 if (ret >= 0 && ret <= 4096) { return null; }
252                 Result_OfferBolt12ParseErrorZ ret_hu_conv = Result_OfferBolt12ParseErrorZ.constr_from_ptr(ret);
253                 return ret_hu_conv;
254         }
255
256 }