pub(crate) fn to_native(&self) -> nativeParseError {
match self {
ParseError::Bech32Error (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeParseError::Bech32Error (
a_nonref.into_rust(),
)
},
ParseError::ParseAmountError (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeParseError::ParseAmountError (
u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
)
},
ParseError::MalformedSignature (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeParseError::MalformedSignature (
a_nonref.into_rust(),
)
ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
ParseError::DescriptionDecodeError (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeParseError::DescriptionDecodeError (
core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
)
ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
ParseError::InvalidSliceLength (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeParseError::InvalidSliceLength (
a_nonref.into_string(),
)
pub(crate) fn from_native(native: &nativeParseError) -> Self {
match native {
nativeParseError::Bech32Error (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
ParseError::Bech32Error (
crate::c_types::Bech32Error::from_rust(a_nonref),
)
},
nativeParseError::ParseAmountError (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
ParseError::ParseAmountError (
crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
)
},
nativeParseError::MalformedSignature (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
ParseError::MalformedSignature (
crate::c_types::Secp256k1Error::from_rust(a_nonref),
)
nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
nativeParseError::DescriptionDecodeError (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
ParseError::DescriptionDecodeError (
crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
)
nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
nativeParseError::InvalidSliceLength (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
ParseError::InvalidSliceLength (
a_nonref.into(),
)
/// Utility method to constructs a new Skip-variant ParseError
pub extern "C" fn ParseError_skip() -> ParseError {
ParseError::Skip}
+/// Checks if two ParseErrors contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn ParseError_eq(a: &ParseError, b: &ParseError) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
/// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
/// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
/// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
pub(crate) fn to_native(&self) -> nativeParseOrSemanticError {
match self {
ParseOrSemanticError::ParseError (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeParseOrSemanticError::ParseError (
a_nonref.into_native(),
)
},
ParseOrSemanticError::SemanticError (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeParseOrSemanticError::SemanticError (
a_nonref.into_native(),
)
pub(crate) fn from_native(native: &nativeParseOrSemanticError) -> Self {
match native {
nativeParseOrSemanticError::ParseError (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
ParseOrSemanticError::ParseError (
crate::lightning_invoice::ParseError::native_into(a_nonref),
)
},
nativeParseOrSemanticError::SemanticError (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
ParseOrSemanticError::SemanticError (
crate::lightning_invoice::SemanticError::native_into(a_nonref),
)
pub extern "C" fn ParseOrSemanticError_semantic_error(a: crate::lightning_invoice::SemanticError) -> ParseOrSemanticError {
ParseOrSemanticError::SemanticError(a, )
}
+/// Checks if two ParseOrSemanticErrors contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn ParseOrSemanticError_eq(a: &ParseOrSemanticError, b: &ParseOrSemanticError) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
/// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
///
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInvoice) };
}
#[allow(unused)]
impl Invoice {
pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
orig.clone()
}
+/// Checks if two Invoices contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn Invoice_hash(o: &Invoice) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSignedRawInvoice) };
}
#[allow(unused)]
impl SignedRawInvoice {
pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
orig.clone()
}
+/// Checks if two SignedRawInvoices contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn SignedRawInvoice_hash(o: &SignedRawInvoice) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
pub(crate) type nativeRawInvoice = nativeRawInvoiceImport;
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawInvoice) };
}
#[allow(unused)]
impl RawInvoice {
pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
orig.clone()
}
+/// Checks if two RawInvoices contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn RawInvoice_hash(o: &RawInvoice) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
use lightning_invoice::RawDataPart as nativeRawDataPartImport;
pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawDataPart) };
}
#[allow(unused)]
impl RawDataPart {
pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
orig.clone()
}
+/// Checks if two RawDataParts contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn RawDataPart_hash(o: &RawDataPart) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativePositiveTimestamp) };
}
#[allow(unused)]
impl PositiveTimestamp {
pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
orig.clone()
}
+/// Checks if two PositiveTimestamps contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn PositiveTimestamp_hash(o: &PositiveTimestamp) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
/// SI prefixes for the human readable part
#[derive(Clone)]
#[must_use]
pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
if &a.to_native() == &b.to_native() { true } else { false }
}
+/// Checks if two SiPrefixs contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn SiPrefix_hash(o: &SiPrefix) -> u64 {
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(&o.to_native(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
/// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
/// This is effectively 10^12 * the prefix multiplier
#[must_use]
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSha256) };
}
#[allow(unused)]
impl Sha256 {
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDescription) };
}
#[allow(unused)]
impl Description {
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativePayeePubKey) };
}
#[allow(unused)]
impl PayeePubKey {
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeExpiryTime) };
}
#[allow(unused)]
impl ExpiryTime {
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry) };
}
#[allow(unused)]
impl MinFinalCltvExpiry {
#[repr(C)]
pub enum Fallback {
SegWitProgram {
- version: crate::c_types::u5,
+ version: crate::c_types::U5,
program: crate::c_types::derived::CVec_u8Z,
},
PubKeyHash(
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,
)
},
Fallback::ScriptHash (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeFallback::ScriptHash (
a_nonref.data,
)
pub(crate) fn from_native(native: &nativeFallback) -> Self {
match native {
nativeFallback::SegWitProgram {ref version, ref program, } => {
- let mut version_nonref = (*version).clone();
- let mut program_nonref = (*program).clone();
+ let mut version_nonref = Clone::clone(version);
+ let mut program_nonref = Clone::clone(program);
let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
Fallback::SegWitProgram {
version: version_nonref.into(),
}
},
nativeFallback::PubKeyHash (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
Fallback::PubKeyHash (
crate::c_types::TwentyBytes { data: a_nonref },
)
},
nativeFallback::ScriptHash (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
Fallback::ScriptHash (
crate::c_types::TwentyBytes { data: a_nonref },
)
}
#[no_mangle]
/// Utility method to constructs a new SegWitProgram-variant Fallback
-pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
+pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::U5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
Fallback::SegWitProgram {
version,
program,
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInvoiceSignature) };
}
#[allow(unused)]
impl InvoiceSignature {
orig.clone()
}
/// Checks if two InvoiceSignatures contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn InvoiceSignature_hash(o: &InvoiceSignature) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
+/// Checks if two InvoiceSignatures contain equal inner contents.
/// This ignores pointers and is_owned flags and looks at the values in fields.
/// Two objects with NULL inner values will be considered "equal" here.
#[no_mangle]
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativePrivateRoute) };
}
#[allow(unused)]
impl PrivateRoute {
/// The hash of the `RawInvoice` that was signed.
#[must_use]
#[no_mangle]
-pub extern "C" fn SignedRawInvoice_hash(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> *const [u8; 32] {
- let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
+pub extern "C" fn SignedRawInvoice_signable_hash(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> *const [u8; 32] {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
ret
}
ret
}
-/// Calculate the hash of the encoded `RawInvoice`
+/// Calculate the hash of the encoded `RawInvoice` which should be signed.
#[must_use]
#[no_mangle]
-pub extern "C" fn RawInvoice_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
- let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
+pub extern "C" fn RawInvoice_signable_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
crate::c_types::ThirtyTwoBytes { data: ret }
}
/// 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]
/// 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]
crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
}
-/// Construct an `ExpiryTime` from a `Duration`.
+/// Construct an `ExpiryTime` from a `Duration`, dropping the sub-second part.
#[must_use]
#[no_mangle]
pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime {
)
},
SignOrCreationError::CreationError (ref a, ) => {
- let mut a_nonref = (*a).clone();
+ let mut a_nonref = Clone::clone(a);
nativeSignOrCreationError::CreationError (
a_nonref.into_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),
)