Update auto-generated bindings to latest upstream
[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         /**
38          * Creates a copy of the SignedRawInvoice
39          */
40         public SignedRawInvoice clone() {
41                 long ret = bindings.SignedRawInvoice_clone(this.ptr);
42                 if (ret < 1024) { return null; }
43                 SignedRawInvoice ret_hu_conv = new SignedRawInvoice(null, ret);
44                 ret_hu_conv.ptrs_to.add(this);
45                 return ret_hu_conv;
46         }
47
48         /**
49          * Disassembles the `SignedRawInvoice` into its three parts:
50          * 1. raw invoice
51          * 2. hash of the raw invoice
52          * 3. signature
53          */
54         public ThreeTuple<RawInvoice, byte[], InvoiceSignature> into_parts() {
55                 long ret = bindings.SignedRawInvoice_into_parts(this.ptr);
56                 if (ret < 1024) { return null; }
57                 long ret_a = bindings.LDKC3Tuple_RawInvoice_u832InvoiceSignatureZ_get_a(ret);
58                 RawInvoice ret_a_hu_conv = new RawInvoice(null, ret_a);
59                 ret_a_hu_conv.ptrs_to.add(this);;
60                 byte[] ret_b = bindings.LDKC3Tuple_RawInvoice_u832InvoiceSignatureZ_get_b(ret);
61                 long ret_c = bindings.LDKC3Tuple_RawInvoice_u832InvoiceSignatureZ_get_c(ret);
62                 InvoiceSignature ret_c_hu_conv = new InvoiceSignature(null, ret_c);
63                 ret_c_hu_conv.ptrs_to.add(this);;
64                 ThreeTuple<RawInvoice, byte[], InvoiceSignature> ret_conv = new ThreeTuple<RawInvoice, byte[], InvoiceSignature>(ret_a_hu_conv, ret_b, ret_c_hu_conv, () -> {
65                         bindings.C3Tuple_RawInvoice_u832InvoiceSignatureZ_free(ret);
66                 });
67                 ret_a_hu_conv.ptrs_to.add(ret_conv);
68                 ret_c_hu_conv.ptrs_to.add(ret_conv);
69                 this.ptrs_to.add(this);
70                 return ret_conv;
71         }
72
73         /**
74          * The `RawInvoice` which was signed.
75          */
76         public RawInvoice raw_invoice() {
77                 long ret = bindings.SignedRawInvoice_raw_invoice(this.ptr);
78                 if (ret < 1024) { return null; }
79                 RawInvoice ret_hu_conv = new RawInvoice(null, ret);
80                 ret_hu_conv.ptrs_to.add(this);
81                 return ret_hu_conv;
82         }
83
84         /**
85          * The hash of the `RawInvoice` that was signed.
86          */
87         public byte[] hash() {
88                 byte[] ret = bindings.SignedRawInvoice_hash(this.ptr);
89                 return ret;
90         }
91
92         /**
93          * InvoiceSignature for the invoice.
94          */
95         public InvoiceSignature signature() {
96                 long ret = bindings.SignedRawInvoice_signature(this.ptr);
97                 if (ret < 1024) { return null; }
98                 InvoiceSignature ret_hu_conv = new InvoiceSignature(null, ret);
99                 ret_hu_conv.ptrs_to.add(this);
100                 return ret_hu_conv;
101         }
102
103         /**
104          * Recovers the public key used for signing the invoice from the recoverable signature.
105          */
106         public Result_PayeePubKeyErrorZ recover_payee_pub_key() {
107                 long ret = bindings.SignedRawInvoice_recover_payee_pub_key(this.ptr);
108                 if (ret < 1024) { return null; }
109                 Result_PayeePubKeyErrorZ ret_hu_conv = Result_PayeePubKeyErrorZ.constr_from_ptr(ret);
110                 return ret_hu_conv;
111         }
112
113         /**
114          * Checks if the signature is valid for the included payee public key or if none exists if it's
115          * valid for the recovered signature (which should always be true?).
116          */
117         public boolean check_signature() {
118                 boolean ret = bindings.SignedRawInvoice_check_signature(this.ptr);
119                 return ret;
120         }
121
122         /**
123          * Read a SignedRawInvoice object from a string
124          */
125         public static Result_SignedRawInvoiceNoneZ from_str(java.lang.String s) {
126                 long ret = bindings.SignedRawInvoice_from_str(s);
127                 if (ret < 1024) { return null; }
128                 Result_SignedRawInvoiceNoneZ ret_hu_conv = Result_SignedRawInvoiceNoneZ.constr_from_ptr(ret);
129                 return ret_hu_conv;
130         }
131
132         /**
133          * Get the string representation of a SignedRawInvoice object
134          */
135         public String to_str() {
136                 String ret = bindings.SignedRawInvoice_to_str(this.ptr);
137                 return ret;
138         }
139
140 }