567d9b657b7c45f5667c58f6aec386b2a4838a55
[ldk-java] / c_sharp / src / org / ldk / structs / PaymentSendFailure.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  * If a payment fails to send, it can be in one of several states. This enum is returned as the
10  * Err() type describing which state the payment is in, see the description of individual enum
11  * states for more.
12  */
13 public class PaymentSendFailure : CommonBase {
14         protected PaymentSendFailure(object _dummy, long ptr) : base(ptr) { }
15         ~PaymentSendFailure() {
16                 if (ptr != 0) { bindings.PaymentSendFailure_free(ptr); }
17         }
18
19         internal static PaymentSendFailure constr_from_ptr(long ptr) {
20                 long raw_ty = bindings.LDKPaymentSendFailure_ty_from_ptr(ptr);
21                 switch (raw_ty) {
22                         case 0: return new PaymentSendFailure_ParameterError(ptr);
23                         case 1: return new PaymentSendFailure_PathParameterError(ptr);
24                         case 2: return new PaymentSendFailure_AllFailedResendSafe(ptr);
25                         case 3: return new PaymentSendFailure_DuplicatePayment(ptr);
26                         case 4: return new PaymentSendFailure_PartialFailure(ptr);
27                         default:
28                                 throw new ArgumentException("Impossible enum variant");
29                 }
30         }
31
32         /** A PaymentSendFailure of type ParameterError */
33         public class PaymentSendFailure_ParameterError : PaymentSendFailure {
34                 public APIError parameter_error;
35                 internal PaymentSendFailure_ParameterError(long ptr) : base(null, ptr) {
36                         long parameter_error = bindings.LDKPaymentSendFailure_ParameterError_get_parameter_error(ptr);
37                         org.ldk.structs.APIError parameter_error_hu_conv = org.ldk.structs.APIError.constr_from_ptr(parameter_error);
38                         if (parameter_error_hu_conv != null) { parameter_error_hu_conv.ptrs_to.AddLast(this); };
39                         this.parameter_error = parameter_error_hu_conv;
40                 }
41         }
42         /** A PaymentSendFailure of type PathParameterError */
43         public class PaymentSendFailure_PathParameterError : PaymentSendFailure {
44                 public Result_NoneAPIErrorZ[] path_parameter_error;
45                 internal PaymentSendFailure_PathParameterError(long ptr) : base(null, ptr) {
46                         long[] path_parameter_error = bindings.LDKPaymentSendFailure_PathParameterError_get_path_parameter_error(ptr);
47                         int path_parameter_error_conv_22_len = path_parameter_error.Length;
48                         Result_NoneAPIErrorZ[] path_parameter_error_conv_22_arr = new Result_NoneAPIErrorZ[path_parameter_error_conv_22_len];
49                         for (int w = 0; w < path_parameter_error_conv_22_len; w++) {
50                                 long path_parameter_error_conv_22 = path_parameter_error[w];
51                                 Result_NoneAPIErrorZ path_parameter_error_conv_22_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(path_parameter_error_conv_22);
52                                 path_parameter_error_conv_22_arr[w] = path_parameter_error_conv_22_hu_conv;
53                         }
54                         this.path_parameter_error = path_parameter_error_conv_22_arr;
55                 }
56         }
57         /** A PaymentSendFailure of type AllFailedResendSafe */
58         public class PaymentSendFailure_AllFailedResendSafe : PaymentSendFailure {
59                 public APIError[] all_failed_resend_safe;
60                 internal PaymentSendFailure_AllFailedResendSafe(long ptr) : base(null, ptr) {
61                         long[] all_failed_resend_safe = bindings.LDKPaymentSendFailure_AllFailedResendSafe_get_all_failed_resend_safe(ptr);
62                         int all_failed_resend_safe_conv_10_len = all_failed_resend_safe.Length;
63                         APIError[] all_failed_resend_safe_conv_10_arr = new APIError[all_failed_resend_safe_conv_10_len];
64                         for (int k = 0; k < all_failed_resend_safe_conv_10_len; k++) {
65                                 long all_failed_resend_safe_conv_10 = all_failed_resend_safe[k];
66                                 org.ldk.structs.APIError all_failed_resend_safe_conv_10_hu_conv = org.ldk.structs.APIError.constr_from_ptr(all_failed_resend_safe_conv_10);
67                                 if (all_failed_resend_safe_conv_10_hu_conv != null) { all_failed_resend_safe_conv_10_hu_conv.ptrs_to.AddLast(this); };
68                                 all_failed_resend_safe_conv_10_arr[k] = all_failed_resend_safe_conv_10_hu_conv;
69                         }
70                         this.all_failed_resend_safe = all_failed_resend_safe_conv_10_arr;
71                 }
72         }
73         /** A PaymentSendFailure of type DuplicatePayment */
74         public class PaymentSendFailure_DuplicatePayment : PaymentSendFailure {
75                 internal PaymentSendFailure_DuplicatePayment(long ptr) : base(null, ptr) {
76                 }
77         }
78         /** A PaymentSendFailure of type PartialFailure */
79         public class PaymentSendFailure_PartialFailure : PaymentSendFailure {
80                 /**
81                  * The errors themselves, in the same order as the route hops.
82                  */
83                 public Result_NoneAPIErrorZ[] results;
84                 /**
85                  * If some paths failed without irrevocably committing to the new HTLC(s), this will
86                  * contain a [`RouteParameters`] object which can be used to calculate a new route that
87                  * will pay all remaining unpaid balance.
88                  * 
89                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
90                  */
91                 public RouteParameters failed_paths_retry;
92                 /**
93                  * The payment id for the payment, which is now at least partially pending.
94                  */
95                 public byte[] payment_id;
96                 internal PaymentSendFailure_PartialFailure(long ptr) : base(null, ptr) {
97                         long[] results = bindings.LDKPaymentSendFailure_PartialFailure_get_results(ptr);
98                         int results_conv_22_len = results.Length;
99                         Result_NoneAPIErrorZ[] results_conv_22_arr = new Result_NoneAPIErrorZ[results_conv_22_len];
100                         for (int w = 0; w < results_conv_22_len; w++) {
101                                 long results_conv_22 = results[w];
102                                 Result_NoneAPIErrorZ results_conv_22_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(results_conv_22);
103                                 results_conv_22_arr[w] = results_conv_22_hu_conv;
104                         }
105                         this.results = results_conv_22_arr;
106                         long failed_paths_retry = bindings.LDKPaymentSendFailure_PartialFailure_get_failed_paths_retry(ptr);
107                         org.ldk.structs.RouteParameters failed_paths_retry_hu_conv = null; if (failed_paths_retry < 0 || failed_paths_retry > 4096) { failed_paths_retry_hu_conv = new org.ldk.structs.RouteParameters(null, failed_paths_retry); }
108                         if (failed_paths_retry_hu_conv != null) { failed_paths_retry_hu_conv.ptrs_to.AddLast(this); };
109                         this.failed_paths_retry = failed_paths_retry_hu_conv;
110                         this.payment_id = bindings.LDKPaymentSendFailure_PartialFailure_get_payment_id(ptr);
111                 }
112         }
113         internal long clone_ptr() {
114                 long ret = bindings.PaymentSendFailure_clone_ptr(this.ptr);
115                 GC.KeepAlive(this);
116                 return ret;
117         }
118
119         /**
120          * Creates a copy of the PaymentSendFailure
121          */
122         public PaymentSendFailure clone() {
123                 long ret = bindings.PaymentSendFailure_clone(this.ptr);
124                 GC.KeepAlive(this);
125                 if (ret >= 0 && ret <= 4096) { return null; }
126                 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
127                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
128                 return ret_hu_conv;
129         }
130
131         /**
132          * Utility method to constructs a new ParameterError-variant PaymentSendFailure
133          */
134         public static PaymentSendFailure parameter_error(org.ldk.structs.APIError a) {
135                 long ret = bindings.PaymentSendFailure_parameter_error(a.ptr);
136                 GC.KeepAlive(a);
137                 if (ret >= 0 && ret <= 4096) { return null; }
138                 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
139                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
140                 return ret_hu_conv;
141         }
142
143         /**
144          * Utility method to constructs a new PathParameterError-variant PaymentSendFailure
145          */
146         public static PaymentSendFailure path_parameter_error(Result_NoneAPIErrorZ[] a) {
147                 long ret = bindings.PaymentSendFailure_path_parameter_error(a != null ? InternalUtils.mapArray(a, a_conv_22 => a_conv_22 != null ? a_conv_22.ptr : 0) : null);
148                 GC.KeepAlive(a);
149                 if (ret >= 0 && ret <= 4096) { return null; }
150                 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
151                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
152                 return ret_hu_conv;
153         }
154
155         /**
156          * Utility method to constructs a new AllFailedResendSafe-variant PaymentSendFailure
157          */
158         public static PaymentSendFailure all_failed_resend_safe(APIError[] a) {
159                 long ret = bindings.PaymentSendFailure_all_failed_resend_safe(a != null ? InternalUtils.mapArray(a, a_conv_10 => a_conv_10.ptr) : null);
160                 GC.KeepAlive(a);
161                 if (ret >= 0 && ret <= 4096) { return null; }
162                 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
163                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
164                 return ret_hu_conv;
165         }
166
167         /**
168          * Utility method to constructs a new DuplicatePayment-variant PaymentSendFailure
169          */
170         public static PaymentSendFailure duplicate_payment() {
171                 long ret = bindings.PaymentSendFailure_duplicate_payment();
172                 if (ret >= 0 && ret <= 4096) { return null; }
173                 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
174                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
175                 return ret_hu_conv;
176         }
177
178         /**
179          * Utility method to constructs a new PartialFailure-variant PaymentSendFailure
180          */
181         public static PaymentSendFailure partial_failure(Result_NoneAPIErrorZ[] results, org.ldk.structs.RouteParameters failed_paths_retry, byte[] payment_id) {
182                 long ret = bindings.PaymentSendFailure_partial_failure(results != null ? InternalUtils.mapArray(results, results_conv_22 => results_conv_22 != null ? results_conv_22.ptr : 0) : null, failed_paths_retry == null ? 0 : failed_paths_retry.ptr, InternalUtils.check_arr_len(payment_id, 32));
183                 GC.KeepAlive(results);
184                 GC.KeepAlive(failed_paths_retry);
185                 GC.KeepAlive(payment_id);
186                 if (ret >= 0 && ret <= 4096) { return null; }
187                 org.ldk.structs.PaymentSendFailure ret_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(ret);
188                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
189                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(failed_paths_retry); };
190                 return ret_hu_conv;
191         }
192
193 }
194 } } }