X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Fchain%2Fmod.rs;h=4879e7f6aacf660d4ff43838ddf6474e25cbc355;hp=2d4382378c60e25c7ea9e2e230749dd5dcbf2e87;hb=e419524cf19c36857bf1f3c79d4b9dd47c7544c8;hpb=9e34ca7e68bc8caca0b76f29efbac903ce5b9d2b diff --git a/lightning-c-bindings/src/lightning/chain/mod.rs b/lightning-c-bindings/src/lightning/chain/mod.rs index 2d43823..4879e7f 100644 --- a/lightning-c-bindings/src/lightning/chain/mod.rs +++ b/lightning-c-bindings/src/lightning/chain/mod.rs @@ -18,6 +18,22 @@ pub mod chainmonitor; pub mod channelmonitor; pub mod transaction; pub mod keysinterface; +mod onchaintx { + +use std::str::FromStr; +use std::ffi::c_void; +use bitcoin::hashes::Hash; +use crate::c_types::*; + +} +mod package { + +use std::str::FromStr; +use std::ffi::c_void; +use bitcoin::hashes::Hash; +use crate::c_types::*; + +} /// An error when accessing the chain via [`Access`]. #[must_use] #[derive(Clone)] @@ -82,6 +98,8 @@ pub struct Access { /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, } +unsafe impl Send for Access {} +unsafe impl Sync for Access {} use lightning::chain::Access as rustAccess; impl rustAccess for Access { @@ -130,6 +148,8 @@ pub struct Listen { /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, } +unsafe impl Send for Listen {} +unsafe impl Sync for Listen {} use lightning::chain::Listen as rustListen; impl rustListen for Listen { @@ -245,12 +265,14 @@ pub struct Confirm { /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, } +unsafe impl Send for Confirm {} +unsafe impl Sync for Confirm {} use lightning::chain::Confirm as rustConfirm; impl rustConfirm for Confirm { fn transactions_confirmed(&self, mut header: &bitcoin::blockdata::block::BlockHeader, mut txdata: &lightning::chain::transaction::TransactionData, mut height: u32) { let mut local_header = { let mut s = [0u8; 80]; s[..].copy_from_slice(&::bitcoin::consensus::encode::serialize(header)); s }; - let mut local_txdata = Vec::new(); for item in txdata.iter() { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = *item; let mut local_txdata_0 = (orig_txdata_0_0, crate::c_types::Transaction::from_bitcoin(&orig_txdata_0_1)).into(); local_txdata_0 }); }; + let mut local_txdata = Vec::new(); for item in txdata.iter() { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item; let mut local_txdata_0 = (orig_txdata_0_0, crate::c_types::Transaction::from_bitcoin(&orig_txdata_0_1)).into(); local_txdata_0 }); }; (self.transactions_confirmed)(self.this_arg, &local_header, local_txdata.into(), height) } fn transaction_unconfirmed(&self, mut txid: &bitcoin::hash_types::Txid) { @@ -339,6 +361,8 @@ pub struct Watch { /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, } +unsafe impl Send for Watch {} +unsafe impl Sync for Watch {} use lightning::chain::Watch as rustWatch; impl rustWatch for Watch { @@ -420,6 +444,8 @@ pub struct Filter { /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, } +unsafe impl Send for Filter {} +unsafe impl Sync for Filter {} use lightning::chain::Filter as rustFilter; impl rustFilter for Filter { @@ -552,3 +578,32 @@ pub extern "C" fn WatchedOutput_new(mut block_hash_arg: crate::c_types::ThirtyTw script_pubkey: ::bitcoin::blockdata::script::Script::from(script_pubkey_arg.into_rust()), })), is_owned: true } } +impl Clone for WatchedOutput { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeWatchedOutput>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn WatchedOutput_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeWatchedOutput)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the WatchedOutput +pub extern "C" fn WatchedOutput_clone(orig: &WatchedOutput) -> WatchedOutput { + orig.clone() +} +/// Checks if two WatchedOutputs contain equal inner contents. +#[no_mangle] +pub extern "C" fn WatchedOutput_hash(o: &WatchedOutput) -> 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) +}