]> git.bitcoin.ninja Git - ldk-java/blob - src/main/java/org/ldk/structs/ParseOrSemanticError.java
Merge pull request #94 from TheBlueMatt/main
[ldk-java] / src / main / java / org / ldk / structs / ParseOrSemanticError.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  * Indicates that something went wrong while parsing or validating the invoice. Parsing errors
13  * should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
14  * like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
15  */
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class ParseOrSemanticError extends CommonBase {
18         private ParseOrSemanticError(Object _dummy, long ptr) { super(ptr); }
19         @Override @SuppressWarnings("deprecation")
20         protected void finalize() throws Throwable {
21                 super.finalize();
22                 if (ptr != 0) { bindings.ParseOrSemanticError_free(ptr); }
23         }
24         static ParseOrSemanticError constr_from_ptr(long ptr) {
25                 bindings.LDKParseOrSemanticError raw_val = bindings.LDKParseOrSemanticError_ref_from_ptr(ptr);
26                 if (raw_val.getClass() == bindings.LDKParseOrSemanticError.ParseError.class) {
27                         return new ParseError(ptr, (bindings.LDKParseOrSemanticError.ParseError)raw_val);
28                 }
29                 if (raw_val.getClass() == bindings.LDKParseOrSemanticError.SemanticError.class) {
30                         return new SemanticError(ptr, (bindings.LDKParseOrSemanticError.SemanticError)raw_val);
31                 }
32                 assert false; return null; // Unreachable without extending the (internal) bindings interface
33         }
34
35         /**
36          * The invoice couldn't be decoded
37          */
38         public final static class ParseError extends ParseOrSemanticError {
39                 public final org.ldk.structs.ParseError parse_error;
40                 private ParseError(long ptr, bindings.LDKParseOrSemanticError.ParseError obj) {
41                         super(null, ptr);
42                         long parse_error = obj.parse_error;
43                         org.ldk.structs.ParseError parse_error_hu_conv = org.ldk.structs.ParseError.constr_from_ptr(parse_error);
44                         parse_error_hu_conv.ptrs_to.add(this);
45                         this.parse_error = parse_error_hu_conv;
46                 }
47         }
48         /**
49          * The invoice could be decoded but violates the BOLT11 standard
50          */
51         public final static class SemanticError extends ParseOrSemanticError {
52                 public final org.ldk.enums.SemanticError semantic_error;
53                 private SemanticError(long ptr, bindings.LDKParseOrSemanticError.SemanticError obj) {
54                         super(null, ptr);
55                         this.semantic_error = obj.semantic_error;
56                 }
57         }
58         long clone_ptr() {
59                 long ret = bindings.ParseOrSemanticError_clone_ptr(this.ptr);
60                 Reference.reachabilityFence(this);
61                 return ret;
62         }
63
64         /**
65          * Creates a copy of the ParseOrSemanticError
66          */
67         public ParseOrSemanticError clone() {
68                 long ret = bindings.ParseOrSemanticError_clone(this.ptr);
69                 Reference.reachabilityFence(this);
70                 if (ret >= 0 && ret <= 4096) { return null; }
71                 org.ldk.structs.ParseOrSemanticError ret_hu_conv = org.ldk.structs.ParseOrSemanticError.constr_from_ptr(ret);
72                 ret_hu_conv.ptrs_to.add(this);
73                 return ret_hu_conv;
74         }
75
76         /**
77          * Utility method to constructs a new ParseError-variant ParseOrSemanticError
78          */
79         public static ParseOrSemanticError parse_error(ParseError a) {
80                 long ret = bindings.ParseOrSemanticError_parse_error(a.ptr);
81                 Reference.reachabilityFence(a);
82                 if (ret >= 0 && ret <= 4096) { return null; }
83                 org.ldk.structs.ParseOrSemanticError ret_hu_conv = org.ldk.structs.ParseOrSemanticError.constr_from_ptr(ret);
84                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
85                 return ret_hu_conv;
86         }
87
88         /**
89          * Utility method to constructs a new SemanticError-variant ParseOrSemanticError
90          */
91         public static ParseOrSemanticError semantic_error(org.ldk.enums.SemanticError a) {
92                 long ret = bindings.ParseOrSemanticError_semantic_error(a);
93                 Reference.reachabilityFence(a);
94                 if (ret >= 0 && ret <= 4096) { return null; }
95                 org.ldk.structs.ParseOrSemanticError ret_hu_conv = org.ldk.structs.ParseOrSemanticError.constr_from_ptr(ret);
96                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
97                 return ret_hu_conv;
98         }
99
100         /**
101          * Get the string representation of a ParseOrSemanticError object
102          */
103         public String to_str() {
104                 String ret = bindings.ParseOrSemanticError_to_str(this.ptr);
105                 Reference.reachabilityFence(this);
106                 return ret;
107         }
108
109 }