Merge pull request #788 from TheBlueMatt/2020-02-concrete-bindings

Concretize bindings templates
This commit is contained in:
Matt Corallo 2021-02-10 20:31:43 -08:00 committed by GitHub
commit 879e309c12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 7420 additions and 3401 deletions

View file

@ -32,6 +32,261 @@ pub fn write_cpp_wrapper(cpp_header_file: &mut File, ty: &str, has_destructor: b
writeln!(cpp_header_file, "}};").unwrap(); writeln!(cpp_header_file, "}};").unwrap();
} }
/// Writes out a C-callable concrete Result<A, B> struct and utility methods
pub fn write_result_block<W: std::io::Write>(w: &mut W, mangled_container: &str, ok_type: &str, err_type: &str, clonable: bool) {
writeln!(w, "#[repr(C)]").unwrap();
writeln!(w, "pub union {}Ptr {{", mangled_container).unwrap();
if ok_type != "()" {
writeln!(w, "\tpub result: *mut {},", ok_type).unwrap();
} else {
writeln!(w, "\t/// Note that this value is always NULL, as there are no contents in the OK variant").unwrap();
writeln!(w, "\tpub result: *mut std::ffi::c_void,").unwrap();
}
if err_type != "()" {
writeln!(w, "\tpub err: *mut {},", err_type).unwrap();
} else {
writeln!(w, "\t/// Note that this value is always NULL, as there are no contents in the Err variant").unwrap();
writeln!(w, "\tpub err: *mut std::ffi::c_void,").unwrap();
}
writeln!(w, "}}").unwrap();
writeln!(w, "#[repr(C)]").unwrap();
writeln!(w, "pub struct {} {{", mangled_container).unwrap();
writeln!(w, "\tpub contents: {}Ptr,", mangled_container).unwrap();
writeln!(w, "\tpub result_ok: bool,").unwrap();
writeln!(w, "}}").unwrap();
writeln!(w, "#[no_mangle]").unwrap();
if ok_type != "()" {
writeln!(w, "pub extern \"C\" fn {}_ok(o: {}) -> {} {{", mangled_container, ok_type, mangled_container).unwrap();
} else {
writeln!(w, "pub extern \"C\" fn {}_ok() -> {} {{", mangled_container, mangled_container).unwrap();
}
writeln!(w, "\t{} {{", mangled_container).unwrap();
writeln!(w, "\t\tcontents: {}Ptr {{", mangled_container).unwrap();
if ok_type != "()" {
writeln!(w, "\t\t\tresult: Box::into_raw(Box::new(o)),").unwrap();
} else {
writeln!(w, "\t\t\tresult: std::ptr::null_mut(),").unwrap();
}
writeln!(w, "\t\t}},").unwrap();
writeln!(w, "\t\tresult_ok: true,").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
writeln!(w, "#[no_mangle]").unwrap();
if err_type != "()" {
writeln!(w, "pub extern \"C\" fn {}_err(e: {}) -> {} {{", mangled_container, err_type, mangled_container).unwrap();
} else {
writeln!(w, "pub extern \"C\" fn {}_err() -> {} {{", mangled_container, mangled_container).unwrap();
}
writeln!(w, "\t{} {{", mangled_container).unwrap();
writeln!(w, "\t\tcontents: {}Ptr {{", mangled_container).unwrap();
if err_type != "()" {
writeln!(w, "\t\t\terr: Box::into_raw(Box::new(e)),").unwrap();
} else {
writeln!(w, "\t\t\terr: std::ptr::null_mut(),").unwrap();
}
writeln!(w, "\t\t}},").unwrap();
writeln!(w, "\t\tresult_ok: false,").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_free(_res: {}) {{ }}", mangled_container, mangled_container).unwrap();
writeln!(w, "impl Drop for {} {{", mangled_container).unwrap();
writeln!(w, "\tfn drop(&mut self) {{").unwrap();
writeln!(w, "\t\tif self.result_ok {{").unwrap();
if ok_type != "()" {
writeln!(w, "\t\t\tif unsafe {{ !(self.contents.result as *mut ()).is_null() }} {{").unwrap();
writeln!(w, "\t\t\t\tlet _ = unsafe {{ Box::from_raw(self.contents.result) }};").unwrap();
writeln!(w, "\t\t\t}}").unwrap();
}
writeln!(w, "\t\t}} else {{").unwrap();
if err_type != "()" {
writeln!(w, "\t\t\tif unsafe {{ !(self.contents.err as *mut ()).is_null() }} {{").unwrap();
writeln!(w, "\t\t\t\tlet _ = unsafe {{ Box::from_raw(self.contents.err) }};").unwrap();
writeln!(w, "\t\t\t}}").unwrap();
}
writeln!(w, "\t\t}}").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
// TODO: Templates should use () now that they can, too
let templ_ok_type = if ok_type != "()" { ok_type } else { "u8" };
let templ_err_type = if err_type != "()" { err_type } else { "u8" };
writeln!(w, "impl From<crate::c_types::CResultTempl<{}, {}>> for {} {{", templ_ok_type, templ_err_type, mangled_container).unwrap();
writeln!(w, "\tfn from(mut o: crate::c_types::CResultTempl<{}, {}>) -> Self {{", templ_ok_type, templ_err_type).unwrap();
writeln!(w, "\t\tlet contents = if o.result_ok {{").unwrap();
if ok_type != "()" {
writeln!(w, "\t\t\tlet result = unsafe {{ o.contents.result }};").unwrap();
writeln!(w, "\t\t\tunsafe {{ o.contents.result = std::ptr::null_mut() }};").unwrap();
writeln!(w, "\t\t\t{}Ptr {{ result }}", mangled_container).unwrap();
} else {
writeln!(w, "\t\t\tlet _ = unsafe {{ Box::from_raw(o.contents.result) }};").unwrap();
writeln!(w, "\t\t\to.contents.result = std::ptr::null_mut();").unwrap();
writeln!(w, "\t\t\t{}Ptr {{ result: std::ptr::null_mut() }}", mangled_container).unwrap();
}
writeln!(w, "\t\t}} else {{").unwrap();
if err_type != "()" {
writeln!(w, "\t\t\tlet err = unsafe {{ o.contents.err }};").unwrap();
writeln!(w, "\t\t\tunsafe {{ o.contents.err = std::ptr::null_mut(); }}").unwrap();
writeln!(w, "\t\t\t{}Ptr {{ err }}", mangled_container).unwrap();
} else {
writeln!(w, "\t\t\tlet _ = unsafe {{ Box::from_raw(o.contents.err) }};").unwrap();
writeln!(w, "\t\t\to.contents.err = std::ptr::null_mut();").unwrap();
writeln!(w, "\t\t\t{}Ptr {{ err: std::ptr::null_mut() }}", mangled_container).unwrap();
}
writeln!(w, "\t\t}};").unwrap();
writeln!(w, "\t\tSelf {{").unwrap();
writeln!(w, "\t\t\tcontents,").unwrap();
writeln!(w, "\t\t\tresult_ok: o.result_ok,").unwrap();
writeln!(w, "\t\t}}").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
if clonable {
writeln!(w, "impl Clone for {} {{", mangled_container).unwrap();
writeln!(w, "\tfn clone(&self) -> Self {{").unwrap();
writeln!(w, "\t\tif self.result_ok {{").unwrap();
writeln!(w, "\t\t\tSelf {{ result_ok: true, contents: {}Ptr {{", mangled_container).unwrap();
if ok_type != "()" {
writeln!(w, "\t\t\t\tresult: Box::into_raw(Box::new(<{}>::clone(unsafe {{ &*self.contents.result }})))", ok_type).unwrap();
} else {
writeln!(w, "\t\t\t\tresult: std::ptr::null_mut()").unwrap();
}
writeln!(w, "\t\t\t}} }}").unwrap();
writeln!(w, "\t\t}} else {{").unwrap();
writeln!(w, "\t\t\tSelf {{ result_ok: false, contents: {}Ptr {{", mangled_container).unwrap();
if err_type != "()" {
writeln!(w, "\t\t\t\terr: Box::into_raw(Box::new(<{}>::clone(unsafe {{ &*self.contents.err }})))", err_type).unwrap();
} else {
writeln!(w, "\t\t\t\terr: std::ptr::null_mut()").unwrap();
}
writeln!(w, "\t\t\t}} }}").unwrap();
writeln!(w, "\t\t}}").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{ orig.clone() }}", mangled_container, mangled_container, mangled_container).unwrap();
}
}
/// Writes out a C-callable concrete Vec<A> struct and utility methods
pub fn write_vec_block<W: std::io::Write>(w: &mut W, mangled_container: &str, inner_type: &str, clonable: bool) {
writeln!(w, "#[repr(C)]").unwrap();
writeln!(w, "pub struct {} {{", mangled_container).unwrap();
writeln!(w, "\tpub data: *mut {},", inner_type).unwrap();
writeln!(w, "\tpub datalen: usize").unwrap();
writeln!(w, "}}").unwrap();
writeln!(w, "impl {} {{", mangled_container).unwrap();
writeln!(w, "\t#[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec<{}> {{", inner_type).unwrap();
writeln!(w, "\t\tif self.datalen == 0 {{ return Vec::new(); }}").unwrap();
writeln!(w, "\t\tlet ret = unsafe {{ Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }}.into();").unwrap();
writeln!(w, "\t\tself.data = std::ptr::null_mut();").unwrap();
writeln!(w, "\t\tself.datalen = 0;").unwrap();
writeln!(w, "\t\tret").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "\t#[allow(unused)] pub(crate) fn as_slice(&self) -> &[{}] {{", inner_type).unwrap();
writeln!(w, "\t\tunsafe {{ std::slice::from_raw_parts_mut(self.data, self.datalen) }}").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
writeln!(w, "impl From<Vec<{}>> for {} {{", inner_type, mangled_container).unwrap();
writeln!(w, "\tfn from(v: Vec<{}>) -> Self {{", inner_type).unwrap();
writeln!(w, "\t\tlet datalen = v.len();").unwrap();
writeln!(w, "\t\tlet data = Box::into_raw(v.into_boxed_slice());").unwrap();
writeln!(w, "\t\tSelf {{ datalen, data: unsafe {{ (*data).as_mut_ptr() }} }}").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_free(_res: {}) {{ }}", mangled_container, mangled_container).unwrap();
writeln!(w, "impl Drop for {} {{", mangled_container).unwrap();
writeln!(w, "\tfn drop(&mut self) {{").unwrap();
writeln!(w, "\t\tif self.datalen == 0 {{ return; }}").unwrap();
writeln!(w, "\t\tunsafe {{ Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }};").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
if clonable {
writeln!(w, "impl Clone for {} {{", mangled_container).unwrap();
writeln!(w, "\tfn clone(&self) -> Self {{").unwrap();
writeln!(w, "\t\tlet mut res = Vec::new();").unwrap();
writeln!(w, "\t\tif self.datalen == 0 {{ return Self::from(res); }}").unwrap();
writeln!(w, "\t\tres.extend_from_slice(unsafe {{ std::slice::from_raw_parts_mut(self.data, self.datalen) }});").unwrap();
writeln!(w, "\t\tSelf::from(res)").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
}
}
/// Writes out a C-callable concrete (A, B, ...) struct and utility methods
pub fn write_tuple_block<W: std::io::Write>(w: &mut W, mangled_container: &str, types: &[String], clonable: bool) {
writeln!(w, "#[repr(C)]").unwrap();
writeln!(w, "pub struct {} {{", mangled_container).unwrap();
for (idx, ty) in types.iter().enumerate() {
writeln!(w, "\tpub {}: {},", ('a' as u8 + idx as u8) as char, ty).unwrap();
}
writeln!(w, "}}").unwrap();
let mut tuple_str = "(".to_owned();
for (idx, ty) in types.iter().enumerate() {
if idx != 0 { tuple_str += ", "; }
tuple_str += ty;
}
tuple_str += ")";
writeln!(w, "impl From<{}> for {} {{", tuple_str, mangled_container).unwrap();
writeln!(w, "\tfn from (tup: {}) -> Self {{", tuple_str).unwrap();
writeln!(w, "\t\tSelf {{").unwrap();
for idx in 0..types.len() {
writeln!(w, "\t\t\t{}: tup.{},", ('a' as u8 + idx as u8) as char, idx).unwrap();
}
writeln!(w, "\t\t}}").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
writeln!(w, "impl {} {{", mangled_container).unwrap();
writeln!(w, "\t#[allow(unused)] pub(crate) fn to_rust(mut self) -> {} {{", tuple_str).unwrap();
write!(w, "\t\t(").unwrap();
for idx in 0..types.len() {
write!(w, "{}self.{}", if idx != 0 {", "} else {""}, ('a' as u8 + idx as u8) as char).unwrap();
}
writeln!(w, ")").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
if clonable {
writeln!(w, "impl Clone for {} {{", mangled_container).unwrap();
writeln!(w, "\tfn clone(&self) -> Self {{").unwrap();
writeln!(w, "\t\tSelf {{").unwrap();
for idx in 0..types.len() {
writeln!(w, "\t\t\t{}: self.{}.clone(),", ('a' as u8 + idx as u8) as char, ('a' as u8 + idx as u8) as char).unwrap();
}
writeln!(w, "\t\t}}").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{ orig.clone() }}", mangled_container, mangled_container, mangled_container).unwrap();
}
write!(w, "#[no_mangle]\npub extern \"C\" fn {}_new(", mangled_container).unwrap();
for (idx, gen) in types.iter().enumerate() {
write!(w, "{}{}: ", if idx != 0 { ", " } else { "" }, ('a' as u8 + idx as u8) as char).unwrap();
//if !self.write_c_type_intern(&mut created_container, gen, generics, false, false, false) { return false; }
write!(w, "{}", gen).unwrap();
}
writeln!(w, ") -> {} {{", mangled_container).unwrap();
write!(w, "\t{} {{ ", mangled_container).unwrap();
for idx in 0..types.len() {
write!(w, "{}, ", ('a' as u8 + idx as u8) as char).unwrap();
}
writeln!(w, "}}\n}}\n").unwrap();
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_free(_res: {}) {{ }}", mangled_container, mangled_container).unwrap();
}
/// Prints the docs from a given attribute list unless its tagged no export /// Prints the docs from a given attribute list unless its tagged no export
pub fn writeln_docs<W: std::io::Write>(w: &mut W, attrs: &[syn::Attribute], prefix: &str) { pub fn writeln_docs<W: std::io::Write>(w: &mut W, attrs: &[syn::Attribute], prefix: &str) {
for attr in attrs.iter() { for attr in attrs.iter() {

View file

@ -10,7 +10,7 @@
//! It also generates relevant memory-management functions and free-standing functions with //! It also generates relevant memory-management functions and free-standing functions with
//! parameters mapped. //! parameters mapped.
use std::collections::HashMap; use std::collections::{HashMap, HashSet};
use std::env; use std::env;
use std::fs::File; use std::fs::File;
use std::io::{Read, Write}; use std::io::{Read, Write};
@ -233,15 +233,20 @@ macro_rules! walk_supertraits { ($t: expr, $types: expr, ($( $pat: pat => $e: ex
} }
// First try to resolve path to find in-crate traits, but if that doesn't work // First try to resolve path to find in-crate traits, but if that doesn't work
// assume its a prelude trait (eg Clone, etc) and just use the single ident. // assume its a prelude trait (eg Clone, etc) and just use the single ident.
if let Some(path) = $types.maybe_resolve_path(&supertrait.path, None) { let types_opt: Option<&TypeResolver> = $types;
match (&path as &str, &supertrait.path.segments.iter().last().unwrap().ident) { if let Some(types) = types_opt {
$( $pat => $e, )* if let Some(path) = types.maybe_resolve_path(&supertrait.path, None) {
match (&path as &str, &supertrait.path.segments.iter().last().unwrap().ident) {
$( $pat => $e, )*
}
continue;
} }
} else if let Some(ident) = supertrait.path.get_ident() { }
if let Some(ident) = supertrait.path.get_ident() {
match (&format!("{}", ident) as &str, &ident) { match (&format!("{}", ident) as &str, &ident) {
$( $pat => $e, )* $( $pat => $e, )*
} }
} else { } else if types_opt.is_some() {
panic!("Supertrait unresolvable and not single-ident"); panic!("Supertrait unresolvable and not single-ident");
} }
}, },
@ -337,7 +342,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
} }
} }
// Add functions which may be required for supertrait implementations. // Add functions which may be required for supertrait implementations.
walk_supertraits!(t, types, ( walk_supertraits!(t, Some(&types), (
("Clone", _) => { ("Clone", _) => {
writeln!(w, "\tpub clone: Option<extern \"C\" fn (this_arg: *const c_void) -> *mut c_void>,").unwrap(); writeln!(w, "\tpub clone: Option<extern \"C\" fn (this_arg: *const c_void) -> *mut c_void>,").unwrap();
generated_fields.push("clone".to_owned()); generated_fields.push("clone".to_owned());
@ -368,7 +373,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
generated_fields.push("free".to_owned()); generated_fields.push("free".to_owned());
writeln!(w, "}}").unwrap(); writeln!(w, "}}").unwrap();
// Implement supertraits for the C-mapped struct. // Implement supertraits for the C-mapped struct.
walk_supertraits!(t, types, ( walk_supertraits!(t, Some(&types), (
("Send", _) => writeln!(w, "unsafe impl Send for {} {{}}", trait_name).unwrap(), ("Send", _) => writeln!(w, "unsafe impl Send for {} {{}}", trait_name).unwrap(),
("Sync", _) => writeln!(w, "unsafe impl Sync for {} {{}}", trait_name).unwrap(), ("Sync", _) => writeln!(w, "unsafe impl Sync for {} {{}}", trait_name).unwrap(),
("std::cmp::Eq", _) => { ("std::cmp::Eq", _) => {
@ -550,40 +555,23 @@ fn writeln_opaque<W: std::io::Write>(w: &mut W, ident: &syn::Ident, struct_name:
writeln!(w, "\t\tret").unwrap(); writeln!(w, "\t\tret").unwrap();
writeln!(w, "\t}}\n}}").unwrap(); writeln!(w, "\t}}\n}}").unwrap();
'attr_loop: for attr in attrs.iter() { if attrs_derives_clone(attrs) {
let tokens_clone = attr.tokens.clone(); writeln!(w, "impl Clone for {} {{", struct_name).unwrap();
let mut token_iter = tokens_clone.into_iter(); writeln!(w, "\tfn clone(&self) -> Self {{").unwrap();
if let Some(token) = token_iter.next() { writeln!(w, "\t\tSelf {{").unwrap();
match token { writeln!(w, "\t\t\tinner: if self.inner.is_null() {{ std::ptr::null_mut() }} else {{").unwrap();
TokenTree::Group(g) => { writeln!(w, "\t\t\t\tBox::into_raw(Box::new(unsafe {{ &*self.inner }}.clone())) }},").unwrap();
if format!("{}", single_ident_generic_path_to_ident(&attr.path).unwrap()) == "derive" { writeln!(w, "\t\t\tis_owned: true,").unwrap();
for id in g.stream().into_iter() { writeln!(w, "\t\t}}\n\t}}\n}}").unwrap();
if let TokenTree::Ident(i) = id { writeln!(w, "#[allow(unused)]").unwrap();
if i == "Clone" { writeln!(w, "/// Used only if an object of this type is returned as a trait impl by a method").unwrap();
writeln!(w, "impl Clone for {} {{", struct_name).unwrap(); writeln!(w, "pub(crate) extern \"C\" fn {}_clone_void(this_ptr: *const c_void) -> *mut c_void {{", struct_name).unwrap();
writeln!(w, "\tfn clone(&self) -> Self {{").unwrap(); writeln!(w, "\tBox::into_raw(Box::new(unsafe {{ (*(this_ptr as *mut native{})).clone() }})) as *mut c_void", struct_name).unwrap();
writeln!(w, "\t\tSelf {{").unwrap(); writeln!(w, "}}").unwrap();
writeln!(w, "\t\t\tinner: Box::into_raw(Box::new(unsafe {{ &*self.inner }}.clone())),").unwrap(); writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "\t\t\tis_owned: true,").unwrap(); writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", struct_name, struct_name, struct_name).unwrap();
writeln!(w, "\t\t}}\n\t}}\n}}").unwrap(); writeln!(w, "\torig.clone()").unwrap();
writeln!(w, "#[allow(unused)]").unwrap(); writeln!(w, "}}").unwrap();
writeln!(w, "/// Used only if an object of this type is returned as a trait impl by a method").unwrap();
writeln!(w, "pub(crate) extern \"C\" fn {}_clone_void(this_ptr: *const c_void) -> *mut c_void {{", struct_name).unwrap();
writeln!(w, "\tBox::into_raw(Box::new(unsafe {{ (*(this_ptr as *mut native{})).clone() }})) as *mut c_void", struct_name).unwrap();
writeln!(w, "}}").unwrap();
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", struct_name, struct_name, struct_name).unwrap();
writeln!(w, "\t{} {{ inner: Box::into_raw(Box::new(unsafe {{ &*orig.inner }}.clone())), is_owned: true }}", struct_name).unwrap();
writeln!(w, "}}").unwrap();
break 'attr_loop;
}
}
}
}
},
_ => {},
}
}
} }
write_cpp_wrapper(cpp_headers, &format!("{}", ident), true); write_cpp_wrapper(cpp_headers, &format!("{}", ident), true);
@ -832,7 +820,7 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
_ => {}, _ => {},
} }
} }
walk_supertraits!(trait_obj, types, ( walk_supertraits!(trait_obj, Some(&types), (
("Clone", _) => { ("Clone", _) => {
writeln!(w, "\t\tclone: Some({}_clone_void),", ident).unwrap(); writeln!(w, "\t\tclone: Some({}_clone_void),", ident).unwrap();
}, },
@ -930,7 +918,7 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
walk_supertraits!(trait_obj, types, ( walk_supertraits!(trait_obj, Some(&types), (
(s, t) => { (s, t) => {
if let Some(supertrait_obj) = types.crate_types.traits.get(s).cloned() { if let Some(supertrait_obj) = types.crate_types.traits.get(s).cloned() {
writeln!(w, "use {}::{} as native{}Trait;", types.orig_crate, s, t).unwrap(); writeln!(w, "use {}::{} as native{}Trait;", types.orig_crate, s, t).unwrap();
@ -1479,6 +1467,10 @@ fn walk_ast<'a>(in_dir: &str, path: &str, module: String, ast_storage: &'a FullL
ExportStatus::NoExport|ExportStatus::TestOnly => continue, ExportStatus::NoExport|ExportStatus::TestOnly => continue,
} }
let struct_path = format!("{}::{}", module, s.ident); let struct_path = format!("{}::{}", module, s.ident);
if attrs_derives_clone(&s.attrs) {
crate_types.clonable_types.insert("crate::".to_owned() + &struct_path);
}
crate_types.opaques.insert(struct_path, &s.ident); crate_types.opaques.insert(struct_path, &s.ident);
} }
}, },
@ -1489,6 +1481,12 @@ fn walk_ast<'a>(in_dir: &str, path: &str, module: String, ast_storage: &'a FullL
ExportStatus::NoExport|ExportStatus::TestOnly => continue, ExportStatus::NoExport|ExportStatus::TestOnly => continue,
} }
let trait_path = format!("{}::{}", module, t.ident); let trait_path = format!("{}::{}", module, t.ident);
walk_supertraits!(t, None, (
("Clone", _) => {
crate_types.clonable_types.insert("crate::".to_owned() + &trait_path);
},
(_, _) => {}
) );
crate_types.traits.insert(trait_path, &t); crate_types.traits.insert(trait_path, &t);
} }
}, },
@ -1524,6 +1522,9 @@ fn walk_ast<'a>(in_dir: &str, path: &str, module: String, ast_storage: &'a FullL
ExportStatus::NoExport|ExportStatus::TestOnly => continue, ExportStatus::NoExport|ExportStatus::TestOnly => continue,
} }
let enum_path = format!("{}::{}", module, e.ident); let enum_path = format!("{}::{}", module, e.ident);
if attrs_derives_clone(&e.attrs) {
crate_types.clonable_types.insert("crate::".to_owned() + &enum_path);
}
crate_types.opaques.insert(enum_path, &e.ident); crate_types.opaques.insert(enum_path, &e.ident);
} }
}, },
@ -1534,6 +1535,9 @@ fn walk_ast<'a>(in_dir: &str, path: &str, module: String, ast_storage: &'a FullL
ExportStatus::NoExport|ExportStatus::TestOnly => continue, ExportStatus::NoExport|ExportStatus::TestOnly => continue,
} }
let enum_path = format!("{}::{}", module, e.ident); let enum_path = format!("{}::{}", module, e.ident);
if attrs_derives_clone(&e.attrs) {
crate_types.clonable_types.insert("crate::".to_owned() + &enum_path);
}
crate_types.mirrored_enums.insert(enum_path, &e); crate_types.mirrored_enums.insert(enum_path, &e);
} }
}, },
@ -1578,7 +1582,8 @@ fn main() {
// ...then walk the ASTs tracking what types we will map, and how, so that we can resolve them // ...then walk the ASTs tracking what types we will map, and how, so that we can resolve them
// when parsing other file ASTs... // when parsing other file ASTs...
let mut libtypes = CrateTypes { traits: HashMap::new(), opaques: HashMap::new(), mirrored_enums: HashMap::new(), let mut libtypes = CrateTypes { traits: HashMap::new(), opaques: HashMap::new(), mirrored_enums: HashMap::new(),
type_aliases: HashMap::new(), templates_defined: HashMap::default(), template_file: &mut derived_templates }; type_aliases: HashMap::new(), templates_defined: HashMap::default(), template_file: &mut derived_templates,
clonable_types: HashSet::new() };
walk_ast(&args[1], "/lib.rs", "".to_string(), &libast, &mut libtypes); walk_ast(&args[1], "/lib.rs", "".to_string(), &libast, &mut libtypes);
// ... finally, do the actual file conversion/mapping, writing out types as we go. // ... finally, do the actual file conversion/mapping, writing out types as we go.

View file

@ -1,8 +1,10 @@
use std::collections::HashMap; use std::collections::{HashMap, HashSet};
use std::fs::File; use std::fs::File;
use std::io::Write; use std::io::Write;
use std::hash; use std::hash;
use crate::blocks::*;
use proc_macro2::{TokenTree, Span}; use proc_macro2::{TokenTree, Span};
// The following utils are used purely to build our known types maps - they break down all the // The following utils are used purely to build our known types maps - they break down all the
@ -39,6 +41,30 @@ pub fn single_ident_generic_path_to_ident(p: &syn::Path) -> Option<&syn::Ident>
} else { None } } else { None }
} }
pub fn attrs_derives_clone(attrs: &[syn::Attribute]) -> bool {
for attr in attrs.iter() {
let tokens_clone = attr.tokens.clone();
let mut token_iter = tokens_clone.into_iter();
if let Some(token) = token_iter.next() {
match token {
TokenTree::Group(g) => {
if format!("{}", single_ident_generic_path_to_ident(&attr.path).unwrap()) == "derive" {
for id in g.stream().into_iter() {
if let TokenTree::Ident(i) = id {
if i == "Clone" {
return true;
}
}
}
}
},
_ => {},
}
}
}
false
}
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum ExportStatus { pub enum ExportStatus {
Export, Export,
@ -293,6 +319,8 @@ pub struct CrateTypes<'a> {
/// The output file for any created template container types, written to as we find new /// The output file for any created template container types, written to as we find new
/// template containers which need to be defined. /// template containers which need to be defined.
pub template_file: &'a mut File, pub template_file: &'a mut File,
/// Set of containers which are clonable
pub clonable_types: HashSet<String>,
} }
/// A struct which tracks resolving rust types into C-mapped equivalents, exists for one specific /// A struct which tracks resolving rust types into C-mapped equivalents, exists for one specific
@ -368,6 +396,16 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
_ => false, _ => false,
} }
} }
pub fn is_clonable(&self, ty: &str) -> bool {
if self.crate_types.clonable_types.contains(ty) { return true; }
if self.is_primitive(ty) { return true; }
match ty {
"()" => true,
"crate::c_types::Signature" => true,
"crate::c_types::TxOut" => true,
_ => false,
}
}
/// Gets the C-mapped type for types which are outside of the crate, or which are manually /// Gets the C-mapped type for types which are outside of the crate, or which are manually
/// ignored by for some reason need mapping anyway. /// ignored by for some reason need mapping anyway.
fn c_type_from_path<'b>(&self, full_path: &'b str, is_ref: bool, ptr_for_ref: bool) -> Option<&'b str> { fn c_type_from_path<'b>(&self, full_path: &'b str, is_ref: bool, ptr_for_ref: bool) -> Option<&'b str> {
@ -753,8 +791,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
"Result" if !is_ref => { "Result" if !is_ref => {
Some(("match ", Some(("match ",
vec![(" { Ok(mut o) => crate::c_types::CResultTempl::ok(".to_string(), "o".to_string()), vec![(" { Ok(mut o) => crate::c_types::CResultTempl::ok(".to_string(), "o".to_string()),
("), Err(mut e) => crate::c_types::CResultTempl::err(".to_string(), "e".to_string())], (").into(), Err(mut e) => crate::c_types::CResultTempl::err(".to_string(), "e".to_string())],
") }")) ").into() }"))
}, },
"Vec" if !is_ref => { "Vec" if !is_ref => {
Some(("Vec::new(); for item in ", vec![(format!(".drain(..) {{ local_{}.push(", var_name), "item".to_string())], "); }")) Some(("Vec::new(); for item in ", vec![(format!(".drain(..) {{ local_{}.push(", var_name), "item".to_string())], "); }"))
@ -1720,153 +1758,90 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
// *** C Container Type Equivalent and alias Printing *** // *** C Container Type Equivalent and alias Printing ***
// ****************************************************** // ******************************************************
fn write_template_constructor<W: std::io::Write>(&mut self, w: &mut W, container_type: &str, mangled_container: &str, args: &Vec<&syn::Type>, generics: Option<&GenericTypes>, is_ref: bool) -> bool { fn write_template_generics<'b, W: std::io::Write>(&mut self, w: &mut W, args: &mut dyn Iterator<Item=&'b syn::Type>, generics: Option<&GenericTypes>, is_ref: bool) -> bool {
if container_type == "Result" { assert!(!is_ref); // We don't currently support outer reference types
assert_eq!(args.len(), 2);
macro_rules! write_fn {
($call: expr) => { {
writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_{}() -> {} {{", mangled_container, $call, mangled_container).unwrap();
writeln!(w, "\t{}::CResultTempl::{}(0)\n}}\n", Self::container_templ_path(), $call).unwrap();
} }
}
macro_rules! write_alias {
($call: expr, $item: expr) => { {
write!(w, "#[no_mangle]\npub static {}_{}: extern \"C\" fn (", mangled_container, $call).unwrap();
if let syn::Type::Path(syn::TypePath { path, .. }) = $item {
let resolved = self.resolve_path(path, generics);
if self.is_known_container(&resolved, is_ref) || self.is_transparent_container(&resolved, is_ref) {
self.write_c_mangled_container_path_intern(w, Self::path_to_generic_args(path), generics,
&format!("{}", single_ident_generic_path_to_ident(path).unwrap()), is_ref, false, false, false);
} else {
self.write_template_generics(w, &mut [$item].iter().map(|t| *t), generics, is_ref, true);
}
} else if let syn::Type::Tuple(syn::TypeTuple { elems, .. }) = $item {
self.write_c_mangled_container_path_intern(w, elems.iter().collect(), generics,
&format!("{}Tuple", elems.len()), is_ref, false, false, false);
} else { unimplemented!(); }
write!(w, ") -> {} =\n\t{}::CResultTempl::<", mangled_container, Self::container_templ_path()).unwrap();
self.write_template_generics(w, &mut args.iter().map(|t| *t), generics, is_ref, true);
writeln!(w, ">::{};\n", $call).unwrap();
} }
}
match args[0] {
syn::Type::Tuple(t) if t.elems.is_empty() => write_fn!("ok"),
_ => write_alias!("ok", args[0]),
}
match args[1] {
syn::Type::Tuple(t) if t.elems.is_empty() => write_fn!("err"),
_ => write_alias!("err", args[1]),
}
} else if container_type.ends_with("Tuple") {
write!(w, "#[no_mangle]\npub extern \"C\" fn {}_new(", mangled_container).unwrap();
for (idx, gen) in args.iter().enumerate() {
write!(w, "{}{}: ", if idx != 0 { ", " } else { "" }, ('a' as u8 + idx as u8) as char).unwrap();
if !self.write_c_type_intern(w, gen, None, false, false, false) { return false; }
}
writeln!(w, ") -> {} {{", mangled_container).unwrap();
write!(w, "\t{} {{ ", mangled_container).unwrap();
for idx in 0..args.len() {
write!(w, "{}, ", ('a' as u8 + idx as u8) as char).unwrap();
}
writeln!(w, "}}\n}}\n").unwrap();
} else {
writeln!(w, "").unwrap();
}
true
}
fn write_template_generics<'b, W: std::io::Write>(&self, w: &mut W, args: &mut dyn Iterator<Item=&'b syn::Type>, generics: Option<&GenericTypes>, is_ref: bool, in_crate: bool) {
for (idx, t) in args.enumerate() { for (idx, t) in args.enumerate() {
if idx != 0 { if idx != 0 {
write!(w, ", ").unwrap(); write!(w, ", ").unwrap();
} }
if let syn::Type::Tuple(tup) = t { if let syn::Type::Reference(r_arg) = t {
if tup.elems.is_empty() { if !self.write_c_type_intern(w, &*r_arg.elem, generics, false, false, false) { return false; }
write!(w, "u8").unwrap();
} else { // While write_c_type_intern, above is correct, we don't want to blindly convert a
write!(w, "{}::C{}TupleTempl<", Self::container_templ_path(), tup.elems.len()).unwrap(); // reference to something stupid, so check that the container is either opaque or a
self.write_template_generics(w, &mut tup.elems.iter(), generics, is_ref, in_crate); // predefined type (currently only Transaction).
write!(w, ">").unwrap();
}
} else if let syn::Type::Path(p_arg) = t {
let resolved_generic = self.resolve_path(&p_arg.path, generics);
if self.is_primitive(&resolved_generic) {
write!(w, "{}", resolved_generic).unwrap();
} else if let Some(c_type) = self.c_type_from_path(&resolved_generic, is_ref, false) {
if self.is_known_container(&resolved_generic, is_ref) {
write!(w, "{}::C{}Templ<", Self::container_templ_path(), single_ident_generic_path_to_ident(&p_arg.path).unwrap()).unwrap();
assert_eq!(p_arg.path.segments.len(), 1);
if let syn::PathArguments::AngleBracketed(args) = &p_arg.path.segments.iter().next().unwrap().arguments {
self.write_template_generics(w, &mut args.args.iter().map(|gen|
if let syn::GenericArgument::Type(t) = gen { t } else { unimplemented!() }),
generics, is_ref, in_crate);
} else { unimplemented!(); }
write!(w, ">").unwrap();
} else if resolved_generic == "Option" {
if let syn::PathArguments::AngleBracketed(args) = &p_arg.path.segments.iter().next().unwrap().arguments {
self.write_template_generics(w, &mut args.args.iter().map(|gen|
if let syn::GenericArgument::Type(t) = gen { t } else { unimplemented!() }),
generics, is_ref, in_crate);
} else { unimplemented!(); }
} else if in_crate {
write!(w, "{}", c_type).unwrap();
} else {
self.write_rust_type(w, generics, &t);
}
} else {
// If we just write out resolved_generic, it may mostly work, however for
// original types which are generic, we need the template args. We could
// figure them out and write them out, too, but its much easier to just
// reference the native{} type alias which exists at least for opaque types.
if in_crate {
write!(w, "crate::{}", resolved_generic).unwrap();
} else {
let path_name: Vec<&str> = resolved_generic.rsplitn(2, "::").collect();
if path_name.len() > 1 {
write!(w, "crate::{}::native{}", path_name[1], path_name[0]).unwrap();
} else {
write!(w, "crate::native{}", path_name[0]).unwrap();
}
}
}
} else if let syn::Type::Reference(r_arg) = t {
if let syn::Type::Path(p_arg) = &*r_arg.elem { if let syn::Type::Path(p_arg) = &*r_arg.elem {
let resolved = self.resolve_path(&p_arg.path, generics); let resolved = self.resolve_path(&p_arg.path, generics);
if self.crate_types.opaques.get(&resolved).is_some() { assert!(self.crate_types.opaques.get(&resolved).is_some() ||
write!(w, "crate::{}", resolved).unwrap(); self.c_type_from_path(&resolved, true, true).is_some(), "Template generics should be opaque or have a predefined mapping");
} else {
let cty = self.c_type_from_path(&resolved, true, true).expect("Template generics should be opaque or have a predefined mapping");
w.write(cty.as_bytes()).unwrap();
}
} else { unimplemented!(); } } else { unimplemented!(); }
} else if let syn::Type::Array(a_arg) = t { } else {
if let syn::Type::Path(p_arg) = &*a_arg.elem { if !self.write_c_type_intern(w, t, generics, false, false, false) { return false; }
let resolved = self.resolve_path(&p_arg.path, generics);
assert!(self.is_primitive(&resolved));
if let syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(len), .. }) = &a_arg.len {
write!(w, "{}",
self.c_type_from_path(&format!("[{}; {}]", resolved, len.base10_digits()), is_ref, false).unwrap()).unwrap();
}
}
} }
} }
true
} }
fn check_create_container(&mut self, mangled_container: String, container_type: &str, args: Vec<&syn::Type>, generics: Option<&GenericTypes>, is_ref: bool) -> bool { fn check_create_container(&mut self, mangled_container: String, container_type: &str, args: Vec<&syn::Type>, generics: Option<&GenericTypes>, is_ref: bool) -> bool {
if !self.crate_types.templates_defined.get(&mangled_container).is_some() { if !self.crate_types.templates_defined.get(&mangled_container).is_some() {
let mut created_container: Vec<u8> = Vec::new(); let mut created_container: Vec<u8> = Vec::new();
write!(&mut created_container, "pub type {} = ", mangled_container).unwrap(); if container_type == "Result" {
write!(&mut created_container, "{}::C{}Templ<", Self::container_templ_path(), container_type).unwrap(); let mut a_ty: Vec<u8> = Vec::new();
self.write_template_generics(&mut created_container, &mut args.iter().map(|t| *t), generics, is_ref, true); if let syn::Type::Tuple(tup) = args.iter().next().unwrap() {
writeln!(&mut created_container, ">;").unwrap(); if tup.elems.is_empty() {
write!(&mut a_ty, "()").unwrap();
} else {
if !self.write_template_generics(&mut a_ty, &mut args.iter().map(|t| *t).take(1), generics, is_ref) { return false; }
}
} else {
if !self.write_template_generics(&mut a_ty, &mut args.iter().map(|t| *t).take(1), generics, is_ref) { return false; }
}
write!(&mut created_container, "#[no_mangle]\npub static {}_free: extern \"C\" fn({}) = ", mangled_container, mangled_container).unwrap(); let mut b_ty: Vec<u8> = Vec::new();
write!(&mut created_container, "{}::C{}Templ_free::<", Self::container_templ_path(), container_type).unwrap(); if let syn::Type::Tuple(tup) = args.iter().skip(1).next().unwrap() {
self.write_template_generics(&mut created_container, &mut args.iter().map(|t| *t), generics, is_ref, true); if tup.elems.is_empty() {
writeln!(&mut created_container, ">;").unwrap(); write!(&mut b_ty, "()").unwrap();
} else {
if !self.write_template_generics(&mut b_ty, &mut args.iter().map(|t| *t).skip(1), generics, is_ref) { return false; }
}
} else {
if !self.write_template_generics(&mut b_ty, &mut args.iter().map(|t| *t).skip(1), generics, is_ref) { return false; }
}
if !self.write_template_constructor(&mut created_container, container_type, &mangled_container, &args, generics, is_ref) { let ok_str = String::from_utf8(a_ty).unwrap();
return false; let err_str = String::from_utf8(b_ty).unwrap();
let is_clonable = self.is_clonable(&ok_str) && self.is_clonable(&err_str);
write_result_block(&mut created_container, &mangled_container, &ok_str, &err_str, is_clonable);
if is_clonable {
self.crate_types.clonable_types.insert(Self::generated_container_path().to_owned() + "::" + &mangled_container);
}
} else if container_type == "Vec" {
let mut a_ty: Vec<u8> = Vec::new();
if !self.write_template_generics(&mut a_ty, &mut args.iter().map(|t| *t), generics, is_ref) { return false; }
let ty = String::from_utf8(a_ty).unwrap();
let is_clonable = self.is_clonable(&ty);
write_vec_block(&mut created_container, &mangled_container, &ty, is_clonable);
if is_clonable {
self.crate_types.clonable_types.insert(Self::generated_container_path().to_owned() + "::" + &mangled_container);
}
} else if container_type.ends_with("Tuple") {
let mut tuple_args = Vec::new();
let mut is_clonable = true;
for arg in args.iter() {
let mut ty: Vec<u8> = Vec::new();
if !self.write_template_generics(&mut ty, &mut [arg].iter().map(|t| **t), generics, is_ref) { return false; }
let ty_str = String::from_utf8(ty).unwrap();
if !self.is_clonable(&ty_str) {
is_clonable = false;
}
tuple_args.push(ty_str);
}
write_tuple_block(&mut created_container, &mangled_container, &tuple_args, is_clonable);
if is_clonable {
self.crate_types.clonable_types.insert(Self::generated_container_path().to_owned() + "::" + &mangled_container);
}
} else {
unreachable!();
} }
self.crate_types.templates_defined.insert(mangled_container.clone(), true); self.crate_types.templates_defined.insert(mangled_container.clone(), true);
@ -1965,7 +1940,6 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
} else if let syn::Type::Path(p_arg) = arg { } else if let syn::Type::Path(p_arg) = arg {
write_path!(p_arg, None); write_path!(p_arg, None);
} else if let syn::Type::Reference(refty) = arg { } else if let syn::Type::Reference(refty) = arg {
if args.len() != 1 { return false; }
if let syn::Type::Path(p_arg) = &*refty.elem { if let syn::Type::Path(p_arg) = &*refty.elem {
write_path!(p_arg, None); write_path!(p_arg, None);
} else if let syn::Type::Slice(_) = &*refty.elem { } else if let syn::Type::Slice(_) = &*refty.elem {
@ -1973,6 +1947,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
// make it a pointer so that its an option. Note that we cannot always convert // make it a pointer so that its an option. Note that we cannot always convert
// the Vec-as-slice (ie non-ref types) containers, so sometimes need to be able // the Vec-as-slice (ie non-ref types) containers, so sometimes need to be able
// to edit it, hence we use *mut here instead of *const. // to edit it, hence we use *mut here instead of *const.
if args.len() != 1 { return false; }
write!(w, "*mut ").unwrap(); write!(w, "*mut ").unwrap();
self.write_c_type(w, arg, None, true); self.write_c_type(w, arg, None, true);
} else { return false; } } else { return false; }

View file

@ -130,7 +130,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
msgs::DecodeError::InvalidValue => return, msgs::DecodeError::InvalidValue => return,
msgs::DecodeError::BadLengthDescriptor => return, msgs::DecodeError::BadLengthDescriptor => return,
msgs::DecodeError::ShortRead => panic!("We picked the length..."), msgs::DecodeError::ShortRead => panic!("We picked the length..."),
msgs::DecodeError::Io(e) => panic!(format!("{}", e)), msgs::DecodeError::Io(e) => panic!(format!("{:?}", e)),
} }
} }
}} }}

