// 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:
//!
-//! * For parsing use `str::parse::<Invoice>(&self)` (see the docs of `impl FromStr for Invoice`)
-//! * For constructing invoices use the `InvoiceBuilder`
-//! * For serializing invoices use the `Display`/`ToString` traits
+//! * For parsing use `str::parse::<Bolt11Invoice>(&self)` (see [`Bolt11Invoice::from_str`])
+//! * For constructing invoices use the [`InvoiceBuilder`]
+//! * For serializing invoices use the [`Display`]/[`ToString`] traits
+//!
+//! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
-use std::str::FromStr;
-use std::ffi::c_void;
+use alloc::str::FromStr;
+use alloc::string::String;
+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 de {
-use std::str::FromStr;
-use std::ffi::c_void;
+use alloc::str::FromStr;
+use alloc::string::String;
+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 alloc::string::String;
+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_SiPrefixBolt11ParseErrorZ {
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::Bolt11ParseError::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 {
- match lightning_invoice::Invoice::from_str(s.into_str()) {
+/// Read a Bolt11Invoice object from a string
+pub extern "C" fn Bolt11Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_Bolt11InvoiceParseOrSemanticErrorZ {
+ match lightning_invoice::Bolt11Invoice::from_str(s.into_str()) {
Ok(r) => {
crate::c_types::CResultTempl::ok(
- crate::lightning_invoice::Invoice { inner: Box::into_raw(Box::new(r)), is_owned: true }
+ crate::lightning_invoice::Bolt11Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
+ )
+ },
+ Err(e) => {
+ crate::c_types::CResultTempl::err(
+ crate::lightning_invoice::ParseOrSemanticError::native_into(e)
)
},
- Err(e) => crate::c_types::CResultTempl::err(()),
}.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 {
- match lightning_invoice::SignedRawInvoice::from_str(s.into_str()) {
+/// Read a SignedRawBolt11Invoice object from a string
+pub extern "C" fn SignedRawBolt11Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawBolt11InvoiceBolt11ParseErrorZ {
+ match lightning_invoice::SignedRawBolt11Invoice::from_str(s.into_str()) {
Ok(r) => {
crate::c_types::CResultTempl::ok(
- crate::lightning_invoice::SignedRawInvoice { inner: Box::into_raw(Box::new(r)), is_owned: true }
+ crate::lightning_invoice::SignedRawBolt11Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
+ )
+ },
+ Err(e) => {
+ crate::c_types::CResultTempl::err(
+ crate::lightning_invoice::Bolt11ParseError::native_into(e)
)
},
- Err(e) => crate::c_types::CResultTempl::err(()),
}.into()
}
+#[no_mangle]
+/// Get the string representation of a Bolt11ParseError object
+pub extern "C" fn Bolt11ParseError_to_str(o: &crate::lightning_invoice::Bolt11ParseError) -> 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 alloc::string::String;
+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!("{}", unsafe { &*o.inner }).into()
+/// Get the string representation of a Bolt11Invoice object
+pub extern "C" fn Bolt11Invoice_to_str(o: &crate::lightning_invoice::Bolt11Invoice) -> Str {
+ 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!("{}", unsafe { &*o.inner }).into()
+/// Get the string representation of a SignedRawBolt11Invoice object
+pub extern "C" fn SignedRawBolt11Invoice_to_str(o: &crate::lightning_invoice::SignedRawBolt11Invoice) -> Str {
+ 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 alloc::string::String;
+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};
}
-/// **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.
+mod prelude {
+
+use alloc::str::FromStr;
+use alloc::string::String;
+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 Bolt11ParseError {
+ 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::Bolt11ParseError as Bolt11ParseErrorImport;
+pub(crate) type nativeBolt11ParseError = Bolt11ParseErrorImport;
+
+impl Bolt11ParseError {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeBolt11ParseError {
+ match self {
+ Bolt11ParseError::Bech32Error (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeBolt11ParseError::Bech32Error (
+ a_nonref.into_rust(),
+ )
+ },
+ Bolt11ParseError::ParseAmountError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeBolt11ParseError::ParseAmountError (
+ u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
+ )
+ },
+ Bolt11ParseError::MalformedSignature (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeBolt11ParseError::MalformedSignature (
+ a_nonref.into_rust(),
+ )
+ },
+ Bolt11ParseError::BadPrefix => nativeBolt11ParseError::BadPrefix,
+ Bolt11ParseError::UnknownCurrency => nativeBolt11ParseError::UnknownCurrency,
+ Bolt11ParseError::UnknownSiPrefix => nativeBolt11ParseError::UnknownSiPrefix,
+ Bolt11ParseError::MalformedHRP => nativeBolt11ParseError::MalformedHRP,
+ Bolt11ParseError::TooShortDataPart => nativeBolt11ParseError::TooShortDataPart,
+ Bolt11ParseError::UnexpectedEndOfTaggedFields => nativeBolt11ParseError::UnexpectedEndOfTaggedFields,
+ Bolt11ParseError::DescriptionDecodeError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeBolt11ParseError::DescriptionDecodeError (
+ core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
+ )
+ },
+ Bolt11ParseError::PaddingError => nativeBolt11ParseError::PaddingError,
+ Bolt11ParseError::IntegerOverflowError => nativeBolt11ParseError::IntegerOverflowError,
+ Bolt11ParseError::InvalidSegWitProgramLength => nativeBolt11ParseError::InvalidSegWitProgramLength,
+ Bolt11ParseError::InvalidPubKeyHashLength => nativeBolt11ParseError::InvalidPubKeyHashLength,
+ Bolt11ParseError::InvalidScriptHashLength => nativeBolt11ParseError::InvalidScriptHashLength,
+ Bolt11ParseError::InvalidRecoveryId => nativeBolt11ParseError::InvalidRecoveryId,
+ Bolt11ParseError::InvalidSliceLength (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeBolt11ParseError::InvalidSliceLength (
+ a_nonref.into_string(),
+ )
+ },
+ Bolt11ParseError::Skip => nativeBolt11ParseError::Skip,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeBolt11ParseError {
+ match self {
+ Bolt11ParseError::Bech32Error (mut a, ) => {
+ nativeBolt11ParseError::Bech32Error (
+ a.into_rust(),
+ )
+ },
+ Bolt11ParseError::ParseAmountError (mut a, ) => {
+ nativeBolt11ParseError::ParseAmountError (
+ u8::from_str_radix(" a", 10).unwrap_err() /*a*/,
+ )
+ },
+ Bolt11ParseError::MalformedSignature (mut a, ) => {
+ nativeBolt11ParseError::MalformedSignature (
+ a.into_rust(),
+ )
+ },
+ Bolt11ParseError::BadPrefix => nativeBolt11ParseError::BadPrefix,
+ Bolt11ParseError::UnknownCurrency => nativeBolt11ParseError::UnknownCurrency,
+ Bolt11ParseError::UnknownSiPrefix => nativeBolt11ParseError::UnknownSiPrefix,
+ Bolt11ParseError::MalformedHRP => nativeBolt11ParseError::MalformedHRP,
+ Bolt11ParseError::TooShortDataPart => nativeBolt11ParseError::TooShortDataPart,
+ Bolt11ParseError::UnexpectedEndOfTaggedFields => nativeBolt11ParseError::UnexpectedEndOfTaggedFields,
+ Bolt11ParseError::DescriptionDecodeError (mut a, ) => {
+ nativeBolt11ParseError::DescriptionDecodeError (
+ core::str::from_utf8(&[0xff]).unwrap_err() /*a*/,
+ )
+ },
+ Bolt11ParseError::PaddingError => nativeBolt11ParseError::PaddingError,
+ Bolt11ParseError::IntegerOverflowError => nativeBolt11ParseError::IntegerOverflowError,
+ Bolt11ParseError::InvalidSegWitProgramLength => nativeBolt11ParseError::InvalidSegWitProgramLength,
+ Bolt11ParseError::InvalidPubKeyHashLength => nativeBolt11ParseError::InvalidPubKeyHashLength,
+ Bolt11ParseError::InvalidScriptHashLength => nativeBolt11ParseError::InvalidScriptHashLength,
+ Bolt11ParseError::InvalidRecoveryId => nativeBolt11ParseError::InvalidRecoveryId,
+ Bolt11ParseError::InvalidSliceLength (mut a, ) => {
+ nativeBolt11ParseError::InvalidSliceLength (
+ a.into_string(),
+ )
+ },
+ Bolt11ParseError::Skip => nativeBolt11ParseError::Skip,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &Bolt11ParseErrorImport) -> Self {
+ let native = unsafe { &*(native as *const _ as *const c_void as *const nativeBolt11ParseError) };
+ match native {
+ nativeBolt11ParseError::Bech32Error (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ Bolt11ParseError::Bech32Error (
+ crate::c_types::Bech32Error::from_rust(a_nonref),
+ )
+ },
+ nativeBolt11ParseError::ParseAmountError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ Bolt11ParseError::ParseAmountError (
+ crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
+ )
+ },
+ nativeBolt11ParseError::MalformedSignature (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ Bolt11ParseError::MalformedSignature (
+ crate::c_types::Secp256k1Error::from_rust(a_nonref),
+ )
+ },
+ nativeBolt11ParseError::BadPrefix => Bolt11ParseError::BadPrefix,
+ nativeBolt11ParseError::UnknownCurrency => Bolt11ParseError::UnknownCurrency,
+ nativeBolt11ParseError::UnknownSiPrefix => Bolt11ParseError::UnknownSiPrefix,
+ nativeBolt11ParseError::MalformedHRP => Bolt11ParseError::MalformedHRP,
+ nativeBolt11ParseError::TooShortDataPart => Bolt11ParseError::TooShortDataPart,
+ nativeBolt11ParseError::UnexpectedEndOfTaggedFields => Bolt11ParseError::UnexpectedEndOfTaggedFields,
+ nativeBolt11ParseError::DescriptionDecodeError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ Bolt11ParseError::DescriptionDecodeError (
+ crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
+ )
+ },
+ nativeBolt11ParseError::PaddingError => Bolt11ParseError::PaddingError,
+ nativeBolt11ParseError::IntegerOverflowError => Bolt11ParseError::IntegerOverflowError,
+ nativeBolt11ParseError::InvalidSegWitProgramLength => Bolt11ParseError::InvalidSegWitProgramLength,
+ nativeBolt11ParseError::InvalidPubKeyHashLength => Bolt11ParseError::InvalidPubKeyHashLength,
+ nativeBolt11ParseError::InvalidScriptHashLength => Bolt11ParseError::InvalidScriptHashLength,
+ nativeBolt11ParseError::InvalidRecoveryId => Bolt11ParseError::InvalidRecoveryId,
+ nativeBolt11ParseError::InvalidSliceLength (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ Bolt11ParseError::InvalidSliceLength (
+ a_nonref.into(),
+ )
+ },
+ nativeBolt11ParseError::Skip => Bolt11ParseError::Skip,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeBolt11ParseError) -> Self {
+ match native {
+ nativeBolt11ParseError::Bech32Error (mut a, ) => {
+ Bolt11ParseError::Bech32Error (
+ crate::c_types::Bech32Error::from_rust(a),
+ )
+ },
+ nativeBolt11ParseError::ParseAmountError (mut a, ) => {
+ Bolt11ParseError::ParseAmountError (
+ crate::c_types::Error { _dummy: 0 } /*a*/,
+ )
+ },
+ nativeBolt11ParseError::MalformedSignature (mut a, ) => {
+ Bolt11ParseError::MalformedSignature (
+ crate::c_types::Secp256k1Error::from_rust(a),
+ )
+ },
+ nativeBolt11ParseError::BadPrefix => Bolt11ParseError::BadPrefix,
+ nativeBolt11ParseError::UnknownCurrency => Bolt11ParseError::UnknownCurrency,
+ nativeBolt11ParseError::UnknownSiPrefix => Bolt11ParseError::UnknownSiPrefix,
+ nativeBolt11ParseError::MalformedHRP => Bolt11ParseError::MalformedHRP,
+ nativeBolt11ParseError::TooShortDataPart => Bolt11ParseError::TooShortDataPart,
+ nativeBolt11ParseError::UnexpectedEndOfTaggedFields => Bolt11ParseError::UnexpectedEndOfTaggedFields,
+ nativeBolt11ParseError::DescriptionDecodeError (mut a, ) => {
+ Bolt11ParseError::DescriptionDecodeError (
+ crate::c_types::Error { _dummy: 0 } /*a*/,
+ )
+ },
+ nativeBolt11ParseError::PaddingError => Bolt11ParseError::PaddingError,
+ nativeBolt11ParseError::IntegerOverflowError => Bolt11ParseError::IntegerOverflowError,
+ nativeBolt11ParseError::InvalidSegWitProgramLength => Bolt11ParseError::InvalidSegWitProgramLength,
+ nativeBolt11ParseError::InvalidPubKeyHashLength => Bolt11ParseError::InvalidPubKeyHashLength,
+ nativeBolt11ParseError::InvalidScriptHashLength => Bolt11ParseError::InvalidScriptHashLength,
+ nativeBolt11ParseError::InvalidRecoveryId => Bolt11ParseError::InvalidRecoveryId,
+ nativeBolt11ParseError::InvalidSliceLength (mut a, ) => {
+ Bolt11ParseError::InvalidSliceLength (
+ a.into(),
+ )
+ },
+ nativeBolt11ParseError::Skip => Bolt11ParseError::Skip,
+ }
+ }
+}
+/// Frees any resources used by the Bolt11ParseError
+#[no_mangle]
+pub extern "C" fn Bolt11ParseError_free(this_ptr: Bolt11ParseError) { }
+/// Creates a copy of the Bolt11ParseError
+#[no_mangle]
+pub extern "C" fn Bolt11ParseError_clone(orig: &Bolt11ParseError) -> Bolt11ParseError {
+ orig.clone()
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn Bolt11ParseError_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Bolt11ParseError)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn Bolt11ParseError_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut Bolt11ParseError) };
+}
+#[no_mangle]
+/// Utility method to constructs a new Bech32Error-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_bech32_error(a: crate::c_types::Bech32Error) -> Bolt11ParseError {
+ Bolt11ParseError::Bech32Error(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new ParseAmountError-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_parse_amount_error(a: crate::c_types::Error) -> Bolt11ParseError {
+ Bolt11ParseError::ParseAmountError(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new MalformedSignature-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> Bolt11ParseError {
+ Bolt11ParseError::MalformedSignature(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new BadPrefix-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_bad_prefix() -> Bolt11ParseError {
+ Bolt11ParseError::BadPrefix}
+#[no_mangle]
+/// Utility method to constructs a new UnknownCurrency-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_unknown_currency() -> Bolt11ParseError {
+ Bolt11ParseError::UnknownCurrency}
+#[no_mangle]
+/// Utility method to constructs a new UnknownSiPrefix-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_unknown_si_prefix() -> Bolt11ParseError {
+ Bolt11ParseError::UnknownSiPrefix}
+#[no_mangle]
+/// Utility method to constructs a new MalformedHRP-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_malformed_hrp() -> Bolt11ParseError {
+ Bolt11ParseError::MalformedHRP}
+#[no_mangle]
+/// Utility method to constructs a new TooShortDataPart-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_too_short_data_part() -> Bolt11ParseError {
+ Bolt11ParseError::TooShortDataPart}
+#[no_mangle]
+/// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_unexpected_end_of_tagged_fields() -> Bolt11ParseError {
+ Bolt11ParseError::UnexpectedEndOfTaggedFields}
+#[no_mangle]
+/// Utility method to constructs a new DescriptionDecodeError-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_description_decode_error(a: crate::c_types::Error) -> Bolt11ParseError {
+ Bolt11ParseError::DescriptionDecodeError(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new PaddingError-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_padding_error() -> Bolt11ParseError {
+ Bolt11ParseError::PaddingError}
+#[no_mangle]
+/// Utility method to constructs a new IntegerOverflowError-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_integer_overflow_error() -> Bolt11ParseError {
+ Bolt11ParseError::IntegerOverflowError}
+#[no_mangle]
+/// Utility method to constructs a new InvalidSegWitProgramLength-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_invalid_seg_wit_program_length() -> Bolt11ParseError {
+ Bolt11ParseError::InvalidSegWitProgramLength}
+#[no_mangle]
+/// Utility method to constructs a new InvalidPubKeyHashLength-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_invalid_pub_key_hash_length() -> Bolt11ParseError {
+ Bolt11ParseError::InvalidPubKeyHashLength}
+#[no_mangle]
+/// Utility method to constructs a new InvalidScriptHashLength-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_invalid_script_hash_length() -> Bolt11ParseError {
+ Bolt11ParseError::InvalidScriptHashLength}
+#[no_mangle]
+/// Utility method to constructs a new InvalidRecoveryId-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_invalid_recovery_id() -> Bolt11ParseError {
+ Bolt11ParseError::InvalidRecoveryId}
+#[no_mangle]
+/// Utility method to constructs a new InvalidSliceLength-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_invalid_slice_length(a: crate::c_types::Str) -> Bolt11ParseError {
+ Bolt11ParseError::InvalidSliceLength(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new Skip-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_skip() -> Bolt11ParseError {
+ Bolt11ParseError::Skip}
+/// Checks if two Bolt11ParseErrors contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn Bolt11ParseError_eq(a: &Bolt11ParseError, b: &Bolt11ParseError) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+/// Get a string which allows debug introspection of a Bolt11ParseError object
+pub extern "C" fn Bolt11ParseError_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Bolt11ParseError }).into()}
+/// 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::Bolt11ParseError),
+ /// The invoice could be decoded but violates the BOLT11 standard
+ SemanticError(
+ crate::lightning_invoice::Bolt11SemanticError),
+}
+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: &ParseOrSemanticErrorImport) -> Self {
+ let native = unsafe { &*(native as *const _ as *const c_void as *const nativeParseOrSemanticError) };
+ match native {
+ nativeParseOrSemanticError::ParseError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ ParseOrSemanticError::ParseError (
+ crate::lightning_invoice::Bolt11ParseError::native_into(a_nonref),
+ )
+ },
+ nativeParseOrSemanticError::SemanticError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ ParseOrSemanticError::SemanticError (
+ crate::lightning_invoice::Bolt11SemanticError::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::Bolt11ParseError::native_into(a),
+ )
+ },
+ nativeParseOrSemanticError::SemanticError (mut a, ) => {
+ ParseOrSemanticError::SemanticError (
+ crate::lightning_invoice::Bolt11SemanticError::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()
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn ParseOrSemanticError_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ParseOrSemanticError)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn ParseOrSemanticError_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut ParseOrSemanticError) };
+}
+#[no_mangle]
+/// Utility method to constructs a new ParseError-variant ParseOrSemanticError
+pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::Bolt11ParseError) -> 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::Bolt11SemanticError) -> 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 }
+}
+/// Get a string which allows debug introspection of a ParseOrSemanticError object
+pub extern "C" fn ParseOrSemanticError_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::ParseOrSemanticError }).into()}
+/// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
///
-/// If this function fails this is considered a bug. Please open an issue describing your
-/// platform and stating your current system time.
+/// [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].
///
-/// # 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.
+/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
+
#[no_mangle]
-pub extern "C" fn check_platform() {
- lightning_invoice::check_platform()
-}
+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_DELTA`].
+///
+/// [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_DELTA: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA;
-use lightning_invoice::Invoice as nativeInvoiceImport;
-type nativeInvoice = nativeInvoiceImport;
+use lightning_invoice::Bolt11Invoice as nativeBolt11InvoiceImport;
+pub(crate) type nativeBolt11Invoice = nativeBolt11InvoiceImport;
/// Represents a syntactically and semantically correct lightning BOLT11 invoice.
///
-/// There are three ways to construct an `Invoice`:
-/// 1. using `InvoiceBuilder`
-/// 2. using `Invoice::from_signed(SignedRawInvoice)`
-/// 3. using `str::parse::<Invoice>(&str)`
+/// There are three ways to construct a `Bolt11Invoice`:
+/// 1. using [`InvoiceBuilder`]
+/// 2. using [`Bolt11Invoice::from_signed`]
+/// 3. using `str::parse::<Bolt11Invoice>(&str)` (see [`Bolt11Invoice::from_str`])
+///
+/// [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
#[must_use]
#[repr(C)]
-pub struct Invoice {
+pub struct Bolt11Invoice {
/// 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 nativeInvoice,
+ pub inner: *mut nativeBolt11Invoice,
/// 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
pub is_owned: bool,
}
-impl Drop for Invoice {
+impl Drop for Bolt11Invoice {
fn drop(&mut self) {
- if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
- let _ = unsafe { Box::from_raw(self.inner) };
+ if self.is_owned && !<*mut nativeBolt11Invoice>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
}
}
}
-/// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
+/// Frees any resources used by the Bolt11Invoice, if is_owned is set and inner is non-NULL.
#[no_mangle]
-pub extern "C" fn Invoice_free(this_obj: Invoice) { }
+pub extern "C" fn Bolt11Invoice_free(this_obj: Bolt11Invoice) { }
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
-extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
+pub(crate) extern "C" fn Bolt11Invoice_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt11Invoice) };
}
#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
-impl Invoice {
- pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
+impl Bolt11Invoice {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeBolt11Invoice {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt11Invoice {
+ 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 nativeBolt11Invoice {
assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
ret
}
}
-impl Clone for Invoice {
+/// Checks if two Bolt11Invoices 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 Bolt11Invoice_eq(a: &Bolt11Invoice, b: &Bolt11Invoice) -> 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 }
+}
+/// Get a string which allows debug introspection of a Bolt11Invoice object
+pub extern "C" fn Bolt11Invoice_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Bolt11Invoice }).into()}
+impl Clone for Bolt11Invoice {
fn clone(&self) -> Self {
Self {
- inner: if <*mut nativeInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
- Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
+ inner: if <*mut nativeBolt11Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
+ ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
is_owned: true,
}
}
}
#[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_clone_void(this_ptr: *const c_void) -> *mut c_void {
- Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
+pub(crate) extern "C" fn Bolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt11Invoice)).clone() })) as *mut c_void
}
#[no_mangle]
-/// Creates a copy of the Invoice
-pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
+/// Creates a copy of the Bolt11Invoice
+pub extern "C" fn Bolt11Invoice_clone(orig: &Bolt11Invoice) -> Bolt11Invoice {
orig.clone()
}
+/// Generates a non-cryptographic 64-bit hash of the Bolt11Invoice.
+#[no_mangle]
+pub extern "C" fn Bolt11Invoice_hash(o: &Bolt11Invoice) -> 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;
-type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
+use lightning_invoice::SignedRawBolt11Invoice as nativeSignedRawBolt11InvoiceImport;
+pub(crate) type nativeSignedRawBolt11Invoice = nativeSignedRawBolt11InvoiceImport;
-/// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
+/// Represents a signed [`RawBolt11Invoice`] with cached hash. The signature is not checked and may be
/// invalid.
///
/// # Invariants
-/// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
+/// The hash has to be either from the deserialized invoice or from the serialized [`RawBolt11Invoice`].
#[must_use]
#[repr(C)]
-pub struct SignedRawInvoice {
+pub struct SignedRawBolt11Invoice {
/// 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 nativeSignedRawInvoice,
+ pub inner: *mut nativeSignedRawBolt11Invoice,
/// 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
pub is_owned: bool,
}
-impl Drop for SignedRawInvoice {
+impl Drop for SignedRawBolt11Invoice {
fn drop(&mut self) {
- if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
- let _ = unsafe { Box::from_raw(self.inner) };
+ if self.is_owned && !<*mut nativeSignedRawBolt11Invoice>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
}
}
}
-/// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
+/// Frees any resources used by the SignedRawBolt11Invoice, if is_owned is set and inner is non-NULL.
#[no_mangle]
-pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
+pub extern "C" fn SignedRawBolt11Invoice_free(this_obj: SignedRawBolt11Invoice) { }
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
-extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
+pub(crate) extern "C" fn SignedRawBolt11Invoice_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSignedRawBolt11Invoice) };
}
#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
-impl SignedRawInvoice {
- pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
+impl SignedRawBolt11Invoice {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawBolt11Invoice {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawBolt11Invoice {
+ 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 nativeSignedRawBolt11Invoice {
assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
ret
}
}
-impl Clone for SignedRawInvoice {
+/// Checks if two SignedRawBolt11Invoices 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 SignedRawBolt11Invoice_eq(a: &SignedRawBolt11Invoice, b: &SignedRawBolt11Invoice) -> 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 }
+}
+/// Get a string which allows debug introspection of a SignedRawBolt11Invoice object
+pub extern "C" fn SignedRawBolt11Invoice_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::SignedRawBolt11Invoice }).into()}
+impl Clone for SignedRawBolt11Invoice {
fn clone(&self) -> Self {
Self {
- inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
- Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
+ inner: if <*mut nativeSignedRawBolt11Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
+ ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
is_owned: true,
}
}
}
#[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_clone_void(this_ptr: *const c_void) -> *mut c_void {
- Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
+pub(crate) extern "C" fn SignedRawBolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeSignedRawBolt11Invoice)).clone() })) as *mut c_void
}
#[no_mangle]
-/// Creates a copy of the SignedRawInvoice
-pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
+/// Creates a copy of the SignedRawBolt11Invoice
+pub extern "C" fn SignedRawBolt11Invoice_clone(orig: &SignedRawBolt11Invoice) -> SignedRawBolt11Invoice {
orig.clone()
}
+/// Generates a non-cryptographic 64-bit hash of the SignedRawBolt11Invoice.
+#[no_mangle]
+pub extern "C" fn SignedRawBolt11Invoice_hash(o: &SignedRawBolt11Invoice) -> 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;
-type nativeRawInvoice = nativeRawInvoiceImport;
+use lightning_invoice::RawBolt11Invoice as nativeRawBolt11InvoiceImport;
+pub(crate) type nativeRawBolt11Invoice = nativeRawBolt11InvoiceImport;
-/// Represents an syntactically correct Invoice for a payment on the lightning network,
+/// Represents an syntactically correct [`Bolt11Invoice`] for a payment on the lightning network,
/// but without the signature information.
-/// De- and encoding should not lead to information loss but may lead to different hashes.
+/// Decoding and encoding should not lead to information loss but may lead to different hashes.
///
-/// For methods without docs see the corresponding methods in `Invoice`.
+/// For methods without docs see the corresponding methods in [`Bolt11Invoice`].
#[must_use]
#[repr(C)]
-pub struct RawInvoice {
+pub struct RawBolt11Invoice {
/// 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 nativeRawInvoice,
+ pub inner: *mut nativeRawBolt11Invoice,
/// 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
pub is_owned: bool,
}
-impl Drop for RawInvoice {
+impl Drop for RawBolt11Invoice {
fn drop(&mut self) {
- if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
- let _ = unsafe { Box::from_raw(self.inner) };
+ if self.is_owned && !<*mut nativeRawBolt11Invoice>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
}
}
}
-/// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
+/// Frees any resources used by the RawBolt11Invoice, if is_owned is set and inner is non-NULL.
#[no_mangle]
-pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
+pub extern "C" fn RawBolt11Invoice_free(this_obj: RawBolt11Invoice) { }
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
-extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
+pub(crate) extern "C" fn RawBolt11Invoice_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawBolt11Invoice) };
}
#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
-impl RawInvoice {
- pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
+impl RawBolt11Invoice {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeRawBolt11Invoice {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawBolt11Invoice {
+ 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 nativeRawBolt11Invoice {
assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
ret
}
}
/// data part
#[no_mangle]
-pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
- let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.data;
- crate::lightning_invoice::RawDataPart { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
+pub extern "C" fn RawBolt11Invoice_get_data(this_ptr: &RawBolt11Invoice) -> crate::lightning_invoice::RawDataPart {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
+ crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
}
/// data part
#[no_mangle]
-pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
- unsafe { &mut *this_ptr.inner }.data = *unsafe { Box::from_raw(val.take_inner()) };
+pub extern "C" fn RawBolt11Invoice_set_data(this_ptr: &mut RawBolt11Invoice, mut val: crate::lightning_invoice::RawDataPart) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
}
-impl Clone for RawInvoice {
+/// Checks if two RawBolt11Invoices 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 RawBolt11Invoice_eq(a: &RawBolt11Invoice, b: &RawBolt11Invoice) -> 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 }
+}
+/// Get a string which allows debug introspection of a RawBolt11Invoice object
+pub extern "C" fn RawBolt11Invoice_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::RawBolt11Invoice }).into()}
+impl Clone for RawBolt11Invoice {
fn clone(&self) -> Self {
Self {
- inner: if <*mut nativeRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
- Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
+ inner: if <*mut nativeRawBolt11Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
+ ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
is_owned: true,
}
}
}
#[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_clone_void(this_ptr: *const c_void) -> *mut c_void {
- Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
+pub(crate) extern "C" fn RawBolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRawBolt11Invoice)).clone() })) as *mut c_void
}
#[no_mangle]
-/// Creates a copy of the RawInvoice
-pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
+/// Creates a copy of the RawBolt11Invoice
+pub extern "C" fn RawBolt11Invoice_clone(orig: &RawBolt11Invoice) -> RawBolt11Invoice {
orig.clone()
}
+/// Generates a non-cryptographic 64-bit hash of the RawBolt11Invoice.
+#[no_mangle]
+pub extern "C" fn RawBolt11Invoice_hash(o: &RawBolt11Invoice) -> 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;
-type nativeRawDataPart = nativeRawDataPartImport;
+pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
-/// Data of the `RawInvoice` that is encoded in the data part
+/// Data of the [`RawBolt11Invoice`] that is encoded in the data part
#[must_use]
#[repr(C)]
pub struct RawDataPart {
impl Drop for RawDataPart {
fn drop(&mut self) {
if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
- let _ = unsafe { Box::from_raw(self.inner) };
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
}
}
}
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
-extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
+pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawDataPart) };
}
#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
impl RawDataPart {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
+ 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 nativeRawDataPart {
assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
ret
}
}
/// generation time of the invoice
#[no_mangle]
pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
- let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.timestamp;
- crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
+ crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
}
/// generation time of the invoice
#[no_mangle]
pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
- unsafe { &mut *this_ptr.inner }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
}
+/// Checks if two RawDataParts 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 RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> 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 }
+}
+/// Get a string which allows debug introspection of a RawDataPart object
+pub extern "C" fn RawDataPart_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::RawDataPart }).into()}
impl Clone for RawDataPart {
fn clone(&self) -> Self {
Self {
- inner: if <*mut nativeRawDataPart>::is_null(self.inner) { std::ptr::null_mut() } else {
- Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
+ 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,
}
}
#[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_clone_void(this_ptr: *const c_void) -> *mut c_void {
- Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRawDataPart)).clone() })) as *mut c_void
}
#[no_mangle]
/// Creates a copy of the RawDataPart
pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
orig.clone()
}
+/// Generates a non-cryptographic 64-bit hash of the RawDataPart.
+#[no_mangle]
+pub extern "C" fn RawDataPart_hash(o: &RawDataPart) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // 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;
-type nativePositiveTimestamp = 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 {
impl Drop for PositiveTimestamp {
fn drop(&mut self) {
if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
- let _ = unsafe { Box::from_raw(self.inner) };
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
}
}
}
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
-extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
+pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativePositiveTimestamp) };
}
#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
impl PositiveTimestamp {
+ pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
+ 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 nativePositiveTimestamp {
assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
ret
}
}
+/// Checks if two PositiveTimestamps 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 PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> 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 }
+}
+/// Get a string which allows debug introspection of a PositiveTimestamp object
+pub extern "C" fn PositiveTimestamp_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::PositiveTimestamp }).into()}
impl Clone for PositiveTimestamp {
fn clone(&self) -> Self {
Self {
- inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { std::ptr::null_mut() } else {
- Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
+ 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,
}
}
#[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_clone_void(this_ptr: *const c_void) -> *mut c_void {
- Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePositiveTimestamp)).clone() })) as *mut c_void
}
#[no_mangle]
/// Creates a copy of the PositiveTimestamp
pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
orig.clone()
}
+/// Generates a non-cryptographic 64-bit hash of the PositiveTimestamp.
+#[no_mangle]
+pub extern "C" fn PositiveTimestamp_hash(o: &PositiveTimestamp) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
/// SI prefixes for the human readable part
-#[must_use]
#[derive(Clone)]
+#[must_use]
#[repr(C)]
pub enum SiPrefix {
/// 10^-3
/// 10^-12
Pico,
}
-use lightning_invoice::SiPrefix as nativeSiPrefix;
+use lightning_invoice::SiPrefix as SiPrefixImport;
+pub(crate) type nativeSiPrefix = SiPrefixImport;
+
impl SiPrefix {
#[allow(unused)]
pub(crate) fn to_native(&self) -> nativeSiPrefix {
}
}
#[allow(unused)]
- pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
+ pub(crate) fn from_native(native: &SiPrefixImport) -> Self {
+ let native = unsafe { &*(native as *const _ as *const c_void as *const nativeSiPrefix) };
match native {
nativeSiPrefix::Milli => SiPrefix::Milli,
nativeSiPrefix::Micro => SiPrefix::Micro,
pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
orig.clone()
}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn SiPrefix_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SiPrefix)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn SiPrefix_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut SiPrefix) };
+}
+#[no_mangle]
+/// Utility method to constructs a new Milli-variant SiPrefix
+pub extern "C" fn SiPrefix_milli() -> SiPrefix {
+ SiPrefix::Milli}
+#[no_mangle]
+/// Utility method to constructs a new Micro-variant SiPrefix
+pub extern "C" fn SiPrefix_micro() -> SiPrefix {
+ SiPrefix::Micro}
+#[no_mangle]
+/// Utility method to constructs a new Nano-variant SiPrefix
+pub extern "C" fn SiPrefix_nano() -> SiPrefix {
+ SiPrefix::Nano}
+#[no_mangle]
+/// Utility method to constructs a new Pico-variant SiPrefix
+pub extern "C" fn SiPrefix_pico() -> SiPrefix {
+ SiPrefix::Pico}
+/// Checks if two SiPrefixs contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+/// Get a string which allows debug introspection of a SiPrefix object
+pub extern "C" fn SiPrefix_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::SiPrefix }).into()}
+/// Generates a non-cryptographic 64-bit hash of the SiPrefix.
+#[no_mangle]
+pub extern "C" fn SiPrefix_hash(o: &SiPrefix) -> u64 {
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[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
BitcoinTestnet,
/// Bitcoin regtest
Regtest,
- /// Bitcoin simnet/signet
+ /// Bitcoin simnet
Simnet,
+ /// 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 {
Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
Currency::Regtest => nativeCurrency::Regtest,
Currency::Simnet => nativeCurrency::Simnet,
+ Currency::Signet => nativeCurrency::Signet,
}
}
#[allow(unused)]
Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
Currency::Regtest => nativeCurrency::Regtest,
Currency::Simnet => nativeCurrency::Simnet,
+ Currency::Signet => nativeCurrency::Signet,
}
}
#[allow(unused)]
- pub(crate) fn from_native(native: &nativeCurrency) -> Self {
+ pub(crate) fn from_native(native: &CurrencyImport) -> Self {
+ let native = unsafe { &*(native as *const _ as *const c_void as *const nativeCurrency) };
match native {
nativeCurrency::Bitcoin => Currency::Bitcoin,
nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
nativeCurrency::Regtest => Currency::Regtest,
nativeCurrency::Simnet => Currency::Simnet,
+ nativeCurrency::Signet => Currency::Signet,
}
}
#[allow(unused)]
nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
nativeCurrency::Regtest => Currency::Regtest,
nativeCurrency::Simnet => Currency::Simnet,
+ nativeCurrency::Signet => Currency::Signet,
}
}
}
pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
orig.clone()
}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn Currency_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Currency)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn Currency_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut Currency) };
+}
+#[no_mangle]
+/// Utility method to constructs a new Bitcoin-variant Currency
+pub extern "C" fn Currency_bitcoin() -> Currency {
+ Currency::Bitcoin}
+#[no_mangle]
+/// Utility method to constructs a new BitcoinTestnet-variant Currency
+pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
+ Currency::BitcoinTestnet}
+#[no_mangle]
+/// Utility method to constructs a new Regtest-variant Currency
+pub extern "C" fn Currency_regtest() -> Currency {
+ Currency::Regtest}
+#[no_mangle]
+/// Utility method to constructs a new Simnet-variant Currency
+pub extern "C" fn Currency_simnet() -> Currency {
+ Currency::Simnet}
+#[no_mangle]
+/// Utility method to constructs a new Signet-variant Currency
+pub extern "C" fn Currency_signet() -> Currency {
+ Currency::Signet}
+/// Get a string which allows debug introspection of a Currency object
+pub extern "C" fn Currency_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Currency }).into()}
+/// Generates a non-cryptographic 64-bit hash of the Currency.
+#[no_mangle]
+pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ 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.
+#[no_mangle]
+pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
use lightning_invoice::Sha256 as nativeSha256Import;
-type nativeSha256 = nativeSha256Import;
+pub(crate) type nativeSha256 = nativeSha256Import;
/// SHA-256 hash
#[must_use]
impl Drop for Sha256 {
fn drop(&mut self) {
if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
- let _ = unsafe { Box::from_raw(self.inner) };
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
}
}
}
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
-extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
+pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSha256) };
}
#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
impl Sha256 {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
+ 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 nativeSha256 {
assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
+ let ret = ObjOps::untweak_ptr(self.inner);
+ 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 {
- Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
+ 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,
}
}
#[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_clone_void(this_ptr: *const c_void) -> *mut c_void {
- Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeSha256)).clone() })) as *mut c_void
}
#[no_mangle]
/// Creates a copy of the Sha256
pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
orig.clone()
}
+/// Get a string which allows debug introspection of a Sha256 object
+pub extern "C" fn Sha256_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Sha256 }).into()}
+/// Generates a non-cryptographic 64-bit hash of the Sha256.
+#[no_mangle]
+pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // 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 Sha256s 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 Sha256_eq(a: &Sha256, b: &Sha256) -> 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 }
+}
+/// Constructs a new [`Sha256`] from the given bytes, which are assumed to be the output of a
+/// single sha256 hash.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Sha256_from_bytes(bytes: *const [u8; 32]) -> crate::lightning_invoice::Sha256 {
+ let mut ret = lightning_invoice::Sha256::from_bytes(unsafe { &*bytes});
+ crate::lightning_invoice::Sha256 { inner: ObjOps::heap_alloc(ret), is_owned: true }
+}
+
use lightning_invoice::Description as nativeDescriptionImport;
-type nativeDescription = nativeDescriptionImport;
+pub(crate) type nativeDescription = nativeDescriptionImport;
/// Description string
///
impl Drop for Description {
fn drop(&mut self) {
if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
- let _ = unsafe { Box::from_raw(self.inner) };
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
}
}
}
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
-extern "C" fn Description_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
+pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDescription) };
}
#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
impl Description {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
+ 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 nativeDescription {
assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
+ let ret = ObjOps::untweak_ptr(self.inner);
+ 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 {
- Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
+ 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,
}
}
#[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_clone_void(this_ptr: *const c_void) -> *mut c_void {
- Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDescription)).clone() })) as *mut c_void
}
#[no_mangle]
/// Creates a copy of the Description
pub extern "C" fn Description_clone(orig: &Description) -> Description {
orig.clone()
}
+/// Get a string which allows debug introspection of a Description object
+pub extern "C" fn Description_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Description }).into()}
+/// Generates a non-cryptographic 64-bit hash of the Description.
+#[no_mangle]
+pub extern "C" fn Description_hash(o: &Description) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // 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 Descriptions 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 Description_eq(a: &Description, b: &Description) -> 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 }
+}
use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
-type nativePayeePubKey = nativePayeePubKeyImport;
+pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
/// Payee public key
#[must_use]
impl Drop for PayeePubKey {
fn drop(&mut self) {
if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
- let _ = unsafe { Box::from_raw(self.inner) };
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
}
}
}
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
-extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
+pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativePayeePubKey) };
}
#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
impl PayeePubKey {
+ pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
+ 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 nativePayeePubKey {
assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
ret
}
}
+#[no_mangle]
+pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
+ crate::c_types::PublicKey::from_rust(&inner_val)
+}
+#[no_mangle]
+pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
+}
+/// Constructs a new PayeePubKey given each field
+#[must_use]
+#[no_mangle]
+pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
+ PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
+ a_arg.into_rust(),
+ )), is_owned: true }
+}
impl Clone for PayeePubKey {
fn clone(&self) -> Self {
Self {
- inner: if <*mut nativePayeePubKey>::is_null(self.inner) { std::ptr::null_mut() } else {
- Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
+ 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,
}
}
#[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_clone_void(this_ptr: *const c_void) -> *mut c_void {
- Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePayeePubKey)).clone() })) as *mut c_void
}
#[no_mangle]
/// Creates a copy of the PayeePubKey
pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
orig.clone()
}
+/// Get a string which allows debug introspection of a PayeePubKey object
+pub extern "C" fn PayeePubKey_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::PayeePubKey }).into()}
+/// Generates a non-cryptographic 64-bit hash of the PayeePubKey.
+#[no_mangle]
+pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // 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 PayeePubKeys 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 PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> 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 }
+}
use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
-type nativeExpiryTime = nativeExpiryTimeImport;
+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 {
impl Drop for ExpiryTime {
fn drop(&mut self) {
if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
- let _ = unsafe { Box::from_raw(self.inner) };
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
}
}
}
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
-extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
+pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeExpiryTime) };
}
#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
impl ExpiryTime {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
+ 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 nativeExpiryTime {
assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
+ let ret = ObjOps::untweak_ptr(self.inner);
+ 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 {
- Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
+ 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,
}
}
#[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_clone_void(this_ptr: *const c_void) -> *mut c_void {
- Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeExpiryTime)).clone() })) as *mut c_void
}
#[no_mangle]
/// Creates a copy of the ExpiryTime
pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
orig.clone()
}
+/// Get a string which allows debug introspection of a ExpiryTime object
+pub extern "C" fn ExpiryTime_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::ExpiryTime }).into()}
+/// Generates a non-cryptographic 64-bit hash of the ExpiryTime.
+#[no_mangle]
+pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // 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 ExpiryTimes 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 ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> 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 }
+}
-use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
-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
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) {
- let _ = unsafe { Box::from_raw(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
-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)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
-impl MinFinalCltvExpiry {
- pub(crate) fn take_inner(mut self) -> *mut 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 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 nativeMinFinalCltvExpiryDelta {
assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
ret
}
}
-impl Clone for MinFinalCltvExpiry {
+#[no_mangle]
+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 MinFinalCltvExpiryDelta_set_a(this_ptr: &mut MinFinalCltvExpiryDelta, mut val: u64) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
+}
+/// Constructs a new MinFinalCltvExpiryDelta given each field
+#[must_use]
+#[no_mangle]
+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 MinFinalCltvExpiryDelta {
fn clone(&self) -> Self {
Self {
- inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else {
- Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
+ 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,
}
}
}
#[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 *const 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()
}
+/// Get a string which allows debug introspection of a MinFinalCltvExpiryDelta object
+pub extern "C" fn MinFinalCltvExpiryDelta_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::MinFinalCltvExpiryDelta }).into()}
+/// Generates a non-cryptographic 64-bit hash of the MinFinalCltvExpiryDelta.
+#[no_mangle]
+pub extern "C" fn MinFinalCltvExpiryDelta_hash(o: &MinFinalCltvExpiryDelta) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // 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 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 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::WitnessVersion,
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(),
}
},
Fallback::PubKeyHash (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeFallback::PubKeyHash (
- a_nonref.data,
+ bitcoin::hash_types::PubkeyHash::from_raw_hash(bitcoin::hashes::Hash::from_byte_array(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,
+ bitcoin::hash_types::ScriptHash::from_raw_hash(bitcoin::hashes::Hash::from_byte_array(a_nonref.data)),
)
},
}
},
Fallback::PubKeyHash (mut a, ) => {
nativeFallback::PubKeyHash (
- a.data,
+ bitcoin::hash_types::PubkeyHash::from_raw_hash(bitcoin::hashes::Hash::from_byte_array(a.data)),
)
},
Fallback::ScriptHash (mut a, ) => {
nativeFallback::ScriptHash (
- a.data,
+ bitcoin::hash_types::ScriptHash::from_raw_hash(bitcoin::hashes::Hash::from_byte_array(a.data)),
)
},
}
}
#[allow(unused)]
- pub(crate) fn from_native(native: &nativeFallback) -> Self {
+ pub(crate) fn from_native(native: &FallbackImport) -> Self {
+ let native = unsafe { &*(native as *const _ as *const c_void as *const nativeFallback) };
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(),
}
},
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 },
+ crate::c_types::TwentyBytes { data: *a_nonref.as_ref() },
)
},
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 },
+ crate::c_types::TwentyBytes { data: *a_nonref.as_ref() },
)
},
}
},
nativeFallback::PubKeyHash (mut a, ) => {
Fallback::PubKeyHash (
- crate::c_types::TwentyBytes { data: a },
+ crate::c_types::TwentyBytes { data: *a.as_ref() },
)
},
nativeFallback::ScriptHash (mut a, ) => {
Fallback::ScriptHash (
- crate::c_types::TwentyBytes { data: a },
+ crate::c_types::TwentyBytes { data: *a.as_ref() },
)
},
}
pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
orig.clone()
}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn Fallback_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Fallback)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn Fallback_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut Fallback) };
+}
+#[no_mangle]
+/// Utility method to constructs a new SegWitProgram-variant Fallback
+pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::WitnessVersion, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
+ Fallback::SegWitProgram {
+ version,
+ program,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new PubKeyHash-variant Fallback
+pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
+ Fallback::PubKeyHash(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new ScriptHash-variant Fallback
+pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
+ Fallback::ScriptHash(a, )
+}
+/// Get a string which allows debug introspection of a Fallback object
+pub extern "C" fn Fallback_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Fallback }).into()}
+/// Generates a non-cryptographic 64-bit hash of the Fallback.
+#[no_mangle]
+pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ 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.
+#[no_mangle]
+pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
-use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
-type nativeInvoiceSignature = nativeInvoiceSignatureImport;
+use lightning_invoice::Bolt11InvoiceSignature as nativeBolt11InvoiceSignatureImport;
+pub(crate) type nativeBolt11InvoiceSignature = nativeBolt11InvoiceSignatureImport;
/// Recoverable signature
#[must_use]
#[repr(C)]
-pub struct InvoiceSignature {
+pub struct Bolt11InvoiceSignature {
/// 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 nativeInvoiceSignature,
+ pub inner: *mut nativeBolt11InvoiceSignature,
/// 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
pub is_owned: bool,
}
-impl Drop for InvoiceSignature {
+impl Drop for Bolt11InvoiceSignature {
fn drop(&mut self) {
- if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
- let _ = unsafe { Box::from_raw(self.inner) };
+ if self.is_owned && !<*mut nativeBolt11InvoiceSignature>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
}
}
}
-/// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
+/// Frees any resources used by the Bolt11InvoiceSignature, if is_owned is set and inner is non-NULL.
#[no_mangle]
-pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
+pub extern "C" fn Bolt11InvoiceSignature_free(this_obj: Bolt11InvoiceSignature) { }
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
-extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
+pub(crate) extern "C" fn Bolt11InvoiceSignature_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt11InvoiceSignature) };
}
#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
-impl InvoiceSignature {
- pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
+impl Bolt11InvoiceSignature {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeBolt11InvoiceSignature {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt11InvoiceSignature {
+ 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 nativeBolt11InvoiceSignature {
assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
ret
}
}
-impl Clone for InvoiceSignature {
+impl Clone for Bolt11InvoiceSignature {
fn clone(&self) -> Self {
Self {
- inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else {
- Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
+ inner: if <*mut nativeBolt11InvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else {
+ ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
is_owned: true,
}
}
}
#[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_clone_void(this_ptr: *const c_void) -> *mut c_void {
- Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
+pub(crate) extern "C" fn Bolt11InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt11InvoiceSignature)).clone() })) as *mut c_void
}
#[no_mangle]
-/// Creates a copy of the InvoiceSignature
-pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
+/// Creates a copy of the Bolt11InvoiceSignature
+pub extern "C" fn Bolt11InvoiceSignature_clone(orig: &Bolt11InvoiceSignature) -> Bolt11InvoiceSignature {
orig.clone()
}
+/// Get a string which allows debug introspection of a Bolt11InvoiceSignature object
+pub extern "C" fn Bolt11InvoiceSignature_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Bolt11InvoiceSignature }).into()}
+/// Generates a non-cryptographic 64-bit hash of the Bolt11InvoiceSignature.
+#[no_mangle]
+pub extern "C" fn Bolt11InvoiceSignature_hash(o: &Bolt11InvoiceSignature) -> 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 Bolt11InvoiceSignatures 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 Bolt11InvoiceSignature_eq(a: &Bolt11InvoiceSignature, b: &Bolt11InvoiceSignature) -> 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 }
+}
-use lightning_invoice::RouteHint as nativeRouteHintImport;
-type nativeRouteHint = nativeRouteHintImport;
+use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
+pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
/// Private routing information
///
///
#[must_use]
#[repr(C)]
-pub struct RouteHint {
+pub struct PrivateRoute {
/// 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 nativeRouteHint,
+ pub inner: *mut nativePrivateRoute,
/// 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
pub is_owned: bool,
}
-impl Drop for RouteHint {
+impl Drop for PrivateRoute {
fn drop(&mut self) {
- if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
- let _ = unsafe { Box::from_raw(self.inner) };
+ if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
}
}
}
-/// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
+/// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
#[no_mangle]
-pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
+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
-extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHint); }
+pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativePrivateRoute) };
}
#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
-impl RouteHint {
- pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
+impl PrivateRoute {
+ pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
+ 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 nativePrivateRoute {
assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
ret
}
}
-impl Clone for RouteHint {
+impl Clone for PrivateRoute {
fn clone(&self) -> Self {
Self {
- inner: if <*mut nativeRouteHint>::is_null(self.inner) { std::ptr::null_mut() } else {
- Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
+ 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,
}
}
}
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
-pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
- Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void
+pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePrivateRoute)).clone() })) as *mut c_void
}
#[no_mangle]
-/// Creates a copy of the RouteHint
-pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
+/// Creates a copy of the PrivateRoute
+pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
orig.clone()
}
-/// Disassembles the `SignedRawInvoice` into its three parts:
+/// Get a string which allows debug introspection of a PrivateRoute object
+pub extern "C" fn PrivateRoute_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::PrivateRoute }).into()}
+/// Generates a non-cryptographic 64-bit hash of the PrivateRoute.
+#[no_mangle]
+pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // 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 PrivateRoutes 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 PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> 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 }
+}
+/// Disassembles the `SignedRawBolt11Invoice` into its three parts:
/// 1. raw invoice
/// 2. hash of the raw invoice
/// 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 SignedRawBolt11Invoice_into_parts(mut this_arg: crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::c_types::derived::C3Tuple_RawBolt11Invoice_u832Bolt11InvoiceSignatureZ {
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: Box::into_raw(Box::new(orig_ret_0)), is_owned: true }, crate::c_types::ThirtyTwoBytes { data: orig_ret_1 }, crate::lightning_invoice::InvoiceSignature { inner: Box::into_raw(Box::new(orig_ret_2)), is_owned: true }).into();
+ let (mut orig_ret_0, mut orig_ret_1, mut orig_ret_2) = ret; let mut local_ret = (crate::lightning_invoice::RawBolt11Invoice { inner: ObjOps::heap_alloc(orig_ret_0), is_owned: true }, crate::c_types::ThirtyTwoBytes { data: orig_ret_1 }, crate::lightning_invoice::Bolt11InvoiceSignature { inner: ObjOps::heap_alloc(orig_ret_2), is_owned: true }).into();
local_ret
}
-/// The `RawInvoice` which was signed.
+/// The [`RawBolt11Invoice`] which was signed.
#[must_use]
#[no_mangle]
-pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
- let mut ret = unsafe { &*this_arg.inner }.raw_invoice();
- crate::lightning_invoice::RawInvoice { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
+pub extern "C" fn SignedRawBolt11Invoice_raw_invoice(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::lightning_invoice::RawBolt11Invoice {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
+ crate::lightning_invoice::RawBolt11Invoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawBolt11Invoice<>) as *mut _) }, is_owned: false }
}
-/// The hash of the `RawInvoice` that was signed.
+/// The hash of the [`RawBolt11Invoice`] that was signed.
#[must_use]
#[no_mangle]
-pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
- let mut ret = unsafe { &*this_arg.inner }.hash();
+pub extern "C" fn SignedRawBolt11Invoice_signable_hash(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> *const [u8; 32] {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
ret
}
-/// InvoiceSignature for the invoice.
+/// Signature for the invoice.
#[must_use]
#[no_mangle]
-pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
- let mut ret = unsafe { &*this_arg.inner }.signature();
- crate::lightning_invoice::InvoiceSignature { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
+pub extern "C" fn SignedRawBolt11Invoice_signature(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::lightning_invoice::Bolt11InvoiceSignature {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
+ crate::lightning_invoice::Bolt11InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::Bolt11InvoiceSignature<>) as *mut _) }, is_owned: false }
}
/// 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 {
- let mut ret = unsafe { &*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: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
+pub extern "C" fn SignedRawBolt11Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::c_types::derived::CResult_PayeePubKeySecp256k1ErrorZ {
+ 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
}
/// 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 {
- let mut ret = unsafe { &*this_arg.inner }.check_signature();
+pub extern "C" fn SignedRawBolt11Invoice_check_signature(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> 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 `RawBolt11Invoice` 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 { &*this_arg.inner }.hash();
+pub extern "C" fn RawBolt11Invoice_signable_hash(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::ThirtyTwoBytes {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
crate::c_types::ThirtyTwoBytes { data: ret }
}
+///
+/// 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 RawBolt11Invoice_payment_hash(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> 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() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false };
+ local_ret
+}
+
+///
+/// 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 {
- let mut ret = unsafe { &*this_arg.inner }.payment_hash();
- let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
+pub extern "C" fn RawBolt11Invoice_description(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> 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() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Description<>) as *mut _ }, is_owned: false };
local_ret
}
+///
+/// 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 {
- let mut ret = unsafe { &*this_arg.inner }.description();
- let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
+pub extern "C" fn RawBolt11Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> 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() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::PayeePubKey<>) as *mut _ }, is_owned: false };
local_ret
}
+///
+/// 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 {
- let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
- let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
+pub extern "C" fn RawBolt11Invoice_description_hash(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> 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() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false };
local_ret
}
+///
+/// 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 {
- let mut ret = unsafe { &*this_arg.inner }.description_hash();
- let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
+pub extern "C" fn RawBolt11Invoice_expiry_time(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> 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() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::ExpiryTime<>) as *mut _ }, is_owned: false };
local_ret
}
+///
+/// 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 {
- let mut ret = unsafe { &*this_arg.inner }.expiry_time();
- let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
+pub extern "C" fn RawBolt11Invoice_min_final_cltv_expiry_delta(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> 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
}
#[must_use]
#[no_mangle]
-pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
- let mut ret = unsafe { &*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 { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
+pub extern "C" fn RawBolt11Invoice_payment_secret(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::COption_ThirtyTwoBytesZ {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
+ let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: (*ret.as_ref().unwrap()).clone().0 } }) };
local_ret
}
#[must_use]
#[no_mangle]
-pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
- let mut ret = unsafe { &*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 } } };
+pub extern "C" fn RawBolt11Invoice_payment_metadata(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_metadata();
+ let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { let mut local_ret_0 = Vec::new(); for mut item in (*ret.as_ref().unwrap()).clone().drain(..) { local_ret_0.push( { item }); }; local_ret_0.into() }) };
local_ret
}
+///
+/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
#[must_use]
#[no_mangle]
-pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
- let mut ret = unsafe { &*this_arg.inner }.features();
- let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
+pub extern "C" fn RawBolt11Invoice_features(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning::ln::features::Bolt11InvoiceFeatures {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
+ let mut local_ret = crate::lightning::ln::features::Bolt11InvoiceFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::Bolt11InvoiceFeatures<>) as *mut _ }, is_owned: false };
local_ret
}
#[must_use]
#[no_mangle]
-pub extern "C" fn RawInvoice_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_RouteHintZ {
- let mut ret = unsafe { &*this_arg.inner }.routes();
- let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::RouteHint { inner: unsafe { ( (&(**item) as *const _) as *mut _) }, is_owned: false } }); };
+pub extern "C" fn RawBolt11Invoice_private_routes(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> 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()
}
+/// Returns `None` if no amount is set or on overflow.
#[must_use]
#[no_mangle]
-pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
- let mut ret = unsafe { &*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()) } };
+pub extern "C" fn RawBolt11Invoice_amount_pico_btc(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> 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
}
#[must_use]
#[no_mangle]
-pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
- let mut ret = unsafe { &*this_arg.inner }.currency();
+pub extern "C" fn RawBolt11Invoice_currency(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> 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 {
let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
- let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
+ 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
}
-/// 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 {
let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
- let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
+ 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
+}
+
+/// 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_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
+/// Returns the Unix timestamp representing the stored time
#[must_use]
#[no_mangle]
-pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
- let mut ret = unsafe { &*this_arg.inner }.as_unix_timestamp();
+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_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: &PositiveTimestamp) -> u64 {
- let mut ret = unsafe { &*this_arg.inner }.as_time();
+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()
}
-/// Transform the `Invoice` into it's unchecked version
+/// The hash of the [`RawBolt11Invoice`] that was signed.
#[must_use]
#[no_mangle]
-pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
+pub extern "C" fn Bolt11Invoice_signable_hash(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::ThirtyTwoBytes {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
+ crate::c_types::ThirtyTwoBytes { data: ret }
+}
+
+/// Transform the `Bolt11Invoice` into its unchecked version.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Bolt11Invoice_into_signed_raw(mut this_arg: crate::lightning_invoice::Bolt11Invoice) -> crate::lightning_invoice::SignedRawBolt11Invoice {
let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
- crate::lightning_invoice::SignedRawInvoice { inner: Box::into_raw(Box::new(ret)), is_owned: true }
+ crate::lightning_invoice::SignedRawBolt11Invoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
}
/// 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 {
- let mut ret = unsafe { &*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() };
+pub extern "C" fn Bolt11Invoice_check_signature(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CResult_NoneBolt11SemanticErrorZ {
+ 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::Bolt11SemanticError::native_into(e) }).into() };
local_ret
}
-/// Constructs an `Invoice` from a `SignedInvoice` by checking all its invariants.
+/// Constructs a `Bolt11Invoice` from a [`SignedRawBolt11Invoice`] by checking all its invariants.
/// ```
/// use lightning_invoice::*;
///
-/// let invoice = \"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp\\
-/// \tl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d7\\
-/// \t3gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ec\\
-/// \tky03ylcqca784w\";
+/// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
+/// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
+/// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
+/// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
+/// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
+/// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
+/// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
+/// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
+/// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
+/// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
+/// j5r6drg6k6zcqj0fcwg\";
///
-/// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
+/// let signed = invoice.parse::<SignedRawBolt11Invoice>().unwrap();
///
-/// assert!(Invoice::from_signed(signed).is_ok());
+/// assert!(Bolt11Invoice::from_signed(signed).is_ok());
/// ```
#[must_use]
#[no_mangle]
-pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
- let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
- let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Invoice { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::SemanticError::native_into(e) }).into() };
+pub extern "C" fn Bolt11Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::c_types::derived::CResult_Bolt11InvoiceBolt11SemanticErrorZ {
+ let mut ret = lightning_invoice::Bolt11Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
+ let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Bolt11Invoice { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::Bolt11SemanticError::native_into(e) }).into() };
local_ret
}
-/// Returns the `Invoice`'s timestamp (should equal it's creation time)
+/// Returns the `Bolt11Invoice`'s timestamp (should equal its creation time)
#[must_use]
#[no_mangle]
-pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
- let mut ret = unsafe { &*this_arg.inner }.timestamp();
+pub extern "C" fn Bolt11Invoice_timestamp(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> 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 `Bolt11Invoice`'s timestamp as a duration since the Unix epoch
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Bolt11Invoice_duration_since_epoch(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> 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] {
- let mut ret = unsafe { &*this_arg.inner }.payment_hash();
- ret.as_inner()
+pub extern "C" fn Bolt11Invoice_payment_hash(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> *const [u8; 32] {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
+ ret.as_ref()
}
/// Get the payee's public key if one was included in the invoice
+///
+/// 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 {
- let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
+pub extern "C" fn Bolt11Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> 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
}
/// 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) -> crate::c_types::ThirtyTwoBytes {
- let mut ret = unsafe { &*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 } } };
+pub extern "C" fn Bolt11Invoice_payment_secret(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> *const [u8; 32] {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
+ &ret.0
+}
+
+/// Get the payment metadata blob if one was included in the invoice
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Bolt11Invoice_payment_metadata(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_metadata();
+ let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { let mut local_ret_0 = Vec::new(); for mut item in (*ret.as_ref().unwrap()).clone().drain(..) { local_ret_0.push( { item }); }; local_ret_0.into() }) };
local_ret
}
/// Get the invoice features if they were included in the invoice
+///
+/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
#[must_use]
#[no_mangle]
-pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
- let mut ret = unsafe { &*this_arg.inner }.features();
- let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
+pub extern "C" fn Bolt11Invoice_features(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::lightning::ln::features::Bolt11InvoiceFeatures {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
+ let mut local_ret = crate::lightning::ln::features::Bolt11InvoiceFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::Bolt11InvoiceFeatures<>) 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 {
- let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
+pub extern "C" fn Bolt11Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> 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)
}
+/// Recover the payee's public key if one was included in the invoice, otherwise return the
+/// recovered public key from the signature
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Bolt11Invoice_get_payee_pub_key(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::PublicKey {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_payee_pub_key();
+ crate::c_types::PublicKey::from_rust(&ret)
+}
+
+/// Returns the Duration since the Unix epoch at which the invoice expires.
+/// Returning None if overflow occurred.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Bolt11Invoice_expires_at(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::COption_u64Z {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expires_at();
+ let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap().as_secs() }) };
+ local_ret
+}
+
/// 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 {
- let mut ret = unsafe { &*this_arg.inner }.expiry_time();
+pub extern "C" fn Bolt11Invoice_expiry_time(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
+ ret.as_secs()
+}
+
+/// Returns whether the invoice has expired.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Bolt11Invoice_is_expired(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> bool {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
+ ret
+}
+
+/// Returns the Duration remaining until the invoice expires.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Bolt11Invoice_duration_until_expiry(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_until_expiry();
ret.as_secs()
}
-/// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
-/// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
+/// Returns the Duration remaining until the invoice expires given the current time.
+/// `time` is the timestamp as a duration since the Unix epoch.
#[must_use]
#[no_mangle]
-pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 {
- let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
+pub extern "C" fn Bolt11Invoice_expiration_remaining_from_epoch(this_arg: &crate::lightning_invoice::Bolt11Invoice, mut time: u64) -> u64 {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiration_remaining_from_epoch(core::time::Duration::from_secs(time));
+ ret.as_secs()
+}
+
+/// Returns whether the expiry time would pass at the given point in time.
+/// `at_time` is the timestamp as a duration since the Unix epoch.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Bolt11Invoice_would_expire(this_arg: &crate::lightning_invoice::Bolt11Invoice, 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 Bolt11Invoice_min_final_cltv_expiry_delta(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry_delta();
+ ret
+}
+
+/// Returns a list of all fallback addresses as [`Address`]es
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Bolt11Invoice_fallback_addresses(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CVec_StrZ {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fallback_addresses();
+ let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { alloc::string::ToString::to_string(&item).into() }); };
+ local_ret.into()
+}
+
/// Returns a list of all routes included in the invoice
#[must_use]
#[no_mangle]
-pub extern "C" fn Invoice_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
- let mut ret = unsafe { &*this_arg.inner }.routes();
- let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::RouteHint { inner: unsafe { ( (&(**item) as *const _) as *mut _) }, is_owned: false } }); };
+pub extern "C" fn Bolt11Invoice_private_routes(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> 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()
+}
+
+/// Returns a list of all routes included in the invoice as the underlying hints
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Bolt11Invoice_route_hints(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> 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()
}
/// 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 {
- let mut ret = unsafe { &*this_arg.inner }.currency();
+pub extern "C" fn Bolt11Invoice_currency(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::lightning_invoice::Currency {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
crate::lightning_invoice::Currency::native_into(ret)
}
-/// Returns the amount if specified in the invoice as pico <currency>.
+/// Returns the amount if specified in the invoice as millisatoshis.
#[must_use]
#[no_mangle]
-pub extern "C" fn Invoice_amount_pico_btc(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
- let mut ret = unsafe { &*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()) } };
+pub extern "C" fn Bolt11Invoice_amount_milli_satoshis(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> 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
}
/// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
-/// returns `CreationError::DescriptionTooLong` otherwise
+/// returns [`CreationError::DescriptionTooLong`] otherwise
///
/// Please note that single characters may use more than one byte due to UTF8 encoding.
#[must_use]
#[no_mangle]
pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
let mut ret = lightning_invoice::Description::new(description.into_string());
- let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Description { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
+ let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Description { 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 underlying description `String`
+/// Returns the underlying description [`UntrustedString`]
#[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::lightning::util::string::UntrustedString {
let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
- ret.into()
+ crate::lightning::util::string::UntrustedString { inner: ObjOps::heap_alloc(ret), is_owned: true }
}
-/// 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`.
+#[no_mangle]
+/// Get the string representation of a Description object
+pub extern "C" fn Description_to_str(o: &crate::lightning_invoice::Description) -> Str {
+ alloc::format!("{}", o.get_native_ref()).into()
+}
+/// 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: Box::into_raw(Box::new(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: Box::into_raw(Box::new(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 {
- let mut ret = unsafe { &*this_arg.inner }.as_seconds();
+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
}
-/// Returns a reference to the underlying `Duration` (=expiry time)
+/// Returns a reference to the underlying [`Duration`] (=expiry time)
#[must_use]
#[no_mangle]
-pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
- let mut ret = unsafe { &*this_arg.inner }.as_duration();
+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()
}
-/// Create a new (partial) route from a list of hops
+/// Creates a new (partial) route from a list of hops
#[must_use]
#[no_mangle]
-pub extern "C" fn RouteHint_new(mut hops: crate::c_types::derived::CVec_RouteHintHopZ) -> crate::c_types::derived::CResult_RouteHintCreationErrorZ {
- let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
- let mut ret = lightning_invoice::RouteHint::new(local_hops);
- let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::RouteHint { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
+pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
+ let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
+ let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PrivateRoute { 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
}
-/// Returrn the underlying vector of hops
+/// Returns the underlying list of hops
#[must_use]
#[no_mangle]
-pub extern "C" fn RouteHint_into_inner(mut this_arg: RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ {
+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();
- let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHintHop { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
- local_ret.into()
+ 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]
+/// Errors that may occur when constructing a new [`RawBolt11Invoice`] or [`Bolt11Invoice`]
#[derive(Clone)]
+#[must_use]
#[repr(C)]
pub enum CreationError {
- /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
+ /// The supplied description string was longer than 639 __bytes__ (see [`Description::new`])
DescriptionTooLong,
/// The specified route has too many hops and can't be encoded
RouteTooLong,
- /// 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 {
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)]
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)]
- pub(crate) fn from_native(native: &nativeCreationError) -> Self {
+ pub(crate) fn from_native(native: &CreationErrorImport) -> Self {
+ let native = unsafe { &*(native as *const _ as *const c_void as *const nativeCreationError) };
match native {
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)]
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,
}
}
}
pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
orig.clone()
}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn CreationError_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const CreationError)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn CreationError_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut CreationError) };
+}
+#[no_mangle]
+/// Utility method to constructs a new DescriptionTooLong-variant CreationError
+pub extern "C" fn CreationError_description_too_long() -> CreationError {
+ CreationError::DescriptionTooLong}
+#[no_mangle]
+/// Utility method to constructs a new RouteTooLong-variant CreationError
+pub extern "C" fn CreationError_route_too_long() -> CreationError {
+ CreationError::RouteTooLong}
+#[no_mangle]
+/// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
+pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
+ CreationError::TimestampOutOfBounds}
+#[no_mangle]
+/// 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]
+pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+/// Get a string which allows debug introspection of a CreationError object
+pub extern "C" fn CreationError_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::CreationError }).into()}
#[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]
+/// Errors that may occur when converting a [`RawBolt11Invoice`] to a [`Bolt11Invoice`]. They relate to
+/// the requirements sections in BOLT #11
#[derive(Clone)]
+#[must_use]
#[repr(C)]
-pub enum SemanticError {
+pub enum Bolt11SemanticError {
/// The invoice is missing the mandatory payment hash
NoPaymentHash,
/// The invoice has multiple payment hashes which isn't allowed
NoDescription,
/// The invoice contains multiple descriptions and/or description hashes which isn't allowed
MultipleDescriptions,
+ /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
+ /// should provide.
+ NoPaymentSecret,
+ /// The invoice contains multiple payment secrets
+ MultiplePaymentSecrets,
+ /// The invoice's features are invalid
+ InvalidFeatures,
/// The recovery id doesn't fit the signature/pub key
InvalidRecoveryId,
/// The invoice's signature is invalid
InvalidSignature,
+ /// The invoice's amount was not a whole number of millisatoshis
+ ImpreciseAmount,
}
-use lightning_invoice::SemanticError as nativeSemanticError;
-impl SemanticError {
+use lightning_invoice::Bolt11SemanticError as Bolt11SemanticErrorImport;
+pub(crate) type nativeBolt11SemanticError = Bolt11SemanticErrorImport;
+
+impl Bolt11SemanticError {
#[allow(unused)]
- pub(crate) fn to_native(&self) -> nativeSemanticError {
+ pub(crate) fn to_native(&self) -> nativeBolt11SemanticError {
match self {
- SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
- SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
- SemanticError::NoDescription => nativeSemanticError::NoDescription,
- SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
- SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
- SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
+ Bolt11SemanticError::NoPaymentHash => nativeBolt11SemanticError::NoPaymentHash,
+ Bolt11SemanticError::MultiplePaymentHashes => nativeBolt11SemanticError::MultiplePaymentHashes,
+ Bolt11SemanticError::NoDescription => nativeBolt11SemanticError::NoDescription,
+ Bolt11SemanticError::MultipleDescriptions => nativeBolt11SemanticError::MultipleDescriptions,
+ Bolt11SemanticError::NoPaymentSecret => nativeBolt11SemanticError::NoPaymentSecret,
+ Bolt11SemanticError::MultiplePaymentSecrets => nativeBolt11SemanticError::MultiplePaymentSecrets,
+ Bolt11SemanticError::InvalidFeatures => nativeBolt11SemanticError::InvalidFeatures,
+ Bolt11SemanticError::InvalidRecoveryId => nativeBolt11SemanticError::InvalidRecoveryId,
+ Bolt11SemanticError::InvalidSignature => nativeBolt11SemanticError::InvalidSignature,
+ Bolt11SemanticError::ImpreciseAmount => nativeBolt11SemanticError::ImpreciseAmount,
}
}
#[allow(unused)]
- pub(crate) fn into_native(self) -> nativeSemanticError {
+ pub(crate) fn into_native(self) -> nativeBolt11SemanticError {
match self {
- SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
- SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
- SemanticError::NoDescription => nativeSemanticError::NoDescription,
- SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
- SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
- SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
+ Bolt11SemanticError::NoPaymentHash => nativeBolt11SemanticError::NoPaymentHash,
+ Bolt11SemanticError::MultiplePaymentHashes => nativeBolt11SemanticError::MultiplePaymentHashes,
+ Bolt11SemanticError::NoDescription => nativeBolt11SemanticError::NoDescription,
+ Bolt11SemanticError::MultipleDescriptions => nativeBolt11SemanticError::MultipleDescriptions,
+ Bolt11SemanticError::NoPaymentSecret => nativeBolt11SemanticError::NoPaymentSecret,
+ Bolt11SemanticError::MultiplePaymentSecrets => nativeBolt11SemanticError::MultiplePaymentSecrets,
+ Bolt11SemanticError::InvalidFeatures => nativeBolt11SemanticError::InvalidFeatures,
+ Bolt11SemanticError::InvalidRecoveryId => nativeBolt11SemanticError::InvalidRecoveryId,
+ Bolt11SemanticError::InvalidSignature => nativeBolt11SemanticError::InvalidSignature,
+ Bolt11SemanticError::ImpreciseAmount => nativeBolt11SemanticError::ImpreciseAmount,
}
}
#[allow(unused)]
- pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
+ pub(crate) fn from_native(native: &Bolt11SemanticErrorImport) -> Self {
+ let native = unsafe { &*(native as *const _ as *const c_void as *const nativeBolt11SemanticError) };
match native {
- nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
- nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
- nativeSemanticError::NoDescription => SemanticError::NoDescription,
- nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
- nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
- nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
+ nativeBolt11SemanticError::NoPaymentHash => Bolt11SemanticError::NoPaymentHash,
+ nativeBolt11SemanticError::MultiplePaymentHashes => Bolt11SemanticError::MultiplePaymentHashes,
+ nativeBolt11SemanticError::NoDescription => Bolt11SemanticError::NoDescription,
+ nativeBolt11SemanticError::MultipleDescriptions => Bolt11SemanticError::MultipleDescriptions,
+ nativeBolt11SemanticError::NoPaymentSecret => Bolt11SemanticError::NoPaymentSecret,
+ nativeBolt11SemanticError::MultiplePaymentSecrets => Bolt11SemanticError::MultiplePaymentSecrets,
+ nativeBolt11SemanticError::InvalidFeatures => Bolt11SemanticError::InvalidFeatures,
+ nativeBolt11SemanticError::InvalidRecoveryId => Bolt11SemanticError::InvalidRecoveryId,
+ nativeBolt11SemanticError::InvalidSignature => Bolt11SemanticError::InvalidSignature,
+ nativeBolt11SemanticError::ImpreciseAmount => Bolt11SemanticError::ImpreciseAmount,
}
}
#[allow(unused)]
- pub(crate) fn native_into(native: nativeSemanticError) -> Self {
+ pub(crate) fn native_into(native: nativeBolt11SemanticError) -> Self {
match native {
- nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
- nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
- nativeSemanticError::NoDescription => SemanticError::NoDescription,
- nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
- nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
- nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
+ nativeBolt11SemanticError::NoPaymentHash => Bolt11SemanticError::NoPaymentHash,
+ nativeBolt11SemanticError::MultiplePaymentHashes => Bolt11SemanticError::MultiplePaymentHashes,
+ nativeBolt11SemanticError::NoDescription => Bolt11SemanticError::NoDescription,
+ nativeBolt11SemanticError::MultipleDescriptions => Bolt11SemanticError::MultipleDescriptions,
+ nativeBolt11SemanticError::NoPaymentSecret => Bolt11SemanticError::NoPaymentSecret,
+ nativeBolt11SemanticError::MultiplePaymentSecrets => Bolt11SemanticError::MultiplePaymentSecrets,
+ nativeBolt11SemanticError::InvalidFeatures => Bolt11SemanticError::InvalidFeatures,
+ nativeBolt11SemanticError::InvalidRecoveryId => Bolt11SemanticError::InvalidRecoveryId,
+ nativeBolt11SemanticError::InvalidSignature => Bolt11SemanticError::InvalidSignature,
+ nativeBolt11SemanticError::ImpreciseAmount => Bolt11SemanticError::ImpreciseAmount,
}
}
}
-/// Creates a copy of the SemanticError
+/// Creates a copy of the Bolt11SemanticError
#[no_mangle]
-pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
+pub extern "C" fn Bolt11SemanticError_clone(orig: &Bolt11SemanticError) -> Bolt11SemanticError {
orig.clone()
}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn Bolt11SemanticError_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Bolt11SemanticError)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn Bolt11SemanticError_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut Bolt11SemanticError) };
+}
+#[no_mangle]
+/// Utility method to constructs a new NoPaymentHash-variant Bolt11SemanticError
+pub extern "C" fn Bolt11SemanticError_no_payment_hash() -> Bolt11SemanticError {
+ Bolt11SemanticError::NoPaymentHash}
+#[no_mangle]
+/// Utility method to constructs a new MultiplePaymentHashes-variant Bolt11SemanticError
+pub extern "C" fn Bolt11SemanticError_multiple_payment_hashes() -> Bolt11SemanticError {
+ Bolt11SemanticError::MultiplePaymentHashes}
+#[no_mangle]
+/// Utility method to constructs a new NoDescription-variant Bolt11SemanticError
+pub extern "C" fn Bolt11SemanticError_no_description() -> Bolt11SemanticError {
+ Bolt11SemanticError::NoDescription}
+#[no_mangle]
+/// Utility method to constructs a new MultipleDescriptions-variant Bolt11SemanticError
+pub extern "C" fn Bolt11SemanticError_multiple_descriptions() -> Bolt11SemanticError {
+ Bolt11SemanticError::MultipleDescriptions}
+#[no_mangle]
+/// Utility method to constructs a new NoPaymentSecret-variant Bolt11SemanticError
+pub extern "C" fn Bolt11SemanticError_no_payment_secret() -> Bolt11SemanticError {
+ Bolt11SemanticError::NoPaymentSecret}
+#[no_mangle]
+/// Utility method to constructs a new MultiplePaymentSecrets-variant Bolt11SemanticError
+pub extern "C" fn Bolt11SemanticError_multiple_payment_secrets() -> Bolt11SemanticError {
+ Bolt11SemanticError::MultiplePaymentSecrets}
#[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()
+/// Utility method to constructs a new InvalidFeatures-variant Bolt11SemanticError
+pub extern "C" fn Bolt11SemanticError_invalid_features() -> Bolt11SemanticError {
+ Bolt11SemanticError::InvalidFeatures}
+#[no_mangle]
+/// Utility method to constructs a new InvalidRecoveryId-variant Bolt11SemanticError
+pub extern "C" fn Bolt11SemanticError_invalid_recovery_id() -> Bolt11SemanticError {
+ Bolt11SemanticError::InvalidRecoveryId}
+#[no_mangle]
+/// Utility method to constructs a new InvalidSignature-variant Bolt11SemanticError
+pub extern "C" fn Bolt11SemanticError_invalid_signature() -> Bolt11SemanticError {
+ Bolt11SemanticError::InvalidSignature}
+#[no_mangle]
+/// Utility method to constructs a new ImpreciseAmount-variant Bolt11SemanticError
+pub extern "C" fn Bolt11SemanticError_imprecise_amount() -> Bolt11SemanticError {
+ Bolt11SemanticError::ImpreciseAmount}
+/// Checks if two Bolt11SemanticErrors contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn Bolt11SemanticError_eq(a: &Bolt11SemanticError, b: &Bolt11SemanticError) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
}
-/// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
+/// Get a string which allows debug introspection of a Bolt11SemanticError object
+pub extern "C" fn Bolt11SemanticError_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Bolt11SemanticError }).into()}
+#[no_mangle]
+/// Get the string representation of a Bolt11SemanticError object
+pub extern "C" fn Bolt11SemanticError_to_str(o: &crate::lightning_invoice::Bolt11SemanticError) -> Str {
+ 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 {
)
},
SignOrCreationError::CreationError (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeSignOrCreationError::CreationError (
a_nonref.into_native(),
)
}
}
#[allow(unused)]
- pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
+ pub(crate) fn from_native(native: &SignOrCreationErrorImport<>) -> Self {
+ let native = unsafe { &*(native as *const _ as *const c_void as *const nativeSignOrCreationError) };
match native {
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),
)
pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
orig.clone()
}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn SignOrCreationError_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SignOrCreationError)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn SignOrCreationError_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut SignOrCreationError) };
+}
+#[no_mangle]
+/// Utility method to constructs a new SignError-variant SignOrCreationError
+pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
+ SignOrCreationError::SignError
+}
+#[no_mangle]
+/// Utility method to constructs a new CreationError-variant SignOrCreationError
+pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
+ SignOrCreationError::CreationError(a, )
+}
+/// Checks if two SignOrCreationErrors contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+/// Get a string which allows debug introspection of a SignOrCreationError object
+pub extern "C" fn SignOrCreationError_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::SignOrCreationError }).into()}
#[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()
}