X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning_invoice%2Fmod.rs;h=12845c6769abbc29a51d84a321bad0b759f8214c;hp=80b6d5d5ba4b56848a66cb3441ca137a263e2774;hb=1eaf50a3d9f777b462ff1817678473567a00eb75;hpb=ed6eb46f7b4e0d4c869ad08dffc600b4e93e2129 diff --git a/lightning-c-bindings/src/lightning_invoice/mod.rs b/lightning-c-bindings/src/lightning_invoice/mod.rs index 80b6d5d..12845c6 100644 --- a/lightning-c-bindings/src/lightning_invoice/mod.rs +++ b/lightning-c-bindings/src/lightning_invoice/mod.rs @@ -15,26 +15,36 @@ //! * For constructing invoices use the `InvoiceBuilder` //! * For serializing invoices use the `Display`/`ToString` traits -use std::str::FromStr; -use std::ffi::c_void; +use alloc::str::FromStr; +use core::ffi::c_void; +use core::convert::Infallible; use bitcoin::hashes::Hash; use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; +pub mod payment; pub mod utils; pub mod constants; mod de { -use std::str::FromStr; -use std::ffi::c_void; +use alloc::str::FromStr; +use core::ffi::c_void; +use core::convert::Infallible; use bitcoin::hashes::Hash; use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; mod hrp_sm { -use std::str::FromStr; -use std::ffi::c_void; +use alloc::str::FromStr; +use core::ffi::c_void; +use core::convert::Infallible; use bitcoin::hashes::Hash; use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; } #[no_mangle] @@ -76,10 +86,13 @@ pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_ } mod ser { -use std::str::FromStr; -use std::ffi::c_void; +use alloc::str::FromStr; +use core::ffi::c_void; +use core::convert::Infallible; use bitcoin::hashes::Hash; use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; #[no_mangle] /// Get the string representation of a Invoice object @@ -104,10 +117,13 @@ pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str } mod tb { -use std::str::FromStr; -use std::ffi::c_void; +use alloc::str::FromStr; +use core::ffi::c_void; +use core::convert::Infallible; use bitcoin::hashes::Hash; use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; } /// Default expiry time as defined by [BOLT 11]. @@ -146,7 +162,7 @@ pub extern "C" fn check_platform() { use lightning_invoice::Invoice as nativeInvoiceImport; -type nativeInvoice = nativeInvoiceImport; +pub(crate) type nativeInvoice = nativeInvoiceImport; /// Represents a syntactically and semantically correct lightning BOLT11 invoice. /// @@ -181,7 +197,7 @@ impl Drop for Invoice { pub extern "C" fn Invoice_free(this_obj: Invoice) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn Invoice_free_void(this_ptr: *mut c_void) { +pub(crate) extern "C" fn Invoice_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); } } #[allow(unused)] @@ -196,7 +212,7 @@ impl Invoice { pub(crate) fn take_inner(mut self) -> *mut nativeInvoice { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -212,7 +228,7 @@ pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool { impl Clone for Invoice { fn clone(&self) -> Self { Self { - inner: if <*mut nativeInvoice>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeInvoice>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -230,7 +246,7 @@ pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice { } use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport; -type nativeSignedRawInvoice = nativeSignedRawInvoiceImport; +pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport; /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be /// invalid. @@ -264,7 +280,7 @@ impl Drop for SignedRawInvoice { pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) { +pub(crate) extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); } } #[allow(unused)] @@ -279,7 +295,7 @@ impl SignedRawInvoice { pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -295,7 +311,7 @@ pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice impl Clone for SignedRawInvoice { fn clone(&self) -> Self { Self { - inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -313,7 +329,7 @@ pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawIn } use lightning_invoice::RawInvoice as nativeRawInvoiceImport; -type nativeRawInvoice = nativeRawInvoiceImport; +pub(crate) type nativeRawInvoice = nativeRawInvoiceImport; /// Represents an syntactically correct Invoice for a payment on the lightning network, /// but without the signature information. @@ -347,7 +363,7 @@ impl Drop for RawInvoice { pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) { +pub(crate) extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); } } #[allow(unused)] @@ -362,7 +378,7 @@ impl RawInvoice { pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -370,7 +386,7 @@ impl RawInvoice { #[no_mangle] pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> 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 _) as *mut _) }, is_owned: false } + 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] @@ -389,7 +405,7 @@ pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool { impl Clone for RawInvoice { fn clone(&self) -> Self { Self { - inner: if <*mut nativeRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -407,7 +423,7 @@ pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice { } 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 #[must_use] @@ -437,7 +453,7 @@ impl Drop for RawDataPart { 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) { +pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); } } #[allow(unused)] @@ -452,7 +468,7 @@ impl RawDataPart { pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -460,7 +476,7 @@ impl RawDataPart { #[no_mangle] pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp { 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 _) as *mut _) }, is_owned: false } + 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] @@ -479,7 +495,7 @@ pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool { impl Clone for RawDataPart { fn clone(&self) -> Self { Self { - inner: if <*mut nativeRawDataPart>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -497,7 +513,7 @@ pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart { } 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. @@ -532,7 +548,7 @@ impl Drop for PositiveTimestamp { 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) { +pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); } } #[allow(unused)] @@ -547,7 +563,7 @@ impl PositiveTimestamp { pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -563,7 +579,7 @@ pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimest impl Clone for PositiveTimestamp { fn clone(&self) -> Self { Self { - inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -753,6 +769,15 @@ pub extern "C" fn Currency_simnet() -> Currency { pub extern "C" fn Currency_signet() -> Currency { Currency::Signet} /// Checks if two Currencys contain equal inner contents. +#[no_mangle] +pub extern "C" fn Currency_hash(o: &Currency) -> u64 { + // Note that we'd love to use 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 { @@ -760,7 +785,7 @@ pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool { } use lightning_invoice::Sha256 as nativeSha256Import; -type nativeSha256 = nativeSha256Import; +pub(crate) type nativeSha256 = nativeSha256Import; /// SHA-256 hash #[must_use] @@ -790,7 +815,7 @@ impl Drop for Sha256 { 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) { +pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); } } #[allow(unused)] @@ -805,23 +830,14 @@ impl Sha256 { pub(crate) fn take_inner(mut self) -> *mut nativeSha256 { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } -/// 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 } -} impl Clone for Sha256 { fn clone(&self) -> Self { Self { - inner: if <*mut nativeSha256>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -837,9 +853,28 @@ pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_vo pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 { orig.clone() } +/// Checks if two Sha256s contain equal inner contents. +#[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 } +} use lightning_invoice::Description as nativeDescriptionImport; -type nativeDescription = nativeDescriptionImport; +pub(crate) type nativeDescription = nativeDescriptionImport; /// Description string /// @@ -872,7 +907,7 @@ impl Drop for Description { 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) { +pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); } } #[allow(unused)] @@ -887,23 +922,14 @@ impl Description { pub(crate) fn take_inner(mut self) -> *mut nativeDescription { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } -/// 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 } -} impl Clone for Description { fn clone(&self) -> Self { Self { - inner: if <*mut nativeDescription>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -919,9 +945,28 @@ pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut pub extern "C" fn Description_clone(orig: &Description) -> Description { orig.clone() } +/// Checks if two Descriptions contain equal inner contents. +#[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] @@ -951,7 +996,7 @@ impl Drop for PayeePubKey { 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) { +pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); } } #[allow(unused)] @@ -966,23 +1011,31 @@ impl PayeePubKey { pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } -/// 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 } +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 { + 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, } @@ -998,9 +1051,28 @@ pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey { orig.clone() } +/// Checks if two PayeePubKeys contain equal inner contents. +#[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 @@ -1036,7 +1108,7 @@ impl Drop for ExpiryTime { 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) { +pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); } } #[allow(unused)] @@ -1051,23 +1123,14 @@ impl ExpiryTime { pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } -/// 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 } -} impl Clone for ExpiryTime { fn clone(&self) -> Self { Self { - inner: if <*mut nativeExpiryTime>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -1083,9 +1146,28 @@ pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime { orig.clone() } +/// Checks if two ExpiryTimes contain equal inner contents. +#[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; +pub(crate) type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport; /// `min_final_cltv_expiry` to use for the last HTLC in the route #[must_use] @@ -1115,7 +1197,7 @@ impl Drop for MinFinalCltvExpiry { pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { } #[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) { +pub(crate) extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); } } #[allow(unused)] @@ -1130,23 +1212,31 @@ impl MinFinalCltvExpiry { pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } -/// Checks if two MinFinalCltvExpirys contain equal inner contents. -/// This ignores pointers and is_owned flags and looks at the values in fields. -/// Two objects with NULL inner values will be considered "equal" here. #[no_mangle] -pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool { - 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 } +pub extern "C" fn MinFinalCltvExpiry_get_a(this_ptr: &MinFinalCltvExpiry) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().0; + *inner_val +} +#[no_mangle] +pub extern "C" fn MinFinalCltvExpiry_set_a(this_ptr: &mut MinFinalCltvExpiry, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val; +} +/// Constructs a new MinFinalCltvExpiry given each field +#[must_use] +#[no_mangle] +pub extern "C" fn MinFinalCltvExpiry_new(mut a_arg: u64) -> MinFinalCltvExpiry { + MinFinalCltvExpiry { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiry ( + a_arg, + )), is_owned: true } } impl Clone for MinFinalCltvExpiry { fn clone(&self) -> Self { Self { - inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -1162,6 +1252,25 @@ pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry { orig.clone() } +/// Checks if two MinFinalCltvExpirys contain equal inner contents. +#[no_mangle] +pub extern "C" fn MinFinalCltvExpiry_hash(o: &MinFinalCltvExpiry) -> 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 MinFinalCltvExpirys contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool { + 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)] @@ -1300,6 +1409,15 @@ pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallba Fallback::ScriptHash(a, ) } /// Checks if two Fallbacks contain equal inner contents. +#[no_mangle] +pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 { + // Note that we'd love to use 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 { @@ -1307,7 +1425,7 @@ pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool { } use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport; -type nativeInvoiceSignature = nativeInvoiceSignatureImport; +pub(crate) type nativeInvoiceSignature = nativeInvoiceSignatureImport; /// Recoverable signature #[must_use] @@ -1337,7 +1455,7 @@ impl Drop for InvoiceSignature { pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) { +pub(crate) extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); } } #[allow(unused)] @@ -1352,23 +1470,14 @@ impl InvoiceSignature { pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } -/// Checks if two InvoiceSignatures contain equal inner contents. -/// This ignores pointers and is_owned flags and looks at the values in fields. -/// Two objects with NULL inner values will be considered "equal" here. -#[no_mangle] -pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> 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 } -} impl Clone for InvoiceSignature { fn clone(&self) -> Self { Self { - inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -1384,9 +1493,18 @@ pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature { orig.clone() } +/// Checks if two InvoiceSignatures contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> 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::PrivateRoute as nativePrivateRouteImport; -type nativePrivateRoute = nativePrivateRouteImport; +pub(crate) type nativePrivateRoute = nativePrivateRouteImport; /// Private routing information /// @@ -1420,7 +1538,7 @@ impl Drop for PrivateRoute { 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 PrivateRoute_free_void(this_ptr: *mut c_void) { +pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) { unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); } } #[allow(unused)] @@ -1435,23 +1553,14 @@ impl PrivateRoute { pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } -/// 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 } -} impl Clone for PrivateRoute { fn clone(&self) -> Self { Self { - inner: if <*mut nativePrivateRoute>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -1467,6 +1576,25 @@ pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mu pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute { orig.clone() } +/// Checks if two PrivateRoutes contain equal inner contents. +#[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 `SignedRawInvoice` into its three parts: /// 1. raw invoice /// 2. hash of the raw invoice @@ -1484,7 +1612,7 @@ pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> #[no_mangle] pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice(); - crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false } + crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawInvoice<>) as *mut _) }, is_owned: false } } /// The hash of the `RawInvoice` that was signed. @@ -1500,7 +1628,7 @@ pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [ #[no_mangle] pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature(); - crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false } + crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::InvoiceSignature<>) as *mut _) }, is_owned: false } } /// Recovers the public key used for signing the invoice from the recoverable signature. @@ -1535,7 +1663,7 @@ pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::Thir #[no_mangle] pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash(); - let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false }; local_ret } @@ -1545,7 +1673,7 @@ pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::light #[no_mangle] pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description(); - let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Description<>) as *mut _ }, is_owned: false }; local_ret } @@ -1555,7 +1683,7 @@ pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightn #[no_mangle] pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key(); - let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::PayeePubKey<>) as *mut _ }, is_owned: false }; local_ret } @@ -1565,7 +1693,7 @@ pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::ligh #[no_mangle] pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash(); - let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false }; local_ret } @@ -1575,7 +1703,7 @@ pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::l #[no_mangle] pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time(); - let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::ExpiryTime<>) as *mut _ }, is_owned: false }; local_ret } @@ -1585,7 +1713,7 @@ pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightn #[no_mangle] pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry(); - let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiry { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiry { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::MinFinalCltvExpiry<>) as *mut _ }, is_owned: false }; local_ret } @@ -1605,7 +1733,7 @@ pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_t #[no_mangle] pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features(); - let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false }; local_ret } @@ -1613,7 +1741,7 @@ pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning #[no_mangle] pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes(); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const _) as *mut _) }, is_owned: false } }); }; + 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() } @@ -1621,7 +1749,7 @@ pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_t #[no_mangle] pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc(); - let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(ret.unwrap()) } }; + 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 } @@ -1691,10 +1819,17 @@ pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types: /// ``` /// 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::().unwrap(); /// @@ -1736,14 +1871,11 @@ pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::P } /// Get the payment secret if one was included in the invoice -/// -/// 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_payment_secret(this_arg: &Invoice) -> crate::c_types::ThirtyTwoBytes { +pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> *const [u8; 32] { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret(); - let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } }; - local_ret + &ret.0 } /// Get the invoice features if they were included in the invoice @@ -1753,7 +1885,7 @@ pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> crate::c_types:: #[no_mangle] pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features(); - let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false }; + let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false }; local_ret } @@ -1773,6 +1905,14 @@ pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 { ret.as_secs() } +/// Returns whether the invoice has expired. +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_is_expired(this_arg: &Invoice) -> bool { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired(); + ret +} + /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`]. #[must_use] @@ -1787,7 +1927,7 @@ pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 { #[no_mangle] pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes(); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const _) as *mut _) }, is_owned: false } }); }; + 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() } @@ -1796,7 +1936,7 @@ pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types:: #[no_mangle] pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints(); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const _) as *mut _) }, is_owned: false } }); }; + 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() } @@ -1808,12 +1948,12 @@ pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoi crate::lightning_invoice::Currency::native_into(ret) } -/// Returns the amount if specified in the invoice as pico . +/// 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 { &*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()) } }; +pub extern "C" fn Invoice_amount_milli_satoshis(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis(); + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap() }) }; local_ret } @@ -1854,7 +1994,7 @@ pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::d #[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 ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration)); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() }; local_ret } @@ -1905,6 +2045,8 @@ pub enum CreationError { TimestampOutOfBounds, /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp` ExpiryTimeOutOfBounds, + /// The supplied millisatoshi amount was greater than the total bitcoin supply. + InvalidAmount, } use lightning_invoice::CreationError as nativeCreationError; impl CreationError { @@ -1915,6 +2057,7 @@ impl CreationError { CreationError::RouteTooLong => nativeCreationError::RouteTooLong, CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds, CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds, + CreationError::InvalidAmount => nativeCreationError::InvalidAmount, } } #[allow(unused)] @@ -1924,6 +2067,7 @@ impl CreationError { CreationError::RouteTooLong => nativeCreationError::RouteTooLong, CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds, CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds, + CreationError::InvalidAmount => nativeCreationError::InvalidAmount, } } #[allow(unused)] @@ -1933,6 +2077,7 @@ impl CreationError { nativeCreationError::RouteTooLong => CreationError::RouteTooLong, nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds, nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds, + nativeCreationError::InvalidAmount => CreationError::InvalidAmount, } } #[allow(unused)] @@ -1942,6 +2087,7 @@ impl CreationError { nativeCreationError::RouteTooLong => CreationError::RouteTooLong, nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds, nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds, + nativeCreationError::InvalidAmount => CreationError::InvalidAmount, } } } @@ -1966,6 +2112,10 @@ pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError { /// Utility method to constructs a new ExpiryTimeOutOfBounds-variant CreationError pub extern "C" fn CreationError_expiry_time_out_of_bounds() -> CreationError { CreationError::ExpiryTimeOutOfBounds} +#[no_mangle] +/// Utility method to constructs a new InvalidAmount-variant CreationError +pub extern "C" fn CreationError_invalid_amount() -> CreationError { + CreationError::InvalidAmount} /// Checks if two CreationErrors contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. #[no_mangle] @@ -1991,6 +2141,9 @@ pub enum SemanticError { 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 @@ -1999,6 +2152,8 @@ pub enum SemanticError { 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 { @@ -2009,10 +2164,12 @@ impl SemanticError { SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes, SemanticError::NoDescription => nativeSemanticError::NoDescription, SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions, + SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret, SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets, SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures, SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId, SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature, + SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount, } } #[allow(unused)] @@ -2022,10 +2179,12 @@ impl SemanticError { SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes, SemanticError::NoDescription => nativeSemanticError::NoDescription, SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions, + SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret, SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets, SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures, SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId, SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature, + SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount, } } #[allow(unused)] @@ -2035,10 +2194,12 @@ impl SemanticError { nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes, nativeSemanticError::NoDescription => SemanticError::NoDescription, nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions, + nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret, nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets, nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures, nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId, nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature, + nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount, } } #[allow(unused)] @@ -2048,10 +2209,12 @@ impl SemanticError { nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes, nativeSemanticError::NoDescription => SemanticError::NoDescription, nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions, + nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret, nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets, nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures, nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId, nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature, + nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount, } } } @@ -2077,6 +2240,10 @@ pub extern "C" fn SemanticError_no_description() -> SemanticError { pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError { SemanticError::MultipleDescriptions} #[no_mangle] +/// Utility method to constructs a new NoPaymentSecret-variant SemanticError +pub extern "C" fn SemanticError_no_payment_secret() -> SemanticError { + SemanticError::NoPaymentSecret} +#[no_mangle] /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError { SemanticError::MultiplePaymentSecrets} @@ -2092,6 +2259,10 @@ pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError { /// Utility method to constructs a new InvalidSignature-variant SemanticError pub extern "C" fn SemanticError_invalid_signature() -> SemanticError { SemanticError::InvalidSignature} +#[no_mangle] +/// Utility method to constructs a new ImpreciseAmount-variant SemanticError +pub extern "C" fn SemanticError_imprecise_amount() -> SemanticError { + SemanticError::ImpreciseAmount} /// Checks if two SemanticErrors contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. #[no_mangle]