Skip to content

Commit cdee9e6

Browse files
committed
- bindings updates
1 parent 6ecc087 commit cdee9e6

File tree

9 files changed

+165
-110
lines changed

9 files changed

+165
-110
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ impl ChannelMonitorUpdate {
5959
impl Clone for ChannelMonitorUpdate {
6060
fn clone(&self) -> Self {
6161
Self {
62-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
62+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
63+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
6364
is_owned: true,
6465
}
6566
}
@@ -71,7 +72,7 @@ pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void
7172
}
7273
#[no_mangle]
7374
pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate {
74-
ChannelMonitorUpdate { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
75+
orig.clone()
7576
}
7677
/// The sequence number of this update. Updates *must* be replayed in-order according to this
7778
/// sequence number (and updates may panic if they are not). The update_id values are strictly
@@ -305,7 +306,8 @@ impl MonitorEvent {
305306
impl Clone for MonitorEvent {
306307
fn clone(&self) -> Self {
307308
Self {
308-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
309+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
310+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
309311
is_owned: true,
310312
}
311313
}
@@ -317,7 +319,7 @@ pub(crate) extern "C" fn MonitorEvent_clone_void(this_ptr: *const c_void) -> *mu
317319
}
318320
#[no_mangle]
319321
pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent {
320-
MonitorEvent { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
322+
orig.clone()
321323
}
322324

323325
use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
@@ -364,7 +366,8 @@ impl HTLCUpdate {
364366
impl Clone for HTLCUpdate {
365367
fn clone(&self) -> Self {
366368
Self {
367-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
369+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
370+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
368371
is_owned: true,
369372
}
370373
}
@@ -376,7 +379,7 @@ pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut
376379
}
377380
#[no_mangle]
378381
pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate {
379-
HTLCUpdate { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
382+
orig.clone()
380383
}
381384
#[no_mangle]
382385
pub extern "C" fn HTLCUpdate_write(obj: &HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,8 @@ impl InMemoryChannelKeys {
612612
impl Clone for InMemoryChannelKeys {
613613
fn clone(&self) -> Self {
614614
Self {
615-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
615+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
616+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
616617
is_owned: true,
617618
}
618619
}
@@ -624,7 +625,7 @@ pub(crate) extern "C" fn InMemoryChannelKeys_clone_void(this_ptr: *const c_void)
624625
}
625626
#[no_mangle]
626627
pub extern "C" fn InMemoryChannelKeys_clone(orig: &InMemoryChannelKeys) -> InMemoryChannelKeys {
627-
InMemoryChannelKeys { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
628+
orig.clone()
628629
}
629630
/// Private key of anchor tx
630631
#[no_mangle]

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ impl OutPoint {
4848
impl Clone for OutPoint {
4949
fn clone(&self) -> Self {
5050
Self {
51-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
51+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
52+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
5253
is_owned: true,
5354
}
5455
}
@@ -60,7 +61,7 @@ pub(crate) extern "C" fn OutPoint_clone_void(this_ptr: *const c_void) -> *mut c_
6061
}
6162
#[no_mangle]
6263
pub extern "C" fn OutPoint_clone(orig: &OutPoint) -> OutPoint {
63-
OutPoint { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
64+
orig.clone()
6465
}
6566
/// The referenced transaction's txid.
6667
#[no_mangle]

lightning-c-bindings/src/ln/chan_utils.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ impl TxCreationKeys {
123123
impl Clone for TxCreationKeys {
124124
fn clone(&self) -> Self {
125125
Self {
126-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
126+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
127+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
127128
is_owned: true,
128129
}
129130
}
@@ -135,7 +136,7 @@ pub(crate) extern "C" fn TxCreationKeys_clone_void(this_ptr: *const c_void) -> *
135136
}
136137
#[no_mangle]
137138
pub extern "C" fn TxCreationKeys_clone(orig: &TxCreationKeys) -> TxCreationKeys {
138-
TxCreationKeys { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
139+
orig.clone()
139140
}
140141
/// The broadcaster's per-commitment public key which was used to derive the other keys.
141142
#[no_mangle]
@@ -264,7 +265,8 @@ impl ChannelPublicKeys {
264265
impl Clone for ChannelPublicKeys {
265266
fn clone(&self) -> Self {
266267
Self {
267-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
268+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
269+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
268270
is_owned: true,
269271
}
270272
}
@@ -276,7 +278,7 @@ pub(crate) extern "C" fn ChannelPublicKeys_clone_void(this_ptr: *const c_void) -
276278
}
277279
#[no_mangle]
278280
pub extern "C" fn ChannelPublicKeys_clone(orig: &ChannelPublicKeys) -> ChannelPublicKeys {
279-
ChannelPublicKeys { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
281+
orig.clone()
280282
}
281283
/// The public key which is used to sign all commitment transactions, as it appears in the
282284
/// on-chain channel lock-in 2-of-2 multisig output.
@@ -448,7 +450,8 @@ impl HTLCOutputInCommitment {
448450
impl Clone for HTLCOutputInCommitment {
449451
fn clone(&self) -> Self {
450452
Self {
451-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
453+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
454+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
452455
is_owned: true,
453456
}
454457
}
@@ -460,7 +463,7 @@ pub(crate) extern "C" fn HTLCOutputInCommitment_clone_void(this_ptr: *const c_vo
460463
}
461464
#[no_mangle]
462465
pub extern "C" fn HTLCOutputInCommitment_clone(orig: &HTLCOutputInCommitment) -> HTLCOutputInCommitment {
463-
HTLCOutputInCommitment { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
466+
orig.clone()
464467
}
465468
/// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
466469
/// Note that this is not the same as whether it is ountbound *from us*. To determine that you
@@ -599,7 +602,8 @@ impl ChannelTransactionParameters {
599602
impl Clone for ChannelTransactionParameters {
600603
fn clone(&self) -> Self {
601604
Self {
602-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
605+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
606+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
603607
is_owned: true,
604608
}
605609
}
@@ -611,7 +615,7 @@ pub(crate) extern "C" fn ChannelTransactionParameters_clone_void(this_ptr: *cons
611615
}
612616
#[no_mangle]
613617
pub extern "C" fn ChannelTransactionParameters_clone(orig: &ChannelTransactionParameters) -> ChannelTransactionParameters {
614-
ChannelTransactionParameters { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
618+
orig.clone()
615619
}
616620
/// Holder public keys
617621
#[no_mangle]
@@ -730,7 +734,8 @@ impl CounterpartyChannelTransactionParameters {
730734
impl Clone for CounterpartyChannelTransactionParameters {
731735
fn clone(&self) -> Self {
732736
Self {
733-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
737+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
738+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
734739
is_owned: true,
735740
}
736741
}
@@ -742,7 +747,7 @@ pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_clone_void(thi
742747
}
743748
#[no_mangle]
744749
pub extern "C" fn CounterpartyChannelTransactionParameters_clone(orig: &CounterpartyChannelTransactionParameters) -> CounterpartyChannelTransactionParameters {
745-
CounterpartyChannelTransactionParameters { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
750+
orig.clone()
746751
}
747752
/// Counter-party public keys
748753
#[no_mangle]
@@ -965,7 +970,8 @@ impl HolderCommitmentTransaction {
965970
impl Clone for HolderCommitmentTransaction {
966971
fn clone(&self) -> Self {
967972
Self {
968-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
973+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
974+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
969975
is_owned: true,
970976
}
971977
}
@@ -977,7 +983,7 @@ pub(crate) extern "C" fn HolderCommitmentTransaction_clone_void(this_ptr: *const
977983
}
978984
#[no_mangle]
979985
pub extern "C" fn HolderCommitmentTransaction_clone(orig: &HolderCommitmentTransaction) -> HolderCommitmentTransaction {
980-
HolderCommitmentTransaction { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
986+
orig.clone()
981987
}
982988
/// Our counterparty's signature for the transaction
983989
#[no_mangle]
@@ -1063,7 +1069,8 @@ impl BuiltCommitmentTransaction {
10631069
impl Clone for BuiltCommitmentTransaction {
10641070
fn clone(&self) -> Self {
10651071
Self {
1066-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
1072+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
1073+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
10671074
is_owned: true,
10681075
}
10691076
}
@@ -1075,7 +1082,7 @@ pub(crate) extern "C" fn BuiltCommitmentTransaction_clone_void(this_ptr: *const
10751082
}
10761083
#[no_mangle]
10771084
pub extern "C" fn BuiltCommitmentTransaction_clone(orig: &BuiltCommitmentTransaction) -> BuiltCommitmentTransaction {
1078-
BuiltCommitmentTransaction { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
1085+
orig.clone()
10791086
}
10801087
/// The commitment transaction
10811088
#[no_mangle]
@@ -1195,7 +1202,8 @@ impl CommitmentTransaction {
11951202
impl Clone for CommitmentTransaction {
11961203
fn clone(&self) -> Self {
11971204
Self {
1198-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
1205+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
1206+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
11991207
is_owned: true,
12001208
}
12011209
}
@@ -1207,7 +1215,7 @@ pub(crate) extern "C" fn CommitmentTransaction_clone_void(this_ptr: *const c_voi
12071215
}
12081216
#[no_mangle]
12091217
pub extern "C" fn CommitmentTransaction_clone(orig: &CommitmentTransaction) -> CommitmentTransaction {
1210-
CommitmentTransaction { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
1218+
orig.clone()
12111219
}
12121220
#[no_mangle]
12131221
pub extern "C" fn CommitmentTransaction_write(obj: &CommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {

lightning-c-bindings/src/ln/channelmanager.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ impl ChannelDetails {
127127
impl Clone for ChannelDetails {
128128
fn clone(&self) -> Self {
129129
Self {
130-
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
130+
inner: if self.inner.is_null() { std::ptr::null_mut() } else {
131+
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
131132
is_owned: true,
132133
}
133134
}
@@ -139,7 +140,7 @@ pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *
139140
}
140141
#[no_mangle]
141142
pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
142-
ChannelDetails { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
143+
orig.clone()
143144
}
144145
/// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
145146
/// thereafter this is the txid of the funding transaction xor the funding transaction output).

0 commit comments

Comments
 (0)