1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! Parsing and formatting for bech32 message encoding.
11 use alloc::str::FromStr;
12 use core::ffi::c_void;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
16 #[cfg(feature="no-std")]
17 use alloc::{vec::Vec, boxed::Box};
21 use alloc::str::FromStr;
22 use core::ffi::c_void;
23 use core::convert::Infallible;
24 use bitcoin::hashes::Hash;
25 use crate::c_types::*;
26 #[cfg(feature="no-std")]
27 use alloc::{vec::Vec, boxed::Box};
31 use lightning::offers::parse::Bolt12ParseError as nativeBolt12ParseErrorImport;
32 pub(crate) type nativeBolt12ParseError = nativeBolt12ParseErrorImport;
34 /// Error when parsing a bech32 encoded message using [`str::parse`].
37 pub struct Bolt12ParseError {
38 /// A pointer to the opaque Rust object.
40 /// Nearly everywhere, inner must be non-null, however in places where
41 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
42 pub inner: *mut nativeBolt12ParseError,
43 /// Indicates that this is the only struct which contains the same pointer.
45 /// Rust functions which take ownership of an object provided via an argument require
46 /// this to be true and invalidate the object pointed to by inner.
50 impl Drop for Bolt12ParseError {
52 if self.is_owned && !<*mut nativeBolt12ParseError>::is_null(self.inner) {
53 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
57 /// Frees any resources used by the Bolt12ParseError, if is_owned is set and inner is non-NULL.
59 pub extern "C" fn Bolt12ParseError_free(this_obj: Bolt12ParseError) { }
61 /// Used only if an object of this type is returned as a trait impl by a method
62 pub(crate) extern "C" fn Bolt12ParseError_free_void(this_ptr: *mut c_void) {
63 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt12ParseError) };
66 impl Bolt12ParseError {
67 pub(crate) fn get_native_ref(&self) -> &'static nativeBolt12ParseError {
68 unsafe { &*ObjOps::untweak_ptr(self.inner) }
70 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt12ParseError {
71 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
73 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
74 pub(crate) fn take_inner(mut self) -> *mut nativeBolt12ParseError {
75 assert!(self.is_owned);
76 let ret = ObjOps::untweak_ptr(self.inner);
77 self.inner = core::ptr::null_mut();
81 impl Clone for Bolt12ParseError {
82 fn clone(&self) -> Self {
84 inner: if <*mut nativeBolt12ParseError>::is_null(self.inner) { core::ptr::null_mut() } else {
85 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
91 /// Used only if an object of this type is returned as a trait impl by a method
92 pub(crate) extern "C" fn Bolt12ParseError_clone_void(this_ptr: *const c_void) -> *mut c_void {
93 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBolt12ParseError)).clone() })) as *mut c_void
96 /// Creates a copy of the Bolt12ParseError
97 pub extern "C" fn Bolt12ParseError_clone(orig: &Bolt12ParseError) -> Bolt12ParseError {
100 /// Error when interpreting a TLV stream as a specific type.
104 pub enum Bolt12SemanticError {
105 /// The current [`std::time::SystemTime`] is past the offer or invoice's expiration.
107 /// The provided chain hash does not correspond to a supported chain.
109 /// A chain was provided but was not expected.
111 /// An amount was expected but was missing.
113 /// The amount exceeded the total bitcoin supply.
115 /// An amount was provided but was not sufficient in value.
117 /// An amount was provided but was not expected.
119 /// A currency was provided that is not supported.
121 /// A feature was required but is unknown.
122 UnknownRequiredFeatures,
123 /// Features were provided but were not expected.
125 /// A required description was not provided.
127 /// A signing pubkey was not provided.
128 MissingSigningPubkey,
129 /// A signing pubkey was provided but a different one was expected.
130 InvalidSigningPubkey,
131 /// A signing pubkey was provided but was not expected.
132 UnexpectedSigningPubkey,
133 /// A quantity was expected but was missing.
135 /// An unsupported quantity was provided.
137 /// A quantity or quantity bounds was provided but was not expected.
139 /// Metadata could not be used to verify the offers message.
141 /// Metadata was provided but was not expected.
143 /// Payer metadata was expected but was missing.
144 MissingPayerMetadata,
145 /// A payer id was expected but was missing.
147 /// Blinded paths were expected but were missing.
149 /// The blinded payinfo given does not match the number of blinded path hops.
151 /// An invoice creation time was expected but was missing.
153 /// An invoice payment hash was expected but was missing.
155 /// A signature was expected but was missing.
158 use lightning::offers::parse::Bolt12SemanticError as Bolt12SemanticErrorImport;
159 pub(crate) type nativeBolt12SemanticError = Bolt12SemanticErrorImport;
161 impl Bolt12SemanticError {
163 pub(crate) fn to_native(&self) -> nativeBolt12SemanticError {
165 Bolt12SemanticError::AlreadyExpired => nativeBolt12SemanticError::AlreadyExpired,
166 Bolt12SemanticError::UnsupportedChain => nativeBolt12SemanticError::UnsupportedChain,
167 Bolt12SemanticError::UnexpectedChain => nativeBolt12SemanticError::UnexpectedChain,
168 Bolt12SemanticError::MissingAmount => nativeBolt12SemanticError::MissingAmount,
169 Bolt12SemanticError::InvalidAmount => nativeBolt12SemanticError::InvalidAmount,
170 Bolt12SemanticError::InsufficientAmount => nativeBolt12SemanticError::InsufficientAmount,
171 Bolt12SemanticError::UnexpectedAmount => nativeBolt12SemanticError::UnexpectedAmount,
172 Bolt12SemanticError::UnsupportedCurrency => nativeBolt12SemanticError::UnsupportedCurrency,
173 Bolt12SemanticError::UnknownRequiredFeatures => nativeBolt12SemanticError::UnknownRequiredFeatures,
174 Bolt12SemanticError::UnexpectedFeatures => nativeBolt12SemanticError::UnexpectedFeatures,
175 Bolt12SemanticError::MissingDescription => nativeBolt12SemanticError::MissingDescription,
176 Bolt12SemanticError::MissingSigningPubkey => nativeBolt12SemanticError::MissingSigningPubkey,
177 Bolt12SemanticError::InvalidSigningPubkey => nativeBolt12SemanticError::InvalidSigningPubkey,
178 Bolt12SemanticError::UnexpectedSigningPubkey => nativeBolt12SemanticError::UnexpectedSigningPubkey,
179 Bolt12SemanticError::MissingQuantity => nativeBolt12SemanticError::MissingQuantity,
180 Bolt12SemanticError::InvalidQuantity => nativeBolt12SemanticError::InvalidQuantity,
181 Bolt12SemanticError::UnexpectedQuantity => nativeBolt12SemanticError::UnexpectedQuantity,
182 Bolt12SemanticError::InvalidMetadata => nativeBolt12SemanticError::InvalidMetadata,
183 Bolt12SemanticError::UnexpectedMetadata => nativeBolt12SemanticError::UnexpectedMetadata,
184 Bolt12SemanticError::MissingPayerMetadata => nativeBolt12SemanticError::MissingPayerMetadata,
185 Bolt12SemanticError::MissingPayerId => nativeBolt12SemanticError::MissingPayerId,
186 Bolt12SemanticError::MissingPaths => nativeBolt12SemanticError::MissingPaths,
187 Bolt12SemanticError::InvalidPayInfo => nativeBolt12SemanticError::InvalidPayInfo,
188 Bolt12SemanticError::MissingCreationTime => nativeBolt12SemanticError::MissingCreationTime,
189 Bolt12SemanticError::MissingPaymentHash => nativeBolt12SemanticError::MissingPaymentHash,
190 Bolt12SemanticError::MissingSignature => nativeBolt12SemanticError::MissingSignature,
194 pub(crate) fn into_native(self) -> nativeBolt12SemanticError {
196 Bolt12SemanticError::AlreadyExpired => nativeBolt12SemanticError::AlreadyExpired,
197 Bolt12SemanticError::UnsupportedChain => nativeBolt12SemanticError::UnsupportedChain,
198 Bolt12SemanticError::UnexpectedChain => nativeBolt12SemanticError::UnexpectedChain,
199 Bolt12SemanticError::MissingAmount => nativeBolt12SemanticError::MissingAmount,
200 Bolt12SemanticError::InvalidAmount => nativeBolt12SemanticError::InvalidAmount,
201 Bolt12SemanticError::InsufficientAmount => nativeBolt12SemanticError::InsufficientAmount,
202 Bolt12SemanticError::UnexpectedAmount => nativeBolt12SemanticError::UnexpectedAmount,
203 Bolt12SemanticError::UnsupportedCurrency => nativeBolt12SemanticError::UnsupportedCurrency,
204 Bolt12SemanticError::UnknownRequiredFeatures => nativeBolt12SemanticError::UnknownRequiredFeatures,
205 Bolt12SemanticError::UnexpectedFeatures => nativeBolt12SemanticError::UnexpectedFeatures,
206 Bolt12SemanticError::MissingDescription => nativeBolt12SemanticError::MissingDescription,
207 Bolt12SemanticError::MissingSigningPubkey => nativeBolt12SemanticError::MissingSigningPubkey,
208 Bolt12SemanticError::InvalidSigningPubkey => nativeBolt12SemanticError::InvalidSigningPubkey,
209 Bolt12SemanticError::UnexpectedSigningPubkey => nativeBolt12SemanticError::UnexpectedSigningPubkey,
210 Bolt12SemanticError::MissingQuantity => nativeBolt12SemanticError::MissingQuantity,
211 Bolt12SemanticError::InvalidQuantity => nativeBolt12SemanticError::InvalidQuantity,
212 Bolt12SemanticError::UnexpectedQuantity => nativeBolt12SemanticError::UnexpectedQuantity,
213 Bolt12SemanticError::InvalidMetadata => nativeBolt12SemanticError::InvalidMetadata,
214 Bolt12SemanticError::UnexpectedMetadata => nativeBolt12SemanticError::UnexpectedMetadata,
215 Bolt12SemanticError::MissingPayerMetadata => nativeBolt12SemanticError::MissingPayerMetadata,
216 Bolt12SemanticError::MissingPayerId => nativeBolt12SemanticError::MissingPayerId,
217 Bolt12SemanticError::MissingPaths => nativeBolt12SemanticError::MissingPaths,
218 Bolt12SemanticError::InvalidPayInfo => nativeBolt12SemanticError::InvalidPayInfo,
219 Bolt12SemanticError::MissingCreationTime => nativeBolt12SemanticError::MissingCreationTime,
220 Bolt12SemanticError::MissingPaymentHash => nativeBolt12SemanticError::MissingPaymentHash,
221 Bolt12SemanticError::MissingSignature => nativeBolt12SemanticError::MissingSignature,
225 pub(crate) fn from_native(native: &nativeBolt12SemanticError) -> Self {
227 nativeBolt12SemanticError::AlreadyExpired => Bolt12SemanticError::AlreadyExpired,
228 nativeBolt12SemanticError::UnsupportedChain => Bolt12SemanticError::UnsupportedChain,
229 nativeBolt12SemanticError::UnexpectedChain => Bolt12SemanticError::UnexpectedChain,
230 nativeBolt12SemanticError::MissingAmount => Bolt12SemanticError::MissingAmount,
231 nativeBolt12SemanticError::InvalidAmount => Bolt12SemanticError::InvalidAmount,
232 nativeBolt12SemanticError::InsufficientAmount => Bolt12SemanticError::InsufficientAmount,
233 nativeBolt12SemanticError::UnexpectedAmount => Bolt12SemanticError::UnexpectedAmount,
234 nativeBolt12SemanticError::UnsupportedCurrency => Bolt12SemanticError::UnsupportedCurrency,
235 nativeBolt12SemanticError::UnknownRequiredFeatures => Bolt12SemanticError::UnknownRequiredFeatures,
236 nativeBolt12SemanticError::UnexpectedFeatures => Bolt12SemanticError::UnexpectedFeatures,
237 nativeBolt12SemanticError::MissingDescription => Bolt12SemanticError::MissingDescription,
238 nativeBolt12SemanticError::MissingSigningPubkey => Bolt12SemanticError::MissingSigningPubkey,
239 nativeBolt12SemanticError::InvalidSigningPubkey => Bolt12SemanticError::InvalidSigningPubkey,
240 nativeBolt12SemanticError::UnexpectedSigningPubkey => Bolt12SemanticError::UnexpectedSigningPubkey,
241 nativeBolt12SemanticError::MissingQuantity => Bolt12SemanticError::MissingQuantity,
242 nativeBolt12SemanticError::InvalidQuantity => Bolt12SemanticError::InvalidQuantity,
243 nativeBolt12SemanticError::UnexpectedQuantity => Bolt12SemanticError::UnexpectedQuantity,
244 nativeBolt12SemanticError::InvalidMetadata => Bolt12SemanticError::InvalidMetadata,
245 nativeBolt12SemanticError::UnexpectedMetadata => Bolt12SemanticError::UnexpectedMetadata,
246 nativeBolt12SemanticError::MissingPayerMetadata => Bolt12SemanticError::MissingPayerMetadata,
247 nativeBolt12SemanticError::MissingPayerId => Bolt12SemanticError::MissingPayerId,
248 nativeBolt12SemanticError::MissingPaths => Bolt12SemanticError::MissingPaths,
249 nativeBolt12SemanticError::InvalidPayInfo => Bolt12SemanticError::InvalidPayInfo,
250 nativeBolt12SemanticError::MissingCreationTime => Bolt12SemanticError::MissingCreationTime,
251 nativeBolt12SemanticError::MissingPaymentHash => Bolt12SemanticError::MissingPaymentHash,
252 nativeBolt12SemanticError::MissingSignature => Bolt12SemanticError::MissingSignature,
256 pub(crate) fn native_into(native: nativeBolt12SemanticError) -> Self {
258 nativeBolt12SemanticError::AlreadyExpired => Bolt12SemanticError::AlreadyExpired,
259 nativeBolt12SemanticError::UnsupportedChain => Bolt12SemanticError::UnsupportedChain,
260 nativeBolt12SemanticError::UnexpectedChain => Bolt12SemanticError::UnexpectedChain,
261 nativeBolt12SemanticError::MissingAmount => Bolt12SemanticError::MissingAmount,
262 nativeBolt12SemanticError::InvalidAmount => Bolt12SemanticError::InvalidAmount,
263 nativeBolt12SemanticError::InsufficientAmount => Bolt12SemanticError::InsufficientAmount,
264 nativeBolt12SemanticError::UnexpectedAmount => Bolt12SemanticError::UnexpectedAmount,
265 nativeBolt12SemanticError::UnsupportedCurrency => Bolt12SemanticError::UnsupportedCurrency,
266 nativeBolt12SemanticError::UnknownRequiredFeatures => Bolt12SemanticError::UnknownRequiredFeatures,
267 nativeBolt12SemanticError::UnexpectedFeatures => Bolt12SemanticError::UnexpectedFeatures,
268 nativeBolt12SemanticError::MissingDescription => Bolt12SemanticError::MissingDescription,
269 nativeBolt12SemanticError::MissingSigningPubkey => Bolt12SemanticError::MissingSigningPubkey,
270 nativeBolt12SemanticError::InvalidSigningPubkey => Bolt12SemanticError::InvalidSigningPubkey,
271 nativeBolt12SemanticError::UnexpectedSigningPubkey => Bolt12SemanticError::UnexpectedSigningPubkey,
272 nativeBolt12SemanticError::MissingQuantity => Bolt12SemanticError::MissingQuantity,
273 nativeBolt12SemanticError::InvalidQuantity => Bolt12SemanticError::InvalidQuantity,
274 nativeBolt12SemanticError::UnexpectedQuantity => Bolt12SemanticError::UnexpectedQuantity,
275 nativeBolt12SemanticError::InvalidMetadata => Bolt12SemanticError::InvalidMetadata,
276 nativeBolt12SemanticError::UnexpectedMetadata => Bolt12SemanticError::UnexpectedMetadata,
277 nativeBolt12SemanticError::MissingPayerMetadata => Bolt12SemanticError::MissingPayerMetadata,
278 nativeBolt12SemanticError::MissingPayerId => Bolt12SemanticError::MissingPayerId,
279 nativeBolt12SemanticError::MissingPaths => Bolt12SemanticError::MissingPaths,
280 nativeBolt12SemanticError::InvalidPayInfo => Bolt12SemanticError::InvalidPayInfo,
281 nativeBolt12SemanticError::MissingCreationTime => Bolt12SemanticError::MissingCreationTime,
282 nativeBolt12SemanticError::MissingPaymentHash => Bolt12SemanticError::MissingPaymentHash,
283 nativeBolt12SemanticError::MissingSignature => Bolt12SemanticError::MissingSignature,
287 /// Creates a copy of the Bolt12SemanticError
289 pub extern "C" fn Bolt12SemanticError_clone(orig: &Bolt12SemanticError) -> Bolt12SemanticError {
293 /// Utility method to constructs a new AlreadyExpired-variant Bolt12SemanticError
294 pub extern "C" fn Bolt12SemanticError_already_expired() -> Bolt12SemanticError {
295 Bolt12SemanticError::AlreadyExpired}
297 /// Utility method to constructs a new UnsupportedChain-variant Bolt12SemanticError
298 pub extern "C" fn Bolt12SemanticError_unsupported_chain() -> Bolt12SemanticError {
299 Bolt12SemanticError::UnsupportedChain}
301 /// Utility method to constructs a new UnexpectedChain-variant Bolt12SemanticError
302 pub extern "C" fn Bolt12SemanticError_unexpected_chain() -> Bolt12SemanticError {
303 Bolt12SemanticError::UnexpectedChain}
305 /// Utility method to constructs a new MissingAmount-variant Bolt12SemanticError
306 pub extern "C" fn Bolt12SemanticError_missing_amount() -> Bolt12SemanticError {
307 Bolt12SemanticError::MissingAmount}
309 /// Utility method to constructs a new InvalidAmount-variant Bolt12SemanticError
310 pub extern "C" fn Bolt12SemanticError_invalid_amount() -> Bolt12SemanticError {
311 Bolt12SemanticError::InvalidAmount}
313 /// Utility method to constructs a new InsufficientAmount-variant Bolt12SemanticError
314 pub extern "C" fn Bolt12SemanticError_insufficient_amount() -> Bolt12SemanticError {
315 Bolt12SemanticError::InsufficientAmount}
317 /// Utility method to constructs a new UnexpectedAmount-variant Bolt12SemanticError
318 pub extern "C" fn Bolt12SemanticError_unexpected_amount() -> Bolt12SemanticError {
319 Bolt12SemanticError::UnexpectedAmount}
321 /// Utility method to constructs a new UnsupportedCurrency-variant Bolt12SemanticError
322 pub extern "C" fn Bolt12SemanticError_unsupported_currency() -> Bolt12SemanticError {
323 Bolt12SemanticError::UnsupportedCurrency}
325 /// Utility method to constructs a new UnknownRequiredFeatures-variant Bolt12SemanticError
326 pub extern "C" fn Bolt12SemanticError_unknown_required_features() -> Bolt12SemanticError {
327 Bolt12SemanticError::UnknownRequiredFeatures}
329 /// Utility method to constructs a new UnexpectedFeatures-variant Bolt12SemanticError
330 pub extern "C" fn Bolt12SemanticError_unexpected_features() -> Bolt12SemanticError {
331 Bolt12SemanticError::UnexpectedFeatures}
333 /// Utility method to constructs a new MissingDescription-variant Bolt12SemanticError
334 pub extern "C" fn Bolt12SemanticError_missing_description() -> Bolt12SemanticError {
335 Bolt12SemanticError::MissingDescription}
337 /// Utility method to constructs a new MissingSigningPubkey-variant Bolt12SemanticError
338 pub extern "C" fn Bolt12SemanticError_missing_signing_pubkey() -> Bolt12SemanticError {
339 Bolt12SemanticError::MissingSigningPubkey}
341 /// Utility method to constructs a new InvalidSigningPubkey-variant Bolt12SemanticError
342 pub extern "C" fn Bolt12SemanticError_invalid_signing_pubkey() -> Bolt12SemanticError {
343 Bolt12SemanticError::InvalidSigningPubkey}
345 /// Utility method to constructs a new UnexpectedSigningPubkey-variant Bolt12SemanticError
346 pub extern "C" fn Bolt12SemanticError_unexpected_signing_pubkey() -> Bolt12SemanticError {
347 Bolt12SemanticError::UnexpectedSigningPubkey}
349 /// Utility method to constructs a new MissingQuantity-variant Bolt12SemanticError
350 pub extern "C" fn Bolt12SemanticError_missing_quantity() -> Bolt12SemanticError {
351 Bolt12SemanticError::MissingQuantity}
353 /// Utility method to constructs a new InvalidQuantity-variant Bolt12SemanticError
354 pub extern "C" fn Bolt12SemanticError_invalid_quantity() -> Bolt12SemanticError {
355 Bolt12SemanticError::InvalidQuantity}
357 /// Utility method to constructs a new UnexpectedQuantity-variant Bolt12SemanticError
358 pub extern "C" fn Bolt12SemanticError_unexpected_quantity() -> Bolt12SemanticError {
359 Bolt12SemanticError::UnexpectedQuantity}
361 /// Utility method to constructs a new InvalidMetadata-variant Bolt12SemanticError
362 pub extern "C" fn Bolt12SemanticError_invalid_metadata() -> Bolt12SemanticError {
363 Bolt12SemanticError::InvalidMetadata}
365 /// Utility method to constructs a new UnexpectedMetadata-variant Bolt12SemanticError
366 pub extern "C" fn Bolt12SemanticError_unexpected_metadata() -> Bolt12SemanticError {
367 Bolt12SemanticError::UnexpectedMetadata}
369 /// Utility method to constructs a new MissingPayerMetadata-variant Bolt12SemanticError
370 pub extern "C" fn Bolt12SemanticError_missing_payer_metadata() -> Bolt12SemanticError {
371 Bolt12SemanticError::MissingPayerMetadata}
373 /// Utility method to constructs a new MissingPayerId-variant Bolt12SemanticError
374 pub extern "C" fn Bolt12SemanticError_missing_payer_id() -> Bolt12SemanticError {
375 Bolt12SemanticError::MissingPayerId}
377 /// Utility method to constructs a new MissingPaths-variant Bolt12SemanticError
378 pub extern "C" fn Bolt12SemanticError_missing_paths() -> Bolt12SemanticError {
379 Bolt12SemanticError::MissingPaths}
381 /// Utility method to constructs a new InvalidPayInfo-variant Bolt12SemanticError
382 pub extern "C" fn Bolt12SemanticError_invalid_pay_info() -> Bolt12SemanticError {
383 Bolt12SemanticError::InvalidPayInfo}
385 /// Utility method to constructs a new MissingCreationTime-variant Bolt12SemanticError
386 pub extern "C" fn Bolt12SemanticError_missing_creation_time() -> Bolt12SemanticError {
387 Bolt12SemanticError::MissingCreationTime}
389 /// Utility method to constructs a new MissingPaymentHash-variant Bolt12SemanticError
390 pub extern "C" fn Bolt12SemanticError_missing_payment_hash() -> Bolt12SemanticError {
391 Bolt12SemanticError::MissingPaymentHash}
393 /// Utility method to constructs a new MissingSignature-variant Bolt12SemanticError
394 pub extern "C" fn Bolt12SemanticError_missing_signature() -> Bolt12SemanticError {
395 Bolt12SemanticError::MissingSignature}