bf8752be035e91feac49503605fcc956174db880
[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                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
39                  */
40                 public byte[] payment_preimage;
41                 /**
42                  * The \"payment secret\". This authenticates the sender to the recipient, preventing a
43                  * number of deanonymization attacks during the routing process.
44                  * It is provided here for your reference, however its accuracy is enforced directly by
45                  * [`ChannelManager`] using the values you previously provided to
46                  * [`ChannelManager::create_inbound_payment`] or
47                  * [`ChannelManager::create_inbound_payment_for_hash`].
48                  * 
49                  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
50                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
51                  * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
52                  */
53                 public byte[] payment_secret;
54                 internal PaymentPurpose_InvoicePayment(long ptr) : base(null, ptr) {
55                         this.payment_preimage = bindings.LDKPaymentPurpose_InvoicePayment_get_payment_preimage(ptr);
56                         this.payment_secret = bindings.LDKPaymentPurpose_InvoicePayment_get_payment_secret(ptr);
57                 }
58         }
59         /** A PaymentPurpose of type SpontaneousPayment */
60         public class PaymentPurpose_SpontaneousPayment : PaymentPurpose {
61                 public byte[] spontaneous_payment;
62                 internal PaymentPurpose_SpontaneousPayment(long ptr) : base(null, ptr) {
63                         this.spontaneous_payment = bindings.LDKPaymentPurpose_SpontaneousPayment_get_spontaneous_payment(ptr);
64                 }
65         }
66         internal long clone_ptr() {
67                 long ret = bindings.PaymentPurpose_clone_ptr(this.ptr);
68                 GC.KeepAlive(this);
69                 return ret;
70         }
71
72         /**
73          * Creates a copy of the PaymentPurpose
74          */
75         public PaymentPurpose clone() {
76                 long ret = bindings.PaymentPurpose_clone(this.ptr);
77                 GC.KeepAlive(this);
78                 if (ret >= 0 && ret <= 4096) { return null; }
79                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
80                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
81                 return ret_hu_conv;
82         }
83
84         /**
85          * Utility method to constructs a new InvoicePayment-variant PaymentPurpose
86          */
87         public static PaymentPurpose invoice_payment(byte[] payment_preimage, byte[] payment_secret) {
88                 long ret = bindings.PaymentPurpose_invoice_payment(InternalUtils.check_arr_len(payment_preimage, 32), InternalUtils.check_arr_len(payment_secret, 32));
89                 GC.KeepAlive(payment_preimage);
90                 GC.KeepAlive(payment_secret);
91                 if (ret >= 0 && ret <= 4096) { return null; }
92                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
93                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
94                 return ret_hu_conv;
95         }
96
97         /**
98          * Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
99          */
100         public static PaymentPurpose spontaneous_payment(byte[] a) {
101                 long ret = bindings.PaymentPurpose_spontaneous_payment(InternalUtils.check_arr_len(a, 32));
102                 GC.KeepAlive(a);
103                 if (ret >= 0 && ret <= 4096) { return null; }
104                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
105                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
106                 return ret_hu_conv;
107         }
108
109         /**
110          * Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
111          */
112         public byte[] write() {
113                 byte[] ret = bindings.PaymentPurpose_write(this.ptr);
114                 GC.KeepAlive(this);
115                 return ret;
116         }
117
118         /**
119          * Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
120          */
121         public static Result_PaymentPurposeDecodeErrorZ read(byte[] ser) {
122                 long ret = bindings.PaymentPurpose_read(ser);
123                 GC.KeepAlive(ser);
124                 if (ret >= 0 && ret <= 4096) { return null; }
125                 Result_PaymentPurposeDecodeErrorZ ret_hu_conv = Result_PaymentPurposeDecodeErrorZ.constr_from_ptr(ret);
126                 return ret_hu_conv;
127         }
128
129 }
130 } } }