From 721d0a855e2dde4f39a3b0c5fd094f07775d6caf Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 12 Mar 2021 11:40:08 -0500 Subject: [PATCH] Add ChannelMonitor_clone patch to bindings --- lightning-c-bindings/Cargo.toml | 2 +- lightning-c-bindings/include/lightning.h | 5 +++++ .../src/chain/channelmonitor.rs | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lightning-c-bindings/Cargo.toml b/lightning-c-bindings/Cargo.toml index e8e556b..55dcb14 100644 --- a/lightning-c-bindings/Cargo.toml +++ b/lightning-c-bindings/Cargo.toml @@ -18,7 +18,7 @@ crate-type = ["staticlib" bitcoin = "0.26" secp256k1 = { version = "0.20.1", features = ["global-context-less-secure"] } # Note that the following line is matched by genbindings to update the path -lightning = { git = "https://git.bitcoin.ninja/rust-lightning", rev = "6fcac8bc65ed6d372e0b8c367e9934c754f99ff3", features = ["allow_wallclock_use"] } +lightning = { git = "https://git.bitcoin.ninja/rust-lightning", rev = "28dc5a1b22c38e0c37e92c9b8797e52130e9c812", features = ["allow_wallclock_use"] } [patch.crates-io] # Rust-Secp256k1 PR 279. Should be dropped once merged. diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index bdeb298..49de1f6 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -10222,6 +10222,11 @@ struct LDKCResult_HTLCUpdateDecodeErrorZ HTLCUpdate_read(struct LDKu8slice ser); */ void ChannelMonitor_free(struct LDKChannelMonitor this_obj); +/** + * Creates a copy of the ChannelMonitor + */ +struct LDKChannelMonitor ChannelMonitor_clone(const struct LDKChannelMonitor *NONNULL_PTR orig); + /** * Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read */ diff --git a/lightning-c-bindings/src/chain/channelmonitor.rs b/lightning-c-bindings/src/chain/channelmonitor.rs index 5e10158..5a50b01 100644 --- a/lightning-c-bindings/src/chain/channelmonitor.rs +++ b/lightning-c-bindings/src/chain/channelmonitor.rs @@ -538,6 +538,25 @@ impl ChannelMonitor { ret } } +impl Clone for ChannelMonitor { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeChannelMonitor>::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 ChannelMonitor_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelMonitor)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the ChannelMonitor +pub extern "C" fn ChannelMonitor_clone(orig: &ChannelMonitor) -> ChannelMonitor { + orig.clone() +} #[no_mangle] /// Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read pub extern "C" fn ChannelMonitor_write(obj: &ChannelMonitor) -> crate::c_types::derived::CVec_u8Z { -- 2.39.5