8a196a29baf0138d05c52f2dc03c030cb2947f0b
[ldk-java] / c_sharp / src / org / ldk / structs / PaymentError.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  * An error that may occur when making a payment.
10  */
11 public class PaymentError : CommonBase {
12         protected PaymentError(object _dummy, long ptr) : base(ptr) { }
13         ~PaymentError() {
14                 if (ptr != 0) { bindings.PaymentError_free(ptr); }
15         }
16
17         internal static PaymentError constr_from_ptr(long ptr) {
18                 long raw_ty = bindings.LDKPaymentError_ty_from_ptr(ptr);
19                 switch (raw_ty) {
20                         case 0: return new PaymentError_Invoice(ptr);
21                         case 1: return new PaymentError_Routing(ptr);
22                         case 2: return new PaymentError_Sending(ptr);
23                         default:
24                                 throw new ArgumentException("Impossible enum variant");
25                 }
26         }
27
28         /** A PaymentError of type Invoice */
29         public class PaymentError_Invoice : PaymentError {
30                 public string invoice;
31                 internal PaymentError_Invoice(long ptr) : base(null, ptr) {
32                         this.invoice = bindings.LDKPaymentError_Invoice_get_invoice(ptr);
33                 }
34         }
35         /** A PaymentError of type Routing */
36         public class PaymentError_Routing : PaymentError {
37                 public LightningError routing;
38                 internal PaymentError_Routing(long ptr) : base(null, ptr) {
39                         long routing = bindings.LDKPaymentError_Routing_get_routing(ptr);
40                         org.ldk.structs.LightningError routing_hu_conv = null; if (routing < 0 || routing > 4096) { routing_hu_conv = new org.ldk.structs.LightningError(null, routing); }
41                         if (routing_hu_conv != null) { routing_hu_conv.ptrs_to.AddLast(this); };
42                         this.routing = routing_hu_conv;
43                 }
44         }
45         /** A PaymentError of type Sending */
46         public class PaymentError_Sending : PaymentError {
47                 public PaymentSendFailure sending;
48                 internal PaymentError_Sending(long ptr) : base(null, ptr) {
49                         long sending = bindings.LDKPaymentError_Sending_get_sending(ptr);
50                         org.ldk.structs.PaymentSendFailure sending_hu_conv = org.ldk.structs.PaymentSendFailure.constr_from_ptr(sending);
51                         if (sending_hu_conv != null) { sending_hu_conv.ptrs_to.AddLast(this); };
52                         this.sending = sending_hu_conv;
53                 }
54         }
55         internal long clone_ptr() {
56                 long ret = bindings.PaymentError_clone_ptr(this.ptr);
57                 GC.KeepAlive(this);
58                 return ret;
59         }
60
61         /**
62          * Creates a copy of the PaymentError
63          */
64         public PaymentError clone() {
65                 long ret = bindings.PaymentError_clone(this.ptr);
66                 GC.KeepAlive(this);
67                 if (ret >= 0 && ret <= 4096) { return null; }
68                 org.ldk.structs.PaymentError ret_hu_conv = org.ldk.structs.PaymentError.constr_from_ptr(ret);
69                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
70                 return ret_hu_conv;
71         }
72
73         /**
74          * Utility method to constructs a new Invoice-variant PaymentError
75          */
76         public static PaymentError invoice(string a) {
77                 long ret = bindings.PaymentError_invoice(a);
78                 GC.KeepAlive(a);
79                 if (ret >= 0 && ret <= 4096) { return null; }
80                 org.ldk.structs.PaymentError ret_hu_conv = org.ldk.structs.PaymentError.constr_from_ptr(ret);
81                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
82                 return ret_hu_conv;
83         }
84
85         /**
86          * Utility method to constructs a new Routing-variant PaymentError
87          */
88         public static PaymentError routing(org.ldk.structs.LightningError a) {
89                 long ret = bindings.PaymentError_routing(a == null ? 0 : a.ptr);
90                 GC.KeepAlive(a);
91                 if (ret >= 0 && ret <= 4096) { return null; }
92                 org.ldk.structs.PaymentError ret_hu_conv = org.ldk.structs.PaymentError.constr_from_ptr(ret);
93                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
94                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(a); };
95                 return ret_hu_conv;
96         }
97
98         /**
99          * Utility method to constructs a new Sending-variant PaymentError
100          */
101         public static PaymentError sending(org.ldk.structs.PaymentSendFailure a) {
102                 long ret = bindings.PaymentError_sending(a.ptr);
103                 GC.KeepAlive(a);
104                 if (ret >= 0 && ret <= 4096) { return null; }
105                 org.ldk.structs.PaymentError ret_hu_conv = org.ldk.structs.PaymentError.constr_from_ptr(ret);
106                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
107                 return ret_hu_conv;
108         }
109
110 }
111 } } }