View file

@ -449,19 +449,19 @@ int main() {
std::this_thread::yield(); std::this_thread::yield();
} }
LDKCVec_C2Tuple_usizeTransactionZZ txdata { .data = (LDKC2TupleTempl_usize__Transaction*)malloc(sizeof(LDKC2Tuple_usizeTransactionZ)), .datalen = 1 }; LDKCVec_C2Tuple_usizeTransactionZZ txdata { .data = (LDKC2Tuple_usizeTransactionZ*)malloc(sizeof(LDKC2Tuple_usizeTransactionZ)), .datalen = 1 };
*txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_tx, .datalen = sizeof(channel_open_tx), .data_is_owned = false }); *txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_tx, .datalen = sizeof(channel_open_tx), .data_is_owned = false });
ChannelManager_block_connected(&cm1, &channel_open_header, txdata, 1); ChannelManager_block_connected(&cm1, &channel_open_header, txdata, 1);
txdata = LDKCVec_C2Tuple_usizeTransactionZZ { .data = (LDKC2TupleTempl_usize__Transaction*)malloc(sizeof(LDKC2Tuple_usizeTransactionZ)), .datalen = 1 }; txdata = LDKCVec_C2Tuple_usizeTransactionZZ { .data = (LDKC2Tuple_usizeTransactionZ*)malloc(sizeof(LDKC2Tuple_usizeTransactionZ)), .datalen = 1 };
*txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_tx, .datalen = sizeof(channel_open_tx), .data_is_owned = false }); *txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_tx, .datalen = sizeof(channel_open_tx), .data_is_owned = false });
ChannelManager_block_connected(&cm2, &channel_open_header, txdata, 1); ChannelManager_block_connected(&cm2, &channel_open_header, txdata, 1);
txdata = LDKCVec_C2Tuple_usizeTransactionZZ { .data = (LDKC2TupleTempl_usize__Transaction*)malloc(sizeof(LDKC2Tuple_usizeTransactionZ)), .datalen = 1 }; txdata = LDKCVec_C2Tuple_usizeTransactionZZ { .data = (LDKC2Tuple_usizeTransactionZ*)malloc(sizeof(LDKC2Tuple_usizeTransactionZ)), .datalen = 1 };
*txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_tx, .datalen = sizeof(channel_open_tx), .data_is_owned = false }); *txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_tx, .datalen = sizeof(channel_open_tx), .data_is_owned = false });
mons1.ConnectBlock(&channel_open_header, 1, txdata, broadcast, fee_est); mons1.ConnectBlock(&channel_open_header, 1, txdata, broadcast, fee_est);
txdata = LDKCVec_C2Tuple_usizeTransactionZZ { .data = (LDKC2TupleTempl_usize__Transaction*)malloc(sizeof(LDKC2Tuple_usizeTransactionZ)), .datalen = 1 }; txdata = LDKCVec_C2Tuple_usizeTransactionZZ { .data = (LDKC2Tuple_usizeTransactionZ*)malloc(sizeof(LDKC2Tuple_usizeTransactionZ)), .datalen = 1 };
*txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_tx, .datalen = sizeof(channel_open_tx), .data_is_owned = false }); *txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_tx, .datalen = sizeof(channel_open_tx), .data_is_owned = false });
mons2.ConnectBlock(&channel_open_header, 1, txdata, broadcast, fee_est); mons2.ConnectBlock(&channel_open_header, 1, txdata, broadcast, fee_est);

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -45,6 +45,7 @@ impl SecretKey {
} }
#[repr(C)] #[repr(C)]
#[derive(Clone)]
pub struct Signature { pub struct Signature {
pub compact_form: [u8; 64], pub compact_form: [u8; 64],
} }
@ -127,7 +128,7 @@ impl Transaction {
impl Drop for Transaction { impl Drop for Transaction {
fn drop(&mut self) { fn drop(&mut self) {
if self.data_is_owned && self.datalen != 0 { if self.data_is_owned && self.datalen != 0 {
let _ = CVecTempl { data: self.data as *mut u8, datalen: self.datalen }; let _ = derived::CVec_u8Z { data: self.data as *mut u8, datalen: self.datalen };
} }
} }
} }
@ -156,13 +157,15 @@ impl TxOut {
} }
pub(crate) fn from_rust(txout: ::bitcoin::blockdata::transaction::TxOut) -> Self { pub(crate) fn from_rust(txout: ::bitcoin::blockdata::transaction::TxOut) -> Self {
Self { Self {
script_pubkey: CVecTempl::from(txout.script_pubkey.into_bytes()), script_pubkey: derived::CVec_u8Z::from(txout.script_pubkey.into_bytes()),
value: txout.value value: txout.value
} }
} }
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn TxOut_free(_res: TxOut) { } pub extern "C" fn TxOut_free(_res: TxOut) { }
#[no_mangle]
pub extern "C" fn TxOut_clone(orig: &TxOut) -> TxOut { orig.clone() }
#[repr(C)] #[repr(C)]
pub struct u8slice { pub struct u8slice {
@ -220,7 +223,7 @@ impl lightning::util::ser::Writer for VecWriter {
pub(crate) fn serialize_obj<I: lightning::util::ser::Writeable>(i: &I) -> derived::CVec_u8Z { pub(crate) fn serialize_obj<I: lightning::util::ser::Writeable>(i: &I) -> derived::CVec_u8Z {
let mut out = VecWriter(Vec::new()); let mut out = VecWriter(Vec::new());
i.write(&mut out).unwrap(); i.write(&mut out).unwrap();
CVecTempl::from(out.0) derived::CVec_u8Z::from(out.0)
} }
pub(crate) fn deserialize_obj<I: lightning::util::ser::Readable>(s: u8slice) -> Result<I, lightning::ln::msgs::DecodeError> { pub(crate) fn deserialize_obj<I: lightning::util::ser::Readable>(s: u8slice) -> Result<I, lightning::ln::msgs::DecodeError> {
I::read(&mut s.to_slice()) I::read(&mut s.to_slice())
@ -256,14 +259,14 @@ impl Into<&'static str> for Str {
// everywhere in the containers. // everywhere in the containers.
#[repr(C)] #[repr(C)]
pub union CResultPtr<O, E> { pub(crate) union CResultPtr<O, E> {
pub result: *mut O, pub(crate) result: *mut O,
pub err: *mut E, pub(crate) err: *mut E,
} }
#[repr(C)] #[repr(C)]
pub struct CResultTempl<O, E> { pub(crate) struct CResultTempl<O, E> {
pub contents: CResultPtr<O, E>, pub(crate) contents: CResultPtr<O, E>,
pub result_ok: bool, pub(crate) result_ok: bool,
} }
impl<O, E> CResultTempl<O, E> { impl<O, E> CResultTempl<O, E> {
pub(crate) extern "C" fn ok(o: O) -> Self { pub(crate) extern "C" fn ok(o: O) -> Self {
@ -283,7 +286,6 @@ impl<O, E> CResultTempl<O, E> {
} }
} }
} }
pub extern "C" fn CResultTempl_free<O, E>(_res: CResultTempl<O, E>) { }
impl<O, E> Drop for CResultTempl<O, E> { impl<O, E> Drop for CResultTempl<O, E> {
fn drop(&mut self) { fn drop(&mut self) {
if self.result_ok { if self.result_ok {
@ -296,96 +298,6 @@ impl<O, E> Drop for CResultTempl<O, E> {
} }
} }
#[repr(C)]
pub struct CVecTempl<T> {
pub data: *mut T,
pub datalen: usize
}
impl<T> CVecTempl<T> {
pub(crate) fn into_rust(&mut self) -> Vec<T> {
if self.datalen == 0 { return Vec::new(); }
let ret = unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }.into();
self.data = std::ptr::null_mut();
self.datalen = 0;
ret
}
pub(crate) fn as_slice(&self) -> &[T] {
unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) }
}
}
impl<T> From<Vec<T>> for CVecTempl<T> {
fn from(v: Vec<T>) -> Self {
let datalen = v.len();
let data = Box::into_raw(v.into_boxed_slice());
CVecTempl { datalen, data: unsafe { (*data).as_mut_ptr() } }
}
}
pub extern "C" fn CVecTempl_free<T>(_res: CVecTempl<T>) { }
impl<T> Drop for CVecTempl<T> {
fn drop(&mut self) {
if self.datalen == 0 { return; }
unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) };
}
}
impl<T: Clone> Clone for CVecTempl<T> {
fn clone(&self) -> Self {
let mut res = Vec::new();
if self.datalen == 0 { return Self::from(res); }
res.extend_from_slice(unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) });
Self::from(res)
}
}
#[repr(C)]
pub struct C2TupleTempl<A, B> {
pub a: A,
pub b: B,
}
impl<A, B> From<(A, B)> for C2TupleTempl<A, B> {
fn from(tup: (A, B)) -> Self {
Self {
a: tup.0,
b: tup.1,
}
}
}
impl<A, B> C2TupleTempl<A, B> {
pub(crate) fn to_rust(mut self) -> (A, B) {
(self.a, self.b)
}
}
pub extern "C" fn C2TupleTempl_free<A, B>(_res: C2TupleTempl<A, B>) { }
impl <A: Clone, B: Clone> Clone for C2TupleTempl<A, B> {
fn clone(&self) -> Self {
Self {
a: self.a.clone(),
b: self.b.clone()
}
}
}
#[repr(C)]
pub struct C3TupleTempl<A, B, C> {
pub a: A,
pub b: B,
pub c: C,
}
impl<A, B, C> From<(A, B, C)> for C3TupleTempl<A, B, C> {
fn from(tup: (A, B, C)) -> Self {
Self {
a: tup.0,
b: tup.1,
c: tup.2,
}
}
}
impl<A, B, C> C3TupleTempl<A, B, C> {
pub(crate) fn to_rust(mut self) -> (A, B, C) {
(self.a, self.b, self.c)
}
}
pub extern "C" fn C3TupleTempl_free<A, B, C>(_res: C3TupleTempl<A, B, C>) { }
/// Utility to make it easy to set a pointer to null and get its original value in line. /// Utility to make it easy to set a pointer to null and get its original value in line.
pub(crate) trait TakePointer<T> { pub(crate) trait TakePointer<T> {
fn take_ptr(&mut self) -> T; fn take_ptr(&mut self) -> T;

View file

@ -141,13 +141,13 @@ use lightning::chain::Watch as WatchTraitImport;
#[must_use] #[must_use]
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 { 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 {
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()) }); 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()) });
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) }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() };
local_ret local_ret
} }
#[must_use] #[must_use]
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 { 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 {
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()) }); 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()) });
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) }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() };
local_ret local_ret
} }
#[must_use] #[must_use]

