[C#] Run tests against release library in determinism CI run
[ldk-java] / c_sharp / src / org / ldk / structs / PaymentPurpose.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  * Some information provided on receipt of payment depends on whether the payment received is a
10  * spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
11  */
12 public class PaymentPurpose : CommonBase {
13         protected PaymentPurpose(object _dummy, long ptr) : base(ptr) { }
14         ~PaymentPurpose() {
15                 if (ptr != 0) { bindings.PaymentPurpose_free(ptr); }
16         }
17
18         internal static PaymentPurpose constr_from_ptr(long ptr) {
19                 long raw_ty = bindings.LDKPaymentPurpose_ty_from_ptr(ptr);
20                 switch (raw_ty) {
21                         case 0: return new PaymentPurpose_Bolt11InvoicePayment(ptr);
22                         case 1: return new PaymentPurpose_Bolt12OfferPayment(ptr);
23                         case 2: return new PaymentPurpose_Bolt12RefundPayment(ptr);
24                         case 3: return new PaymentPurpose_SpontaneousPayment(ptr);
25                         default:
26                                 throw new ArgumentException("Impossible enum variant");
27                 }
28         }
29
30         /** A PaymentPurpose of type Bolt11InvoicePayment */
31         public class PaymentPurpose_Bolt11InvoicePayment : PaymentPurpose {
32                 /**
33                  * The preimage to the payment_hash, if the payment hash (and secret) were fetched via
34                  * [`ChannelManager::create_inbound_payment`]. When handling [`Event::PaymentClaimable`],
35                  * this can be passed directly to [`ChannelManager::claim_funds`] to claim the payment. No
36                  * action is needed when seen in [`Event::PaymentClaimed`].
37                  * 
38                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
39                  * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
40                  */
41                 public Option_ThirtyTwoBytesZ payment_preimage;
42                 /**
43                  * The \"payment secret\". This authenticates the sender to the recipient, preventing a
44                  * number of deanonymization attacks during the routing process.
45                  * It is provided here for your reference, however its accuracy is enforced directly by
46                  * [`ChannelManager`] using the values you previously provided to
47                  * [`ChannelManager::create_inbound_payment`] or
48                  * [`ChannelManager::create_inbound_payment_for_hash`].
49                  * 
50                  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
51                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
52                  * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
53                  */
54                 public byte[] payment_secret;
55                 internal PaymentPurpose_Bolt11InvoicePayment(long ptr) : base(null, ptr) {
56                         long payment_preimage = bindings.LDKPaymentPurpose_Bolt11InvoicePayment_get_payment_preimage(ptr);
57                         org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(payment_preimage);
58                         if (payment_preimage_hu_conv != null) { payment_preimage_hu_conv.ptrs_to.AddLast(this); };
59                         this.payment_preimage = payment_preimage_hu_conv;
60                         long payment_secret = bindings.LDKPaymentPurpose_Bolt11InvoicePayment_get_payment_secret(ptr);
61                         byte[] payment_secret_conv = InternalUtils.decodeUint8Array(payment_secret);
62                         this.payment_secret = payment_secret_conv;
63                 }
64         }
65         /** A PaymentPurpose of type Bolt12OfferPayment */
66         public class PaymentPurpose_Bolt12OfferPayment : PaymentPurpose {
67                 /**
68                  * The preimage to the payment hash. When handling [`Event::PaymentClaimable`], this can be
69                  * passed directly to [`ChannelManager::claim_funds`], if provided. No action is needed
70                  * when seen in [`Event::PaymentClaimed`].
71                  * 
72                  * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
73                  */
74                 public Option_ThirtyTwoBytesZ payment_preimage;
75                 /**
76                  * The secret used to authenticate the sender to the recipient, preventing a number of
77                  * de-anonymization attacks while routing a payment.
78                  * 
79                  * See [`PaymentPurpose::Bolt11InvoicePayment::payment_secret`] for further details.
80                  */
81                 public byte[] payment_secret;
82                 /**
83                  * The context of the payment such as information about the corresponding [`Offer`] and
84                  * [`InvoiceRequest`].
85                  * 
86                  * [`Offer`]: crate::offers::offer::Offer
87                  * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
88                  */
89                 public Bolt12OfferContext payment_context;
90                 internal PaymentPurpose_Bolt12OfferPayment(long ptr) : base(null, ptr) {
91                         long payment_preimage = bindings.LDKPaymentPurpose_Bolt12OfferPayment_get_payment_preimage(ptr);
92                         org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(payment_preimage);
93                         if (payment_preimage_hu_conv != null) { payment_preimage_hu_conv.ptrs_to.AddLast(this); };
94                         this.payment_preimage = payment_preimage_hu_conv;
95                         long payment_secret = bindings.LDKPaymentPurpose_Bolt12OfferPayment_get_payment_secret(ptr);
96                         byte[] payment_secret_conv = InternalUtils.decodeUint8Array(payment_secret);
97                         this.payment_secret = payment_secret_conv;
98                         long payment_context = bindings.LDKPaymentPurpose_Bolt12OfferPayment_get_payment_context(ptr);
99                         org.ldk.structs.Bolt12OfferContext payment_context_hu_conv = null; if (payment_context < 0 || payment_context > 4096) { payment_context_hu_conv = new org.ldk.structs.Bolt12OfferContext(null, payment_context); }
100                         if (payment_context_hu_conv != null) { payment_context_hu_conv.ptrs_to.AddLast(this); };
101                         this.payment_context = payment_context_hu_conv;
102                 }
103         }
104         /** A PaymentPurpose of type Bolt12RefundPayment */
105         public class PaymentPurpose_Bolt12RefundPayment : PaymentPurpose {
106                 /**
107                  * The preimage to the payment hash. When handling [`Event::PaymentClaimable`], this can be
108                  * passed directly to [`ChannelManager::claim_funds`], if provided. No action is needed
109                  * when seen in [`Event::PaymentClaimed`].
110                  * 
111                  * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
112                  */
113                 public Option_ThirtyTwoBytesZ payment_preimage;
114                 /**
115                  * The secret used to authenticate the sender to the recipient, preventing a number of
116                  * de-anonymization attacks while routing a payment.
117                  * 
118                  * See [`PaymentPurpose::Bolt11InvoicePayment::payment_secret`] for further details.
119                  */
120                 public byte[] payment_secret;
121                 /**
122                  * The context of the payment such as information about the corresponding [`Refund`].
123                  * 
124                  * [`Refund`]: crate::offers::refund::Refund
125                  */
126                 public Bolt12RefundContext payment_context;
127                 internal PaymentPurpose_Bolt12RefundPayment(long ptr) : base(null, ptr) {
128                         long payment_preimage = bindings.LDKPaymentPurpose_Bolt12RefundPayment_get_payment_preimage(ptr);
129                         org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(payment_preimage);
130                         if (payment_preimage_hu_conv != null) { payment_preimage_hu_conv.ptrs_to.AddLast(this); };
131                         this.payment_preimage = payment_preimage_hu_conv;
132                         long payment_secret = bindings.LDKPaymentPurpose_Bolt12RefundPayment_get_payment_secret(ptr);
133                         byte[] payment_secret_conv = InternalUtils.decodeUint8Array(payment_secret);
134                         this.payment_secret = payment_secret_conv;
135                         long payment_context = bindings.LDKPaymentPurpose_Bolt12RefundPayment_get_payment_context(ptr);
136                         org.ldk.structs.Bolt12RefundContext payment_context_hu_conv = null; if (payment_context < 0 || payment_context > 4096) { payment_context_hu_conv = new org.ldk.structs.Bolt12RefundContext(null, payment_context); }
137                         if (payment_context_hu_conv != null) { payment_context_hu_conv.ptrs_to.AddLast(this); };
138                         this.payment_context = payment_context_hu_conv;
139                 }
140         }
141         /** A PaymentPurpose of type SpontaneousPayment */
142         public class PaymentPurpose_SpontaneousPayment : PaymentPurpose {
143                 public byte[] spontaneous_payment;
144                 internal PaymentPurpose_SpontaneousPayment(long ptr) : base(null, ptr) {
145                         long spontaneous_payment = bindings.LDKPaymentPurpose_SpontaneousPayment_get_spontaneous_payment(ptr);
146                         byte[] spontaneous_payment_conv = InternalUtils.decodeUint8Array(spontaneous_payment);
147                         this.spontaneous_payment = spontaneous_payment_conv;
148                 }
149         }
150         internal long clone_ptr() {
151                 long ret = bindings.PaymentPurpose_clone_ptr(this.ptr);
152                 GC.KeepAlive(this);
153                 return ret;
154         }
155
156         /**
157          * Creates a copy of the PaymentPurpose
158          */
159         public PaymentPurpose clone() {
160                 long ret = bindings.PaymentPurpose_clone(this.ptr);
161                 GC.KeepAlive(this);
162                 if (ret >= 0 && ret <= 4096) { return null; }
163                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
164                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
165                 return ret_hu_conv;
166         }
167
168         /**
169          * Utility method to constructs a new Bolt11InvoicePayment-variant PaymentPurpose
170          */
171         public static PaymentPurpose bolt11_invoice_payment(org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, byte[] payment_secret) {
172                 long ret = bindings.PaymentPurpose_bolt11_invoice_payment(payment_preimage.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_secret, 32)));
173                 GC.KeepAlive(payment_preimage);
174                 GC.KeepAlive(payment_secret);
175                 if (ret >= 0 && ret <= 4096) { return null; }
176                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
177                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
178                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_preimage); };
179                 return ret_hu_conv;
180         }
181
182         /**
183          * Utility method to constructs a new Bolt12OfferPayment-variant PaymentPurpose
184          */
185         public static PaymentPurpose bolt12_offer_payment(org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, byte[] payment_secret, org.ldk.structs.Bolt12OfferContext payment_context) {
186                 long ret = bindings.PaymentPurpose_bolt12_offer_payment(payment_preimage.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_secret, 32)), payment_context.ptr);
187                 GC.KeepAlive(payment_preimage);
188                 GC.KeepAlive(payment_secret);
189                 GC.KeepAlive(payment_context);
190                 if (ret >= 0 && ret <= 4096) { return null; }
191                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
192                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
193                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_preimage); };
194                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_context); };
195                 return ret_hu_conv;
196         }
197
198         /**
199          * Utility method to constructs a new Bolt12RefundPayment-variant PaymentPurpose
200          */
201         public static PaymentPurpose bolt12_refund_payment(org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, byte[] payment_secret, org.ldk.structs.Bolt12RefundContext payment_context) {
202                 long ret = bindings.PaymentPurpose_bolt12_refund_payment(payment_preimage.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_secret, 32)), payment_context.ptr);
203                 GC.KeepAlive(payment_preimage);
204                 GC.KeepAlive(payment_secret);
205                 GC.KeepAlive(payment_context);
206                 if (ret >= 0 && ret <= 4096) { return null; }
207                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
208                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
209                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_preimage); };
210                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_context); };
211                 return ret_hu_conv;
212         }
213
214         /**
215          * Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
216          */
217         public static PaymentPurpose spontaneous_payment(byte[] a) {
218                 long ret = bindings.PaymentPurpose_spontaneous_payment(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(a, 32)));
219                 GC.KeepAlive(a);
220                 if (ret >= 0 && ret <= 4096) { return null; }
221                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
222                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
223                 return ret_hu_conv;
224         }
225
226         /**
227          * Checks if two PaymentPurposes contain equal inner contents.
228          * This ignores pointers and is_owned flags and looks at the values in fields.
229          */
230         public bool eq(org.ldk.structs.PaymentPurpose b) {
231                 bool ret = bindings.PaymentPurpose_eq(this.ptr, b.ptr);
232                 GC.KeepAlive(this);
233                 GC.KeepAlive(b);
234                 return ret;
235         }
236
237         public override bool Equals(object o) {
238                 if (!(o is PaymentPurpose)) return false;
239                 return this.eq((PaymentPurpose)o);
240         }
241         /**
242          * Returns the preimage for this payment, if it is known.
243          */
244         public Option_ThirtyTwoBytesZ preimage() {
245                 long ret = bindings.PaymentPurpose_preimage(this.ptr);
246                 GC.KeepAlive(this);
247                 if (ret >= 0 && ret <= 4096) { return null; }
248                 org.ldk.structs.Option_ThirtyTwoBytesZ ret_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(ret);
249                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
250                 return ret_hu_conv;
251         }
252
253         /**
254          * Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
255          */
256         public byte[] write() {
257                 long ret = bindings.PaymentPurpose_write(this.ptr);
258                 GC.KeepAlive(this);
259                 if (ret >= 0 && ret <= 4096) { return null; }
260                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
261                 return ret_conv;
262         }
263
264         /**
265          * Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
266          */
267         public static Result_PaymentPurposeDecodeErrorZ read(byte[] ser) {
268                 long ret = bindings.PaymentPurpose_read(InternalUtils.encodeUint8Array(ser));
269                 GC.KeepAlive(ser);
270                 if (ret >= 0 && ret <= 4096) { return null; }
271                 Result_PaymentPurposeDecodeErrorZ ret_hu_conv = Result_PaymentPurposeDecodeErrorZ.constr_from_ptr(ret);
272                 return ret_hu_conv;
273         }
274
275 }
276 } } }