Skip to content

Commit 30a42f4

Browse files
committed
Update auto-generated bindings, including bumping cbindgen version
1 parent b243c65 commit 30a42f4

19 files changed

+3455
-1950
lines changed

lightning-c-bindings/include/lightning.h

Lines changed: 1739 additions & 1340 deletions
Large diffs are not rendered by default.

lightning-c-bindings/include/lightningpp.hpp

Lines changed: 145 additions & 89 deletions
Large diffs are not rendered by default.

lightning-c-bindings/include/rust_types.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,24 @@ struct nativePeerManagerOpaque;
123123
typedef struct nativePeerManagerOpaque LDKnativePeerManager;
124124
struct nativeTxCreationKeysOpaque;
125125
typedef struct nativeTxCreationKeysOpaque LDKnativeTxCreationKeys;
126-
struct nativePreCalculatedTxCreationKeysOpaque;
127-
typedef struct nativePreCalculatedTxCreationKeysOpaque LDKnativePreCalculatedTxCreationKeys;
128126
struct nativeChannelPublicKeysOpaque;
129127
typedef struct nativeChannelPublicKeysOpaque LDKnativeChannelPublicKeys;
130128
struct nativeHTLCOutputInCommitmentOpaque;
131129
typedef struct nativeHTLCOutputInCommitmentOpaque LDKnativeHTLCOutputInCommitment;
130+
struct nativeChannelTransactionParametersOpaque;
131+
typedef struct nativeChannelTransactionParametersOpaque LDKnativeChannelTransactionParameters;
132+
struct nativeCounterpartyChannelTransactionParametersOpaque;
133+
typedef struct nativeCounterpartyChannelTransactionParametersOpaque LDKnativeCounterpartyChannelTransactionParameters;
134+
struct nativeDirectedChannelTransactionParametersOpaque;
135+
typedef struct nativeDirectedChannelTransactionParametersOpaque LDKnativeDirectedChannelTransactionParameters;
132136
struct nativeHolderCommitmentTransactionOpaque;
133137
typedef struct nativeHolderCommitmentTransactionOpaque LDKnativeHolderCommitmentTransaction;
138+
struct nativeBuiltCommitmentTransactionOpaque;
139+
typedef struct nativeBuiltCommitmentTransactionOpaque LDKnativeBuiltCommitmentTransaction;
140+
struct nativeCommitmentTransactionOpaque;
141+
typedef struct nativeCommitmentTransactionOpaque LDKnativeCommitmentTransaction;
142+
struct nativeTrustedCommitmentTransactionOpaque;
143+
typedef struct nativeTrustedCommitmentTransactionOpaque LDKnativeTrustedCommitmentTransaction;
134144
struct nativeInitFeaturesOpaque;
135145
typedef struct nativeInitFeaturesOpaque LDKnativeInitFeatures;
136146
struct nativeNodeFeaturesOpaque;

lightning-c-bindings/src/c_types/derived.rs

Lines changed: 32 additions & 76 deletions
Large diffs are not rendered by default.