View file

@ -59,7 +59,8 @@ impl ChannelMonitorUpdate {
impl Clone for ChannelMonitorUpdate { impl Clone for ChannelMonitorUpdate {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -71,7 +72,7 @@ pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate { pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate {
ChannelMonitorUpdate { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The sequence number of this update. Updates *must* be replayed in-order according to this /// The sequence number of this update. Updates *must* be replayed in-order according to this
/// sequence number (and updates may panic if they are not). The update_id values are strictly /// sequence number (and updates may panic if they are not). The update_id values are strictly
@ -122,7 +123,7 @@ pub(crate) extern "C" fn ChannelMonitorUpdate_write_void(obj: *const c_void) ->
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelMonitorUpdateDecodeErrorZ { pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelMonitorUpdateDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::chain::channelmonitor::ChannelMonitorUpdate { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::chain::channelmonitor::ChannelMonitorUpdate { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
/// An error enum representing a failure to persist a channel monitor update. /// An error enum representing a failure to persist a channel monitor update.
@ -264,6 +265,24 @@ impl MonitorUpdateError {
ret ret
} }
} }
impl Clone for MonitorUpdateError {
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 MonitorUpdateError_clone_void(this_ptr: *const c_void) -> *mut c_void {
Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMonitorUpdateError)).clone() })) as *mut c_void
}
#[no_mangle]
pub extern "C" fn MonitorUpdateError_clone(orig: &MonitorUpdateError) -> MonitorUpdateError {
orig.clone()
}
use lightning::chain::channelmonitor::MonitorEvent as nativeMonitorEventImport; use lightning::chain::channelmonitor::MonitorEvent as nativeMonitorEventImport;
type nativeMonitorEvent = nativeMonitorEventImport; type nativeMonitorEvent = nativeMonitorEventImport;
@ -305,7 +324,8 @@ impl MonitorEvent {
impl Clone for MonitorEvent { impl Clone for MonitorEvent {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -317,7 +337,7 @@ pub(crate) extern "C" fn MonitorEvent_clone_void(this_ptr: *const c_void) -> *mu
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent { pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent {
MonitorEvent { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport; use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
@ -364,7 +384,8 @@ impl HTLCUpdate {
impl Clone for HTLCUpdate { impl Clone for HTLCUpdate {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -376,7 +397,7 @@ pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate { pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate {
HTLCUpdate { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn HTLCUpdate_write(obj: &HTLCUpdate) -> crate::c_types::derived::CVec_u8Z { pub extern "C" fn HTLCUpdate_write(obj: &HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {
@ -463,7 +484,7 @@ pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate:
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelMonitor_update_monitor(this_arg: &mut ChannelMonitor, updates: &crate::chain::channelmonitor::ChannelMonitorUpdate, broadcaster: &crate::chain::chaininterface::BroadcasterInterface, fee_estimator: &crate::chain::chaininterface::FeeEstimator, logger: &crate::util::logger::Logger) -> crate::c_types::derived::CResult_NoneMonitorUpdateErrorZ { pub extern "C" fn ChannelMonitor_update_monitor(this_arg: &mut ChannelMonitor, updates: &crate::chain::channelmonitor::ChannelMonitorUpdate, broadcaster: &crate::chain::chaininterface::BroadcasterInterface, fee_estimator: &crate::chain::chaininterface::FeeEstimator, logger: &crate::util::logger::Logger) -> crate::c_types::derived::CResult_NoneMonitorUpdateErrorZ {
let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChannelMonitor)) }.update_monitor(unsafe { &*updates.inner }, broadcaster, fee_estimator, logger); let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChannelMonitor)) }.update_monitor(unsafe { &*updates.inner }, broadcaster, fee_estimator, logger);
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::MonitorUpdateError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::chain::channelmonitor::MonitorUpdateError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
@ -652,6 +673,6 @@ impl Drop for Persist {
pub extern "C" fn C2Tuple_BlockHashChannelMonitorZ_read(ser: crate::c_types::u8slice, arg: &crate::chain::keysinterface::KeysInterface) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { pub extern "C" fn C2Tuple_BlockHashChannelMonitorZ_read(ser: crate::c_types::u8slice, arg: &crate::chain::keysinterface::KeysInterface) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ {
let arg_conv = arg; let arg_conv = arg;
let res: Result<(bitcoin::hash_types::BlockHash, lightning::chain::channelmonitor::ChannelMonitor<crate::chain::keysinterface::ChannelKeys>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv); let res: Result<(bitcoin::hash_types::BlockHash, lightning::chain::channelmonitor::ChannelMonitor<crate::chain::keysinterface::ChannelKeys>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_res_0_0, mut orig_res_0_1) = o; let mut local_res_0 = (crate::c_types::ThirtyTwoBytes { data: orig_res_0_0.into_inner() }, crate::chain::channelmonitor::ChannelMonitor { inner: Box::into_raw(Box::new(orig_res_0_1)), is_owned: true }).into(); local_res_0 }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_res_0_0, mut orig_res_0_1) = o; let mut local_res_0 = (crate::c_types::ThirtyTwoBytes { data: orig_res_0_0.into_inner() }, crate::chain::channelmonitor::ChannelMonitor { inner: Box::into_raw(Box::new(orig_res_0_1)), is_owned: true }).into(); local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }

View file

@ -231,7 +231,7 @@ pub extern "C" fn SpendableOutputDescriptor_write(obj: &SpendableOutputDescripto
#[no_mangle] #[no_mangle]
pub extern "C" fn SpendableOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpendableOutputDescriptorDecodeErrorZ { pub extern "C" fn SpendableOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpendableOutputDescriptorDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::chain::keysinterface::SpendableOutputDescriptor::native_into(o) }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::chain::keysinterface::SpendableOutputDescriptor::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
/// Set of lightning keys needed to operate a channel as described in BOLT 3. /// Set of lightning keys needed to operate a channel as described in BOLT 3.
@ -612,7 +612,8 @@ impl InMemoryChannelKeys {
impl Clone for InMemoryChannelKeys { impl Clone for InMemoryChannelKeys {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -624,7 +625,7 @@ pub(crate) extern "C" fn InMemoryChannelKeys_clone_void(this_ptr: *const c_void)
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn InMemoryChannelKeys_clone(orig: &InMemoryChannelKeys) -> InMemoryChannelKeys { pub extern "C" fn InMemoryChannelKeys_clone(orig: &InMemoryChannelKeys) -> InMemoryChannelKeys {
InMemoryChannelKeys { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// Private key of anchor tx /// Private key of anchor tx
#[no_mangle] #[no_mangle]
@ -825,38 +826,38 @@ extern "C" fn InMemoryChannelKeys_ChannelKeys_key_derivation_params(this_arg: *c
#[must_use] #[must_use]
extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_counterparty_commitment(this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::CommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_counterparty_commitment(this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::CommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ {
let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_counterparty_commitment(unsafe { &*commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new()); let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_counterparty_commitment(unsafe { &*commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_orig_ret_0_1 = Vec::new(); for item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::c_types::Signature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::Signature::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_orig_ret_0_1 = Vec::new(); for item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::c_types::Signature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::Signature::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }).into() };
local_ret local_ret
} }
#[must_use] #[must_use]
extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_holder_commitment_and_htlcs(this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_holder_commitment_and_htlcs(this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ {
let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_holder_commitment_and_htlcs(unsafe { &*commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new()); let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_holder_commitment_and_htlcs(unsafe { &*commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_orig_ret_0_1 = Vec::new(); for item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::c_types::Signature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::Signature::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_orig_ret_0_1 = Vec::new(); for item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::c_types::Signature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::Signature::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }).into() };
local_ret local_ret
} }
#[must_use] #[must_use]
extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_justice_transaction(this_arg: *const c_void, mut justice_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, per_commitment_key: *const [u8; 32], htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ { extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_justice_transaction(this_arg: *const c_void, mut justice_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, per_commitment_key: *const [u8; 32], htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ {
let mut local_htlc = if htlc.inner.is_null() { None } else { Some((* { unsafe { &*htlc.inner } }).clone()) }; let mut local_htlc = if htlc.inner.is_null() { None } else { Some((* { unsafe { &*htlc.inner } }).clone()) };
let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_justice_transaction(&justice_tx.into_bitcoin(), input, amount, &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *per_commitment_key}[..]).unwrap(), &local_htlc, &bitcoin::secp256k1::Secp256k1::new()); let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_justice_transaction(&justice_tx.into_bitcoin(), input, amount, &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *per_commitment_key}[..]).unwrap(), &local_htlc, &bitcoin::secp256k1::Secp256k1::new());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }).into() };
local_ret local_ret
} }
#[must_use] #[must_use]
extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_counterparty_htlc_transaction(this_arg: *const c_void, mut htlc_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, mut per_commitment_point: crate::c_types::PublicKey, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ { extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_counterparty_htlc_transaction(this_arg: *const c_void, mut htlc_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, mut per_commitment_point: crate::c_types::PublicKey, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ {
let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_counterparty_htlc_transaction(&htlc_tx.into_bitcoin(), input, amount, &per_commitment_point.into_rust(), unsafe { &*htlc.inner }, &bitcoin::secp256k1::Secp256k1::new()); let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_counterparty_htlc_transaction(&htlc_tx.into_bitcoin(), input, amount, &per_commitment_point.into_rust(), unsafe { &*htlc.inner }, &bitcoin::secp256k1::Secp256k1::new());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }).into() };
local_ret local_ret
} }
#[must_use] #[must_use]
extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_closing_transaction(this_arg: *const c_void, mut closing_tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_SignatureNoneZ { extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_closing_transaction(this_arg: *const c_void, mut closing_tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_SignatureNoneZ {
let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_closing_transaction(&closing_tx.into_bitcoin(), &bitcoin::secp256k1::Secp256k1::new()); let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_closing_transaction(&closing_tx.into_bitcoin(), &bitcoin::secp256k1::Secp256k1::new());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }).into() };
local_ret local_ret
} }
#[must_use] #[must_use]
extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_channel_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_SignatureNoneZ { extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_channel_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_SignatureNoneZ {
let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_channel_announcement(unsafe { &*msg.inner }, &bitcoin::secp256k1::Secp256k1::new()); let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_channel_announcement(unsafe { &*msg.inner }, &bitcoin::secp256k1::Secp256k1::new());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }).into() };
local_ret local_ret
} }
extern "C" fn InMemoryChannelKeys_ChannelKeys_ready_channel(this_arg: *mut c_void, channel_parameters: &crate::ln::chan_utils::ChannelTransactionParameters) { extern "C" fn InMemoryChannelKeys_ChannelKeys_ready_channel(this_arg: *mut c_void, channel_parameters: &crate::ln::chan_utils::ChannelTransactionParameters) {
@ -874,7 +875,7 @@ pub(crate) extern "C" fn InMemoryChannelKeys_write_void(obj: *const c_void) -> c
#[no_mangle] #[no_mangle]
pub extern "C" fn InMemoryChannelKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InMemoryChannelKeysDecodeErrorZ { pub extern "C" fn InMemoryChannelKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InMemoryChannelKeysDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::chain::keysinterface::InMemoryChannelKeys { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::chain::keysinterface::InMemoryChannelKeys { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
@ -1011,7 +1012,7 @@ extern "C" fn KeysManager_KeysInterface_get_secure_random_bytes(this_arg: *const
#[must_use] #[must_use]
extern "C" fn KeysManager_KeysInterface_read_chan_signer(this_arg: *const c_void, mut reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChanKeySignerDecodeErrorZ { extern "C" fn KeysManager_KeysInterface_read_chan_signer(this_arg: *const c_void, mut reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChanKeySignerDecodeErrorZ {
let mut ret = unsafe { &mut *(this_arg as *mut nativeKeysManager) }.read_chan_signer(reader.to_slice()); let mut ret = unsafe { &mut *(this_arg as *mut nativeKeysManager) }.read_chan_signer(reader.to_slice());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o.into() }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }

View file

@ -48,7 +48,8 @@ impl OutPoint {
impl Clone for OutPoint { impl Clone for OutPoint {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -60,7 +61,7 @@ pub(crate) extern "C" fn OutPoint_clone_void(this_ptr: *const c_void) -> *mut c_
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn OutPoint_clone(orig: &OutPoint) -> OutPoint { pub extern "C" fn OutPoint_clone(orig: &OutPoint) -> OutPoint {
OutPoint { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The referenced transaction's txid. /// The referenced transaction's txid.
#[no_mangle] #[no_mangle]

View file

@ -21,7 +21,7 @@ pub extern "C" fn build_commitment_secret(commitment_seed: *const [u8; 32], mut
#[no_mangle] #[no_mangle]
pub extern "C" fn derive_private_key(mut per_commitment_point: crate::c_types::PublicKey, base_secret: *const [u8; 32]) -> crate::c_types::derived::CResult_SecretKeySecpErrorZ { pub extern "C" fn derive_private_key(mut per_commitment_point: crate::c_types::PublicKey, base_secret: *const [u8; 32]) -> crate::c_types::derived::CResult_SecretKeySecpErrorZ {
let mut ret = lightning::ln::chan_utils::derive_private_key(&bitcoin::secp256k1::Secp256k1::new(), &per_commitment_point.into_rust(), &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *base_secret}[..]).unwrap()); let mut ret = lightning::ln::chan_utils::derive_private_key(&bitcoin::secp256k1::Secp256k1::new(), &per_commitment_point.into_rust(), &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *base_secret}[..]).unwrap());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SecretKey::from_rust(o) }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SecretKey::from_rust(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
local_ret local_ret
} }
@ -34,7 +34,7 @@ pub extern "C" fn derive_private_key(mut per_commitment_point: crate::c_types::P
#[no_mangle] #[no_mangle]
pub extern "C" fn derive_public_key(mut per_commitment_point: crate::c_types::PublicKey, mut base_point: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_PublicKeySecpErrorZ { pub extern "C" fn derive_public_key(mut per_commitment_point: crate::c_types::PublicKey, mut base_point: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_PublicKeySecpErrorZ {
let mut ret = lightning::ln::chan_utils::derive_public_key(&bitcoin::secp256k1::Secp256k1::new(), &per_commitment_point.into_rust(), &base_point.into_rust()); let mut ret = lightning::ln::chan_utils::derive_public_key(&bitcoin::secp256k1::Secp256k1::new(), &per_commitment_point.into_rust(), &base_point.into_rust());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
local_ret local_ret
} }
@ -50,7 +50,7 @@ pub extern "C" fn derive_public_key(mut per_commitment_point: crate::c_types::Pu
#[no_mangle] #[no_mangle]
pub extern "C" fn derive_private_revocation_key(per_commitment_secret: *const [u8; 32], countersignatory_revocation_base_secret: *const [u8; 32]) -> crate::c_types::derived::CResult_SecretKeySecpErrorZ { pub extern "C" fn derive_private_revocation_key(per_commitment_secret: *const [u8; 32], countersignatory_revocation_base_secret: *const [u8; 32]) -> crate::c_types::derived::CResult_SecretKeySecpErrorZ {
let mut ret = lightning::ln::chan_utils::derive_private_revocation_key(&bitcoin::secp256k1::Secp256k1::new(), &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *per_commitment_secret}[..]).unwrap(), &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *countersignatory_revocation_base_secret}[..]).unwrap()); let mut ret = lightning::ln::chan_utils::derive_private_revocation_key(&bitcoin::secp256k1::Secp256k1::new(), &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *per_commitment_secret}[..]).unwrap(), &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *countersignatory_revocation_base_secret}[..]).unwrap());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SecretKey::from_rust(o) }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SecretKey::from_rust(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
local_ret local_ret
} }
@ -68,7 +68,7 @@ pub extern "C" fn derive_private_revocation_key(per_commitment_secret: *const [u
#[no_mangle] #[no_mangle]
pub extern "C" fn derive_public_revocation_key(mut per_commitment_point: crate::c_types::PublicKey, mut countersignatory_revocation_base_point: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_PublicKeySecpErrorZ { pub extern "C" fn derive_public_revocation_key(mut per_commitment_point: crate::c_types::PublicKey, mut countersignatory_revocation_base_point: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_PublicKeySecpErrorZ {
let mut ret = lightning::ln::chan_utils::derive_public_revocation_key(&bitcoin::secp256k1::Secp256k1::new(), &per_commitment_point.into_rust(), &countersignatory_revocation_base_point.into_rust()); let mut ret = lightning::ln::chan_utils::derive_public_revocation_key(&bitcoin::secp256k1::Secp256k1::new(), &per_commitment_point.into_rust(), &countersignatory_revocation_base_point.into_rust());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
local_ret local_ret
} }
@ -123,7 +123,8 @@ impl TxCreationKeys {
impl Clone for TxCreationKeys { impl Clone for TxCreationKeys {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -135,7 +136,7 @@ pub(crate) extern "C" fn TxCreationKeys_clone_void(this_ptr: *const c_void) -> *
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn TxCreationKeys_clone(orig: &TxCreationKeys) -> TxCreationKeys { pub extern "C" fn TxCreationKeys_clone(orig: &TxCreationKeys) -> TxCreationKeys {
TxCreationKeys { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The broadcaster's per-commitment public key which was used to derive the other keys. /// The broadcaster's per-commitment public key which was used to derive the other keys.
#[no_mangle] #[no_mangle]
@ -264,7 +265,8 @@ impl ChannelPublicKeys {
impl Clone for ChannelPublicKeys { impl Clone for ChannelPublicKeys {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -276,7 +278,7 @@ pub(crate) extern "C" fn ChannelPublicKeys_clone_void(this_ptr: *const c_void) -
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelPublicKeys_clone(orig: &ChannelPublicKeys) -> ChannelPublicKeys { pub extern "C" fn ChannelPublicKeys_clone(orig: &ChannelPublicKeys) -> ChannelPublicKeys {
ChannelPublicKeys { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The public key which is used to sign all commitment transactions, as it appears in the /// The public key which is used to sign all commitment transactions, as it appears in the
/// on-chain channel lock-in 2-of-2 multisig output. /// on-chain channel lock-in 2-of-2 multisig output.
@ -384,7 +386,7 @@ pub extern "C" fn ChannelPublicKeys_read(ser: crate::c_types::u8slice) -> Channe
#[no_mangle] #[no_mangle]
pub extern "C" fn TxCreationKeys_derive_new(mut per_commitment_point: crate::c_types::PublicKey, mut broadcaster_delayed_payment_base: crate::c_types::PublicKey, mut broadcaster_htlc_base: crate::c_types::PublicKey, mut countersignatory_revocation_base: crate::c_types::PublicKey, mut countersignatory_htlc_base: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_TxCreationKeysSecpErrorZ { pub extern "C" fn TxCreationKeys_derive_new(mut per_commitment_point: crate::c_types::PublicKey, mut broadcaster_delayed_payment_base: crate::c_types::PublicKey, mut broadcaster_htlc_base: crate::c_types::PublicKey, mut countersignatory_revocation_base: crate::c_types::PublicKey, mut countersignatory_htlc_base: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_TxCreationKeysSecpErrorZ {
let mut ret = lightning::ln::chan_utils::TxCreationKeys::derive_new(&bitcoin::secp256k1::Secp256k1::new(), &per_commitment_point.into_rust(), &broadcaster_delayed_payment_base.into_rust(), &broadcaster_htlc_base.into_rust(), &countersignatory_revocation_base.into_rust(), &countersignatory_htlc_base.into_rust()); let mut ret = lightning::ln::chan_utils::TxCreationKeys::derive_new(&bitcoin::secp256k1::Secp256k1::new(), &per_commitment_point.into_rust(), &broadcaster_delayed_payment_base.into_rust(), &broadcaster_htlc_base.into_rust(), &countersignatory_revocation_base.into_rust(), &countersignatory_htlc_base.into_rust());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::TxCreationKeys { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::TxCreationKeys { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
local_ret local_ret
} }
@ -394,7 +396,7 @@ pub extern "C" fn TxCreationKeys_derive_new(mut per_commitment_point: crate::c_t
#[no_mangle] #[no_mangle]
pub extern "C" fn TxCreationKeys_from_channel_static_keys(mut per_commitment_point: crate::c_types::PublicKey, broadcaster_keys: &crate::ln::chan_utils::ChannelPublicKeys, countersignatory_keys: &crate::ln::chan_utils::ChannelPublicKeys) -> crate::c_types::derived::CResult_TxCreationKeysSecpErrorZ { pub extern "C" fn TxCreationKeys_from_channel_static_keys(mut per_commitment_point: crate::c_types::PublicKey, broadcaster_keys: &crate::ln::chan_utils::ChannelPublicKeys, countersignatory_keys: &crate::ln::chan_utils::ChannelPublicKeys) -> crate::c_types::derived::CResult_TxCreationKeysSecpErrorZ {
let mut ret = lightning::ln::chan_utils::TxCreationKeys::from_channel_static_keys(&per_commitment_point.into_rust(), unsafe { &*broadcaster_keys.inner }, unsafe { &*countersignatory_keys.inner }, &bitcoin::secp256k1::Secp256k1::new()); let mut ret = lightning::ln::chan_utils::TxCreationKeys::from_channel_static_keys(&per_commitment_point.into_rust(), unsafe { &*broadcaster_keys.inner }, unsafe { &*countersignatory_keys.inner }, &bitcoin::secp256k1::Secp256k1::new());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::TxCreationKeys { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::TxCreationKeys { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
local_ret local_ret
} }
@ -448,7 +450,8 @@ impl HTLCOutputInCommitment {
impl Clone for HTLCOutputInCommitment { impl Clone for HTLCOutputInCommitment {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -460,7 +463,7 @@ pub(crate) extern "C" fn HTLCOutputInCommitment_clone_void(this_ptr: *const c_vo
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn HTLCOutputInCommitment_clone(orig: &HTLCOutputInCommitment) -> HTLCOutputInCommitment { pub extern "C" fn HTLCOutputInCommitment_clone(orig: &HTLCOutputInCommitment) -> HTLCOutputInCommitment {
HTLCOutputInCommitment { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction). /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
/// Note that this is not the same as whether it is ountbound *from us*. To determine that you /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
@ -599,7 +602,8 @@ impl ChannelTransactionParameters {
impl Clone for ChannelTransactionParameters { impl Clone for ChannelTransactionParameters {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -611,7 +615,7 @@ pub(crate) extern "C" fn ChannelTransactionParameters_clone_void(this_ptr: *cons
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelTransactionParameters_clone(orig: &ChannelTransactionParameters) -> ChannelTransactionParameters { pub extern "C" fn ChannelTransactionParameters_clone(orig: &ChannelTransactionParameters) -> ChannelTransactionParameters {
ChannelTransactionParameters { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// Holder public keys /// Holder public keys
#[no_mangle] #[no_mangle]
@ -730,7 +734,8 @@ impl CounterpartyChannelTransactionParameters {
impl Clone for CounterpartyChannelTransactionParameters { impl Clone for CounterpartyChannelTransactionParameters {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -742,7 +747,7 @@ pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_clone_void(thi
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn CounterpartyChannelTransactionParameters_clone(orig: &CounterpartyChannelTransactionParameters) -> CounterpartyChannelTransactionParameters { pub extern "C" fn CounterpartyChannelTransactionParameters_clone(orig: &CounterpartyChannelTransactionParameters) -> CounterpartyChannelTransactionParameters {
CounterpartyChannelTransactionParameters { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// Counter-party public keys /// Counter-party public keys
#[no_mangle] #[no_mangle]
@ -965,7 +970,8 @@ impl HolderCommitmentTransaction {
impl Clone for HolderCommitmentTransaction { impl Clone for HolderCommitmentTransaction {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -977,7 +983,7 @@ pub(crate) extern "C" fn HolderCommitmentTransaction_clone_void(this_ptr: *const
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn HolderCommitmentTransaction_clone(orig: &HolderCommitmentTransaction) -> HolderCommitmentTransaction { pub extern "C" fn HolderCommitmentTransaction_clone(orig: &HolderCommitmentTransaction) -> HolderCommitmentTransaction {
HolderCommitmentTransaction { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// Our counterparty's signature for the transaction /// Our counterparty's signature for the transaction
#[no_mangle] #[no_mangle]
@ -1063,7 +1069,8 @@ impl BuiltCommitmentTransaction {
impl Clone for BuiltCommitmentTransaction { impl Clone for BuiltCommitmentTransaction {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -1075,7 +1082,7 @@ pub(crate) extern "C" fn BuiltCommitmentTransaction_clone_void(this_ptr: *const
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn BuiltCommitmentTransaction_clone(orig: &BuiltCommitmentTransaction) -> BuiltCommitmentTransaction { pub extern "C" fn BuiltCommitmentTransaction_clone(orig: &BuiltCommitmentTransaction) -> BuiltCommitmentTransaction {
BuiltCommitmentTransaction { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The commitment transaction /// The commitment transaction
#[no_mangle] #[no_mangle]
@ -1195,7 +1202,8 @@ impl CommitmentTransaction {
impl Clone for CommitmentTransaction { impl Clone for CommitmentTransaction {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -1207,7 +1215,7 @@ pub(crate) extern "C" fn CommitmentTransaction_clone_void(this_ptr: *const c_voi
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn CommitmentTransaction_clone(orig: &CommitmentTransaction) -> CommitmentTransaction { pub extern "C" fn CommitmentTransaction_clone(orig: &CommitmentTransaction) -> CommitmentTransaction {
CommitmentTransaction { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn CommitmentTransaction_write(obj: &CommitmentTransaction) -> crate::c_types::derived::CVec_u8Z { pub extern "C" fn CommitmentTransaction_write(obj: &CommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
@ -1280,7 +1288,7 @@ pub extern "C" fn CommitmentTransaction_trust(this_arg: &CommitmentTransaction)
#[no_mangle] #[no_mangle]
pub extern "C" fn CommitmentTransaction_verify(this_arg: &CommitmentTransaction, channel_parameters: &crate::ln::chan_utils::DirectedChannelTransactionParameters, broadcaster_keys: &crate::ln::chan_utils::ChannelPublicKeys, countersignatory_keys: &crate::ln::chan_utils::ChannelPublicKeys) -> crate::c_types::derived::CResult_TrustedCommitmentTransactionNoneZ { pub extern "C" fn CommitmentTransaction_verify(this_arg: &CommitmentTransaction, channel_parameters: &crate::ln::chan_utils::DirectedChannelTransactionParameters, broadcaster_keys: &crate::ln::chan_utils::ChannelPublicKeys, countersignatory_keys: &crate::ln::chan_utils::ChannelPublicKeys) -> crate::c_types::derived::CResult_TrustedCommitmentTransactionNoneZ {
let mut ret = unsafe { &*this_arg.inner }.verify(unsafe { &*channel_parameters.inner }, unsafe { &*broadcaster_keys.inner }, unsafe { &*countersignatory_keys.inner }, &bitcoin::secp256k1::Secp256k1::new()); let mut ret = unsafe { &*this_arg.inner }.verify(unsafe { &*channel_parameters.inner }, unsafe { &*broadcaster_keys.inner }, unsafe { &*countersignatory_keys.inner }, &bitcoin::secp256k1::Secp256k1::new());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::TrustedCommitmentTransaction { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::TrustedCommitmentTransaction { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }).into() };
local_ret local_ret
} }
@ -1359,7 +1367,7 @@ pub extern "C" fn TrustedCommitmentTransaction_keys(this_arg: &TrustedCommitment
#[no_mangle] #[no_mangle]
pub extern "C" fn TrustedCommitmentTransaction_get_htlc_sigs(this_arg: &TrustedCommitmentTransaction, htlc_base_key: *const [u8; 32], channel_parameters: &crate::ln::chan_utils::DirectedChannelTransactionParameters) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ { pub extern "C" fn TrustedCommitmentTransaction_get_htlc_sigs(this_arg: &TrustedCommitmentTransaction, htlc_base_key: *const [u8; 32], channel_parameters: &crate::ln::chan_utils::DirectedChannelTransactionParameters) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ {
let mut ret = unsafe { &*this_arg.inner }.get_htlc_sigs(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *htlc_base_key}[..]).unwrap(), unsafe { &*channel_parameters.inner }, &bitcoin::secp256k1::Secp256k1::new()); let mut ret = unsafe { &*this_arg.inner }.get_htlc_sigs(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *htlc_base_key}[..]).unwrap(), unsafe { &*channel_parameters.inner }, &bitcoin::secp256k1::Secp256k1::new());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for item in o.drain(..) { local_ret_0.push( { crate::c_types::Signature::from_rust(&item) }); }; local_ret_0.into() }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for item in o.drain(..) { local_ret_0.push( { crate::c_types::Signature::from_rust(&item) }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }).into() };
local_ret local_ret
} }

View file

@ -127,7 +127,8 @@ impl ChannelDetails {
impl Clone for ChannelDetails { impl Clone for ChannelDetails {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -139,7 +140,7 @@ pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails { pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails {
ChannelDetails { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel's ID (prior to funding transaction generation, this is a random 32 bytes, /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
/// thereafter this is the txid of the funding transaction xor the funding transaction output). /// thereafter this is the txid of the funding transaction xor the funding transaction output).
@ -295,6 +296,24 @@ impl PaymentSendFailure {
ret ret
} }
} }
impl Clone for PaymentSendFailure {
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 PaymentSendFailure_clone_void(this_ptr: *const c_void) -> *mut c_void {
Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentSendFailure)).clone() })) as *mut c_void
}
#[no_mangle]
pub extern "C" fn PaymentSendFailure_clone(orig: &PaymentSendFailure) -> PaymentSendFailure {
orig.clone()
}
/// Constructs a new ChannelManager to hold several channels and route between them. /// Constructs a new ChannelManager to hold several channels and route between them.
/// ///
/// This is the main \"logic hub\" for all channel-related actions, and implements /// This is the main \"logic hub\" for all channel-related actions, and implements
@ -333,7 +352,7 @@ pub extern "C" fn ChannelManager_new(mut network: crate::bitcoin::network::Netwo
pub extern "C" fn ChannelManager_create_channel(this_arg: &ChannelManager, mut their_network_key: crate::c_types::PublicKey, mut channel_value_satoshis: u64, mut push_msat: u64, mut user_id: u64, mut override_config: crate::util::config::UserConfig) -> crate::c_types::derived::CResult_NoneAPIErrorZ { pub extern "C" fn ChannelManager_create_channel(this_arg: &ChannelManager, mut their_network_key: crate::c_types::PublicKey, mut channel_value_satoshis: u64, mut push_msat: u64, mut user_id: u64, mut override_config: crate::util::config::UserConfig) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) }; let mut local_override_config = if override_config.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(override_config.take_inner()) } }) };
let mut ret = unsafe { &*this_arg.inner }.create_channel(their_network_key.into_rust(), channel_value_satoshis, push_msat, user_id, local_override_config); let mut ret = unsafe { &*this_arg.inner }.create_channel(their_network_key.into_rust(), channel_value_satoshis, push_msat, user_id, local_override_config);
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::util::errors::APIError::native_into(e) }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::util::errors::APIError::native_into(e) }).into() };
local_ret local_ret
} }
@ -369,7 +388,7 @@ pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &ChannelManager)
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelManager_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ { pub extern "C" fn ChannelManager_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
let mut ret = unsafe { &*this_arg.inner }.close_channel(unsafe { &*channel_id}); let mut ret = unsafe { &*this_arg.inner }.close_channel(unsafe { &*channel_id});
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::util::errors::APIError::native_into(e) }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::util::errors::APIError::native_into(e) }).into() };
local_ret local_ret
} }
@ -379,7 +398,7 @@ pub extern "C" fn ChannelManager_close_channel(this_arg: &ChannelManager, channe
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelManager_force_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ { pub extern "C" fn ChannelManager_force_close_channel(this_arg: &ChannelManager, channel_id: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
let mut ret = unsafe { &*this_arg.inner }.force_close_channel(unsafe { &*channel_id}); let mut ret = unsafe { &*this_arg.inner }.force_close_channel(unsafe { &*channel_id});
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::util::errors::APIError::native_into(e) }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::util::errors::APIError::native_into(e) }).into() };
local_ret local_ret
} }
@ -434,7 +453,7 @@ pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &ChannelMana
pub extern "C" fn ChannelManager_send_payment(this_arg: &ChannelManager, route: &crate::routing::router::Route, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ { pub extern "C" fn ChannelManager_send_payment(this_arg: &ChannelManager, route: &crate::routing::router::Route, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NonePaymentSendFailureZ {
let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) }; let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) };
let mut ret = unsafe { &*this_arg.inner }.send_payment(unsafe { &*route.inner }, ::lightning::ln::channelmanager::PaymentHash(payment_hash.data), &local_payment_secret); let mut ret = unsafe { &*this_arg.inner }.send_payment(unsafe { &*route.inner }, ::lightning::ln::channelmanager::PaymentHash(payment_hash.data), &local_payment_secret);
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::ln::channelmanager::PaymentSendFailure { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::channelmanager::PaymentSendFailure { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
@ -898,6 +917,6 @@ pub extern "C" fn ChannelManagerReadArgs_new(mut keys_manager: crate::chain::key
pub extern "C" fn C2Tuple_BlockHashChannelManagerZ_read(ser: crate::c_types::u8slice, arg: crate::ln::channelmanager::ChannelManagerReadArgs) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ { pub extern "C" fn C2Tuple_BlockHashChannelManagerZ_read(ser: crate::c_types::u8slice, arg: crate::ln::channelmanager::ChannelManagerReadArgs) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ {
let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) }; let arg_conv = *unsafe { Box::from_raw(arg.take_inner()) };
let res: Result<(bitcoin::hash_types::BlockHash, lightning::ln::channelmanager::ChannelManager<crate::chain::keysinterface::ChannelKeys, crate::chain::Watch, crate::chain::chaininterface::BroadcasterInterface, crate::chain::keysinterface::KeysInterface, crate::chain::chaininterface::FeeEstimator, crate::util::logger::Logger>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv); let res: Result<(bitcoin::hash_types::BlockHash, lightning::ln::channelmanager::ChannelManager<crate::chain::keysinterface::ChannelKeys, crate::chain::Watch, crate::chain::chaininterface::BroadcasterInterface, crate::chain::keysinterface::KeysInterface, crate::chain::chaininterface::FeeEstimator, crate::util::logger::Logger>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_res_0_0, mut orig_res_0_1) = o; let mut local_res_0 = (crate::c_types::ThirtyTwoBytes { data: orig_res_0_0.into_inner() }, crate::ln::channelmanager::ChannelManager { inner: Box::into_raw(Box::new(orig_res_0_1)), is_owned: true }).into(); local_res_0 }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_res_0_0, mut orig_res_0_1) = o; let mut local_res_0 = (crate::c_types::ThirtyTwoBytes { data: orig_res_0_0.into_inner() }, crate::ln::channelmanager::ChannelManager { inner: Box::into_raw(Box::new(orig_res_0_1)), is_owned: true }).into(); local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }

View file

@ -57,6 +57,24 @@ impl DecodeError {
ret ret
} }
} }
impl Clone for DecodeError {
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 DecodeError_clone_void(this_ptr: *const c_void) -> *mut c_void {
Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDecodeError)).clone() })) as *mut c_void
}
#[no_mangle]
pub extern "C" fn DecodeError_clone(orig: &DecodeError) -> DecodeError {
orig.clone()
}
use lightning::ln::msgs::Init as nativeInitImport; use lightning::ln::msgs::Init as nativeInitImport;
type nativeInit = nativeInitImport; type nativeInit = nativeInitImport;
@ -98,7 +116,8 @@ impl Init {
impl Clone for Init { impl Clone for Init {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -110,7 +129,7 @@ pub(crate) extern "C" fn Init_clone_void(this_ptr: *const c_void) -> *mut c_void
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Init_clone(orig: &Init) -> Init { pub extern "C" fn Init_clone(orig: &Init) -> Init {
Init { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
use lightning::ln::msgs::ErrorMessage as nativeErrorMessageImport; use lightning::ln::msgs::ErrorMessage as nativeErrorMessageImport;
@ -153,7 +172,8 @@ impl ErrorMessage {
impl Clone for ErrorMessage { impl Clone for ErrorMessage {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -165,7 +185,7 @@ pub(crate) extern "C" fn ErrorMessage_clone_void(this_ptr: *const c_void) -> *mu
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ErrorMessage_clone(orig: &ErrorMessage) -> ErrorMessage { pub extern "C" fn ErrorMessage_clone(orig: &ErrorMessage) -> ErrorMessage {
ErrorMessage { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID involved in the error /// The channel ID involved in the error
#[no_mangle] #[no_mangle]
@ -244,7 +264,8 @@ impl Ping {
impl Clone for Ping { impl Clone for Ping {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -256,7 +277,7 @@ pub(crate) extern "C" fn Ping_clone_void(this_ptr: *const c_void) -> *mut c_void
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Ping_clone(orig: &Ping) -> Ping { pub extern "C" fn Ping_clone(orig: &Ping) -> Ping {
Ping { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The desired response length /// The desired response length
#[no_mangle] #[no_mangle]
@ -331,7 +352,8 @@ impl Pong {
impl Clone for Pong { impl Clone for Pong {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -343,7 +365,7 @@ pub(crate) extern "C" fn Pong_clone_void(this_ptr: *const c_void) -> *mut c_void
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Pong_clone(orig: &Pong) -> Pong { pub extern "C" fn Pong_clone(orig: &Pong) -> Pong {
Pong { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The pong packet size. /// The pong packet size.
/// This field is not sent on the wire. byteslen zeros are sent. /// This field is not sent on the wire. byteslen zeros are sent.
@ -406,7 +428,8 @@ impl OpenChannel {
impl Clone for OpenChannel { impl Clone for OpenChannel {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -418,7 +441,7 @@ pub(crate) extern "C" fn OpenChannel_clone_void(this_ptr: *const c_void) -> *mut
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn OpenChannel_clone(orig: &OpenChannel) -> OpenChannel { pub extern "C" fn OpenChannel_clone(orig: &OpenChannel) -> OpenChannel {
OpenChannel { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The genesis hash of the blockchain where the channel is to be opened /// The genesis hash of the blockchain where the channel is to be opened
#[no_mangle] #[no_mangle]
@ -659,7 +682,8 @@ impl AcceptChannel {
impl Clone for AcceptChannel { impl Clone for AcceptChannel {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -671,7 +695,7 @@ pub(crate) extern "C" fn AcceptChannel_clone_void(this_ptr: *const c_void) -> *m
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn AcceptChannel_clone(orig: &AcceptChannel) -> AcceptChannel { pub extern "C" fn AcceptChannel_clone(orig: &AcceptChannel) -> AcceptChannel {
AcceptChannel { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// A temporary channel ID, until the funding outpoint is announced /// A temporary channel ID, until the funding outpoint is announced
#[no_mangle] #[no_mangle]
@ -868,7 +892,8 @@ impl FundingCreated {
impl Clone for FundingCreated { impl Clone for FundingCreated {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -880,7 +905,7 @@ pub(crate) extern "C" fn FundingCreated_clone_void(this_ptr: *const c_void) -> *
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn FundingCreated_clone(orig: &FundingCreated) -> FundingCreated { pub extern "C" fn FundingCreated_clone(orig: &FundingCreated) -> FundingCreated {
FundingCreated { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// A temporary channel ID, until the funding is established /// A temporary channel ID, until the funding is established
#[no_mangle] #[no_mangle]
@ -977,7 +1002,8 @@ impl FundingSigned {
impl Clone for FundingSigned { impl Clone for FundingSigned {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -989,7 +1015,7 @@ pub(crate) extern "C" fn FundingSigned_clone_void(this_ptr: *const c_void) -> *m
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn FundingSigned_clone(orig: &FundingSigned) -> FundingSigned { pub extern "C" fn FundingSigned_clone(orig: &FundingSigned) -> FundingSigned {
FundingSigned { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID /// The channel ID
#[no_mangle] #[no_mangle]
@ -1062,7 +1088,8 @@ impl FundingLocked {
impl Clone for FundingLocked { impl Clone for FundingLocked {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -1074,7 +1101,7 @@ pub(crate) extern "C" fn FundingLocked_clone_void(this_ptr: *const c_void) -> *m
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn FundingLocked_clone(orig: &FundingLocked) -> FundingLocked { pub extern "C" fn FundingLocked_clone(orig: &FundingLocked) -> FundingLocked {
FundingLocked { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID /// The channel ID
#[no_mangle] #[no_mangle]
@ -1147,7 +1174,8 @@ impl Shutdown {
impl Clone for Shutdown { impl Clone for Shutdown {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -1159,7 +1187,7 @@ pub(crate) extern "C" fn Shutdown_clone_void(this_ptr: *const c_void) -> *mut c_
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Shutdown_clone(orig: &Shutdown) -> Shutdown { pub extern "C" fn Shutdown_clone(orig: &Shutdown) -> Shutdown {
Shutdown { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID /// The channel ID
#[no_mangle] #[no_mangle]
@ -1234,7 +1262,8 @@ impl ClosingSigned {
impl Clone for ClosingSigned { impl Clone for ClosingSigned {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -1246,7 +1275,7 @@ pub(crate) extern "C" fn ClosingSigned_clone_void(this_ptr: *const c_void) -> *m
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ClosingSigned_clone(orig: &ClosingSigned) -> ClosingSigned { pub extern "C" fn ClosingSigned_clone(orig: &ClosingSigned) -> ClosingSigned {
ClosingSigned { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID /// The channel ID
#[no_mangle] #[no_mangle]
@ -1331,7 +1360,8 @@ impl UpdateAddHTLC {
impl Clone for UpdateAddHTLC { impl Clone for UpdateAddHTLC {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -1343,7 +1373,7 @@ pub(crate) extern "C" fn UpdateAddHTLC_clone_void(this_ptr: *const c_void) -> *m
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn UpdateAddHTLC_clone(orig: &UpdateAddHTLC) -> UpdateAddHTLC { pub extern "C" fn UpdateAddHTLC_clone(orig: &UpdateAddHTLC) -> UpdateAddHTLC {
UpdateAddHTLC { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID /// The channel ID
#[no_mangle] #[no_mangle]
@ -1441,7 +1471,8 @@ impl UpdateFulfillHTLC {
impl Clone for UpdateFulfillHTLC { impl Clone for UpdateFulfillHTLC {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -1453,7 +1484,7 @@ pub(crate) extern "C" fn UpdateFulfillHTLC_clone_void(this_ptr: *const c_void) -
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn UpdateFulfillHTLC_clone(orig: &UpdateFulfillHTLC) -> UpdateFulfillHTLC { pub extern "C" fn UpdateFulfillHTLC_clone(orig: &UpdateFulfillHTLC) -> UpdateFulfillHTLC {
UpdateFulfillHTLC { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID /// The channel ID
#[no_mangle] #[no_mangle]
@ -1538,7 +1569,8 @@ impl UpdateFailHTLC {
impl Clone for UpdateFailHTLC { impl Clone for UpdateFailHTLC {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -1550,7 +1582,7 @@ pub(crate) extern "C" fn UpdateFailHTLC_clone_void(this_ptr: *const c_void) -> *
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn UpdateFailHTLC_clone(orig: &UpdateFailHTLC) -> UpdateFailHTLC { pub extern "C" fn UpdateFailHTLC_clone(orig: &UpdateFailHTLC) -> UpdateFailHTLC {
UpdateFailHTLC { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID /// The channel ID
#[no_mangle] #[no_mangle]
@ -1615,7 +1647,8 @@ impl UpdateFailMalformedHTLC {
impl Clone for UpdateFailMalformedHTLC { impl Clone for UpdateFailMalformedHTLC {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -1627,7 +1660,7 @@ pub(crate) extern "C" fn UpdateFailMalformedHTLC_clone_void(this_ptr: *const c_v
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn UpdateFailMalformedHTLC_clone(orig: &UpdateFailMalformedHTLC) -> UpdateFailMalformedHTLC { pub extern "C" fn UpdateFailMalformedHTLC_clone(orig: &UpdateFailMalformedHTLC) -> UpdateFailMalformedHTLC {
UpdateFailMalformedHTLC { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID /// The channel ID
#[no_mangle] #[no_mangle]
@ -1703,7 +1736,8 @@ impl CommitmentSigned {
impl Clone for CommitmentSigned { impl Clone for CommitmentSigned {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -1715,7 +1749,7 @@ pub(crate) extern "C" fn CommitmentSigned_clone_void(this_ptr: *const c_void) ->
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn CommitmentSigned_clone(orig: &CommitmentSigned) -> CommitmentSigned { pub extern "C" fn CommitmentSigned_clone(orig: &CommitmentSigned) -> CommitmentSigned {
CommitmentSigned { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID /// The channel ID
#[no_mangle] #[no_mangle]
@ -1796,7 +1830,8 @@ impl RevokeAndACK {
impl Clone for RevokeAndACK { impl Clone for RevokeAndACK {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -1808,7 +1843,7 @@ pub(crate) extern "C" fn RevokeAndACK_clone_void(this_ptr: *const c_void) -> *mu
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn RevokeAndACK_clone(orig: &RevokeAndACK) -> RevokeAndACK { pub extern "C" fn RevokeAndACK_clone(orig: &RevokeAndACK) -> RevokeAndACK {
RevokeAndACK { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID /// The channel ID
#[no_mangle] #[no_mangle]
@ -1893,7 +1928,8 @@ impl UpdateFee {
impl Clone for UpdateFee { impl Clone for UpdateFee {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -1905,7 +1941,7 @@ pub(crate) extern "C" fn UpdateFee_clone_void(this_ptr: *const c_void) -> *mut c
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn UpdateFee_clone(orig: &UpdateFee) -> UpdateFee { pub extern "C" fn UpdateFee_clone(orig: &UpdateFee) -> UpdateFee {
UpdateFee { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID /// The channel ID
#[no_mangle] #[no_mangle]
@ -1981,7 +2017,8 @@ impl DataLossProtect {
impl Clone for DataLossProtect { impl Clone for DataLossProtect {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -1993,7 +2030,7 @@ pub(crate) extern "C" fn DataLossProtect_clone_void(this_ptr: *const c_void) ->
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn DataLossProtect_clone(orig: &DataLossProtect) -> DataLossProtect { pub extern "C" fn DataLossProtect_clone(orig: &DataLossProtect) -> DataLossProtect {
DataLossProtect { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// Proof that the sender knows the per-commitment secret of a specific commitment transaction /// Proof that the sender knows the per-commitment secret of a specific commitment transaction
/// belonging to the recipient /// belonging to the recipient
@ -2068,7 +2105,8 @@ impl ChannelReestablish {
impl Clone for ChannelReestablish { impl Clone for ChannelReestablish {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -2080,7 +2118,7 @@ pub(crate) extern "C" fn ChannelReestablish_clone_void(this_ptr: *const c_void)
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelReestablish_clone(orig: &ChannelReestablish) -> ChannelReestablish { pub extern "C" fn ChannelReestablish_clone(orig: &ChannelReestablish) -> ChannelReestablish {
ChannelReestablish { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID /// The channel ID
#[no_mangle] #[no_mangle]
@ -2156,7 +2194,8 @@ impl AnnouncementSignatures {
impl Clone for AnnouncementSignatures { impl Clone for AnnouncementSignatures {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -2168,7 +2207,7 @@ pub(crate) extern "C" fn AnnouncementSignatures_clone_void(this_ptr: *const c_vo
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn AnnouncementSignatures_clone(orig: &AnnouncementSignatures) -> AnnouncementSignatures { pub extern "C" fn AnnouncementSignatures_clone(orig: &AnnouncementSignatures) -> AnnouncementSignatures {
AnnouncementSignatures { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The channel ID /// The channel ID
#[no_mangle] #[no_mangle]
@ -2414,7 +2453,7 @@ pub extern "C" fn NetAddress_write(obj: &NetAddress) -> crate::c_types::derived:
#[no_mangle] #[no_mangle]
pub extern "C" fn Result_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CResult_NetAddressu8ZDecodeErrorZ { pub extern "C" fn Result_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CResult_NetAddressu8ZDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = match o { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::NetAddress::native_into(o) }), Err(mut e) => crate::c_types::CResultTempl::err( { e }) }; local_res_0 }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = match o { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::NetAddress::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { e }).into() }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
@ -2458,7 +2497,8 @@ impl UnsignedNodeAnnouncement {
impl Clone for UnsignedNodeAnnouncement { impl Clone for UnsignedNodeAnnouncement {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -2470,7 +2510,7 @@ pub(crate) extern "C" fn UnsignedNodeAnnouncement_clone_void(this_ptr: *const c_
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn UnsignedNodeAnnouncement_clone(orig: &UnsignedNodeAnnouncement) -> UnsignedNodeAnnouncement { pub extern "C" fn UnsignedNodeAnnouncement_clone(orig: &UnsignedNodeAnnouncement) -> UnsignedNodeAnnouncement {
UnsignedNodeAnnouncement { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The advertised features /// The advertised features
#[no_mangle] #[no_mangle]
@ -2578,7 +2618,8 @@ impl NodeAnnouncement {
impl Clone for NodeAnnouncement { impl Clone for NodeAnnouncement {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -2590,7 +2631,7 @@ pub(crate) extern "C" fn NodeAnnouncement_clone_void(this_ptr: *const c_void) ->
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn NodeAnnouncement_clone(orig: &NodeAnnouncement) -> NodeAnnouncement { pub extern "C" fn NodeAnnouncement_clone(orig: &NodeAnnouncement) -> NodeAnnouncement {
NodeAnnouncement { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The signature by the node key /// The signature by the node key
#[no_mangle] #[no_mangle]
@ -2663,7 +2704,8 @@ impl UnsignedChannelAnnouncement {
impl Clone for UnsignedChannelAnnouncement { impl Clone for UnsignedChannelAnnouncement {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -2675,7 +2717,7 @@ pub(crate) extern "C" fn UnsignedChannelAnnouncement_clone_void(this_ptr: *const
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn UnsignedChannelAnnouncement_clone(orig: &UnsignedChannelAnnouncement) -> UnsignedChannelAnnouncement { pub extern "C" fn UnsignedChannelAnnouncement_clone(orig: &UnsignedChannelAnnouncement) -> UnsignedChannelAnnouncement {
UnsignedChannelAnnouncement { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The advertised channel features /// The advertised channel features
#[no_mangle] #[no_mangle]
@ -2795,7 +2837,8 @@ impl ChannelAnnouncement {
impl Clone for ChannelAnnouncement { impl Clone for ChannelAnnouncement {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -2807,7 +2850,7 @@ pub(crate) extern "C" fn ChannelAnnouncement_clone_void(this_ptr: *const c_void)
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelAnnouncement_clone(orig: &ChannelAnnouncement) -> ChannelAnnouncement { pub extern "C" fn ChannelAnnouncement_clone(orig: &ChannelAnnouncement) -> ChannelAnnouncement {
ChannelAnnouncement { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// Authentication of the announcement by the first public node /// Authentication of the announcement by the first public node
#[no_mangle] #[no_mangle]
@ -2916,7 +2959,8 @@ impl UnsignedChannelUpdate {
impl Clone for UnsignedChannelUpdate { impl Clone for UnsignedChannelUpdate {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -2928,7 +2972,7 @@ pub(crate) extern "C" fn UnsignedChannelUpdate_clone_void(this_ptr: *const c_voi
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn UnsignedChannelUpdate_clone(orig: &UnsignedChannelUpdate) -> UnsignedChannelUpdate { pub extern "C" fn UnsignedChannelUpdate_clone(orig: &UnsignedChannelUpdate) -> UnsignedChannelUpdate {
UnsignedChannelUpdate { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The genesis hash of the blockchain where the channel is to be opened /// The genesis hash of the blockchain where the channel is to be opened
#[no_mangle] #[no_mangle]
@ -3059,7 +3103,8 @@ impl ChannelUpdate {
impl Clone for ChannelUpdate { impl Clone for ChannelUpdate {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -3071,7 +3116,7 @@ pub(crate) extern "C" fn ChannelUpdate_clone_void(this_ptr: *const c_void) -> *m
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelUpdate_clone(orig: &ChannelUpdate) -> ChannelUpdate { pub extern "C" fn ChannelUpdate_clone(orig: &ChannelUpdate) -> ChannelUpdate {
ChannelUpdate { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// A signature of the channel update /// A signature of the channel update
#[no_mangle] #[no_mangle]
@ -3147,7 +3192,8 @@ impl QueryChannelRange {
impl Clone for QueryChannelRange { impl Clone for QueryChannelRange {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -3159,7 +3205,7 @@ pub(crate) extern "C" fn QueryChannelRange_clone_void(this_ptr: *const c_void) -
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn QueryChannelRange_clone(orig: &QueryChannelRange) -> QueryChannelRange { pub extern "C" fn QueryChannelRange_clone(orig: &QueryChannelRange) -> QueryChannelRange {
QueryChannelRange { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The genesis hash of the blockchain being queried /// The genesis hash of the blockchain being queried
#[no_mangle] #[no_mangle]
@ -3250,7 +3296,8 @@ impl ReplyChannelRange {
impl Clone for ReplyChannelRange { impl Clone for ReplyChannelRange {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -3262,7 +3309,7 @@ pub(crate) extern "C" fn ReplyChannelRange_clone_void(this_ptr: *const c_void) -
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ReplyChannelRange_clone(orig: &ReplyChannelRange) -> ReplyChannelRange { pub extern "C" fn ReplyChannelRange_clone(orig: &ReplyChannelRange) -> ReplyChannelRange {
ReplyChannelRange { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The genesis hash of the blockchain being queried /// The genesis hash of the blockchain being queried
#[no_mangle] #[no_mangle]
@ -3297,18 +3344,16 @@ pub extern "C" fn ReplyChannelRange_get_number_of_blocks(this_ptr: &ReplyChannel
pub extern "C" fn ReplyChannelRange_set_number_of_blocks(this_ptr: &mut ReplyChannelRange, mut val: u32) { pub extern "C" fn ReplyChannelRange_set_number_of_blocks(this_ptr: &mut ReplyChannelRange, mut val: u32) {
unsafe { &mut *this_ptr.inner }.number_of_blocks = val; unsafe { &mut *this_ptr.inner }.number_of_blocks = val;
} }
/// Indicates if the query recipient maintains up-to-date channel /// True when this is the final reply for a query
/// information for the chain_hash
#[no_mangle] #[no_mangle]
pub extern "C" fn ReplyChannelRange_get_full_information(this_ptr: &ReplyChannelRange) -> bool { pub extern "C" fn ReplyChannelRange_get_sync_complete(this_ptr: &ReplyChannelRange) -> bool {
let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.full_information; let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.sync_complete;
(*inner_val) (*inner_val)
} }
/// Indicates if the query recipient maintains up-to-date channel /// True when this is the final reply for a query
/// information for the chain_hash
#[no_mangle] #[no_mangle]
pub extern "C" fn ReplyChannelRange_set_full_information(this_ptr: &mut ReplyChannelRange, mut val: bool) { pub extern "C" fn ReplyChannelRange_set_sync_complete(this_ptr: &mut ReplyChannelRange, mut val: bool) {
unsafe { &mut *this_ptr.inner }.full_information = val; unsafe { &mut *this_ptr.inner }.sync_complete = val;
} }
/// The short_channel_ids in the channel range /// The short_channel_ids in the channel range
#[no_mangle] #[no_mangle]
@ -3318,13 +3363,13 @@ pub extern "C" fn ReplyChannelRange_set_short_channel_ids(this_ptr: &mut ReplyCh
} }
#[must_use] #[must_use]
#[no_mangle] #[no_mangle]
pub extern "C" fn ReplyChannelRange_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut first_blocknum_arg: u32, mut number_of_blocks_arg: u32, mut full_information_arg: bool, mut short_channel_ids_arg: crate::c_types::derived::CVec_u64Z) -> ReplyChannelRange { pub extern "C" fn ReplyChannelRange_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut first_blocknum_arg: u32, mut number_of_blocks_arg: u32, mut sync_complete_arg: bool, mut short_channel_ids_arg: crate::c_types::derived::CVec_u64Z) -> ReplyChannelRange {
let mut local_short_channel_ids_arg = Vec::new(); for mut item in short_channel_ids_arg.into_rust().drain(..) { local_short_channel_ids_arg.push( { item }); }; let mut local_short_channel_ids_arg = Vec::new(); for mut item in short_channel_ids_arg.into_rust().drain(..) { local_short_channel_ids_arg.push( { item }); };
ReplyChannelRange { inner: Box::into_raw(Box::new(nativeReplyChannelRange { ReplyChannelRange { inner: Box::into_raw(Box::new(nativeReplyChannelRange {
chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(),
first_blocknum: first_blocknum_arg, first_blocknum: first_blocknum_arg,
number_of_blocks: number_of_blocks_arg, number_of_blocks: number_of_blocks_arg,
full_information: full_information_arg, sync_complete: sync_complete_arg,
short_channel_ids: local_short_channel_ids_arg, short_channel_ids: local_short_channel_ids_arg,
})), is_owned: true } })), is_owned: true }
} }
@ -3376,7 +3421,8 @@ impl QueryShortChannelIds {
impl Clone for QueryShortChannelIds { impl Clone for QueryShortChannelIds {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -3388,7 +3434,7 @@ pub(crate) extern "C" fn QueryShortChannelIds_clone_void(this_ptr: *const c_void
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn QueryShortChannelIds_clone(orig: &QueryShortChannelIds) -> QueryShortChannelIds { pub extern "C" fn QueryShortChannelIds_clone(orig: &QueryShortChannelIds) -> QueryShortChannelIds {
QueryShortChannelIds { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The genesis hash of the blockchain being queried /// The genesis hash of the blockchain being queried
#[no_mangle] #[no_mangle]
@ -3460,7 +3506,8 @@ impl ReplyShortChannelIdsEnd {
impl Clone for ReplyShortChannelIdsEnd { impl Clone for ReplyShortChannelIdsEnd {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -3472,7 +3519,7 @@ pub(crate) extern "C" fn ReplyShortChannelIdsEnd_clone_void(this_ptr: *const c_v
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ReplyShortChannelIdsEnd_clone(orig: &ReplyShortChannelIdsEnd) -> ReplyShortChannelIdsEnd { pub extern "C" fn ReplyShortChannelIdsEnd_clone(orig: &ReplyShortChannelIdsEnd) -> ReplyShortChannelIdsEnd {
ReplyShortChannelIdsEnd { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The genesis hash of the blockchain that was queried /// The genesis hash of the blockchain that was queried
#[no_mangle] #[no_mangle]
@ -3549,7 +3596,8 @@ impl GossipTimestampFilter {
impl Clone for GossipTimestampFilter { impl Clone for GossipTimestampFilter {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -3561,7 +3609,7 @@ pub(crate) extern "C" fn GossipTimestampFilter_clone_void(this_ptr: *const c_voi
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn GossipTimestampFilter_clone(orig: &GossipTimestampFilter) -> GossipTimestampFilter { pub extern "C" fn GossipTimestampFilter_clone(orig: &GossipTimestampFilter) -> GossipTimestampFilter {
GossipTimestampFilter { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The genesis hash of the blockchain for channel and node information /// The genesis hash of the blockchain for channel and node information
#[no_mangle] #[no_mangle]
@ -3740,6 +3788,24 @@ impl LightningError {
ret ret
} }
} }
impl Clone for LightningError {
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 LightningError_clone_void(this_ptr: *const c_void) -> *mut c_void {
Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeLightningError)).clone() })) as *mut c_void
}
#[no_mangle]
pub extern "C" fn LightningError_clone(orig: &LightningError) -> LightningError {
orig.clone()
}
/// A human-readable message describing the error /// A human-readable message describing the error
#[no_mangle] #[no_mangle]
pub extern "C" fn LightningError_get_err(this_ptr: &LightningError) -> crate::c_types::Str { pub extern "C" fn LightningError_get_err(this_ptr: &LightningError) -> crate::c_types::Str {
@ -3812,7 +3878,8 @@ impl CommitmentUpdate {
impl Clone for CommitmentUpdate { impl Clone for CommitmentUpdate {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -3824,7 +3891,7 @@ pub(crate) extern "C" fn CommitmentUpdate_clone_void(this_ptr: *const c_void) ->
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn CommitmentUpdate_clone(orig: &CommitmentUpdate) -> CommitmentUpdate { pub extern "C" fn CommitmentUpdate_clone(orig: &CommitmentUpdate) -> CommitmentUpdate {
CommitmentUpdate { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// update_add_htlc messages which should be sent /// update_add_htlc messages which should be sent
#[no_mangle] #[no_mangle]
@ -4344,7 +4411,7 @@ pub(crate) extern "C" fn ChannelReestablish_write_void(obj: *const c_void) -> cr
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelReestablish_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelReestablishDecodeErrorZ { pub extern "C" fn ChannelReestablish_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelReestablishDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -4438,7 +4505,7 @@ pub(crate) extern "C" fn Init_write_void(obj: *const c_void) -> crate::c_types::
#[no_mangle] #[no_mangle]
pub extern "C" fn Init_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InitDecodeErrorZ { pub extern "C" fn Init_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InitDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::Init { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::Init { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -4580,7 +4647,7 @@ pub(crate) extern "C" fn Ping_write_void(obj: *const c_void) -> crate::c_types::
#[no_mangle] #[no_mangle]
pub extern "C" fn Ping_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PingDecodeErrorZ { pub extern "C" fn Ping_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PingDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::Ping { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::Ping { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -4594,7 +4661,7 @@ pub(crate) extern "C" fn Pong_write_void(obj: *const c_void) -> crate::c_types::
#[no_mangle] #[no_mangle]
pub extern "C" fn Pong_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PongDecodeErrorZ { pub extern "C" fn Pong_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PongDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::Pong { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::Pong { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -4608,7 +4675,7 @@ pub(crate) extern "C" fn UnsignedChannelAnnouncement_write_void(obj: *const c_vo
#[no_mangle] #[no_mangle]
pub extern "C" fn UnsignedChannelAnnouncement_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UnsignedChannelAnnouncementDecodeErrorZ { pub extern "C" fn UnsignedChannelAnnouncement_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UnsignedChannelAnnouncementDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::UnsignedChannelAnnouncement { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::UnsignedChannelAnnouncement { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -4638,7 +4705,7 @@ pub(crate) extern "C" fn UnsignedChannelUpdate_write_void(obj: *const c_void) ->
#[no_mangle] #[no_mangle]
pub extern "C" fn UnsignedChannelUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UnsignedChannelUpdateDecodeErrorZ { pub extern "C" fn UnsignedChannelUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UnsignedChannelUpdateDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::UnsignedChannelUpdate { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::UnsignedChannelUpdate { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -4668,7 +4735,7 @@ pub(crate) extern "C" fn ErrorMessage_write_void(obj: *const c_void) -> crate::c
#[no_mangle] #[no_mangle]
pub extern "C" fn ErrorMessage_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ErrorMessageDecodeErrorZ { pub extern "C" fn ErrorMessage_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ErrorMessageDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::ErrorMessage { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::ErrorMessage { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -4682,7 +4749,7 @@ pub(crate) extern "C" fn UnsignedNodeAnnouncement_write_void(obj: *const c_void)
#[no_mangle] #[no_mangle]
pub extern "C" fn UnsignedNodeAnnouncement_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UnsignedNodeAnnouncementDecodeErrorZ { pub extern "C" fn UnsignedNodeAnnouncement_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UnsignedNodeAnnouncementDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::UnsignedNodeAnnouncement { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::UnsignedNodeAnnouncement { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -4704,7 +4771,7 @@ pub extern "C" fn NodeAnnouncement_read(ser: crate::c_types::u8slice) -> NodeAnn
#[no_mangle] #[no_mangle]
pub extern "C" fn QueryShortChannelIds_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_QueryShortChannelIdsDecodeErrorZ { pub extern "C" fn QueryShortChannelIds_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_QueryShortChannelIdsDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -4718,7 +4785,7 @@ pub(crate) extern "C" fn QueryShortChannelIds_write_void(obj: *const c_void) ->
#[no_mangle] #[no_mangle]
pub extern "C" fn ReplyShortChannelIdsEnd_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ReplyShortChannelIdsEndDecodeErrorZ { pub extern "C" fn ReplyShortChannelIdsEnd_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ReplyShortChannelIdsEndDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::ReplyShortChannelIdsEnd { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::ReplyShortChannelIdsEnd { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -4732,7 +4799,7 @@ pub(crate) extern "C" fn ReplyShortChannelIdsEnd_write_void(obj: *const c_void)
#[no_mangle] #[no_mangle]
pub extern "C" fn QueryChannelRange_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_QueryChannelRangeDecodeErrorZ { pub extern "C" fn QueryChannelRange_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_QueryChannelRangeDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -4746,7 +4813,7 @@ pub(crate) extern "C" fn QueryChannelRange_write_void(obj: *const c_void) -> cra
#[no_mangle] #[no_mangle]
pub extern "C" fn ReplyChannelRange_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ReplyChannelRangeDecodeErrorZ { pub extern "C" fn ReplyChannelRange_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ReplyChannelRangeDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::ReplyChannelRange { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::ReplyChannelRange { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -4760,7 +4827,7 @@ pub(crate) extern "C" fn ReplyChannelRange_write_void(obj: *const c_void) -> cra
#[no_mangle] #[no_mangle]
pub extern "C" fn GossipTimestampFilter_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_GossipTimestampFilterDecodeErrorZ { pub extern "C" fn GossipTimestampFilter_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_GossipTimestampFilterDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::GossipTimestampFilter { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::msgs::GossipTimestampFilter { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]

View file

@ -183,10 +183,8 @@ use lightning::ln::peer_handler::PeerHandleError as nativePeerHandleErrorImport;
type nativePeerHandleError = nativePeerHandleErrorImport; type nativePeerHandleError = nativePeerHandleErrorImport;
/// Error for PeerManager errors. If you get one of these, you must disconnect the socket and /// Error for PeerManager errors. If you get one of these, you must disconnect the socket and
/// generate no further read_event/write_buffer_space_avail calls for the descriptor, only /// generate no further read_event/write_buffer_space_avail/socket_disconnected calls for the
/// triggering a single socket_disconnected call (unless it was provided in response to a /// descriptor.
/// new_*_connection event, in which case no such socket_disconnected() must be called and the
/// socket silently disconencted).
#[must_use] #[must_use]
#[repr(C)] #[repr(C)]
pub struct PeerHandleError { pub struct PeerHandleError {
@ -220,6 +218,24 @@ impl PeerHandleError {
ret ret
} }
} }
impl Clone for PeerHandleError {
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 PeerHandleError_clone_void(this_ptr: *const c_void) -> *mut c_void {
Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePeerHandleError)).clone() })) as *mut c_void
}
#[no_mangle]
pub extern "C" fn PeerHandleError_clone(orig: &PeerHandleError) -> PeerHandleError {
orig.clone()
}
/// Used to indicate that we probably can't make any future connections to this peer, implying /// Used to indicate that we probably can't make any future connections to this peer, implying
/// we should go ahead and force-close any channels we have with it. /// we should go ahead and force-close any channels we have with it.
#[no_mangle] #[no_mangle]
@ -320,7 +336,7 @@ pub extern "C" fn PeerManager_get_peer_node_ids(this_arg: &PeerManager) -> crate
#[no_mangle] #[no_mangle]
pub extern "C" fn PeerManager_new_outbound_connection(this_arg: &PeerManager, mut their_node_id: crate::c_types::PublicKey, mut descriptor: crate::ln::peer_handler::SocketDescriptor) -> crate::c_types::derived::CResult_CVec_u8ZPeerHandleErrorZ { pub extern "C" fn PeerManager_new_outbound_connection(this_arg: &PeerManager, mut their_node_id: crate::c_types::PublicKey, mut descriptor: crate::ln::peer_handler::SocketDescriptor) -> crate::c_types::derived::CResult_CVec_u8ZPeerHandleErrorZ {
let mut ret = unsafe { &*this_arg.inner }.new_outbound_connection(their_node_id.into_rust(), descriptor); let mut ret = unsafe { &*this_arg.inner }.new_outbound_connection(their_node_id.into_rust(), descriptor);
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for item in o.drain(..) { local_ret_0.push( { item }); }; local_ret_0.into() }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::peer_handler::PeerHandleError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for item in o.drain(..) { local_ret_0.push( { item }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::peer_handler::PeerHandleError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
@ -337,7 +353,7 @@ pub extern "C" fn PeerManager_new_outbound_connection(this_arg: &PeerManager, mu
#[no_mangle] #[no_mangle]
pub extern "C" fn PeerManager_new_inbound_connection(this_arg: &PeerManager, mut descriptor: crate::ln::peer_handler::SocketDescriptor) -> crate::c_types::derived::CResult_NonePeerHandleErrorZ { pub extern "C" fn PeerManager_new_inbound_connection(this_arg: &PeerManager, mut descriptor: crate::ln::peer_handler::SocketDescriptor) -> crate::c_types::derived::CResult_NonePeerHandleErrorZ {
let mut ret = unsafe { &*this_arg.inner }.new_inbound_connection(descriptor); let mut ret = unsafe { &*this_arg.inner }.new_inbound_connection(descriptor);
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::ln::peer_handler::PeerHandleError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::peer_handler::PeerHandleError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
@ -355,7 +371,7 @@ pub extern "C" fn PeerManager_new_inbound_connection(this_arg: &PeerManager, mut
#[no_mangle] #[no_mangle]
pub extern "C" fn PeerManager_write_buffer_space_avail(this_arg: &PeerManager, descriptor: &mut crate::ln::peer_handler::SocketDescriptor) -> crate::c_types::derived::CResult_NonePeerHandleErrorZ { pub extern "C" fn PeerManager_write_buffer_space_avail(this_arg: &PeerManager, descriptor: &mut crate::ln::peer_handler::SocketDescriptor) -> crate::c_types::derived::CResult_NonePeerHandleErrorZ {
let mut ret = unsafe { &*this_arg.inner }.write_buffer_space_avail(descriptor); let mut ret = unsafe { &*this_arg.inner }.write_buffer_space_avail(descriptor);
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::ln::peer_handler::PeerHandleError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::peer_handler::PeerHandleError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
@ -375,7 +391,7 @@ pub extern "C" fn PeerManager_write_buffer_space_avail(this_arg: &PeerManager, d
#[no_mangle] #[no_mangle]
pub extern "C" fn PeerManager_read_event(this_arg: &PeerManager, peer_descriptor: &mut crate::ln::peer_handler::SocketDescriptor, mut data: crate::c_types::u8slice) -> crate::c_types::derived::CResult_boolPeerHandleErrorZ { pub extern "C" fn PeerManager_read_event(this_arg: &PeerManager, peer_descriptor: &mut crate::ln::peer_handler::SocketDescriptor, mut data: crate::c_types::u8slice) -> crate::c_types::derived::CResult_boolPeerHandleErrorZ {
let mut ret = unsafe { &*this_arg.inner }.read_event(peer_descriptor, data.to_slice()); let mut ret = unsafe { &*this_arg.inner }.read_event(peer_descriptor, data.to_slice());
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::peer_handler::PeerHandleError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::peer_handler::PeerHandleError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }

View file

@ -203,13 +203,13 @@ use lightning::ln::msgs::RoutingMessageHandler as RoutingMessageHandlerTraitImpo
#[must_use] #[must_use]
extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ { extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_node_announcement(unsafe { &*msg.inner }); let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_node_announcement(unsafe { &*msg.inner });
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
#[must_use] #[must_use]
extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ { extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_channel_announcement(unsafe { &*msg.inner }); let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_channel_announcement(unsafe { &*msg.inner });
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, update: &crate::ln::msgs::HTLCFailChannelUpdate) { extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, update: &crate::ln::msgs::HTLCFailChannelUpdate) {
@ -218,7 +218,7 @@ extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_
#[must_use] #[must_use]
extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ { extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_channel_update(unsafe { &*msg.inner }); let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_channel_update(unsafe { &*msg.inner });
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
#[must_use] #[must_use]
@ -240,25 +240,25 @@ extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table(this_a
#[must_use] #[must_use]
extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ { extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_reply_channel_range(&their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) }); let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_reply_channel_range(&their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
#[must_use] #[must_use]
extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ { extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_reply_short_channel_ids_end(&their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) }); let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_reply_short_channel_ids_end(&their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
#[must_use] #[must_use]
extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ { extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_query_channel_range(&_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) }); let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_query_channel_range(&_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) });
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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
#[must_use] #[must_use]
extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ { extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_query_short_channel_ids(&_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) }); let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_query_short_channel_ids(&_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) });
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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
use lightning::util::events::MessageSendEventsProvider as nativeMessageSendEventsProviderTrait; use lightning::util::events::MessageSendEventsProvider as nativeMessageSendEventsProviderTrait;
@ -334,6 +334,24 @@ impl DirectionalChannelInfo {
ret ret
} }
} }
impl Clone for DirectionalChannelInfo {
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 DirectionalChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectionalChannelInfo)).clone() })) as *mut c_void
}
#[no_mangle]
pub extern "C" fn DirectionalChannelInfo_clone(orig: &DirectionalChannelInfo) -> DirectionalChannelInfo {
orig.clone()
}
/// When the last update to the channel direction was issued. /// When the last update to the channel direction was issued.
/// Value is opaque, as set in the announcement. /// Value is opaque, as set in the announcement.
#[no_mangle] #[no_mangle]
@ -600,7 +618,8 @@ impl RoutingFees {
impl Clone for RoutingFees { impl Clone for RoutingFees {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -612,7 +631,7 @@ pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees { pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
RoutingFees { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// Flat routing fee in satoshis /// Flat routing fee in satoshis
#[no_mangle] #[no_mangle]
@ -649,7 +668,7 @@ pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_milli
#[no_mangle] #[no_mangle]
pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ { pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::RoutingFees { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::RoutingFees { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -698,6 +717,24 @@ impl NodeAnnouncementInfo {
ret ret
} }
} }
impl Clone for NodeAnnouncementInfo {
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 NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
}
#[no_mangle]
pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
orig.clone()
}
/// Protocol features the node announced support for /// Protocol features the node announced support for
#[no_mangle] #[no_mangle]
pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::ln::features::NodeFeatures { pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::ln::features::NodeFeatures {
@ -798,7 +835,7 @@ pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) ->
#[no_mangle] #[no_mangle]
pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ { pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::NodeAnnouncementInfo { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::NodeAnnouncementInfo { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
@ -839,6 +876,24 @@ impl NodeInfo {
ret ret
} }
} }
impl Clone for NodeInfo {
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 NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
}
#[no_mangle]
pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
orig.clone()
}
/// All valid channels a node has announced /// All valid channels a node has announced
#[no_mangle] #[no_mangle]
pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) { pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
@ -902,7 +957,7 @@ pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_typ
#[no_mangle] #[no_mangle]
pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ { pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::NodeInfo { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::NodeInfo { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
#[no_mangle] #[no_mangle]
@ -916,7 +971,7 @@ pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c
#[no_mangle] #[no_mangle]
pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ { pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
/// Creates a new, empty, network graph. /// Creates a new, empty, network graph.
@ -937,7 +992,7 @@ pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBy
#[no_mangle] #[no_mangle]
pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ { pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_announcement(unsafe { &*msg.inner }, &bitcoin::secp256k1::Secp256k1::new()); let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_announcement(unsafe { &*msg.inner }, &bitcoin::secp256k1::Secp256k1::new());
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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
@ -949,7 +1004,7 @@ pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &mut Netw
#[no_mangle] #[no_mangle]
pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedNodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ { pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedNodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_unsigned_announcement(unsafe { &*msg.inner }); let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_unsigned_announcement(unsafe { &*msg.inner });
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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
@ -966,7 +1021,7 @@ pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg:
pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::ChannelAnnouncement, chain_access: *mut crate::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ { pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::ChannelAnnouncement, chain_access: *mut crate::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) }; let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_announcement(unsafe { &*msg.inner }, &local_chain_access, &bitcoin::secp256k1::Secp256k1::new()); let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_announcement(unsafe { &*msg.inner }, &local_chain_access, &bitcoin::secp256k1::Secp256k1::new());
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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
@ -981,7 +1036,7 @@ pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &mut N
pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedChannelAnnouncement, chain_access: *mut crate::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ { pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedChannelAnnouncement, chain_access: *mut crate::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) }; let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_unsigned_announcement(unsafe { &*msg.inner }, &local_chain_access); let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_unsigned_announcement(unsafe { &*msg.inner }, &local_chain_access);
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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
@ -1004,7 +1059,7 @@ pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkG
#[no_mangle] #[no_mangle]
pub extern "C" fn NetworkGraph_update_channel(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ { pub extern "C" fn NetworkGraph_update_channel(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel(unsafe { &*msg.inner }, &bitcoin::secp256k1::Secp256k1::new()); let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel(unsafe { &*msg.inner }, &bitcoin::secp256k1::Secp256k1::new());
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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }
@ -1015,7 +1070,7 @@ pub extern "C" fn NetworkGraph_update_channel(this_arg: &mut NetworkGraph, msg:
#[no_mangle] #[no_mangle]
pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ { pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_unsigned(unsafe { &*msg.inner }); let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_unsigned(unsafe { &*msg.inner });
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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }

View file

@ -48,7 +48,8 @@ impl RouteHop {
impl Clone for RouteHop { impl Clone for RouteHop {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -60,7 +61,7 @@ pub(crate) extern "C" fn RouteHop_clone_void(this_ptr: *const c_void) -> *mut c_
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop { pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop {
RouteHop { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The node_id of the node at this hop. /// The node_id of the node at this hop.
#[no_mangle] #[no_mangle]
@ -188,7 +189,8 @@ impl Route {
impl Clone for Route { impl Clone for Route {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -200,7 +202,7 @@ pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_voi
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Route_clone(orig: &Route) -> Route { pub extern "C" fn Route_clone(orig: &Route) -> Route {
Route { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the /// The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
/// last RouteHop in each path must be the same. /// last RouteHop in each path must be the same.
@ -232,7 +234,7 @@ pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types:
#[no_mangle] #[no_mangle]
pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ { pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ {
let res = crate::c_types::deserialize_obj(ser); let res = crate::c_types::deserialize_obj(ser);
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::router::Route { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::router::Route { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_res local_res
} }
@ -276,7 +278,8 @@ impl RouteHint {
impl Clone for RouteHint { impl Clone for RouteHint {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -288,7 +291,7 @@ pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint { pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
RouteHint { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// The node_id of the non-target end of the route /// The node_id of the non-target end of the route
#[no_mangle] #[no_mangle]
@ -377,7 +380,7 @@ pub extern "C" fn get_route(mut our_node_id: crate::c_types::PublicKey, network:
let mut local_first_hops_base = if first_hops == std::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { unsafe { &*item.inner } }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]); let mut local_first_hops_base = if first_hops == std::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { unsafe { &*item.inner } }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]);
let mut local_last_hops = Vec::new(); for mut item in last_hops.as_slice().iter() { local_last_hops.push( { unsafe { &*item.inner } }); }; let mut local_last_hops = Vec::new(); for mut item in last_hops.as_slice().iter() { local_last_hops.push( { unsafe { &*item.inner } }); };
let mut ret = lightning::routing::router::get_route(&our_node_id.into_rust(), unsafe { &*network.inner }, &target.into_rust(), local_first_hops, &local_last_hops[..], final_value_msat, final_cltv, logger); let mut ret = lightning::routing::router::get_route(&our_node_id.into_rust(), unsafe { &*network.inner }, &target.into_rust(), local_first_hops, &local_last_hops[..], final_value_msat, final_cltv, logger);
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::router::Route { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) }; let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::router::Route { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
local_ret local_ret
} }

View file

@ -48,7 +48,8 @@ impl ChannelHandshakeConfig {
impl Clone for ChannelHandshakeConfig { impl Clone for ChannelHandshakeConfig {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -60,7 +61,7 @@ pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_vo
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig { pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig {
ChannelHandshakeConfig { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// Confirmations we will wait for before considering the channel locked in. /// Confirmations we will wait for before considering the channel locked in.
/// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
@ -202,7 +203,8 @@ impl ChannelHandshakeLimits {
impl Clone for ChannelHandshakeLimits { impl Clone for ChannelHandshakeLimits {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -214,7 +216,7 @@ pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_vo
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits { pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits {
ChannelHandshakeLimits { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
/// only applies to inbound channels. /// only applies to inbound channels.
@ -475,7 +477,8 @@ impl ChannelConfig {
impl Clone for ChannelConfig { impl Clone for ChannelConfig {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -487,7 +490,7 @@ pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *m
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig { pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig {
ChannelConfig { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi. /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
/// This may be allowed to change at runtime in a later update, however doing so must result in /// This may be allowed to change at runtime in a later update, however doing so must result in
@ -644,7 +647,8 @@ impl UserConfig {
impl Clone for UserConfig { impl Clone for UserConfig {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())), inner: if self.inner.is_null() { std::ptr::null_mut() } else {
Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
is_owned: true, is_owned: true,
} }
} }
@ -656,7 +660,7 @@ pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig { pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig {
UserConfig { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true } orig.clone()
} }
/// Channel config that we propose to our counterparty. /// Channel config that we propose to our counterparty.
#[no_mangle] #[no_mangle]

View file

@ -174,7 +174,7 @@ pub enum ChannelMonitorUpdateErr {
/// means you tried to update a monitor for a different channel or the ChannelMonitorUpdate was /// means you tried to update a monitor for a different channel or the ChannelMonitorUpdate was
/// corrupted. /// corrupted.
/// Contains a developer-readable error message. /// Contains a developer-readable error message.
#[derive(Debug)] #[derive(Clone, Debug)]
pub struct MonitorUpdateError(pub &'static str); pub struct MonitorUpdateError(pub &'static str);
/// An event to be processed by the ChannelManager. /// An event to be processed by the ChannelManager.

View file

@ -514,7 +514,7 @@ pub struct ChannelDetails {
/// If a payment fails to send, it can be in one of several states. This enum is returned as the /// If a payment fails to send, it can be in one of several states. This enum is returned as the
/// Err() type describing which state the payment is in, see the description of individual enum /// Err() type describing which state the payment is in, see the description of individual enum
/// states for more. /// states for more.
#[derive(Debug)] #[derive(Clone, Debug)]
pub enum PaymentSendFailure { pub enum PaymentSendFailure {
/// A parameter which was passed to send_payment was invalid, preventing us from attempting to /// A parameter which was passed to send_payment was invalid, preventing us from attempting to
/// send the payment at all. No channel state has been changed or messages sent to peers, and /// send the payment at all. No channel state has been changed or messages sent to peers, and

View file

@ -33,6 +33,7 @@ use bitcoin::hash_types::{Txid, BlockHash};
use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
use std::{cmp, fmt}; use std::{cmp, fmt};
use std::fmt::Debug;
use std::io::Read; use std::io::Read;
use util::events::MessageSendEventsProvider; use util::events::MessageSendEventsProvider;
@ -44,7 +45,7 @@ use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret};
pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000; pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000;
/// An error in decoding a message or struct. /// An error in decoding a message or struct.
#[derive(Debug)] #[derive(Clone, Debug)]
pub enum DecodeError { pub enum DecodeError {
/// A version byte specified something we don't know how to handle. /// A version byte specified something we don't know how to handle.
/// Includes unknown realm byte in an OnionHopData packet /// Includes unknown realm byte in an OnionHopData packet
@ -60,7 +61,7 @@ pub enum DecodeError {
/// A length descriptor in the packet didn't describe the later data correctly /// A length descriptor in the packet didn't describe the later data correctly
BadLengthDescriptor, BadLengthDescriptor,
/// Error from std::io /// Error from std::io
Io(::std::io::Error), Io(::std::io::ErrorKind),
} }
/// An init message to be sent or received from a peer /// An init message to be sent or received from a peer
@ -674,6 +675,7 @@ pub enum ErrorAction {
} }
/// An Err type for failure to process messages. /// An Err type for failure to process messages.
#[derive(Clone)]
pub struct LightningError { pub struct LightningError {
/// A human-readable message describing the error /// A human-readable message describing the error
pub err: String, pub err: String,
@ -949,7 +951,7 @@ impl From<::std::io::Error> for DecodeError {
if e.kind() == ::std::io::ErrorKind::UnexpectedEof { if e.kind() == ::std::io::ErrorKind::UnexpectedEof {
DecodeError::ShortRead DecodeError::ShortRead
} else { } else {
DecodeError::Io(e) DecodeError::Io(e.kind())
} }
} }
} }

View file

@ -90,6 +90,7 @@ pub trait SocketDescriptor : cmp::Eq + hash::Hash + Clone {
/// Error for PeerManager errors. If you get one of these, you must disconnect the socket and /// Error for PeerManager errors. If you get one of these, you must disconnect the socket and
/// generate no further read_event/write_buffer_space_avail/socket_disconnected calls for the /// generate no further read_event/write_buffer_space_avail/socket_disconnected calls for the
/// descriptor. /// descriptor.
#[derive(Clone)]
pub struct PeerHandleError { pub struct PeerHandleError {
/// Used to indicate that we probably can't make any future connections to this peer, implying /// Used to indicate that we probably can't make any future connections to this peer, implying
/// we should go ahead and force-close any channels we have with it. /// we should go ahead and force-close any channels we have with it.

View file

@ -329,7 +329,7 @@ where
} }
} }
#[derive(PartialEq, Debug)] #[derive(Clone, PartialEq, Debug)]
/// Details about one direction of a channel. Received /// Details about one direction of a channel. Received
/// within a channel update. /// within a channel update.
pub struct DirectionalChannelInfo { pub struct DirectionalChannelInfo {
@ -441,7 +441,7 @@ impl Writeable for RoutingFees {
} }
} }
#[derive(PartialEq, Debug)] #[derive(Clone, PartialEq, Debug)]
/// Information received in the latest node_announcement from this node. /// Information received in the latest node_announcement from this node.
pub struct NodeAnnouncementInfo { pub struct NodeAnnouncementInfo {
/// Protocol features the node announced support for /// Protocol features the node announced support for
@ -507,7 +507,7 @@ impl Readable for NodeAnnouncementInfo {
} }
} }
#[derive(PartialEq)] #[derive(Clone, PartialEq)]
/// Details about a node in the network, known from the network announcement. /// Details about a node in the network, known from the network announcement.
pub struct NodeInfo { pub struct NodeInfo {
/// All valid channels a node has announced /// All valid channels a node has announced

View file

@ -13,6 +13,7 @@ use std::fmt;
/// Indicates an error on the client's part (usually some variant of attempting to use too-low or /// Indicates an error on the client's part (usually some variant of attempting to use too-low or
/// too-high values) /// too-high values)
#[derive(Clone)]
pub enum APIError { pub enum APIError {
/// Indicates the API was wholly misused (see err for more). Cases where these can be returned /// Indicates the API was wholly misused (see err for more). Cases where these can be returned
/// are documented, but generally indicates some precondition of a function was violated. /// are documented, but generally indicates some precondition of a function was violated.

View file

@ -718,7 +718,7 @@ macro_rules! impl_consensus_ser {
match consensus::encode::Decodable::consensus_decode(r) { match consensus::encode::Decodable::consensus_decode(r) {
Ok(t) => Ok(t), Ok(t) => Ok(t),
Err(consensus::encode::Error::Io(ref e)) if e.kind() == ::std::io::ErrorKind::UnexpectedEof => Err(DecodeError::ShortRead), Err(consensus::encode::Error::Io(ref e)) if e.kind() == ::std::io::ErrorKind::UnexpectedEof => Err(DecodeError::ShortRead),
Err(consensus::encode::Error::Io(e)) => Err(DecodeError::Io(e)), Err(consensus::encode::Error::Io(e)) => Err(DecodeError::Io(e.kind())),
Err(_) => Err(DecodeError::InvalidValue), Err(_) => Err(DecodeError::InvalidValue),
} }
} }