6 namespace org { namespace ldk { namespace structs {
9 * The context of an inbound payment, which is included in a [`BlindedPath`] via [`ReceiveTlvs`]
10 * and surfaced in [`PaymentPurpose`].
12 * [`BlindedPath`]: crate::blinded_path::BlindedPath
13 * [`PaymentPurpose`]: crate::events::PaymentPurpose
15 public class PaymentContext : CommonBase {
16 protected PaymentContext(object _dummy, long ptr) : base(ptr) { }
18 if (ptr != 0) { bindings.PaymentContext_free(ptr); }
21 internal static PaymentContext constr_from_ptr(long ptr) {
22 long raw_ty = bindings.LDKPaymentContext_ty_from_ptr(ptr);
24 case 0: return new PaymentContext_Unknown(ptr);
25 case 1: return new PaymentContext_Bolt12Offer(ptr);
26 case 2: return new PaymentContext_Bolt12Refund(ptr);
28 throw new ArgumentException("Impossible enum variant");
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;
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;
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;
62 internal long clone_ptr() {
63 long ret = bindings.PaymentContext_clone_ptr(this.ptr);
69 * Creates a copy of the PaymentContext
71 public PaymentContext clone() {
72 long ret = bindings.PaymentContext_clone(this.ptr);
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); };
81 * Utility method to constructs a new Unknown-variant PaymentContext
83 public static PaymentContext unknown(org.ldk.structs.UnknownPaymentContext a) {
84 long ret = bindings.PaymentContext_unknown(a.ptr);
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); };
94 * Utility method to constructs a new Bolt12Offer-variant PaymentContext
96 public static PaymentContext bolt12_offer(org.ldk.structs.Bolt12OfferContext a) {
97 long ret = bindings.PaymentContext_bolt12_offer(a.ptr);
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); };
107 * Utility method to constructs a new Bolt12Refund-variant PaymentContext
109 public static PaymentContext bolt12_refund(org.ldk.structs.Bolt12RefundContext a) {
110 long ret = bindings.PaymentContext_bolt12_refund(a.ptr);
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); };
120 * Checks if two PaymentContexts contain equal inner contents.
121 * This ignores pointers and is_owned flags and looks at the values in fields.
123 public bool eq(org.ldk.structs.PaymentContext b) {
124 bool ret = bindings.PaymentContext_eq(this.ptr, b.ptr);
130 public override bool Equals(object o) {
131 if (!(o is PaymentContext)) return false;
132 return this.eq((PaymentContext)o);
135 * Serialize the PaymentContext object into a byte array which can be read by PaymentContext_read
137 public byte[] write() {
138 long ret = bindings.PaymentContext_write(this.ptr);
140 if (ret >= 0 && ret <= 4096) { return null; }
141 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
146 * Read a PaymentContext from a byte array, created by PaymentContext_write
148 public static Result_PaymentContextDecodeErrorZ read(byte[] ser) {
149 long ret = bindings.PaymentContext_read(InternalUtils.encodeUint8Array(ser));
151 if (ret >= 0 && ret <= 4096) { return null; }
152 Result_PaymentContextDecodeErrorZ ret_hu_conv = Result_PaymentContextDecodeErrorZ.constr_from_ptr(ret);