[Java] Update auto-generated Java bindings for 0.0.116
[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          * Returns whether the given chain is supported by the offer.
66          */
67         public boolean supports_chain(byte[] chain) {
68                 boolean ret = bindings.Offer_supports_chain(this.ptr, InternalUtils.check_arr_len(chain, 32));
69                 Reference.reachabilityFence(this);
70                 Reference.reachabilityFence(chain);
71                 return ret;
72         }
73
74         /**
75          * Opaque bytes set by the originator. Useful for authentication and validating fields since it
76          * is reflected in `invoice_request` messages along with all the other fields from the `offer`.
77          */
78         public Option_CVec_u8ZZ metadata() {
79                 long ret = bindings.Offer_metadata(this.ptr);
80                 Reference.reachabilityFence(this);
81                 if (ret >= 0 && ret <= 4096) { return null; }
82                 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
83                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
84                 return ret_hu_conv;
85         }
86
87         /**
88          * The minimum amount required for a successful payment of a single item.
89          * 
90          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
91          */
92         @Nullable
93         public Amount amount() {
94                 long ret = bindings.Offer_amount(this.ptr);
95                 Reference.reachabilityFence(this);
96                 if (ret >= 0 && ret <= 4096) { return null; }
97                 org.ldk.structs.Amount ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Amount(null, ret); }
98                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
99                 return ret_hu_conv;
100         }
101
102         /**
103          * A complete description of the purpose of the payment. Intended to be displayed to the user
104          * but with the caveat that it has not been verified in any way.
105          */
106         public PrintableString description() {
107                 long ret = bindings.Offer_description(this.ptr);
108                 Reference.reachabilityFence(this);
109                 if (ret >= 0 && ret <= 4096) { return null; }
110                 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
111                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
112                 return ret_hu_conv;
113         }
114
115         /**
116          * Features pertaining to the offer.
117          */
118         public OfferFeatures features() {
119                 long ret = bindings.Offer_features(this.ptr);
120                 Reference.reachabilityFence(this);
121                 if (ret >= 0 && ret <= 4096) { return null; }
122                 org.ldk.structs.OfferFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OfferFeatures(null, ret); }
123                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
124                 return ret_hu_conv;
125         }
126
127         /**
128          * Duration since the Unix epoch when an invoice should no longer be requested.
129          * 
130          * If `None`, the offer does not expire.
131          */
132         public Option_DurationZ absolute_expiry() {
133                 long ret = bindings.Offer_absolute_expiry(this.ptr);
134                 Reference.reachabilityFence(this);
135                 if (ret >= 0 && ret <= 4096) { return null; }
136                 org.ldk.structs.Option_DurationZ ret_hu_conv = org.ldk.structs.Option_DurationZ.constr_from_ptr(ret);
137                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
138                 return ret_hu_conv;
139         }
140
141         /**
142          * Whether the offer has expired.
143          */
144         public boolean is_expired() {
145                 boolean ret = bindings.Offer_is_expired(this.ptr);
146                 Reference.reachabilityFence(this);
147                 return ret;
148         }
149
150         /**
151          * The issuer of the offer, possibly beginning with `user@domain` or `domain`. Intended to be
152          * displayed to the user but with the caveat that it has not been verified in any way.
153          * 
154          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
155          */
156         @Nullable
157         public PrintableString issuer() {
158                 long ret = bindings.Offer_issuer(this.ptr);
159                 Reference.reachabilityFence(this);
160                 if (ret >= 0 && ret <= 4096) { return null; }
161                 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
162                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
163                 return ret_hu_conv;
164         }
165
166         /**
167          * Paths to the recipient originating from publicly reachable nodes. Blinded paths provide
168          * recipient privacy by obfuscating its node id.
169          */
170         public BlindedPath[] paths() {
171                 long[] ret = bindings.Offer_paths(this.ptr);
172                 Reference.reachabilityFence(this);
173                 int ret_conv_13_len = ret.length;
174                 BlindedPath[] ret_conv_13_arr = new BlindedPath[ret_conv_13_len];
175                 for (int n = 0; n < ret_conv_13_len; n++) {
176                         long ret_conv_13 = ret[n];
177                         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); }
178                         if (ret_conv_13_hu_conv != null) { ret_conv_13_hu_conv.ptrs_to.add(this); };
179                         ret_conv_13_arr[n] = ret_conv_13_hu_conv;
180                 }
181                 return ret_conv_13_arr;
182         }
183
184         /**
185          * The quantity of items supported.
186          */
187         public Quantity supported_quantity() {
188                 long ret = bindings.Offer_supported_quantity(this.ptr);
189                 Reference.reachabilityFence(this);
190                 if (ret >= 0 && ret <= 4096) { return null; }
191                 org.ldk.structs.Quantity ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Quantity(null, ret); }
192                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
193                 return ret_hu_conv;
194         }
195
196         /**
197          * Returns whether the given quantity is valid for the offer.
198          */
199         public boolean is_valid_quantity(long quantity) {
200                 boolean ret = bindings.Offer_is_valid_quantity(this.ptr, quantity);
201                 Reference.reachabilityFence(this);
202                 Reference.reachabilityFence(quantity);
203                 return ret;
204         }
205
206         /**
207          * Returns whether a quantity is expected in an [`InvoiceRequest`] for the offer.
208          * 
209          * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
210          */
211         public boolean expects_quantity() {
212                 boolean ret = bindings.Offer_expects_quantity(this.ptr);
213                 Reference.reachabilityFence(this);
214                 return ret;
215         }
216
217         /**
218          * The public key used by the recipient to sign invoices.
219          */
220         public byte[] signing_pubkey() {
221                 byte[] ret = bindings.Offer_signing_pubkey(this.ptr);
222                 Reference.reachabilityFence(this);
223                 return ret;
224         }
225
226         /**
227          * Serialize the Offer object into a byte array which can be read by Offer_read
228          */
229         public byte[] write() {
230                 byte[] ret = bindings.Offer_write(this.ptr);
231                 Reference.reachabilityFence(this);
232                 return ret;
233         }
234
235         /**
236          * Read a Offer object from a string
237          */
238         public static Result_OfferBolt12ParseErrorZ from_str(java.lang.String s) {
239                 long ret = bindings.Offer_from_str(s);
240                 Reference.reachabilityFence(s);
241                 if (ret >= 0 && ret <= 4096) { return null; }
242                 Result_OfferBolt12ParseErrorZ ret_hu_conv = Result_OfferBolt12ParseErrorZ.constr_from_ptr(ret);
243                 return ret_hu_conv;
244         }
245
246 }