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=7ab1c2ede2be551286d1eb80e2afce77fbf6dde1;hp=0895be3c97a7b24af9d4e92a9c09968b67be8ed5;hb=2f0c348c6fe505a736c3d015df6d6cd30032c912;hpb=4b8e6fc66969585677c4f982b1db1f59716f4ba0 diff --git a/lightning-c-bindings/src/lightning_invoice/mod.rs b/lightning-c-bindings/src/lightning_invoice/mod.rs index 0895be3..7ab1c2e 100644 --- a/lightning-c-bindings/src/lightning_invoice/mod.rs +++ b/lightning-c-bindings/src/lightning_invoice/mod.rs @@ -110,6 +110,22 @@ use bitcoin::hashes::Hash; use crate::c_types::*; } +/// Default expiry time as defined by [BOLT 11]. +/// +/// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md + +#[no_mangle] +pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME; +/// Default minimum final CLTV expiry as defined by [BOLT 11]. +/// +/// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is +/// provided in [`MIN_FINAL_CLTV_EXPIRY`]. +/// +/// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md +/// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY + +#[no_mangle] +pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY; /// **Call this function on startup to ensure that all assumptions about the platform are valid.** /// /// Unfortunately we have to make assumptions about the upper bounds of the `SystemTime` type on @@ -178,6 +194,15 @@ impl Invoice { ret } } +/// Checks if two Invoices 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 Invoice_eq(a: &Invoice, b: &Invoice) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } +} impl Clone for Invoice { fn clone(&self) -> Self { Self { @@ -246,6 +271,15 @@ impl SignedRawInvoice { ret } } +/// Checks if two SignedRawInvoices 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 SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } +} impl Clone for SignedRawInvoice { fn clone(&self) -> Self { Self { @@ -325,6 +359,15 @@ pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning 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()) }; } +/// Checks if two RawInvoices 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 RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } +} impl Clone for RawInvoice { fn clone(&self) -> Self { Self { @@ -400,6 +443,15 @@ pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::li 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()) }; } +/// 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 unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } +} impl Clone for RawDataPart { fn clone(&self) -> Self { Self { @@ -469,6 +521,15 @@ impl PositiveTimestamp { 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 unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } +} impl Clone for PositiveTimestamp { fn clone(&self) -> Self { Self { @@ -546,6 +607,28 @@ impl SiPrefix { pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix { orig.clone() } +#[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 } +} /// 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] @@ -566,8 +649,10 @@ pub enum Currency { BitcoinTestnet, /// Bitcoin regtest Regtest, - /// Bitcoin simnet/signet + /// Bitcoin simnet Simnet, + /// Bitcoin signet + Signet, } use lightning_invoice::Currency as nativeCurrency; impl Currency { @@ -578,6 +663,7 @@ impl Currency { Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet, Currency::Regtest => nativeCurrency::Regtest, Currency::Simnet => nativeCurrency::Simnet, + Currency::Signet => nativeCurrency::Signet, } } #[allow(unused)] @@ -587,6 +673,7 @@ impl Currency { Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet, Currency::Regtest => nativeCurrency::Regtest, Currency::Simnet => nativeCurrency::Simnet, + Currency::Signet => nativeCurrency::Signet, } } #[allow(unused)] @@ -596,6 +683,7 @@ impl Currency { nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet, nativeCurrency::Regtest => Currency::Regtest, nativeCurrency::Simnet => Currency::Simnet, + nativeCurrency::Signet => Currency::Signet, } } #[allow(unused)] @@ -605,6 +693,7 @@ impl Currency { nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet, nativeCurrency::Regtest => Currency::Regtest, nativeCurrency::Simnet => Currency::Simnet, + nativeCurrency::Signet => Currency::Signet, } } } @@ -613,6 +702,32 @@ impl Currency { pub extern "C" fn Currency_clone(orig: &Currency) -> Currency { orig.clone() } +#[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} +/// 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; @@ -658,6 +773,15 @@ impl Sha256 { 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 unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } +} impl Clone for Sha256 { fn clone(&self) -> Self { Self { @@ -725,6 +849,15 @@ impl Description { 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 unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } +} impl Clone for Description { fn clone(&self) -> Self { Self { @@ -789,6 +922,15 @@ impl PayeePubKey { 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 unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } +} impl Clone for PayeePubKey { fn clone(&self) -> Self { Self { @@ -859,6 +1001,15 @@ impl ExpiryTime { 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 unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } +} impl Clone for ExpiryTime { fn clone(&self) -> Self { Self { @@ -923,6 +1074,15 @@ impl MinFinalCltvExpiry { 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 unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } +} impl Clone for MinFinalCltvExpiry { fn clone(&self) -> Self { Self { @@ -1061,6 +1221,30 @@ pub extern "C" fn Fallback_free(this_ptr: Fallback) { } pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback { orig.clone() } +#[no_mangle] +/// Utility method to constructs a new SegWitProgram-variant Fallback +pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback { + 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, ) +} +/// 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; @@ -1106,6 +1290,15 @@ impl InvoiceSignature { 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 unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } +} impl Clone for InvoiceSignature { fn clone(&self) -> Self { Self { @@ -1126,8 +1319,8 @@ pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSign orig.clone() } -use lightning_invoice::RouteHint as nativeRouteHintImport; -type nativeRouteHint = nativeRouteHintImport; +use lightning_invoice::PrivateRoute as nativePrivateRouteImport; +type nativePrivateRoute = nativePrivateRouteImport; /// Private routing information /// @@ -1136,12 +1329,12 @@ type nativeRouteHint = nativeRouteHintImport; /// #[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 @@ -1149,35 +1342,44 @@ pub struct RouteHint { 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) { + if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) { let _ = unsafe { Box::from_raw(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); } +extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) { + unsafe { let _ = 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 take_inner(mut self) -> *mut nativePrivateRoute { assert!(self.is_owned); let ret = self.inner; self.inner = std::ptr::null_mut(); ret } } -impl Clone for RouteHint { +/// 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 unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false } +} +impl Clone for PrivateRoute { fn clone(&self) -> Self { Self { - inner: if <*mut nativeRouteHint>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativePrivateRoute>::is_null(self.inner) { std::ptr::null_mut() } else { Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, is_owned: true, } @@ -1185,12 +1387,12 @@ impl Clone for RouteHint { } #[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 *mut 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: @@ -1255,6 +1457,8 @@ pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::Thir 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 RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 { @@ -1263,6 +1467,8 @@ pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::light 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 { @@ -1271,6 +1477,8 @@ pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightn 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 { @@ -1279,6 +1487,8 @@ pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::ligh 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 { @@ -1287,6 +1497,8 @@ pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::l 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 { @@ -1295,6 +1507,8 @@ pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightn 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_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry { @@ -1303,6 +1517,8 @@ pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> cra 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_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes { @@ -1311,6 +1527,8 @@ pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_t 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 { @@ -1321,9 +1539,9 @@ pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning #[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 RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ { + let mut ret = unsafe { &*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 { ( (&(*item) as *const _) as *mut _) }, is_owned: false } }); }; local_ret.into() } @@ -1397,7 +1615,7 @@ pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types: local_ret } -/// Constructs an `Invoice` from a `SignedInvoice` by checking all its invariants. +/// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants. /// ``` /// use lightning_invoice::*; /// @@ -1435,6 +1653,8 @@ pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] { } /// 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 { @@ -1444,6 +1664,8 @@ 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 { @@ -1453,6 +1675,8 @@ pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> crate::c_types:: } /// 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 { @@ -1489,9 +1713,18 @@ pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 { /// 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 Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ { + let mut ret = unsafe { &*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 { ( (&(*item) as *const _) 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 Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ { + let mut ret = unsafe { &*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 { ( (&(*item) as *const _) as *mut _) }, is_owned: false } }); }; local_ret.into() } @@ -1570,23 +1803,21 @@ pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 { 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: 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 } -/// 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: 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: Box::into_raw(Box::new(ret)), is_owned: true } } /// Errors that may occur when constructing a new `RawInvoice` or `Invoice` @@ -1648,6 +1879,28 @@ pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError { orig.clone() } #[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 ExpiryTimeOutOfBounds-variant CreationError +pub extern "C" fn CreationError_expiry_time_out_of_bounds() -> CreationError { + CreationError::ExpiryTimeOutOfBounds} +/// 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 } +} +#[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() @@ -1666,6 +1919,10 @@ pub enum SemanticError { NoDescription, /// The invoice contains multiple descriptions and/or description hashes which isn't allowed MultipleDescriptions, + /// 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 @@ -1680,6 +1937,8 @@ impl SemanticError { SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes, SemanticError::NoDescription => nativeSemanticError::NoDescription, SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions, + SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets, + SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures, SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId, SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature, } @@ -1691,6 +1950,8 @@ impl SemanticError { SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes, SemanticError::NoDescription => nativeSemanticError::NoDescription, SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions, + SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets, + SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures, SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId, SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature, } @@ -1702,6 +1963,8 @@ impl SemanticError { nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes, nativeSemanticError::NoDescription => SemanticError::NoDescription, nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions, + nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets, + nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures, nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId, nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature, } @@ -1713,6 +1976,8 @@ impl SemanticError { nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes, nativeSemanticError::NoDescription => SemanticError::NoDescription, nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions, + nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets, + nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures, nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId, nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature, } @@ -1724,6 +1989,44 @@ pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError { orig.clone() } #[no_mangle] +/// Utility method to constructs a new NoPaymentHash-variant SemanticError +pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError { + SemanticError::NoPaymentHash} +#[no_mangle] +/// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError +pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError { + SemanticError::MultiplePaymentHashes} +#[no_mangle] +/// Utility method to constructs a new NoDescription-variant SemanticError +pub extern "C" fn SemanticError_no_description() -> SemanticError { + SemanticError::NoDescription} +#[no_mangle] +/// Utility method to constructs a new MultipleDescriptions-variant SemanticError +pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError { + SemanticError::MultipleDescriptions} +#[no_mangle] +/// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError +pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError { + SemanticError::MultiplePaymentSecrets} +#[no_mangle] +/// Utility method to constructs a new InvalidFeatures-variant SemanticError +pub extern "C" fn SemanticError_invalid_features() -> SemanticError { + SemanticError::InvalidFeatures} +#[no_mangle] +/// Utility method to constructs a new InvalidRecoveryId-variant SemanticError +pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError { + SemanticError::InvalidRecoveryId} +#[no_mangle] +/// Utility method to constructs a new InvalidSignature-variant SemanticError +pub extern "C" fn SemanticError_invalid_signature() -> SemanticError { + SemanticError::InvalidSignature} +/// Checks if two SemanticErrors contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +#[no_mangle] +pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool { + if &a.to_native() == &b.to_native() { true } else { false } +} +#[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() @@ -1807,6 +2110,22 @@ pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignO orig.clone() } #[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 } +} +#[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()