e9e4e9592796857c13e7b89eb33e3d92c5e700a5
[ldk-java] / c_sharp / src / org / ldk / structs / SignedRawInvoice.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8
9 /**
10  * Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
11  * invalid.
12  * 
13  * # Invariants
14  * The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
15  */
16 public class SignedRawInvoice : CommonBase {
17         internal SignedRawInvoice(object _dummy, long ptr) : base(ptr) { }
18         ~SignedRawInvoice() {
19                 if (ptr != 0) { bindings.SignedRawInvoice_free(ptr); }
20         }
21
22         /**
23          * Checks if two SignedRawInvoices contain equal inner contents.
24          * This ignores pointers and is_owned flags and looks at the values in fields.
25          * Two objects with NULL inner values will be considered "equal" here.
26          */
27         public bool eq(org.ldk.structs.SignedRawInvoice b) {
28                 bool ret = bindings.SignedRawInvoice_eq(this.ptr, b == null ? 0 : b.ptr);
29                 GC.KeepAlive(this);
30                 GC.KeepAlive(b);
31                 if (this != null) { this.ptrs_to.AddLast(b); };
32                 return ret;
33         }
34
35         public override bool Equals(object o) {
36                 if (!(o is SignedRawInvoice)) return false;
37                 return this.eq((SignedRawInvoice)o);
38         }
39         internal long clone_ptr() {
40                 long ret = bindings.SignedRawInvoice_clone_ptr(this.ptr);
41                 GC.KeepAlive(this);
42                 return ret;
43         }
44
45         /**
46          * Creates a copy of the SignedRawInvoice
47          */
48         public SignedRawInvoice clone() {
49                 long ret = bindings.SignedRawInvoice_clone(this.ptr);
50                 GC.KeepAlive(this);
51                 if (ret >= 0 && ret <= 4096) { return null; }
52                 org.ldk.structs.SignedRawInvoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.SignedRawInvoice(null, ret); }
53                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
54                 return ret_hu_conv;
55         }
56
57         /**
58          * Checks if two SignedRawInvoices contain equal inner contents.
59          */
60         public long hash() {
61                 long ret = bindings.SignedRawInvoice_hash(this.ptr);
62                 GC.KeepAlive(this);
63                 return ret;
64         }
65
66         public override int GetHashCode() {
67                 return (int)this.hash();
68         }
69         /**
70          * Disassembles the `SignedRawInvoice` into its three parts:
71          * 1. raw invoice
72          * 2. hash of the raw invoice
73          * 3. signature
74          */
75         public ThreeTuple_RawInvoice_u832InvoiceSignatureZ into_parts() {
76                 long ret = bindings.SignedRawInvoice_into_parts(this.ptr);
77                 GC.KeepAlive(this);
78                 if (ret >= 0 && ret <= 4096) { return null; }
79                 ThreeTuple_RawInvoice_u832InvoiceSignatureZ ret_hu_conv = new ThreeTuple_RawInvoice_u832InvoiceSignatureZ(null, ret);
80                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
81                 if (this != null) { this.ptrs_to.AddLast(this); };
82                 return ret_hu_conv;
83         }
84
85         /**
86          * The `RawInvoice` which was signed.
87          */
88         public RawInvoice raw_invoice() {
89                 long ret = bindings.SignedRawInvoice_raw_invoice(this.ptr);
90                 GC.KeepAlive(this);
91                 if (ret >= 0 && ret <= 4096) { return null; }
92                 org.ldk.structs.RawInvoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RawInvoice(null, ret); }
93                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
94                 return ret_hu_conv;
95         }
96
97         /**
98          * The hash of the `RawInvoice` that was signed.
99          */
100         public byte[] signable_hash() {
101                 byte[] ret = bindings.SignedRawInvoice_signable_hash(this.ptr);
102                 GC.KeepAlive(this);
103                 return ret;
104         }
105
106         /**
107          * InvoiceSignature for the invoice.
108          */
109         public InvoiceSignature signature() {
110                 long ret = bindings.SignedRawInvoice_signature(this.ptr);
111                 GC.KeepAlive(this);
112                 if (ret >= 0 && ret <= 4096) { return null; }
113                 org.ldk.structs.InvoiceSignature ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InvoiceSignature(null, ret); }
114                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
115                 return ret_hu_conv;
116         }
117
118         /**
119          * Recovers the public key used for signing the invoice from the recoverable signature.
120          */
121         public Result_PayeePubKeyErrorZ recover_payee_pub_key() {
122                 long ret = bindings.SignedRawInvoice_recover_payee_pub_key(this.ptr);
123                 GC.KeepAlive(this);
124                 if (ret >= 0 && ret <= 4096) { return null; }
125                 Result_PayeePubKeyErrorZ ret_hu_conv = Result_PayeePubKeyErrorZ.constr_from_ptr(ret);
126                 return ret_hu_conv;
127         }
128
129         /**
130          * Checks if the signature is valid for the included payee public key or if none exists if it's
131          * valid for the recovered signature (which should always be true?).
132          */
133         public bool check_signature() {
134                 bool ret = bindings.SignedRawInvoice_check_signature(this.ptr);
135                 GC.KeepAlive(this);
136                 return ret;
137         }
138
139         /**
140          * Read a SignedRawInvoice object from a string
141          */
142         public static Result_SignedRawInvoiceParseErrorZ from_str(string s) {
143                 long ret = bindings.SignedRawInvoice_from_str(s);
144                 GC.KeepAlive(s);
145                 if (ret >= 0 && ret <= 4096) { return null; }
146                 Result_SignedRawInvoiceParseErrorZ ret_hu_conv = Result_SignedRawInvoiceParseErrorZ.constr_from_ptr(ret);
147                 return ret_hu_conv;
148         }
149
150         /**
151          * Get the string representation of a SignedRawInvoice object
152          */
153         public string to_str() {
154                 string ret = bindings.SignedRawInvoice_to_str(this.ptr);
155                 GC.KeepAlive(this);
156                 return ret;
157         }
158
159 }
160 } } }