8b996d41e95354dcf4e323f59d1151c2f24d4670
[ldk-java] / src / main / java / org / ldk / structs / InvoiceError.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  * An error in response to an [`InvoiceRequest`] or an [`Bolt12Invoice`].
13  * 
14  * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
15  * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class InvoiceError extends CommonBase {
19         InvoiceError(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.InvoiceError_free(ptr); }
24         }
25
26         /**
27          * The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error.
28          * 
29          * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
30          * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
31          * 
32          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
33          */
34         @Nullable
35         public ErroneousField get_erroneous_field() {
36                 long ret = bindings.InvoiceError_get_erroneous_field(this.ptr);
37                 Reference.reachabilityFence(this);
38                 if (ret >= 0 && ret <= 4096) { return null; }
39                 org.ldk.structs.ErroneousField ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ErroneousField(null, ret); }
40                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
41                 return ret_hu_conv;
42         }
43
44         /**
45          * The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error.
46          * 
47          * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
48          * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
49          * 
50          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
51          */
52         public void set_erroneous_field(@Nullable org.ldk.structs.ErroneousField val) {
53                 bindings.InvoiceError_set_erroneous_field(this.ptr, val == null ? 0 : val.ptr);
54                 Reference.reachabilityFence(this);
55                 Reference.reachabilityFence(val);
56                 if (this != null) { this.ptrs_to.add(val); };
57         }
58
59         /**
60          * An explanation of the error.
61          */
62         public UntrustedString get_message() {
63                 long ret = bindings.InvoiceError_get_message(this.ptr);
64                 Reference.reachabilityFence(this);
65                 if (ret >= 0 && ret <= 4096) { return null; }
66                 org.ldk.structs.UntrustedString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UntrustedString(null, ret); }
67                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
68                 return ret_hu_conv;
69         }
70
71         /**
72          * An explanation of the error.
73          */
74         public void set_message(org.ldk.structs.UntrustedString val) {
75                 bindings.InvoiceError_set_message(this.ptr, val == null ? 0 : val.ptr);
76                 Reference.reachabilityFence(this);
77                 Reference.reachabilityFence(val);
78                 if (this != null) { this.ptrs_to.add(val); };
79         }
80
81         /**
82          * Constructs a new InvoiceError given each field
83          */
84         public static InvoiceError of(org.ldk.structs.ErroneousField erroneous_field_arg, org.ldk.structs.UntrustedString message_arg) {
85                 long ret = bindings.InvoiceError_new(erroneous_field_arg == null ? 0 : erroneous_field_arg.ptr, message_arg == null ? 0 : message_arg.ptr);
86                 Reference.reachabilityFence(erroneous_field_arg);
87                 Reference.reachabilityFence(message_arg);
88                 if (ret >= 0 && ret <= 4096) { return null; }
89                 org.ldk.structs.InvoiceError ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InvoiceError(null, ret); }
90                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
91                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(erroneous_field_arg); };
92                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(message_arg); };
93                 return ret_hu_conv;
94         }
95
96         long clone_ptr() {
97                 long ret = bindings.InvoiceError_clone_ptr(this.ptr);
98                 Reference.reachabilityFence(this);
99                 return ret;
100         }
101
102         /**
103          * Creates a copy of the InvoiceError
104          */
105         public InvoiceError clone() {
106                 long ret = bindings.InvoiceError_clone(this.ptr);
107                 Reference.reachabilityFence(this);
108                 if (ret >= 0 && ret <= 4096) { return null; }
109                 org.ldk.structs.InvoiceError ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InvoiceError(null, ret); }
110                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
111                 return ret_hu_conv;
112         }
113
114         /**
115          * Serialize the InvoiceError object into a byte array which can be read by InvoiceError_read
116          */
117         public byte[] write() {
118                 byte[] ret = bindings.InvoiceError_write(this.ptr);
119                 Reference.reachabilityFence(this);
120                 return ret;
121         }
122
123         /**
124          * Read a InvoiceError from a byte array, created by InvoiceError_write
125          */
126         public static Result_InvoiceErrorDecodeErrorZ read(byte[] ser) {
127                 long ret = bindings.InvoiceError_read(ser);
128                 Reference.reachabilityFence(ser);
129                 if (ret >= 0 && ret <= 4096) { return null; }
130                 Result_InvoiceErrorDecodeErrorZ ret_hu_conv = Result_InvoiceErrorDecodeErrorZ.constr_from_ptr(ret);
131                 return ret_hu_conv;
132         }
133
134 }