X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning_invoice%2Fmod.rs;h=4b12f320c9fe1c94ad7b5bcd2f5f6efddafacd95;hb=11b997c3a0452ea1da5b7b352e7887798105db29;hp=53314331cf26b146aa5665b794bb1808cf1d2822;hpb=18337a0191c3abdca8d51861c328dd3d2d9ca6b7;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning_invoice/mod.rs b/lightning-c-bindings/src/lightning_invoice/mod.rs index 5331433..4b12f32 100644 --- a/lightning-c-bindings/src/lightning_invoice/mod.rs +++ b/lightning-c-bindings/src/lightning_invoice/mod.rs @@ -7,7 +7,7 @@ // 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: //! @@ -15,141 +15,611 @@ //! * For constructing invoices use the `InvoiceBuilder` //! * For serializing invoices use the `Display`/`ToString` traits -use std::str::FromStr; -use std::ffi::c_void; +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}; 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 std::str::FromStr; -use std::ffi::c_void; +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 hrp_sm { -use std::str::FromStr; -use std::ffi::c_void; +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}; } #[no_mangle] /// Read a SiPrefix object from a string -pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixNoneZ { +pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixParseErrorZ { match lightning_invoice::SiPrefix::from_str(s.into_str()) { Ok(r) => { crate::c_types::CResultTempl::ok( crate::lightning_invoice::SiPrefix::native_into(r) ) }, - Err(e) => crate::c_types::CResultTempl::err(()), + Err(e) => { + crate::c_types::CResultTempl::err( + crate::lightning_invoice::ParseError::native_into(e) + ) + }, }.into() } #[no_mangle] /// Read a Invoice object from a string -pub extern "C" fn Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_InvoiceNoneZ { +pub extern "C" fn Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_InvoiceParseOrSemanticErrorZ { match lightning_invoice::Invoice::from_str(s.into_str()) { Ok(r) => { crate::c_types::CResultTempl::ok( crate::lightning_invoice::Invoice { inner: ObjOps::heap_alloc(r), is_owned: true } ) }, - Err(e) => crate::c_types::CResultTempl::err(()), + Err(e) => { + crate::c_types::CResultTempl::err( + crate::lightning_invoice::ParseOrSemanticError::native_into(e) + ) + }, }.into() } #[no_mangle] /// Read a SignedRawInvoice object from a string -pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawInvoiceNoneZ { +pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawInvoiceParseErrorZ { match lightning_invoice::SignedRawInvoice::from_str(s.into_str()) { Ok(r) => { crate::c_types::CResultTempl::ok( crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(r), is_owned: true } ) }, - Err(e) => crate::c_types::CResultTempl::err(()), + Err(e) => { + crate::c_types::CResultTempl::err( + crate::lightning_invoice::ParseError::native_into(e) + ) + }, }.into() } +#[no_mangle] +/// Get the string representation of a ParseError object +pub extern "C" fn ParseError_to_str(o: &crate::lightning_invoice::ParseError) -> Str { + alloc::format!("{}", &o.to_native()).into() +} +#[no_mangle] +/// Get the string representation of a ParseOrSemanticError object +pub extern "C" fn ParseOrSemanticError_to_str(o: &crate::lightning_invoice::ParseOrSemanticError) -> Str { + alloc::format!("{}", &o.to_native()).into() +} } mod ser { -use std::str::FromStr; -use std::ffi::c_void; +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}; #[no_mangle] /// Get the string representation of a Invoice object pub extern "C" fn Invoice_to_str(o: &crate::lightning_invoice::Invoice) -> Str { - format!("{}", o.get_native_ref()).into() + alloc::format!("{}", o.get_native_ref()).into() } #[no_mangle] /// Get the string representation of a SignedRawInvoice object pub extern "C" fn SignedRawInvoice_to_str(o: &crate::lightning_invoice::SignedRawInvoice) -> Str { - format!("{}", o.get_native_ref()).into() + alloc::format!("{}", o.get_native_ref()).into() } #[no_mangle] /// Get the string representation of a Currency object pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str { - format!("{}", &o.to_native()).into() + alloc::format!("{}", &o.to_native()).into() } #[no_mangle] /// Get the string representation of a SiPrefix object pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str { - format!("{}", &o.to_native()).into() + alloc::format!("{}", &o.to_native()).into() } } mod tb { -use std::str::FromStr; -use std::ffi::c_void; +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 prelude { + +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 sync { + +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}; + +} +/// 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. +#[derive(Clone)] +#[must_use] +#[repr(C)] +pub enum ParseError { + 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), + PaddingError, + IntegerOverflowError, + InvalidSegWitProgramLength, + InvalidPubKeyHashLength, + InvalidScriptHashLength, + InvalidRecoveryId, + 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 ParseErrorImport; +pub(crate) type nativeParseError = ParseErrorImport; +impl ParseError { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeParseError { + match self { + ParseError::Bech32Error (ref a, ) => { + let mut a_nonref = Clone::clone(a); + nativeParseError::Bech32Error ( + a_nonref.into_rust(), + ) + }, + ParseError::ParseAmountError (ref a, ) => { + let mut a_nonref = Clone::clone(a); + nativeParseError::ParseAmountError ( + u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/, + ) + }, + ParseError::MalformedSignature (ref a, ) => { + let mut a_nonref = Clone::clone(a); + nativeParseError::MalformedSignature ( + a_nonref.into_rust(), + ) + }, + ParseError::BadPrefix => nativeParseError::BadPrefix, + ParseError::UnknownCurrency => nativeParseError::UnknownCurrency, + ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix, + ParseError::MalformedHRP => nativeParseError::MalformedHRP, + ParseError::TooShortDataPart => nativeParseError::TooShortDataPart, + ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields, + ParseError::DescriptionDecodeError (ref a, ) => { + let mut a_nonref = Clone::clone(a); + nativeParseError::DescriptionDecodeError ( + core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/, + ) + }, + ParseError::PaddingError => nativeParseError::PaddingError, + ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError, + ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength, + ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength, + ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength, + ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId, + ParseError::InvalidSliceLength (ref a, ) => { + let mut a_nonref = Clone::clone(a); + nativeParseError::InvalidSliceLength ( + a_nonref.into_string(), + ) + }, + ParseError::Skip => nativeParseError::Skip, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeParseError { + match self { + ParseError::Bech32Error (mut a, ) => { + nativeParseError::Bech32Error ( + a.into_rust(), + ) + }, + ParseError::ParseAmountError (mut a, ) => { + nativeParseError::ParseAmountError ( + u8::from_str_radix(" a", 10).unwrap_err() /*a*/, + ) + }, + ParseError::MalformedSignature (mut a, ) => { + nativeParseError::MalformedSignature ( + a.into_rust(), + ) + }, + ParseError::BadPrefix => nativeParseError::BadPrefix, + ParseError::UnknownCurrency => nativeParseError::UnknownCurrency, + ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix, + ParseError::MalformedHRP => nativeParseError::MalformedHRP, + ParseError::TooShortDataPart => nativeParseError::TooShortDataPart, + ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields, + ParseError::DescriptionDecodeError (mut a, ) => { + nativeParseError::DescriptionDecodeError ( + core::str::from_utf8(&[0xff]).unwrap_err() /*a*/, + ) + }, + ParseError::PaddingError => nativeParseError::PaddingError, + ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError, + ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength, + ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength, + ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength, + ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId, + ParseError::InvalidSliceLength (mut a, ) => { + nativeParseError::InvalidSliceLength ( + a.into_string(), + ) + }, + ParseError::Skip => nativeParseError::Skip, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &nativeParseError) -> Self { + match native { + nativeParseError::Bech32Error (ref a, ) => { + let mut a_nonref = Clone::clone(a); + ParseError::Bech32Error ( + crate::c_types::Bech32Error::from_rust(a_nonref), + ) + }, + nativeParseError::ParseAmountError (ref a, ) => { + let mut a_nonref = Clone::clone(a); + ParseError::ParseAmountError ( + crate::c_types::Error { _dummy: 0 } /*a_nonref*/, + ) + }, + nativeParseError::MalformedSignature (ref a, ) => { + let mut a_nonref = Clone::clone(a); + ParseError::MalformedSignature ( + crate::c_types::Secp256k1Error::from_rust(a_nonref), + ) + }, + nativeParseError::BadPrefix => ParseError::BadPrefix, + nativeParseError::UnknownCurrency => ParseError::UnknownCurrency, + nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix, + nativeParseError::MalformedHRP => ParseError::MalformedHRP, + nativeParseError::TooShortDataPart => ParseError::TooShortDataPart, + nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields, + nativeParseError::DescriptionDecodeError (ref a, ) => { + let mut a_nonref = Clone::clone(a); + ParseError::DescriptionDecodeError ( + crate::c_types::Error { _dummy: 0 } /*a_nonref*/, + ) + }, + nativeParseError::PaddingError => ParseError::PaddingError, + nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError, + nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength, + nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength, + nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength, + nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId, + nativeParseError::InvalidSliceLength (ref a, ) => { + let mut a_nonref = Clone::clone(a); + ParseError::InvalidSliceLength ( + a_nonref.into(), + ) + }, + nativeParseError::Skip => ParseError::Skip, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeParseError) -> Self { + match native { + nativeParseError::Bech32Error (mut a, ) => { + ParseError::Bech32Error ( + crate::c_types::Bech32Error::from_rust(a), + ) + }, + nativeParseError::ParseAmountError (mut a, ) => { + ParseError::ParseAmountError ( + crate::c_types::Error { _dummy: 0 } /*a*/, + ) + }, + nativeParseError::MalformedSignature (mut a, ) => { + ParseError::MalformedSignature ( + crate::c_types::Secp256k1Error::from_rust(a), + ) + }, + nativeParseError::BadPrefix => ParseError::BadPrefix, + nativeParseError::UnknownCurrency => ParseError::UnknownCurrency, + nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix, + nativeParseError::MalformedHRP => ParseError::MalformedHRP, + nativeParseError::TooShortDataPart => ParseError::TooShortDataPart, + nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields, + nativeParseError::DescriptionDecodeError (mut a, ) => { + ParseError::DescriptionDecodeError ( + crate::c_types::Error { _dummy: 0 } /*a*/, + ) + }, + nativeParseError::PaddingError => ParseError::PaddingError, + nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError, + nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength, + nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength, + nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength, + nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId, + nativeParseError::InvalidSliceLength (mut a, ) => { + ParseError::InvalidSliceLength ( + a.into(), + ) + }, + nativeParseError::Skip => ParseError::Skip, + } + } +} +/// Frees any resources used by the ParseError +#[no_mangle] +pub extern "C" fn ParseError_free(this_ptr: ParseError) { } +/// Creates a copy of the ParseError +#[no_mangle] +pub extern "C" fn ParseError_clone(orig: &ParseError) -> ParseError { + orig.clone() +} +#[no_mangle] +/// Utility method to constructs a new Bech32Error-variant ParseError +pub extern "C" fn ParseError_bech32_error(a: crate::c_types::Bech32Error) -> ParseError { + ParseError::Bech32Error(a, ) +} +#[no_mangle] +/// Utility method to constructs a new ParseAmountError-variant ParseError +pub extern "C" fn ParseError_parse_amount_error(a: crate::c_types::Error) -> ParseError { + ParseError::ParseAmountError(a, ) +} +#[no_mangle] +/// Utility method to constructs a new MalformedSignature-variant ParseError +pub extern "C" fn ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> ParseError { + ParseError::MalformedSignature(a, ) +} +#[no_mangle] +/// Utility method to constructs a new BadPrefix-variant ParseError +pub extern "C" fn ParseError_bad_prefix() -> ParseError { + ParseError::BadPrefix} +#[no_mangle] +/// Utility method to constructs a new UnknownCurrency-variant ParseError +pub extern "C" fn ParseError_unknown_currency() -> ParseError { + ParseError::UnknownCurrency} +#[no_mangle] +/// Utility method to constructs a new UnknownSiPrefix-variant ParseError +pub extern "C" fn ParseError_unknown_si_prefix() -> ParseError { + ParseError::UnknownSiPrefix} +#[no_mangle] +/// Utility method to constructs a new MalformedHRP-variant ParseError +pub extern "C" fn ParseError_malformed_hrp() -> ParseError { + ParseError::MalformedHRP} +#[no_mangle] +/// Utility method to constructs a new TooShortDataPart-variant ParseError +pub extern "C" fn ParseError_too_short_data_part() -> ParseError { + ParseError::TooShortDataPart} +#[no_mangle] +/// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant ParseError +pub extern "C" fn ParseError_unexpected_end_of_tagged_fields() -> ParseError { + ParseError::UnexpectedEndOfTaggedFields} +#[no_mangle] +/// Utility method to constructs a new DescriptionDecodeError-variant ParseError +pub extern "C" fn ParseError_description_decode_error(a: crate::c_types::Error) -> ParseError { + ParseError::DescriptionDecodeError(a, ) +} +#[no_mangle] +/// Utility method to constructs a new PaddingError-variant ParseError +pub extern "C" fn ParseError_padding_error() -> ParseError { + ParseError::PaddingError} +#[no_mangle] +/// Utility method to constructs a new IntegerOverflowError-variant ParseError +pub extern "C" fn ParseError_integer_overflow_error() -> ParseError { + ParseError::IntegerOverflowError} +#[no_mangle] +/// Utility method to constructs a new InvalidSegWitProgramLength-variant ParseError +pub extern "C" fn ParseError_invalid_seg_wit_program_length() -> ParseError { + ParseError::InvalidSegWitProgramLength} +#[no_mangle] +/// Utility method to constructs a new InvalidPubKeyHashLength-variant ParseError +pub extern "C" fn ParseError_invalid_pub_key_hash_length() -> ParseError { + ParseError::InvalidPubKeyHashLength} +#[no_mangle] +/// Utility method to constructs a new InvalidScriptHashLength-variant ParseError +pub extern "C" fn ParseError_invalid_script_hash_length() -> ParseError { + ParseError::InvalidScriptHashLength} +#[no_mangle] +/// Utility method to constructs a new InvalidRecoveryId-variant ParseError +pub extern "C" fn ParseError_invalid_recovery_id() -> ParseError { + ParseError::InvalidRecoveryId} +#[no_mangle] +/// Utility method to constructs a new InvalidSliceLength-variant ParseError +pub extern "C" fn ParseError_invalid_slice_length(a: crate::c_types::Str) -> ParseError { + ParseError::InvalidSliceLength(a, ) +} +#[no_mangle] +/// 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. +#[derive(Clone)] +#[must_use] +#[repr(C)] +pub enum ParseOrSemanticError { + /// The invoice couldn't be decoded + ParseError( + crate::lightning_invoice::ParseError), + /// The invoice could be decoded but violates the BOLT11 standard + SemanticError( + crate::lightning_invoice::SemanticError), +} +use lightning_invoice::ParseOrSemanticError as ParseOrSemanticErrorImport; +pub(crate) type nativeParseOrSemanticError = ParseOrSemanticErrorImport; + +impl ParseOrSemanticError { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeParseOrSemanticError { + match self { + ParseOrSemanticError::ParseError (ref a, ) => { + let mut a_nonref = Clone::clone(a); + nativeParseOrSemanticError::ParseError ( + a_nonref.into_native(), + ) + }, + ParseOrSemanticError::SemanticError (ref a, ) => { + let mut a_nonref = Clone::clone(a); + nativeParseOrSemanticError::SemanticError ( + a_nonref.into_native(), + ) + }, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeParseOrSemanticError { + match self { + ParseOrSemanticError::ParseError (mut a, ) => { + nativeParseOrSemanticError::ParseError ( + a.into_native(), + ) + }, + ParseOrSemanticError::SemanticError (mut a, ) => { + nativeParseOrSemanticError::SemanticError ( + a.into_native(), + ) + }, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &nativeParseOrSemanticError) -> Self { + match native { + nativeParseOrSemanticError::ParseError (ref a, ) => { + let mut a_nonref = Clone::clone(a); + ParseOrSemanticError::ParseError ( + crate::lightning_invoice::ParseError::native_into(a_nonref), + ) + }, + nativeParseOrSemanticError::SemanticError (ref a, ) => { + let mut a_nonref = Clone::clone(a); + ParseOrSemanticError::SemanticError ( + crate::lightning_invoice::SemanticError::native_into(a_nonref), + ) + }, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeParseOrSemanticError) -> Self { + match native { + nativeParseOrSemanticError::ParseError (mut a, ) => { + ParseOrSemanticError::ParseError ( + crate::lightning_invoice::ParseError::native_into(a), + ) + }, + nativeParseOrSemanticError::SemanticError (mut a, ) => { + ParseOrSemanticError::SemanticError ( + crate::lightning_invoice::SemanticError::native_into(a), + ) + }, + } + } } +/// Frees any resources used by the ParseOrSemanticError +#[no_mangle] +pub extern "C" fn ParseOrSemanticError_free(this_ptr: ParseOrSemanticError) { } +/// Creates a copy of the ParseOrSemanticError +#[no_mangle] +pub extern "C" fn ParseOrSemanticError_clone(orig: &ParseOrSemanticError) -> ParseOrSemanticError { + orig.clone() +} +#[no_mangle] +/// Utility method to constructs a new ParseError-variant ParseOrSemanticError +pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::ParseError) -> ParseOrSemanticError { + ParseOrSemanticError::ParseError(a, ) +} +#[no_mangle] +/// Utility method to constructs a new SemanticError-variant ParseOrSemanticError +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 + +#[no_mangle] +pub static MAX_TIMESTAMP: u64 = lightning_invoice::MAX_TIMESTAMP; /// Default expiry time as defined by [BOLT 11]. /// -/// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md +/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md #[no_mangle] pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME; /// Default minimum final CLTV expiry as defined by [BOLT 11]. /// /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is -/// provided in [`MIN_FINAL_CLTV_EXPIRY`]. +/// provided in [`MIN_FINAL_CLTV_EXPIRY_DELTA`]. /// -/// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md -/// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY +/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md +/// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA #[no_mangle] -pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY; -/// **Call this function on startup to ensure that all assumptions about the platform are valid.** -/// -/// Unfortunately we have to make assumptions about the upper bounds of the `SystemTime` type on -/// your platform which we can't fully verify at compile time and which isn't part of it's contract. -/// To our best knowledge our assumptions hold for all platforms officially supported by rust, but -/// since this check is fast we recommend to do it anyway. -/// -/// If this function fails this is considered a bug. Please open an issue describing your -/// platform and stating your current system time. -/// -/// # Panics -/// If the check fails this function panics. By calling this function on startup you ensure that -/// this wont happen at an arbitrary later point in time. -#[no_mangle] -pub extern "C" fn check_platform() { - lightning_invoice::check_platform() -} - +pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA; use lightning_invoice::Invoice as nativeInvoiceImport; pub(crate) type nativeInvoice = nativeInvoiceImport; @@ -188,7 +658,7 @@ pub extern "C" fn Invoice_free(this_obj: Invoice) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Invoice_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInvoice) }; } #[allow(unused)] impl Invoice { @@ -202,7 +672,7 @@ impl Invoice { pub(crate) fn take_inner(mut self) -> *mut nativeInvoice { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -218,7 +688,7 @@ pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool { impl Clone for Invoice { fn clone(&self) -> Self { Self { - inner: if <*mut nativeInvoice>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeInvoice>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -234,6 +704,16 @@ pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_v 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; @@ -271,7 +751,7 @@ pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSignedRawInvoice) }; } #[allow(unused)] impl SignedRawInvoice { @@ -285,7 +765,7 @@ impl SignedRawInvoice { pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -301,7 +781,7 @@ pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice impl Clone for SignedRawInvoice { fn clone(&self) -> Self { Self { - inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -317,6 +797,16 @@ pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> 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; @@ -354,7 +844,7 @@ pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawInvoice) }; } #[allow(unused)] impl RawInvoice { @@ -368,7 +858,7 @@ impl RawInvoice { pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -395,7 +885,7 @@ pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool { impl Clone for RawInvoice { fn clone(&self) -> Self { Self { - inner: if <*mut nativeRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -411,6 +901,16 @@ pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut 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; @@ -444,7 +944,7 @@ pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawDataPart) }; } #[allow(unused)] impl RawDataPart { @@ -458,7 +958,7 @@ impl RawDataPart { pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -485,7 +985,7 @@ pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool { impl Clone for RawDataPart { fn clone(&self) -> Self { Self { - inner: if <*mut nativeRawDataPart>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -501,16 +1001,26 @@ pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut 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; -/// A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX -/// timestamp is positive. +/// A timestamp that refers to a date after 1 January 1970. /// /// # Invariants -/// The UNIX timestamp representing the stored time has to be positive and small enough so that -/// a `EpiryTime` can be added to it without an overflow. +/// +/// The Unix timestamp representing the stored time has to be positive and no greater than +/// [`MAX_TIMESTAMP`]. #[must_use] #[repr(C)] pub struct PositiveTimestamp { @@ -539,7 +1049,7 @@ pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativePositiveTimestamp) }; } #[allow(unused)] impl PositiveTimestamp { @@ -553,7 +1063,7 @@ impl PositiveTimestamp { pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -569,7 +1079,7 @@ pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimest impl Clone for PositiveTimestamp { fn clone(&self) -> Self { Self { - inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -585,9 +1095,19 @@ pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) - 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 @@ -599,7 +1119,9 @@ pub enum SiPrefix { /// 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 { @@ -665,18 +1187,27 @@ pub extern "C" fn SiPrefix_pico() -> SiPrefix { 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] #[no_mangle] -pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 { +pub extern "C" fn SiPrefix_multiplier(this_arg: &crate::lightning_invoice::SiPrefix) -> u64 { let mut ret = this_arg.to_native().multiplier(); ret } /// Enum representing the crypto currencies (or networks) supported by this library -#[must_use] #[derive(Clone)] +#[must_use] #[repr(C)] pub enum Currency { /// Bitcoin mainnet @@ -690,7 +1221,9 @@ pub enum Currency { /// 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 { @@ -761,11 +1294,11 @@ pub extern "C" fn Currency_signet() -> Currency { /// Checks if two Currencys contain equal inner contents. #[no_mangle] pub extern "C" fn Currency_hash(o: &Currency) -> u64 { - // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core + // 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(); - std::hash::Hash::hash(&o.to_native(), &mut hasher); - std::hash::Hasher::finish(&hasher) + core::hash::Hash::hash(&o.to_native(), &mut hasher); + core::hash::Hasher::finish(&hasher) } /// Checks if two Currencys contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. @@ -806,7 +1339,7 @@ pub extern "C" fn Sha256_free(this_obj: Sha256) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSha256) }; } #[allow(unused)] impl Sha256 { @@ -820,14 +1353,14 @@ impl Sha256 { pub(crate) fn take_inner(mut self) -> *mut nativeSha256 { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } impl Clone for Sha256 { fn clone(&self) -> Self { Self { - inner: if <*mut nativeSha256>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -847,11 +1380,11 @@ pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 { #[no_mangle] pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 { if o.inner.is_null() { return 0; } - // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core + // 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(); - std::hash::Hash::hash(o.get_native_ref(), &mut hasher); - std::hash::Hasher::finish(&hasher) + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) } /// Checks if two Sha256s contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. @@ -898,7 +1431,7 @@ pub extern "C" fn Description_free(this_obj: Description) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDescription) }; } #[allow(unused)] impl Description { @@ -912,14 +1445,14 @@ impl Description { pub(crate) fn take_inner(mut self) -> *mut nativeDescription { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } impl Clone for Description { fn clone(&self) -> Self { Self { - inner: if <*mut nativeDescription>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -939,11 +1472,11 @@ pub extern "C" fn Description_clone(orig: &Description) -> Description { #[no_mangle] pub extern "C" fn Description_hash(o: &Description) -> u64 { if o.inner.is_null() { return 0; } - // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core + // 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(); - std::hash::Hash::hash(o.get_native_ref(), &mut hasher); - std::hash::Hasher::finish(&hasher) + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) } /// Checks if two Descriptions contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. @@ -987,7 +1520,7 @@ pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativePayeePubKey) }; } #[allow(unused)] impl PayeePubKey { @@ -1001,7 +1534,7 @@ impl PayeePubKey { pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -1025,7 +1558,7 @@ pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> Payee impl Clone for PayeePubKey { fn clone(&self) -> Self { Self { - inner: if <*mut nativePayeePubKey>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativePayeePubKey>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -1045,11 +1578,11 @@ pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey { #[no_mangle] pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 { if o.inner.is_null() { return 0; } - // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core + // 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(); - std::hash::Hash::hash(o.get_native_ref(), &mut hasher); - std::hash::Hasher::finish(&hasher) + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) } /// Checks if two PayeePubKeys contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. @@ -1066,11 +1599,6 @@ pub(crate) type nativeExpiryTime = nativeExpiryTimeImport; /// Positive duration that defines when (relatively to the timestamp) in the future the invoice /// expires -/// -/// # Invariants -/// The number of seconds this expiry time represents has to be in the range -/// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a -/// timestamp #[must_use] #[repr(C)] pub struct ExpiryTime { @@ -1099,7 +1627,7 @@ pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeExpiryTime) }; } #[allow(unused)] impl ExpiryTime { @@ -1113,14 +1641,14 @@ impl ExpiryTime { pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } impl Clone for ExpiryTime { fn clone(&self) -> Self { Self { - inner: if <*mut nativeExpiryTime>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -1140,11 +1668,11 @@ pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime { #[no_mangle] pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 { if o.inner.is_null() { return 0; } - // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core + // 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(); - std::hash::Hash::hash(o.get_native_ref(), &mut hasher); - std::hash::Hasher::finish(&hasher) + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) } /// Checks if two ExpiryTimes contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. @@ -1156,18 +1684,18 @@ pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool { if a.get_native_ref() == b.get_native_ref() { true } else { false } } -use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport; -pub(crate) type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport; +use lightning_invoice::MinFinalCltvExpiryDelta as nativeMinFinalCltvExpiryDeltaImport; +pub(crate) type nativeMinFinalCltvExpiryDelta = nativeMinFinalCltvExpiryDeltaImport; -/// `min_final_cltv_expiry` to use for the last HTLC in the route +/// `min_final_cltv_expiry_delta` to use for the last HTLC in the route #[must_use] #[repr(C)] -pub struct MinFinalCltvExpiry { +pub struct MinFinalCltvExpiryDelta { /// A pointer to the opaque Rust object. /// Nearly everywhere, inner must be non-null, however in places where /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeMinFinalCltvExpiry, + pub inner: *mut nativeMinFinalCltvExpiryDelta, /// Indicates that this is the only struct which contains the same pointer. /// Rust functions which take ownership of an object provided via an argument require @@ -1175,58 +1703,58 @@ pub struct MinFinalCltvExpiry { pub is_owned: bool, } -impl Drop for MinFinalCltvExpiry { +impl Drop for MinFinalCltvExpiryDelta { fn drop(&mut self) { - if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { + if self.is_owned && !<*mut nativeMinFinalCltvExpiryDelta>::is_null(self.inner) { let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; } } } -/// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL. +/// Frees any resources used by the MinFinalCltvExpiryDelta, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { } +pub extern "C" fn MinFinalCltvExpiryDelta_free(this_obj: MinFinalCltvExpiryDelta) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); } +pub(crate) extern "C" fn MinFinalCltvExpiryDelta_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiryDelta) }; } #[allow(unused)] -impl MinFinalCltvExpiry { - pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiry { +impl MinFinalCltvExpiryDelta { + pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiryDelta { unsafe { &*ObjOps::untweak_ptr(self.inner) } } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiry { + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiryDelta { unsafe { &mut *ObjOps::untweak_ptr(self.inner) } } /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy - pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry { + pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiryDelta { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } #[no_mangle] -pub extern "C" fn MinFinalCltvExpiry_get_a(this_ptr: &MinFinalCltvExpiry) -> u64 { +pub extern "C" fn MinFinalCltvExpiryDelta_get_a(this_ptr: &MinFinalCltvExpiryDelta) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().0; *inner_val } #[no_mangle] -pub extern "C" fn MinFinalCltvExpiry_set_a(this_ptr: &mut MinFinalCltvExpiry, mut val: u64) { +pub extern "C" fn MinFinalCltvExpiryDelta_set_a(this_ptr: &mut MinFinalCltvExpiryDelta, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val; } -/// Constructs a new MinFinalCltvExpiry given each field +/// Constructs a new MinFinalCltvExpiryDelta given each field #[must_use] #[no_mangle] -pub extern "C" fn MinFinalCltvExpiry_new(mut a_arg: u64) -> MinFinalCltvExpiry { - MinFinalCltvExpiry { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiry ( +pub extern "C" fn MinFinalCltvExpiryDelta_new(mut a_arg: u64) -> MinFinalCltvExpiryDelta { + MinFinalCltvExpiryDelta { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiryDelta ( a_arg, )), is_owned: true } } -impl Clone for MinFinalCltvExpiry { +impl Clone for MinFinalCltvExpiryDelta { fn clone(&self) -> Self { Self { - inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeMinFinalCltvExpiryDelta>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -1234,53 +1762,57 @@ impl Clone for MinFinalCltvExpiry { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void +pub(crate) extern "C" fn MinFinalCltvExpiryDelta_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiryDelta)).clone() })) as *mut c_void } #[no_mangle] -/// Creates a copy of the MinFinalCltvExpiry -pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry { +/// Creates a copy of the MinFinalCltvExpiryDelta +pub extern "C" fn MinFinalCltvExpiryDelta_clone(orig: &MinFinalCltvExpiryDelta) -> MinFinalCltvExpiryDelta { orig.clone() } -/// Checks if two MinFinalCltvExpirys contain equal inner contents. +/// Checks if two MinFinalCltvExpiryDeltas contain equal inner contents. #[no_mangle] -pub extern "C" fn MinFinalCltvExpiry_hash(o: &MinFinalCltvExpiry) -> u64 { +pub extern "C" fn MinFinalCltvExpiryDelta_hash(o: &MinFinalCltvExpiryDelta) -> u64 { if o.inner.is_null() { return 0; } - // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core + // 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(); - std::hash::Hash::hash(o.get_native_ref(), &mut hasher); - std::hash::Hasher::finish(&hasher) + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) } -/// Checks if two MinFinalCltvExpirys contain equal inner contents. +/// Checks if two MinFinalCltvExpiryDeltas 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] -pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool { +pub extern "C" fn MinFinalCltvExpiryDelta_eq(a: &MinFinalCltvExpiryDelta, b: &MinFinalCltvExpiryDelta) -> bool { if a.inner == b.inner { return true; } if a.inner.is_null() || b.inner.is_null() { return false; } 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, + 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 { match self { Fallback::SegWitProgram {ref version, ref program, } => { - let mut version_nonref = (*version).clone(); - let mut program_nonref = (*program).clone(); + let mut version_nonref = Clone::clone(version); + let mut program_nonref = Clone::clone(program); let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); }; nativeFallback::SegWitProgram { version: version_nonref.into(), @@ -1288,13 +1820,13 @@ impl Fallback { } }, Fallback::PubKeyHash (ref a, ) => { - let mut a_nonref = (*a).clone(); + let mut a_nonref = Clone::clone(a); nativeFallback::PubKeyHash ( a_nonref.data, ) }, Fallback::ScriptHash (ref a, ) => { - let mut a_nonref = (*a).clone(); + let mut a_nonref = Clone::clone(a); nativeFallback::ScriptHash ( a_nonref.data, ) @@ -1327,8 +1859,8 @@ impl Fallback { pub(crate) fn from_native(native: &nativeFallback) -> Self { match native { nativeFallback::SegWitProgram {ref version, ref program, } => { - let mut version_nonref = (*version).clone(); - let mut program_nonref = (*program).clone(); + let mut version_nonref = Clone::clone(version); + let mut program_nonref = Clone::clone(program); let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); }; Fallback::SegWitProgram { version: version_nonref.into(), @@ -1336,13 +1868,13 @@ impl Fallback { } }, nativeFallback::PubKeyHash (ref a, ) => { - let mut a_nonref = (*a).clone(); + let mut a_nonref = Clone::clone(a); Fallback::PubKeyHash ( crate::c_types::TwentyBytes { data: a_nonref }, ) }, nativeFallback::ScriptHash (ref a, ) => { - let mut a_nonref = (*a).clone(); + let mut a_nonref = Clone::clone(a); Fallback::ScriptHash ( crate::c_types::TwentyBytes { data: a_nonref }, ) @@ -1382,7 +1914,7 @@ pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback { } #[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::U5, program: crate::c_types::derived::CVec_u8Z) -> Fallback { Fallback::SegWitProgram { version, program, @@ -1401,11 +1933,11 @@ pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallba /// Checks if two Fallbacks contain equal inner contents. #[no_mangle] pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 { - // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core + // 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(); - std::hash::Hash::hash(&o.to_native(), &mut hasher); - std::hash::Hasher::finish(&hasher) + core::hash::Hash::hash(&o.to_native(), &mut hasher); + core::hash::Hasher::finish(&hasher) } /// Checks if two Fallbacks contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. @@ -1446,7 +1978,7 @@ pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInvoiceSignature) }; } #[allow(unused)] impl InvoiceSignature { @@ -1460,14 +1992,14 @@ impl InvoiceSignature { pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } impl Clone for InvoiceSignature { fn clone(&self) -> Self { Self { - inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -1484,6 +2016,16 @@ pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSign 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] @@ -1529,7 +2071,7 @@ pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativePrivateRoute) }; } #[allow(unused)] impl PrivateRoute { @@ -1543,14 +2085,14 @@ impl PrivateRoute { pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } impl Clone for PrivateRoute { fn clone(&self) -> Self { Self { - inner: if <*mut nativePrivateRoute>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -1570,11 +2112,11 @@ pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute { #[no_mangle] pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 { if o.inner.is_null() { return 0; } - // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core + // 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(); - std::hash::Hash::hash(o.get_native_ref(), &mut hasher); - std::hash::Hasher::finish(&hasher) + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) } /// Checks if two PrivateRoutes contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. @@ -1591,7 +2133,7 @@ pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool { /// 3. signature #[must_use] #[no_mangle] -pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ { +pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ { let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts(); let (mut orig_ret_0, mut orig_ret_1, mut orig_ret_2) = ret; let mut local_ret = (crate::lightning_invoice::RawInvoice { inner: ObjOps::heap_alloc(orig_ret_0), is_owned: true }, crate::c_types::ThirtyTwoBytes { data: orig_ret_1 }, crate::lightning_invoice::InvoiceSignature { inner: ObjOps::heap_alloc(orig_ret_2), is_owned: true }).into(); local_ret @@ -1600,7 +2142,7 @@ pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> /// The `RawInvoice` which was signed. #[must_use] #[no_mangle] -pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice { +pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::RawInvoice { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice(); crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawInvoice<>) as *mut _) }, is_owned: false } } @@ -1608,15 +2150,15 @@ pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> c /// The hash of the `RawInvoice` that was signed. #[must_use] #[no_mangle] -pub extern "C" fn SignedRawInvoice_hash(this_arg: &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 } /// InvoiceSignature for the invoice. #[must_use] #[no_mangle] -pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature { +pub extern "C" fn SignedRawInvoice_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature(); crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::InvoiceSignature<>) as *mut _) }, is_owned: false } } @@ -1624,7 +2166,7 @@ pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> cra /// Recovers the public key used for signing the invoice from the recoverable signature. #[must_use] #[no_mangle] -pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ { +pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key(); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PayeePubKey { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() }; local_ret @@ -1634,16 +2176,16 @@ pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInv /// valid for the recovered signature (which should always be true?). #[must_use] #[no_mangle] -pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool { +pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> bool { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature(); 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: &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 } } @@ -1651,9 +2193,9 @@ pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::Thir /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 { +pub extern "C" fn RawInvoice_payment_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash(); - let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false }; local_ret } @@ -1661,9 +2203,9 @@ pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::light /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description { +pub extern "C" fn RawInvoice_description(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Description { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description(); - let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Description<>) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Description<>) as *mut _ }, is_owned: false }; local_ret } @@ -1671,9 +2213,9 @@ pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightn /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey { +pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::PayeePubKey { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key(); - let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::PayeePubKey<>) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::PayeePubKey<>) as *mut _ }, is_owned: false }; local_ret } @@ -1681,9 +2223,9 @@ pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::ligh /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 { +pub extern "C" fn RawInvoice_description_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash(); - let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false }; local_ret } @@ -1691,9 +2233,9 @@ pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::l /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime { +pub extern "C" fn RawInvoice_expiry_time(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::ExpiryTime { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time(); - let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::ExpiryTime<>) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::ExpiryTime<>) as *mut _ }, is_owned: false }; local_ret } @@ -1701,9 +2243,9 @@ pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightn /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry(); - let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiry { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::MinFinalCltvExpiry<>) as *mut _ }, is_owned: false }; +pub extern "C" fn RawInvoice_min_final_cltv_expiry_delta(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiryDelta { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry_delta(); + let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiryDelta { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::MinFinalCltvExpiryDelta<>) as *mut _ }, is_owned: false }; local_ret } @@ -1711,7 +2253,7 @@ pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> cra /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes { +pub extern "C" fn RawInvoice_payment_secret(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret(); let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } }; local_ret @@ -1721,15 +2263,15 @@ pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_t /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures { +pub extern "C" fn RawInvoice_features(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features(); - let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false }; local_ret } #[must_use] #[no_mangle] -pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ { +pub extern "C" fn RawInvoice_private_routes(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes(); let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning_invoice::PrivateRoute<>) as *mut _) }, is_owned: false } }); }; local_ret.into() @@ -1737,7 +2279,7 @@ pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_t #[must_use] #[no_mangle] -pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z { +pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::COption_u64Z { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc(); let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap() }) }; local_ret @@ -1745,14 +2287,14 @@ pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_ #[must_use] #[no_mangle] -pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency { +pub extern "C" fn RawInvoice_currency(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Currency { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency(); crate::lightning_invoice::Currency::native_into(ret) } -/// Create a new `PositiveTimestamp` from a unix timestamp in the Range -/// `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a -/// `CreationError::TimestampOutOfBounds`. +/// Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`. +/// +/// Otherwise, returns a [`CreationError::TimestampOutOfBounds`]. #[must_use] #[no_mangle] pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ { @@ -1761,9 +2303,12 @@ pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) - local_ret } -/// Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in -/// the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a -/// `CreationError::TimestampOutOfBounds`. +/// 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] pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ { @@ -1772,18 +2317,40 @@ pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_ local_ret } -/// Returns the UNIX timestamp representing the stored time +/// 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] -pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 { +pub extern "C" fn PositiveTimestamp_from_duration_since_epoch(mut duration: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ { + let mut ret = lightning_invoice::PositiveTimestamp::from_duration_since_epoch(core::time::Duration::from_secs(duration)); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() }; + local_ret +} + +/// Returns the Unix timestamp representing the stored time +#[must_use] +#[no_mangle] +pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp(); ret } -/// Returns a reference to the internal `SystemTime` time representation +/// Returns the duration of the stored time since the Unix epoch #[must_use] #[no_mangle] -pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 { +pub extern "C" fn PositiveTimestamp_as_duration_since_epoch(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration_since_epoch(); + ret.as_secs() +} + +/// Returns the [`SystemTime`] representing the stored time +#[must_use] +#[no_mangle] +pub extern "C" fn PositiveTimestamp_as_time(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time(); ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs() } @@ -1791,7 +2358,7 @@ pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 /// Transform the `Invoice` into it's unchecked version #[must_use] #[no_mangle] -pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice { +pub extern "C" fn Invoice_into_signed_raw(mut this_arg: crate::lightning_invoice::Invoice) -> crate::lightning_invoice::SignedRawInvoice { let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw(); crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(ret), is_owned: true } } @@ -1799,7 +2366,7 @@ pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::light /// Check that the invoice is signed correctly and that key recovery works #[must_use] #[no_mangle] -pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ { +pub extern "C" fn Invoice_check_signature(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature(); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::SemanticError::native_into(e) }).into() }; local_ret @@ -1833,18 +2400,26 @@ pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoi local_ret } -/// Returns the `Invoice`'s timestamp (should equal it's creation time) +/// Returns the `Invoice`'s timestamp (should equal its creation time) #[must_use] #[no_mangle] -pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 { +pub extern "C" fn Invoice_timestamp(this_arg: &crate::lightning_invoice::Invoice) -> u64 { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp(); ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs() } +/// Returns the `Invoice`'s timestamp as a duration since the Unix epoch +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_duration_since_epoch(this_arg: &crate::lightning_invoice::Invoice) -> u64 { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_since_epoch(); + ret.as_secs() +} + /// Returns the hash to which we will receive the preimage on completion of the payment #[must_use] #[no_mangle] -pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] { +pub extern "C" fn Invoice_payment_hash(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash(); ret.as_inner() } @@ -1854,7 +2429,7 @@ pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] { /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey { +pub extern "C" fn Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key(); let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } }; local_ret @@ -1863,7 +2438,7 @@ pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::P /// Get the payment secret if one was included in the invoice #[must_use] #[no_mangle] -pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> *const [u8; 32] { +pub extern "C" fn Invoice_payment_secret(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret(); &ret.0 } @@ -1873,16 +2448,16 @@ pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> *const [u8; 32] /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures { +pub extern "C" fn Invoice_features(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning::ln::features::InvoiceFeatures { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features(); - let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false }; local_ret } /// Recover the payee's public key (only to be used if none was included in the invoice) #[must_use] #[no_mangle] -pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey { +pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key(); crate::c_types::PublicKey::from_rust(&ret) } @@ -1890,7 +2465,7 @@ pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_ /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`]. #[must_use] #[no_mangle] -pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 { +pub extern "C" fn Invoice_expiry_time(this_arg: &crate::lightning_invoice::Invoice) -> u64 { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time(); ret.as_secs() } @@ -1898,24 +2473,33 @@ pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 { /// Returns whether the invoice has expired. #[must_use] #[no_mangle] -pub extern "C" fn Invoice_is_expired(this_arg: &Invoice) -> bool { +pub extern "C" fn Invoice_is_expired(this_arg: &crate::lightning_invoice::Invoice) -> bool { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired(); ret } -/// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise -/// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`]. +/// 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] +#[no_mangle] +pub extern "C" fn Invoice_would_expire(this_arg: &crate::lightning_invoice::Invoice, mut at_time: u64) -> bool { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.would_expire(core::time::Duration::from_secs(at_time)); + ret +} + +/// Returns the invoice's `min_final_cltv_expiry_delta` time, if present, otherwise +/// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA`]. #[must_use] #[no_mangle] -pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry(); +pub extern "C" fn Invoice_min_final_cltv_expiry_delta(this_arg: &crate::lightning_invoice::Invoice) -> u64 { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry_delta(); ret } /// Returns a list of all routes included in the invoice #[must_use] #[no_mangle] -pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ { +pub extern "C" fn Invoice_private_routes(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes(); let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning_invoice::PrivateRoute<>) as *mut _) }, is_owned: false } }); }; local_ret.into() @@ -1924,7 +2508,7 @@ pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types:: /// Returns a list of all routes included in the invoice as the underlying hints #[must_use] #[no_mangle] -pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ { +pub extern "C" fn Invoice_route_hints(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_RouteHintZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints(); let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; local_ret.into() @@ -1933,7 +2517,7 @@ pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::der /// Returns the currency for which the invoice was issued #[must_use] #[no_mangle] -pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency { +pub extern "C" fn Invoice_currency(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning_invoice::Currency { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency(); crate::lightning_invoice::Currency::native_into(ret) } @@ -1941,7 +2525,7 @@ pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoi /// Returns the amount if specified in the invoice as millisatoshis. #[must_use] #[no_mangle] -pub extern "C" fn Invoice_amount_milli_satoshis(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z { +pub extern "C" fn Invoice_amount_milli_satoshis(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::COption_u64Z { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis(); let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap() }) }; local_ret @@ -1962,37 +2546,31 @@ pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate /// Returns the underlying description `String` #[must_use] #[no_mangle] -pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::Str { +pub extern "C" fn Description_into_inner(mut this_arg: crate::lightning_invoice::Description) -> crate::c_types::Str { let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner(); ret.into() } -/// Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would -/// overflow on adding the `EpiryTime` to it then this function will return a -/// `CreationError::ExpiryTimeOutOfBounds`. +/// Construct an `ExpiryTime` from seconds. #[must_use] #[no_mangle] -pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ { +pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::lightning_invoice::ExpiryTime { let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() }; - local_ret + crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true } } -/// Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which -/// would overflow on adding the `EpiryTime` to it then this function will return a -/// `CreationError::ExpiryTimeOutOfBounds`. +/// 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::c_types::derived::CResult_ExpiryTimeCreationErrorZ { - let mut ret = lightning_invoice::ExpiryTime::from_duration(std::time::Duration::from_secs(duration)); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() }; - local_ret +pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime { + let mut ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration)); + crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true } } /// Returns the expiry time in seconds #[must_use] #[no_mangle] -pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 { +pub extern "C" fn ExpiryTime_as_seconds(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds(); ret } @@ -2000,7 +2578,7 @@ pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 { /// Returns a reference to the underlying `Duration` (=expiry time) #[must_use] #[no_mangle] -pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 { +pub extern "C" fn ExpiryTime_as_duration(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration(); ret.as_secs() } @@ -2017,26 +2595,37 @@ pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router:: /// Returns the underlying list of hops #[must_use] #[no_mangle] -pub extern "C" fn PrivateRoute_into_inner(mut this_arg: PrivateRoute) -> crate::lightning::routing::router::RouteHint { +pub extern "C" fn PrivateRoute_into_inner(mut this_arg: crate::lightning_invoice::PrivateRoute) -> crate::lightning::routing::router::RouteHint { let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner(); crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true } } /// 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)) DescriptionTooLong, /// The specified route has too many hops and can't be encoded RouteTooLong, - /// The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime` + /// The Unix timestamp of the supplied date is less than zero or greater than 35-bits TimestampOutOfBounds, - /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp` - ExpiryTimeOutOfBounds, -} -use lightning_invoice::CreationError as nativeCreationError; + /// The supplied millisatoshi amount was greater than the total bitcoin supply. + InvalidAmount, + /// Route hints were required for this invoice and were missing. Applies to + /// [phantom invoices]. + /// + /// [phantom invoices]: crate::utils::create_phantom_invoice + MissingRouteHints, + /// The provided `min_final_cltv_expiry_delta` was less than [`MIN_FINAL_CLTV_EXPIRY_DELTA`]. + /// + /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA + MinFinalCltvExpiryDeltaTooShort, +} +use lightning_invoice::CreationError as CreationErrorImport; +pub(crate) type nativeCreationError = CreationErrorImport; + impl CreationError { #[allow(unused)] pub(crate) fn to_native(&self) -> nativeCreationError { @@ -2044,7 +2633,9 @@ impl CreationError { CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong, CreationError::RouteTooLong => nativeCreationError::RouteTooLong, CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds, - CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds, + CreationError::InvalidAmount => nativeCreationError::InvalidAmount, + CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints, + CreationError::MinFinalCltvExpiryDeltaTooShort => nativeCreationError::MinFinalCltvExpiryDeltaTooShort, } } #[allow(unused)] @@ -2053,7 +2644,9 @@ impl CreationError { CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong, CreationError::RouteTooLong => nativeCreationError::RouteTooLong, CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds, - CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds, + CreationError::InvalidAmount => nativeCreationError::InvalidAmount, + CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints, + CreationError::MinFinalCltvExpiryDeltaTooShort => nativeCreationError::MinFinalCltvExpiryDeltaTooShort, } } #[allow(unused)] @@ -2062,7 +2655,9 @@ impl CreationError { nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong, nativeCreationError::RouteTooLong => CreationError::RouteTooLong, nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds, - nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds, + nativeCreationError::InvalidAmount => CreationError::InvalidAmount, + nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints, + nativeCreationError::MinFinalCltvExpiryDeltaTooShort => CreationError::MinFinalCltvExpiryDeltaTooShort, } } #[allow(unused)] @@ -2071,7 +2666,9 @@ impl CreationError { nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong, nativeCreationError::RouteTooLong => CreationError::RouteTooLong, nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds, - nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds, + nativeCreationError::InvalidAmount => CreationError::InvalidAmount, + nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints, + nativeCreationError::MinFinalCltvExpiryDeltaTooShort => CreationError::MinFinalCltvExpiryDeltaTooShort, } } } @@ -2093,9 +2690,17 @@ pub extern "C" fn CreationError_route_too_long() -> CreationError { pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError { CreationError::TimestampOutOfBounds} #[no_mangle] -/// Utility method to constructs a new ExpiryTimeOutOfBounds-variant CreationError -pub extern "C" fn CreationError_expiry_time_out_of_bounds() -> CreationError { - CreationError::ExpiryTimeOutOfBounds} +/// Utility method to constructs a new InvalidAmount-variant CreationError +pub extern "C" fn CreationError_invalid_amount() -> CreationError { + CreationError::InvalidAmount} +#[no_mangle] +/// Utility method to constructs a new MissingRouteHints-variant CreationError +pub extern "C" fn CreationError_missing_route_hints() -> CreationError { + CreationError::MissingRouteHints} +#[no_mangle] +/// Utility method to constructs a new MinFinalCltvExpiryDeltaTooShort-variant CreationError +pub extern "C" fn CreationError_min_final_cltv_expiry_delta_too_short() -> CreationError { + CreationError::MinFinalCltvExpiryDeltaTooShort} /// Checks if two CreationErrors contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. #[no_mangle] @@ -2105,12 +2710,12 @@ pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool #[no_mangle] /// Get the string representation of a CreationError object pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str { - format!("{}", &o.to_native()).into() + alloc::format!("{}", &o.to_native()).into() } /// 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 @@ -2135,7 +2740,9 @@ pub enum SemanticError { /// 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 { @@ -2252,20 +2859,23 @@ pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool #[no_mangle] /// Get the string representation of a SemanticError object pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str { - format!("{}", &o.to_native()).into() + alloc::format!("{}", &o.to_native()).into() } /// 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 { @@ -2276,7 +2886,7 @@ impl SignOrCreationError { ) }, SignOrCreationError::CreationError (ref a, ) => { - let mut a_nonref = (*a).clone(); + let mut a_nonref = Clone::clone(a); nativeSignOrCreationError::CreationError ( a_nonref.into_native(), ) @@ -2304,7 +2914,7 @@ impl SignOrCreationError { nativeSignOrCreationError::SignError (ref a, ) => { SignOrCreationError::SignError }, nativeSignOrCreationError::CreationError (ref a, ) => { - let mut a_nonref = (*a).clone(); + let mut a_nonref = Clone::clone(a); SignOrCreationError::CreationError ( crate::lightning_invoice::CreationError::native_into(a_nonref), ) @@ -2351,5 +2961,5 @@ pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCrea #[no_mangle] /// Get the string representation of a SignOrCreationError object pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str { - format!("{}", &o.to_native()).into() + alloc::format!("{}", &o.to_native()).into() }