1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * The context of an inbound payment, which is included in a [`BlindedPath`] via [`ReceiveTlvs`]
13 * and surfaced in [`PaymentPurpose`].
15 * [`BlindedPath`]: crate::blinded_path::BlindedPath
16 * [`PaymentPurpose`]: crate::events::PaymentPurpose
18 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class PaymentContext extends CommonBase {
20 private PaymentContext(Object _dummy, long ptr) { super(ptr); }
21 @Override @SuppressWarnings("deprecation")
22 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.PaymentContext_free(ptr); }
26 static PaymentContext constr_from_ptr(long ptr) {
27 bindings.LDKPaymentContext raw_val = bindings.LDKPaymentContext_ref_from_ptr(ptr);
28 if (raw_val.getClass() == bindings.LDKPaymentContext.Unknown.class) {
29 return new Unknown(ptr, (bindings.LDKPaymentContext.Unknown)raw_val);
31 if (raw_val.getClass() == bindings.LDKPaymentContext.Bolt12Offer.class) {
32 return new Bolt12Offer(ptr, (bindings.LDKPaymentContext.Bolt12Offer)raw_val);
34 if (raw_val.getClass() == bindings.LDKPaymentContext.Bolt12Refund.class) {
35 return new Bolt12Refund(ptr, (bindings.LDKPaymentContext.Bolt12Refund)raw_val);
37 assert false; return null; // Unreachable without extending the (internal) bindings interface
41 * The payment context was unknown.
43 public final static class Unknown extends PaymentContext {
44 public final org.ldk.structs.UnknownPaymentContext unknown;
45 private Unknown(long ptr, bindings.LDKPaymentContext.Unknown obj) {
47 long unknown = obj.unknown;
48 org.ldk.structs.UnknownPaymentContext unknown_hu_conv = null; if (unknown < 0 || unknown > 4096) { unknown_hu_conv = new org.ldk.structs.UnknownPaymentContext(null, unknown); }
49 if (unknown_hu_conv != null) { unknown_hu_conv.ptrs_to.add(this); };
50 this.unknown = unknown_hu_conv;
54 * The payment was made for an invoice requested from a BOLT 12 [`Offer`].
56 * [`Offer`]: crate::offers::offer::Offer
58 public final static class Bolt12Offer extends PaymentContext {
59 public final org.ldk.structs.Bolt12OfferContext bolt12_offer;
60 private Bolt12Offer(long ptr, bindings.LDKPaymentContext.Bolt12Offer obj) {
62 long bolt12_offer = obj.bolt12_offer;
63 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); }
64 if (bolt12_offer_hu_conv != null) { bolt12_offer_hu_conv.ptrs_to.add(this); };
65 this.bolt12_offer = bolt12_offer_hu_conv;
69 * The payment was made for an invoice sent for a BOLT 12 [`Refund`].
71 * [`Refund`]: crate::offers::refund::Refund
73 public final static class Bolt12Refund extends PaymentContext {
74 public final org.ldk.structs.Bolt12RefundContext bolt12_refund;
75 private Bolt12Refund(long ptr, bindings.LDKPaymentContext.Bolt12Refund obj) {
77 long bolt12_refund = obj.bolt12_refund;
78 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); }
79 if (bolt12_refund_hu_conv != null) { bolt12_refund_hu_conv.ptrs_to.add(this); };
80 this.bolt12_refund = bolt12_refund_hu_conv;
84 long ret = bindings.PaymentContext_clone_ptr(this.ptr);
85 Reference.reachabilityFence(this);
90 * Creates a copy of the PaymentContext
92 public PaymentContext clone() {
93 long ret = bindings.PaymentContext_clone(this.ptr);
94 Reference.reachabilityFence(this);
95 if (ret >= 0 && ret <= 4096) { return null; }
96 org.ldk.structs.PaymentContext ret_hu_conv = org.ldk.structs.PaymentContext.constr_from_ptr(ret);
97 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
102 * Utility method to constructs a new Unknown-variant PaymentContext
104 public static PaymentContext unknown(org.ldk.structs.UnknownPaymentContext a) {
105 long ret = bindings.PaymentContext_unknown(a.ptr);
106 Reference.reachabilityFence(a);
107 if (ret >= 0 && ret <= 4096) { return null; }
108 org.ldk.structs.PaymentContext ret_hu_conv = org.ldk.structs.PaymentContext.constr_from_ptr(ret);
109 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
110 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
115 * Utility method to constructs a new Bolt12Offer-variant PaymentContext
117 public static PaymentContext bolt12_offer(org.ldk.structs.Bolt12OfferContext a) {
118 long ret = bindings.PaymentContext_bolt12_offer(a.ptr);
119 Reference.reachabilityFence(a);
120 if (ret >= 0 && ret <= 4096) { return null; }
121 org.ldk.structs.PaymentContext ret_hu_conv = org.ldk.structs.PaymentContext.constr_from_ptr(ret);
122 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
123 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
128 * Utility method to constructs a new Bolt12Refund-variant PaymentContext
130 public static PaymentContext bolt12_refund(org.ldk.structs.Bolt12RefundContext a) {
131 long ret = bindings.PaymentContext_bolt12_refund(a.ptr);
132 Reference.reachabilityFence(a);
133 if (ret >= 0 && ret <= 4096) { return null; }
134 org.ldk.structs.PaymentContext ret_hu_conv = org.ldk.structs.PaymentContext.constr_from_ptr(ret);
135 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
136 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
141 * Checks if two PaymentContexts contain equal inner contents.
142 * This ignores pointers and is_owned flags and looks at the values in fields.
144 public boolean eq(org.ldk.structs.PaymentContext b) {
145 boolean ret = bindings.PaymentContext_eq(this.ptr, b.ptr);
146 Reference.reachabilityFence(this);
147 Reference.reachabilityFence(b);
151 @Override public boolean equals(Object o) {
152 if (!(o instanceof PaymentContext)) return false;
153 return this.eq((PaymentContext)o);
156 * Serialize the PaymentContext object into a byte array which can be read by PaymentContext_read
158 public byte[] write() {
159 byte[] ret = bindings.PaymentContext_write(this.ptr);
160 Reference.reachabilityFence(this);
165 * Read a PaymentContext from a byte array, created by PaymentContext_write
167 public static Result_PaymentContextDecodeErrorZ read(byte[] ser) {
168 long ret = bindings.PaymentContext_read(ser);
169 Reference.reachabilityFence(ser);
170 if (ret >= 0 && ret <= 4096) { return null; }
171 Result_PaymentContextDecodeErrorZ ret_hu_conv = Result_PaymentContextDecodeErrorZ.constr_from_ptr(ret);