Merge pull request #56 from TheBlueMatt/main
[ldk-java] / src / main / java / org / ldk / structs / SignedRawInvoice.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 javax.annotation.Nullable;
8
9
10 /**
11  * Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
12  * invalid.
13  * 
14  * # Invariants
15  * The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class SignedRawInvoice extends CommonBase {
19         SignedRawInvoice(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.SignedRawInvoice_free(ptr); }
24         }
25
26         /**
27          * Checks if two SignedRawInvoices contain equal inner contents.
28          * This ignores pointers and is_owned flags and looks at the values in fields.
29          * Two objects with NULL inner values will be considered "equal" here.
30          */
31         public boolean eq(SignedRawInvoice b) {
32                 boolean ret = bindings.SignedRawInvoice_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
33                 this.ptrs_to.add(b);
34                 return ret;
35         }
36
37         long clone_ptr() {
38                 long ret = bindings.SignedRawInvoice_clone_ptr(this.ptr);
39                 return ret;
40         }
41
42         /**
43          * Creates a copy of the SignedRawInvoice
44          */
45         public SignedRawInvoice clone() {
46                 long ret = bindings.SignedRawInvoice_clone(this.ptr);
47                 if (ret >= 0 && ret <= 4096) { return null; }
48                 SignedRawInvoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new SignedRawInvoice(null, ret); }
49                 ret_hu_conv.ptrs_to.add(this);
50                 return ret_hu_conv;
51         }
52
53         /**
54          * Disassembles the `SignedRawInvoice` into its three parts:
55          * 1. raw invoice
56          * 2. hash of the raw invoice
57          * 3. signature
58          */
59         public ThreeTuple_RawInvoice_u832InvoiceSignatureZ into_parts() {
60                 long ret = bindings.SignedRawInvoice_into_parts(this.ptr);
61                 if (ret >= 0 && ret <= 4096) { return null; }
62                 ThreeTuple_RawInvoice_u832InvoiceSignatureZ ret_hu_conv = new ThreeTuple_RawInvoice_u832InvoiceSignatureZ(null, ret);
63                 ret_hu_conv.ptrs_to.add(this);
64                 ;
65                 return ret_hu_conv;
66         }
67
68         /**
69          * The `RawInvoice` which was signed.
70          */
71         public RawInvoice raw_invoice() {
72                 long ret = bindings.SignedRawInvoice_raw_invoice(this.ptr);
73                 if (ret >= 0 && ret <= 4096) { return null; }
74                 RawInvoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new RawInvoice(null, ret); }
75                 ret_hu_conv.ptrs_to.add(this);
76                 return ret_hu_conv;
77         }
78
79         /**
80          * The hash of the `RawInvoice` that was signed.
81          */
82         public byte[] hash() {
83                 byte[] ret = bindings.SignedRawInvoice_hash(this.ptr);
84                 return ret;
85         }
86
87         /**
88          * InvoiceSignature for the invoice.
89          */
90         public InvoiceSignature signature() {
91                 long ret = bindings.SignedRawInvoice_signature(this.ptr);
92                 if (ret >= 0 && ret <= 4096) { return null; }
93                 InvoiceSignature ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new InvoiceSignature(null, ret); }
94                 ret_hu_conv.ptrs_to.add(this);
95                 return ret_hu_conv;
96         }
97
98         /**
99          * Recovers the public key used for signing the invoice from the recoverable signature.
100          */
101         public Result_PayeePubKeyErrorZ recover_payee_pub_key() {
102                 long ret = bindings.SignedRawInvoice_recover_payee_pub_key(this.ptr);
103                 if (ret >= 0 && ret <= 4096) { return null; }
104                 Result_PayeePubKeyErrorZ ret_hu_conv = Result_PayeePubKeyErrorZ.constr_from_ptr(ret);
105                 return ret_hu_conv;
106         }
107
108         /**
109          * Checks if the signature is valid for the included payee public key or if none exists if it's
110          * valid for the recovered signature (which should always be true?).
111          */
112         public boolean check_signature() {
113                 boolean ret = bindings.SignedRawInvoice_check_signature(this.ptr);
114                 return ret;
115         }
116
117         /**
118          * Read a SignedRawInvoice object from a string
119          */
120         public static Result_SignedRawInvoiceNoneZ from_str(java.lang.String s) {
121                 long ret = bindings.SignedRawInvoice_from_str(s);
122                 if (ret >= 0 && ret <= 4096) { return null; }
123                 Result_SignedRawInvoiceNoneZ ret_hu_conv = Result_SignedRawInvoiceNoneZ.constr_from_ptr(ret);
124                 return ret_hu_conv;
125         }
126
127         /**
128          * Get the string representation of a SignedRawInvoice object
129          */
130         public String to_str() {
131                 String ret = bindings.SignedRawInvoice_to_str(this.ptr);
132                 return ret;
133         }
134
135 }