[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / RecipientOnionFields.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  * Information which is provided, encrypted, to the payment recipient when sending HTLCs.
11  * 
12  * This should generally be constructed with data communicated to us from the recipient (via a
13  * BOLT11 or BOLT12 invoice).
14  */
15 public class RecipientOnionFields : CommonBase {
16         internal RecipientOnionFields(object _dummy, long ptr) : base(ptr) { }
17         ~RecipientOnionFields() {
18                 if (ptr != 0) { bindings.RecipientOnionFields_free(ptr); }
19         }
20
21         /**
22          * The [`PaymentSecret`] is an arbitrary 32 bytes provided by the recipient for us to repeat
23          * in the onion. It is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to
24          * authenticate the sender to the recipient and prevent payment-probing (deanonymization)
25          * attacks.
26          * 
27          * If you do not have one, the [`Route`] you pay over must not contain multiple paths as
28          * multi-path payments require a recipient-provided secret.
29          * 
30          * Some implementations may reject spontaneous payments with payment secrets, so you may only
31          * want to provide a secret for a spontaneous payment if MPP is needed and you know your
32          * recipient will not reject it.
33          */
34         public Option_ThirtyTwoBytesZ get_payment_secret() {
35                 long ret = bindings.RecipientOnionFields_get_payment_secret(this.ptr);
36                 GC.KeepAlive(this);
37                 if (ret >= 0 && ret <= 4096) { return null; }
38                 org.ldk.structs.Option_ThirtyTwoBytesZ ret_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(ret);
39                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
40                 return ret_hu_conv;
41         }
42
43         /**
44          * The [`PaymentSecret`] is an arbitrary 32 bytes provided by the recipient for us to repeat
45          * in the onion. It is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to
46          * authenticate the sender to the recipient and prevent payment-probing (deanonymization)
47          * attacks.
48          * 
49          * If you do not have one, the [`Route`] you pay over must not contain multiple paths as
50          * multi-path payments require a recipient-provided secret.
51          * 
52          * Some implementations may reject spontaneous payments with payment secrets, so you may only
53          * want to provide a secret for a spontaneous payment if MPP is needed and you know your
54          * recipient will not reject it.
55          */
56         public void set_payment_secret(org.ldk.structs.Option_ThirtyTwoBytesZ val) {
57                 bindings.RecipientOnionFields_set_payment_secret(this.ptr, val.ptr);
58                 GC.KeepAlive(this);
59                 GC.KeepAlive(val);
60                 if (this != null) { this.ptrs_to.AddLast(val); };
61         }
62
63         /**
64          * The payment metadata serves a similar purpose as [`Self::payment_secret`] but is of
65          * arbitrary length. This gives recipients substantially more flexibility to receive
66          * additional data.
67          * 
68          * In LDK, while the [`Self::payment_secret`] is fixed based on an internal authentication
69          * scheme to authenticate received payments against expected payments and invoices, this field
70          * is not used in LDK for received payments, and can be used to store arbitrary data in
71          * invoices which will be received with the payment.
72          * 
73          * Note that this field was added to the lightning specification more recently than
74          * [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
75          * may not be supported as universally.
76          * 
77          * Returns a copy of the field.
78          */
79         public Option_CVec_u8ZZ get_payment_metadata() {
80                 long ret = bindings.RecipientOnionFields_get_payment_metadata(this.ptr);
81                 GC.KeepAlive(this);
82                 if (ret >= 0 && ret <= 4096) { return null; }
83                 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
84                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
85                 return ret_hu_conv;
86         }
87
88         /**
89          * The payment metadata serves a similar purpose as [`Self::payment_secret`] but is of
90          * arbitrary length. This gives recipients substantially more flexibility to receive
91          * additional data.
92          * 
93          * In LDK, while the [`Self::payment_secret`] is fixed based on an internal authentication
94          * scheme to authenticate received payments against expected payments and invoices, this field
95          * is not used in LDK for received payments, and can be used to store arbitrary data in
96          * invoices which will be received with the payment.
97          * 
98          * Note that this field was added to the lightning specification more recently than
99          * [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
100          * may not be supported as universally.
101          */
102         public void set_payment_metadata(org.ldk.structs.Option_CVec_u8ZZ val) {
103                 bindings.RecipientOnionFields_set_payment_metadata(this.ptr, val.ptr);
104                 GC.KeepAlive(this);
105                 GC.KeepAlive(val);
106                 if (this != null) { this.ptrs_to.AddLast(val); };
107         }
108
109         internal long clone_ptr() {
110                 long ret = bindings.RecipientOnionFields_clone_ptr(this.ptr);
111                 GC.KeepAlive(this);
112                 return ret;
113         }
114
115         /**
116          * Creates a copy of the RecipientOnionFields
117          */
118         public RecipientOnionFields clone() {
119                 long ret = bindings.RecipientOnionFields_clone(this.ptr);
120                 GC.KeepAlive(this);
121                 if (ret >= 0 && ret <= 4096) { return null; }
122                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
123                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
124                 return ret_hu_conv;
125         }
126
127         /**
128          * Checks if two RecipientOnionFieldss contain equal inner contents.
129          * This ignores pointers and is_owned flags and looks at the values in fields.
130          * Two objects with NULL inner values will be considered "equal" here.
131          */
132         public bool eq(org.ldk.structs.RecipientOnionFields b) {
133                 bool ret = bindings.RecipientOnionFields_eq(this.ptr, b == null ? 0 : b.ptr);
134                 GC.KeepAlive(this);
135                 GC.KeepAlive(b);
136                 if (this != null) { this.ptrs_to.AddLast(b); };
137                 return ret;
138         }
139
140         public override bool Equals(object o) {
141                 if (!(o is RecipientOnionFields)) return false;
142                 return this.eq((RecipientOnionFields)o);
143         }
144         /**
145          * Serialize the RecipientOnionFields object into a byte array which can be read by RecipientOnionFields_read
146          */
147         public byte[] write() {
148                 long ret = bindings.RecipientOnionFields_write(this.ptr);
149                 GC.KeepAlive(this);
150                 if (ret >= 0 && ret <= 4096) { return null; }
151                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
152                 return ret_conv;
153         }
154
155         /**
156          * Read a RecipientOnionFields from a byte array, created by RecipientOnionFields_write
157          */
158         public static Result_RecipientOnionFieldsDecodeErrorZ read(byte[] ser) {
159                 long ret = bindings.RecipientOnionFields_read(InternalUtils.encodeUint8Array(ser));
160                 GC.KeepAlive(ser);
161                 if (ret >= 0 && ret <= 4096) { return null; }
162                 Result_RecipientOnionFieldsDecodeErrorZ ret_hu_conv = Result_RecipientOnionFieldsDecodeErrorZ.constr_from_ptr(ret);
163                 return ret_hu_conv;
164         }
165
166         /**
167          * Creates a [`RecipientOnionFields`] from only a [`PaymentSecret`]. This is the most common
168          * set of onion fields for today's BOLT11 invoices - most nodes require a [`PaymentSecret`]
169          * but do not require or provide any further data.
170          */
171         public static RecipientOnionFields secret_only(byte[] payment_secret) {
172                 long ret = bindings.RecipientOnionFields_secret_only(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_secret, 32)));
173                 GC.KeepAlive(payment_secret);
174                 if (ret >= 0 && ret <= 4096) { return null; }
175                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
176                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
177                 return ret_hu_conv;
178         }
179
180         /**
181          * Creates a new [`RecipientOnionFields`] with no fields. This generally does not create
182          * payable HTLCs except for single-path spontaneous payments, i.e. this should generally
183          * only be used for calls to [`ChannelManager::send_spontaneous_payment`]. If you are sending
184          * a spontaneous MPP this will not work as all MPP require payment secrets; you may
185          * instead want to use [`RecipientOnionFields::secret_only`].
186          * 
187          * [`ChannelManager::send_spontaneous_payment`]: super::channelmanager::ChannelManager::send_spontaneous_payment
188          * [`RecipientOnionFields::secret_only`]: RecipientOnionFields::secret_only
189          */
190         public static RecipientOnionFields spontaneous_empty() {
191                 long ret = bindings.RecipientOnionFields_spontaneous_empty();
192                 if (ret >= 0 && ret <= 4096) { return null; }
193                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
194                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
195                 return ret_hu_conv;
196         }
197
198         /**
199          * Creates a new [`RecipientOnionFields`] from an existing one, adding custom TLVs. Each
200          * TLV is provided as a `(u64, Vec<u8>)` for the type number and serialized value
201          * respectively. TLV type numbers must be unique and within the range
202          * reserved for custom types, i.e. >= 2^16, otherwise this method will return `Err(())`.
203          * 
204          * This method will also error for types in the experimental range which have been
205          * standardized within the protocol, which only includes 5482373484 (keysend) for now.
206          * 
207          * See [`Self::custom_tlvs`] for more info.
208          */
209         public Result_RecipientOnionFieldsNoneZ with_custom_tlvs(TwoTuple_u64CVec_u8ZZ[] custom_tlvs) {
210                 long ret = bindings.RecipientOnionFields_with_custom_tlvs(this.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(custom_tlvs, custom_tlvs_conv_23 => custom_tlvs_conv_23 != null ? custom_tlvs_conv_23.ptr : 0)));
211                 GC.KeepAlive(this);
212                 GC.KeepAlive(custom_tlvs);
213                 if (ret >= 0 && ret <= 4096) { return null; }
214                 Result_RecipientOnionFieldsNoneZ ret_hu_conv = Result_RecipientOnionFieldsNoneZ.constr_from_ptr(ret);
215                 if (this != null) { this.ptrs_to.AddLast(this); };
216                 return ret_hu_conv;
217         }
218
219         /**
220          * Gets the custom TLVs that will be sent or have been received.
221          * 
222          * Custom TLVs allow sending extra application-specific data with a payment. They provide
223          * additional flexibility on top of payment metadata, as while other implementations may
224          * require `payment_metadata` to reflect metadata provided in an invoice, custom TLVs
225          * do not have this restriction.
226          * 
227          * Note that if this field is non-empty, it will contain strictly increasing TLVs, each
228          * represented by a `(u64, Vec<u8>)` for its type number and serialized value respectively.
229          * This is validated when setting this field using [`Self::with_custom_tlvs`].
230          */
231         public TwoTuple_u64CVec_u8ZZ[] custom_tlvs() {
232                 long ret = bindings.RecipientOnionFields_custom_tlvs(this.ptr);
233                 GC.KeepAlive(this);
234                 if (ret >= 0 && ret <= 4096) { return null; }
235                 int ret_conv_23_len = InternalUtils.getArrayLength(ret);
236                 TwoTuple_u64CVec_u8ZZ[] ret_conv_23_arr = new TwoTuple_u64CVec_u8ZZ[ret_conv_23_len];
237                 for (int x = 0; x < ret_conv_23_len; x++) {
238                         long ret_conv_23 = InternalUtils.getU64ArrayElem(ret, x);
239                         TwoTuple_u64CVec_u8ZZ ret_conv_23_hu_conv = new TwoTuple_u64CVec_u8ZZ(null, ret_conv_23);
240                         if (ret_conv_23_hu_conv != null) { ret_conv_23_hu_conv.ptrs_to.AddLast(this); };
241                         ret_conv_23_arr[x] = ret_conv_23_hu_conv;
242                 }
243                 bindings.free_buffer(ret);
244                 return ret_conv_23_arr;
245         }
246
247 }
248 } } }