// source was automatically generated.
//! This crate provides data structures to represent
-//! [lightning BOLT11](https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md)
+//! [lightning BOLT11](https://github.com/lightning/bolts/blob/master/11-payment-encoding.md)
//! invoices and functions to create, encode and decode these. If you just want to use the standard
//! en-/decoding functionality this should get you started:
//!
pub mod payment;
pub mod utils;
pub mod constants;
+mod time_utils {
+
+use alloc::str::FromStr;
+use core::ffi::c_void;
+use core::convert::Infallible;
+use bitcoin::hashes::Hash;
+use crate::c_types::*;
+#[cfg(feature="no-std")]
+use alloc::{vec::Vec, boxed::Box};
+
+}
mod de {
use alloc::str::FromStr;
}
/// Errors that indicate what is wrong with the invoice. They have some granularity for debug
/// reasons, but should generally result in an \"invalid BOLT11 invoice\" message for the user.
-#[must_use]
#[derive(Clone)]
+#[must_use]
#[repr(C)]
pub enum ParseError {
- Bech32Error(crate::c_types::Bech32Error),
- ParseAmountError(crate::c_types::Error),
- MalformedSignature(crate::c_types::Secp256k1Error),
+ Bech32Error(
+ crate::c_types::Bech32Error),
+ ParseAmountError(
+ crate::c_types::Error),
+ MalformedSignature(
+ crate::c_types::Secp256k1Error),
BadPrefix,
UnknownCurrency,
UnknownSiPrefix,
MalformedHRP,
TooShortDataPart,
UnexpectedEndOfTaggedFields,
- DescriptionDecodeError(crate::c_types::Error),
+ DescriptionDecodeError(
+ crate::c_types::Error),
PaddingError,
IntegerOverflowError,
InvalidSegWitProgramLength,
InvalidPubKeyHashLength,
InvalidScriptHashLength,
InvalidRecoveryId,
- InvalidSliceLength(crate::c_types::Str),
+ InvalidSliceLength(
+ crate::c_types::Str),
/// Not an error, but used internally to signal that a part of the invoice should be ignored
/// according to BOLT11
Skip,
}
-use lightning_invoice::ParseError as nativeParseError;
+use lightning_invoice::ParseError as ParseErrorImport;
+pub(crate) type nativeParseError = ParseErrorImport;
+
impl ParseError {
#[allow(unused)]
pub(crate) fn to_native(&self) -> nativeParseError {
/// Utility method to constructs a new Skip-variant ParseError
pub extern "C" fn ParseError_skip() -> ParseError {
ParseError::Skip}
+/// Checks if two ParseErrors contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn ParseError_eq(a: &ParseError, b: &ParseError) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
/// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
/// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
/// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
-#[must_use]
#[derive(Clone)]
+#[must_use]
#[repr(C)]
pub enum ParseOrSemanticError {
/// The invoice couldn't be decoded
- ParseError(crate::lightning_invoice::ParseError),
+ ParseError(
+ crate::lightning_invoice::ParseError),
/// The invoice could be decoded but violates the BOLT11 standard
- SemanticError(crate::lightning_invoice::SemanticError),
+ SemanticError(
+ crate::lightning_invoice::SemanticError),
}
-use lightning_invoice::ParseOrSemanticError as nativeParseOrSemanticError;
+use lightning_invoice::ParseOrSemanticError as ParseOrSemanticErrorImport;
+pub(crate) type nativeParseOrSemanticError = ParseOrSemanticErrorImport;
+
impl ParseOrSemanticError {
#[allow(unused)]
pub(crate) fn to_native(&self) -> nativeParseOrSemanticError {
pub extern "C" fn ParseOrSemanticError_semantic_error(a: crate::lightning_invoice::SemanticError) -> ParseOrSemanticError {
ParseOrSemanticError::SemanticError(a, )
}
+/// Checks if two ParseOrSemanticErrors contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn ParseOrSemanticError_eq(a: &ParseOrSemanticError, b: &ParseOrSemanticError) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
/// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
///
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
orig.clone()
}
+/// Checks if two Invoices contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn Invoice_hash(o: &Invoice) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
orig.clone()
}
+/// Checks if two SignedRawInvoices contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn SignedRawInvoice_hash(o: &SignedRawInvoice) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
pub(crate) type nativeRawInvoice = nativeRawInvoiceImport;
pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
orig.clone()
}
+/// Checks if two RawInvoices contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn RawInvoice_hash(o: &RawInvoice) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
use lightning_invoice::RawDataPart as nativeRawDataPartImport;
pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
orig.clone()
}
+/// Checks if two RawDataParts contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn RawDataPart_hash(o: &RawDataPart) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
orig.clone()
}
+/// Checks if two PositiveTimestamps contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn PositiveTimestamp_hash(o: &PositiveTimestamp) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
/// SI prefixes for the human readable part
-#[must_use]
#[derive(Clone)]
+#[must_use]
#[repr(C)]
pub enum SiPrefix {
/// 10^-3
/// 10^-12
Pico,
}
-use lightning_invoice::SiPrefix as nativeSiPrefix;
+use lightning_invoice::SiPrefix as SiPrefixImport;
+pub(crate) type nativeSiPrefix = SiPrefixImport;
+
impl SiPrefix {
#[allow(unused)]
pub(crate) fn to_native(&self) -> nativeSiPrefix {
pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
if &a.to_native() == &b.to_native() { true } else { false }
}
+/// Checks if two SiPrefixs contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn SiPrefix_hash(o: &SiPrefix) -> u64 {
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(&o.to_native(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
/// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
/// This is effectively 10^12 * the prefix multiplier
#[must_use]
}
/// Enum representing the crypto currencies (or networks) supported by this library
-#[must_use]
#[derive(Clone)]
+#[must_use]
#[repr(C)]
pub enum Currency {
/// Bitcoin mainnet
/// Bitcoin signet
Signet,
}
-use lightning_invoice::Currency as nativeCurrency;
+use lightning_invoice::Currency as CurrencyImport;
+pub(crate) type nativeCurrency = CurrencyImport;
+
impl Currency {
#[allow(unused)]
pub(crate) fn to_native(&self) -> nativeCurrency {
if a.get_native_ref() == b.get_native_ref() { true } else { false }
}
/// Fallback address in case no LN payment is possible
-#[must_use]
#[derive(Clone)]
+#[must_use]
#[repr(C)]
pub enum Fallback {
SegWitProgram {
version: crate::c_types::u5,
program: crate::c_types::derived::CVec_u8Z,
},
- PubKeyHash(crate::c_types::TwentyBytes),
- ScriptHash(crate::c_types::TwentyBytes),
+ PubKeyHash(
+ crate::c_types::TwentyBytes),
+ ScriptHash(
+ crate::c_types::TwentyBytes),
}
-use lightning_invoice::Fallback as nativeFallback;
+use lightning_invoice::Fallback as FallbackImport;
+pub(crate) type nativeFallback = FallbackImport;
+
impl Fallback {
#[allow(unused)]
pub(crate) fn to_native(&self) -> nativeFallback {
orig.clone()
}
/// Checks if two InvoiceSignatures contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn InvoiceSignature_hash(o: &InvoiceSignature) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
+/// Checks if two InvoiceSignatures contain equal inner contents.
/// This ignores pointers and is_owned flags and looks at the values in fields.
/// Two objects with NULL inner values will be considered "equal" here.
#[no_mangle]
/// The hash of the `RawInvoice` that was signed.
#[must_use]
#[no_mangle]
-pub extern "C" fn SignedRawInvoice_hash(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> *const [u8; 32] {
- let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
+pub extern "C" fn SignedRawInvoice_signable_hash(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> *const [u8; 32] {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
ret
}
ret
}
-/// Calculate the hash of the encoded `RawInvoice`
+/// Calculate the hash of the encoded `RawInvoice` which should be signed.
#[must_use]
#[no_mangle]
-pub extern "C" fn RawInvoice_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
- let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
+pub extern "C" fn RawInvoice_signable_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
crate::c_types::ThirtyTwoBytes { data: ret }
}
/// Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
/// the range `0..=MAX_TIMESTAMP`.
///
+/// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
+///
/// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
#[must_use]
#[no_mangle]
/// Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range
/// `0..=MAX_TIMESTAMP`.
///
+/// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
+///
/// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
#[must_use]
#[no_mangle]
crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
}
-/// Construct an `ExpiryTime` from a `Duration`.
+/// Construct an `ExpiryTime` from a `Duration`, dropping the sub-second part.
#[must_use]
#[no_mangle]
pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime {
}
/// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
-#[must_use]
#[derive(Clone)]
+#[must_use]
#[repr(C)]
pub enum CreationError {
/// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
/// [phantom invoices]: crate::utils::create_phantom_invoice
MissingRouteHints,
}
-use lightning_invoice::CreationError as nativeCreationError;
+use lightning_invoice::CreationError as CreationErrorImport;
+pub(crate) type nativeCreationError = CreationErrorImport;
+
impl CreationError {
#[allow(unused)]
pub(crate) fn to_native(&self) -> nativeCreationError {
}
/// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
/// requirements sections in BOLT #11
-#[must_use]
#[derive(Clone)]
+#[must_use]
#[repr(C)]
pub enum SemanticError {
/// The invoice is missing the mandatory payment hash
/// The invoice's amount was not a whole number of millisatoshis
ImpreciseAmount,
}
-use lightning_invoice::SemanticError as nativeSemanticError;
+use lightning_invoice::SemanticError as SemanticErrorImport;
+pub(crate) type nativeSemanticError = SemanticErrorImport;
+
impl SemanticError {
#[allow(unused)]
pub(crate) fn to_native(&self) -> nativeSemanticError {
}
/// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
/// may occur.
-#[must_use]
#[derive(Clone)]
+#[must_use]
#[repr(C)]
pub enum SignOrCreationError {
/// An error occurred during signing
SignError,
/// An error occurred while building the transaction
- CreationError(crate::lightning_invoice::CreationError),
+ CreationError(
+ crate::lightning_invoice::CreationError),
}
-use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
+use lightning_invoice::SignOrCreationError as SignOrCreationErrorImport;
+pub(crate) type nativeSignOrCreationError = SignOrCreationErrorImport<>;
+
impl SignOrCreationError {
#[allow(unused)]
pub(crate) fn to_native(&self) -> nativeSignOrCreationError {