]> git.bitcoin.ninja Git - ldk-java/blob - src/main/java/org/ldk/structs/PaymentContext.java
[Java] Update auto-generated bindings to LDK 0.0.123
[ldk-java] / src / main / java / org / ldk / structs / PaymentContext.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * The context of an inbound payment, which is included in a [`BlindedPath`] via [`ReceiveTlvs`]
13  * and surfaced in [`PaymentPurpose`].
14  * 
15  * [`BlindedPath`]: crate::blinded_path::BlindedPath
16  * [`PaymentPurpose`]: crate::events::PaymentPurpose
17  */
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 {
23                 super.finalize();
24                 if (ptr != 0) { bindings.PaymentContext_free(ptr); }
25         }
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);
30                 }
31                 if (raw_val.getClass() == bindings.LDKPaymentContext.Bolt12Offer.class) {
32                         return new Bolt12Offer(ptr, (bindings.LDKPaymentContext.Bolt12Offer)raw_val);
33                 }
34                 if (raw_val.getClass() == bindings.LDKPaymentContext.Bolt12Refund.class) {
35                         return new Bolt12Refund(ptr, (bindings.LDKPaymentContext.Bolt12Refund)raw_val);
36                 }
37                 assert false; return null; // Unreachable without extending the (internal) bindings interface
38         }
39
40         /**
41          * The payment context was unknown.
42          */
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) {
46                         super(null, ptr);
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;
51                 }
52         }
53         /**
54          * The payment was made for an invoice requested from a BOLT 12 [`Offer`].
55          * 
56          * [`Offer`]: crate::offers::offer::Offer
57          */
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) {
61                         super(null, ptr);
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;
66                 }
67         }
68         /**
69          * The payment was made for an invoice sent for a BOLT 12 [`Refund`].
70          * 
71          * [`Refund`]: crate::offers::refund::Refund
72          */
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) {
76                         super(null, ptr);
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;
81                 }
82         }
83         long clone_ptr() {
84                 long ret = bindings.PaymentContext_clone_ptr(this.ptr);
85                 Reference.reachabilityFence(this);
86                 return ret;
87         }
88
89         /**
90          * Creates a copy of the PaymentContext
91          */
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); };
98                 return ret_hu_conv;
99         }
100
101         /**
102          * Utility method to constructs a new Unknown-variant PaymentContext
103          */
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); };
111                 return ret_hu_conv;
112         }
113
114         /**
115          * Utility method to constructs a new Bolt12Offer-variant PaymentContext
116          */
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); };
124                 return ret_hu_conv;
125         }
126
127         /**
128          * Utility method to constructs a new Bolt12Refund-variant PaymentContext
129          */
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); };
137                 return ret_hu_conv;
138         }
139
140         /**
141          * Checks if two PaymentContexts contain equal inner contents.
142          * This ignores pointers and is_owned flags and looks at the values in fields.
143          */
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);
148                 return ret;
149         }
150
151         @Override public boolean equals(Object o) {
152                 if (!(o instanceof PaymentContext)) return false;
153                 return this.eq((PaymentContext)o);
154         }
155         /**
156          * Serialize the PaymentContext object into a byte array which can be read by PaymentContext_read
157          */
158         public byte[] write() {
159                 byte[] ret = bindings.PaymentContext_write(this.ptr);
160                 Reference.reachabilityFence(this);
161                 return ret;
162         }
163
164         /**
165          * Read a PaymentContext from a byte array, created by PaymentContext_write
166          */
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);
172                 return ret_hu_conv;
173         }
174
175 }