//! 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:
//!
-//! * For parsing use `str::parse::<Invoice>(&self)` (see the docs of `impl FromStr for Invoice`)
-//! * For constructing invoices use the `InvoiceBuilder`
-//! * For serializing invoices use the `Display`/`ToString` traits
+//! * For parsing use `str::parse::<Invoice>(&self)` (see [`Invoice::from_str`])
+//! * For constructing invoices use the [`InvoiceBuilder`]
+//! * For serializing invoices use the [`Display`]/[`ToString`] traits
+//!
+//! [`Invoice::from_str`]: crate::Invoice#impl-FromStr
use alloc::str::FromStr;
use core::ffi::c_void;
/// Represents a syntactically and semantically correct lightning BOLT11 invoice.
///
/// There are three ways to construct an `Invoice`:
-/// 1. using `InvoiceBuilder`
-/// 2. using `Invoice::from_signed(SignedRawInvoice)`
-/// 3. using `str::parse::<Invoice>(&str)`
+/// 1. using [`InvoiceBuilder`]
+/// 2. using [`Invoice::from_signed`]
+/// 3. using `str::parse::<Invoice>(&str)` (see [`Invoice::from_str`])
+///
+/// [`Invoice::from_str`]: crate::Invoice#impl-FromStr
#[must_use]
#[repr(C)]
pub struct Invoice {
pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
orig.clone()
}
-/// Checks if two Invoices contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the Invoice.
#[no_mangle]
pub extern "C" fn Invoice_hash(o: &Invoice) -> u64 {
if o.inner.is_null() { return 0; }
use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
-/// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
+/// Represents a signed [`RawInvoice`] with cached hash. The signature is not checked and may be
/// invalid.
///
/// # Invariants
-/// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
+/// The hash has to be either from the deserialized invoice or from the serialized [`RawInvoice`].
#[must_use]
#[repr(C)]
pub struct SignedRawInvoice {
pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
orig.clone()
}
-/// Checks if two SignedRawInvoices contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the SignedRawInvoice.
#[no_mangle]
pub extern "C" fn SignedRawInvoice_hash(o: &SignedRawInvoice) -> u64 {
if o.inner.is_null() { return 0; }
use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
pub(crate) type nativeRawInvoice = nativeRawInvoiceImport;
-/// Represents an syntactically correct Invoice for a payment on the lightning network,
+/// Represents an syntactically correct [`Invoice`] for a payment on the lightning network,
/// but without the signature information.
-/// De- and encoding should not lead to information loss but may lead to different hashes.
+/// Decoding and encoding should not lead to information loss but may lead to different hashes.
///
-/// For methods without docs see the corresponding methods in `Invoice`.
+/// For methods without docs see the corresponding methods in [`Invoice`].
#[must_use]
#[repr(C)]
pub struct RawInvoice {
pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
orig.clone()
}
-/// Checks if two RawInvoices contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the RawInvoice.
#[no_mangle]
pub extern "C" fn RawInvoice_hash(o: &RawInvoice) -> u64 {
if o.inner.is_null() { return 0; }
use lightning_invoice::RawDataPart as nativeRawDataPartImport;
pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
-/// Data of the `RawInvoice` that is encoded in the data part
+/// Data of the [`RawInvoice`] that is encoded in the data part
#[must_use]
#[repr(C)]
pub struct RawDataPart {
pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
orig.clone()
}
-/// Checks if two RawDataParts contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the RawDataPart.
#[no_mangle]
pub extern "C" fn RawDataPart_hash(o: &RawDataPart) -> u64 {
if o.inner.is_null() { return 0; }
pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
orig.clone()
}
-/// Checks if two PositiveTimestamps contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the PositiveTimestamp.
#[no_mangle]
pub extern "C" fn PositiveTimestamp_hash(o: &PositiveTimestamp) -> u64 {
if o.inner.is_null() { return 0; }
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.
+/// Generates a non-cryptographic 64-bit hash of the SiPrefix.
#[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
/// Utility method to constructs a new Signet-variant Currency
pub extern "C" fn Currency_signet() -> Currency {
Currency::Signet}
-/// Checks if two Currencys contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the Currency.
#[no_mangle]
pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
// Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
orig.clone()
}
-/// Checks if two Sha256s contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the Sha256.
#[no_mangle]
pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
if o.inner.is_null() { return 0; }
if a.inner.is_null() || b.inner.is_null() { return false; }
if a.get_native_ref() == b.get_native_ref() { true } else { false }
}
+/// Constructs a new [`Sha256`] from the given bytes, which are assumed to be the output of a
+/// single sha256 hash.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Sha256_from_bytes(bytes: *const [u8; 32]) -> crate::lightning_invoice::Sha256 {
+ let mut ret = lightning_invoice::Sha256::from_bytes(unsafe { &*bytes});
+ crate::lightning_invoice::Sha256 { inner: ObjOps::heap_alloc(ret), is_owned: true }
+}
+
use lightning_invoice::Description as nativeDescriptionImport;
pub(crate) type nativeDescription = nativeDescriptionImport;
pub extern "C" fn Description_clone(orig: &Description) -> Description {
orig.clone()
}
-/// Checks if two Descriptions contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the Description.
#[no_mangle]
pub extern "C" fn Description_hash(o: &Description) -> u64 {
if o.inner.is_null() { return 0; }
pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
orig.clone()
}
-/// Checks if two PayeePubKeys contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the PayeePubKey.
#[no_mangle]
pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
if o.inner.is_null() { return 0; }
pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
orig.clone()
}
-/// Checks if two ExpiryTimes contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the ExpiryTime.
#[no_mangle]
pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
if o.inner.is_null() { return 0; }
pub extern "C" fn MinFinalCltvExpiryDelta_clone(orig: &MinFinalCltvExpiryDelta) -> MinFinalCltvExpiryDelta {
orig.clone()
}
-/// Checks if two MinFinalCltvExpiryDeltas contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the MinFinalCltvExpiryDelta.
#[no_mangle]
pub extern "C" fn MinFinalCltvExpiryDelta_hash(o: &MinFinalCltvExpiryDelta) -> u64 {
if o.inner.is_null() { return 0; }
#[repr(C)]
pub enum Fallback {
SegWitProgram {
- version: crate::c_types::U5,
+ version: crate::c_types::WitnessVersion,
program: crate::c_types::derived::CVec_u8Z,
},
PubKeyHash(
Fallback::PubKeyHash (ref a, ) => {
let mut a_nonref = Clone::clone(a);
nativeFallback::PubKeyHash (
- a_nonref.data,
+ bitcoin::hash_types::PubkeyHash::from_hash(bitcoin::hashes::Hash::from_inner(a_nonref.data)),
)
},
Fallback::ScriptHash (ref a, ) => {
let mut a_nonref = Clone::clone(a);
nativeFallback::ScriptHash (
- a_nonref.data,
+ bitcoin::hash_types::ScriptHash::from_hash(bitcoin::hashes::Hash::from_inner(a_nonref.data)),
)
},
}
},
Fallback::PubKeyHash (mut a, ) => {
nativeFallback::PubKeyHash (
- a.data,
+ bitcoin::hash_types::PubkeyHash::from_hash(bitcoin::hashes::Hash::from_inner(a.data)),
)
},
Fallback::ScriptHash (mut a, ) => {
nativeFallback::ScriptHash (
- a.data,
+ bitcoin::hash_types::ScriptHash::from_hash(bitcoin::hashes::Hash::from_inner(a.data)),
)
},
}
nativeFallback::PubKeyHash (ref a, ) => {
let mut a_nonref = Clone::clone(a);
Fallback::PubKeyHash (
- crate::c_types::TwentyBytes { data: a_nonref },
+ crate::c_types::TwentyBytes { data: a_nonref.as_hash().into_inner() },
)
},
nativeFallback::ScriptHash (ref a, ) => {
let mut a_nonref = Clone::clone(a);
Fallback::ScriptHash (
- crate::c_types::TwentyBytes { data: a_nonref },
+ crate::c_types::TwentyBytes { data: a_nonref.as_hash().into_inner() },
)
},
}
},
nativeFallback::PubKeyHash (mut a, ) => {
Fallback::PubKeyHash (
- crate::c_types::TwentyBytes { data: a },
+ crate::c_types::TwentyBytes { data: a.as_hash().into_inner() },
)
},
nativeFallback::ScriptHash (mut a, ) => {
Fallback::ScriptHash (
- crate::c_types::TwentyBytes { data: a },
+ crate::c_types::TwentyBytes { data: a.as_hash().into_inner() },
)
},
}
}
#[no_mangle]
/// Utility method to constructs a new SegWitProgram-variant Fallback
-pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::U5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
+pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::WitnessVersion, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
Fallback::SegWitProgram {
version,
program,
pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
Fallback::ScriptHash(a, )
}
-/// Checks if two Fallbacks contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the Fallback.
#[no_mangle]
pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
// Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
orig.clone()
}
-/// Checks if two InvoiceSignatures contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the InvoiceSignature.
#[no_mangle]
pub extern "C" fn InvoiceSignature_hash(o: &InvoiceSignature) -> u64 {
if o.inner.is_null() { return 0; }
pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
orig.clone()
}
-/// Checks if two PrivateRoutes contain equal inner contents.
+/// Generates a non-cryptographic 64-bit hash of the PrivateRoute.
#[no_mangle]
pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
if o.inner.is_null() { return 0; }
local_ret
}
-/// The `RawInvoice` which was signed.
+/// The [`RawInvoice`] which was signed.
#[must_use]
#[no_mangle]
pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawInvoice<>) as *mut _) }, is_owned: false }
}
-/// The hash of the `RawInvoice` that was signed.
+/// The hash of the [`RawInvoice`] that was signed.
#[must_use]
#[no_mangle]
pub extern "C" fn SignedRawInvoice_signable_hash(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> *const [u8; 32] {
ret
}
-/// InvoiceSignature for the invoice.
+/// Signature for the invoice.
#[must_use]
#[no_mangle]
pub extern "C" fn SignedRawInvoice_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
local_ret
}
+#[must_use]
+#[no_mangle]
+pub extern "C" fn RawInvoice_payment_metadata(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_metadata();
+ let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { let mut local_ret_0 = Vec::new(); for mut item in (*ret.as_ref().unwrap()).clone().drain(..) { local_ret_0.push( { item }); }; local_ret_0.into() }) };
+ local_ret
+}
+
///
/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
#[must_use]
ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
}
+/// The hash of the [`RawInvoice`] that was signed.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Invoice_signable_hash(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::ThirtyTwoBytes {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
+ crate::c_types::ThirtyTwoBytes { data: ret }
+}
+
/// Transform the `Invoice` into it's unchecked version
#[must_use]
#[no_mangle]
local_ret
}
-/// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
+/// Constructs an `Invoice` from a [`SignedRawInvoice`] by checking all its invariants.
/// ```
/// use lightning_invoice::*;
///
&ret.0
}
+/// Get the payment metadata blob if one was included in the invoice
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Invoice_payment_metadata(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_metadata();
+ let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { let mut local_ret_0 = Vec::new(); for mut item in (*ret.as_ref().unwrap()).clone().drain(..) { local_ret_0.push( { item }); }; local_ret_0.into() }) };
+ local_ret
+}
+
/// Get the invoice features if they were included in the invoice
///
/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
crate::c_types::PublicKey::from_rust(&ret)
}
+/// Returns the Duration since the Unix epoch at which the invoice expires.
+/// Returning None if overflow occurred.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Invoice_expires_at(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::COption_DurationZ {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expires_at();
+ let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_DurationZ::None } else { crate::c_types::derived::COption_DurationZ::Some( { ret.unwrap().as_secs() }) };
+ local_ret
+}
+
/// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
#[must_use]
#[no_mangle]
ret
}
+/// Returns the Duration remaining until the invoice expires.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Invoice_duration_until_expiry(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_until_expiry();
+ ret.as_secs()
+}
+
+/// Returns the Duration remaining until the invoice expires given the current time.
+/// `time` is the timestamp as a duration since the Unix epoch.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Invoice_expiration_remaining_from_epoch(this_arg: &crate::lightning_invoice::Invoice, mut time: u64) -> u64 {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiration_remaining_from_epoch(core::time::Duration::from_secs(time));
+ ret.as_secs()
+}
+
/// Returns whether the expiry time would pass at the given point in time.
/// `at_time` is the timestamp as a duration since the Unix epoch.
#[must_use]
ret
}
+/// Returns a list of all fallback addresses as [`Address`]es
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Invoice_fallback_addresses(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_AddressZ {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fallback_addresses();
+ let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { alloc::string::ToString::to_string(&item).into() }); };
+ local_ret.into()
+}
+
/// Returns a list of all routes included in the invoice
#[must_use]
#[no_mangle]
}
/// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
-/// returns `CreationError::DescriptionTooLong` otherwise
+/// returns [`CreationError::DescriptionTooLong`] otherwise
///
/// Please note that single characters may use more than one byte due to UTF8 encoding.
#[must_use]
local_ret
}
-/// Returns the underlying description `String`
+/// Returns the underlying description [`String`]
#[must_use]
#[no_mangle]
pub extern "C" fn Description_into_inner(mut this_arg: crate::lightning_invoice::Description) -> crate::c_types::Str {
crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
}
-/// Construct an `ExpiryTime` from a `Duration`, dropping the sub-second part.
+/// 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 {
ret
}
-/// Returns a reference to the underlying `Duration` (=expiry time)
+/// Returns a reference to the underlying [`Duration`] (=expiry time)
#[must_use]
#[no_mangle]
pub extern "C" fn ExpiryTime_as_duration(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
}
-/// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
+/// Errors that may occur when constructing a new [`RawInvoice`] or [`Invoice`]
#[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))
+ /// The supplied description string was longer than 639 __bytes__ (see [`Description::new`])
DescriptionTooLong,
/// The specified route has too many hops and can't be encoded
RouteTooLong,
pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
alloc::format!("{}", &o.to_native()).into()
}
-/// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
+/// Errors that may occur when converting a [`RawInvoice`] to an [`Invoice`]. They relate to the
/// requirements sections in BOLT #11
#[derive(Clone)]
#[must_use]
pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
alloc::format!("{}", &o.to_native()).into()
}
-/// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
+/// When signing using a fallible method either an user-supplied `SignError` or a [`CreationError`]
/// may occur.
#[derive(Clone)]
#[must_use]