1e0597a51ea12e0aefe9cb0a10d92f471ce82afc
[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_Sending(ptr);
22                         default:
23                                 throw new ArgumentException("Impossible enum variant");
24                 }
25         }
26
27         /** A PaymentError of type Invoice */
28         public class PaymentError_Invoice : PaymentError {
29                 public string invoice;
30                 internal PaymentError_Invoice(long ptr) : base(null, ptr) {
31                         this.invoice = bindings.LDKPaymentError_Invoice_get_invoice(ptr);
32                 }
33         }
34         /** A PaymentError of type Sending */
35         public class PaymentError_Sending : PaymentError {
36                 public RetryableSendFailure sending;
37                 internal PaymentError_Sending(long ptr) : base(null, ptr) {
38                         this.sending = bindings.LDKPaymentError_Sending_get_sending(ptr);
39                 }
40         }
41         internal long clone_ptr() {
42                 long ret = bindings.PaymentError_clone_ptr(this.ptr);
43                 GC.KeepAlive(this);
44                 return ret;
45         }
46
47         /**
48          * Creates a copy of the PaymentError
49          */
50         public PaymentError clone() {
51                 long ret = bindings.PaymentError_clone(this.ptr);
52                 GC.KeepAlive(this);
53                 if (ret >= 0 && ret <= 4096) { return null; }
54                 org.ldk.structs.PaymentError ret_hu_conv = org.ldk.structs.PaymentError.constr_from_ptr(ret);
55                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
56                 return ret_hu_conv;
57         }
58
59         /**
60          * Utility method to constructs a new Invoice-variant PaymentError
61          */
62         public static PaymentError invoice(string a) {
63                 long ret = bindings.PaymentError_invoice(a);
64                 GC.KeepAlive(a);
65                 if (ret >= 0 && ret <= 4096) { return null; }
66                 org.ldk.structs.PaymentError ret_hu_conv = org.ldk.structs.PaymentError.constr_from_ptr(ret);
67                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
68                 return ret_hu_conv;
69         }
70
71         /**
72          * Utility method to constructs a new Sending-variant PaymentError
73          */
74         public static PaymentError sending(RetryableSendFailure a) {
75                 long ret = bindings.PaymentError_sending(a);
76                 GC.KeepAlive(a);
77                 if (ret >= 0 && ret <= 4096) { return null; }
78                 org.ldk.structs.PaymentError ret_hu_conv = org.ldk.structs.PaymentError.constr_from_ptr(ret);
79                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
80                 return ret_hu_conv;
81         }
82
83         /**
84          * Checks if two PaymentErrors contain equal inner contents.
85          * This ignores pointers and is_owned flags and looks at the values in fields.
86          */
87         public bool eq(org.ldk.structs.PaymentError b) {
88                 bool ret = bindings.PaymentError_eq(this.ptr, b == null ? 0 : b.ptr);
89                 GC.KeepAlive(this);
90                 GC.KeepAlive(b);
91                 return ret;
92         }
93
94         public override bool Equals(object o) {
95                 if (!(o is PaymentError)) return false;
96                 return this.eq((PaymentError)o);
97         }
98 }
99 } } }