[TS] Update auto-generated bindings to LDK-C-Bindings 0.0.123.1
[ldk-java] / c_sharp / src / org / ldk / structs / PaymentContext.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  * The context of an inbound payment, which is included in a [`BlindedPath`] via [`ReceiveTlvs`]
10  * and surfaced in [`PaymentPurpose`].
11  * 
12  * [`BlindedPath`]: crate::blinded_path::BlindedPath
13  * [`PaymentPurpose`]: crate::events::PaymentPurpose
14  */
15 public class PaymentContext : CommonBase {
16         protected PaymentContext(object _dummy, long ptr) : base(ptr) { }
17         ~PaymentContext() {
18                 if (ptr != 0) { bindings.PaymentContext_free(ptr); }
19         }
20
21         internal static PaymentContext constr_from_ptr(long ptr) {
22                 long raw_ty = bindings.LDKPaymentContext_ty_from_ptr(ptr);
23                 switch (raw_ty) {
24                         case 0: return new PaymentContext_Unknown(ptr);
25                         case 1: return new PaymentContext_Bolt12Offer(ptr);
26                         case 2: return new PaymentContext_Bolt12Refund(ptr);
27                         default:
28                                 throw new ArgumentException("Impossible enum variant");
29                 }
30         }
31
32         /** A PaymentContext of type Unknown */
33         public class PaymentContext_Unknown : PaymentContext {
34                 public UnknownPaymentContext unknown;
35                 internal PaymentContext_Unknown(long ptr) : base(null, ptr) {
36                         long unknown = bindings.LDKPaymentContext_Unknown_get_unknown(ptr);
37                         org.ldk.structs.UnknownPaymentContext unknown_hu_conv = null; if (unknown < 0 || unknown > 4096) { unknown_hu_conv = new org.ldk.structs.UnknownPaymentContext(null, unknown); }
38                         if (unknown_hu_conv != null) { unknown_hu_conv.ptrs_to.AddLast(this); };
39                         this.unknown = unknown_hu_conv;
40                 }
41         }
42         /** A PaymentContext of type Bolt12Offer */
43         public class PaymentContext_Bolt12Offer : PaymentContext {
44                 public Bolt12OfferContext bolt12_offer;
45                 internal PaymentContext_Bolt12Offer(long ptr) : base(null, ptr) {
46                         long bolt12_offer = bindings.LDKPaymentContext_Bolt12Offer_get_bolt12_offer(ptr);
47                         org.ldk.structs.Bolt12OfferContext bolt12_offer_hu_conv = null; if (bolt12_offer < 0 || bolt12_offer > 4096) { bolt12_offer_hu_conv = new org.ldk.structs.Bolt12OfferContext(null, bolt12_offer); }
48                         if (bolt12_offer_hu_conv != null) { bolt12_offer_hu_conv.ptrs_to.AddLast(this); };
49                         this.bolt12_offer = bolt12_offer_hu_conv;
50                 }
51         }
52         /** A PaymentContext of type Bolt12Refund */
53         public class PaymentContext_Bolt12Refund : PaymentContext {
54                 public Bolt12RefundContext bolt12_refund;
55                 internal PaymentContext_Bolt12Refund(long ptr) : base(null, ptr) {
56                         long bolt12_refund = bindings.LDKPaymentContext_Bolt12Refund_get_bolt12_refund(ptr);
57                         org.ldk.structs.Bolt12RefundContext bolt12_refund_hu_conv = null; if (bolt12_refund < 0 || bolt12_refund > 4096) { bolt12_refund_hu_conv = new org.ldk.structs.Bolt12RefundContext(null, bolt12_refund); }
58                         if (bolt12_refund_hu_conv != null) { bolt12_refund_hu_conv.ptrs_to.AddLast(this); };
59                         this.bolt12_refund = bolt12_refund_hu_conv;
60                 }
61         }
62         internal long clone_ptr() {
63                 long ret = bindings.PaymentContext_clone_ptr(this.ptr);
64                 GC.KeepAlive(this);
65                 return ret;
66         }
67
68         /**
69          * Creates a copy of the PaymentContext
70          */
71         public PaymentContext clone() {
72                 long ret = bindings.PaymentContext_clone(this.ptr);
73                 GC.KeepAlive(this);
74                 if (ret >= 0 && ret <= 4096) { return null; }
75                 org.ldk.structs.PaymentContext ret_hu_conv = org.ldk.structs.PaymentContext.constr_from_ptr(ret);
76                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
77                 return ret_hu_conv;
78         }
79
80         /**
81          * Utility method to constructs a new Unknown-variant PaymentContext
82          */
83         public static PaymentContext unknown(org.ldk.structs.UnknownPaymentContext a) {
84                 long ret = bindings.PaymentContext_unknown(a.ptr);
85                 GC.KeepAlive(a);
86                 if (ret >= 0 && ret <= 4096) { return null; }
87                 org.ldk.structs.PaymentContext ret_hu_conv = org.ldk.structs.PaymentContext.constr_from_ptr(ret);
88                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
89                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(a); };
90                 return ret_hu_conv;
91         }
92
93         /**
94          * Utility method to constructs a new Bolt12Offer-variant PaymentContext
95          */
96         public static PaymentContext bolt12_offer(org.ldk.structs.Bolt12OfferContext a) {
97                 long ret = bindings.PaymentContext_bolt12_offer(a.ptr);
98                 GC.KeepAlive(a);
99                 if (ret >= 0 && ret <= 4096) { return null; }
100                 org.ldk.structs.PaymentContext ret_hu_conv = org.ldk.structs.PaymentContext.constr_from_ptr(ret);
101                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
102                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(a); };
103                 return ret_hu_conv;
104         }
105
106         /**
107          * Utility method to constructs a new Bolt12Refund-variant PaymentContext
108          */
109         public static PaymentContext bolt12_refund(org.ldk.structs.Bolt12RefundContext a) {
110                 long ret = bindings.PaymentContext_bolt12_refund(a.ptr);
111                 GC.KeepAlive(a);
112                 if (ret >= 0 && ret <= 4096) { return null; }
113                 org.ldk.structs.PaymentContext ret_hu_conv = org.ldk.structs.PaymentContext.constr_from_ptr(ret);
114                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
115                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(a); };
116                 return ret_hu_conv;
117         }
118
119         /**
120          * Checks if two PaymentContexts contain equal inner contents.
121          * This ignores pointers and is_owned flags and looks at the values in fields.
122          */
123         public bool eq(org.ldk.structs.PaymentContext b) {
124                 bool ret = bindings.PaymentContext_eq(this.ptr, b.ptr);
125                 GC.KeepAlive(this);
126                 GC.KeepAlive(b);
127                 return ret;
128         }
129
130         public override bool Equals(object o) {
131                 if (!(o is PaymentContext)) return false;
132                 return this.eq((PaymentContext)o);
133         }
134         /**
135          * Serialize the PaymentContext object into a byte array which can be read by PaymentContext_read
136          */
137         public byte[] write() {
138                 long ret = bindings.PaymentContext_write(this.ptr);
139                 GC.KeepAlive(this);
140                 if (ret >= 0 && ret <= 4096) { return null; }
141                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
142                 return ret_conv;
143         }
144
145         /**
146          * Read a PaymentContext from a byte array, created by PaymentContext_write
147          */
148         public static Result_PaymentContextDecodeErrorZ read(byte[] ser) {
149                 long ret = bindings.PaymentContext_read(InternalUtils.encodeUint8Array(ser));
150                 GC.KeepAlive(ser);
151                 if (ret >= 0 && ret <= 4096) { return null; }
152                 Result_PaymentContextDecodeErrorZ ret_hu_conv = Result_PaymentContextDecodeErrorZ.constr_from_ptr(ret);
153                 return ret_hu_conv;
154         }
155
156 }
157 } } }