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