4ac140d34609451965eb06734f329207ce51ea98
[ldk-java] / c_sharp / src / org / ldk / structs / PaymentParameters.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 used to route a payment.
11  */
12 public class PaymentParameters : CommonBase {
13         internal PaymentParameters(object _dummy, long ptr) : base(ptr) { }
14         ~PaymentParameters() {
15                 if (ptr != 0) { bindings.PaymentParameters_free(ptr); }
16         }
17
18         /**
19          * Information about the payee, such as their features and route hints for their channels.
20          */
21         public Payee get_payee() {
22                 long ret = bindings.PaymentParameters_get_payee(this.ptr);
23                 GC.KeepAlive(this);
24                 if (ret >= 0 && ret <= 4096) { return null; }
25                 org.ldk.structs.Payee ret_hu_conv = org.ldk.structs.Payee.constr_from_ptr(ret);
26                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
27                 return ret_hu_conv;
28         }
29
30         /**
31          * Information about the payee, such as their features and route hints for their channels.
32          */
33         public void set_payee(org.ldk.structs.Payee val) {
34                 bindings.PaymentParameters_set_payee(this.ptr, val.ptr);
35                 GC.KeepAlive(this);
36                 GC.KeepAlive(val);
37                 if (this != null) { this.ptrs_to.AddLast(val); };
38         }
39
40         /**
41          * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
42          */
43         public Option_u64Z get_expiry_time() {
44                 long ret = bindings.PaymentParameters_get_expiry_time(this.ptr);
45                 GC.KeepAlive(this);
46                 if (ret >= 0 && ret <= 4096) { return null; }
47                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
48                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
49                 return ret_hu_conv;
50         }
51
52         /**
53          * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
54          */
55         public void set_expiry_time(org.ldk.structs.Option_u64Z val) {
56                 bindings.PaymentParameters_set_expiry_time(this.ptr, val.ptr);
57                 GC.KeepAlive(this);
58                 GC.KeepAlive(val);
59                 if (this != null) { this.ptrs_to.AddLast(val); };
60         }
61
62         /**
63          * The maximum total CLTV delta we accept for the route.
64          * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
65          */
66         public int get_max_total_cltv_expiry_delta() {
67                 int ret = bindings.PaymentParameters_get_max_total_cltv_expiry_delta(this.ptr);
68                 GC.KeepAlive(this);
69                 return ret;
70         }
71
72         /**
73          * The maximum total CLTV delta we accept for the route.
74          * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
75          */
76         public void set_max_total_cltv_expiry_delta(int val) {
77                 bindings.PaymentParameters_set_max_total_cltv_expiry_delta(this.ptr, val);
78                 GC.KeepAlive(this);
79                 GC.KeepAlive(val);
80         }
81
82         /**
83          * The maximum number of paths that may be used by (MPP) payments.
84          * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
85          */
86         public byte get_max_path_count() {
87                 byte ret = bindings.PaymentParameters_get_max_path_count(this.ptr);
88                 GC.KeepAlive(this);
89                 return ret;
90         }
91
92         /**
93          * The maximum number of paths that may be used by (MPP) payments.
94          * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
95          */
96         public void set_max_path_count(byte val) {
97                 bindings.PaymentParameters_set_max_path_count(this.ptr, val);
98                 GC.KeepAlive(this);
99                 GC.KeepAlive(val);
100         }
101
102         /**
103          * Selects the maximum share of a channel's total capacity which will be sent over a channel,
104          * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
105          * a lower value prefers to send larger MPP parts, potentially saturating channels and
106          * increasing failure probability for those paths.
107          * 
108          * Note that this restriction will be relaxed during pathfinding after paths which meet this
109          * restriction have been found. While paths which meet this criteria will be searched for, it
110          * is ultimately up to the scorer to select them over other paths.
111          * 
112          * A value of 0 will allow payments up to and including a channel's total announced usable
113          * capacity, a value of one will only use up to half its capacity, two 1/4, etc.
114          * 
115          * Default value: 2
116          */
117         public byte get_max_channel_saturation_power_of_half() {
118                 byte ret = bindings.PaymentParameters_get_max_channel_saturation_power_of_half(this.ptr);
119                 GC.KeepAlive(this);
120                 return ret;
121         }
122
123         /**
124          * Selects the maximum share of a channel's total capacity which will be sent over a channel,
125          * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
126          * a lower value prefers to send larger MPP parts, potentially saturating channels and
127          * increasing failure probability for those paths.
128          * 
129          * Note that this restriction will be relaxed during pathfinding after paths which meet this
130          * restriction have been found. While paths which meet this criteria will be searched for, it
131          * is ultimately up to the scorer to select them over other paths.
132          * 
133          * A value of 0 will allow payments up to and including a channel's total announced usable
134          * capacity, a value of one will only use up to half its capacity, two 1/4, etc.
135          * 
136          * Default value: 2
137          */
138         public void set_max_channel_saturation_power_of_half(byte val) {
139                 bindings.PaymentParameters_set_max_channel_saturation_power_of_half(this.ptr, val);
140                 GC.KeepAlive(this);
141                 GC.KeepAlive(val);
142         }
143
144         /**
145          * A list of SCIDs which this payment was previously attempted over and which caused the
146          * payment to fail. Future attempts for the same payment shouldn't be relayed through any of
147          * these SCIDs.
148          * 
149          * Returns a copy of the field.
150          */
151         public long[] get_previously_failed_channels() {
152                 long ret = bindings.PaymentParameters_get_previously_failed_channels(this.ptr);
153                 GC.KeepAlive(this);
154                 if (ret >= 0 && ret <= 4096) { return null; }
155                 long[] ret_conv = InternalUtils.decodeUint64Array(ret);
156                 return ret_conv;
157         }
158
159         /**
160          * A list of SCIDs which this payment was previously attempted over and which caused the
161          * payment to fail. Future attempts for the same payment shouldn't be relayed through any of
162          * these SCIDs.
163          */
164         public void set_previously_failed_channels(long[] val) {
165                 bindings.PaymentParameters_set_previously_failed_channels(this.ptr, InternalUtils.encodeUint64Array(val));
166                 GC.KeepAlive(this);
167                 GC.KeepAlive(val);
168         }
169
170         /**
171          * Constructs a new PaymentParameters given each field
172          */
173         public static PaymentParameters of(org.ldk.structs.Payee payee_arg, org.ldk.structs.Option_u64Z expiry_time_arg, int max_total_cltv_expiry_delta_arg, byte max_path_count_arg, byte max_channel_saturation_power_of_half_arg, long[] previously_failed_channels_arg) {
174                 long ret = bindings.PaymentParameters_new(payee_arg.ptr, expiry_time_arg.ptr, max_total_cltv_expiry_delta_arg, max_path_count_arg, max_channel_saturation_power_of_half_arg, InternalUtils.encodeUint64Array(previously_failed_channels_arg));
175                 GC.KeepAlive(payee_arg);
176                 GC.KeepAlive(expiry_time_arg);
177                 GC.KeepAlive(max_total_cltv_expiry_delta_arg);
178                 GC.KeepAlive(max_path_count_arg);
179                 GC.KeepAlive(max_channel_saturation_power_of_half_arg);
180                 GC.KeepAlive(previously_failed_channels_arg);
181                 if (ret >= 0 && ret <= 4096) { return null; }
182                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
183                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
184                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payee_arg); };
185                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(expiry_time_arg); };
186                 return ret_hu_conv;
187         }
188
189         internal long clone_ptr() {
190                 long ret = bindings.PaymentParameters_clone_ptr(this.ptr);
191                 GC.KeepAlive(this);
192                 return ret;
193         }
194
195         /**
196          * Creates a copy of the PaymentParameters
197          */
198         public PaymentParameters clone() {
199                 long ret = bindings.PaymentParameters_clone(this.ptr);
200                 GC.KeepAlive(this);
201                 if (ret >= 0 && ret <= 4096) { return null; }
202                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
203                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
204                 return ret_hu_conv;
205         }
206
207         /**
208          * Generates a non-cryptographic 64-bit hash of the PaymentParameters.
209          */
210         public long hash() {
211                 long ret = bindings.PaymentParameters_hash(this.ptr);
212                 GC.KeepAlive(this);
213                 return ret;
214         }
215
216         public override int GetHashCode() {
217                 return (int)this.hash();
218         }
219         /**
220          * Checks if two PaymentParameterss contain equal inner contents.
221          * This ignores pointers and is_owned flags and looks at the values in fields.
222          * Two objects with NULL inner values will be considered "equal" here.
223          */
224         public bool eq(org.ldk.structs.PaymentParameters b) {
225                 bool ret = bindings.PaymentParameters_eq(this.ptr, b == null ? 0 : b.ptr);
226                 GC.KeepAlive(this);
227                 GC.KeepAlive(b);
228                 if (this != null) { this.ptrs_to.AddLast(b); };
229                 return ret;
230         }
231
232         public override bool Equals(object o) {
233                 if (!(o is PaymentParameters)) return false;
234                 return this.eq((PaymentParameters)o);
235         }
236         /**
237          * Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
238          */
239         public byte[] write() {
240                 long ret = bindings.PaymentParameters_write(this.ptr);
241                 GC.KeepAlive(this);
242                 if (ret >= 0 && ret <= 4096) { return null; }
243                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
244                 return ret_conv;
245         }
246
247         /**
248          * Read a PaymentParameters from a byte array, created by PaymentParameters_write
249          */
250         public static Result_PaymentParametersDecodeErrorZ read(byte[] ser, int arg) {
251                 long ret = bindings.PaymentParameters_read(InternalUtils.encodeUint8Array(ser), arg);
252                 GC.KeepAlive(ser);
253                 GC.KeepAlive(arg);
254                 if (ret >= 0 && ret <= 4096) { return null; }
255                 Result_PaymentParametersDecodeErrorZ ret_hu_conv = Result_PaymentParametersDecodeErrorZ.constr_from_ptr(ret);
256                 return ret_hu_conv;
257         }
258
259         /**
260          * Creates a payee with the node id of the given `pubkey`.
261          * 
262          * The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
263          * provided.
264          */
265         public static PaymentParameters from_node_id(byte[] payee_pubkey, int final_cltv_expiry_delta) {
266                 long ret = bindings.PaymentParameters_from_node_id(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payee_pubkey, 33)), final_cltv_expiry_delta);
267                 GC.KeepAlive(payee_pubkey);
268                 GC.KeepAlive(final_cltv_expiry_delta);
269                 if (ret >= 0 && ret <= 4096) { return null; }
270                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
271                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
272                 return ret_hu_conv;
273         }
274
275         /**
276          * Creates a payee with the node id of the given `pubkey` to use for keysend payments.
277          * 
278          * The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
279          * provided.
280          * 
281          * Note that MPP keysend is not widely supported yet. The `allow_mpp` lets you choose
282          * whether your router will be allowed to find a multi-part route for this payment. If you
283          * set `allow_mpp` to true, you should ensure a payment secret is set on send, likely via
284          * [`RecipientOnionFields::secret_only`].
285          * 
286          * [`RecipientOnionFields::secret_only`]: crate::ln::channelmanager::RecipientOnionFields::secret_only
287          */
288         public static PaymentParameters for_keysend(byte[] payee_pubkey, int final_cltv_expiry_delta, bool allow_mpp) {
289                 long ret = bindings.PaymentParameters_for_keysend(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payee_pubkey, 33)), final_cltv_expiry_delta, allow_mpp);
290                 GC.KeepAlive(payee_pubkey);
291                 GC.KeepAlive(final_cltv_expiry_delta);
292                 GC.KeepAlive(allow_mpp);
293                 if (ret >= 0 && ret <= 4096) { return null; }
294                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
295                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
296                 return ret_hu_conv;
297         }
298
299         /**
300          * Creates parameters for paying to a blinded payee from the provided invoice. Sets
301          * [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and
302          * [`PaymentParameters::expiry_time`].
303          */
304         public static PaymentParameters from_bolt12_invoice(org.ldk.structs.Bolt12Invoice invoice) {
305                 long ret = bindings.PaymentParameters_from_bolt12_invoice(invoice == null ? 0 : invoice.ptr);
306                 GC.KeepAlive(invoice);
307                 if (ret >= 0 && ret <= 4096) { return null; }
308                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
309                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
310                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(invoice); };
311                 return ret_hu_conv;
312         }
313
314         /**
315          * Creates parameters for paying to a blinded payee from the provided blinded route hints.
316          */
317         public static PaymentParameters blinded(TwoTuple_BlindedPayInfoBlindedPathZ[] blinded_route_hints) {
318                 long ret = bindings.PaymentParameters_blinded(InternalUtils.encodeUint64Array(InternalUtils.mapArray(blinded_route_hints, blinded_route_hints_conv_37 => blinded_route_hints_conv_37 != null ? blinded_route_hints_conv_37.ptr : 0)));
319                 GC.KeepAlive(blinded_route_hints);
320                 if (ret >= 0 && ret <= 4096) { return null; }
321                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
322                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
323                 return ret_hu_conv;
324         }
325
326 }
327 } } }