X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Fchain%2Ftransaction.rs;h=45794a14c39029f880df02418fe94b66582930c2;hb=036da10cc98c0d3ca093a58a9cd9f20dcba832c7;hp=b4ea08cdd07292a2e4c89a02a12523bb68867deb;hpb=c35ef17b94a8f4e9e019a2b63e0ed22110671b9c;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/chain/transaction.rs b/lightning-c-bindings/src/lightning/chain/transaction.rs index b4ea08c..45794a1 100644 --- a/lightning-c-bindings/src/lightning/chain/transaction.rs +++ b/lightning-c-bindings/src/lightning/chain/transaction.rs @@ -8,6 +8,7 @@ //! Types describing on-chain transactions. +use std::str::FromStr; use std::ffi::c_void; use bitcoin::hashes::Hash; use crate::c_types::*; @@ -110,6 +111,25 @@ pub(crate) extern "C" fn OutPoint_clone_void(this_ptr: *const c_void) -> *mut c_ pub extern "C" fn OutPoint_clone(orig: &OutPoint) -> OutPoint { orig.clone() } +/// Checks if two OutPoints 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 OutPoint_eq(a: &OutPoint, b: &OutPoint) -> 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 } +} +/// Checks if two OutPoints contain equal inner contents. +#[no_mangle] +pub extern "C" fn OutPoint_hash(o: &OutPoint) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + std::hash::Hash::hash(unsafe { &*o.inner }, &mut hasher); + std::hash::Hasher::finish(&hasher) +} /// Convert an `OutPoint` to a lightning channel id. #[must_use] #[no_mangle]