X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Futil%2Fser.rs;h=1235f5cd08206750603fbcb608cc3348c00a0731;hb=636543d86915837013c3eb1e0a9ea96114ef73fc;hp=663a172f66487f9783dd34c3596e698a202743ac;hpb=f7105f5bb3fdf379d58286eacd8e44edba686954;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/util/ser.rs b/lightning-c-bindings/src/lightning/util/ser.rs index 663a172..1235f5c 100644 --- a/lightning-c-bindings/src/lightning/util/ser.rs +++ b/lightning-c-bindings/src/lightning/util/ser.rs @@ -111,13 +111,16 @@ impl Clone for BigSize { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn BigSize_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBigSize)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBigSize)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the BigSize pub extern "C" fn BigSize_clone(orig: &BigSize) -> BigSize { orig.clone() } +/// Get a string which allows debug introspection of a BigSize object +pub extern "C" fn BigSize_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::util::ser::BigSize }).into()} /// Generates a non-cryptographic 64-bit hash of the BigSize. #[no_mangle] pub extern "C" fn BigSize_hash(o: &BigSize) -> u64 { @@ -142,7 +145,7 @@ pub extern "C" fn BigSize_eq(a: &BigSize, b: &BigSize) -> bool { pub extern "C" fn BigSize_write(obj: &crate::lightning::util::ser::BigSize) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn BigSize_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBigSize) }) } @@ -222,13 +225,26 @@ impl Clone for Hostname { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Hostname_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHostname)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHostname)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Hostname pub extern "C" fn Hostname_clone(orig: &Hostname) -> Hostname { orig.clone() } +/// Get a string which allows debug introspection of a Hostname object +pub extern "C" fn Hostname_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::util::ser::Hostname }).into()} +/// Generates a non-cryptographic 64-bit hash of the Hostname. +#[no_mangle] +pub extern "C" fn Hostname_hash(o: &Hostname) -> 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 Hostnames 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. @@ -246,12 +262,17 @@ pub extern "C" fn Hostname_len(this_arg: &crate::lightning::util::ser::Hostname) ret } +#[no_mangle] +/// Get the string representation of a Hostname object +pub extern "C" fn Hostname_to_str(o: &crate::lightning::util::ser::Hostname) -> Str { + alloc::format!("{}", o.get_native_ref()).into() +} #[no_mangle] /// Serialize the Hostname object into a byte array which can be read by Hostname_read pub extern "C" fn Hostname_write(obj: &crate::lightning::util::ser::Hostname) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Hostname_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHostname) }) } @@ -328,13 +349,26 @@ impl Clone for TransactionU16LenLimited { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TransactionU16LenLimited_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTransactionU16LenLimited)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTransactionU16LenLimited)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TransactionU16LenLimited pub extern "C" fn TransactionU16LenLimited_clone(orig: &TransactionU16LenLimited) -> TransactionU16LenLimited { orig.clone() } +/// Get a string which allows debug introspection of a TransactionU16LenLimited object +pub extern "C" fn TransactionU16LenLimited_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::util::ser::TransactionU16LenLimited }).into()} +/// Generates a non-cryptographic 64-bit hash of the TransactionU16LenLimited. +#[no_mangle] +pub extern "C" fn TransactionU16LenLimited_hash(o: &TransactionU16LenLimited) -> 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 TransactionU16LenLimiteds 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. @@ -362,12 +396,20 @@ pub extern "C" fn TransactionU16LenLimited_into_transaction(mut this_arg: crate: crate::c_types::Transaction::from_bitcoin(&ret) } +/// Returns a reference to the contained `Transaction` +#[must_use] +#[no_mangle] +pub extern "C" fn TransactionU16LenLimited_as_transaction(this_arg: &crate::lightning::util::ser::TransactionU16LenLimited) -> crate::c_types::Transaction { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_transaction(); + crate::c_types::Transaction::from_bitcoin(ret) +} + #[no_mangle] /// Serialize the TransactionU16LenLimited object into a byte array which can be read by TransactionU16LenLimited_read pub extern "C" fn TransactionU16LenLimited_write(obj: &crate::lightning::util::ser::TransactionU16LenLimited) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TransactionU16LenLimited_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTransactionU16LenLimited) }) }