lightning-c-bindings/src/chain/chainmonitor.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ extern "C" fn ChainMonitor_free_void(this_ptr: *mut c_void) {
6464
#[allow(unused)]
6565
/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
6666
impl ChainMonitor {
67-
pub(crate) fn take_ptr(mut self) -> *mut nativeChainMonitor {
67+
pub(crate) fn take_inner(mut self) -> *mut nativeChainMonitor {
6868
assert!(self.is_owned);
6969
let ret = self.inner;
7070
self.inner = std::ptr::null_mut();
@@ -117,6 +117,16 @@ pub extern "C" fn ChainMonitor_new(chain_source: *mut crate::chain::Filter, mut
117117
ChainMonitor { inner: Box::into_raw(Box::new(ret)), is_owned: true }
118118
}
119119

120+
impl From<nativeChainMonitor> for crate::chain::Watch {
121+
fn from(obj: nativeChainMonitor) -> Self {
122+
let mut rust_obj = ChainMonitor { inner: Box::into_raw(Box::new(obj)), is_owned: true };
123+
let mut ret = ChainMonitor_as_Watch(&rust_obj);
124+
// We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
125+
rust_obj.inner = std::ptr::null_mut();
126+
ret.free = Some(ChainMonitor_free_void);
127+
ret
128+
}
129+
}
120130
#[no_mangle]
121131
pub extern "C" fn ChainMonitor_as_Watch(this_arg: *const ChainMonitor) -> crate::chain::Watch {
122132
crate::chain::Watch {
@@ -130,13 +140,13 @@ pub extern "C" fn ChainMonitor_as_Watch(this_arg: *const ChainMonitor) -> crate:
130140
use lightning::chain::Watch as WatchTraitImport;
131141
#[must_use]
132142
extern "C" fn ChainMonitor_Watch_watch_channel(this_arg: *const c_void, mut funding_outpoint: crate::chain::transaction::OutPoint, mut monitor: crate::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ {
133-
let mut ret = unsafe { &mut *(this_arg as *mut nativeChainMonitor) }.watch_channel(*unsafe { Box::from_raw(funding_outpoint.take_ptr()) }, *unsafe { Box::from_raw(monitor.take_ptr()) });
143+
let mut ret = unsafe { &mut *(this_arg as *mut nativeChainMonitor) }.watch_channel(*unsafe { Box::from_raw(funding_outpoint.take_inner()) }, *unsafe { Box::from_raw(monitor.take_inner()) });
134144
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }) };
135145
local_ret
136146
}
137147
#[must_use]
138148
extern "C" fn ChainMonitor_Watch_update_channel(this_arg: *const c_void, mut funding_txo: crate::chain::transaction::OutPoint, mut update: crate::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ {
139-
let mut ret = unsafe { &mut *(this_arg as *mut nativeChainMonitor) }.update_channel(*unsafe { Box::from_raw(funding_txo.take_ptr()) }, *unsafe { Box::from_raw(update.take_ptr()) });
149+
let mut ret = unsafe { &mut *(this_arg as *mut nativeChainMonitor) }.update_channel(*unsafe { Box::from_raw(funding_txo.take_inner()) }, *unsafe { Box::from_raw(update.take_inner()) });
140150
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }) };
141151
local_ret
142152
}
@@ -147,6 +157,16 @@ extern "C" fn ChainMonitor_Watch_release_pending_monitor_events(this_arg: *const
147157
local_ret.into()
148158
}
149159

160+
impl From<nativeChainMonitor> for crate::util::events::EventsProvider {
161+
fn from(obj: nativeChainMonitor) -> Self {
162+
let mut rust_obj = ChainMonitor { inner: Box::into_raw(Box::new(obj)), is_owned: true };
163+
let mut ret = ChainMonitor_as_EventsProvider(&rust_obj);
164+
// We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
165+
rust_obj.inner = std::ptr::null_mut();
166+
ret.free = Some(ChainMonitor_free_void);
167+
ret
168+
}
169+
}
150170
#[no_mangle]
151171
pub extern "C" fn ChainMonitor_as_EventsProvider(this_arg: *const ChainMonitor) -> crate::util::events::EventsProvider {
152172
crate::util::events::EventsProvider {

lightning-c-bindings/src/chain/channelmonitor.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extern "C" fn ChannelMonitorUpdate_free_void(this_ptr: *mut c_void) {
4949
#[allow(unused)]
5050
/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
5151
impl ChannelMonitorUpdate {
52-
pub(crate) fn take_ptr(mut self) -> *mut nativeChannelMonitorUpdate {
52+
pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitorUpdate {
5353
assert!(self.is_owned);
5454
let ret = self.inner;
5555
self.inner = std::ptr::null_mut();
@@ -116,6 +116,10 @@ pub extern "C" fn ChannelMonitorUpdate_write(obj: *const ChannelMonitorUpdate) -
116116
crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
117117
}
118118
#[no_mangle]
119+
pub(crate) extern "C" fn ChannelMonitorUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
120+
crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitorUpdate) })
121+
}
122+
#[no_mangle]
119123
pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> ChannelMonitorUpdate {
120124
if let Ok(res) = crate::c_types::deserialize_obj(ser) {
121125
ChannelMonitorUpdate { inner: Box::into_raw(Box::new(res)), is_owned: true }
@@ -255,7 +259,7 @@ extern "C" fn MonitorUpdateError_free_void(this_ptr: *mut c_void) {
255259
#[allow(unused)]
256260
/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
257261
impl MonitorUpdateError {
258-
pub(crate) fn take_ptr(mut self) -> *mut nativeMonitorUpdateError {
262+
pub(crate) fn take_inner(mut self) -> *mut nativeMonitorUpdateError {
259263
assert!(self.is_owned);
260264
let ret = self.inner;
261265
self.inner = std::ptr::null_mut();
@@ -293,7 +297,7 @@ extern "C" fn MonitorEvent_free_void(this_ptr: *mut c_void) {
293297
#[allow(unused)]
294298
/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
295299
impl MonitorEvent {
296-
pub(crate) fn take_ptr(mut self) -> *mut nativeMonitorEvent {
300+
pub(crate) fn take_inner(mut self) -> *mut nativeMonitorEvent {
297301
assert!(self.is_owned);
298302
let ret = self.inner;
299303
self.inner = std::ptr::null_mut();
@@ -352,7 +356,7 @@ extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) {
352356
#[allow(unused)]
353357
/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
354358
impl HTLCUpdate {
355-
pub(crate) fn take_ptr(mut self) -> *mut nativeHTLCUpdate {
359+
pub(crate) fn take_inner(mut self) -> *mut nativeHTLCUpdate {
356360
assert!(self.is_owned);
357361
let ret = self.inner;
358362
self.inner = std::ptr::null_mut();
@@ -381,6 +385,10 @@ pub extern "C" fn HTLCUpdate_write(obj: *const HTLCUpdate) -> crate::c_types::de
381385
crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
382386
}
383387
#[no_mangle]
388+
pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
389+
crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) })
390+
}
391+
#[no_mangle]
384392
pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> HTLCUpdate {
385393
if let Ok(res) = crate::c_types::deserialize_obj(ser) {
386394
HTLCUpdate { inner: Box::into_raw(Box::new(res)), is_owned: true }
@@ -402,6 +410,12 @@ type nativeChannelMonitor = nativeChannelMonitorImport<crate::chain::keysinterfa
402410
/// get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and
403411
/// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
404412
/// gotten are fully handled before re-serializing the new state.
413+
///
414+
/// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which
415+
/// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
416+
/// the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
417+
/// returned block hash and the the current chain and then reconnecting blocks to get to the
418+
/// best chain) upon deserializing the object!
405419
#[must_use]
406420
#[repr(C)]
407421
pub struct ChannelMonitor {
@@ -428,7 +442,7 @@ extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
428442
#[allow(unused)]
429443
/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
430444
impl ChannelMonitor {
431-
pub(crate) fn take_ptr(mut self) -> *mut nativeChannelMonitor {
445+
pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitor {
432446
assert!(self.is_owned);
433447
let ret = self.inner;
434448
self.inner = std::ptr::null_mut();
@@ -600,12 +614,12 @@ use lightning::chain::channelmonitor::Persist as rustPersist;
600614
impl rustPersist<crate::chain::keysinterface::ChannelKeys> for Persist {
601615
fn persist_new_channel(&self, id: lightning::chain::transaction::OutPoint, data: &lightning::chain::channelmonitor::ChannelMonitor<crate::chain::keysinterface::ChannelKeys>) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> {
602616
let mut ret = (self.persist_new_channel)(self.this_arg, crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(id)), is_owned: true }, &crate::chain::channelmonitor::ChannelMonitor { inner: unsafe { (data as *const _) as *mut _ }, is_owned: false });
603-
let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(ret.contents.result.take_ptr()) })*/ }), false => Err( { (*unsafe { Box::from_raw(ret.contents.err.take_ptr()) }).into_native() })};
617+
let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })};
604618
local_ret
605619
}
606620
fn update_persisted_channel(&self, id: lightning::chain::transaction::OutPoint, update: &lightning::chain::channelmonitor::ChannelMonitorUpdate, data: &lightning::chain::channelmonitor::ChannelMonitor<crate::chain::keysinterface::ChannelKeys>) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> {
607621
let mut ret = (self.update_persisted_channel)(self.this_arg, crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(id)), is_owned: true }, &crate::chain::channelmonitor::ChannelMonitorUpdate { inner: unsafe { (update as *const _) as *mut _ }, is_owned: false }, &crate::chain::channelmonitor::ChannelMonitor { inner: unsafe { (data as *const _) as *mut _ }, is_owned: false });
608-
let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(ret.contents.result.take_ptr()) })*/ }), false => Err( { (*unsafe { Box::from_raw(ret.contents.err.take_ptr()) }).into_native() })};
622+
let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })};
609623
local_ret
610624
}
611625
}

0 commit comments

Comments
 (0)