Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize trait derives in network message and graph objects #803

Merged
merged 4 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lightning-c-bindings/include/lightning.h
Original file line number Diff line number Diff line change
Expand Up @@ -4150,6 +4150,8 @@ struct LDKCResult_ChannelInfoDecodeErrorZ CResult_ChannelInfoDecodeErrorZ_err(st

void CResult_ChannelInfoDecodeErrorZ_free(struct LDKCResult_ChannelInfoDecodeErrorZ _res);

struct LDKCResult_ChannelInfoDecodeErrorZ CResult_ChannelInfoDecodeErrorZ_clone(const struct LDKCResult_ChannelInfoDecodeErrorZ *NONNULL_PTR orig);

struct LDKCResult_RoutingFeesDecodeErrorZ CResult_RoutingFeesDecodeErrorZ_ok(struct LDKRoutingFees o);

struct LDKCResult_RoutingFeesDecodeErrorZ CResult_RoutingFeesDecodeErrorZ_err(struct LDKDecodeError e);
Expand Down Expand Up @@ -4184,6 +4186,8 @@ struct LDKCResult_NetworkGraphDecodeErrorZ CResult_NetworkGraphDecodeErrorZ_err(

void CResult_NetworkGraphDecodeErrorZ_free(struct LDKCResult_NetworkGraphDecodeErrorZ _res);

struct LDKCResult_NetworkGraphDecodeErrorZ CResult_NetworkGraphDecodeErrorZ_clone(const struct LDKCResult_NetworkGraphDecodeErrorZ *NONNULL_PTR orig);

struct LDKC2Tuple_usizeTransactionZ C2Tuple_usizeTransactionZ_new(uintptr_t a, struct LDKTransaction b);

void C2Tuple_usizeTransactionZ_free(struct LDKC2Tuple_usizeTransactionZ _res);
Expand Down Expand Up @@ -6149,6 +6153,18 @@ struct LDKDecodeError DecodeError_clone(const struct LDKDecodeError *NONNULL_PTR

void Init_free(struct LDKInit this_ptr);

/**
* The relevant features which the sender supports
*/
struct LDKInitFeatures Init_get_features(const struct LDKInit *NONNULL_PTR this_ptr);

/**
* The relevant features which the sender supports
*/
void Init_set_features(struct LDKInit *NONNULL_PTR this_ptr, struct LDKInitFeatures val);

MUST_USE_RES struct LDKInit Init_new(struct LDKInitFeatures features_arg);

struct LDKInit Init_clone(const struct LDKInit *NONNULL_PTR orig);

void ErrorMessage_free(struct LDKErrorMessage this_ptr);
Expand Down Expand Up @@ -8772,6 +8788,8 @@ struct LDKCResult_RouteLightningErrorZ get_route(struct LDKPublicKey our_node_id

void NetworkGraph_free(struct LDKNetworkGraph this_ptr);

struct LDKNetworkGraph NetworkGraph_clone(const struct LDKNetworkGraph *NONNULL_PTR orig);

void LockedNetworkGraph_free(struct LDKLockedNetworkGraph this_ptr);

void NetGraphMsgHandler_free(struct LDKNetGraphMsgHandler this_ptr);
Expand Down Expand Up @@ -8952,6 +8970,8 @@ struct LDKChannelAnnouncement ChannelInfo_get_announcement_message(const struct
*/
void ChannelInfo_set_announcement_message(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKChannelAnnouncement val);

struct LDKChannelInfo ChannelInfo_clone(const struct LDKChannelInfo *NONNULL_PTR orig);

struct LDKCVec_u8Z ChannelInfo_write(const struct LDKChannelInfo *NONNULL_PTR obj);

struct LDKCResult_ChannelInfoDecodeErrorZ ChannelInfo_read(struct LDKu8slice ser);
Expand Down
30 changes: 30 additions & 0 deletions lightning-c-bindings/src/c_types/derived.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,21 @@ impl From<crate::c_types::CResultTempl<crate::routing::network_graph::ChannelInf
}
}
}
impl Clone for CResult_ChannelInfoDecodeErrorZ {
fn clone(&self) -> Self {
if self.result_ok {
Self { result_ok: true, contents: CResult_ChannelInfoDecodeErrorZPtr {
result: Box::into_raw(Box::new(<crate::routing::network_graph::ChannelInfo>::clone(unsafe { &*self.contents.result })))
} }
} else {
Self { result_ok: false, contents: CResult_ChannelInfoDecodeErrorZPtr {
err: Box::into_raw(Box::new(<crate::ln::msgs::DecodeError>::clone(unsafe { &*self.contents.err })))
} }
}
}
}
#[no_mangle]
pub extern "C" fn CResult_ChannelInfoDecodeErrorZ_clone(orig: &CResult_ChannelInfoDecodeErrorZ) -> CResult_ChannelInfoDecodeErrorZ { orig.clone() }
#[repr(C)]
pub union CResult_RoutingFeesDecodeErrorZPtr {
pub result: *mut crate::routing::network_graph::RoutingFees,
Expand Down Expand Up @@ -2305,6 +2320,21 @@ impl From<crate::c_types::CResultTempl<crate::routing::network_graph::NetworkGra
}
}
}
impl Clone for CResult_NetworkGraphDecodeErrorZ {
fn clone(&self) -> Self {
if self.result_ok {
Self { result_ok: true, contents: CResult_NetworkGraphDecodeErrorZPtr {
result: Box::into_raw(Box::new(<crate::routing::network_graph::NetworkGraph>::clone(unsafe { &*self.contents.result })))
} }
} else {
Self { result_ok: false, contents: CResult_NetworkGraphDecodeErrorZPtr {
err: Box::into_raw(Box::new(<crate::ln::msgs::DecodeError>::clone(unsafe { &*self.contents.err })))
} }
}
}
}
#[no_mangle]
pub extern "C" fn CResult_NetworkGraphDecodeErrorZ_clone(orig: &CResult_NetworkGraphDecodeErrorZ) -> CResult_NetworkGraphDecodeErrorZ { orig.clone() }
#[repr(C)]
pub struct C2Tuple_usizeTransactionZ {
pub a: usize,
Expand Down
18 changes: 18 additions & 0 deletions lightning-c-bindings/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ impl Init {
ret
}
}
/// The relevant features which the sender supports
#[no_mangle]
pub extern "C" fn Init_get_features(this_ptr: &Init) -> crate::ln::features::InitFeatures {
let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
crate::ln::features::InitFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
}
/// The relevant features which the sender supports
#[no_mangle]
pub extern "C" fn Init_set_features(this_ptr: &mut Init, mut val: crate::ln::features::InitFeatures) {
unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) };
}
#[must_use]
#[no_mangle]
pub extern "C" fn Init_new(mut features_arg: crate::ln::features::InitFeatures) -> Init {
Init { inner: Box::into_raw(Box::new(nativeInit {
features: *unsafe { Box::from_raw(features_arg.take_inner()) },
})), is_owned: true }
}
impl Clone for Init {
fn clone(&self) -> Self {
Self {
Expand Down
36 changes: 36 additions & 0 deletions lightning-c-bindings/src/routing/network_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ impl NetworkGraph {
ret
}
}
impl Clone for NetworkGraph {
fn clone(&self) -> Self {
Self {
inner: if self.inner.is_null() { 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 NetworkGraph_clone_void(this_ptr: *const c_void) -> *mut c_void {
Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNetworkGraph)).clone() })) as *mut c_void
}
#[no_mangle]
pub extern "C" fn NetworkGraph_clone(orig: &NetworkGraph) -> NetworkGraph {
orig.clone()
}

use lightning::routing::network_graph::LockedNetworkGraph as nativeLockedNetworkGraphImport;
type nativeLockedNetworkGraph = nativeLockedNetworkGraphImport<'static>;
Expand Down Expand Up @@ -559,6 +577,24 @@ pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInf
let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
}
impl Clone for ChannelInfo {
fn clone(&self) -> Self {
Self {
inner: if self.inner.is_null() { 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 ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
}
#[no_mangle]
pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
orig.clone()
}
#[no_mangle]
pub extern "C" fn ChannelInfo_write(obj: &ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
Expand Down
Loading