Merge pull request #139 from TheBlueMatt/main
[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_InvoicePayment(ptr);
22                         case 1: return new PaymentPurpose_SpontaneousPayment(ptr);
23                         default:
24                                 throw new ArgumentException("Impossible enum variant");
25                 }
26         }
27
28         /** A PaymentPurpose of type InvoicePayment */
29         public class PaymentPurpose_InvoicePayment : PaymentPurpose {
30                 /**
31                  * The preimage to the payment_hash, if the payment hash (and secret) were fetched via
32                  * [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
33                  * [`ChannelManager::claim_funds`].
34                  * 
35                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
36                  * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
37                  */
38                 public Option_PaymentPreimageZ payment_preimage;
39                 /**
40                  * The \"payment secret\". This authenticates the sender to the recipient, preventing a
41                  * number of deanonymization attacks during the routing process.
42                  * It is provided here for your reference, however its accuracy is enforced directly by
43                  * [`ChannelManager`] using the values you previously provided to
44                  * [`ChannelManager::create_inbound_payment`] or
45                  * [`ChannelManager::create_inbound_payment_for_hash`].
46                  * 
47                  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
48                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
49                  * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
50                  */
51                 public byte[] payment_secret;
52                 internal PaymentPurpose_InvoicePayment(long ptr) : base(null, ptr) {
53                         long payment_preimage = bindings.LDKPaymentPurpose_InvoicePayment_get_payment_preimage(ptr);
54                         org.ldk.structs.Option_PaymentPreimageZ payment_preimage_hu_conv = org.ldk.structs.Option_PaymentPreimageZ.constr_from_ptr(payment_preimage);
55                         if (payment_preimage_hu_conv != null) { payment_preimage_hu_conv.ptrs_to.AddLast(this); };
56                         this.payment_preimage = payment_preimage_hu_conv;
57                         this.payment_secret = bindings.LDKPaymentPurpose_InvoicePayment_get_payment_secret(ptr);
58                 }
59         }
60         /** A PaymentPurpose of type SpontaneousPayment */
61         public class PaymentPurpose_SpontaneousPayment : PaymentPurpose {
62                 public byte[] spontaneous_payment;
63                 internal PaymentPurpose_SpontaneousPayment(long ptr) : base(null, ptr) {
64                         this.spontaneous_payment = bindings.LDKPaymentPurpose_SpontaneousPayment_get_spontaneous_payment(ptr);
65                 }
66         }
67         internal long clone_ptr() {
68                 long ret = bindings.PaymentPurpose_clone_ptr(this.ptr);
69                 GC.KeepAlive(this);
70                 return ret;
71         }
72
73         /**
74          * Creates a copy of the PaymentPurpose
75          */
76         public PaymentPurpose clone() {
77                 long ret = bindings.PaymentPurpose_clone(this.ptr);
78                 GC.KeepAlive(this);
79                 if (ret >= 0 && ret <= 4096) { return null; }
80                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
81                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
82                 return ret_hu_conv;
83         }
84
85         /**
86          * Utility method to constructs a new InvoicePayment-variant PaymentPurpose
87          */
88         public static PaymentPurpose invoice_payment(org.ldk.structs.Option_PaymentPreimageZ payment_preimage, byte[] payment_secret) {
89                 long ret = bindings.PaymentPurpose_invoice_payment(payment_preimage.ptr, InternalUtils.check_arr_len(payment_secret, 32));
90                 GC.KeepAlive(payment_preimage);
91                 GC.KeepAlive(payment_secret);
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.AddLast(ret_hu_conv); };
95                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_preimage); };
96                 return ret_hu_conv;
97         }
98
99         /**
100          * Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
101          */
102         public static PaymentPurpose spontaneous_payment(byte[] a) {
103                 long ret = bindings.PaymentPurpose_spontaneous_payment(InternalUtils.check_arr_len(a, 32));
104                 GC.KeepAlive(a);
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.AddLast(ret_hu_conv); };
108                 return ret_hu_conv;
109         }
110
111         /**
112          * Checks if two PaymentPurposes contain equal inner contents.
113          * This ignores pointers and is_owned flags and looks at the values in fields.
114          */
115         public bool eq(org.ldk.structs.PaymentPurpose b) {
116                 bool ret = bindings.PaymentPurpose_eq(this.ptr, b == null ? 0 : b.ptr);
117                 GC.KeepAlive(this);
118                 GC.KeepAlive(b);
119                 return ret;
120         }
121
122         public override bool Equals(object o) {
123                 if (!(o is PaymentPurpose)) return false;
124                 return this.eq((PaymentPurpose)o);
125         }
126         /**
127          * Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
128          */
129         public byte[] write() {
130                 byte[] ret = bindings.PaymentPurpose_write(this.ptr);
131                 GC.KeepAlive(this);
132                 return ret;
133         }
134
135         /**
136          * Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
137          */
138         public static Result_PaymentPurposeDecodeErrorZ read(byte[] ser) {
139                 long ret = bindings.PaymentPurpose_read(ser);
140                 GC.KeepAlive(ser);
141                 if (ret >= 0 && ret <= 4096) { return null; }
142                 Result_PaymentPurposeDecodeErrorZ ret_hu_conv = Result_PaymentPurposeDecodeErrorZ.constr_from_ptr(ret);
143                 return ret_hu_conv;
144         }
145
146 }
147 } } }