From: Matt Corallo Date: Mon, 8 Mar 2021 18:43:00 +0000 (-0500) Subject: Drop C bindings (which are now in a separate repo) X-Git-Tag: v0.0.13~3^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=d793a2fc7adfd12f275297f1b4e6e9598302d7a4;p=rust-lightning Drop C bindings (which are now in a separate repo) This allows us to drop the usually-failing C bindings CI check, and makes Github code search more useful by dropping redundant things. --- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 628d620a5..09cef0ffc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -206,46 +206,6 @@ jobs: - name: Run fuzzers run: cd fuzz && ./ci-fuzz.sh - check_bindings: - runs-on: ubuntu-latest - # Ubuntu's version of rustc uses its own LLVM instead of being a real native package. - # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS. - # We further (temporarily) use Debian experimental since testing links rustc against the - # brand-new llvm-10, but clang/llvm still default to LLVM 9. - container: debian:experimental - env: - TOOLCHAIN: stable - steps: - - name: Install native Rust toolchain, Valgrind, and build utilitis - run: | - echo 'Package: llvm llvm-runtime clang lld' > /etc/apt/preferences.d/99-llvm10 - echo 'Pin: release n=experimental' >> /etc/apt/preferences.d/99-llvm10 - echo 'Pin-Priority: 995' >> /etc/apt/preferences.d/99-llvm10 - apt-get update - apt-get -y dist-upgrade - apt-get -y install cargo valgrind lld git g++ clang - - name: Checkout source code - uses: actions/checkout@v2 - - name: Sanity test bindings - working-directory: lightning-c-bindings - run: cargo check - - name: Install cbindgen - run: cargo install --force cbindgen - - name: Rebuild bindings, and check the sample app builds + links - run: ./genbindings.sh - - name: Check that the latest bindings are in git - run: | - if [ "$(git diff)" != "" ]; then - # cbindgen's bindings output order can be FS-dependant, so check that the lines are all the same: - mv lightning-c-bindings/include/lightning.h lightning-c-bindings/include/lightning.h.new - git checkout lightning-c-bindings/include/lightning.h - cat lightning-c-bindings/include/lightning.h | grep -v "Generated with cbindgen:[0-9\.]*" | sort > lightning-c-bindings/include/lightning.h.sorted - cat lightning-c-bindings/include/lightning.h.new | grep -v "Generated with cbindgen:[0-9\.]*" | sort > lightning-c-bindings/include/lightning.h.new.sorted - diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted - [ "$(diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted)" != "" ] && exit 2 - git diff --exit-code - fi - linting: runs-on: ubuntu-latest env: diff --git a/c-bindings-gen/Cargo.toml b/c-bindings-gen/Cargo.toml deleted file mode 100644 index dedeade8f..000000000 --- a/c-bindings-gen/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "c-bindings-gen" -version = "0.0.1" -authors = ["Matt Corallo"] -edition = "2018" - -[dependencies] -syn = { version = "1", features = ["full", "extra-traits"] } -proc-macro2 = "1" - -[profile.release] -debug = true - -# We're not in the workspace as we're just a binary code generator: -[workspace] diff --git a/c-bindings-gen/README.md b/c-bindings-gen/README.md deleted file mode 100644 index 8377adc4b..000000000 --- a/c-bindings-gen/README.md +++ /dev/null @@ -1,14 +0,0 @@ -LDK C Bindings Generator -======================== - -This program parses a Rust crate's AST from a single lib.rs passed in on stdin and generates a -second crate which is C-callable (and carries appropriate annotations for cbindgen). It is usually -invoked via the `genbindings.sh` script in the top-level directory, which converts the lightning -crate into a single file with a call to -`RUSTC_BOOTSTRAP=1 cargo rustc --profile=check -- -Zunstable-options --pretty=expanded`. - -`genbindings.sh` requires that you have a rustc installed with the `wasm32-wasi` target available -(eg via the `libstd-rust-dev-wasm32` package on Debian or `rustup target add wasm32-wasi` for those -using rustup), cbindgen installed via `cargo install cbindgen` and in your `PATH`, and `clang`, -`clang++`, `gcc`, and `g++` available in your `PATH`. It uses `valgrind` if it is available to test -the generated bindings thoroughly for memory management issues. diff --git a/c-bindings-gen/src/blocks.rs b/c-bindings-gen/src/blocks.rs deleted file mode 100644 index dd57a82b5..000000000 --- a/c-bindings-gen/src/blocks.rs +++ /dev/null @@ -1,601 +0,0 @@ -//! Printing logic for basic blocks of Rust-mapped code - parts of functions and declarations but -//! not the full mapping logic. - -use std::fs::File; -use std::io::Write; -use proc_macro2::{TokenTree, Span}; - -use crate::types::*; - -/// Writes out a C++ wrapper class for the given type, which contains various utilities to access -/// the underlying C-mapped type safely avoiding some common memory management issues by handling -/// resource-freeing and prevending accidental raw copies. -pub fn write_cpp_wrapper(cpp_header_file: &mut File, ty: &str, has_destructor: bool) { - writeln!(cpp_header_file, "class {} {{", ty).unwrap(); - writeln!(cpp_header_file, "private:").unwrap(); - writeln!(cpp_header_file, "\tLDK{} self;", ty).unwrap(); - writeln!(cpp_header_file, "public:").unwrap(); - writeln!(cpp_header_file, "\t{}(const {}&) = delete;", ty, ty).unwrap(); - writeln!(cpp_header_file, "\t{}({}&& o) : self(o.self) {{ memset(&o, 0, sizeof({})); }}", ty, ty, ty).unwrap(); - writeln!(cpp_header_file, "\t{}(LDK{}&& m_self) : self(m_self) {{ memset(&m_self, 0, sizeof(LDK{})); }}", ty, ty, ty).unwrap(); - writeln!(cpp_header_file, "\toperator LDK{}() && {{ LDK{} res = self; memset(&self, 0, sizeof(LDK{})); return res; }}", ty, ty, ty).unwrap(); - if has_destructor { - writeln!(cpp_header_file, "\t~{}() {{ {}_free(self); }}", ty, ty).unwrap(); - writeln!(cpp_header_file, "\t{}& operator=({}&& o) {{ {}_free(self); self = o.self; memset(&o, 0, sizeof({})); return *this; }}", ty, ty, ty, ty).unwrap(); - } else { - writeln!(cpp_header_file, "\t{}& operator=({}&& o) {{ self = o.self; memset(&o, 0, sizeof({})); return *this; }}", ty, ty, ty).unwrap(); - } - writeln!(cpp_header_file, "\tLDK{}* operator &() {{ return &self; }}", ty).unwrap(); - writeln!(cpp_header_file, "\tLDK{}* operator ->() {{ return &self; }}", ty).unwrap(); - writeln!(cpp_header_file, "\tconst LDK{}* operator &() const {{ return &self; }}", ty).unwrap(); - writeln!(cpp_header_file, "\tconst LDK{}* operator ->() const {{ return &self; }}", ty).unwrap(); - writeln!(cpp_header_file, "}};").unwrap(); -} - -/// Writes out a C-callable concrete Result struct and utility methods -pub fn write_result_block(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> 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 struct and utility methods -pub fn write_vec_block(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> 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: &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 -pub fn writeln_docs(w: &mut W, attrs: &[syn::Attribute], prefix: &str) { - 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::Punct(c) if c.as_char() == '=' => { - // syn gets '=' from '///' or '//!' as it is syntax for #[doc = ""] - }, - TokenTree::Group(_) => continue, // eg #[derive()] - _ => unimplemented!(), - } - } else { continue; } - match attr.style { - syn::AttrStyle::Inner(_) => { - match token_iter.next().unwrap() { - TokenTree::Literal(lit) => { - // Drop the first and last chars from lit as they are always " - let doc = format!("{}", lit); - writeln!(w, "{}//!{}", prefix, &doc[1..doc.len() - 1]).unwrap(); - }, - _ => unimplemented!(), - } - }, - syn::AttrStyle::Outer => { - match token_iter.next().unwrap() { - TokenTree::Literal(lit) => { - // Drop the first and last chars from lit as they are always " - let doc = format!("{}", lit); - writeln!(w, "{}///{}", prefix, &doc[1..doc.len() - 1]).unwrap(); - }, - _ => unimplemented!(), - } - }, - } - } -} - -/// Print the parameters in a method declaration, starting after the open parenthesis, through and -/// including the closing parenthesis and return value, but not including the open bracket or any -/// trailing semicolons. -/// -/// Usable both for a function definition and declaration. -/// -/// this_param is used when returning Self or accepting a self parameter, and should be the -/// concrete, mapped type. -pub fn write_method_params(w: &mut W, sig: &syn::Signature, this_param: &str, types: &mut TypeResolver, generics: Option<&GenericTypes>, self_ptr: bool, fn_decl: bool) { - if sig.constness.is_some() || sig.asyncness.is_some() || sig.unsafety.is_some() || - sig.abi.is_some() || sig.variadic.is_some() { - unimplemented!(); - } - if sig.generics.lt_token.is_some() { - for generic in sig.generics.params.iter() { - match generic { - syn::GenericParam::Type(_)|syn::GenericParam::Lifetime(_) => { - // We ignore these, if they're not on skipped args, we'll blow up - // later, and lifetimes we just hope the C client enforces. - }, - _ => unimplemented!(), - } - } - } - - let mut first_arg = true; - let mut num_unused = 0; - for inp in sig.inputs.iter() { - match inp { - syn::FnArg::Receiver(recv) => { - if !recv.attrs.is_empty() || recv.reference.is_none() { unimplemented!(); } - write!(w, "this_arg: {}{}", - match (self_ptr, recv.mutability.is_some()) { - (true, true) => "*mut ", - (true, false) => "*const ", - (false, true) => "&mut ", - (false, false) => "&", - }, this_param).unwrap(); - assert!(first_arg); - first_arg = false; - }, - syn::FnArg::Typed(arg) => { - if types.skip_arg(&*arg.ty, generics) { continue; } - if !arg.attrs.is_empty() { unimplemented!(); } - // First get the c type so that we can check if it ends up being a reference: - let mut c_type = Vec::new(); - types.write_c_type(&mut c_type, &*arg.ty, generics, false); - match &*arg.pat { - syn::Pat::Ident(ident) => { - if !ident.attrs.is_empty() || ident.subpat.is_some() { - unimplemented!(); - } - write!(w, "{}{}{}: ", if first_arg { "" } else { ", " }, if !fn_decl || c_type[0] == '&' as u8 || c_type[0] == '*' as u8 { "" } else { "mut " }, ident.ident).unwrap(); - first_arg = false; - }, - syn::Pat::Wild(wild) => { - if !wild.attrs.is_empty() { unimplemented!(); } - write!(w, "{}unused_{}: ", if first_arg { "" } else { ", " }, num_unused).unwrap(); - num_unused += 1; - }, - _ => unimplemented!(), - } - w.write(&c_type).unwrap(); - } - } - } - write!(w, ")").unwrap(); - match &sig.output { - syn::ReturnType::Type(_, rtype) => { - write!(w, " -> ").unwrap(); - if let Some(mut remaining_path) = first_seg_self(&*rtype) { - if remaining_path.next().is_none() { - write!(w, "{}", this_param).unwrap(); - return; - } - } - if let syn::Type::Reference(r) = &**rtype { - // We can't return a reference, cause we allocate things on the stack. - types.write_c_type(w, &*r.elem, generics, true); - } else { - types.write_c_type(w, &*rtype, generics, true); - } - }, - _ => {}, - } -} - -/// Print the main part of a method declaration body, starting with a newline after the function -/// open bracket and converting each function parameter to or from C-mapped types. Ends with "let -/// mut ret = " assuming the next print will be the unmapped Rust function to call followed by the -/// parameters we mapped to/from C here. -pub fn write_method_var_decl_body(w: &mut W, sig: &syn::Signature, extra_indent: &str, types: &TypeResolver, generics: Option<&GenericTypes>, to_c: bool) { - let mut num_unused = 0; - for inp in sig.inputs.iter() { - match inp { - syn::FnArg::Receiver(_) => {}, - syn::FnArg::Typed(arg) => { - if types.skip_arg(&*arg.ty, generics) { continue; } - if !arg.attrs.is_empty() { unimplemented!(); } - macro_rules! write_new_var { - ($ident: expr, $ty: expr) => { - if to_c { - if types.write_to_c_conversion_new_var(w, &$ident, &$ty, generics, false) { - write!(w, "\n\t{}", extra_indent).unwrap(); - } - } else { - if types.write_from_c_conversion_new_var(w, &$ident, &$ty, generics) { - write!(w, "\n\t{}", extra_indent).unwrap(); - } - } - } - } - match &*arg.pat { - syn::Pat::Ident(ident) => { - if !ident.attrs.is_empty() || ident.subpat.is_some() { - unimplemented!(); - } - write_new_var!(ident.ident, *arg.ty); - }, - syn::Pat::Wild(w) => { - if !w.attrs.is_empty() { unimplemented!(); } - write_new_var!(syn::Ident::new(&format!("unused_{}", num_unused), Span::call_site()), *arg.ty); - num_unused += 1; - }, - _ => unimplemented!(), - } - } - } - } - match &sig.output { - syn::ReturnType::Type(_, _) => { - write!(w, "let mut ret = ").unwrap(); - }, - _ => {}, - } -} - -/// Prints the parameters in a method call, starting after the open parenthesis and ending with a -/// final return statement returning the method's result. Should be followed by a single closing -/// bracket. -/// -/// The return value is expected to be bound to a variable named `ret` which is available after a -/// method-call-ending semicolon. -pub fn write_method_call_params(w: &mut W, sig: &syn::Signature, extra_indent: &str, types: &TypeResolver, generics: Option<&GenericTypes>, this_type: &str, to_c: bool) { - let mut first_arg = true; - let mut num_unused = 0; - for inp in sig.inputs.iter() { - match inp { - syn::FnArg::Receiver(recv) => { - if !recv.attrs.is_empty() || recv.reference.is_none() { unimplemented!(); } - if to_c { - write!(w, "self.this_arg").unwrap(); - first_arg = false; - } - }, - syn::FnArg::Typed(arg) => { - if types.skip_arg(&*arg.ty, generics) { - if !to_c { - if !first_arg { - write!(w, ", ").unwrap(); - } - first_arg = false; - types.no_arg_to_rust(w, &*arg.ty, generics); - } - continue; - } - if !arg.attrs.is_empty() { unimplemented!(); } - macro_rules! write_ident { - ($ident: expr) => { - if !first_arg { - write!(w, ", ").unwrap(); - } - first_arg = false; - if to_c { - types.write_to_c_conversion_inline_prefix(w, &*arg.ty, generics, false); - write!(w, "{}", $ident).unwrap(); - types.write_to_c_conversion_inline_suffix(w, &*arg.ty, generics, false); - } else { - types.write_from_c_conversion_prefix(w, &*arg.ty, generics); - write!(w, "{}", $ident).unwrap(); - types.write_from_c_conversion_suffix(w, &*arg.ty, generics); - } - } - } - match &*arg.pat { - syn::Pat::Ident(ident) => { - if !ident.attrs.is_empty() || ident.subpat.is_some() { - unimplemented!(); - } - write_ident!(ident.ident); - }, - syn::Pat::Wild(w) => { - if !w.attrs.is_empty() { unimplemented!(); } - write_ident!(format!("unused_{}", num_unused)); - num_unused += 1; - }, - _ => unimplemented!(), - } - } - } - } - write!(w, ")").unwrap(); - match &sig.output { - syn::ReturnType::Type(_, rtype) => { - write!(w, ";\n\t{}", extra_indent).unwrap(); - - let self_segs_iter = first_seg_self(&*rtype); - if to_c && first_seg_self(&*rtype).is_some() { - // Assume rather blindly that we're returning an associated trait from a C fn call to a Rust trait object. - write!(w, "ret").unwrap(); - } else if !to_c && self_segs_iter.is_some() && self_segs_iter.unwrap().next().is_none() { - // If we're returning "Self" (and not "Self::X"), just do it manually - write!(w, "{} {{ inner: Box::into_raw(Box::new(ret)), is_owned: true }}", this_type).unwrap(); - } else if to_c { - let new_var = types.write_from_c_conversion_new_var(w, &syn::Ident::new("ret", Span::call_site()), rtype, generics); - if new_var { - write!(w, "\n\t{}", extra_indent).unwrap(); - } - types.write_from_c_conversion_prefix(w, &*rtype, generics); - write!(w, "ret").unwrap(); - types.write_from_c_conversion_suffix(w, &*rtype, generics); - } else { - let ret_returned = if let syn::Type::Reference(_) = &**rtype { true } else { false }; - let new_var = types.write_to_c_conversion_new_var(w, &syn::Ident::new("ret", Span::call_site()), &rtype, generics, true); - if new_var { - write!(w, "\n\t{}", extra_indent).unwrap(); - } - types.write_to_c_conversion_inline_prefix(w, &rtype, generics, true); - write!(w, "{}ret", if ret_returned && !new_var { "*" } else { "" }).unwrap(); - types.write_to_c_conversion_inline_suffix(w, &rtype, generics, true); - } - } - _ => {}, - } -} - -/// Prints concrete generic parameters for a struct/trait/function, including the less-than and -/// greater-than symbols, if any generic parameters are defined. -pub fn maybe_write_generics(w: &mut W, generics: &syn::Generics, types: &TypeResolver, concrete_lifetimes: bool) { - let mut gen_types = GenericTypes::new(); - assert!(gen_types.learn_generics(generics, types)); - if !generics.params.is_empty() { - write!(w, "<").unwrap(); - for (idx, generic) in generics.params.iter().enumerate() { - match generic { - syn::GenericParam::Type(type_param) => { - let mut printed_param = false; - for bound in type_param.bounds.iter() { - if let syn::TypeParamBound::Trait(trait_bound) = bound { - assert_simple_bound(&trait_bound); - write!(w, "{}{}", if idx != 0 { ", " } else { "" }, gen_types.maybe_resolve_ident(&type_param.ident).unwrap()).unwrap(); - if printed_param { - unimplemented!("Can't print generic params that have multiple non-lifetime bounds"); - } - printed_param = true; - } - } - }, - syn::GenericParam::Lifetime(lt) => { - if concrete_lifetimes { - write!(w, "'static").unwrap(); - } else { - write!(w, "{}'{}", if idx != 0 { ", " } else { "" }, lt.lifetime.ident).unwrap(); - } - }, - _ => unimplemented!(), - } - } - write!(w, ">").unwrap(); - } -} - - diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs deleted file mode 100644 index a0acfc65d..000000000 --- a/c-bindings-gen/src/main.rs +++ /dev/null @@ -1,1615 +0,0 @@ -//! Converts a rust crate into a rust crate containing a number of C-exported wrapper functions and -//! classes (which is exportable using cbindgen). -//! In general, supports convering: -//! * structs as a pointer to the underlying type (either owned or not owned), -//! * traits as a void-ptr plus a jump table, -//! * enums as an equivalent enum with all the inner fields mapped to the mapped types, -//! * certain containers (tuples, slices, Vecs, Options, and Results currently) to a concrete -//! version of a defined container template. -//! -//! It also generates relevant memory-management functions and free-standing functions with -//! parameters mapped. - -use std::collections::{HashMap, hash_map, HashSet}; -use std::env; -use std::fs::File; -use std::io::{Read, Write}; -use std::process; - -use proc_macro2::{TokenTree, TokenStream, Span}; - -mod types; -mod blocks; -use types::*; -use blocks::*; - -// ************************************* -// *** Manually-expanded conversions *** -// ************************************* - -/// Because we don't expand macros, any code that we need to generated based on their contents has -/// to be completely manual. In this case its all just serialization, so its not too hard. -fn convert_macro(w: &mut W, macro_path: &syn::Path, stream: &TokenStream, types: &TypeResolver) { - assert_eq!(macro_path.segments.len(), 1); - match &format!("{}", macro_path.segments.iter().next().unwrap().ident) as &str { - "impl_writeable" | "impl_writeable_len_match" => { - let struct_for = if let TokenTree::Ident(i) = stream.clone().into_iter().next().unwrap() { i } else { unimplemented!(); }; - if let Some(s) = types.maybe_resolve_ident(&struct_for) { - if !types.crate_types.opaques.get(&s).is_some() { return; } - writeln!(w, "#[no_mangle]").unwrap(); - writeln!(w, "pub extern \"C\" fn {}_write(obj: &{}) -> crate::c_types::derived::CVec_u8Z {{", struct_for, struct_for).unwrap(); - writeln!(w, "\tcrate::c_types::serialize_obj(unsafe {{ &(*(*obj).inner) }})").unwrap(); - writeln!(w, "}}").unwrap(); - writeln!(w, "#[no_mangle]").unwrap(); - writeln!(w, "pub(crate) extern \"C\" fn {}_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {{", struct_for).unwrap(); - writeln!(w, "\tcrate::c_types::serialize_obj(unsafe {{ &*(obj as *const native{}) }})", struct_for).unwrap(); - writeln!(w, "}}").unwrap(); - writeln!(w, "#[no_mangle]").unwrap(); - writeln!(w, "pub extern \"C\" fn {}_read(ser: crate::c_types::u8slice) -> {} {{", struct_for, struct_for).unwrap(); - writeln!(w, "\tif let Ok(res) = crate::c_types::deserialize_obj(ser) {{").unwrap(); - writeln!(w, "\t\t{} {{ inner: Box::into_raw(Box::new(res)), is_owned: true }}", struct_for).unwrap(); - writeln!(w, "\t}} else {{").unwrap(); - writeln!(w, "\t\t{} {{ inner: std::ptr::null_mut(), is_owned: true }}", struct_for).unwrap(); - writeln!(w, "\t}}\n}}").unwrap(); - } - }, - _ => {}, - } -} - -/// Convert "impl trait_path for for_ty { .. }" for manually-mapped types (ie (de)serialization) -fn maybe_convert_trait_impl(w: &mut W, trait_path: &syn::Path, for_ty: &syn::Type, types: &mut TypeResolver, generics: &GenericTypes) { - if let Some(t) = types.maybe_resolve_path(&trait_path, Some(generics)) { - let for_obj; - let full_obj_path; - let mut has_inner = false; - if let syn::Type::Path(ref p) = for_ty { - if let Some(ident) = single_ident_generic_path_to_ident(&p.path) { - for_obj = format!("{}", ident); - full_obj_path = for_obj.clone(); - has_inner = types.c_type_has_inner_from_path(&types.resolve_path(&p.path, Some(generics))); - } else { return; } - } else { - // We assume that anything that isn't a Path is somehow a generic that ends up in our - // derived-types module. - let mut for_obj_vec = Vec::new(); - types.write_c_type(&mut for_obj_vec, for_ty, Some(generics), false); - full_obj_path = String::from_utf8(for_obj_vec).unwrap(); - assert!(full_obj_path.starts_with(TypeResolver::generated_container_path())); - for_obj = full_obj_path[TypeResolver::generated_container_path().len() + 2..].into(); - } - - match &t as &str { - "util::ser::Writeable" => { - writeln!(w, "#[no_mangle]").unwrap(); - writeln!(w, "pub extern \"C\" fn {}_write(obj: &{}) -> crate::c_types::derived::CVec_u8Z {{", for_obj, full_obj_path).unwrap(); - - let ref_type = syn::Type::Reference(syn::TypeReference { - and_token: syn::Token!(&)(Span::call_site()), lifetime: None, mutability: None, - elem: Box::new(for_ty.clone()) }); - assert!(!types.write_from_c_conversion_new_var(w, &syn::Ident::new("obj", Span::call_site()), &ref_type, Some(generics))); - - write!(w, "\tcrate::c_types::serialize_obj(").unwrap(); - types.write_from_c_conversion_prefix(w, &ref_type, Some(generics)); - write!(w, "unsafe {{ &*obj }}").unwrap(); - types.write_from_c_conversion_suffix(w, &ref_type, Some(generics)); - writeln!(w, ")").unwrap(); - - writeln!(w, "}}").unwrap(); - if has_inner { - writeln!(w, "#[no_mangle]").unwrap(); - writeln!(w, "pub(crate) extern \"C\" fn {}_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {{", for_obj).unwrap(); - writeln!(w, "\tcrate::c_types::serialize_obj(unsafe {{ &*(obj as *const native{}) }})", for_obj).unwrap(); - writeln!(w, "}}").unwrap(); - } - }, - "util::ser::Readable"|"util::ser::ReadableArgs" => { - // Create the Result syn::Type - let mut err_segs = syn::punctuated::Punctuated::new(); - err_segs.push(syn::PathSegment { ident: syn::Ident::new("ln", Span::call_site()), arguments: syn::PathArguments::None }); - err_segs.push(syn::PathSegment { ident: syn::Ident::new("msgs", Span::call_site()), arguments: syn::PathArguments::None }); - err_segs.push(syn::PathSegment { ident: syn::Ident::new("DecodeError", Span::call_site()), arguments: syn::PathArguments::None }); - let mut args = syn::punctuated::Punctuated::new(); - args.push(syn::GenericArgument::Type(for_ty.clone())); - args.push(syn::GenericArgument::Type(syn::Type::Path(syn::TypePath { - qself: None, path: syn::Path { - leading_colon: Some(syn::Token![::](Span::call_site())), segments: err_segs, - } - }))); - let mut res_segs = syn::punctuated::Punctuated::new(); - res_segs.push(syn::PathSegment { - ident: syn::Ident::new("Result", Span::call_site()), - arguments: syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments { - colon2_token: None, lt_token: syn::Token![<](Span::call_site()), args, gt_token: syn::Token![>](Span::call_site()), - }) - }); - let res_ty = syn::Type::Path(syn::TypePath { qself: None, path: syn::Path { - leading_colon: None, segments: res_segs } }); - - writeln!(w, "#[no_mangle]").unwrap(); - write!(w, "pub extern \"C\" fn {}_read(ser: crate::c_types::u8slice", for_obj).unwrap(); - - let mut arg_conv = Vec::new(); - if t == "util::ser::ReadableArgs" { - write!(w, ", arg: ").unwrap(); - assert!(trait_path.leading_colon.is_none()); - let args_seg = trait_path.segments.iter().last().unwrap(); - assert_eq!(format!("{}", args_seg.ident), "ReadableArgs"); - if let syn::PathArguments::AngleBracketed(args) = &args_seg.arguments { - assert_eq!(args.args.len(), 1); - if let syn::GenericArgument::Type(args_ty) = args.args.iter().next().unwrap() { - types.write_c_type(w, args_ty, Some(generics), false); - - assert!(!types.write_from_c_conversion_new_var(&mut arg_conv, &syn::Ident::new("arg", Span::call_site()), &args_ty, Some(generics))); - - write!(&mut arg_conv, "\tlet arg_conv = ").unwrap(); - types.write_from_c_conversion_prefix(&mut arg_conv, &args_ty, Some(generics)); - write!(&mut arg_conv, "arg").unwrap(); - types.write_from_c_conversion_suffix(&mut arg_conv, &args_ty, Some(generics)); - } else { unreachable!(); } - } else { unreachable!(); } - } - write!(w, ") -> ").unwrap(); - types.write_c_type(w, &res_ty, Some(generics), false); - writeln!(w, " {{").unwrap(); - - if t == "util::ser::ReadableArgs" { - w.write(&arg_conv).unwrap(); - write!(w, ";\n\tlet res: ").unwrap(); - // At least in one case we need type annotations here, so provide them. - types.write_rust_type(w, Some(generics), &res_ty); - writeln!(w, " = crate::c_types::deserialize_obj_arg(ser, arg_conv);").unwrap(); - } else { - writeln!(w, "\tlet res = crate::c_types::deserialize_obj(ser);").unwrap(); - } - write!(w, "\t").unwrap(); - if types.write_to_c_conversion_new_var(w, &syn::Ident::new("res", Span::call_site()), &res_ty, Some(generics), false) { - write!(w, "\n\t").unwrap(); - } - types.write_to_c_conversion_inline_prefix(w, &res_ty, Some(generics), false); - write!(w, "res").unwrap(); - types.write_to_c_conversion_inline_suffix(w, &res_ty, Some(generics), false); - writeln!(w, "\n}}").unwrap(); - }, - _ => {}, - } - } -} - -/// Convert "TraitA : TraitB" to a single function name and return type. -/// -/// This is (obviously) somewhat over-specialized and only useful for TraitB's that only require a -/// single function (eg for serialization). -fn convert_trait_impl_field(trait_path: &str) -> (String, &'static str) { - match trait_path { - "util::ser::Writeable" => ("write".to_owned(), "crate::c_types::derived::CVec_u8Z"), - _ => unimplemented!(), - } -} - -/// Companion to convert_trait_impl_field, write an assignment for the function defined by it for -/// `for_obj` which implements the the trait at `trait_path`. -fn write_trait_impl_field_assign(w: &mut W, trait_path: &str, for_obj: &syn::Ident) { - match trait_path { - "util::ser::Writeable" => { - writeln!(w, "\t\twrite: {}_write_void,", for_obj).unwrap(); - }, - _ => unimplemented!(), - } -} - -/// Write out the impl block for a defined trait struct which has a supertrait -fn do_write_impl_trait(w: &mut W, trait_path: &str, trait_name: &syn::Ident, for_obj: &str) { - match trait_path { - "util::events::MessageSendEventsProvider" => { - writeln!(w, "impl lightning::{} for {} {{", trait_path, for_obj).unwrap(); - writeln!(w, "\tfn get_and_clear_pending_msg_events(&self) -> Vec {{").unwrap(); - writeln!(w, "\t\t::get_and_clear_pending_msg_events(&self.{})", trait_path, trait_path, trait_name).unwrap(); - writeln!(w, "\t}}\n}}").unwrap(); - }, - "util::ser::Writeable" => { - writeln!(w, "impl lightning::{} for {} {{", trait_path, for_obj).unwrap(); - writeln!(w, "\tfn write(&self, w: &mut W) -> Result<(), ::std::io::Error> {{").unwrap(); - writeln!(w, "\t\tlet vec = (self.write)(self.this_arg);").unwrap(); - writeln!(w, "\t\tw.write_all(vec.as_slice())").unwrap(); - writeln!(w, "\t}}\n}}").unwrap(); - }, - _ => panic!(), - } -} - -// ******************************* -// *** Per-Type Printing Logic *** -// ******************************* - -macro_rules! walk_supertraits { ($t: expr, $types: expr, ($( $pat: pat => $e: expr),*) ) => { { - if $t.colon_token.is_some() { - for st in $t.supertraits.iter() { - match st { - syn::TypeParamBound::Trait(supertrait) => { - if supertrait.paren_token.is_some() || supertrait.lifetimes.is_some() { - unimplemented!(); - } - // 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. - let types_opt: Option<&TypeResolver> = $types; - if let Some(types) = types_opt { - 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; - } - } - if let Some(ident) = supertrait.path.get_ident() { - match (&format!("{}", ident) as &str, &ident) { - $( $pat => $e, )* - } - } else if types_opt.is_some() { - panic!("Supertrait unresolvable and not single-ident"); - } - }, - syn::TypeParamBound::Lifetime(_) => unimplemented!(), - } - } - } -} } } - -/// Prints a C-mapped trait object containing a void pointer and a jump table for each function in -/// the original trait. -/// Implements the native Rust trait and relevant parent traits for the new C-mapped trait. -/// -/// Finally, implements Deref for MappedTrait which allows its use in types which need -/// a concrete Deref to the Rust trait. -fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, types: &mut TypeResolver<'b, 'a>, extra_headers: &mut File, cpp_headers: &mut File) { - let trait_name = format!("{}", t.ident); - match export_status(&t.attrs) { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => return, - } - writeln_docs(w, &t.attrs, ""); - - let mut gen_types = GenericTypes::new(); - assert!(gen_types.learn_generics(&t.generics, types)); - gen_types.learn_associated_types(&t, types); - - writeln!(w, "#[repr(C)]\npub struct {} {{", trait_name).unwrap(); - writeln!(w, "\tpub this_arg: *mut c_void,").unwrap(); - let mut generated_fields = Vec::new(); // Every field's name except this_arg, used in Clone generation - for item in t.items.iter() { - match item { - &syn::TraitItem::Method(ref m) => { - match export_status(&m.attrs) { - ExportStatus::NoExport => { - // NoExport in this context means we'll hit an unimplemented!() at runtime, - // so bail out. - unimplemented!(); - }, - ExportStatus::Export => {}, - ExportStatus::TestOnly => continue, - } - if m.default.is_some() { unimplemented!(); } - - gen_types.push_ctx(); - assert!(gen_types.learn_generics(&m.sig.generics, types)); - - writeln_docs(w, &m.attrs, "\t"); - - if let syn::ReturnType::Type(_, rtype) = &m.sig.output { - if let syn::Type::Reference(r) = &**rtype { - // We have to do quite a dance for trait functions which return references - // - they ultimately require us to have a native Rust object stored inside - // our concrete trait to return a reference to. However, users may wish to - // update the value to be returned each time the function is called (or, to - // make C copies of Rust impls equivalent, we have to be able to). - // - // Thus, we store a copy of the C-mapped type (which is just a pointer to - // the Rust type and a flag to indicate whether deallocation needs to - // happen) as well as provide an Option<>al function pointer which is - // called when the trait method is called which allows updating on the fly. - write!(w, "\tpub {}: ", m.sig.ident).unwrap(); - generated_fields.push(format!("{}", m.sig.ident)); - types.write_c_type(w, &*r.elem, Some(&gen_types), false); - writeln!(w, ",").unwrap(); - writeln!(w, "\t/// Fill in the {} field as a reference to it will be given to Rust after this returns", m.sig.ident).unwrap(); - writeln!(w, "\t/// Note that this takes a pointer to this object, not the this_ptr like other methods do").unwrap(); - writeln!(w, "\t/// This function pointer may be NULL if {} is filled in when this object is created and never needs updating.", m.sig.ident).unwrap(); - writeln!(w, "\tpub set_{}: Option,", m.sig.ident, trait_name).unwrap(); - generated_fields.push(format!("set_{}", m.sig.ident)); - // Note that cbindgen will now generate - // typedef struct Thing {..., set_thing: (const Thing*), ...} Thing; - // which does not compile since Thing is not defined before it is used. - writeln!(extra_headers, "struct LDK{};", trait_name).unwrap(); - writeln!(extra_headers, "typedef struct LDK{} LDK{};", trait_name, trait_name).unwrap(); - gen_types.pop_ctx(); - continue; - } - // Sadly, this currently doesn't do what we want, but it should be easy to get - // cbindgen to support it. See https://github.com/eqrion/cbindgen/issues/531 - writeln!(w, "\t#[must_use]").unwrap(); - } - - write!(w, "\tpub {}: extern \"C\" fn (", m.sig.ident).unwrap(); - generated_fields.push(format!("{}", m.sig.ident)); - write_method_params(w, &m.sig, "c_void", types, Some(&gen_types), true, false); - writeln!(w, ",").unwrap(); - - gen_types.pop_ctx(); - }, - &syn::TraitItem::Type(_) => {}, - _ => unimplemented!(), - } - } - // Add functions which may be required for supertrait implementations. - walk_supertraits!(t, Some(&types), ( - ("Clone", _) => { - writeln!(w, "\tpub clone: Option *mut c_void>,").unwrap(); - generated_fields.push("clone".to_owned()); - }, - ("std::cmp::Eq", _) => { - writeln!(w, "\tpub eq: extern \"C\" fn (this_arg: *const c_void, other_arg: &{}) -> bool,", trait_name).unwrap(); - writeln!(extra_headers, "typedef struct LDK{} LDK{};", trait_name, trait_name).unwrap(); - generated_fields.push("eq".to_owned()); - }, - ("std::hash::Hash", _) => { - writeln!(w, "\tpub hash: extern \"C\" fn (this_arg: *const c_void) -> u64,").unwrap(); - generated_fields.push("hash".to_owned()); - }, - ("Send", _) => {}, ("Sync", _) => {}, - (s, i) => { - generated_fields.push(if types.crate_types.traits.get(s).is_none() { - let (name, ret) = convert_trait_impl_field(s); - writeln!(w, "\tpub {}: extern \"C\" fn (this_arg: *const c_void) -> {},", name, ret).unwrap(); - name - } else { - // For in-crate supertraits, just store a C-mapped copy of the supertrait as a member. - writeln!(w, "\tpub {}: crate::{},", i, s).unwrap(); - format!("{}", i) - }); - } - ) ); - writeln!(w, "\tpub free: Option,").unwrap(); - generated_fields.push("free".to_owned()); - writeln!(w, "}}").unwrap(); - // Implement supertraits for the C-mapped struct. - walk_supertraits!(t, Some(&types), ( - ("Send", _) => writeln!(w, "unsafe impl Send for {} {{}}", trait_name).unwrap(), - ("Sync", _) => writeln!(w, "unsafe impl Sync for {} {{}}", trait_name).unwrap(), - ("std::cmp::Eq", _) => { - writeln!(w, "impl std::cmp::Eq for {} {{}}", trait_name).unwrap(); - writeln!(w, "impl std::cmp::PartialEq for {} {{", trait_name).unwrap(); - writeln!(w, "\tfn eq(&self, o: &Self) -> bool {{ (self.eq)(self.this_arg, o) }}\n}}").unwrap(); - }, - ("std::hash::Hash", _) => { - writeln!(w, "impl std::hash::Hash for {} {{", trait_name).unwrap(); - writeln!(w, "\tfn hash(&self, hasher: &mut H) {{ hasher.write_u64((self.hash)(self.this_arg)) }}\n}}").unwrap(); - }, - ("Clone", _) => { - writeln!(w, "#[no_mangle]").unwrap(); - writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", trait_name, trait_name, trait_name).unwrap(); - writeln!(w, "\t{} {{", trait_name).unwrap(); - writeln!(w, "\t\tthis_arg: if let Some(f) = orig.clone {{ (f)(orig.this_arg) }} else {{ orig.this_arg }},").unwrap(); - for field in generated_fields.iter() { - writeln!(w, "\t\t{}: orig.{}.clone(),", field, field).unwrap(); - } - writeln!(w, "\t}}\n}}").unwrap(); - writeln!(w, "impl Clone for {} {{", trait_name).unwrap(); - writeln!(w, "\tfn clone(&self) -> Self {{").unwrap(); - writeln!(w, "\t\t{}_clone(self)", trait_name).unwrap(); - writeln!(w, "\t}}\n}}").unwrap(); - }, - (s, i) => { - do_write_impl_trait(w, s, i, &trait_name); - } - ) ); - - // Finally, implement the original Rust trait for the newly created mapped trait. - writeln!(w, "\nuse {}::{}::{} as rust{};", types.orig_crate, types.module_path, t.ident, trait_name).unwrap(); - write!(w, "impl rust{}", t.ident).unwrap(); - maybe_write_generics(w, &t.generics, types, false); - writeln!(w, " for {} {{", trait_name).unwrap(); - for item in t.items.iter() { - match item { - syn::TraitItem::Method(m) => { - if let ExportStatus::TestOnly = export_status(&m.attrs) { continue; } - if m.default.is_some() { unimplemented!(); } - if m.sig.constness.is_some() || m.sig.asyncness.is_some() || m.sig.unsafety.is_some() || - m.sig.abi.is_some() || m.sig.variadic.is_some() { - unimplemented!(); - } - gen_types.push_ctx(); - assert!(gen_types.learn_generics(&m.sig.generics, types)); - write!(w, "\tfn {}", m.sig.ident).unwrap(); - types.write_rust_generic_param(w, Some(&gen_types), m.sig.generics.params.iter()); - write!(w, "(").unwrap(); - for inp in m.sig.inputs.iter() { - match inp { - syn::FnArg::Receiver(recv) => { - if !recv.attrs.is_empty() || recv.reference.is_none() { unimplemented!(); } - write!(w, "&").unwrap(); - if let Some(lft) = &recv.reference.as_ref().unwrap().1 { - write!(w, "'{} ", lft.ident).unwrap(); - } - if recv.mutability.is_some() { - write!(w, "mut self").unwrap(); - } else { - write!(w, "self").unwrap(); - } - }, - syn::FnArg::Typed(arg) => { - if !arg.attrs.is_empty() { unimplemented!(); } - match &*arg.pat { - syn::Pat::Ident(ident) => { - if !ident.attrs.is_empty() || ident.by_ref.is_some() || - ident.mutability.is_some() || ident.subpat.is_some() { - unimplemented!(); - } - write!(w, ", {}{}: ", if types.skip_arg(&*arg.ty, Some(&gen_types)) { "_" } else { "" }, ident.ident).unwrap(); - } - _ => unimplemented!(), - } - types.write_rust_type(w, Some(&gen_types), &*arg.ty); - } - } - } - write!(w, ")").unwrap(); - match &m.sig.output { - syn::ReturnType::Type(_, rtype) => { - write!(w, " -> ").unwrap(); - types.write_rust_type(w, Some(&gen_types), &*rtype) - }, - _ => {}, - } - write!(w, " {{\n\t\t").unwrap(); - match export_status(&m.attrs) { - ExportStatus::NoExport => { - unimplemented!(); - }, - _ => {}, - } - if let syn::ReturnType::Type(_, rtype) = &m.sig.output { - if let syn::Type::Reference(r) = &**rtype { - assert_eq!(m.sig.inputs.len(), 1); // Must only take self! - writeln!(w, "if let Some(f) = self.set_{} {{", m.sig.ident).unwrap(); - writeln!(w, "\t\t\t(f)(self);").unwrap(); - write!(w, "\t\t}}\n\t\t").unwrap(); - types.write_from_c_conversion_to_ref_prefix(w, &*r.elem, Some(&gen_types)); - write!(w, "self.{}", m.sig.ident).unwrap(); - types.write_from_c_conversion_to_ref_suffix(w, &*r.elem, Some(&gen_types)); - writeln!(w, "\n\t}}").unwrap(); - gen_types.pop_ctx(); - continue; - } - } - write_method_var_decl_body(w, &m.sig, "\t", types, Some(&gen_types), true); - write!(w, "(self.{})(", m.sig.ident).unwrap(); - write_method_call_params(w, &m.sig, "\t", types, Some(&gen_types), "", true); - - writeln!(w, "\n\t}}").unwrap(); - gen_types.pop_ctx(); - }, - &syn::TraitItem::Type(ref t) => { - if t.default.is_some() || t.generics.lt_token.is_some() { unimplemented!(); } - let mut bounds_iter = t.bounds.iter(); - match bounds_iter.next().unwrap() { - syn::TypeParamBound::Trait(tr) => { - writeln!(w, "\ttype {} = crate::{};", t.ident, types.resolve_path(&tr.path, Some(&gen_types))).unwrap(); - }, - _ => unimplemented!(), - } - if bounds_iter.next().is_some() { unimplemented!(); } - }, - _ => unimplemented!(), - } - } - writeln!(w, "}}\n").unwrap(); - writeln!(w, "// We're essentially a pointer already, or at least a set of pointers, so allow us to be used").unwrap(); - writeln!(w, "// directly as a Deref trait in higher-level structs:").unwrap(); - writeln!(w, "impl std::ops::Deref for {} {{\n\ttype Target = Self;", trait_name).unwrap(); - writeln!(w, "\tfn deref(&self) -> &Self {{\n\t\tself\n\t}}\n}}").unwrap(); - - writeln!(w, "/// Calls the free function if one is set").unwrap(); - writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_free(this_ptr: {}) {{ }}", trait_name, trait_name).unwrap(); - writeln!(w, "impl Drop for {} {{", trait_name).unwrap(); - writeln!(w, "\tfn drop(&mut self) {{").unwrap(); - writeln!(w, "\t\tif let Some(f) = self.free {{").unwrap(); - writeln!(w, "\t\t\tf(self.this_arg);").unwrap(); - writeln!(w, "\t\t}}\n\t}}\n}}").unwrap(); - - write_cpp_wrapper(cpp_headers, &trait_name, true); -} - -/// Write out a simple "opaque" type (eg structs) which contain a pointer to the native Rust type -/// and a flag to indicate whether Drop'ing the mapped struct drops the underlying Rust type. -/// -/// Also writes out a _free function and a C++ wrapper which handles calling _free. -fn writeln_opaque(w: &mut W, ident: &syn::Ident, struct_name: &str, generics: &syn::Generics, attrs: &[syn::Attribute], types: &TypeResolver, extra_headers: &mut File, cpp_headers: &mut File) { - // If we directly read the original type by its original name, cbindgen hits - // https://github.com/eqrion/cbindgen/issues/286 Thus, instead, we import it as a temporary - // name and then reference it by that name, which works around the issue. - write!(w, "\nuse {}::{}::{} as native{}Import;\ntype native{} = native{}Import", types.orig_crate, types.module_path, ident, ident, ident, ident).unwrap(); - maybe_write_generics(w, &generics, &types, true); - writeln!(w, ";\n").unwrap(); - writeln!(extra_headers, "struct native{}Opaque;\ntypedef struct native{}Opaque LDKnative{};", ident, ident, ident).unwrap(); - writeln_docs(w, &attrs, ""); - writeln!(w, "#[must_use]\n#[repr(C)]\npub struct {} {{\n\t/// Nearly everywhere, inner must be non-null, however in places where", struct_name).unwrap(); - writeln!(w, "\t/// the Rust equivalent takes an Option, it may be set to null to indicate None.").unwrap(); - writeln!(w, "\tpub inner: *mut native{},\n\tpub is_owned: bool,\n}}\n", ident).unwrap(); - writeln!(w, "impl Drop for {} {{\n\tfn drop(&mut self) {{", struct_name).unwrap(); - writeln!(w, "\t\tif self.is_owned && !<*mut native{}>::is_null(self.inner) {{", ident).unwrap(); - writeln!(w, "\t\t\tlet _ = unsafe {{ Box::from_raw(self.inner) }};\n\t\t}}\n\t}}\n}}").unwrap(); - writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_free(this_ptr: {}) {{ }}", struct_name, struct_name).unwrap(); - writeln!(w, "#[allow(unused)]").unwrap(); - writeln!(w, "/// Used only if an object of this type is returned as a trait impl by a method").unwrap(); - writeln!(w, "extern \"C\" fn {}_free_void(this_ptr: *mut c_void) {{", struct_name).unwrap(); - writeln!(w, "\tunsafe {{ let _ = Box::from_raw(this_ptr as *mut native{}); }}\n}}", struct_name).unwrap(); - writeln!(w, "#[allow(unused)]").unwrap(); - writeln!(w, "/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy").unwrap(); - writeln!(w, "impl {} {{", struct_name).unwrap(); - writeln!(w, "\tpub(crate) fn take_inner(mut self) -> *mut native{} {{", struct_name).unwrap(); - writeln!(w, "\t\tassert!(self.is_owned);").unwrap(); - writeln!(w, "\t\tlet ret = self.inner;").unwrap(); - writeln!(w, "\t\tself.inner = std::ptr::null_mut();").unwrap(); - writeln!(w, "\t\tret").unwrap(); - writeln!(w, "\t}}\n}}").unwrap(); - - write_cpp_wrapper(cpp_headers, &format!("{}", ident), true); -} - -/// Writes out all the relevant mappings for a Rust struct, deferring to writeln_opaque to generate -/// the struct itself, and then writing getters and setters for public, understood-type fields and -/// a constructor if every field is public. -fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct, types: &mut TypeResolver<'b, 'a>, extra_headers: &mut File, cpp_headers: &mut File) { - if export_status(&s.attrs) != ExportStatus::Export { return; } - - let struct_name = &format!("{}", s.ident); - writeln_opaque(w, &s.ident, struct_name, &s.generics, &s.attrs, types, extra_headers, cpp_headers); - - if let syn::Fields::Named(fields) = &s.fields { - let mut gen_types = GenericTypes::new(); - assert!(gen_types.learn_generics(&s.generics, types)); - - let mut all_fields_settable = true; - for field in fields.named.iter() { - if let syn::Visibility::Public(_) = field.vis { - let export = export_status(&field.attrs); - match export { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => { - all_fields_settable = false; - continue - }, - } - - if let Some(ident) = &field.ident { - let ref_type = syn::Type::Reference(syn::TypeReference { - and_token: syn::Token!(&)(Span::call_site()), lifetime: None, mutability: None, - elem: Box::new(field.ty.clone()) }); - if types.understood_c_type(&ref_type, Some(&gen_types)) { - writeln_docs(w, &field.attrs, ""); - write!(w, "#[no_mangle]\npub extern \"C\" fn {}_get_{}(this_ptr: &{}) -> ", struct_name, ident, struct_name).unwrap(); - types.write_c_type(w, &ref_type, Some(&gen_types), true); - write!(w, " {{\n\tlet mut inner_val = &mut unsafe {{ &mut *this_ptr.inner }}.{};\n\t", ident).unwrap(); - let local_var = types.write_to_c_conversion_new_var(w, &syn::Ident::new("inner_val", Span::call_site()), &ref_type, Some(&gen_types), true); - if local_var { write!(w, "\n\t").unwrap(); } - types.write_to_c_conversion_inline_prefix(w, &ref_type, Some(&gen_types), true); - if local_var { - write!(w, "inner_val").unwrap(); - } else { - write!(w, "(*inner_val)").unwrap(); - } - types.write_to_c_conversion_inline_suffix(w, &ref_type, Some(&gen_types), true); - writeln!(w, "\n}}").unwrap(); - } - - if types.understood_c_type(&field.ty, Some(&gen_types)) { - writeln_docs(w, &field.attrs, ""); - write!(w, "#[no_mangle]\npub extern \"C\" fn {}_set_{}(this_ptr: &mut {}, mut val: ", struct_name, ident, struct_name).unwrap(); - types.write_c_type(w, &field.ty, Some(&gen_types), false); - write!(w, ") {{\n\t").unwrap(); - let local_var = types.write_from_c_conversion_new_var(w, &syn::Ident::new("val", Span::call_site()), &field.ty, Some(&gen_types)); - if local_var { write!(w, "\n\t").unwrap(); } - write!(w, "unsafe {{ &mut *this_ptr.inner }}.{} = ", ident).unwrap(); - types.write_from_c_conversion_prefix(w, &field.ty, Some(&gen_types)); - write!(w, "val").unwrap(); - types.write_from_c_conversion_suffix(w, &field.ty, Some(&gen_types)); - writeln!(w, ";\n}}").unwrap(); - } else { all_fields_settable = false; } - } else { all_fields_settable = false; } - } else { all_fields_settable = false; } - } - - if all_fields_settable { - // Build a constructor! - write!(w, "#[must_use]\n#[no_mangle]\npub extern \"C\" fn {}_new(", struct_name).unwrap(); - for (idx, field) in fields.named.iter().enumerate() { - if idx != 0 { write!(w, ", ").unwrap(); } - write!(w, "mut {}_arg: ", field.ident.as_ref().unwrap()).unwrap(); - types.write_c_type(w, &field.ty, Some(&gen_types), false); - } - write!(w, ") -> {} {{\n\t", struct_name).unwrap(); - for field in fields.named.iter() { - let field_name = format!("{}_arg", field.ident.as_ref().unwrap()); - if types.write_from_c_conversion_new_var(w, &syn::Ident::new(&field_name, Span::call_site()), &field.ty, Some(&gen_types)) { - write!(w, "\n\t").unwrap(); - } - } - writeln!(w, "{} {{ inner: Box::into_raw(Box::new(native{} {{", struct_name, s.ident).unwrap(); - for field in fields.named.iter() { - write!(w, "\t\t{}: ", field.ident.as_ref().unwrap()).unwrap(); - types.write_from_c_conversion_prefix(w, &field.ty, Some(&gen_types)); - write!(w, "{}_arg", field.ident.as_ref().unwrap()).unwrap(); - types.write_from_c_conversion_suffix(w, &field.ty, Some(&gen_types)); - writeln!(w, ",").unwrap(); - } - writeln!(w, "\t}})), is_owned: true }}\n}}").unwrap(); - } - } -} - -/// Prints a relevant conversion for impl * -/// -/// For simple impl Struct {}s, this just outputs the wrapper functions as Struct_fn_name() { .. }. -/// -/// For impl Trait for Struct{}s, this non-exported generates wrapper functions as -/// Trait_Struct_fn_name and a Struct_as_Trait(&struct) -> Trait function which returns a populated -/// Trait struct containing a pointer to the passed struct's inner field and the wrapper functions. -/// -/// A few non-crate Traits are hard-coded including Default. -fn writeln_impl(w: &mut W, i: &syn::ItemImpl, types: &mut TypeResolver) { - match export_status(&i.attrs) { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => return, - } - - if let syn::Type::Tuple(_) = &*i.self_ty { - if types.understood_c_type(&*i.self_ty, None) { - let mut gen_types = GenericTypes::new(); - if !gen_types.learn_generics(&i.generics, types) { - eprintln!("Not implementing anything for `impl (..)` due to not understood generics"); - return; - } - - if i.defaultness.is_some() || i.unsafety.is_some() { unimplemented!(); } - if let Some(trait_path) = i.trait_.as_ref() { - if trait_path.0.is_some() { unimplemented!(); } - if types.understood_c_path(&trait_path.1) { - eprintln!("Not implementing anything for `impl Trait for (..)` - we only support manual defines"); - return; - } else { - // Just do a manual implementation: - maybe_convert_trait_impl(w, &trait_path.1, &*i.self_ty, types, &gen_types); - } - } else { - eprintln!("Not implementing anything for plain `impl (..)` block - we only support `impl Trait for (..)` blocks"); - return; - } - } - return; - } - if let &syn::Type::Path(ref p) = &*i.self_ty { - if p.qself.is_some() { unimplemented!(); } - if let Some(ident) = single_ident_generic_path_to_ident(&p.path) { - if let Some(resolved_path) = types.maybe_resolve_non_ignored_ident(&ident) { - let mut gen_types = GenericTypes::new(); - if !gen_types.learn_generics(&i.generics, types) { - eprintln!("Not implementing anything for impl {} due to not understood generics", ident); - return; - } - - if i.defaultness.is_some() || i.unsafety.is_some() { unimplemented!(); } - if let Some(trait_path) = i.trait_.as_ref() { - if trait_path.0.is_some() { unimplemented!(); } - if types.understood_c_path(&trait_path.1) { - let full_trait_path = types.resolve_path(&trait_path.1, None); - let trait_obj = *types.crate_types.traits.get(&full_trait_path).unwrap(); - // We learn the associated types maping from the original trait object. - // That's great, except that they are unresolved idents, so if we learn - // mappings from a trai defined in a different file, we may mis-resolve or - // fail to resolve the mapped types. - gen_types.learn_associated_types(trait_obj, types); - let mut impl_associated_types = HashMap::new(); - for item in i.items.iter() { - match item { - syn::ImplItem::Type(t) => { - if let syn::Type::Path(p) = &t.ty { - if let Some(id) = single_ident_generic_path_to_ident(&p.path) { - impl_associated_types.insert(&t.ident, id); - } - } - }, - _ => {}, - } - } - - let export = export_status(&trait_obj.attrs); - match export { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => return, - } - - // For cases where we have a concrete native object which implements a - // trait and need to return the C-mapped version of the trait, provide a - // From<> implementation which does all the work to ensure free is handled - // properly. This way we can call this method from deep in the - // type-conversion logic without actually knowing the concrete native type. - writeln!(w, "impl From for crate::{} {{", ident, full_trait_path).unwrap(); - writeln!(w, "\tfn from(obj: native{}) -> Self {{", ident).unwrap(); - writeln!(w, "\t\tlet mut rust_obj = {} {{ inner: Box::into_raw(Box::new(obj)), is_owned: true }};", ident).unwrap(); - writeln!(w, "\t\tlet mut ret = {}_as_{}(&rust_obj);", ident, trait_obj.ident).unwrap(); - writeln!(w, "\t\t// We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn").unwrap(); - writeln!(w, "\t\trust_obj.inner = std::ptr::null_mut();").unwrap(); - writeln!(w, "\t\tret.free = Some({}_free_void);", ident).unwrap(); - writeln!(w, "\t\tret\n\t}}\n}}").unwrap(); - - write!(w, "#[no_mangle]\npub extern \"C\" fn {}_as_{}(this_arg: &{}) -> crate::{} {{\n", ident, trait_obj.ident, ident, full_trait_path).unwrap(); - writeln!(w, "\tcrate::{} {{", full_trait_path).unwrap(); - writeln!(w, "\t\tthis_arg: unsafe {{ (*this_arg).inner as *mut c_void }},").unwrap(); - writeln!(w, "\t\tfree: None,").unwrap(); - - macro_rules! write_meth { - ($m: expr, $trait: expr, $indent: expr) => { - let trait_method = $trait.items.iter().filter_map(|item| { - if let syn::TraitItem::Method(t_m) = item { Some(t_m) } else { None } - }).find(|trait_meth| trait_meth.sig.ident == $m.sig.ident).unwrap(); - match export_status(&trait_method.attrs) { - ExportStatus::Export => {}, - ExportStatus::NoExport => { - write!(w, "{}\t\t//XXX: Need to export {}\n", $indent, $m.sig.ident).unwrap(); - continue; - }, - ExportStatus::TestOnly => continue, - } - - let mut printed = false; - if let syn::ReturnType::Type(_, rtype) = &$m.sig.output { - if let syn::Type::Reference(r) = &**rtype { - write!(w, "\n\t\t{}{}: ", $indent, $m.sig.ident).unwrap(); - types.write_empty_rust_val(Some(&gen_types), w, &*r.elem); - writeln!(w, ",\n{}\t\tset_{}: Some({}_{}_set_{}),", $indent, $m.sig.ident, ident, trait_obj.ident, $m.sig.ident).unwrap(); - printed = true; - } - } - if !printed { - write!(w, "{}\t\t{}: {}_{}_{},\n", $indent, $m.sig.ident, ident, trait_obj.ident, $m.sig.ident).unwrap(); - } - } - } - for item in trait_obj.items.iter() { - match item { - syn::TraitItem::Method(m) => { - write_meth!(m, trait_obj, ""); - }, - _ => {}, - } - } - walk_supertraits!(trait_obj, Some(&types), ( - ("Clone", _) => { - writeln!(w, "\t\tclone: Some({}_clone_void),", ident).unwrap(); - }, - ("Sync", _) => {}, ("Send", _) => {}, - ("std::marker::Sync", _) => {}, ("std::marker::Send", _) => {}, - (s, t) => { - if let Some(supertrait_obj) = types.crate_types.traits.get(s) { - writeln!(w, "\t\t{}: crate::{} {{", t, s).unwrap(); - writeln!(w, "\t\t\tthis_arg: unsafe {{ (*this_arg).inner as *mut c_void }},").unwrap(); - writeln!(w, "\t\t\tfree: None,").unwrap(); - for item in supertrait_obj.items.iter() { - match item { - syn::TraitItem::Method(m) => { - write_meth!(m, supertrait_obj, "\t"); - }, - _ => {}, - } - } - write!(w, "\t\t}},\n").unwrap(); - } else { - write_trait_impl_field_assign(w, s, ident); - } - } - ) ); - writeln!(w, "\t}}\n}}\n").unwrap(); - - macro_rules! impl_meth { - ($m: expr, $trait_path: expr, $trait: expr, $indent: expr) => { - let trait_method = $trait.items.iter().filter_map(|item| { - if let syn::TraitItem::Method(t_m) = item { Some(t_m) } else { None } - }).find(|trait_meth| trait_meth.sig.ident == $m.sig.ident).unwrap(); - match export_status(&trait_method.attrs) { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => continue, - } - - if let syn::ReturnType::Type(_, _) = &$m.sig.output { - writeln!(w, "#[must_use]").unwrap(); - } - write!(w, "extern \"C\" fn {}_{}_{}(", ident, trait_obj.ident, $m.sig.ident).unwrap(); - gen_types.push_ctx(); - assert!(gen_types.learn_generics(&$m.sig.generics, types)); - write_method_params(w, &$m.sig, "c_void", types, Some(&gen_types), true, true); - write!(w, " {{\n\t").unwrap(); - write_method_var_decl_body(w, &$m.sig, "", types, Some(&gen_types), false); - let mut takes_self = false; - for inp in $m.sig.inputs.iter() { - if let syn::FnArg::Receiver(_) = inp { - takes_self = true; - } - } - - let mut t_gen_args = String::new(); - for (idx, _) in $trait.generics.params.iter().enumerate() { - if idx != 0 { t_gen_args += ", " }; - t_gen_args += "_" - } - if takes_self { - write!(w, ">::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, ", ident, types.orig_crate, $trait_path, t_gen_args, $m.sig.ident, ident).unwrap(); - } else { - write!(w, ">::{}(", ident, types.orig_crate, $trait_path, t_gen_args, $m.sig.ident).unwrap(); - } - - let mut real_type = "".to_string(); - match &$m.sig.output { - syn::ReturnType::Type(_, rtype) => { - if let Some(mut remaining_path) = first_seg_self(&*rtype) { - if let Some(associated_seg) = get_single_remaining_path_seg(&mut remaining_path) { - real_type = format!("{}", impl_associated_types.get(associated_seg).unwrap()); - } - } - }, - _ => {}, - } - write_method_call_params(w, &$m.sig, "", types, Some(&gen_types), &real_type, false); - gen_types.pop_ctx(); - write!(w, "\n}}\n").unwrap(); - if let syn::ReturnType::Type(_, rtype) = &$m.sig.output { - if let syn::Type::Reference(r) = &**rtype { - assert_eq!($m.sig.inputs.len(), 1); // Must only take self - writeln!(w, "extern \"C\" fn {}_{}_set_{}(trait_self_arg: &{}) {{", ident, trait_obj.ident, $m.sig.ident, trait_obj.ident).unwrap(); - writeln!(w, "\t// This is a bit race-y in the general case, but for our specific use-cases today, we're safe").unwrap(); - writeln!(w, "\t// Specifically, we must ensure that the first time we're called it can never be in parallel").unwrap(); - write!(w, "\tif ").unwrap(); - types.write_empty_rust_val_check(Some(&gen_types), w, &*r.elem, &format!("trait_self_arg.{}", $m.sig.ident)); - writeln!(w, " {{").unwrap(); - writeln!(w, "\t\tunsafe {{ &mut *(trait_self_arg as *const {} as *mut {}) }}.{} = {}_{}_{}(trait_self_arg.this_arg);", trait_obj.ident, trait_obj.ident, $m.sig.ident, ident, trait_obj.ident, $m.sig.ident).unwrap(); - writeln!(w, "\t}}").unwrap(); - writeln!(w, "}}").unwrap(); - } - } - } - } - - for item in i.items.iter() { - match item { - syn::ImplItem::Method(m) => { - impl_meth!(m, full_trait_path, trait_obj, ""); - }, - syn::ImplItem::Type(_) => {}, - _ => unimplemented!(), - } - } - walk_supertraits!(trait_obj, Some(&types), ( - (s, _) => { - if let Some(supertrait_obj) = types.crate_types.traits.get(s).cloned() { - for item in supertrait_obj.items.iter() { - match item { - syn::TraitItem::Method(m) => { - impl_meth!(m, s, supertrait_obj, "\t"); - }, - _ => {}, - } - } - } - } - ) ); - write!(w, "\n").unwrap(); - } else if path_matches_nongeneric(&trait_path.1, &["From"]) { - } else if path_matches_nongeneric(&trait_path.1, &["Default"]) { - write!(w, "#[must_use]\n#[no_mangle]\npub extern \"C\" fn {}_default() -> {} {{\n", ident, ident).unwrap(); - write!(w, "\t{} {{ inner: Box::into_raw(Box::new(Default::default())), is_owned: true }}\n", ident).unwrap(); - write!(w, "}}\n").unwrap(); - } else if path_matches_nongeneric(&trait_path.1, &["core", "cmp", "PartialEq"]) { - } else if (path_matches_nongeneric(&trait_path.1, &["core", "clone", "Clone"]) || path_matches_nongeneric(&trait_path.1, &["Clone"])) && - types.c_type_has_inner_from_path(&resolved_path) { - writeln!(w, "impl Clone for {} {{", ident).unwrap(); - writeln!(w, "\tfn clone(&self) -> Self {{").unwrap(); - writeln!(w, "\t\tSelf {{").unwrap(); - writeln!(w, "\t\t\tinner: if <*mut native{}>::is_null(self.inner) {{ std::ptr::null_mut() }} else {{", ident).unwrap(); - writeln!(w, "\t\t\t\tBox::into_raw(Box::new(unsafe {{ &*self.inner }}.clone())) }},").unwrap(); - writeln!(w, "\t\t\tis_owned: true,").unwrap(); - writeln!(w, "\t\t}}\n\t}}\n}}").unwrap(); - writeln!(w, "#[allow(unused)]").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 {{", ident).unwrap(); - writeln!(w, "\tBox::into_raw(Box::new(unsafe {{ (*(this_ptr as *mut native{})).clone() }})) as *mut c_void", ident).unwrap(); - writeln!(w, "}}").unwrap(); - writeln!(w, "#[no_mangle]").unwrap(); - writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", ident, ident, ident).unwrap(); - writeln!(w, "\torig.clone()").unwrap(); - writeln!(w, "}}").unwrap(); - } else { - //XXX: implement for other things like ToString - // If we have no generics, try a manual implementation: - maybe_convert_trait_impl(w, &trait_path.1, &*i.self_ty, types, &gen_types); - } - } else { - let declared_type = (*types.get_declared_type(&ident).unwrap()).clone(); - for item in i.items.iter() { - match item { - syn::ImplItem::Method(m) => { - if let syn::Visibility::Public(_) = m.vis { - match export_status(&m.attrs) { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => continue, - } - if m.defaultness.is_some() { unimplemented!(); } - writeln_docs(w, &m.attrs, ""); - if let syn::ReturnType::Type(_, _) = &m.sig.output { - writeln!(w, "#[must_use]").unwrap(); - } - write!(w, "#[no_mangle]\npub extern \"C\" fn {}_{}(", ident, m.sig.ident).unwrap(); - let ret_type = match &declared_type { - DeclType::MirroredEnum => format!("{}", ident), - DeclType::StructImported => format!("{}", ident), - _ => unimplemented!(), - }; - gen_types.push_ctx(); - assert!(gen_types.learn_generics(&m.sig.generics, types)); - write_method_params(w, &m.sig, &ret_type, types, Some(&gen_types), false, true); - write!(w, " {{\n\t").unwrap(); - write_method_var_decl_body(w, &m.sig, "", types, Some(&gen_types), false); - let mut takes_self = false; - let mut takes_mut_self = false; - for inp in m.sig.inputs.iter() { - if let syn::FnArg::Receiver(r) = inp { - takes_self = true; - if r.mutability.is_some() { takes_mut_self = true; } - } - } - if takes_mut_self { - write!(w, "unsafe {{ &mut (*(this_arg.inner as *mut native{})) }}.{}(", ident, m.sig.ident).unwrap(); - } else if takes_self { - write!(w, "unsafe {{ &*this_arg.inner }}.{}(", m.sig.ident).unwrap(); - } else { - write!(w, "{}::{}::{}(", types.orig_crate, resolved_path, m.sig.ident).unwrap(); - } - write_method_call_params(w, &m.sig, "", types, Some(&gen_types), &ret_type, false); - gen_types.pop_ctx(); - writeln!(w, "\n}}\n").unwrap(); - } - }, - _ => {}, - } - } - } - } else if let Some(resolved_path) = types.maybe_resolve_ident(&ident) { - if let Some(aliases) = types.crate_types.reverse_alias_map.get(&resolved_path).cloned() { - 'alias_impls: for (alias, arguments) in aliases { - let alias_resolved = types.resolve_path(&alias, None); - for (idx, gen) in i.generics.params.iter().enumerate() { - match gen { - syn::GenericParam::Type(type_param) => { - 'bounds_check: for bound in type_param.bounds.iter() { - if let syn::TypeParamBound::Trait(trait_bound) = bound { - if let syn::PathArguments::AngleBracketed(ref t) = &arguments { - assert!(idx < t.args.len()); - if let syn::GenericArgument::Type(syn::Type::Path(p)) = &t.args[idx] { - let generic_arg = types.resolve_path(&p.path, None); - let generic_bound = types.resolve_path(&trait_bound.path, None); - if let Some(traits_impld) = types.crate_types.trait_impls.get(&generic_arg) { - for trait_impld in traits_impld { - if *trait_impld == generic_bound { continue 'bounds_check; } - } - eprintln!("struct {}'s generic arg {} didn't match bound {}", alias_resolved, generic_arg, generic_bound); - continue 'alias_impls; - } else { - eprintln!("struct {}'s generic arg {} didn't match bound {}", alias_resolved, generic_arg, generic_bound); - continue 'alias_impls; - } - } else { unimplemented!(); } - } else { unimplemented!(); } - } else { unimplemented!(); } - } - }, - syn::GenericParam::Lifetime(_) => {}, - syn::GenericParam::Const(_) => unimplemented!(), - } - } - let aliased_impl = syn::ItemImpl { - attrs: i.attrs.clone(), - brace_token: syn::token::Brace(Span::call_site()), - defaultness: None, - generics: syn::Generics { - lt_token: None, - params: syn::punctuated::Punctuated::new(), - gt_token: None, - where_clause: None, - }, - impl_token: syn::Token![impl](Span::call_site()), - items: i.items.clone(), - self_ty: Box::new(syn::Type::Path(syn::TypePath { qself: None, path: alias.clone() })), - trait_: i.trait_.clone(), - unsafety: None, - }; - writeln_impl(w, &aliased_impl, types); - } - } else { - eprintln!("Not implementing anything for {} due to it being marked not exported", ident); - } - } else { - eprintln!("Not implementing anything for {} due to no-resolve (probably the type isn't pub)", ident); - } - } - } -} - - -/// Print a mapping of an enum. If all of the enum's fields are C-mapped in some form (or the enum -/// is unitary), we generate an equivalent enum with all types replaced with their C mapped -/// versions followed by conversion functions which map between the Rust version and the C mapped -/// version. -fn writeln_enum<'a, 'b, W: std::io::Write>(w: &mut W, e: &'a syn::ItemEnum, types: &mut TypeResolver<'b, 'a>, extra_headers: &mut File, cpp_headers: &mut File) { - match export_status(&e.attrs) { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => return, - } - - if is_enum_opaque(e) { - eprintln!("Skipping enum {} as it contains non-unit fields", e.ident); - writeln_opaque(w, &e.ident, &format!("{}", e.ident), &e.generics, &e.attrs, types, extra_headers, cpp_headers); - return; - } - writeln_docs(w, &e.attrs, ""); - - if e.generics.lt_token.is_some() { - unimplemented!(); - } - - let mut needs_free = false; - - writeln!(w, "#[must_use]\n#[derive(Clone)]\n#[repr(C)]\npub enum {} {{", e.ident).unwrap(); - for var in e.variants.iter() { - assert_eq!(export_status(&var.attrs), ExportStatus::Export); // We can't partially-export a mirrored enum - writeln_docs(w, &var.attrs, "\t"); - write!(w, "\t{}", var.ident).unwrap(); - if let syn::Fields::Named(fields) = &var.fields { - needs_free = true; - writeln!(w, " {{").unwrap(); - for field in fields.named.iter() { - if export_status(&field.attrs) == ExportStatus::TestOnly { continue; } - write!(w, "\t\t{}: ", field.ident.as_ref().unwrap()).unwrap(); - types.write_c_type(w, &field.ty, None, false); - writeln!(w, ",").unwrap(); - } - write!(w, "\t}}").unwrap(); - } else if let syn::Fields::Unnamed(fields) = &var.fields { - needs_free = true; - write!(w, "(").unwrap(); - for (idx, field) in fields.unnamed.iter().enumerate() { - if export_status(&field.attrs) == ExportStatus::TestOnly { continue; } - types.write_c_type(w, &field.ty, None, false); - if idx != fields.unnamed.len() - 1 { - write!(w, ",").unwrap(); - } - } - write!(w, ")").unwrap(); - } - if var.discriminant.is_some() { unimplemented!(); } - writeln!(w, ",").unwrap(); - } - writeln!(w, "}}\nuse {}::{}::{} as native{};\nimpl {} {{", types.orig_crate, types.module_path, e.ident, e.ident, e.ident).unwrap(); - - macro_rules! write_conv { - ($fn_sig: expr, $to_c: expr, $ref: expr) => { - writeln!(w, "\t#[allow(unused)]\n\tpub(crate) fn {} {{\n\t\tmatch {} {{", $fn_sig, if $to_c { "native" } else { "self" }).unwrap(); - for var in e.variants.iter() { - write!(w, "\t\t\t{}{}::{} ", if $to_c { "native" } else { "" }, e.ident, var.ident).unwrap(); - if let syn::Fields::Named(fields) = &var.fields { - write!(w, "{{").unwrap(); - for field in fields.named.iter() { - if export_status(&field.attrs) == ExportStatus::TestOnly { continue; } - write!(w, "{}{}, ", if $ref { "ref " } else { "mut " }, field.ident.as_ref().unwrap()).unwrap(); - } - write!(w, "}} ").unwrap(); - } else if let syn::Fields::Unnamed(fields) = &var.fields { - write!(w, "(").unwrap(); - for (idx, field) in fields.unnamed.iter().enumerate() { - if export_status(&field.attrs) == ExportStatus::TestOnly { continue; } - write!(w, "{}{}, ", if $ref { "ref " } else { "mut " }, ('a' as u8 + idx as u8) as char).unwrap(); - } - write!(w, ") ").unwrap(); - } - write!(w, "=>").unwrap(); - - macro_rules! handle_field_a { - ($field: expr, $field_ident: expr) => { { - if export_status(&$field.attrs) == ExportStatus::TestOnly { continue; } - let mut sink = ::std::io::sink(); - let mut out: &mut dyn std::io::Write = if $ref { &mut sink } else { w }; - let new_var = if $to_c { - types.write_to_c_conversion_new_var(&mut out, $field_ident, &$field.ty, None, false) - } else { - types.write_from_c_conversion_new_var(&mut out, $field_ident, &$field.ty, None) - }; - if $ref || new_var { - if $ref { - write!(w, "let mut {}_nonref = (*{}).clone();\n\t\t\t\t", $field_ident, $field_ident).unwrap(); - if new_var { - let nonref_ident = syn::Ident::new(&format!("{}_nonref", $field_ident), Span::call_site()); - if $to_c { - types.write_to_c_conversion_new_var(w, &nonref_ident, &$field.ty, None, false); - } else { - types.write_from_c_conversion_new_var(w, &nonref_ident, &$field.ty, None); - } - write!(w, "\n\t\t\t\t").unwrap(); - } - } else { - write!(w, "\n\t\t\t\t").unwrap(); - } - } - } } - } - if let syn::Fields::Named(fields) = &var.fields { - write!(w, " {{\n\t\t\t\t").unwrap(); - for field in fields.named.iter() { - handle_field_a!(field, field.ident.as_ref().unwrap()); - } - } else if let syn::Fields::Unnamed(fields) = &var.fields { - write!(w, " {{\n\t\t\t\t").unwrap(); - for (idx, field) in fields.unnamed.iter().enumerate() { - handle_field_a!(field, &syn::Ident::new(&(('a' as u8 + idx as u8) as char).to_string(), Span::call_site())); - } - } else { write!(w, " ").unwrap(); } - - write!(w, "{}{}::{}", if $to_c { "" } else { "native" }, e.ident, var.ident).unwrap(); - - macro_rules! handle_field_b { - ($field: expr, $field_ident: expr) => { { - if export_status(&$field.attrs) == ExportStatus::TestOnly { continue; } - if $to_c { - types.write_to_c_conversion_inline_prefix(w, &$field.ty, None, false); - } else { - types.write_from_c_conversion_prefix(w, &$field.ty, None); - } - write!(w, "{}{}", $field_ident, - if $ref { "_nonref" } else { "" }).unwrap(); - if $to_c { - types.write_to_c_conversion_inline_suffix(w, &$field.ty, None, false); - } else { - types.write_from_c_conversion_suffix(w, &$field.ty, None); - } - write!(w, ",").unwrap(); - } } - } - - if let syn::Fields::Named(fields) = &var.fields { - write!(w, " {{").unwrap(); - for field in fields.named.iter() { - if export_status(&field.attrs) == ExportStatus::TestOnly { continue; } - write!(w, "\n\t\t\t\t\t{}: ", field.ident.as_ref().unwrap()).unwrap(); - handle_field_b!(field, field.ident.as_ref().unwrap()); - } - writeln!(w, "\n\t\t\t\t}}").unwrap(); - write!(w, "\t\t\t}}").unwrap(); - } else if let syn::Fields::Unnamed(fields) = &var.fields { - write!(w, " (").unwrap(); - for (idx, field) in fields.unnamed.iter().enumerate() { - write!(w, "\n\t\t\t\t\t").unwrap(); - handle_field_b!(field, &syn::Ident::new(&(('a' as u8 + idx as u8) as char).to_string(), Span::call_site())); - } - writeln!(w, "\n\t\t\t\t)").unwrap(); - write!(w, "\t\t\t}}").unwrap(); - } - writeln!(w, ",").unwrap(); - } - writeln!(w, "\t\t}}\n\t}}").unwrap(); - } - } - - write_conv!(format!("to_native(&self) -> native{}", e.ident), false, true); - write_conv!(format!("into_native(self) -> native{}", e.ident), false, false); - write_conv!(format!("from_native(native: &native{}) -> Self", e.ident), true, true); - write_conv!(format!("native_into(native: native{}) -> Self", e.ident), true, false); - writeln!(w, "}}").unwrap(); - - if needs_free { - writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_free(this_ptr: {}) {{ }}", e.ident, e.ident).unwrap(); - } - writeln!(w, "#[no_mangle]").unwrap(); - writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", e.ident, e.ident, e.ident).unwrap(); - writeln!(w, "\torig.clone()").unwrap(); - writeln!(w, "}}").unwrap(); - write_cpp_wrapper(cpp_headers, &format!("{}", e.ident), needs_free); -} - -fn writeln_fn<'a, 'b, W: std::io::Write>(w: &mut W, f: &'a syn::ItemFn, types: &mut TypeResolver<'b, 'a>) { - match export_status(&f.attrs) { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => return, - } - writeln_docs(w, &f.attrs, ""); - - let mut gen_types = GenericTypes::new(); - if !gen_types.learn_generics(&f.sig.generics, types) { return; } - - write!(w, "#[no_mangle]\npub extern \"C\" fn {}(", f.sig.ident).unwrap(); - write_method_params(w, &f.sig, "", types, Some(&gen_types), false, true); - write!(w, " {{\n\t").unwrap(); - write_method_var_decl_body(w, &f.sig, "", types, Some(&gen_types), false); - write!(w, "{}::{}::{}(", types.orig_crate, types.module_path, f.sig.ident).unwrap(); - write_method_call_params(w, &f.sig, "", types, Some(&gen_types), "", false); - writeln!(w, "\n}}\n").unwrap(); -} - -// ******************************** -// *** File/Crate Walking Logic *** -// ******************************** -/// A public module -struct ASTModule { - pub attrs: Vec, - pub items: Vec, - pub submods: Vec, -} -/// A struct containing the syn::File AST for each file in the crate. -struct FullLibraryAST { - modules: HashMap, -} -impl FullLibraryAST { - fn load_module(&mut self, module: String, attrs: Vec, mut items: Vec) { - let mut non_mod_items = Vec::with_capacity(items.len()); - let mut submods = Vec::with_capacity(items.len()); - for item in items.drain(..) { - match item { - syn::Item::Mod(m) if m.content.is_some() => { - if export_status(&m.attrs) == ExportStatus::Export { - if let syn::Visibility::Public(_) = m.vis { - let modident = format!("{}", m.ident); - let modname = if module != "" { - module.clone() + "::" + &modident - } else { - modident.clone() - }; - self.load_module(modname, m.attrs, m.content.unwrap().1); - submods.push(modident); - } else { - non_mod_items.push(syn::Item::Mod(m)); - } - } - }, - syn::Item::Mod(_) => panic!("--pretty=expanded output should never have non-body modules"), - _ => { non_mod_items.push(item); } - } - } - self.modules.insert(module, ASTModule { attrs, items: non_mod_items, submods }); - } - - pub fn load_lib(lib: syn::File) -> Self { - assert_eq!(export_status(&lib.attrs), ExportStatus::Export); - let mut res = Self { modules: HashMap::default() }; - res.load_module("".to_owned(), lib.attrs, lib.items); - res - } -} - -/// Do the Real Work of mapping an original file to C-callable wrappers. Creates a new file at -/// `out_path` and fills it with wrapper structs/functions to allow calling the things in the AST -/// at `module` from C. -fn convert_file<'a, 'b>(libast: &'a FullLibraryAST, crate_types: &mut CrateTypes<'a>, out_dir: &str, orig_crate: &str, header_file: &mut File, cpp_header_file: &mut File) { - for (module, astmod) in libast.modules.iter() { - let ASTModule { ref attrs, ref items, ref submods } = astmod; - assert_eq!(export_status(&attrs), ExportStatus::Export); - - let new_file_path = if submods.is_empty() { - format!("{}/{}.rs", out_dir, module.replace("::", "/")) - } else if module != "" { - format!("{}/{}/mod.rs", out_dir, module.replace("::", "/")) - } else { - format!("{}/lib.rs", out_dir) - }; - let _ = std::fs::create_dir((&new_file_path.as_ref() as &std::path::Path).parent().unwrap()); - let mut out = std::fs::OpenOptions::new().write(true).create(true).truncate(true) - .open(new_file_path).expect("Unable to open new src file"); - - writeln_docs(&mut out, &attrs, ""); - - if module == "" { - // Special-case the top-level lib.rs with various lint allows and a pointer to the c_types - // and bitcoin hand-written modules. - writeln!(out, "#![allow(unknown_lints)]").unwrap(); - writeln!(out, "#![allow(non_camel_case_types)]").unwrap(); - writeln!(out, "#![allow(non_snake_case)]").unwrap(); - writeln!(out, "#![allow(unused_imports)]").unwrap(); - writeln!(out, "#![allow(unused_variables)]").unwrap(); - writeln!(out, "#![allow(unused_mut)]").unwrap(); - writeln!(out, "#![allow(unused_parens)]").unwrap(); - writeln!(out, "#![allow(unused_unsafe)]").unwrap(); - writeln!(out, "#![allow(unused_braces)]").unwrap(); - writeln!(out, "mod c_types;").unwrap(); - writeln!(out, "mod bitcoin;").unwrap(); - } else { - writeln!(out, "\nuse std::ffi::c_void;\nuse bitcoin::hashes::Hash;\nuse crate::c_types::*;\n").unwrap(); - } - - for m in submods { - writeln!(out, "pub mod {};", m).unwrap(); - } - - eprintln!("Converting {} entries...", module); - - let import_resolver = ImportResolver::new(module, items); - let mut type_resolver = TypeResolver::new(orig_crate, module, import_resolver, crate_types); - - for item in items.iter() { - match item { - syn::Item::Use(_) => {}, // Handled above - syn::Item::Static(_) => {}, - syn::Item::Enum(e) => { - if let syn::Visibility::Public(_) = e.vis { - writeln_enum(&mut out, &e, &mut type_resolver, header_file, cpp_header_file); - } - }, - syn::Item::Impl(i) => { - writeln_impl(&mut out, &i, &mut type_resolver); - }, - syn::Item::Struct(s) => { - if let syn::Visibility::Public(_) = s.vis { - writeln_struct(&mut out, &s, &mut type_resolver, header_file, cpp_header_file); - } - }, - syn::Item::Trait(t) => { - if let syn::Visibility::Public(_) = t.vis { - writeln_trait(&mut out, &t, &mut type_resolver, header_file, cpp_header_file); - } - }, - syn::Item::Mod(_) => {}, // We don't have to do anything - the top loop handles these. - syn::Item::Const(c) => { - // Re-export any primitive-type constants. - if let syn::Visibility::Public(_) = c.vis { - if let syn::Type::Path(p) = &*c.ty { - let resolved_path = type_resolver.resolve_path(&p.path, None); - if type_resolver.is_primitive(&resolved_path) { - writeln!(out, "\n#[no_mangle]").unwrap(); - writeln!(out, "pub static {}: {} = {}::{}::{};", c.ident, resolved_path, orig_crate, module, c.ident).unwrap(); - } - } - } - }, - syn::Item::Type(t) => { - if let syn::Visibility::Public(_) = t.vis { - match export_status(&t.attrs) { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => continue, - } - - let mut process_alias = true; - for tok in t.generics.params.iter() { - if let syn::GenericParam::Lifetime(_) = tok {} - else { process_alias = false; } - } - if process_alias { - match &*t.ty { - syn::Type::Path(_) => - writeln_opaque(&mut out, &t.ident, &format!("{}", t.ident), &t.generics, &t.attrs, &type_resolver, header_file, cpp_header_file), - _ => {} - } - } - } - }, - syn::Item::Fn(f) => { - if let syn::Visibility::Public(_) = f.vis { - writeln_fn(&mut out, &f, &mut type_resolver); - } - }, - syn::Item::Macro(m) => { - if m.ident.is_none() { // If its not a macro definition - convert_macro(&mut out, &m.mac.path, &m.mac.tokens, &type_resolver); - } - }, - syn::Item::Verbatim(_) => {}, - syn::Item::ExternCrate(_) => {}, - _ => unimplemented!(), - } - } - - out.flush().unwrap(); - } -} - -fn walk_private_mod<'a>(module: String, items: &'a syn::ItemMod, crate_types: &mut CrateTypes<'a>) { - let import_resolver = ImportResolver::new(&module, &items.content.as_ref().unwrap().1); - for item in items.content.as_ref().unwrap().1.iter() { - match item { - syn::Item::Mod(m) => walk_private_mod(format!("{}::{}", module, m.ident), m, crate_types), - syn::Item::Impl(i) => { - if let &syn::Type::Path(ref p) = &*i.self_ty { - if let Some(trait_path) = i.trait_.as_ref() { - if let Some(tp) = import_resolver.maybe_resolve_path(&trait_path.1, None) { - if let Some(sp) = import_resolver.maybe_resolve_path(&p.path, None) { - match crate_types.trait_impls.entry(sp) { - hash_map::Entry::Occupied(mut e) => { e.get_mut().push(tp); }, - hash_map::Entry::Vacant(e) => { e.insert(vec![tp]); }, - } - } - } - } - } - }, - _ => {}, - } - } -} - -/// Walk the FullLibraryAST, deciding how things will be mapped and adding tracking to CrateTypes. -fn walk_ast<'a>(ast_storage: &'a FullLibraryAST, crate_types: &mut CrateTypes<'a>) { - for (module, astmod) in ast_storage.modules.iter() { - let ASTModule { ref attrs, ref items, submods: _ } = astmod; - assert_eq!(export_status(&attrs), ExportStatus::Export); - let import_resolver = ImportResolver::new(module, items); - - for item in items.iter() { - match item { - syn::Item::Struct(s) => { - if let syn::Visibility::Public(_) = s.vis { - match export_status(&s.attrs) { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => continue, - } - let struct_path = format!("{}::{}", module, s.ident); - crate_types.opaques.insert(struct_path, &s.ident); - } - }, - syn::Item::Trait(t) => { - if let syn::Visibility::Public(_) = t.vis { - match export_status(&t.attrs) { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => continue, - } - 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); - } - }, - syn::Item::Type(t) => { - if let syn::Visibility::Public(_) = t.vis { - match export_status(&t.attrs) { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => continue, - } - let type_path = format!("{}::{}", module, t.ident); - let mut process_alias = true; - for tok in t.generics.params.iter() { - if let syn::GenericParam::Lifetime(_) = tok {} - else { process_alias = false; } - } - if process_alias { - match &*t.ty { - syn::Type::Path(p) => { - // If its a path with no generics, assume we don't map the aliased type and map it opaque - let mut segments = syn::punctuated::Punctuated::new(); - segments.push(syn::PathSegment { - ident: t.ident.clone(), - arguments: syn::PathArguments::None, - }); - let path_obj = syn::Path { leading_colon: None, segments }; - let args_obj = p.path.segments.last().unwrap().arguments.clone(); - match crate_types.reverse_alias_map.entry(import_resolver.maybe_resolve_path(&p.path, None).unwrap()) { - hash_map::Entry::Occupied(mut e) => { e.get_mut().push((path_obj, args_obj)); }, - hash_map::Entry::Vacant(e) => { e.insert(vec![(path_obj, args_obj)]); }, - } - - crate_types.opaques.insert(type_path.clone(), &t.ident); - }, - _ => { - crate_types.type_aliases.insert(type_path, import_resolver.resolve_imported_refs((*t.ty).clone())); - } - } - } - } - }, - syn::Item::Enum(e) if is_enum_opaque(e) => { - if let syn::Visibility::Public(_) = e.vis { - match export_status(&e.attrs) { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => continue, - } - let enum_path = format!("{}::{}", module, e.ident); - crate_types.opaques.insert(enum_path, &e.ident); - } - }, - syn::Item::Enum(e) => { - if let syn::Visibility::Public(_) = e.vis { - match export_status(&e.attrs) { - ExportStatus::Export => {}, - ExportStatus::NoExport|ExportStatus::TestOnly => continue, - } - let enum_path = format!("{}::{}", module, e.ident); - crate_types.mirrored_enums.insert(enum_path, &e); - } - }, - syn::Item::Impl(i) => { - if let &syn::Type::Path(ref p) = &*i.self_ty { - if let Some(trait_path) = i.trait_.as_ref() { - if path_matches_nongeneric(&trait_path.1, &["core", "clone", "Clone"]) { - if let Some(full_path) = import_resolver.maybe_resolve_path(&p.path, None) { - crate_types.clonable_types.insert("crate::".to_owned() + &full_path); - } - } - if let Some(tp) = import_resolver.maybe_resolve_path(&trait_path.1, None) { - if let Some(sp) = import_resolver.maybe_resolve_path(&p.path, None) { - match crate_types.trait_impls.entry(sp) { - hash_map::Entry::Occupied(mut e) => { e.get_mut().push(tp); }, - hash_map::Entry::Vacant(e) => { e.insert(vec![tp]); }, - } - } - } - } - } - }, - syn::Item::Mod(m) => walk_private_mod(format!("{}::{}", module, m.ident), m, crate_types), - _ => {}, - } - } - } -} - -fn main() { - let args: Vec = env::args().collect(); - if args.len() != 6 { - eprintln!("Usage: target/dir source_crate_name derived_templates.rs extra/includes.h extra/cpp/includes.hpp"); - process::exit(1); - } - - let mut derived_templates = std::fs::OpenOptions::new().write(true).create(true).truncate(true) - .open(&args[3]).expect("Unable to open new header file"); - let mut header_file = std::fs::OpenOptions::new().write(true).create(true).truncate(true) - .open(&args[4]).expect("Unable to open new header file"); - let mut cpp_header_file = std::fs::OpenOptions::new().write(true).create(true).truncate(true) - .open(&args[5]).expect("Unable to open new header file"); - - writeln!(header_file, "#if defined(__GNUC__)").unwrap(); - writeln!(header_file, "#define MUST_USE_STRUCT __attribute__((warn_unused))").unwrap(); - writeln!(header_file, "#define MUST_USE_RES __attribute__((warn_unused_result))").unwrap(); - writeln!(header_file, "#else").unwrap(); - writeln!(header_file, "#define MUST_USE_STRUCT").unwrap(); - writeln!(header_file, "#define MUST_USE_RES").unwrap(); - writeln!(header_file, "#endif").unwrap(); - writeln!(header_file, "#if defined(__clang__)").unwrap(); - writeln!(header_file, "#define NONNULL_PTR _Nonnull").unwrap(); - writeln!(header_file, "#else").unwrap(); - writeln!(header_file, "#define NONNULL_PTR").unwrap(); - writeln!(header_file, "#endif").unwrap(); - writeln!(cpp_header_file, "#include \nnamespace LDK {{").unwrap(); - - // First parse the full crate's ASTs, caching them so that we can hold references to the AST - // objects in other datastructures: - let mut lib_src = String::new(); - std::io::stdin().lock().read_to_string(&mut lib_src).unwrap(); - let lib_syntax = syn::parse_file(&lib_src).expect("Unable to parse file"); - let libast = FullLibraryAST::load_lib(lib_syntax); - - // ...then walk the ASTs tracking what types we will map, and how, so that we can resolve them - // when parsing other file ASTs... - let mut libtypes = CrateTypes { traits: HashMap::new(), opaques: HashMap::new(), mirrored_enums: HashMap::new(), - type_aliases: HashMap::new(), reverse_alias_map: HashMap::new(), templates_defined: HashMap::default(), - template_file: &mut derived_templates, - clonable_types: HashSet::new(), trait_impls: HashMap::new() }; - walk_ast(&libast, &mut libtypes); - - // ... finally, do the actual file conversion/mapping, writing out types as we go. - convert_file(&libast, &mut libtypes, &args[1], &args[2], &mut header_file, &mut cpp_header_file); - - // For container templates which we created while walking the crate, make sure we add C++ - // mapped types so that C++ users can utilize the auto-destructors available. - for (ty, has_destructor) in libtypes.templates_defined.iter() { - write_cpp_wrapper(&mut cpp_header_file, ty, *has_destructor); - } - writeln!(cpp_header_file, "}}").unwrap(); - - header_file.flush().unwrap(); - cpp_header_file.flush().unwrap(); - derived_templates.flush().unwrap(); -} diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs deleted file mode 100644 index ad21b4c6b..000000000 --- a/c-bindings-gen/src/types.rs +++ /dev/null @@ -1,2182 +0,0 @@ -use std::collections::{HashMap, HashSet}; -use std::fs::File; -use std::io::Write; -use std::hash; - -use crate::blocks::*; - -use proc_macro2::{TokenTree, Span}; - -// The following utils are used purely to build our known types maps - they break down all the -// types we need to resolve to include the given object, and no more. - -pub fn first_seg_self<'a>(t: &'a syn::Type) -> Option + 'a> { - match t { - syn::Type::Path(p) => { - if p.qself.is_some() || p.path.leading_colon.is_some() { - return None; - } - let mut segs = p.path.segments.iter(); - let ty = segs.next().unwrap(); - if !ty.arguments.is_empty() { return None; } - if format!("{}", ty.ident) == "Self" { - Some(segs) - } else { None } - }, - _ => None, - } -} - -pub fn get_single_remaining_path_seg<'a, I: Iterator>(segs: &mut I) -> Option<&'a syn::Ident> { - if let Some(ty) = segs.next() { - if !ty.arguments.is_empty() { unimplemented!(); } - if segs.next().is_some() { return None; } - Some(&ty.ident) - } else { None } -} - -pub fn single_ident_generic_path_to_ident(p: &syn::Path) -> Option<&syn::Ident> { - if p.segments.len() == 1 { - Some(&p.segments.iter().next().unwrap().ident) - } else { None } -} - -pub fn path_matches_nongeneric(p: &syn::Path, exp: &[&str]) -> bool { - if p.segments.len() != exp.len() { return false; } - for (seg, e) in p.segments.iter().zip(exp.iter()) { - if seg.arguments != syn::PathArguments::None { return false; } - if &format!("{}", seg.ident) != *e { return false; } - } - true -} - -#[derive(Debug, PartialEq)] -pub enum ExportStatus { - Export, - NoExport, - TestOnly, -} -/// Gets the ExportStatus of an object (struct, fn, etc) given its attributes. -pub fn export_status(attrs: &[syn::Attribute]) -> ExportStatus { - 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::Punct(c) if c.as_char() == '=' => { - // Really not sure where syn gets '=' from here - - // it somehow represents '///' or '//!' - }, - TokenTree::Group(g) => { - if format!("{}", single_ident_generic_path_to_ident(&attr.path).unwrap()) == "cfg" { - let mut iter = g.stream().into_iter(); - if let TokenTree::Ident(i) = iter.next().unwrap() { - if i == "any" { - // #[cfg(any(test, feature = ""))] - if let TokenTree::Group(g) = iter.next().unwrap() { - if let TokenTree::Ident(i) = g.stream().into_iter().next().unwrap() { - if i == "test" || i == "feature" { - // If its cfg(feature(...)) we assume its test-only - return ExportStatus::TestOnly; - } - } - } - } else if i == "test" || i == "feature" { - // If its cfg(feature(...)) we assume its test-only - return ExportStatus::TestOnly; - } - } - } - continue; // eg #[derive()] - }, - _ => unimplemented!(), - } - } else { continue; } - match token_iter.next().unwrap() { - TokenTree::Literal(lit) => { - let line = format!("{}", lit); - if line.contains("(C-not exported)") { - return ExportStatus::NoExport; - } - }, - _ => unimplemented!(), - } - } - ExportStatus::Export -} - -pub fn assert_simple_bound(bound: &syn::TraitBound) { - if bound.paren_token.is_some() || bound.lifetimes.is_some() { unimplemented!(); } - if let syn::TraitBoundModifier::Maybe(_) = bound.modifier { unimplemented!(); } -} - -/// Returns true if the enum will be mapped as an opaue (ie struct with a pointer to the underlying -/// type), otherwise it is mapped into a transparent, C-compatible version of itself. -pub fn is_enum_opaque(e: &syn::ItemEnum) -> bool { - for var in e.variants.iter() { - if let syn::Fields::Named(fields) = &var.fields { - for field in fields.named.iter() { - match export_status(&field.attrs) { - ExportStatus::Export|ExportStatus::TestOnly => {}, - ExportStatus::NoExport => return true, - } - } - } else if let syn::Fields::Unnamed(fields) = &var.fields { - for field in fields.unnamed.iter() { - match export_status(&field.attrs) { - ExportStatus::Export|ExportStatus::TestOnly => {}, - ExportStatus::NoExport => return true, - } - } - } - } - false -} - -/// A stack of sets of generic resolutions. -/// -/// This tracks the template parameters for a function, struct, or trait, allowing resolution into -/// a concrete type. By pushing a new context onto the stack, this can track a function's template -/// parameters inside of a generic struct or trait. -/// -/// It maps both direct types as well as Deref, mapping them via the provided -/// TypeResolver's resolve_path function (ie traits map to the concrete jump table, structs to the -/// concrete C container struct, etc). -pub struct GenericTypes<'a> { - typed_generics: Vec)>>, -} -impl<'a> GenericTypes<'a> { - pub fn new() -> Self { - Self { typed_generics: vec![HashMap::new()], } - } - - /// push a new context onto the stack, allowing for a new set of generics to be learned which - /// will override any lower contexts, but which will still fall back to resoltion via lower - /// contexts. - pub fn push_ctx(&mut self) { - self.typed_generics.push(HashMap::new()); - } - /// pop the latest context off the stack. - pub fn pop_ctx(&mut self) { - self.typed_generics.pop(); - } - - /// Learn the generics in generics in the current context, given a TypeResolver. - pub fn learn_generics<'b, 'c>(&mut self, generics: &'a syn::Generics, types: &'b TypeResolver<'a, 'c>) -> bool { - // First learn simple generics... - for generic in generics.params.iter() { - match generic { - syn::GenericParam::Type(type_param) => { - let mut non_lifetimes_processed = false; - for bound in type_param.bounds.iter() { - if let syn::TypeParamBound::Trait(trait_bound) = bound { - if let Some(ident) = single_ident_generic_path_to_ident(&trait_bound.path) { - match &format!("{}", ident) as &str { "Send" => continue, "Sync" => continue, _ => {} } - } - if path_matches_nongeneric(&trait_bound.path, &["core", "clone", "Clone"]) { continue; } - - assert_simple_bound(&trait_bound); - if let Some(mut path) = types.maybe_resolve_path(&trait_bound.path, None) { - if types.skip_path(&path) { continue; } - if non_lifetimes_processed { return false; } - non_lifetimes_processed = true; - let new_ident = if path != "std::ops::Deref" { - path = "crate::".to_string() + &path; - Some(&trait_bound.path) - } else { None }; - self.typed_generics.last_mut().unwrap().insert(&type_param.ident, (path, new_ident)); - } else { return false; } - } - } - }, - _ => {}, - } - } - // Then find generics where we are required to pass a Deref and pretend its just X. - if let Some(wh) = &generics.where_clause { - for pred in wh.predicates.iter() { - if let syn::WherePredicate::Type(t) = pred { - if let syn::Type::Path(p) = &t.bounded_ty { - if p.qself.is_some() { return false; } - if p.path.leading_colon.is_some() { return false; } - let mut p_iter = p.path.segments.iter(); - if let Some(gen) = self.typed_generics.last_mut().unwrap().get_mut(&p_iter.next().unwrap().ident) { - if gen.0 != "std::ops::Deref" { return false; } - if &format!("{}", p_iter.next().unwrap().ident) != "Target" { return false; } - - let mut non_lifetimes_processed = false; - for bound in t.bounds.iter() { - if let syn::TypeParamBound::Trait(trait_bound) = bound { - if non_lifetimes_processed { return false; } - non_lifetimes_processed = true; - assert_simple_bound(&trait_bound); - *gen = ("crate::".to_string() + &types.resolve_path(&trait_bound.path, None), - Some(&trait_bound.path)); - } - } - } else { return false; } - } else { return false; } - } - } - } - for (_, (_, ident)) in self.typed_generics.last().unwrap().iter() { - if ident.is_none() { return false; } - } - true - } - - /// Learn the associated types from the trait in the current context. - pub fn learn_associated_types<'b, 'c>(&mut self, t: &'a syn::ItemTrait, types: &'b TypeResolver<'a, 'c>) { - for item in t.items.iter() { - match item { - &syn::TraitItem::Type(ref t) => { - if t.default.is_some() || t.generics.lt_token.is_some() { unimplemented!(); } - let mut bounds_iter = t.bounds.iter(); - match bounds_iter.next().unwrap() { - syn::TypeParamBound::Trait(tr) => { - assert_simple_bound(&tr); - if let Some(mut path) = types.maybe_resolve_path(&tr.path, None) { - if types.skip_path(&path) { continue; } - // In general we handle Deref as if it were just X (and - // implement Deref for relevant types). We don't - // bother to implement it for associated types, however, so we just - // ignore such bounds. - let new_ident = if path != "std::ops::Deref" { - path = "crate::".to_string() + &path; - Some(&tr.path) - } else { None }; - self.typed_generics.last_mut().unwrap().insert(&t.ident, (path, new_ident)); - } else { unimplemented!(); } - }, - _ => unimplemented!(), - } - if bounds_iter.next().is_some() { unimplemented!(); } - }, - _ => {}, - } - } - } - - /// Attempt to resolve an Ident as a generic parameter and return the full path. - pub fn maybe_resolve_ident<'b>(&'b self, ident: &syn::Ident) -> Option<&'b String> { - for gen in self.typed_generics.iter().rev() { - if let Some(res) = gen.get(ident).map(|(a, _)| a) { - return Some(res); - } - } - None - } - /// Attempt to resolve a Path as a generic parameter and return the full path. as both a string - /// and syn::Path. - pub fn maybe_resolve_path<'b>(&'b self, path: &syn::Path) -> Option<(&'b String, &'a syn::Path)> { - if let Some(ident) = path.get_ident() { - for gen in self.typed_generics.iter().rev() { - if let Some(res) = gen.get(ident).map(|(a, b)| (a, b.unwrap())) { - return Some(res); - } - } - } else { - // Associated types are usually specified as "Self::Generic", so we check for that - // explicitly here. - let mut it = path.segments.iter(); - if path.segments.len() == 2 && format!("{}", it.next().unwrap().ident) == "Self" { - let ident = &it.next().unwrap().ident; - for gen in self.typed_generics.iter().rev() { - if let Some(res) = gen.get(ident).map(|(a, b)| (a, b.unwrap())) { - return Some(res); - } - } - } - } - None - } -} - -#[derive(Clone, PartialEq)] -// The type of declaration and the object itself -pub enum DeclType<'a> { - MirroredEnum, - Trait(&'a syn::ItemTrait), - StructImported, - StructIgnored, - EnumIgnored, -} - -pub struct ImportResolver<'mod_lifetime, 'crate_lft: 'mod_lifetime> { - module_path: &'mod_lifetime str, - imports: HashMap, - declared: HashMap>, - priv_modules: HashSet, -} -impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'crate_lft> { - fn process_use_intern(imports: &mut HashMap, u: &syn::UseTree, partial_path: &str, mut path: syn::punctuated::Punctuated) { - match u { - syn::UseTree::Path(p) => { - let new_path = format!("{}{}::", partial_path, p.ident); - path.push(syn::PathSegment { ident: p.ident.clone(), arguments: syn::PathArguments::None }); - Self::process_use_intern(imports, &p.tree, &new_path, path); - }, - syn::UseTree::Name(n) => { - let full_path = format!("{}{}", partial_path, n.ident); - path.push(syn::PathSegment { ident: n.ident.clone(), arguments: syn::PathArguments::None }); - imports.insert(n.ident.clone(), (full_path, syn::Path { leading_colon: Some(syn::Token![::](Span::call_site())), segments: path })); - }, - syn::UseTree::Group(g) => { - for i in g.items.iter() { - Self::process_use_intern(imports, i, partial_path, path.clone()); - } - }, - syn::UseTree::Rename(r) => { - let full_path = format!("{}{}", partial_path, r.ident); - path.push(syn::PathSegment { ident: r.ident.clone(), arguments: syn::PathArguments::None }); - imports.insert(r.rename.clone(), (full_path, syn::Path { leading_colon: Some(syn::Token![::](Span::call_site())), segments: path })); - }, - syn::UseTree::Glob(_) => { - eprintln!("Ignoring * use for {} - this may result in resolution failures", partial_path); - }, - } - } - - fn process_use(imports: &mut HashMap, u: &syn::ItemUse) { - if let syn::Visibility::Public(_) = u.vis { - // We actually only use these for #[cfg(fuzztarget)] - eprintln!("Ignoring pub(use) tree!"); - return; - } - if u.leading_colon.is_some() { eprintln!("Ignoring leading-colon use!"); return; } - Self::process_use_intern(imports, &u.tree, "", syn::punctuated::Punctuated::new()); - } - - fn insert_primitive(imports: &mut HashMap, id: &str) { - let ident = syn::Ident::new(id, Span::call_site()); - let mut path = syn::punctuated::Punctuated::new(); - path.push(syn::PathSegment { ident: ident.clone(), arguments: syn::PathArguments::None }); - imports.insert(ident, (id.to_owned(), syn::Path { leading_colon: Some(syn::Token![::](Span::call_site())), segments: path })); - } - - pub fn new(module_path: &'mod_lifetime str, contents: &'crate_lft [syn::Item]) -> Self { - let mut imports = HashMap::new(); - // Add primitives to the "imports" list: - Self::insert_primitive(&mut imports, "bool"); - Self::insert_primitive(&mut imports, "u64"); - Self::insert_primitive(&mut imports, "u32"); - Self::insert_primitive(&mut imports, "u16"); - Self::insert_primitive(&mut imports, "u8"); - Self::insert_primitive(&mut imports, "usize"); - Self::insert_primitive(&mut imports, "str"); - Self::insert_primitive(&mut imports, "String"); - - // These are here to allow us to print native Rust types in trait fn impls even if we don't - // have C mappings: - Self::insert_primitive(&mut imports, "Result"); - Self::insert_primitive(&mut imports, "Vec"); - Self::insert_primitive(&mut imports, "Option"); - - let mut declared = HashMap::new(); - let mut priv_modules = HashSet::new(); - - for item in contents.iter() { - match item { - syn::Item::Use(u) => Self::process_use(&mut imports, &u), - syn::Item::Struct(s) => { - if let syn::Visibility::Public(_) = s.vis { - match export_status(&s.attrs) { - ExportStatus::Export => { declared.insert(s.ident.clone(), DeclType::StructImported); }, - ExportStatus::NoExport => { declared.insert(s.ident.clone(), DeclType::StructIgnored); }, - ExportStatus::TestOnly => continue, - } - } - }, - syn::Item::Type(t) if export_status(&t.attrs) == ExportStatus::Export => { - if let syn::Visibility::Public(_) = t.vis { - let mut process_alias = true; - for tok in t.generics.params.iter() { - if let syn::GenericParam::Lifetime(_) = tok {} - else { process_alias = false; } - } - if process_alias { - match &*t.ty { - syn::Type::Path(_) => { declared.insert(t.ident.clone(), DeclType::StructImported); }, - _ => {}, - } - } - } - }, - syn::Item::Enum(e) => { - if let syn::Visibility::Public(_) = e.vis { - match export_status(&e.attrs) { - ExportStatus::Export if is_enum_opaque(e) => { declared.insert(e.ident.clone(), DeclType::EnumIgnored); }, - ExportStatus::Export => { declared.insert(e.ident.clone(), DeclType::MirroredEnum); }, - _ => continue, - } - } - }, - syn::Item::Trait(t) if export_status(&t.attrs) == ExportStatus::Export => { - if let syn::Visibility::Public(_) = t.vis { - declared.insert(t.ident.clone(), DeclType::Trait(t)); - } - }, - syn::Item::Mod(m) => { - priv_modules.insert(m.ident.clone()); - }, - _ => {}, - } - } - - Self { module_path, imports, declared, priv_modules } - } - - pub fn get_declared_type(&self, ident: &syn::Ident) -> Option<&DeclType<'crate_lft>> { - self.declared.get(ident) - } - - pub fn maybe_resolve_declared(&self, id: &syn::Ident) -> Option<&DeclType<'crate_lft>> { - self.declared.get(id) - } - - pub fn maybe_resolve_ident(&self, id: &syn::Ident) -> Option { - if let Some((imp, _)) = self.imports.get(id) { - Some(imp.clone()) - } else if self.declared.get(id).is_some() { - Some(self.module_path.to_string() + "::" + &format!("{}", id)) - } else { None } - } - - pub fn maybe_resolve_non_ignored_ident(&self, id: &syn::Ident) -> Option { - if let Some((imp, _)) = self.imports.get(id) { - Some(imp.clone()) - } else if let Some(decl_type) = self.declared.get(id) { - match decl_type { - DeclType::StructIgnored => None, - _ => Some(self.module_path.to_string() + "::" + &format!("{}", id)), - } - } else { None } - } - - pub fn maybe_resolve_path(&self, p_arg: &syn::Path, generics: Option<&GenericTypes>) -> Option { - let p = if let Some(gen_types) = generics { - if let Some((_, synpath)) = gen_types.maybe_resolve_path(p_arg) { - synpath - } else { p_arg } - } else { p_arg }; - - if p.leading_colon.is_some() { - Some(p.segments.iter().enumerate().map(|(idx, seg)| { - format!("{}{}", if idx == 0 { "" } else { "::" }, seg.ident) - }).collect()) - } else if let Some(id) = p.get_ident() { - self.maybe_resolve_ident(id) - } else { - if p.segments.len() == 1 { - let seg = p.segments.iter().next().unwrap(); - return self.maybe_resolve_ident(&seg.ident); - } - let mut seg_iter = p.segments.iter(); - let first_seg = seg_iter.next().unwrap(); - let remaining: String = seg_iter.map(|seg| { - format!("::{}", seg.ident) - }).collect(); - if let Some((imp, _)) = self.imports.get(&first_seg.ident) { - if remaining != "" { - Some(imp.clone() + &remaining) - } else { - Some(imp.clone()) - } - } else if let Some(_) = self.priv_modules.get(&first_seg.ident) { - Some(format!("{}::{}{}", self.module_path, first_seg.ident, remaining)) - } else { None } - } - } - - /// Map all the Paths in a Type into absolute paths given a set of imports (generated via process_use_intern) - pub fn resolve_imported_refs(&self, mut ty: syn::Type) -> syn::Type { - match &mut ty { - syn::Type::Path(p) => { - if let Some(ident) = p.path.get_ident() { - if let Some((_, newpath)) = self.imports.get(ident) { - p.path = newpath.clone(); - } - } else { unimplemented!(); } - }, - syn::Type::Reference(r) => { - r.elem = Box::new(self.resolve_imported_refs((*r.elem).clone())); - }, - syn::Type::Slice(s) => { - s.elem = Box::new(self.resolve_imported_refs((*s.elem).clone())); - }, - syn::Type::Tuple(t) => { - for e in t.elems.iter_mut() { - *e = self.resolve_imported_refs(e.clone()); - } - }, - _ => unimplemented!(), - } - ty - } -} - -// templates_defined is walked to write the C++ header, so if we use the default hashing it get -// reordered on each genbindings run. Instead, we use SipHasher (which defaults to 0-keys) so that -// the sorting is stable across runs. It is deprecated, but the "replacement" doesn't actually -// accomplish the same goals, so we just ignore it. -#[allow(deprecated)] -pub type NonRandomHash = hash::BuildHasherDefault; - -/// Top-level struct tracking everything which has been defined while walking the crate. -pub struct CrateTypes<'a> { - /// This may contain structs or enums, but only when either is mapped as - /// struct X { inner: *mut originalX, .. } - pub opaques: HashMap, - /// Enums which are mapped as C enums with conversion functions - pub mirrored_enums: HashMap, - /// Traits which are mapped as a pointer + jump table - pub traits: HashMap, - /// Aliases from paths to some other Type - pub type_aliases: HashMap, - /// Value is an alias to Key (maybe with some generics) - pub reverse_alias_map: HashMap>, - /// Template continer types defined, map from mangled type name -> whether a destructor fn - /// exists. - /// - /// This is used at the end of processing to make C++ wrapper classes - pub templates_defined: HashMap, - /// The output file for any created template container types, written to as we find new - /// template containers which need to be defined. - pub template_file: &'a mut File, - /// Set of containers which are clonable - pub clonable_types: HashSet, - /// Key impls Value - pub trait_impls: HashMap>, -} - -/// A struct which tracks resolving rust types into C-mapped equivalents, exists for one specific -/// module but contains a reference to the overall CrateTypes tracking. -pub struct TypeResolver<'mod_lifetime, 'crate_lft: 'mod_lifetime> { - pub orig_crate: &'mod_lifetime str, - pub module_path: &'mod_lifetime str, - pub crate_types: &'mod_lifetime mut CrateTypes<'crate_lft>, - types: ImportResolver<'mod_lifetime, 'crate_lft>, -} - -/// Returned by write_empty_rust_val_check_suffix to indicate what type of dereferencing needs to -/// happen to get the inner value of a generic. -enum EmptyValExpectedTy { - /// A type which has a flag for being empty (eg an array where we treat all-0s as empty). - NonPointer, - /// A pointer that we want to dereference and move out of. - OwnedPointer, - /// A pointer which we want to convert to a reference. - ReferenceAsPointer, -} - -impl<'a, 'c: 'a> TypeResolver<'a, 'c> { - pub fn new(orig_crate: &'a str, module_path: &'a str, types: ImportResolver<'a, 'c>, crate_types: &'a mut CrateTypes<'c>) -> Self { - Self { orig_crate, module_path, types, crate_types } - } - - // ************************************************* - // *** Well know type and conversion definitions *** - // ************************************************* - - /// Returns true we if can just skip passing this to C entirely - fn skip_path(&self, full_path: &str) -> bool { - full_path == "bitcoin::secp256k1::Secp256k1" || - full_path == "bitcoin::secp256k1::Signing" || - full_path == "bitcoin::secp256k1::Verification" - } - /// Returns true we if can just skip passing this to C entirely - fn no_arg_path_to_rust(&self, full_path: &str) -> &str { - if full_path == "bitcoin::secp256k1::Secp256k1" { - "secp256k1::SECP256K1" - } else { unimplemented!(); } - } - - /// Returns true if the object is a primitive and is mapped as-is with no conversion - /// whatsoever. - pub fn is_primitive(&self, full_path: &str) -> bool { - match full_path { - "bool" => true, - "u64" => true, - "u32" => true, - "u16" => true, - "u8" => true, - "usize" => true, - _ => 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 - /// 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> { - if self.is_primitive(full_path) { - return Some(full_path); - } - match full_path { - "Result" => Some("crate::c_types::derived::CResult"), - "Vec" if !is_ref => Some("crate::c_types::derived::CVec"), - "Option" => Some(""), - - // Note that no !is_ref types can map to an array because Rust and C's call semantics - // for arrays are different (https://github.com/eqrion/cbindgen/issues/528) - - "[u8; 32]" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"), - "[u8; 16]" if !is_ref => Some("crate::c_types::SixteenBytes"), - "[u8; 10]" if !is_ref => Some("crate::c_types::TenBytes"), - "[u8; 4]" if !is_ref => Some("crate::c_types::FourBytes"), - "[u8; 3]" if !is_ref => Some("crate::c_types::ThreeBytes"), // Used for RGB values - - "str" if is_ref => Some("crate::c_types::Str"), - "String" if !is_ref => Some("crate::c_types::derived::CVec_u8Z"), - "String" if is_ref => Some("crate::c_types::Str"), - - "std::time::Duration" => Some("u64"), - - "bitcoin::secp256k1::key::PublicKey" => Some("crate::c_types::PublicKey"), - "bitcoin::secp256k1::Signature" => Some("crate::c_types::Signature"), - "bitcoin::secp256k1::key::SecretKey" if is_ref => Some("*const [u8; 32]"), - "bitcoin::secp256k1::key::SecretKey" if !is_ref => Some("crate::c_types::SecretKey"), - "bitcoin::secp256k1::Error" if !is_ref => Some("crate::c_types::Secp256k1Error"), - "bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice"), - "bitcoin::blockdata::script::Script" if !is_ref => Some("crate::c_types::derived::CVec_u8Z"), - "bitcoin::blockdata::transaction::OutPoint" => Some("crate::chain::transaction::OutPoint"), - "bitcoin::blockdata::transaction::Transaction" => Some("crate::c_types::Transaction"), - "bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut"), - "bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network"), - "bitcoin::blockdata::block::BlockHeader" if is_ref => Some("*const [u8; 80]"), - "bitcoin::blockdata::block::Block" if is_ref => Some("crate::c_types::u8slice"), - - // Newtypes that we just expose in their original form. - "bitcoin::hash_types::Txid" if is_ref => Some("*const [u8; 32]"), - "bitcoin::hash_types::Txid" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"), - "bitcoin::hash_types::BlockHash" if is_ref => Some("*const [u8; 32]"), - "bitcoin::hash_types::BlockHash" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"), - "bitcoin::secp256k1::Message" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"), - "ln::channelmanager::PaymentHash" if is_ref => Some("*const [u8; 32]"), - "ln::channelmanager::PaymentHash" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"), - "ln::channelmanager::PaymentPreimage" if is_ref => Some("*const [u8; 32]"), - "ln::channelmanager::PaymentPreimage" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"), - "ln::channelmanager::PaymentSecret" if is_ref => Some("crate::c_types::ThirtyTwoBytes"), - "ln::channelmanager::PaymentSecret" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"), - - // Override the default since Records contain an fmt with a lifetime: - "util::logger::Record" => Some("*const std::os::raw::c_char"), - - _ => None, - } - } - - fn from_c_conversion_new_var_from_path<'b>(&self, _full_path: &str, _is_ref: bool) -> Option<(&'b str, &'b str)> { - None - } - fn from_c_conversion_prefix_from_path<'b>(&self, full_path: &str, is_ref: bool) -> Option { - if self.is_primitive(full_path) { - return Some("".to_owned()); - } - match full_path { - "Vec" if !is_ref => Some("local_"), - "Result" if !is_ref => Some("local_"), - "Option" if is_ref => Some("&local_"), - "Option" => Some("local_"), - - "[u8; 32]" if is_ref => Some("unsafe { &*"), - "[u8; 32]" if !is_ref => Some(""), - "[u8; 16]" if !is_ref => Some(""), - "[u8; 10]" if !is_ref => Some(""), - "[u8; 4]" if !is_ref => Some(""), - "[u8; 3]" if !is_ref => Some(""), - - "[u8]" if is_ref => Some(""), - "[usize]" if is_ref => Some(""), - - "str" if is_ref => Some(""), - "String" if !is_ref => Some("String::from_utf8("), - // Note that we'll panic for String if is_ref, as we only have non-owned memory, we - // cannot create a &String. - - "std::time::Duration" => Some("std::time::Duration::from_secs("), - - "bitcoin::secp256k1::key::PublicKey" if is_ref => Some("&"), - "bitcoin::secp256k1::key::PublicKey" => Some(""), - "bitcoin::secp256k1::Signature" if is_ref => Some("&"), - "bitcoin::secp256k1::Signature" => Some(""), - "bitcoin::secp256k1::key::SecretKey" if is_ref => Some("&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *"), - "bitcoin::secp256k1::key::SecretKey" if !is_ref => Some(""), - "bitcoin::blockdata::script::Script" if is_ref => Some("&::bitcoin::blockdata::script::Script::from(Vec::from("), - "bitcoin::blockdata::script::Script" if !is_ref => Some("::bitcoin::blockdata::script::Script::from("), - "bitcoin::blockdata::transaction::Transaction" if is_ref => Some("&"), - "bitcoin::blockdata::transaction::Transaction" => Some(""), - "bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(""), - "bitcoin::network::constants::Network" => Some(""), - "bitcoin::blockdata::block::BlockHeader" => Some("&::bitcoin::consensus::encode::deserialize(unsafe { &*"), - "bitcoin::blockdata::block::Block" if is_ref => Some("&::bitcoin::consensus::encode::deserialize("), - - // Newtypes that we just expose in their original form. - "bitcoin::hash_types::Txid" if is_ref => Some("&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*"), - "bitcoin::hash_types::Txid" if !is_ref => Some("::bitcoin::hash_types::Txid::from_slice(&"), - "bitcoin::hash_types::BlockHash" => Some("::bitcoin::hash_types::BlockHash::from_slice(&"), - "ln::channelmanager::PaymentHash" if !is_ref => Some("::lightning::ln::channelmanager::PaymentHash("), - "ln::channelmanager::PaymentHash" if is_ref => Some("&::lightning::ln::channelmanager::PaymentHash(unsafe { *"), - "ln::channelmanager::PaymentPreimage" if !is_ref => Some("::lightning::ln::channelmanager::PaymentPreimage("), - "ln::channelmanager::PaymentPreimage" if is_ref => Some("&::lightning::ln::channelmanager::PaymentPreimage(unsafe { *"), - "ln::channelmanager::PaymentSecret" => Some("::lightning::ln::channelmanager::PaymentSecret("), - - // List of traits we map (possibly during processing of other files): - "crate::util::logger::Logger" => Some(""), - - _ => None, - }.map(|s| s.to_owned()) - } - fn from_c_conversion_suffix_from_path<'b>(&self, full_path: &str, is_ref: bool) -> Option { - if self.is_primitive(full_path) { - return Some("".to_owned()); - } - match full_path { - "Vec" if !is_ref => Some(""), - "Option" => Some(""), - "Result" if !is_ref => Some(""), - - "[u8; 32]" if is_ref => Some("}"), - "[u8; 32]" if !is_ref => Some(".data"), - "[u8; 16]" if !is_ref => Some(".data"), - "[u8; 10]" if !is_ref => Some(".data"), - "[u8; 4]" if !is_ref => Some(".data"), - "[u8; 3]" if !is_ref => Some(".data"), - - "[u8]" if is_ref => Some(".to_slice()"), - "[usize]" if is_ref => Some(".to_slice()"), - - "str" if is_ref => Some(".into()"), - "String" if !is_ref => Some(".into_rust()).unwrap()"), - - "std::time::Duration" => Some(")"), - - "bitcoin::secp256k1::key::PublicKey" => Some(".into_rust()"), - "bitcoin::secp256k1::Signature" => Some(".into_rust()"), - "bitcoin::secp256k1::key::SecretKey" if !is_ref => Some(".into_rust()"), - "bitcoin::secp256k1::key::SecretKey" if is_ref => Some("}[..]).unwrap()"), - "bitcoin::blockdata::script::Script" if is_ref => Some(".to_slice()))"), - "bitcoin::blockdata::script::Script" if !is_ref => Some(".into_rust())"), - "bitcoin::blockdata::transaction::Transaction" => Some(".into_bitcoin()"), - "bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(".into_rust()"), - "bitcoin::network::constants::Network" => Some(".into_bitcoin()"), - "bitcoin::blockdata::block::BlockHeader" => Some(" }).unwrap()"), - "bitcoin::blockdata::block::Block" => Some(".to_slice()).unwrap()"), - - // Newtypes that we just expose in their original form. - "bitcoin::hash_types::Txid" if is_ref => Some(" }[..]).unwrap()"), - "bitcoin::hash_types::Txid" => Some(".data[..]).unwrap()"), - "bitcoin::hash_types::BlockHash" if !is_ref => Some(".data[..]).unwrap()"), - "ln::channelmanager::PaymentHash" if !is_ref => Some(".data)"), - "ln::channelmanager::PaymentHash" if is_ref => Some(" })"), - "ln::channelmanager::PaymentPreimage" if !is_ref => Some(".data)"), - "ln::channelmanager::PaymentPreimage" if is_ref => Some(" })"), - "ln::channelmanager::PaymentSecret" => Some(".data)"), - - // List of traits we map (possibly during processing of other files): - "crate::util::logger::Logger" => Some(""), - - _ => None, - }.map(|s| s.to_owned()) - } - - fn to_c_conversion_new_var_from_path<'b>(&self, full_path: &str, is_ref: bool) -> Option<(&'b str, &'b str)> { - if self.is_primitive(full_path) { - return None; - } - match full_path { - "[u8]" if is_ref => Some(("crate::c_types::u8slice::from_slice(", ")")), - "[usize]" if is_ref => Some(("crate::c_types::usizeslice::from_slice(", ")")), - - "bitcoin::blockdata::transaction::Transaction" if is_ref => Some(("::bitcoin::consensus::encode::serialize(", ")")), - "bitcoin::blockdata::transaction::Transaction" if !is_ref => Some(("::bitcoin::consensus::encode::serialize(&", ")")), - "bitcoin::blockdata::block::BlockHeader" if is_ref => Some(("{ let mut s = [0u8; 80]; s[..].copy_from_slice(&::bitcoin::consensus::encode::serialize(", ")); s }")), - "bitcoin::blockdata::block::Block" if is_ref => Some(("::bitcoin::consensus::encode::serialize(", ")")), - "bitcoin::hash_types::Txid" => None, - - // Override the default since Records contain an fmt with a lifetime: - // TODO: We should include the other record fields - "util::logger::Record" => Some(("std::ffi::CString::new(format!(\"{}\", ", ".args)).unwrap()")), - _ => None, - }.map(|s| s.to_owned()) - } - fn to_c_conversion_inline_prefix_from_path(&self, full_path: &str, is_ref: bool, _ptr_for_ref: bool) -> Option { - if self.is_primitive(full_path) { - return Some("".to_owned()); - } - match full_path { - "Result" if !is_ref => Some("local_"), - "Vec" if !is_ref => Some("local_"), - "Option" => Some("local_"), - - "[u8; 32]" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "), - "[u8; 32]" if is_ref => Some("&"), - "[u8; 16]" if !is_ref => Some("crate::c_types::SixteenBytes { data: "), - "[u8; 10]" if !is_ref => Some("crate::c_types::TenBytes { data: "), - "[u8; 4]" if !is_ref => Some("crate::c_types::FourBytes { data: "), - "[u8; 3]" if is_ref => Some("&"), - - "[u8]" if is_ref => Some("local_"), - "[usize]" if is_ref => Some("local_"), - - "str" if is_ref => Some(""), - "String" => Some(""), - - "std::time::Duration" => Some(""), - - "bitcoin::secp256k1::key::PublicKey" => Some("crate::c_types::PublicKey::from_rust(&"), - "bitcoin::secp256k1::Signature" => Some("crate::c_types::Signature::from_rust(&"), - "bitcoin::secp256k1::key::SecretKey" if is_ref => Some(""), - "bitcoin::secp256k1::key::SecretKey" if !is_ref => Some("crate::c_types::SecretKey::from_rust("), - "bitcoin::secp256k1::Error" if !is_ref => Some("crate::c_types::Secp256k1Error::from_rust("), - "bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice::from_slice(&"), - "bitcoin::blockdata::script::Script" if !is_ref => Some(""), - "bitcoin::blockdata::transaction::Transaction" => Some("crate::c_types::Transaction::from_vec(local_"), - "bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::bitcoin_to_C_outpoint("), - "bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut::from_rust("), - "bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network::from_bitcoin("), - "bitcoin::blockdata::block::BlockHeader" if is_ref => Some("&local_"), - "bitcoin::blockdata::block::Block" if is_ref => Some("crate::c_types::u8slice::from_slice(&local_"), - - "bitcoin::hash_types::Txid" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "), - - // Newtypes that we just expose in their original form. - "bitcoin::hash_types::Txid" if is_ref => Some(""), - "bitcoin::hash_types::BlockHash" if is_ref => Some(""), - "bitcoin::hash_types::BlockHash" => Some("crate::c_types::ThirtyTwoBytes { data: "), - "bitcoin::secp256k1::Message" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "), - "ln::channelmanager::PaymentHash" if is_ref => Some("&"), - "ln::channelmanager::PaymentHash" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "), - "ln::channelmanager::PaymentPreimage" if is_ref => Some("&"), - "ln::channelmanager::PaymentPreimage" => Some("crate::c_types::ThirtyTwoBytes { data: "), - "ln::channelmanager::PaymentSecret" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "), - - // Override the default since Records contain an fmt with a lifetime: - "util::logger::Record" => Some("local_"), - - _ => None, - }.map(|s| s.to_owned()) - } - fn to_c_conversion_inline_suffix_from_path(&self, full_path: &str, is_ref: bool, _ptr_for_ref: bool) -> Option { - if self.is_primitive(full_path) { - return Some("".to_owned()); - } - match full_path { - "Result" if !is_ref => Some(""), - "Vec" if !is_ref => Some(".into()"), - "Option" => Some(""), - - "[u8; 32]" if !is_ref => Some(" }"), - "[u8; 32]" if is_ref => Some(""), - "[u8; 16]" if !is_ref => Some(" }"), - "[u8; 10]" if !is_ref => Some(" }"), - "[u8; 4]" if !is_ref => Some(" }"), - "[u8; 3]" if is_ref => Some(""), - - "[u8]" if is_ref => Some(""), - "[usize]" if is_ref => Some(""), - - "str" if is_ref => Some(".into()"), - "String" if !is_ref => Some(".into_bytes().into()"), - "String" if is_ref => Some(".as_str().into()"), - - "std::time::Duration" => Some(".as_secs()"), - - "bitcoin::secp256k1::key::PublicKey" => Some(")"), - "bitcoin::secp256k1::Signature" => Some(")"), - "bitcoin::secp256k1::key::SecretKey" if !is_ref => Some(")"), - "bitcoin::secp256k1::key::SecretKey" if is_ref => Some(".as_ref()"), - "bitcoin::secp256k1::Error" if !is_ref => Some(")"), - "bitcoin::blockdata::script::Script" if is_ref => Some("[..])"), - "bitcoin::blockdata::script::Script" if !is_ref => Some(".into_bytes().into()"), - "bitcoin::blockdata::transaction::Transaction" => Some(")"), - "bitcoin::blockdata::transaction::OutPoint" => Some(")"), - "bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(")"), - "bitcoin::network::constants::Network" => Some(")"), - "bitcoin::blockdata::block::BlockHeader" if is_ref => Some(""), - "bitcoin::blockdata::block::Block" if is_ref => Some(")"), - - "bitcoin::hash_types::Txid" if !is_ref => Some(".into_inner() }"), - - // Newtypes that we just expose in their original form. - "bitcoin::hash_types::Txid" if is_ref => Some(".as_inner()"), - "bitcoin::hash_types::BlockHash" if is_ref => Some(".as_inner()"), - "bitcoin::hash_types::BlockHash" => Some(".into_inner() }"), - "bitcoin::secp256k1::Message" if !is_ref => Some(".as_ref().clone() }"), - "ln::channelmanager::PaymentHash" if is_ref => Some(".0"), - "ln::channelmanager::PaymentHash" => Some(".0 }"), - "ln::channelmanager::PaymentPreimage" if is_ref => Some(".0"), - "ln::channelmanager::PaymentPreimage" => Some(".0 }"), - "ln::channelmanager::PaymentSecret" if !is_ref => Some(".0 }"), - - // Override the default since Records contain an fmt with a lifetime: - "util::logger::Record" => Some(".as_ptr()"), - - _ => None, - }.map(|s| s.to_owned()) - } - - fn empty_val_check_suffix_from_path(&self, full_path: &str) -> Option<&str> { - match full_path { - "ln::channelmanager::PaymentSecret" => Some(".data == [0; 32]"), - "bitcoin::secp256k1::key::PublicKey" => Some(".is_null()"), - "bitcoin::secp256k1::Signature" => Some(".is_null()"), - _ => None - } - } - - // **************************** - // *** Container Processing *** - // **************************** - - /// Returns the module path in the generated mapping crate to the containers which we generate - /// when writing to CrateTypes::template_file. - pub fn generated_container_path() -> &'static str { - "crate::c_types::derived" - } - /// Returns the module path in the generated mapping crate to the container templates, which - /// are then concretized and put in the generated container path/template_file. - fn container_templ_path() -> &'static str { - "crate::c_types" - } - - /// Returns true if this is a "transparent" container, ie an Option or a container which does - /// not require a generated continer class. - fn is_transparent_container(&self, full_path: &str, _is_ref: bool) -> bool { - full_path == "Option" - } - /// Returns true if this is a known, supported, non-transparent container. - fn is_known_container(&self, full_path: &str, is_ref: bool) -> bool { - (full_path == "Result" && !is_ref) || (full_path == "Vec" && !is_ref) || full_path.ends_with("Tuple") - } - fn to_c_conversion_container_new_var<'b>(&self, generics: Option<&GenericTypes>, full_path: &str, is_ref: bool, single_contained: Option<&syn::Type>, var_name: &syn::Ident, var_access: &str) - // Returns prefix + Vec<(prefix, var-name-to-inline-convert)> + suffix - // expecting one element in the vec per generic type, each of which is inline-converted - -> Option<(&'b str, Vec<(String, String)>, &'b str)> { - match full_path { - "Result" if !is_ref => { - Some(("match ", - vec![(" { Ok(mut o) => crate::c_types::CResultTempl::ok(".to_string(), "o".to_string()), - (").into(), Err(mut e) => crate::c_types::CResultTempl::err(".to_string(), "e".to_string())], - ").into() }")) - }, - "Vec" if !is_ref => { - Some(("Vec::new(); for mut item in ", vec![(format!(".drain(..) {{ local_{}.push(", var_name), "item".to_string())], "); }")) - }, - "Slice" => { - Some(("Vec::new(); for item in ", vec![(format!(".iter() {{ local_{}.push(", var_name), "**item".to_string())], "); }")) - }, - "Option" => { - if let Some(syn::Type::Path(p)) = single_contained { - if self.c_type_has_inner_from_path(&self.resolve_path(&p.path, generics)) { - if is_ref { - return Some(("if ", vec![ - (".is_none() { std::ptr::null() } else { ".to_owned(), format!("({}.as_ref().unwrap())", var_access)) - ], " }")); - } else { - return Some(("if ", vec![ - (".is_none() { std::ptr::null_mut() } else { ".to_owned(), format!("({}.unwrap())", var_access)) - ], " }")); - } - } - } - if let Some(t) = single_contained { - let mut v = Vec::new(); - self.write_empty_rust_val(generics, &mut v, t); - let s = String::from_utf8(v).unwrap(); - return Some(("if ", vec![ - (format!(".is_none() {{ {} }} else {{ ", s), format!("({}.unwrap())", var_access)) - ], " }")); - } else { unreachable!(); } - }, - _ => None, - } - } - - /// only_contained_has_inner implies that there is only one contained element in the container - /// and it has an inner field (ie is an "opaque" type we've defined). - fn from_c_conversion_container_new_var<'b>(&self, generics: Option<&GenericTypes>, full_path: &str, is_ref: bool, single_contained: Option<&syn::Type>, var_name: &syn::Ident, var_access: &str) - // Returns prefix + Vec<(prefix, var-name-to-inline-convert)> + suffix - // expecting one element in the vec per generic type, each of which is inline-converted - -> Option<(&'b str, Vec<(String, String)>, &'b str)> { - match full_path { - "Result" if !is_ref => { - Some(("match ", - vec![(".result_ok { true => Ok(".to_string(), format!("(*unsafe {{ Box::from_raw(<*mut _>::take_ptr(&mut {}.contents.result)) }})", var_access)), - ("), false => Err(".to_string(), format!("(*unsafe {{ Box::from_raw(<*mut _>::take_ptr(&mut {}.contents.err)) }})", var_access))], - ")}")) - }, - "Vec"|"Slice" if !is_ref => { - Some(("Vec::new(); for mut item in ", vec![(format!(".into_rust().drain(..) {{ local_{}.push(", var_name), "item".to_string())], "); }")) - }, - "Slice" if is_ref => { - Some(("Vec::new(); for mut item in ", vec![(format!(".as_slice().iter() {{ local_{}.push(", var_name), "item".to_string())], "); }")) - }, - "Option" => { - if let Some(syn::Type::Path(p)) = single_contained { - if self.c_type_has_inner_from_path(&self.resolve_path(&p.path, generics)) { - if is_ref { - return Some(("if ", vec![(".inner.is_null() { None } else { Some((*".to_string(), format!("{}", var_access))], ").clone()) }")) - } else { - return Some(("if ", vec![(".inner.is_null() { None } else { Some(".to_string(), format!("{}", var_access))], ") }")); - } - } - } - - if let Some(t) = single_contained { - let mut v = Vec::new(); - let ret_ref = self.write_empty_rust_val_check_suffix(generics, &mut v, t); - let s = String::from_utf8(v).unwrap(); - match ret_ref { - EmptyValExpectedTy::ReferenceAsPointer => - return Some(("if ", vec![ - (format!("{} {{ None }} else {{ Some(", s), format!("unsafe {{ &mut *{} }}", var_access)) - ], ") }")), - EmptyValExpectedTy::OwnedPointer => - return Some(("if ", vec![ - (format!("{} {{ None }} else {{ Some(", s), format!("unsafe {{ *Box::from_raw({}) }}", var_access)) - ], ") }")), - EmptyValExpectedTy::NonPointer => - return Some(("if ", vec![ - (format!("{} {{ None }} else {{ Some(", s), format!("{}", var_access)) - ], ") }")), - } - } else { unreachable!(); } - }, - _ => None, - } - } - - // ************************************************* - // *** Type definition during main.rs processing *** - // ************************************************* - - pub fn get_declared_type(&'a self, ident: &syn::Ident) -> Option<&'a DeclType<'c>> { - self.types.get_declared_type(ident) - } - /// Returns true if the object at the given path is mapped as X { inner: *mut origX, .. }. - pub fn c_type_has_inner_from_path(&self, full_path: &str) -> bool{ - self.crate_types.opaques.get(full_path).is_some() - } - - pub fn maybe_resolve_ident(&self, id: &syn::Ident) -> Option { - self.types.maybe_resolve_ident(id) - } - - pub fn maybe_resolve_non_ignored_ident(&self, id: &syn::Ident) -> Option { - self.types.maybe_resolve_non_ignored_ident(id) - } - - pub fn maybe_resolve_path(&self, p_arg: &syn::Path, generics: Option<&GenericTypes>) -> Option { - self.types.maybe_resolve_path(p_arg, generics) - } - pub fn resolve_path(&self, p: &syn::Path, generics: Option<&GenericTypes>) -> String { - self.maybe_resolve_path(p, generics).unwrap() - } - - // *********************************** - // *** Original Rust Type Printing *** - // *********************************** - - fn in_rust_prelude(resolved_path: &str) -> bool { - match resolved_path { - "Vec" => true, - "Result" => true, - "Option" => true, - _ => false, - } - } - - fn write_rust_path(&self, w: &mut W, generics_resolver: Option<&GenericTypes>, path: &syn::Path) { - if let Some(resolved) = self.maybe_resolve_path(&path, generics_resolver) { - if self.is_primitive(&resolved) { - write!(w, "{}", path.get_ident().unwrap()).unwrap(); - } else { - // TODO: We should have a generic "is from a dependency" check here instead of - // checking for "bitcoin" explicitly. - if resolved.starts_with("bitcoin::") || Self::in_rust_prelude(&resolved) { - write!(w, "{}", resolved).unwrap(); - // If we're printing a generic argument, it needs to reference the crate, otherwise - // the original crate: - } else if self.maybe_resolve_path(&path, None).as_ref() == Some(&resolved) { - write!(w, "{}::{}", self.orig_crate, resolved).unwrap(); - } else { - write!(w, "crate::{}", resolved).unwrap(); - } - } - if let syn::PathArguments::AngleBracketed(args) = &path.segments.iter().last().unwrap().arguments { - self.write_rust_generic_arg(w, generics_resolver, args.args.iter()); - } - } else { - if path.leading_colon.is_some() { - write!(w, "::").unwrap(); - } - for (idx, seg) in path.segments.iter().enumerate() { - if idx != 0 { write!(w, "::").unwrap(); } - write!(w, "{}", seg.ident).unwrap(); - if let syn::PathArguments::AngleBracketed(args) = &seg.arguments { - self.write_rust_generic_arg(w, generics_resolver, args.args.iter()); - } - } - } - } - pub fn write_rust_generic_param<'b, W: std::io::Write>(&self, w: &mut W, generics_resolver: Option<&GenericTypes>, generics: impl Iterator) { - let mut had_params = false; - for (idx, arg) in generics.enumerate() { - if idx != 0 { write!(w, ", ").unwrap(); } else { write!(w, "<").unwrap(); } - had_params = true; - match arg { - syn::GenericParam::Lifetime(lt) => write!(w, "'{}", lt.lifetime.ident).unwrap(), - syn::GenericParam::Type(t) => { - write!(w, "{}", t.ident).unwrap(); - if t.colon_token.is_some() { write!(w, ":").unwrap(); } - for (idx, bound) in t.bounds.iter().enumerate() { - if idx != 0 { write!(w, " + ").unwrap(); } - match bound { - syn::TypeParamBound::Trait(tb) => { - if tb.paren_token.is_some() || tb.lifetimes.is_some() { unimplemented!(); } - self.write_rust_path(w, generics_resolver, &tb.path); - }, - _ => unimplemented!(), - } - } - if t.eq_token.is_some() || t.default.is_some() { unimplemented!(); } - }, - _ => unimplemented!(), - } - } - if had_params { write!(w, ">").unwrap(); } - } - - pub fn write_rust_generic_arg<'b, W: std::io::Write>(&self, w: &mut W, generics_resolver: Option<&GenericTypes>, generics: impl Iterator) { - write!(w, "<").unwrap(); - for (idx, arg) in generics.enumerate() { - if idx != 0 { write!(w, ", ").unwrap(); } - match arg { - syn::GenericArgument::Type(t) => self.write_rust_type(w, generics_resolver, t), - _ => unimplemented!(), - } - } - write!(w, ">").unwrap(); - } - pub fn write_rust_type(&self, w: &mut W, generics: Option<&GenericTypes>, t: &syn::Type) { - match t { - syn::Type::Path(p) => { - if p.qself.is_some() { - unimplemented!(); - } - self.write_rust_path(w, generics, &p.path); - }, - syn::Type::Reference(r) => { - write!(w, "&").unwrap(); - if let Some(lft) = &r.lifetime { - write!(w, "'{} ", lft.ident).unwrap(); - } - if r.mutability.is_some() { - write!(w, "mut ").unwrap(); - } - self.write_rust_type(w, generics, &*r.elem); - }, - syn::Type::Array(a) => { - write!(w, "[").unwrap(); - self.write_rust_type(w, generics, &a.elem); - if let syn::Expr::Lit(l) = &a.len { - if let syn::Lit::Int(i) = &l.lit { - write!(w, "; {}]", i).unwrap(); - } else { unimplemented!(); } - } else { unimplemented!(); } - } - syn::Type::Slice(s) => { - write!(w, "[").unwrap(); - self.write_rust_type(w, generics, &s.elem); - write!(w, "]").unwrap(); - }, - syn::Type::Tuple(s) => { - write!(w, "(").unwrap(); - for (idx, t) in s.elems.iter().enumerate() { - if idx != 0 { write!(w, ", ").unwrap(); } - self.write_rust_type(w, generics, &t); - } - write!(w, ")").unwrap(); - }, - _ => unimplemented!(), - } - } - - /// Prints a constructor for something which is "uninitialized" (but obviously not actually - /// unint'd memory). - pub fn write_empty_rust_val(&self, generics: Option<&GenericTypes>, w: &mut W, t: &syn::Type) { - match t { - syn::Type::Path(p) => { - let resolved = self.resolve_path(&p.path, generics); - if self.crate_types.opaques.get(&resolved).is_some() { - write!(w, "crate::{} {{ inner: std::ptr::null_mut(), is_owned: true }}", resolved).unwrap(); - } else { - // Assume its a manually-mapped C type, where we can just define an null() fn - write!(w, "{}::null()", self.c_type_from_path(&resolved, false, false).unwrap()).unwrap(); - } - }, - syn::Type::Array(a) => { - if let syn::Expr::Lit(l) = &a.len { - if let syn::Lit::Int(i) = &l.lit { - if i.base10_digits().parse::().unwrap() < 32 { - // Blindly assume that if we're trying to create an empty value for an - // array < 32 entries that all-0s may be a valid state. - unimplemented!(); - } - let arrty = format!("[u8; {}]", i.base10_digits()); - write!(w, "{}", self.to_c_conversion_inline_prefix_from_path(&arrty, false, false).unwrap()).unwrap(); - write!(w, "[0; {}]", i.base10_digits()).unwrap(); - write!(w, "{}", self.to_c_conversion_inline_suffix_from_path(&arrty, false, false).unwrap()).unwrap(); - } else { unimplemented!(); } - } else { unimplemented!(); } - } - _ => unimplemented!(), - } - } - - /// Prints a suffix to determine if a variable is empty (ie was set by write_empty_rust_val). - /// See EmptyValExpectedTy for information on return types. - fn write_empty_rust_val_check_suffix(&self, generics: Option<&GenericTypes>, w: &mut W, t: &syn::Type) -> EmptyValExpectedTy { - match t { - syn::Type::Path(p) => { - let resolved = self.resolve_path(&p.path, generics); - if self.crate_types.opaques.get(&resolved).is_some() { - write!(w, ".inner.is_null()").unwrap(); - EmptyValExpectedTy::NonPointer - } else { - if let Some(suffix) = self.empty_val_check_suffix_from_path(&resolved) { - write!(w, "{}", suffix).unwrap(); - // We may eventually need to allow empty_val_check_suffix_from_path to specify if we need a deref or not - EmptyValExpectedTy::NonPointer - } else { - write!(w, " == std::ptr::null_mut()").unwrap(); - EmptyValExpectedTy::OwnedPointer - } - } - }, - syn::Type::Array(a) => { - if let syn::Expr::Lit(l) = &a.len { - if let syn::Lit::Int(i) = &l.lit { - write!(w, " == [0; {}]", i.base10_digits()).unwrap(); - EmptyValExpectedTy::NonPointer - } else { unimplemented!(); } - } else { unimplemented!(); } - }, - syn::Type::Slice(_) => { - // Option<[]> always implies that we want to treat len() == 0 differently from - // None, so we always map an Option<[]> into a pointer. - write!(w, " == std::ptr::null_mut()").unwrap(); - EmptyValExpectedTy::ReferenceAsPointer - }, - _ => unimplemented!(), - } - } - - /// Prints a suffix to determine if a variable is empty (ie was set by write_empty_rust_val). - pub fn write_empty_rust_val_check(&self, generics: Option<&GenericTypes>, w: &mut W, t: &syn::Type, var_access: &str) { - match t { - syn::Type::Path(_) => { - write!(w, "{}", var_access).unwrap(); - self.write_empty_rust_val_check_suffix(generics, w, t); - }, - syn::Type::Array(a) => { - if let syn::Expr::Lit(l) = &a.len { - if let syn::Lit::Int(i) = &l.lit { - let arrty = format!("[u8; {}]", i.base10_digits()); - // We don't (yet) support a new-var conversion here. - assert!(self.from_c_conversion_new_var_from_path(&arrty, false).is_none()); - write!(w, "{}{}{}", - self.from_c_conversion_prefix_from_path(&arrty, false).unwrap(), - var_access, - self.from_c_conversion_suffix_from_path(&arrty, false).unwrap()).unwrap(); - self.write_empty_rust_val_check_suffix(generics, w, t); - } else { unimplemented!(); } - } else { unimplemented!(); } - } - _ => unimplemented!(), - } - } - - // ******************************** - // *** Type conversion printing *** - // ******************************** - - /// Returns true we if can just skip passing this to C entirely - pub fn skip_arg(&self, t: &syn::Type, generics: Option<&GenericTypes>) -> bool { - match t { - syn::Type::Path(p) => { - if p.qself.is_some() { unimplemented!(); } - if let Some(full_path) = self.maybe_resolve_path(&p.path, generics) { - self.skip_path(&full_path) - } else { false } - }, - syn::Type::Reference(r) => { - self.skip_arg(&*r.elem, generics) - }, - _ => false, - } - } - pub fn no_arg_to_rust(&self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>) { - match t { - syn::Type::Path(p) => { - if p.qself.is_some() { unimplemented!(); } - if let Some(full_path) = self.maybe_resolve_path(&p.path, generics) { - write!(w, "{}", self.no_arg_path_to_rust(&full_path)).unwrap(); - } - }, - syn::Type::Reference(r) => { - self.no_arg_to_rust(w, &*r.elem, generics); - }, - _ => {}, - } - } - - fn write_conversion_inline_intern Option, DL: Fn(&mut W, &DeclType, &str, bool, bool), SC: Fn(bool) -> &'static str> - (&self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>, is_ref: bool, is_mut: bool, ptr_for_ref: bool, - tupleconv: &str, prefix: bool, sliceconv: SC, path_lookup: LP, decl_lookup: DL) { - match t { - syn::Type::Reference(r) => { - self.write_conversion_inline_intern(w, &*r.elem, generics, true, r.mutability.is_some(), - ptr_for_ref, tupleconv, prefix, sliceconv, path_lookup, decl_lookup); - }, - syn::Type::Path(p) => { - if p.qself.is_some() { - unimplemented!(); - } - - let resolved_path = self.resolve_path(&p.path, generics); - if let Some(aliased_type) = self.crate_types.type_aliases.get(&resolved_path) { - return self.write_conversion_inline_intern(w, aliased_type, None, is_ref, is_mut, ptr_for_ref, tupleconv, prefix, sliceconv, path_lookup, decl_lookup); - } else if let Some(c_type) = path_lookup(&resolved_path, is_ref, ptr_for_ref) { - write!(w, "{}", c_type).unwrap(); - } else if self.crate_types.opaques.get(&resolved_path).is_some() { - decl_lookup(w, &DeclType::StructImported, &resolved_path, is_ref, is_mut); - } else if self.crate_types.mirrored_enums.get(&resolved_path).is_some() { - decl_lookup(w, &DeclType::MirroredEnum, &resolved_path, is_ref, is_mut); - } else if let Some(t) = self.crate_types.traits.get(&resolved_path) { - decl_lookup(w, &DeclType::Trait(t), &resolved_path, is_ref, is_mut); - } else if let Some(ident) = single_ident_generic_path_to_ident(&p.path) { - if let Some(decl_type) = self.types.maybe_resolve_declared(ident) { - decl_lookup(w, decl_type, &self.maybe_resolve_ident(ident).unwrap(), is_ref, is_mut); - } else { unimplemented!(); } - } else { unimplemented!(); } - }, - syn::Type::Array(a) => { - // We assume all arrays contain only [int_literal; X]s. - // This may result in some outputs not compiling. - if let syn::Expr::Lit(l) = &a.len { - if let syn::Lit::Int(i) = &l.lit { - write!(w, "{}", path_lookup(&format!("[u8; {}]", i.base10_digits()), is_ref, ptr_for_ref).unwrap()).unwrap(); - } else { unimplemented!(); } - } else { unimplemented!(); } - }, - syn::Type::Slice(s) => { - // We assume all slices contain only literals or references. - // This may result in some outputs not compiling. - if let syn::Type::Path(p) = &*s.elem { - let resolved = self.resolve_path(&p.path, generics); - assert!(self.is_primitive(&resolved)); - write!(w, "{}", path_lookup("[u8]", is_ref, ptr_for_ref).unwrap()).unwrap(); - } else if let syn::Type::Reference(r) = &*s.elem { - if let syn::Type::Path(p) = &*r.elem { - write!(w, "{}", sliceconv(self.c_type_has_inner_from_path(&self.resolve_path(&p.path, generics)))).unwrap(); - } else { unimplemented!(); } - } else if let syn::Type::Tuple(t) = &*s.elem { - assert!(!t.elems.is_empty()); - if prefix { - write!(w, "&local_").unwrap(); - } else { - let mut needs_map = false; - for e in t.elems.iter() { - if let syn::Type::Reference(_) = e { - needs_map = true; - } - } - if needs_map { - write!(w, ".iter().map(|(").unwrap(); - for i in 0..t.elems.len() { - write!(w, "{}{}", if i != 0 { ", " } else { "" }, ('a' as u8 + i as u8) as char).unwrap(); - } - write!(w, ")| (").unwrap(); - for (idx, e) in t.elems.iter().enumerate() { - if let syn::Type::Reference(_) = e { - write!(w, "{}{}", if idx != 0 { ", " } else { "" }, (idx as u8 + 'a' as u8) as char).unwrap(); - } else if let syn::Type::Path(_) = e { - write!(w, "{}*{}", if idx != 0 { ", " } else { "" }, (idx as u8 + 'a' as u8) as char).unwrap(); - } else { unimplemented!(); } - } - write!(w, ")).collect::>()[..]").unwrap(); - } - } - } else { unimplemented!(); } - }, - syn::Type::Tuple(t) => { - if t.elems.is_empty() { - // cbindgen has poor support for (), see, eg https://github.com/eqrion/cbindgen/issues/527 - // so work around it by just pretending its a 0u8 - write!(w, "{}", tupleconv).unwrap(); - } else { - if prefix { write!(w, "local_").unwrap(); } - } - }, - _ => unimplemented!(), - } - } - - fn write_to_c_conversion_inline_prefix_inner(&self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>, is_ref: bool, ptr_for_ref: bool, from_ptr: bool) { - self.write_conversion_inline_intern(w, t, generics, is_ref, false, ptr_for_ref, "0u8 /*", true, |_| "local_", - |a, b, c| self.to_c_conversion_inline_prefix_from_path(a, b, c), - |w, decl_type, decl_path, is_ref, _is_mut| { - match decl_type { - DeclType::MirroredEnum if is_ref && ptr_for_ref => write!(w, "crate::{}::from_native(&", decl_path).unwrap(), - DeclType::MirroredEnum if is_ref => write!(w, "&crate::{}::from_native(&", decl_path).unwrap(), - DeclType::MirroredEnum => write!(w, "crate::{}::native_into(", decl_path).unwrap(), - DeclType::EnumIgnored|DeclType::StructImported if is_ref && ptr_for_ref && from_ptr => - write!(w, "crate::{} {{ inner: unsafe {{ (", decl_path).unwrap(), - DeclType::EnumIgnored|DeclType::StructImported if is_ref && ptr_for_ref => - write!(w, "crate::{} {{ inner: unsafe {{ ( (&(", decl_path).unwrap(), - DeclType::EnumIgnored|DeclType::StructImported if is_ref => - write!(w, "&crate::{} {{ inner: unsafe {{ (", decl_path).unwrap(), - DeclType::EnumIgnored|DeclType::StructImported if !is_ref && from_ptr => - write!(w, "crate::{} {{ inner: ", decl_path).unwrap(), - DeclType::EnumIgnored|DeclType::StructImported if !is_ref => - write!(w, "crate::{} {{ inner: Box::into_raw(Box::new(", decl_path).unwrap(), - DeclType::Trait(_) if is_ref => write!(w, "&").unwrap(), - DeclType::Trait(_) if !is_ref => {}, - _ => panic!("{:?}", decl_path), - } - }); - } - pub fn write_to_c_conversion_inline_prefix(&self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>, ptr_for_ref: bool) { - self.write_to_c_conversion_inline_prefix_inner(w, t, generics, false, ptr_for_ref, false); - } - fn write_to_c_conversion_inline_suffix_inner(&self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>, is_ref: bool, ptr_for_ref: bool, from_ptr: bool) { - self.write_conversion_inline_intern(w, t, generics, is_ref, false, ptr_for_ref, "*/", false, |_| ".into()", - |a, b, c| self.to_c_conversion_inline_suffix_from_path(a, b, c), - |w, decl_type, _full_path, is_ref, _is_mut| match decl_type { - DeclType::MirroredEnum => write!(w, ")").unwrap(), - DeclType::EnumIgnored|DeclType::StructImported if is_ref && ptr_for_ref && from_ptr => - write!(w, " as *const _) as *mut _ }}, is_owned: false }}").unwrap(), - DeclType::EnumIgnored|DeclType::StructImported if is_ref && ptr_for_ref => - write!(w, ") as *const _) as *mut _) }}, is_owned: false }}").unwrap(), - DeclType::EnumIgnored|DeclType::StructImported if is_ref => - write!(w, " as *const _) as *mut _ }}, is_owned: false }}").unwrap(), - DeclType::EnumIgnored|DeclType::StructImported if !is_ref && from_ptr => - write!(w, ", is_owned: true }}").unwrap(), - DeclType::EnumIgnored|DeclType::StructImported if !is_ref => write!(w, ")), is_owned: true }}").unwrap(), - DeclType::Trait(_) if is_ref => {}, - DeclType::Trait(_) => { - // This is used when we're converting a concrete Rust type into a C trait - // for use when a Rust trait method returns an associated type. - // Because all of our C traits implement From - // we can just call .into() here and be done. - write!(w, ".into()").unwrap() - }, - _ => unimplemented!(), - }); - } - pub fn write_to_c_conversion_inline_suffix(&self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>, ptr_for_ref: bool) { - self.write_to_c_conversion_inline_suffix_inner(w, t, generics, false, ptr_for_ref, false); - } - - fn write_from_c_conversion_prefix_inner(&self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>, is_ref: bool, ptr_for_ref: bool) { - self.write_conversion_inline_intern(w, t, generics, is_ref, false, false, "() /*", true, |_| "&local_", - |a, b, _c| self.from_c_conversion_prefix_from_path(a, b), - |w, decl_type, _full_path, is_ref, is_mut| match decl_type { - DeclType::StructImported if is_ref && ptr_for_ref => write!(w, "unsafe {{ &*(*").unwrap(), - DeclType::StructImported if is_mut && is_ref => write!(w, "unsafe {{ &mut *").unwrap(), - DeclType::StructImported if is_ref => write!(w, "unsafe {{ &*").unwrap(), - DeclType::StructImported if !is_ref => write!(w, "*unsafe {{ Box::from_raw(").unwrap(), - DeclType::MirroredEnum if is_ref => write!(w, "&").unwrap(), - DeclType::MirroredEnum => {}, - DeclType::Trait(_) => {}, - _ => unimplemented!(), - }); - } - pub fn write_from_c_conversion_prefix(&self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>) { - self.write_from_c_conversion_prefix_inner(w, t, generics, false, false); - } - fn write_from_c_conversion_suffix_inner(&self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>, is_ref: bool, ptr_for_ref: bool) { - self.write_conversion_inline_intern(w, t, generics, is_ref, false, false, "*/", false, - |has_inner| match has_inner { - false => ".iter().collect::>()[..]", - true => "[..]", - }, - |a, b, _c| self.from_c_conversion_suffix_from_path(a, b), - |w, decl_type, _full_path, is_ref, _is_mut| match decl_type { - DeclType::StructImported if is_ref && ptr_for_ref => write!(w, ").inner }}").unwrap(), - DeclType::StructImported if is_ref => write!(w, ".inner }}").unwrap(), - DeclType::StructImported if !is_ref => write!(w, ".take_inner()) }}").unwrap(), - DeclType::MirroredEnum if is_ref => write!(w, ".to_native()").unwrap(), - DeclType::MirroredEnum => write!(w, ".into_native()").unwrap(), - DeclType::Trait(_) => {}, - _ => unimplemented!(), - }); - } - pub fn write_from_c_conversion_suffix(&self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>) { - self.write_from_c_conversion_suffix_inner(w, t, generics, false, false); - } - // Note that compared to the above conversion functions, the following two are generally - // significantly undertested: - pub fn write_from_c_conversion_to_ref_prefix(&self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>) { - self.write_conversion_inline_intern(w, t, generics, false, false, false, "() /*", true, |_| "&local_", - |a, b, _c| { - if let Some(conv) = self.from_c_conversion_prefix_from_path(a, b) { - Some(format!("&{}", conv)) - } else { None } - }, - |w, decl_type, _full_path, is_ref, _is_mut| match decl_type { - DeclType::StructImported if !is_ref => write!(w, "unsafe {{ &*").unwrap(), - _ => unimplemented!(), - }); - } - pub fn write_from_c_conversion_to_ref_suffix(&self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>) { - self.write_conversion_inline_intern(w, t, generics, false, false, false, "*/", false, - |has_inner| match has_inner { - false => ".iter().collect::>()[..]", - true => "[..]", - }, - |a, b, _c| self.from_c_conversion_suffix_from_path(a, b), - |w, decl_type, _full_path, is_ref, _is_mut| match decl_type { - DeclType::StructImported if !is_ref => write!(w, ".inner }}").unwrap(), - _ => unimplemented!(), - }); - } - - fn write_conversion_new_var_intern<'b, W: std::io::Write, - LP: Fn(&str, bool) -> Option<(&str, &str)>, - LC: Fn(&str, bool, Option<&syn::Type>, &syn::Ident, &str) -> Option<(&'b str, Vec<(String, String)>, &'b str)>, - VP: Fn(&mut W, &syn::Type, Option<&GenericTypes>, bool, bool, bool), - VS: Fn(&mut W, &syn::Type, Option<&GenericTypes>, bool, bool, bool)> - (&self, w: &mut W, ident: &syn::Ident, var: &str, t: &syn::Type, generics: Option<&GenericTypes>, - mut is_ref: bool, mut ptr_for_ref: bool, to_c: bool, - path_lookup: &LP, container_lookup: &LC, var_prefix: &VP, var_suffix: &VS) -> bool { - - macro_rules! convert_container { - ($container_type: expr, $args_len: expr, $args_iter: expr) => { { - // For slices (and Options), we refuse to directly map them as is_ref when they - // aren't opaque types containing an inner pointer. This is due to the fact that, - // in both cases, the actual higher-level type is non-is_ref. - let ty_has_inner = if self.is_transparent_container(&$container_type, is_ref) || $container_type == "Slice" { - let ty = $args_iter().next().unwrap(); - if $container_type == "Slice" && to_c { - // "To C ptr_for_ref" means "return the regular object with is_owned - // set to false", which is totally what we want in a slice if we're about to - // set ty_has_inner. - ptr_for_ref = true; - } - if let syn::Type::Reference(t) = ty { - if let syn::Type::Path(p) = &*t.elem { - self.c_type_has_inner_from_path(&self.resolve_path(&p.path, generics)) - } else { false } - } else if let syn::Type::Path(p) = ty { - self.c_type_has_inner_from_path(&self.resolve_path(&p.path, generics)) - } else { false } - } else { true }; - - // Options get a bunch of special handling, since in general we map Option<>al - // types into the same C type as non-Option-wrapped types. This ends up being - // pretty manual here and most of the below special-cases are for Options. - let mut needs_ref_map = false; - let mut only_contained_type = None; - let mut only_contained_has_inner = false; - let mut contains_slice = false; - if $args_len == 1 && self.is_transparent_container(&$container_type, is_ref) { - only_contained_has_inner = ty_has_inner; - let arg = $args_iter().next().unwrap(); - if let syn::Type::Reference(t) = arg { - only_contained_type = Some(&*t.elem); - if let syn::Type::Path(_) = &*t.elem { - is_ref = true; - } else if let syn::Type::Slice(_) = &*t.elem { - contains_slice = true; - } else { return false; } - needs_ref_map = true; - } else if let syn::Type::Path(_) = arg { - only_contained_type = Some(&arg); - } else { unimplemented!(); } - } - - if let Some((prefix, conversions, suffix)) = container_lookup(&$container_type, is_ref && ty_has_inner, only_contained_type, ident, var) { - assert_eq!(conversions.len(), $args_len); - write!(w, "let mut local_{}{} = ", ident, if !to_c && needs_ref_map {"_base"} else { "" }).unwrap(); - if only_contained_has_inner && to_c { - var_prefix(w, $args_iter().next().unwrap(), generics, is_ref, ptr_for_ref, true); - } - write!(w, "{}{}", prefix, var).unwrap(); - - for ((pfx, var_name), (idx, ty)) in conversions.iter().zip($args_iter().enumerate()) { - let mut var = std::io::Cursor::new(Vec::new()); - write!(&mut var, "{}", var_name).unwrap(); - let var_access = String::from_utf8(var.into_inner()).unwrap(); - - let conv_ty = if needs_ref_map { only_contained_type.as_ref().unwrap() } else { ty }; - - write!(w, "{} {{ ", pfx).unwrap(); - let new_var_name = format!("{}_{}", ident, idx); - let new_var = self.write_conversion_new_var_intern(w, &syn::Ident::new(&new_var_name, Span::call_site()), - &var_access, conv_ty, generics, contains_slice || (is_ref && ty_has_inner), ptr_for_ref, to_c, path_lookup, container_lookup, var_prefix, var_suffix); - if new_var { write!(w, " ").unwrap(); } - if (!only_contained_has_inner || !to_c) && !contains_slice { - var_prefix(w, conv_ty, generics, is_ref && ty_has_inner, ptr_for_ref, false); - } - - if !is_ref && !needs_ref_map && to_c && only_contained_has_inner { - write!(w, "Box::into_raw(Box::new(").unwrap(); - } - write!(w, "{}{}", if contains_slice { "local_" } else { "" }, if new_var { new_var_name } else { var_access }).unwrap(); - if (!only_contained_has_inner || !to_c) && !contains_slice { - var_suffix(w, conv_ty, generics, is_ref && ty_has_inner, ptr_for_ref, false); - } - if !is_ref && !needs_ref_map && to_c && only_contained_has_inner { - write!(w, "))").unwrap(); - } - write!(w, " }}").unwrap(); - } - write!(w, "{}", suffix).unwrap(); - if only_contained_has_inner && to_c { - var_suffix(w, $args_iter().next().unwrap(), generics, is_ref, ptr_for_ref, true); - } - write!(w, ";").unwrap(); - if !to_c && needs_ref_map { - write!(w, " let mut local_{} = local_{}_base.as_ref()", ident, ident).unwrap(); - if contains_slice { - write!(w, ".map(|a| &a[..])").unwrap(); - } - write!(w, ";").unwrap(); - } - return true; - } - } } - } - - match t { - syn::Type::Reference(r) => { - if let syn::Type::Slice(_) = &*r.elem { - self.write_conversion_new_var_intern(w, ident, var, &*r.elem, generics, is_ref, ptr_for_ref, to_c, path_lookup, container_lookup, var_prefix, var_suffix) - } else { - self.write_conversion_new_var_intern(w, ident, var, &*r.elem, generics, true, ptr_for_ref, to_c, path_lookup, container_lookup, var_prefix, var_suffix) - } - }, - syn::Type::Path(p) => { - if p.qself.is_some() { - unimplemented!(); - } - let resolved_path = self.resolve_path(&p.path, generics); - if let Some(aliased_type) = self.crate_types.type_aliases.get(&resolved_path) { - return self.write_conversion_new_var_intern(w, ident, var, aliased_type, None, is_ref, ptr_for_ref, to_c, path_lookup, container_lookup, var_prefix, var_suffix); - } - if self.is_known_container(&resolved_path, is_ref) || self.is_transparent_container(&resolved_path, is_ref) { - if let syn::PathArguments::AngleBracketed(args) = &p.path.segments.iter().next().unwrap().arguments { - convert_container!(resolved_path, args.args.len(), || args.args.iter().map(|arg| { - if let syn::GenericArgument::Type(ty) = arg { - ty - } else { unimplemented!(); } - })); - } else { unimplemented!(); } - } - if self.is_primitive(&resolved_path) { - false - } else if let Some(ty_ident) = single_ident_generic_path_to_ident(&p.path) { - if let Some((prefix, suffix)) = path_lookup(&resolved_path, is_ref) { - write!(w, "let mut local_{} = {}{}{};", ident, prefix, var, suffix).unwrap(); - true - } else if self.types.maybe_resolve_declared(ty_ident).is_some() { - false - } else { false } - } else { false } - }, - syn::Type::Array(_) => { - // We assume all arrays contain only primitive types. - // This may result in some outputs not compiling. - false - }, - syn::Type::Slice(s) => { - if let syn::Type::Path(p) = &*s.elem { - let resolved = self.resolve_path(&p.path, generics); - assert!(self.is_primitive(&resolved)); - let slice_path = format!("[{}]", resolved); - if let Some((prefix, suffix)) = path_lookup(&slice_path, true) { - write!(w, "let mut local_{} = {}{}{};", ident, prefix, var, suffix).unwrap(); - true - } else { false } - } else if let syn::Type::Reference(ty) = &*s.elem { - let tyref = [&*ty.elem]; - is_ref = true; - convert_container!("Slice", 1, || tyref.iter()); - unimplemented!("convert_container should return true as container_lookup should succeed for slices"); - } else if let syn::Type::Tuple(t) = &*s.elem { - // When mapping into a temporary new var, we need to own all the underlying objects. - // Thus, we drop any references inside the tuple and convert with non-reference types. - let mut elems = syn::punctuated::Punctuated::new(); - for elem in t.elems.iter() { - if let syn::Type::Reference(r) = elem { - elems.push((*r.elem).clone()); - } else { - elems.push(elem.clone()); - } - } - let ty = [syn::Type::Tuple(syn::TypeTuple { - paren_token: t.paren_token, elems - })]; - is_ref = false; - ptr_for_ref = true; - convert_container!("Slice", 1, || ty.iter()); - unimplemented!("convert_container should return true as container_lookup should succeed for slices"); - } else { unimplemented!() } - }, - syn::Type::Tuple(t) => { - if !t.elems.is_empty() { - // We don't (yet) support tuple elements which cannot be converted inline - write!(w, "let (").unwrap(); - for idx in 0..t.elems.len() { - if idx != 0 { write!(w, ", ").unwrap(); } - write!(w, "{} orig_{}_{}", if is_ref { "ref" } else { "mut" }, ident, idx).unwrap(); - } - write!(w, ") = {}{}; ", var, if !to_c { ".to_rust()" } else { "" }).unwrap(); - // Like other template types, tuples are always mapped as their non-ref - // versions for types which have different ref mappings. Thus, we convert to - // non-ref versions and handle opaque types with inner pointers manually. - for (idx, elem) in t.elems.iter().enumerate() { - if let syn::Type::Path(p) = elem { - let v_name = format!("orig_{}_{}", ident, idx); - let tuple_elem_ident = syn::Ident::new(&v_name, Span::call_site()); - if self.write_conversion_new_var_intern(w, &tuple_elem_ident, &v_name, elem, generics, - false, ptr_for_ref, to_c, - path_lookup, container_lookup, var_prefix, var_suffix) { - write!(w, " ").unwrap(); - // Opaque types with inner pointers shouldn't ever create new stack - // variables, so we don't handle it and just assert that it doesn't - // here. - assert!(!self.c_type_has_inner_from_path(&self.resolve_path(&p.path, generics))); - } - } - } - write!(w, "let mut local_{} = (", ident).unwrap(); - for (idx, elem) in t.elems.iter().enumerate() { - let ty_has_inner = { - if to_c { - // "To C ptr_for_ref" means "return the regular object with - // is_owned set to false", which is totally what we want - // if we're about to set ty_has_inner. - ptr_for_ref = true; - } - if let syn::Type::Reference(t) = elem { - if let syn::Type::Path(p) = &*t.elem { - self.c_type_has_inner_from_path(&self.resolve_path(&p.path, generics)) - } else { false } - } else if let syn::Type::Path(p) = elem { - self.c_type_has_inner_from_path(&self.resolve_path(&p.path, generics)) - } else { false } - }; - if idx != 0 { write!(w, ", ").unwrap(); } - var_prefix(w, elem, generics, is_ref && ty_has_inner, ptr_for_ref, false); - if is_ref && ty_has_inner { - // For ty_has_inner, the regular var_prefix mapping will take a - // reference, so deref once here to make sure we keep the original ref. - write!(w, "*").unwrap(); - } - write!(w, "orig_{}_{}", ident, idx).unwrap(); - if is_ref && !ty_has_inner { - // If we don't have an inner variable's reference to maintain, just - // hope the type is Clonable and use that. - write!(w, ".clone()").unwrap(); - } - var_suffix(w, elem, generics, is_ref && ty_has_inner, ptr_for_ref, false); - } - write!(w, "){};", if to_c { ".into()" } else { "" }).unwrap(); - true - } else { false } - }, - _ => unimplemented!(), - } - } - - pub fn write_to_c_conversion_new_var_inner(&self, w: &mut W, ident: &syn::Ident, var_access: &str, t: &syn::Type, generics: Option<&GenericTypes>, ptr_for_ref: bool) -> bool { - self.write_conversion_new_var_intern(w, ident, var_access, t, generics, false, ptr_for_ref, true, - &|a, b| self.to_c_conversion_new_var_from_path(a, b), - &|a, b, c, d, e| self.to_c_conversion_container_new_var(generics, a, b, c, d, e), - // We force ptr_for_ref here since we can't generate a ref on one line and use it later - &|a, b, c, d, e, f| self.write_to_c_conversion_inline_prefix_inner(a, b, c, d, e, f), - &|a, b, c, d, e, f| self.write_to_c_conversion_inline_suffix_inner(a, b, c, d, e, f)) - } - pub fn write_to_c_conversion_new_var(&self, w: &mut W, ident: &syn::Ident, t: &syn::Type, generics: Option<&GenericTypes>, ptr_for_ref: bool) -> bool { - self.write_to_c_conversion_new_var_inner(w, ident, &format!("{}", ident), t, generics, ptr_for_ref) - } - pub fn write_from_c_conversion_new_var(&self, w: &mut W, ident: &syn::Ident, t: &syn::Type, generics: Option<&GenericTypes>) -> bool { - self.write_conversion_new_var_intern(w, ident, &format!("{}", ident), t, generics, false, false, false, - &|a, b| self.from_c_conversion_new_var_from_path(a, b), - &|a, b, c, d, e| self.from_c_conversion_container_new_var(generics, a, b, c, d, e), - // We force ptr_for_ref here since we can't generate a ref on one line and use it later - &|a, b, c, d, e, _f| self.write_from_c_conversion_prefix_inner(a, b, c, d, e), - &|a, b, c, d, e, _f| self.write_from_c_conversion_suffix_inner(a, b, c, d, e)) - } - - // ****************************************************** - // *** C Container Type Equivalent and alias Printing *** - // ****************************************************** - - fn write_template_generics<'b, W: std::io::Write>(&mut self, w: &mut W, args: &mut dyn Iterator, generics: Option<&GenericTypes>, is_ref: bool) -> bool { - assert!(!is_ref); // We don't currently support outer reference types - for (idx, t) in args.enumerate() { - if idx != 0 { - write!(w, ", ").unwrap(); - } - if let syn::Type::Reference(r_arg) = t { - if !self.write_c_type_intern(w, &*r_arg.elem, generics, false, false, false) { return false; } - - // While write_c_type_intern, above is correct, we don't want to blindly convert a - // reference to something stupid, so check that the container is either opaque or a - // predefined type (currently only Transaction). - if let syn::Type::Path(p_arg) = &*r_arg.elem { - let resolved = self.resolve_path(&p_arg.path, generics); - assert!(self.crate_types.opaques.get(&resolved).is_some() || - self.c_type_from_path(&resolved, true, true).is_some(), "Template generics should be opaque or have a predefined mapping"); - } else { unimplemented!(); } - } else { - if !self.write_c_type_intern(w, t, generics, false, false, false) { return false; } - } - } - true - } - 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() { - let mut created_container: Vec = Vec::new(); - - if container_type == "Result" { - let mut a_ty: Vec = Vec::new(); - if let syn::Type::Tuple(tup) = args.iter().next().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; } - } - - let mut b_ty: Vec = Vec::new(); - if let syn::Type::Tuple(tup) = args.iter().skip(1).next().unwrap() { - if tup.elems.is_empty() { - 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; } - } - - let ok_str = String::from_utf8(a_ty).unwrap(); - 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 = 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 = 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.template_file.write(&created_container).unwrap(); - } - true - } - fn path_to_generic_args(path: &syn::Path) -> Vec<&syn::Type> { - if let syn::PathArguments::AngleBracketed(args) = &path.segments.iter().next().unwrap().arguments { - args.args.iter().map(|gen| if let syn::GenericArgument::Type(t) = gen { t } else { unimplemented!() }).collect() - } else { unimplemented!(); } - } - fn write_c_mangled_container_path_intern - (&mut self, w: &mut W, args: Vec<&syn::Type>, generics: Option<&GenericTypes>, ident: &str, is_ref: bool, is_mut: bool, ptr_for_ref: bool, in_type: bool) -> bool { - let mut mangled_type: Vec = Vec::new(); - if !self.is_transparent_container(ident, is_ref) { - write!(w, "C{}_", ident).unwrap(); - write!(mangled_type, "C{}_", ident).unwrap(); - } else { assert_eq!(args.len(), 1); } - for arg in args.iter() { - macro_rules! write_path { - ($p_arg: expr, $extra_write: expr) => { - if let Some(subtype) = self.maybe_resolve_path(&$p_arg.path, generics) { - if self.is_transparent_container(ident, is_ref) { - // We dont (yet) support primitives or containers inside transparent - // containers, so check for that first: - if self.is_primitive(&subtype) { return false; } - if self.is_known_container(&subtype, is_ref) { return false; } - if !in_type { - if self.c_type_has_inner_from_path(&subtype) { - if !self.write_c_path_intern(w, &$p_arg.path, generics, is_ref, is_mut, ptr_for_ref) { return false; } - } else { - // Option needs to be converted to a *mut T, ie mut ptr-for-ref - if !self.write_c_path_intern(w, &$p_arg.path, generics, true, true, true) { return false; } - } - } else { - write!(w, "{}", $p_arg.path.segments.last().unwrap().ident).unwrap(); - } - } else if self.is_known_container(&subtype, is_ref) || self.is_transparent_container(&subtype, is_ref) { - if !self.write_c_mangled_container_path_intern(w, Self::path_to_generic_args(&$p_arg.path), generics, - &subtype, is_ref, is_mut, ptr_for_ref, true) { - return false; - } - self.write_c_mangled_container_path_intern(&mut mangled_type, Self::path_to_generic_args(&$p_arg.path), - generics, &subtype, is_ref, is_mut, ptr_for_ref, true); - if let Some(w2) = $extra_write as Option<&mut Vec> { - self.write_c_mangled_container_path_intern(w2, Self::path_to_generic_args(&$p_arg.path), - generics, &subtype, is_ref, is_mut, ptr_for_ref, true); - } - } else { - let id = subtype.rsplitn(2, ':').next().unwrap(); // Get the "Base" name of the resolved type - write!(w, "{}", id).unwrap(); - write!(mangled_type, "{}", id).unwrap(); - if let Some(w2) = $extra_write as Option<&mut Vec> { - write!(w2, "{}", id).unwrap(); - } - } - } else { return false; } - } - } - if let syn::Type::Tuple(tuple) = arg { - if tuple.elems.len() == 0 { - write!(w, "None").unwrap(); - write!(mangled_type, "None").unwrap(); - } else { - let mut mangled_tuple_type: Vec = Vec::new(); - - // Figure out what the mangled type should look like. To disambiguate - // ((A, B), C) and (A, B, C) we prefix the generic args with a _ and suffix - // them with a Z. Ideally we wouldn't use Z, but not many special chars are - // available for use in type names. - write!(w, "C{}Tuple_", tuple.elems.len()).unwrap(); - write!(mangled_type, "C{}Tuple_", tuple.elems.len()).unwrap(); - write!(mangled_tuple_type, "C{}Tuple_", tuple.elems.len()).unwrap(); - for elem in tuple.elems.iter() { - if let syn::Type::Path(p) = elem { - write_path!(p, Some(&mut mangled_tuple_type)); - } else if let syn::Type::Reference(refelem) = elem { - if let syn::Type::Path(p) = &*refelem.elem { - write_path!(p, Some(&mut mangled_tuple_type)); - } else { return false; } - } else { return false; } - } - write!(w, "Z").unwrap(); - write!(mangled_type, "Z").unwrap(); - write!(mangled_tuple_type, "Z").unwrap(); - if !self.check_create_container(String::from_utf8(mangled_tuple_type).unwrap(), - &format!("{}Tuple", tuple.elems.len()), tuple.elems.iter().collect(), generics, is_ref) { - return false; - } - } - } else if let syn::Type::Path(p_arg) = arg { - write_path!(p_arg, None); - } else if let syn::Type::Reference(refty) = arg { - if let syn::Type::Path(p_arg) = &*refty.elem { - write_path!(p_arg, None); - } else if let syn::Type::Slice(_) = &*refty.elem { - // write_c_type will actually do exactly what we want here, we just need to - // 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 - // to edit it, hence we use *mut here instead of *const. - if args.len() != 1 { return false; } - write!(w, "*mut ").unwrap(); - self.write_c_type(w, arg, None, true); - } else { return false; } - } else if let syn::Type::Array(a) = arg { - if let syn::Type::Path(p_arg) = &*a.elem { - let resolved = self.resolve_path(&p_arg.path, generics); - if !self.is_primitive(&resolved) { return false; } - if let syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(len), .. }) = &a.len { - if self.c_type_from_path(&format!("[{}; {}]", resolved, len.base10_digits()), is_ref, ptr_for_ref).is_none() { return false; } - write!(w, "_{}{}", resolved, len.base10_digits()).unwrap(); - write!(mangled_type, "_{}{}", resolved, len.base10_digits()).unwrap(); - } else { return false; } - } else { return false; } - } else { return false; } - } - if self.is_transparent_container(ident, is_ref) { return true; } - // Push the "end of type" Z - write!(w, "Z").unwrap(); - write!(mangled_type, "Z").unwrap(); - - // Make sure the type is actually defined: - self.check_create_container(String::from_utf8(mangled_type).unwrap(), ident, args, generics, is_ref) - } - fn write_c_mangled_container_path(&mut self, w: &mut W, args: Vec<&syn::Type>, generics: Option<&GenericTypes>, ident: &str, is_ref: bool, is_mut: bool, ptr_for_ref: bool) -> bool { - if !self.is_transparent_container(ident, is_ref) { - write!(w, "{}::", Self::generated_container_path()).unwrap(); - } - self.write_c_mangled_container_path_intern(w, args, generics, ident, is_ref, is_mut, ptr_for_ref, false) - } - - // ********************************** - // *** C Type Equivalent Printing *** - // ********************************** - - fn write_c_path_intern(&self, w: &mut W, path: &syn::Path, generics: Option<&GenericTypes>, is_ref: bool, is_mut: bool, ptr_for_ref: bool) -> bool { - let full_path = match self.maybe_resolve_path(&path, generics) { - Some(path) => path, None => return false }; - if let Some(c_type) = self.c_type_from_path(&full_path, is_ref, ptr_for_ref) { - write!(w, "{}", c_type).unwrap(); - true - } else if self.crate_types.traits.get(&full_path).is_some() { - if is_ref && ptr_for_ref { - write!(w, "*{} crate::{}", if is_mut { "mut" } else { "const" }, full_path).unwrap(); - } else if is_ref { - write!(w, "&{}crate::{}", if is_mut { "mut " } else { "" }, full_path).unwrap(); - } else { - write!(w, "crate::{}", full_path).unwrap(); - } - true - } else if self.crate_types.opaques.get(&full_path).is_some() || self.crate_types.mirrored_enums.get(&full_path).is_some() { - if is_ref && ptr_for_ref { - // ptr_for_ref implies we're returning the object, which we can't really do for - // opaque or mirrored types without box'ing them, which is quite a waste, so return - // the actual object itself (for opaque types we'll set the pointer to the actual - // type and note that its a reference). - write!(w, "crate::{}", full_path).unwrap(); - } else if is_ref { - write!(w, "&{}crate::{}", if is_mut { "mut " } else { "" }, full_path).unwrap(); - } else { - write!(w, "crate::{}", full_path).unwrap(); - } - true - } else { - false - } - } - fn write_c_type_intern(&mut self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>, is_ref: bool, is_mut: bool, ptr_for_ref: bool) -> bool { - match t { - syn::Type::Path(p) => { - if p.qself.is_some() { - return false; - } - if let Some(full_path) = self.maybe_resolve_path(&p.path, generics) { - if self.is_known_container(&full_path, is_ref) || self.is_transparent_container(&full_path, is_ref) { - return self.write_c_mangled_container_path(w, Self::path_to_generic_args(&p.path), generics, &full_path, is_ref, is_mut, ptr_for_ref); - } - if let Some(aliased_type) = self.crate_types.type_aliases.get(&full_path).cloned() { - return self.write_c_type_intern(w, &aliased_type, None, is_ref, is_mut, ptr_for_ref); - } - } - self.write_c_path_intern(w, &p.path, generics, is_ref, is_mut, ptr_for_ref) - }, - syn::Type::Reference(r) => { - self.write_c_type_intern(w, &*r.elem, generics, true, r.mutability.is_some(), ptr_for_ref) - }, - syn::Type::Array(a) => { - if is_ref && is_mut { - write!(w, "*mut [").unwrap(); - if !self.write_c_type_intern(w, &a.elem, generics, false, false, ptr_for_ref) { return false; } - } else if is_ref { - write!(w, "*const [").unwrap(); - if !self.write_c_type_intern(w, &a.elem, generics, false, false, ptr_for_ref) { return false; } - } else { - let mut typecheck = Vec::new(); - if !self.write_c_type_intern(&mut typecheck, &a.elem, generics, false, false, ptr_for_ref) { return false; } - if typecheck[..] != ['u' as u8, '8' as u8] { return false; } - } - if let syn::Expr::Lit(l) = &a.len { - if let syn::Lit::Int(i) = &l.lit { - if !is_ref { - if let Some(ty) = self.c_type_from_path(&format!("[u8; {}]", i.base10_digits()), false, ptr_for_ref) { - write!(w, "{}", ty).unwrap(); - true - } else { false } - } else { - write!(w, "; {}]", i).unwrap(); - true - } - } else { false } - } else { false } - } - syn::Type::Slice(s) => { - if !is_ref || is_mut { return false; } - if let syn::Type::Path(p) = &*s.elem { - let resolved = self.resolve_path(&p.path, generics); - if self.is_primitive(&resolved) { - write!(w, "{}::{}slice", Self::container_templ_path(), resolved).unwrap(); - true - } else { false } - } else if let syn::Type::Reference(r) = &*s.elem { - if let syn::Type::Path(p) = &*r.elem { - // Slices with "real types" inside are mapped as the equivalent non-ref Vec - let resolved = self.resolve_path(&p.path, generics); - let mangled_container = if let Some(ident) = self.crate_types.opaques.get(&resolved) { - format!("CVec_{}Z", ident) - } else if let Some(en) = self.crate_types.mirrored_enums.get(&resolved) { - format!("CVec_{}Z", en.ident) - } else if let Some(id) = p.path.get_ident() { - format!("CVec_{}Z", id) - } else { return false; }; - write!(w, "{}::{}", Self::generated_container_path(), mangled_container).unwrap(); - self.check_create_container(mangled_container, "Vec", vec![&*r.elem], generics, false) - } else { false } - } else if let syn::Type::Tuple(_) = &*s.elem { - let mut args = syn::punctuated::Punctuated::new(); - args.push(syn::GenericArgument::Type((*s.elem).clone())); - let mut segments = syn::punctuated::Punctuated::new(); - segments.push(syn::PathSegment { - ident: syn::Ident::new("Vec", Span::call_site()), - arguments: syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments { - colon2_token: None, lt_token: syn::Token![<](Span::call_site()), args, gt_token: syn::Token![>](Span::call_site()), - }) - }); - self.write_c_type_intern(w, &syn::Type::Path(syn::TypePath { qself: None, path: syn::Path { leading_colon: None, segments } }), generics, false, is_mut, ptr_for_ref) - } else { false } - }, - syn::Type::Tuple(t) => { - if t.elems.len() == 0 { - true - } else { - self.write_c_mangled_container_path(w, t.elems.iter().collect(), generics, - &format!("{}Tuple", t.elems.len()), is_ref, is_mut, ptr_for_ref) - } - }, - _ => false, - } - } - pub fn write_c_type(&mut self, w: &mut W, t: &syn::Type, generics: Option<&GenericTypes>, ptr_for_ref: bool) { - assert!(self.write_c_type_intern(w, t, generics, false, false, ptr_for_ref)); - } - pub fn understood_c_path(&mut self, p: &syn::Path) -> bool { - if p.leading_colon.is_some() { return false; } - self.write_c_path_intern(&mut std::io::sink(), p, None, false, false, false) - } - pub fn understood_c_type(&mut self, t: &syn::Type, generics: Option<&GenericTypes>) -> bool { - self.write_c_type_intern(&mut std::io::sink(), t, generics, false, false, false) - } -} diff --git a/genbindings.sh b/genbindings.sh deleted file mode 100755 index 241ed3e8c..000000000 --- a/genbindings.sh +++ /dev/null @@ -1,215 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -x - -# Generate (and reasonably test) C bindings - -# First build the latest c-bindings-gen binary -cd c-bindings-gen && cargo build --release && cd .. - -# Then wipe all the existing C bindings (because we're being run in the right directory) -# note that we keep the few manually-generated files first: -mv lightning-c-bindings/src/c_types/mod.rs ./ -mv lightning-c-bindings/src/bitcoin ./ - -rm -rf lightning-c-bindings/src - -mkdir -p lightning-c-bindings/src/c_types/ -mv ./mod.rs lightning-c-bindings/src/c_types/ -mv ./bitcoin lightning-c-bindings/src/ - -# Finally, run the c-bindings-gen binary, building fresh bindings. -OUT="$(pwd)/lightning-c-bindings/src" -OUT_TEMPL="$(pwd)/lightning-c-bindings/src/c_types/derived.rs" -OUT_F="$(pwd)/lightning-c-bindings/include/rust_types.h" -OUT_CPP="$(pwd)/lightning-c-bindings/include/lightningpp.hpp" - -cd lightning -RUSTC_BOOTSTRAP=1 cargo rustc --profile=check -- -Zunstable-options --pretty=expanded | - RUST_BACKTRACE=1 ../c-bindings-gen/target/release/c-bindings-gen $OUT/ lightning $OUT_TEMPL $OUT_F $OUT_CPP -cd .. - -# Now cd to lightning-c-bindings, build the generated bindings, and call cbindgen to build a C header file -PATH="$PATH:~/.cargo/bin" -cd lightning-c-bindings -cargo build -cbindgen -v --config cbindgen.toml -o include/lightning.h >/dev/null 2>&1 - -HOST_PLATFORM="$(rustc --version --verbose | grep "host:")" - -# cbindgen is relatively braindead when exporting typedefs - -# it happily exports all our typedefs for private types, even with the -# generics we specified in C mode! So we drop all those types manually here. -if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then - # OSX sed is for some reason not compatible with GNU sed - sed -i '' 's/typedef LDKnative.*Import.*LDKnative.*;//g' include/lightning.h - - # stdlib.h doesn't exist in clang's wasm sysroot, and cbindgen - # doesn't actually use it anyway, so drop the import. - sed -i '' 's/#include //g' include/lightning.h -else - sed -i 's/typedef LDKnative.*Import.*LDKnative.*;//g' include/lightning.h - - # stdlib.h doesn't exist in clang's wasm sysroot, and cbindgen - # doesn't actually use it anyway, so drop the import. - sed -i 's/#include //g' include/lightning.h -fi - -# Finally, sanity-check the generated C and C++ bindings with demo apps: - -CFLAGS="-Wall -Wno-nullability-completeness -pthread" - -# Naively run the C demo app: -gcc $CFLAGS -Wall -g -pthread demo.c target/debug/libldk.a -ldl -./a.out - -# And run the C++ demo app in valgrind to test memory model correctness and lack of leaks. -g++ $CFLAGS -std=c++11 -Wall -g -pthread demo.cpp -Ltarget/debug/ -lldk -ldl -if [ -x "`which valgrind`" ]; then - LD_LIBRARY_PATH=target/debug/ valgrind --error-exitcode=4 --memcheck:leak-check=full --show-leak-kinds=all ./a.out - echo -else - echo "WARNING: Please install valgrind for more testing" -fi - -# Test a statically-linked C++ version, tracking the resulting binary size and runtime -# across debug, LTO, and cross-language LTO builds (using the same compiler each time). -clang++ $CFLAGS -std=c++11 demo.cpp target/debug/libldk.a -ldl -strip ./a.out -echo " C++ Bin size and runtime w/o optimization:" -ls -lha a.out -time ./a.out > /dev/null - -# Then, check with memory sanitizer, if we're on Linux and have rustc nightly -if [ "$HOST_PLATFORM" = "host: x86_64-unknown-linux-gnu" ]; then - if cargo +nightly --version >/dev/null 2>&1; then - LLVM_V=$(rustc +nightly --version --verbose | grep "LLVM version" | awk '{ print substr($3, 0, 2); }') - if [ -x "$(which clang-$LLVM_V)" ]; then - cargo +nightly clean - cargo +nightly rustc -Zbuild-std --target x86_64-unknown-linux-gnu -v -- -Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes - mv target/x86_64-unknown-linux-gnu/debug/libldk.* target/debug/ - - # Sadly, std doesn't seem to compile into something that is memsan-safe as of Aug 2020, - # so we'll always fail, not to mention we may be linking against git rustc LLVM which - # may differ from clang-llvm, so just allow everything here to fail. - set +e - - # First the C demo app... - clang-$LLVM_V $CFLAGS -fsanitize=memory -fsanitize-memory-track-origins -g demo.c target/debug/libldk.a -ldl - ./a.out - - # ...then the C++ demo app - clang++-$LLVM_V $CFLAGS -std=c++11 -fsanitize=memory -fsanitize-memory-track-origins -g demo.cpp target/debug/libldk.a -ldl - ./a.out >/dev/null - - # restore exit-on-failure - set -e - else - echo "WARNING: Can't use memory sanitizer without clang-$LLVM_V" - fi - else - echo "WARNING: Can't use memory sanitizer without rustc nightly" - fi -else - echo "WARNING: Can't use memory sanitizer on non-Linux, non-x86 platforms" -fi - -RUSTC_LLVM_V=$(rustc --version --verbose | grep "LLVM version" | awk '{ print substr($3, 0, 2); }' | tr -d '.') - -if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then - # Apple is special, as always, and decided that they must ensure that there is no way to identify - # the LLVM version used. Why? Just to make your life hard. - # This list is taken from https://en.wikipedia.org/wiki/Xcode - APPLE_CLANG_V=$(clang --version | head -n1 | awk '{ print $4 }') - if [ "$APPLE_CLANG_V" = "10.0.0" ]; then - CLANG_LLVM_V="6" - elif [ "$APPLE_CLANG_V" = "10.0.1" ]; then - CLANG_LLVM_V="7" - elif [ "$APPLE_CLANG_V" = "11.0.0" ]; then - CLANG_LLVM_V="8" - elif [ "$APPLE_CLANG_V" = "11.0.3" ]; then - CLANG_LLVM_V="9" - elif [ "$APPLE_CLANG_V" = "12.0.0" ]; then - CLANG_LLVM_V="10" - else - echo "WARNING: Unable to identify Apple clang LLVM version" - CLANG_LLVM_V="0" - fi -else - CLANG_LLVM_V=$(clang --version | head -n1 | awk '{ print substr($4, 0, 2); }' | tr -d '.') -fi - -if [ "$CLANG_LLVM_V" = "$RUSTC_LLVM_V" ]; then - CLANG=clang - CLANGPP=clang++ -elif [ "$(which clang-$RUSTC_LLVM_V)" != "" ]; then - CLANG="$(which clang-$RUSTC_LLVM_V)" - CLANGPP="$(which clang++-$RUSTC_LLVM_V)" -fi - -if [ "$CLANG" != "" -a "$CLANGPP" = "" ]; then - echo "WARNING: It appears you have a clang-$RUSTC_LLVM_V but not clang++-$RUSTC_LLVM_V. This is common, but leaves us unable to compile C++ with LLVM $RUSTC_LLVM_V" - echo "You should create a symlink called clang++-$RUSTC_LLVM_V pointing to $CLANG in $(dirname $CLANG)" -fi - -# Finally, if we're on OSX or on Linux, build the final debug binary with address sanitizer (and leave it there) -if [ "$HOST_PLATFORM" = "host: x86_64-unknown-linux-gnu" -o "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then - if [ "$CLANGPP" != "" ]; then - if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then - # OSX sed is for some reason not compatible with GNU sed - sed -i .bk 's/,"cdylib"]/]/g' Cargo.toml - else - sed -i.bk 's/,"cdylib"]/]/g' Cargo.toml - fi - RUSTC_BOOTSTRAP=1 cargo rustc -v -- -Zsanitizer=address -Cforce-frame-pointers=yes || ( mv Cargo.toml.bk Cargo.toml; exit 1) - mv Cargo.toml.bk Cargo.toml - - # First the C demo app... - $CLANG $CFLAGS -fsanitize=address -g demo.c target/debug/libldk.a -ldl - ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' ./a.out - - # ...then the C++ demo app - $CLANGPP $CFLAGS -std=c++11 -fsanitize=address -g demo.cpp target/debug/libldk.a -ldl - ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' ./a.out >/dev/null - else - echo "WARNING: Please install clang-$RUSTC_LLVM_V and clang++-$RUSTC_LLVM_V to build with address sanitizer" - fi -else - echo "WARNING: Can't use address sanitizer on non-Linux, non-OSX non-x86 platforms" -fi - -if [ "$(rustc --print target-list | grep wasm32-wasi)" != "" ]; then - # Test to see if clang supports wasm32 as a target (which is needed to build rust-secp256k1) - echo "int main() {}" > genbindings_wasm_test_file.c - clang -nostdlib -o /dev/null --target=wasm32-wasi -Wl,--no-entry genbindings_wasm_test_file.c > /dev/null 2>&1 && - # And if it does, build a WASM binary without capturing errors - cargo rustc -v --target=wasm32-wasi -- -C embed-bitcode=yes && - CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release --target=wasm32-wasi -- -C opt-level=s -C linker-plugin-lto -C lto || - echo "Cannot build WASM lib as clang does not seem to support the wasm32-wasi target" - rm genbindings_wasm_test_file.c -fi - -# Now build with LTO on on both C++ and rust, but without cross-language LTO: -CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release -- -C lto -clang++ $CFLAGS -std=c++11 -flto -O2 demo.cpp target/release/libldk.a -ldl -strip ./a.out -echo "C++ Bin size and runtime with only RL (LTO) optimized:" -ls -lha a.out -time ./a.out > /dev/null - -if [ "$HOST_PLATFORM" != "host: x86_64-apple-darwin" -a "$CLANGPP" != "" ]; then - # Finally, test cross-language LTO. Note that this will fail if rustc and clang++ - # build against different versions of LLVM (eg when rustc is installed via rustup - # or Ubuntu packages). This should work fine on Distros which do more involved - # packaging than simply shipping the rustup binaries (eg Debian should Just Work - # here). - CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release -- -C linker-plugin-lto -C lto -C link-arg=-fuse-ld=lld - $CLANGPP $CFLAGS -flto -fuse-ld=lld -O2 demo.cpp target/release/libldk.a -ldl - strip ./a.out - echo "C++ Bin size and runtime with cross-language LTO:" - ls -lha a.out - time ./a.out > /dev/null -else - echo "WARNING: Building with cross-language LTO is not avilable on OSX or without clang-$RUSTC_LLVM_V" -fi diff --git a/lightning-c-bindings/Cargo.toml b/lightning-c-bindings/Cargo.toml deleted file mode 100644 index 76047314e..000000000 --- a/lightning-c-bindings/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "lightning-c-bindings" -version = "0.0.1" -authors = ["Matt Corallo"] -license = "Apache-2.0" -edition = "2018" -description = """ -Utilities to fetch the chain from Bitcoin Core REST/RPC Interfaces and feed them into Rust Lightning. -""" - -[lib] -name = "ldk" -crate-type = ["staticlib" -# Note that the following line is matched exactly by genbindings to turn off dylib creation -,"cdylib"] - -[dependencies] -bitcoin = "0.26" -secp256k1 = { version = "0.20.1", features = ["global-context-less-secure"] } -lightning = { version = "0.0.12", path = "../lightning" } - -[patch.crates-io] -# Rust-Secp256k1 PR 279. Should be dropped once merged. -secp256k1 = { git = 'https://github.com/TheBlueMatt/rust-secp256k1', rev = '15a0d4195a20355f6b1e8f54c84eba56abc15cbd' } - -# Always force panic=abort, further options are set in the genbindings.sh build script -[profile.dev] -panic = "abort" - -[profile.release] -panic = "abort" - -# We eventually want to join the root workspace, but for now, the bindings generation is -# a bit brittle and we don't want to hold up other developers from making changes just -# because they break the bindings -[workspace] diff --git a/lightning-c-bindings/README.md b/lightning-c-bindings/README.md deleted file mode 100644 index 0c221c7c6..000000000 --- a/lightning-c-bindings/README.md +++ /dev/null @@ -1,238 +0,0 @@ -The wrapper crate and C/C++ Headers in this folder are auto-generated from the Rust-Lightning -source by the c-bindings-gen crate contained in the source tree and -[cbindgen](https://github.com/eqrion/cbindgen). They are intended to be used as a base for building -language-specific bindings, and are thus incredibly low-level and may be difficult to work with -directly. - -In other words, if you're reading this, you're either writing bindings for a new language, or -you're in the wrong place - individual language bindings should come with their own documentation. - -LDK C Bindings -============== - -The C bindings available at include/lightning.h require inclusion of include/rust_types.h first. - -All of the Rust-Lightning types are mapped into C equivalents which take a few forms, with the C -type getting an `LDK` prefix to their native Rust type names. - -#### Structs -Structs are mapped into a simple wrapper containing a pointer to the native Rust-Lightning object -and a flag to indicate whether the object is owned or only a reference. Such mappings usually -generate a `X_free` function which must be called to release the allocated resources. Note that -calling `X_free` will do nothing if the underlying pointer is NULL or if the `is_owned` flag is not -set. - -You MUST NOT create such wrapper structs manually, relying instead on constructors which have been -mapped from equivalent Rust constructors. - -Note that, thanks to the is-owned flag and the pointer being NULLable, such structs effectively -represent `RustType`, `&RustType`, and `Option`. Check the corresponding Rust -documentation for the function or struct you are using to ensure you use the correct call semantics. -The passed struct must match the call semantics or an assertion failure or NULL pointer dereference -may occur. - -For example, this is the mapping of ChannelManager. -```c -typedef struct MUST_USE_STRUCT LDKChannelManager { - /** ... */ - LDKnativeChannelManager *inner; - bool is_owned; -} LDKChannelManager; -``` - -#### Traits -Traits are mapped into a concrete struct containing a void pointer (named `this_arg` and a jump -table listing the functions which the trait must implement. The void pointer may be set to any value -and is never interpreted (or dereferenced) by the bindings logic in any way. It is passed as the -first argument to all function calls in the trait. You may wish to use it as a pointer to your own -internal data structure, though it may also occasionally make sense to e.g. cast a file descriptor -into a void pointer and use it to track a socket. - -This should remind you of a C++ vtable, only written out by hand and with the class only containing -a pointer, instead of the regular class data. - -Each trait additionally contains `free` and `clone` function pointers, which may be NULL. The `free` -function is passed the void pointer when the object is `Drop`ed in Rust. The `clone` function is -passed the void pointer when the object is `Clone`ed in Rust, returning a new void pointer for the -new object. If the `free` pointer is NULL, you will not receive any notification when the trait -object is no longer needed. If the `clone` pointer is NULL, we assume that the trait object may be -`memcpy()`'d to create copies. Note that if you release resources with `free` without implementing -`clone`, you will likely end up with use-after-free bugs (as copies of the original this_arg value -may still exist, unbeknownst to you). - -For example, `LDKSocketDescriptor` is mapped as follows: -```c -typedef struct LDKSocketDescriptor { - void *this_arg; - /** ... */ - uintptr_t (*send_data)(void *this_arg, LDKu8slice data, bool resume_read); - /** ... */ - void (*disconnect_socket)(void *this_arg); - bool (*eq)(const void *this_arg, const void *other_arg); - uint64_t (*hash)(const void *this_arg); - void *(*clone)(const void *this_arg); - void (*free)(void *this_arg); -} LDKSocketDescriptor; -``` - -##### Rust Trait Implementations -Rust structs that implement a trait result in the generation of an `X_as_Y` function, which takes a -C struct wrapping the Rust native object and returns a generated trait object. Such generated -objects are only valid as long as the original Rust native object has not been `free`'d or moved as -a part of a Rust function call (ie continues to be owned by the C struct). For example, to use an -`LDKInMemoryChannelKeys` as a `ChannelKeys`, `InMemoryChannelKeys_as_ChannelKeys` is exposed: - -```c -LDKChannelKeys InMemoryChannelKeys_as_ChannelKeys(const LDKInMemoryChannelKeys *this_arg); -``` - -#### Enums -Rust "unitary" enums are mapped simply as an equivalent C enum; however, some Rust enums have -variants which contain payloads. Such enums are mapped automatically by cbindgen as a tag which -indicates the type and a union which holds the relevant fields for a given tag. An `X_free` function -is provided for the enum as a whole which automatically frees the correct fields for a give tag, and -a `Sentinel` tag is provided which causes the free function to do nothing (but which must never -appear in an enum when accessed by Rust code). The `Sentinel` tag is used by the C++ wrapper classes -to allow moving the ownership of an enum while invalidating the old copy. - -For example, the unitary enum `LDKChannelMonitorUpdateErr` is mapped as follows: -```c -typedef enum LDKChannelMonitorUpdateErr { - /** .. */ - LDKChannelMonitorUpdateErr_TemporaryFailure, - /** .. */ - LDKChannelMonitorUpdateErr_PermanentFailure, - /** .. */ - LDKChannelMonitorUpdateErr_Sentinel, -} LDKChannelMonitorUpdateErr; -``` - -and the non-unitary enum LDKErrorAction is mapped as follows: -```c -typedef enum LDKErrorAction_Tag { - /** .. */ - LDKErrorAction_DisconnectPeer, - /** .. */ - LDKErrorAction_IgnoreError, - /** .. */ - LDKErrorAction_SendErrorMessage, - /** .. */ - LDKErrorAction_Sentinel, -} LDKErrorAction_Tag; - -typedef struct LDKErrorAction_LDKDisconnectPeer_Body { - LDKErrorMessage msg; -} LDKErrorAction_LDKDisconnectPeer_Body; - -typedef struct LDKErrorAction_LDKSendErrorMessage_Body { - LDKErrorMessage msg; -} LDKErrorAction_LDKSendErrorMessage_Body; - -typedef struct LDKErrorAction { - LDKErrorAction_Tag tag; - union { - LDKErrorAction_LDKDisconnectPeer_Body disconnect_peer; - LDKErrorAction_LDKSendErrorMessage_Body send_error_message; - }; -} LDKErrorAction; -``` - -#### Functions -Struct member functions are mapped as `Struct_function_name` and take a pointer to the mapped struct -as their first argument. Free-standing functions are mapped simply as `function_name` and take the -relevant mapped type arguments. - -Functions which return `&OpaqueRustType` and which return `OpaqueRustType` are both mapped to a -function returning an owned wrapper struct. The `is_owned` flag (see above) will be set to indicate -that the pointed-to Rust object is owned or only a reference. Thus, when implementing a function -which Rust will call or calling a Rust function, you should check the Rust documentation for the -function to determine whether an owned or referenced object is expected or returned. - -Similarly, when a function takes an `Option` as a parameter or a return value, the C type -is the same as if it took only `RustType`, with the `inner` field set to NULL to indicate None. For -example, `ChannelManager_create_channel` takes an `Option` not an `LDKUserConfig`, -but its definition is: -```c -MUST_USE_RES ... ChannelManager_create_channel(const LDKChannelManager *this_arg, ..., LDKUserConfig override_config); -``` - -#### Containers -Various containers (Tuples, Vecs, Results, etc) are mapped into C structs of the form -`LDKCContainerType_ContainerElementsZ`. Inner fields are often pointers, and in the case of -primitive types, these may be allocated in C using the system allocator. See [the Rust docs on your -platform's default System allocator](https://doc.rust-lang.org/std/alloc/struct.System.html) for - which allocator you must use. Recursive containers are possible, and simply replace the -`ContainerElements` part with `InnerContainerType_InnerContainerElementsZ`, eg -`LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ` represents a -`Result<(Signature, Vec), ()>`. - -#### Notes -As the bindings are auto-generated, the best resource for documentation on them is the native Rust -docs available via `cargo doc` or [docs.rs/lightning](https://docs.rs/lightning). - -The memory model is largely the Rust memory model and not a native C-like memory model. Thus, -function parameters are largely only ever passed by reference or by move, with pass-by-copy -semantics only applying to primitive types. However, because the underlying types are largely -pointers, the same function signature may imply two different memory ownership semantics. Thus, you -MUST read the Rust documentation while using the C bindings. For functions which take arguments -where ownership is moved to the function scope, the corresponding `X_free` function MUST NOT be -called on the object, whereas for all other objects, `X_free` MUST be used to free resources. - -LDK C++ Bindings -================ - -The C++ bindings available at include/lightningpp.hpp require extern "C" inclusion of lightning.h -and rust_types.h first. They represent thin wrappers around the C types which provide a few -C++-isms to make memory model correctness easier to achieve. They provide: - * automated destructors which call the relevant `X_free` C functions, - * move constructors both from C++ classes and the original C struct, with the original object - cleared to ensure destruction/`X_free` calls do not cause a double-free. - * Move semantics via the () operator, returning the original C struct and clearing the C++ object. - This allows calls such as `C_function(cpp_object)` which work as expected with move semantics. - -In general, you should prefer to use the C++ bindings if possible, as they make memory leaks and -other violations somewhat easier to avoid. Note that, because the C functions are not redefined in -C++, all functions return the C type. Thus, you must bind returned values to the equivalent C++ type -(replacing `LDKX` with `LDK::X`) to ensure the destructor is properly run. A demonstration of such -usage is available at [demo.cpp](demo.cpp). - -Gotchas -======= - -There are a few gotchas around future changes to Rust-Lightning which the bindings may not support. -These include: - * Any trait method which returns a reference to a struct or inner variable cannot be called in - parallel. This is because such functions always return a local variable stored inside the trait, - with a call through a function pointer to get the local variable set correctly. Automatically - generated setter functions have comments describing the potential race conditions in their - definition. - - For example, the `ChannelKeys::pubkeys() -> &ChannelPublicKeys` function is mapped as this: - - ```c - typedef struct LDKChannelKeys { - ... - LDKChannelPublicKeys pubkeys; - /** ... */ - void (*set_pubkeys)(const LDKChannelKeys*); - ... - } LDKChannelKeys; - ``` - * Private and public keys are asserted valid at the FFI boundary. Thus, before passing any - (untrusted) private or public key material across the boundary, ensure that they represent valid - (ie in-range) keys. - -**It is highly recommended that you test any code which relies on the C (or C++) bindings in -valgrind, AddressSanitizer, MemorySanitizer, or other similar tools to ensure correctness.** - -Process -======= - -`genbindings.sh` is currently a catch-all script for bindings - it generates the latest Rust/C/C++ -code for bindings from the rust-lightning source code, builds it, and then runs various test apps. - -Note that after running `genbindings.sh`, if possible, the static lib in target/debug (eg -target/debug/liblightning.a) will be linked with address sanitizer. In order to build against it, -you will need to link with `clang` with `-fsanitize=address` with the same version of LLVM as -`rustc`'s LLVM. If `genbindings.sh` failed to find a matching `clang` or you are building on an -unsupported platform, a warning noting that address sanitizer is not available will be printed. diff --git a/lightning-c-bindings/cbindgen.toml b/lightning-c-bindings/cbindgen.toml deleted file mode 100644 index 9480b8688..000000000 --- a/lightning-c-bindings/cbindgen.toml +++ /dev/null @@ -1,555 +0,0 @@ -# The language to output bindings in -# -# possible values: "C", "C++" -# -# default: "C++" -language = "C" - - - - -# Options for wrapping the contents of the header: - -# An optional string of text to output at the beginning of the generated file -# default: doesn't emit anything -header = "/* Text to put at the beginning of the generated file. Probably a license. */" - -# An optional string of text to output at the end of the generated file -# default: doesn't emit anything -trailer = "/* Text to put at the end of the generated file */" - -# An optional name to use as an include guard -# default: doesn't emit an include guard -# include_guard = "mozilla_wr_bindings_h" - -# An optional string of text to output between major sections of the generated -# file as a warning against manual editing -# -# default: doesn't emit anything -autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" - -# Whether to include a comment with the version of cbindgen used to generate the file -# default: false -include_version = true - -# An optional namespace to output around the generated bindings -# default: doesn't emit a namespace -namespace = "LDK" - -# An optional list of namespaces to output around the generated bindings -# default: [] -namespaces = [] - -# An optional list of namespaces to declare as using with "using namespace" -# default: [] -using_namespaces = [] - -# A list of sys headers to #include (with angle brackets) -# default: [] -# sys_includes = ["stdio", "string"] -# sys_includes = ["stdint"] - -# A list of headers to #include (with quotes) -# default: [] -# includes = ["my_great_lib.h"] - -# Whether cbindgen's default C/C++ standard imports should be suppressed. These -# imports are included by default because our generated headers tend to require -# them (e.g. for uint32_t). Currently, the generated imports are: -# -# * for C: , , , , -# -# * for C++: , , , , (depending on config) -# -# default: false -no_includes = false - - - - - -# Code Style Options - -# The style to use for curly braces -# -# possible values: "SameLine", "NextLine" -# -# default: "SameLine" -braces = "SameLine" - -# The desired length of a line to use when formatting lines -# default: 100 -line_length = 80 - -# The amount of spaces to indent by -# default: 2 -tab_width = 3 - -# How the generated documentation should be commented. -# -# possible values: -# * "c": /* like this */ -# * "c99": // like this -# * "c++": /// like this -# * "doxy": like C, but with leading *'s on each line -# * "auto": "c++" if that's the language, "doxy" otherwise -# -# default: "auto" -documentation_style = "doxy" - - - - - -# Codegen Options - -# When generating a C header, the kind of declaration style to use for structs -# or enums. -# -# possible values: -# * "type": typedef struct { ... } MyType; -# * "tag": struct MyType { ... }; -# * "both": typedef struct MyType { ... } MyType; -# -# default: "both" -style = "both" - -# A list of substitutions for converting cfg's to ifdefs. cfgs which aren't -# defined here will just be discarded. -# -# e.g. -# `#[cfg(target = "freebsd")] ...` -# becomes -# `#if defined(DEFINE_FREEBSD) ... #endif` -[defines] -"target_os = freebsd" = "DEFINE_FREEBSD" -"feature = serde" = "DEFINE_SERDE" - - - - - -[export] -# A list of additional items to always include in the generated bindings if they're -# found but otherwise don't appear to be used by the public API. -# -# default: [] -# include = ["MyOrphanStruct", "MyGreatTypeRename"] - -# A list of items to not include in the generated bindings -# default: [] -# exclude = ["Bad"] - -# A prefix to add before the name of every item -# default: no prefix is added -prefix = "LDK" - -# Types of items that we'll generate. If empty, then all types of item are emitted. -# -# possible items: (TODO: explain these in detail) -# * "constants": -# * "globals": -# * "enums": -# * "structs": -# * "unions": -# * "typedefs": -# * "opaque": -# * "functions": -# -# default: [] -item_types = ["constants", "globals", "enums", "structs", "unions", "typedefs", "opaque", "functions"] - -# Whether applying rules in export.rename prevents export.prefix from applying. -# -# e.g. given this toml: -# -# [export] -# prefix = "capi_" -# [export.rename] -# "MyType" = "my_cool_type" -# -# You get the following results: -# -# renaming_overrides_prefixing = true: -# "MyType" => "my_cool_type" -# -# renaming_overrides_prefixing = false: -# "MyType => capi_my_cool_type" -# -# default: false -renaming_overrides_prefixing = true - -# Table of name conversions to apply to item names (lhs becomes rhs) -# [export.rename] -# "MyType" = "my_cool_type" -# "my_function" = "BetterFunctionName" - -# Table of things to prepend to the body of any struct, union, or enum that has the -# given name. This can be used to add things like methods which don't change ABI, -# mark fields private, etc -[export.pre_body] -"MyType" = """ - MyType() = delete; -private: -""" - -# Table of things to append to the body of any struct, union, or enum that has the -# given name. This can be used to add things like methods which don't change ABI. -[export.body] -"MyType" = """ - void cppMethod() const; -""" - -[layout] -# A string that should come before the name of any type which has been marked -# as `#[repr(packed)]`. For instance, "__attribute__((packed))" would be a -# reasonable value if targeting gcc/clang. A more portable solution would -# involve emitting the name of a macro which you define in a platform-specific -# way. e.g. "PACKED" -# -# default: `#[repr(packed)]` types will be treated as opaque, since it would -# be unsafe for C callers to use a incorrectly laid-out union. -packed = "PACKED" - -# A string that should come before the name of any type which has been marked -# as `#[repr(align(n))]`. This string must be a function-like macro which takes -# a single argument (the requested alignment, `n`). For instance, a macro -# `#define`d as `ALIGNED(n)` in `header` which translates to -# `__attribute__((aligned(n)))` would be a reasonable value if targeting -# gcc/clang. -# -# default: `#[repr(align(n))]` types will be treated as opaque, since it -# could be unsafe for C callers to use a incorrectly-aligned union. -aligned_n = "ALIGNED" - - -[fn] -# An optional prefix to put before every function declaration -# default: no prefix added -# prefix = "WR_START_FUNC" - -# An optional postfix to put after any function declaration -# default: no postix added -# postfix = "WR_END_FUNC" - -# How to format function arguments -# -# possible values: -# * "horizontal": place all arguments on the same line -# * "vertical": place each argument on its own line -# * "auto": only use vertical if horizontal would exceed line_length -# -# default: "auto" -args = "horizontal" - -# An optional string that should prefix function declarations which have been -# marked as `#[must_use]`. For instance, "__attribute__((warn_unused_result))" -# would be a reasonable value if targeting gcc/clang. A more portable solution -# would involve emitting the name of a macro which you define in a -# platform-specific way. e.g. "MUST_USE_FUNC" -# default: nothing is emitted for must_use functions -must_use = "MUST_USE_RES" - -# An optional string that, if present, will be used to generate Swift function -# and method signatures for generated functions, for example "CF_SWIFT_NAME". -# If no such macro is available in your toolchain, you can define one using the -# `header` option in cbindgen.toml -# default: no swift_name function attributes are generated -# swift_name_macro = "CF_SWIFT_NAME" - -# A rule to use to rename function argument names. The renaming assumes the input -# is the Rust standard snake_case, however it accepts all the different rename_args -# inputs. This means many options here are no-ops or redundant. -# -# possible values (that actually do something): -# * "CamelCase": my_arg => myArg -# * "PascalCase": my_arg => MyArg -# * "GeckoCase": my_arg => aMyArg -# * "ScreamingSnakeCase": my_arg => MY_ARG -# * "None": apply no renaming -# -# technically possible values (that shouldn't have a purpose here): -# * "SnakeCase": apply no renaming -# * "LowerCase": apply no renaming (actually applies to_lowercase, is this bug?) -# * "UpperCase": same as ScreamingSnakeCase in this context -# * "QualifiedScreamingSnakeCase" => same as ScreamingSnakeCase in this context -# -# default: "None" -rename_args = "None" - -# This rule specifies if the order of functions will be sorted in some way. -# -# "Name": sort by the name of the function -# "None": keep order in which the functions have been parsed -# -# default: "Name" -sort_by = "None" - -[struct] -# A rule to use to rename struct field names. The renaming assumes the input is -# the Rust standard snake_case, however it acccepts all the different rename_args -# inputs. This means many options here are no-ops or redundant. -# -# possible values (that actually do something): -# * "CamelCase": my_arg => myArg -# * "PascalCase": my_arg => MyArg -# * "GeckoCase": my_arg => mMyArg -# * "ScreamingSnakeCase": my_arg => MY_ARG -# * "None": apply no renaming -# -# technically possible values (that shouldn't have a purpose here): -# * "SnakeCase": apply no renaming -# * "LowerCase": apply no renaming (actually applies to_lowercase, is this bug?) -# * "UpperCase": same as ScreamingSnakeCase in this context -# * "QualifiedScreamingSnakeCase" => same as ScreamingSnakeCase in this context -# -# default: "None" -rename_fields = "None" - -# An optional string that should come before the name of any struct which has been -# marked as `#[must_use]`. For instance, "__attribute__((warn_unused))" -# would be a reasonable value if targeting gcc/clang. A more portable solution -# would involve emitting the name of a macro which you define in a -# platform-specific way. e.g. "MUST_USE_STRUCT" -# -# default: nothing is emitted for must_use structs -must_use = "MUST_USE_STRUCT" - -# Whether a Rust type with associated consts should emit those consts inside the -# type's body. Otherwise they will be emitted trailing and with the type's name -# prefixed. This does nothing if the target is C, or if -# [const]allow_static_const = false -# -# default: false -# associated_constants_in_body: false - -# Whether to derive a simple constructor that takes a value for every field. -# default: false -derive_constructor = true - -# Whether to derive an operator== for all structs -# default: false -derive_eq = false - -# Whether to derive an operator!= for all structs -# default: false -derive_neq = false - -# Whether to derive an operator< for all structs -# default: false -derive_lt = false - -# Whether to derive an operator<= for all structs -# default: false -derive_lte = false - -# Whether to derive an operator> for all structs -# default: false -derive_gt = false - -# Whether to derive an operator>= for all structs -# default: false -derive_gte = false - - - - - -[enum] -# A rule to use to rename enum variants, and the names of any fields those -# variants have. This should probably be split up into two separate options, but -# for now, they're the same! See the documentation for `[struct]rename_fields` -# for how this applies to fields. Renaming of the variant assumes that the input -# is the Rust standard PascalCase. In the case of QualifiedScreamingSnakeCase, -# it also assumed that the enum's name is PascalCase. -# -# possible values (that actually do something): -# * "CamelCase": MyVariant => myVariant -# * "SnakeCase": MyVariant => my_variant -# * "ScreamingSnakeCase": MyVariant => MY_VARIANT -# * "QualifiedScreamingSnakeCase": MyVariant => ENUM_NAME_MY_VARIANT -# * "LowerCase": MyVariant => myvariant -# * "UpperCase": MyVariant => MYVARIANT -# * "None": apply no renaming -# -# technically possible values (that shouldn't have a purpose for the variants): -# * "PascalCase": apply no renaming -# * "GeckoCase": apply no renaming -# -# default: "None" -rename_variants = "None" - -# Whether an extra "sentinel" enum variant should be added to all generated enums. -# Firefox uses this for their IPC serialization library. -# -# WARNING: if the sentinel is ever passed into Rust, behaviour will be Undefined. -# Rust does not know about this value, and will assume it cannot happen. -# -# default: false -add_sentinel = true - -# Whether enum variant names should be prefixed with the name of the enum. -# default: false -prefix_with_name = true - -# Whether to emit enums using "enum class" when targeting C++. -# default: true -enum_class = true - -# Whether to generate static `::MyVariant(..)` constructors and `bool IsMyVariant()` -# methods for enums with fields. -# -# default: false -derive_helper_methods = false - -# Whether to generate `const MyVariant& AsMyVariant() const` methods for enums with fields. -# default: false -derive_const_casts = false - -# Whether to generate `MyVariant& AsMyVariant()` methods for enums with fields -# default: false -derive_mut_casts = false - -# The name of the macro/function to use for asserting `IsMyVariant()` in the body of -# derived `AsMyVariant()` cast methods. -# -# default: "assert" (but also causes `` to be included by default) -cast_assert_name = "MOZ_RELEASE_ASSERT" - -# An optional string that should come before the name of any enum which has been -# marked as `#[must_use]`. For instance, "__attribute__((warn_unused))" -# would be a reasonable value if targeting gcc/clang. A more portable solution -# would involve emitting the name of a macro which you define in a -# platform-specific way. e.g. "MUST_USE_ENUM" -# -# Note that this refers to the *output* type. That means this will not apply to an enum -# with fields, as it will be emitted as a struct. `[struct]must_use` will apply there. -# -# default: nothing is emitted for must_use enums -must_use = "MUST_USE_ENUM" - -# Whether enums with fields should generate destructors. This exists so that generic -# enums can be properly instantiated with payloads that are C++ types with -# destructors. This isn't necessary for structs because C++ has rules to -# automatically derive the correct constructors and destructors for those types. -# -# Care should be taken with this option, as Rust and C++ cannot -# properly interoperate with eachother's notions of destructors. Also, this may -# change the ABI for the type. Either your destructor-full enums must live -# exclusively within C++, or they must only be passed by-reference between -# C++ and Rust. -# -# default: false -derive_tagged_enum_destructor = false - -# Whether enums with fields should generate copy-constructor. See the discussion on -# derive_tagged_enum_destructor for why this is both useful and very dangerous. -# -# default: false -derive_tagged_enum_copy_constructor = false -# Whether enums with fields should generate copy-assignment operators. -# -# This depends on also deriving copy-constructors, and it is highly encouraged -# for this to be set to true. -# -# default: false -derive_tagged_enum_copy_assignment = false - -# Whether enums with fields should generate an empty, private destructor. -# This allows the auto-generated constructor functions to compile, if there are -# non-trivially constructible members. This falls in the same family of -# dangerousness as `derive_tagged_enum_copy_constructor` and co. -# -# default: false -private_default_tagged_enum_constructor = false - - - - - -[const] -# Whether a generated constant can be a static const in C++ mode. I have no -# idea why you would turn this off. -# -# default: true -allow_static_const = true - -# Whether a generated constant can be constexpr in C++ mode. -# -# default: false - - - - - -[macro_expansion] -# Whether bindings should be generated for instances of the bitflags! macro. -# default: false -bitflags = true - - - - - - -# Options for how your Rust library should be parsed - -[parse] -# Whether to parse dependent crates and include their types in the output -# default: false -parse_deps = true - -# A white list of crate names that are allowed to be parsed. If this is defined, -# only crates found in this list will ever be parsed. -# -# default: there is no whitelist (NOTE: this is the opposite of []) -include = ["webrender", "webrender_traits"] - -# A black list of crate names that are not allowed to be parsed. -# default: [] -exclude = ["libc"] - -# Whether to use a new temporary target directory when running `rustc --pretty=expanded`. -# This may be required for some build processes. -# -# default: false -clean = false - -# Which crates other than the top-level binding crate we should generate -# bindings for. -# -# default: [] -extra_bindings = ["my_awesome_dep"] - -[parse.expand] -# A list of crate names that should be run through `cargo expand` before -# parsing to expand any macros. Note that if a crate is named here, it -# will always be parsed, even if the blacklist/whitelist says it shouldn't be. -# -# default: [] -crates = ["euclid"] - -# If enabled, use the `--all-features` option when expanding. Ignored when -# `features` is set. For backwards-compatibility, this is forced on if -# `expand = ["euclid"]` shorthand is used. -# -# default: false -all_features = false - -# When `all_features` is disabled and this is also disabled, use the -# `--no-default-features` option when expanding. -# -# default: true -default_features = true - -# A list of feature names that should be used when running `cargo expand`. This -# combines with `default_features` like in your `Cargo.toml`. Note that the features -# listed here are features for the current crate being built, *not* the crates -# being expanded. The crate's `Cargo.toml` must take care of enabling the -# appropriate features in its dependencies -# -# default: [] -features = ["cbindgen"] - -[ptr] -non_null_attribute = "NONNULL_PTR" diff --git a/lightning-c-bindings/demo.c b/lightning-c-bindings/demo.c deleted file mode 100644 index d9508c59e..000000000 --- a/lightning-c-bindings/demo.c +++ /dev/null @@ -1,99 +0,0 @@ -#include "include/rust_types.h" -#include "include/lightning.h" - -#include -#include -#include - -void print_log(const void *this_arg, const char *record) { - printf("%s", record); -} - -uint32_t get_fee(const void *this_arg, LDKConfirmationTarget target) { - if (target == LDKConfirmationTarget_Background) { - return 253; - } else { - return 507; - } -} - -void broadcast_tx(const void *this_arg, LDKTransaction tx) { - //TODO - Transaction_free(tx); -} - -LDKCResult_NoneChannelMonitorUpdateErrZ add_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) { - return CResult_NoneChannelMonitorUpdateErrZ_ok(); -} -LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, LDKChannelMonitorUpdate monitor) { - return CResult_NoneChannelMonitorUpdateErrZ_ok(); -} -LDKCVec_MonitorEventZ monitors_pending_monitor_events(const void *this_arg) { - LDKCVec_MonitorEventZ empty_htlc_vec = { - .data = NULL, - .datalen = 0, - }; - return empty_htlc_vec; -} - -int main() { - uint8_t node_seed[32]; - memset(node_seed, 0, 32); - - LDKNetwork net = LDKNetwork_Bitcoin; - - LDKLogger logger = { - .this_arg = NULL, - .log = print_log, - .free = NULL, - }; - - LDKFeeEstimator fee_est = { - .this_arg = NULL, - .get_est_sat_per_1000_weight = get_fee, - .free = NULL - }; - - LDKWatch mon = { - .this_arg = NULL, - .watch_channel = add_channel_monitor, - .update_channel = update_channel_monitor, - .release_pending_monitor_events = monitors_pending_monitor_events, - .free = NULL, - }; - - LDKBroadcasterInterface broadcast = { - broadcast.this_arg = NULL, - broadcast.broadcast_transaction = broadcast_tx, - .free = NULL, - }; - - LDKKeysManager keys = KeysManager_new(&node_seed, 0, 0); - LDKKeysInterface keys_source = KeysManager_as_KeysInterface(&keys); - - LDKUserConfig config = UserConfig_default(); - LDKThirtyTwoBytes chain_tip; - memset(&chain_tip, 0, 32); - LDKChainParameters chain = ChainParameters_new(net, chain_tip, 0); - LDKChannelManager cm = ChannelManager_new(fee_est, mon, broadcast, logger, keys_source, config, chain); - - LDKCVec_ChannelDetailsZ channels = ChannelManager_list_channels(&cm); - assert((unsigned long)channels.data < 4096); // There's an offset, but it should still be an offset against null in the 0 page - assert(channels.datalen == 0); - CVec_ChannelDetailsZ_free(channels); - - LDKEventsProvider prov = ChannelManager_as_EventsProvider(&cm); - LDKCVec_EventZ events = (prov.get_and_clear_pending_events)(prov.this_arg); - assert((unsigned long)events.data < 4096); // There's an offset, but it should still be an offset against null in the 0 page - assert(events.datalen == 0); - - ChannelManager_free(cm); - KeysManager_free(keys); - - // Check that passing empty vecs to rust doesn't blow it up: - LDKCVec_MonitorEventZ empty_htlc_vec = { - .data = NULL, - .datalen = 0, - }; - CVec_MonitorEventZ_free(empty_htlc_vec); -} diff --git a/lightning-c-bindings/demo.cpp b/lightning-c-bindings/demo.cpp deleted file mode 100644 index 230d0c0c9..000000000 --- a/lightning-c-bindings/demo.cpp +++ /dev/null @@ -1,640 +0,0 @@ -extern "C" { -#include "include/rust_types.h" -#include "include/lightning.h" -} -#include "include/lightningpp.hpp" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -const uint8_t valid_node_announcement[] = { - 0x94, 0xe4, 0xf5, 0x61, 0x41, 0x24, 0x7d, 0x90, 0x23, 0xa0, 0xc8, 0x34, 0x8c, 0xc4, 0xca, 0x51, - 0xd8, 0x17, 0x59, 0xff, 0x7d, 0xac, 0x8c, 0x9b, 0x63, 0x29, 0x1c, 0xe6, 0x12, 0x12, 0x93, 0xbd, - 0x66, 0x4d, 0x6b, 0x9c, 0xfb, 0x35, 0xda, 0x16, 0x06, 0x3d, 0xf0, 0x8f, 0x8a, 0x39, 0x99, 0xa2, - 0xf2, 0x5d, 0x12, 0x0f, 0x2b, 0x42, 0x1b, 0x8b, 0x9a, 0xfe, 0x33, 0x0c, 0xeb, 0x33, 0x5e, 0x52, - 0xee, 0x99, 0xa1, 0x07, 0x06, 0xed, 0xf8, 0x48, 0x7a, 0xc6, 0xe5, 0xf5, 0x5e, 0x01, 0x3a, 0x41, - 0x2f, 0x18, 0x94, 0x8a, 0x3b, 0x0a, 0x52, 0x3f, 0xbf, 0x61, 0xa9, 0xc5, 0x4f, 0x70, 0xee, 0xb8, - 0x79, 0x23, 0xbb, 0x1a, 0x44, 0x7d, 0x91, 0xe6, 0x2a, 0xbc, 0xa1, 0x07, 0xbc, 0x65, 0x3b, 0x02, - 0xd9, 0x1d, 0xb2, 0xf2, 0x3a, 0xcb, 0x75, 0x79, 0xc6, 0x66, 0xd8, 0xc1, 0x71, 0x29, 0xdf, 0x04, - 0x60, 0xf4, 0xbf, 0x07, 0x7b, 0xb9, 0xc2, 0x11, 0x94, 0x6a, 0x28, 0xc2, 0xdd, 0xd8, 0x7b, 0x44, - 0x8f, 0x08, 0xe3, 0xc8, 0xd8, 0xf4, 0x81, 0xb0, 0x9f, 0x94, 0xcb, 0xc8, 0xc1, 0x3c, 0xc2, 0x6e, - 0x31, 0x26, 0xfc, 0x33, 0x16, 0x3b, 0xe0, 0xde, 0xa1, 0x16, 0x21, 0x9f, 0x89, 0xdd, 0x97, 0xa4, - 0x41, 0xf2, 0x9f, 0x19, 0xb1, 0xae, 0x82, 0xf7, 0x85, 0x9a, 0xb7, 0x8f, 0xb7, 0x52, 0x7a, 0x72, - 0xf1, 0x5e, 0x89, 0xe1, 0x8a, 0xcd, 0x40, 0xb5, 0x8e, 0xc3, 0xca, 0x42, 0x76, 0xa3, 0x6e, 0x1b, - 0xf4, 0x87, 0x35, 0x30, 0x58, 0x43, 0x04, 0xd9, 0x2c, 0x50, 0x54, 0x55, 0x47, 0x6f, 0x70, 0x9b, - 0x42, 0x1f, 0x91, 0xfc, 0xa1, 0xdb, 0x72, 0x53, 0x96, 0xc8, 0xe5, 0xcd, 0x0e, 0xcb, 0xa0, 0xfe, - 0x6b, 0x08, 0x77, 0x48, 0xb7, 0xad, 0x4a, 0x69, 0x7c, 0xdc, 0xd8, 0x04, 0x28, 0x35, 0x9b, 0x73, - 0x00, 0x00, 0x43, 0x49, 0x7f, 0xd7, 0xf8, 0x26, 0x95, 0x71, 0x08, 0xf4, 0xa3, 0x0f, 0xd9, 0xce, - 0xc3, 0xae, 0xba, 0x79, 0x97, 0x20, 0x84, 0xe9, 0x0e, 0xad, 0x01, 0xea, 0x33, 0x09, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x5b, 0xe5, 0xe9, 0x47, 0x82, - 0x09, 0x67, 0x4a, 0x96, 0xe6, 0x0f, 0x1f, 0x03, 0x7f, 0x61, 0x76, 0x54, 0x0f, 0xd0, 0x01, 0xfa, - 0x1d, 0x64, 0x69, 0x47, 0x70, 0xc5, 0x6a, 0x77, 0x09, 0xc4, 0x2c, 0x03, 0x5c, 0x4e, 0x0d, 0xec, - 0x72, 0x15, 0xe2, 0x68, 0x33, 0x93, 0x87, 0x30, 0xe5, 0xe5, 0x05, 0xaa, 0x62, 0x50, 0x4d, 0xa8, - 0x5b, 0xa5, 0x71, 0x06, 0xa4, 0x6b, 0x5a, 0x24, 0x04, 0xfc, 0x9d, 0x8e, 0x02, 0xba, 0x72, 0xa6, - 0xe8, 0xba, 0x53, 0xe8, 0xb9, 0x71, 0xad, 0x0c, 0x98, 0x23, 0x96, 0x8a, 0xef, 0x4d, 0x78, 0xce, - 0x8a, 0xf2, 0x55, 0xab, 0x43, 0xdf, 0xf8, 0x30, 0x03, 0xc9, 0x02, 0xfb, 0x8d, 0x02, 0x16, 0x34, - 0x5b, 0xf8, 0x31, 0x16, 0x4a, 0x03, 0x75, 0x8e, 0xae, 0xa5, 0xe8, 0xb6, 0x6f, 0xee, 0x2b, 0xe7, - 0x71, 0x0b, 0x8f, 0x19, 0x0e, 0xe8, 0x80, 0x24, 0x90, 0x32, 0xa2, 0x9e, 0xd6, 0x6e -}; - -// A simple block containing only one transaction (which is the channel-open transaction for the -// channel we'll create). This was originally created by printing additional data in a simple -// rust-lightning unit test. -const uint8_t channel_open_header[80] = { - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xa2, 0x47, 0xd2, 0xf8, 0xd4, 0xe0, 0x6a, 0x3f, 0xf9, 0x7a, 0x9a, 0x34, - 0xbb, 0xa9, 0x96, 0xde, 0x63, 0x84, 0x5a, 0xce, 0xcf, 0x98, 0xb8, 0xbb, 0x75, 0x4c, 0x4f, 0x7d, - 0xee, 0x4c, 0xa9, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; - -const uint8_t channel_open_tx[] = { - 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x9c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x20, 0xd1, 0xd9, 0x13, 0xa9, - 0x76, 0x09, 0x05, 0xa3, 0x4d, 0x13, 0x5b, 0x69, 0xaa, 0xe7, 0x79, 0x71, 0xb9, 0x75, 0xa1, 0xd0, - 0x77, 0xcb, 0xa2, 0xf6, 0x6a, 0x25, 0x37, 0x3a, 0xaf, 0xdc, 0x11, 0x09, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00 -}; - -// The first transaction in the block is header (80 bytes) + transaction count (1 byte) into the block data. -const uint8_t channel_open_txid[] = { - 0x02, 0xe0, 0x50, 0x05, 0x33, 0xd3, 0x29, 0x66, 0x0c, 0xb2, 0xcb, 0x1e, 0x7a, 0x4a, 0xc7, 0xc7, - 0x8b, 0x02, 0x46, 0x7e, 0x30, 0x2c, 0xe6, 0x19, 0xce, 0x43, 0x3e, 0xdf, 0x43, 0x65, 0xae, 0xf9, -}; - -// Two blocks built on top of channel_open_block: -const uint8_t header_1[80] = { - 0x01, 0x00, 0x00, 0x00, 0x65, 0x8e, 0xf1, 0x90, 0x88, 0xfa, 0x13, 0x9c, 0x6a, 0xea, 0xf7, 0xc1, - 0x5a, 0xdd, 0x52, 0x4d, 0x3c, 0x48, 0x03, 0xb3, 0x9b, 0x25, 0x4f, 0x02, 0x79, 0x05, 0x90, 0xe0, - 0xc4, 0x8d, 0xa0, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; -const uint8_t header_2[80] = { - 0x01, 0x00, 0x00, 0x00, 0xf2, 0x08, 0x87, 0x51, 0xcb, 0xb1, 0x1a, 0x51, 0x76, 0x01, 0x6c, 0x5d, - 0x76, 0x26, 0x54, 0x6f, 0xd9, 0xbd, 0xa6, 0xa5, 0xe9, 0x4b, 0x21, 0x6e, 0xda, 0xa3, 0x64, 0x23, - 0xcd, 0xf1, 0xe2, 0xe2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; - -const LDKThirtyTwoBytes payment_preimage_1 = { - .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 } -}; -const LDKThirtyTwoBytes payment_hash_1 = { - .data = { - 0xdc, 0xb1, 0xac, 0x4a, 0x5d, 0xe3, 0x70, 0xca, 0xd0, 0x91, 0xc1, 0x3f, 0x13, 0xae, 0xe2, 0xf9, - 0x36, 0xc2, 0x78, 0xfa, 0x05, 0xd2, 0x64, 0x65, 0x3c, 0x0c, 0x13, 0x21, 0x85, 0x2a, 0x35, 0xe8 - } -}; - -const LDKThirtyTwoBytes genesis_hash = { // We don't care particularly if this is "right" - .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 } -}; - -void print_log(const void *this_arg, const char *record) { - printf("%p - %s\n", this_arg, record); -} - -uint32_t get_fee(const void *this_arg, LDKConfirmationTarget target) { - if (target == LDKConfirmationTarget_Background) { - return 253; - } else { - return 507; - } - // Note that we don't call _free() on target, but that's OK, its unitary -} -// We use the same fee estimator globally: -const LDKFeeEstimator fee_est { - .this_arg = NULL, - .get_est_sat_per_1000_weight = get_fee, - .free = NULL, -}; - -static std::atomic_int num_txs_broadcasted(0); -void broadcast_tx(const void *this_arg, LDKTransaction tx) { - num_txs_broadcasted += 1; - //TODO - Transaction_free(tx); -} - -struct NodeMonitors { - std::mutex mut; - std::vector> mons; - LDKLogger* logger; - - void ConnectBlock(const uint8_t (*header)[80], uint32_t height, LDKCVec_C2Tuple_usizeTransactionZZ tx_data, LDKBroadcasterInterface broadcast, LDKFeeEstimator fee_est) { - std::unique_lock l(mut); - for (auto& mon : mons) { - LDK::CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ res = ChannelMonitor_block_connected(&mon.second, &header_2, tx_data, height, broadcast, fee_est, *logger); - } - } -}; - -LDKCResult_NoneChannelMonitorUpdateErrZ add_channel_monitor(const void *this_arg, LDKOutPoint funding_txo_arg, LDKChannelMonitor monitor_arg) { - // First bind the args to C++ objects so they auto-free - LDK::ChannelMonitor mon(std::move(monitor_arg)); - LDK::OutPoint funding_txo(std::move(funding_txo_arg)); - - NodeMonitors* arg = (NodeMonitors*) this_arg; - std::unique_lock l(arg->mut); - - arg->mons.push_back(std::make_pair(std::move(funding_txo), std::move(mon))); - return CResult_NoneChannelMonitorUpdateErrZ_ok(); -} -static std::atomic_int mons_updated(0); -LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_monitor(const void *this_arg, LDKOutPoint funding_txo_arg, LDKChannelMonitorUpdate monitor_arg) { - // First bind the args to C++ objects so they auto-free - LDK::ChannelMonitorUpdate update(std::move(monitor_arg)); - LDK::OutPoint funding_txo(std::move(funding_txo_arg)); - - NodeMonitors* arg = (NodeMonitors*) this_arg; - std::unique_lock l(arg->mut); - - bool updated = false; - for (auto& mon : arg->mons) { - if (OutPoint_get_index(&mon.first) == OutPoint_get_index(&funding_txo) && - !memcmp(OutPoint_get_txid(&mon.first), OutPoint_get_txid(&funding_txo), 32)) { - updated = true; - LDKBroadcasterInterface broadcaster = { - .broadcast_transaction = broadcast_tx, - }; - LDK::CResult_NoneMonitorUpdateErrorZ res = ChannelMonitor_update_monitor(&mon.second, &update, &broadcaster, &fee_est, arg->logger); - assert(res->result_ok); - } - } - assert(updated); - - mons_updated += 1; - return CResult_NoneChannelMonitorUpdateErrZ_ok(); -} -LDKCVec_MonitorEventZ monitors_pending_monitor_events(const void *this_arg) { - NodeMonitors* arg = (NodeMonitors*) this_arg; - std::unique_lock l(arg->mut); - - if (arg->mons.size() == 0) { - return LDKCVec_MonitorEventZ { - .data = NULL, - .datalen = 0, - }; - } else { - // We only ever actually have one channel per node, plus concatenating two - // Rust Vecs to each other from C++ will require a bit of effort. - assert(arg->mons.size() == 1); - return ChannelMonitor_get_and_clear_pending_monitor_events(&arg->mons[0].second); - } -} - -uintptr_t sock_send_data(void *this_arg, LDKu8slice data, bool resume_read) { - return write((int)((long)this_arg), data.data, data.datalen); -} -void sock_disconnect_socket(void *this_arg) { - close((int)((long)this_arg)); -} -bool sock_eq(const void *this_arg, const LDKSocketDescriptor *other_arg) { - return this_arg == other_arg->this_arg; -} -uint64_t sock_hash(const void *this_arg) { - return (uint64_t)this_arg; -} -void sock_read_data_thread(int rdfd, LDKSocketDescriptor *peer_descriptor, LDKPeerManager *pm) { - unsigned char buf[1024]; - LDKu8slice data; - data.data = buf; - ssize_t readlen = 0; - while ((readlen = read(rdfd, buf, 1024)) > 0) { - data.datalen = readlen; - LDK::CResult_boolPeerHandleErrorZ res = PeerManager_read_event(&*pm, peer_descriptor, data); - if (!res->result_ok) { - peer_descriptor->disconnect_socket(peer_descriptor->this_arg); - return; - } - PeerManager_process_events(pm); - } - PeerManager_socket_disconnected(&*pm, peer_descriptor); -} - -class PeersConnection { - int pipefds_1_to_2[2]; - int pipefds_2_to_1[2]; - std::thread t1, t2; - LDKSocketDescriptor sock1, sock2; - -public: - PeersConnection(LDK::ChannelManager& cm1, LDK::ChannelManager& cm2, LDK::PeerManager& net1, LDK::PeerManager& net2) { - assert(!pipe(pipefds_1_to_2)); - assert(!pipe(pipefds_2_to_1)); - - sock1 = LDKSocketDescriptor { - .this_arg = (void*)(long)pipefds_1_to_2[1], - .send_data = sock_send_data, - .disconnect_socket = sock_disconnect_socket, - .eq = sock_eq, - .hash = sock_hash, - .clone = NULL, - .free = NULL, - }; - - sock2 = LDKSocketDescriptor { - .this_arg = (void*)(long)pipefds_2_to_1[1], - .send_data = sock_send_data, - .disconnect_socket = sock_disconnect_socket, - .eq = sock_eq, - .hash = sock_hash, - .clone = NULL, - .free = NULL, - }; - - t1 = std::thread(&sock_read_data_thread, pipefds_2_to_1[0], &sock1, &net1); - t2 = std::thread(&sock_read_data_thread, pipefds_1_to_2[0], &sock2, &net2); - - // Note that we have to bind the result to a C++ class to make sure it gets free'd - LDK::CResult_CVec_u8ZPeerHandleErrorZ con_res = PeerManager_new_outbound_connection(&net1, ChannelManager_get_our_node_id(&cm2), sock1); - assert(con_res->result_ok); - LDK::CResult_NonePeerHandleErrorZ con_res2 = PeerManager_new_inbound_connection(&net2, sock2); - assert(con_res2->result_ok); - - auto writelen = write(pipefds_1_to_2[1], con_res->contents.result->data, con_res->contents.result->datalen); - assert(writelen > 0 && uint64_t(writelen) == con_res->contents.result->datalen); - - while (true) { - // Wait for the initial handshakes to complete... - LDK::CVec_PublicKeyZ peers_1 = PeerManager_get_peer_node_ids(&net1); - LDK::CVec_PublicKeyZ peers_2 = PeerManager_get_peer_node_ids(&net2); - if (peers_1->datalen == 1 && peers_2->datalen ==1) { break; } - std::this_thread::yield(); - } - } - - void stop() { - close(pipefds_1_to_2[0]); - close(pipefds_2_to_1[0]); - close(pipefds_1_to_2[1]); - close(pipefds_2_to_1[1]); - t1.join(); - t2.join(); - } -}; - -int main() { - LDKPublicKey null_pk; - memset(&null_pk, 0, sizeof(null_pk)); - - LDKThirtyTwoBytes random_bytes; - LDKThirtyTwoBytes chain_tip; - memset(&chain_tip, 0, sizeof(chain_tip)); // channel_open_header's prev_blockhash is all-0s - - LDKNetwork network = LDKNetwork_Testnet; - - // Trait implementations: - LDKBroadcasterInterface broadcast { - .this_arg = NULL, - .broadcast_transaction = broadcast_tx, - .free = NULL, - }; - - // Instantiate classes for the nodes that don't get reloaded on a ser-des reload - LDKLogger logger1 { - .this_arg = (void*)1, - .log = print_log, - .free = NULL, - }; - - NodeMonitors mons1; - mons1.logger = &logger1; - LDKWatch mon1 { - .this_arg = &mons1, - .watch_channel = add_channel_monitor, - .update_channel = update_channel_monitor, - .release_pending_monitor_events = monitors_pending_monitor_events, - .free = NULL, - }; - - LDK::NetGraphMsgHandler net_graph1 = NetGraphMsgHandler_new(genesis_hash, NULL, logger1); - LDKSecretKey node_secret1; - - LDKLogger logger2 { - .this_arg = (void*)2, - .log = print_log, - .free = NULL, - }; - - NodeMonitors mons2; - mons2.logger = &logger2; - LDKWatch mon2 { - .this_arg = &mons2, - .watch_channel = add_channel_monitor, - .update_channel = update_channel_monitor, - .release_pending_monitor_events = monitors_pending_monitor_events, - .free = NULL, - }; - - LDK::NetGraphMsgHandler net_graph2 = NetGraphMsgHandler_new(genesis_hash, NULL, logger2); - LDKSecretKey node_secret2; - - LDK::CVec_u8Z cm1_ser = LDKCVec_u8Z {}; // ChannelManager 1 serialization at the end of the ser-des scope - LDK::CVec_u8Z cm2_ser = LDKCVec_u8Z {}; // ChannelManager 2 serialization at the end of the ser-des scope - - { // Scope for the ser-des reload - // Instantiate classes for node 1: - uint8_t node_seed[32]; - memset(&node_seed, 0, 32); - LDK::KeysManager keys1 = KeysManager_new(&node_seed, 0, 0); - LDK::KeysInterface keys_source1 = KeysManager_as_KeysInterface(&keys1); - node_secret1 = keys_source1->get_node_secret(keys_source1->this_arg); - - LDK::ChannelManager cm1 = ChannelManager_new(fee_est, mon1, broadcast, logger1, KeysManager_as_KeysInterface(&keys1), UserConfig_default(), ChainParameters_new(network, chain_tip, 0)); - - LDK::CVec_ChannelDetailsZ channels = ChannelManager_list_channels(&cm1); - assert(channels->datalen == 0); - - LDK::MessageHandler msg_handler1 = MessageHandler_new(ChannelManager_as_ChannelMessageHandler(&cm1), NetGraphMsgHandler_as_RoutingMessageHandler(&net_graph1)); - - random_bytes = keys_source1->get_secure_random_bytes(keys_source1->this_arg); - LDK::PeerManager net1 = PeerManager_new(std::move(msg_handler1), node_secret1, &random_bytes.data, logger1); - - // Demo getting a channel key and check that its returning real pubkeys: - LDK::Sign chan_signer1 = keys_source1->get_channel_signer(keys_source1->this_arg, false, 42); - chan_signer1->set_pubkeys(&chan_signer1); // Make sure pubkeys is defined - LDKPublicKey payment_point = ChannelPublicKeys_get_payment_point(&chan_signer1->pubkeys); - assert(memcmp(&payment_point, &null_pk, sizeof(null_pk))); - - // Instantiate classes for node 2: - memset(&node_seed, 1, 32); - LDK::KeysManager keys2 = KeysManager_new(&node_seed, 0, 0); - LDK::KeysInterface keys_source2 = KeysManager_as_KeysInterface(&keys2); - node_secret2 = keys_source2->get_node_secret(keys_source2->this_arg); - - LDK::ChannelHandshakeConfig handshake_config2 = ChannelHandshakeConfig_default(); - ChannelHandshakeConfig_set_minimum_depth(&handshake_config2, 2); - LDK::UserConfig config2 = UserConfig_default(); - UserConfig_set_own_channel_config(&config2, std::move(handshake_config2)); - - LDK::ChannelManager cm2 = ChannelManager_new(fee_est, mon2, broadcast, logger2, KeysManager_as_KeysInterface(&keys2), std::move(config2), ChainParameters_new(network, chain_tip, 0)); - - LDK::CVec_ChannelDetailsZ channels2 = ChannelManager_list_channels(&cm2); - assert(channels2->datalen == 0); - - LDK::RoutingMessageHandler net_msgs2 = NetGraphMsgHandler_as_RoutingMessageHandler(&net_graph2); - LDK::CResult_ChannelAnnouncementDecodeErrorZ chan_ann = ChannelAnnouncement_read(LDKu8slice { .data = valid_node_announcement, .datalen = sizeof(valid_node_announcement) }); - assert(chan_ann->result_ok); - LDK::CResult_boolLightningErrorZ ann_res = net_msgs2->handle_channel_announcement(net_msgs2->this_arg, chan_ann->contents.result); - assert(ann_res->result_ok); - - LDK::MessageHandler msg_handler2 = MessageHandler_new(ChannelManager_as_ChannelMessageHandler(&cm2), std::move(net_msgs2)); - - random_bytes = keys_source2->get_secure_random_bytes(keys_source2->this_arg); - LDK::PeerManager net2 = PeerManager_new(std::move(msg_handler2), node_secret2, &random_bytes.data, logger2); - - // Open a connection! - PeersConnection conn(cm1, cm2, net1, net2); - - // Note that we have to bind the result to a C++ class to make sure it gets free'd - LDK::CResult_NoneAPIErrorZ res = ChannelManager_create_channel(&cm1, ChannelManager_get_our_node_id(&cm2), 40000, 1000, 42, UserConfig_default()); - assert(res->result_ok); - PeerManager_process_events(&net1); - - LDK::CVec_ChannelDetailsZ new_channels = ChannelManager_list_channels(&cm1); - assert(new_channels->datalen == 1); - LDKPublicKey chan_open_pk = ChannelDetails_get_remote_network_id(&new_channels->data[0]); - assert(!memcmp(chan_open_pk.compressed_form, ChannelManager_get_our_node_id(&cm2).compressed_form, 33)); - - while (true) { - LDK::CVec_ChannelDetailsZ new_channels_2 = ChannelManager_list_channels(&cm2); - if (new_channels_2->datalen == 1) { - // Sample getting our counterparty's init features (which used to be hard to do without a memory leak): - const LDK::InitFeatures init_feats = ChannelDetails_get_counterparty_features(&new_channels_2->data[0]); - assert(init_feats->inner != NULL); - break; - } - std::this_thread::yield(); - } - - LDKEventsProvider ev1 = ChannelManager_as_EventsProvider(&cm1); - while (true) { - LDK::CVec_EventZ events = ev1.get_and_clear_pending_events(ev1.this_arg); - if (events->datalen == 1) { - assert(events->data[0].tag == LDKEvent_FundingGenerationReady); - assert(events->data[0].funding_generation_ready.user_channel_id == 42); - assert(events->data[0].funding_generation_ready.channel_value_satoshis == 40000); - assert(events->data[0].funding_generation_ready.output_script.datalen == 34); - assert(!memcmp(events->data[0].funding_generation_ready.output_script.data, channel_open_tx + 58, 34)); - LDKThirtyTwoBytes txid; - for (int i = 0; i < 32; i++) { txid.data[i] = channel_open_txid[31-i]; } - LDK::OutPoint outp = OutPoint_new(txid, 0); - ChannelManager_funding_transaction_generated(&cm1, &events->data[0].funding_generation_ready.temporary_channel_id.data, std::move(outp)); - break; - } - std::this_thread::yield(); - } - - // We observe when the funding signed messages have been exchanged by - // waiting for two monitors to be registered. - PeerManager_process_events(&net1); - while (true) { - LDK::CVec_EventZ events = ev1.get_and_clear_pending_events(ev1.this_arg); - if (events->datalen == 1) { - assert(events->data[0].tag == LDKEvent_FundingBroadcastSafe); - assert(events->data[0].funding_broadcast_safe.user_channel_id == 42); - break; - } - std::this_thread::yield(); - } - - 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 }); - ChannelManager_block_connected(&cm1, &channel_open_header, txdata, 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 }); - ChannelManager_block_connected(&cm2, &channel_open_header, txdata, 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 }); - mons1.ConnectBlock(&channel_open_header, 1, txdata, broadcast, fee_est); - - 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 }); - mons2.ConnectBlock(&channel_open_header, 1, txdata, broadcast, fee_est); - - ChannelManager_block_connected(&cm1, &header_1, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, 2); - ChannelManager_block_connected(&cm2, &header_1, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, 2); - mons1.ConnectBlock(&header_1, 2, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, broadcast, fee_est); - mons2.ConnectBlock(&header_1, 2, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, broadcast, fee_est); - - ChannelManager_block_connected(&cm1, &header_2, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, 3); - ChannelManager_block_connected(&cm2, &header_2, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, 3); - mons1.ConnectBlock(&header_2, 3, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, broadcast, fee_est); - mons2.ConnectBlock(&header_2, 3, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, broadcast, fee_est); - - PeerManager_process_events(&net1); - PeerManager_process_events(&net2); - - // Now send funds from 1 to 2! - while (true) { - LDK::CVec_ChannelDetailsZ outbound_channels = ChannelManager_list_usable_channels(&cm1); - if (outbound_channels->datalen == 1) { - const LDKChannelDetails *channel = &outbound_channels->data[0]; - // Note that the channel ID is the same as the channel txid reversed as the output index is 0 - uint8_t expected_chan_id[32]; - for (int i = 0; i < 32; i++) { expected_chan_id[i] = channel_open_txid[31-i]; } - assert(!memcmp(ChannelDetails_get_channel_id(channel), expected_chan_id, 32)); - assert(!memcmp(ChannelDetails_get_remote_network_id(channel).compressed_form, - ChannelManager_get_our_node_id(&cm2).compressed_form, 33)); - assert(ChannelDetails_get_channel_value_satoshis(channel) == 40000); - // We opened the channel with 1000 push_msat: - assert(ChannelDetails_get_outbound_capacity_msat(channel) == 40000*1000 - 1000); - assert(ChannelDetails_get_inbound_capacity_msat(channel) == 1000); - assert(ChannelDetails_get_is_live(channel)); - break; - } - std::this_thread::yield(); - } - - LDK::CVec_ChannelDetailsZ outbound_channels = ChannelManager_list_usable_channels(&cm1); - LDKThirtyTwoBytes payment_secret; - memset(payment_secret.data, 0x42, 32); - { - LDK::LockedNetworkGraph graph_2_locked = NetGraphMsgHandler_read_locked_graph(&net_graph2); - LDK::NetworkGraph graph_2_ref = LockedNetworkGraph_graph(&graph_2_locked); - LDK::CResult_RouteLightningErrorZ route = get_route(ChannelManager_get_our_node_id(&cm1), &graph_2_ref, ChannelManager_get_our_node_id(&cm2), &outbound_channels, LDKCVec_RouteHintZ { - .data = NULL, .datalen = 0 - }, 5000, 10, logger1); - assert(route->result_ok); - LDK::CResult_NonePaymentSendFailureZ send_res = ChannelManager_send_payment(&cm1, route->contents.result, payment_hash_1, payment_secret); - assert(send_res->result_ok); - } - - mons_updated = 0; - PeerManager_process_events(&net1); - while (mons_updated != 4) { - std::this_thread::yield(); - } - - // Check that we received the payment! - LDKEventsProvider ev2 = ChannelManager_as_EventsProvider(&cm2); - while (true) { - LDK::CVec_EventZ events = ev2.get_and_clear_pending_events(ev2.this_arg); - if (events->datalen == 1) { - assert(events->data[0].tag == LDKEvent_PendingHTLCsForwardable); - break; - } - std::this_thread::yield(); - } - ChannelManager_process_pending_htlc_forwards(&cm2); - PeerManager_process_events(&net2); - - mons_updated = 0; - { - LDK::CVec_EventZ events = ev2.get_and_clear_pending_events(ev2.this_arg); - assert(events->datalen == 1); - assert(events->data[0].tag == LDKEvent_PaymentReceived); - assert(!memcmp(events->data[0].payment_received.payment_hash.data, payment_hash_1.data, 32)); - assert(!memcmp(events->data[0].payment_received.payment_secret.data, payment_secret.data, 32)); - assert(events->data[0].payment_received.amt == 5000); - assert(ChannelManager_claim_funds(&cm2, payment_preimage_1, payment_secret, 5000)); - } - PeerManager_process_events(&net2); - // Wait until we've passed through a full set of monitor updates (ie new preimage + CS/RAA messages) - while (mons_updated != 5) { - std::this_thread::yield(); - } - { - LDK::CVec_EventZ events = ev1.get_and_clear_pending_events(ev1.this_arg); - assert(events->datalen == 1); - assert(events->data[0].tag == LDKEvent_PaymentSent); - assert(!memcmp(events->data[0].payment_sent.payment_preimage.data, payment_preimage_1.data, 32)); - } - - conn.stop(); - - cm1_ser = ChannelManager_write(&cm1); - cm2_ser = ChannelManager_write(&cm2); - } - - LDK::CVec_ChannelMonitorZ mons_list1 = LDKCVec_ChannelMonitorZ { .data = (LDKChannelMonitor*)malloc(sizeof(LDKChannelMonitor)), .datalen = 1 }; - assert(mons1.mons.size() == 1); - mons_list1->data[0] = *& std::get<1>(mons1.mons[0]); // Note that we need a reference, thus need a raw clone here, which *& does. - mons_list1->data[0].is_owned = false; // XXX: God this sucks - uint8_t node_seed[32]; - memset(&node_seed, 0, 32); - LDK::KeysManager keys1 = KeysManager_new(&node_seed, 1, 0); - LDK::KeysInterface keys_source1 = KeysManager_as_KeysInterface(&keys1); - - LDK::ChannelManagerReadArgs cm1_args = ChannelManagerReadArgs_new(KeysManager_as_KeysInterface(&keys1), fee_est, mon1, broadcast, logger1, UserConfig_default(), std::move(mons_list1)); - LDK::CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ cm1_read = - C2Tuple_BlockHashChannelManagerZ_read(LDKu8slice { .data = cm1_ser->data, .datalen = cm1_ser -> datalen}, std::move(cm1_args)); - assert(cm1_read->result_ok); - LDK::ChannelManager cm1(std::move(cm1_read->contents.result->b)); - - LDK::CVec_ChannelMonitorZ mons_list2 = LDKCVec_ChannelMonitorZ { .data = (LDKChannelMonitor*)malloc(sizeof(LDKChannelMonitor)), .datalen = 1 }; - assert(mons2.mons.size() == 1); - mons_list2->data[0] = *& std::get<1>(mons2.mons[0]); // Note that we need a reference, thus need a raw clone here, which *& does. - mons_list2->data[0].is_owned = false; // XXX: God this sucks - memset(&node_seed, 1, 32); - LDK::KeysManager keys2 = KeysManager_new(&node_seed, 1, 0); - - LDK::ChannelManagerReadArgs cm2_args = ChannelManagerReadArgs_new(KeysManager_as_KeysInterface(&keys2), fee_est, mon2, broadcast, logger2, UserConfig_default(), std::move(mons_list2)); - LDK::CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ cm2_read = - C2Tuple_BlockHashChannelManagerZ_read(LDKu8slice { .data = cm2_ser->data, .datalen = cm2_ser -> datalen}, std::move(cm2_args)); - assert(cm2_read->result_ok); - LDK::ChannelManager cm2(std::move(cm2_read->contents.result->b)); - - // Attempt to close the channel... - uint8_t chan_id[32]; - for (int i = 0; i < 32; i++) { chan_id[i] = channel_open_txid[31-i]; } - LDK::CResult_NoneAPIErrorZ close_res = ChannelManager_close_channel(&cm1, &chan_id); - assert(!close_res->result_ok); // Note that we can't close while disconnected! - - // Open a connection! - LDK::MessageHandler msg_handler1 = MessageHandler_new(ChannelManager_as_ChannelMessageHandler(&cm1), NetGraphMsgHandler_as_RoutingMessageHandler(&net_graph1)); - random_bytes = keys_source1->get_secure_random_bytes(keys_source1->this_arg); - LDK::PeerManager net1 = PeerManager_new(std::move(msg_handler1), node_secret1, &random_bytes.data, logger1); - - LDK::MessageHandler msg_handler2 = MessageHandler_new(ChannelManager_as_ChannelMessageHandler(&cm2), NetGraphMsgHandler_as_RoutingMessageHandler(&net_graph2)); - random_bytes = keys_source1->get_secure_random_bytes(keys_source1->this_arg); - LDK::PeerManager net2 = PeerManager_new(std::move(msg_handler2), node_secret2, &random_bytes.data, logger2); - - PeersConnection conn(cm1, cm2, net1, net2); - - while (true) { - // Wait for the channels to be considered up once the reestablish messages are processed - LDK::CVec_ChannelDetailsZ outbound_channels = ChannelManager_list_usable_channels(&cm1); - if (outbound_channels->datalen == 1) { - break; - } - } - - // Actually close the channel - close_res = ChannelManager_close_channel(&cm1, &chan_id); - assert(close_res->result_ok); - PeerManager_process_events(&net1); - num_txs_broadcasted = 0; - while (num_txs_broadcasted != 2) { - std::this_thread::yield(); - } - LDK::CVec_ChannelDetailsZ chans_after_close1 = ChannelManager_list_channels(&cm1); - assert(chans_after_close1->datalen == 0); - LDK::CVec_ChannelDetailsZ chans_after_close2 = ChannelManager_list_channels(&cm2); - assert(chans_after_close2->datalen == 0); - - conn.stop(); - - // Few extra random tests: - LDKSecretKey sk; - memset(&sk, 42, 32); - LDKThirtyTwoBytes kdiv_params; - memset(&kdiv_params, 43, 32); - LDK::InMemorySigner signer = InMemorySigner_new(sk, sk, sk, sk, sk, random_bytes, 42, kdiv_params); -} diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h deleted file mode 100644 index eb6f45b71..000000000 --- a/lightning-c-bindings/include/lightning.h +++ /dev/null @@ -1,9348 +0,0 @@ -/* Text to put at the beginning of the generated file. Probably a license. */ - -/* Generated with cbindgen:0.16.0 */ - -/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ - -#include -#include -#include - - -/** - * An error when accessing the chain via [`Access`]. - * - * [`Access`]: trait.Access.html - */ -typedef enum LDKAccessError { - /** - * The requested chain is unknown. - */ - LDKAccessError_UnknownChain, - /** - * The requested transaction doesn't exist or hasn't confirmed. - */ - LDKAccessError_UnknownTx, - /** - * Must be last for serialization purposes - */ - LDKAccessError_Sentinel, -} LDKAccessError; - -/** - * An error enum representing a failure to persist a channel monitor update. - */ -typedef enum LDKChannelMonitorUpdateErr { - /** - * Used to indicate a temporary failure (eg connection to a watchtower or remote backup of - * our state failed, but is expected to succeed at some point in the future). - * - * Such a failure will \"freeze\" a channel, preventing us from revoking old states or - * submitting new commitment transactions to the counterparty. Once the update(s) which failed - * have been successfully applied, ChannelManager::channel_monitor_updated can be used to - * restore the channel to an operational state. - * - * Note that a given ChannelManager will *never* re-generate a given ChannelMonitorUpdate. If - * you return a TemporaryFailure you must ensure that it is written to disk safely before - * writing out the latest ChannelManager state. - * - * Even when a channel has been \"frozen\" updates to the ChannelMonitor can continue to occur - * (eg if an inbound HTLC which we forwarded was claimed upstream resulting in us attempting - * to claim it on this channel) and those updates must be applied wherever they can be. At - * least one such updated ChannelMonitor must be persisted otherwise PermanentFailure should - * be returned to get things on-chain ASAP using only the in-memory copy. Obviously updates to - * the channel which would invalidate previous ChannelMonitors are not made when a channel has - * been \"frozen\". - * - * Note that even if updates made after TemporaryFailure succeed you must still call - * channel_monitor_updated to ensure you have the latest monitor and re-enable normal channel - * operation. - * - * Note that the update being processed here will not be replayed for you when you call - * ChannelManager::channel_monitor_updated, so you must store the update itself along - * with the persisted ChannelMonitor on your own local disk prior to returning a - * TemporaryFailure. You may, of course, employ a journaling approach, storing only the - * ChannelMonitorUpdate on disk without updating the monitor itself, replaying the journal at - * reload-time. - * - * For deployments where a copy of ChannelMonitors and other local state are backed up in a - * remote location (with local copies persisted immediately), it is anticipated that all - * updates will return TemporaryFailure until the remote copies could be updated. - */ - LDKChannelMonitorUpdateErr_TemporaryFailure, - /** - * Used to indicate no further channel monitor updates will be allowed (eg we've moved on to a - * different watchtower and cannot update with all watchtowers that were previously informed - * of this channel). - * - * At reception of this error, ChannelManager will force-close the channel and return at - * least a final ChannelMonitorUpdate::ChannelForceClosed which must be delivered to at - * least one ChannelMonitor copy. Revocation secret MUST NOT be released and offchain channel - * update must be rejected. - * - * This failure may also signal a failure to update the local persisted copy of one of - * the channel monitor instance. - * - * Note that even when you fail a holder commitment transaction update, you must store the - * update to ensure you can claim from it in case of a duplicate copy of this ChannelMonitor - * broadcasts it (e.g distributed channel-monitor deployment) - * - * In case of distributed watchtowers deployment, the new version must be written to disk, as - * state may have been stored but rejected due to a block forcing a commitment broadcast. This - * storage is used to claim outputs of rejected state confirmed onchain by another watchtower, - * lagging behind on block processing. - */ - LDKChannelMonitorUpdateErr_PermanentFailure, - /** - * Must be last for serialization purposes - */ - LDKChannelMonitorUpdateErr_Sentinel, -} LDKChannelMonitorUpdateErr; - -/** - * An enum that represents the speed at which we want a transaction to confirm used for feerate - * estimation. - */ -typedef enum LDKConfirmationTarget { - /** - * We are happy with this transaction confirming slowly when feerate drops some. - */ - LDKConfirmationTarget_Background, - /** - * We'd like this transaction to confirm without major delay, but 12-18 blocks is fine. - */ - LDKConfirmationTarget_Normal, - /** - * We'd like this transaction to confirm in the next few blocks. - */ - LDKConfirmationTarget_HighPriority, - /** - * Must be last for serialization purposes - */ - LDKConfirmationTarget_Sentinel, -} LDKConfirmationTarget; - -/** - * An enum representing the available verbosity levels of the logger. - */ -typedef enum LDKLevel { - /** - *Designates logger being silent - */ - LDKLevel_Off, - /** - * Designates very serious errors - */ - LDKLevel_Error, - /** - * Designates hazardous situations - */ - LDKLevel_Warn, - /** - * Designates useful information - */ - LDKLevel_Info, - /** - * Designates lower priority information - */ - LDKLevel_Debug, - /** - * Designates very low priority, often extremely verbose, information - */ - LDKLevel_Trace, - /** - * Must be last for serialization purposes - */ - LDKLevel_Sentinel, -} LDKLevel; - -typedef enum LDKNetwork { - LDKNetwork_Bitcoin, - LDKNetwork_Testnet, - LDKNetwork_Regtest, - LDKNetwork_Signet, - /** - * Must be last for serialization purposes - */ - LDKNetwork_Sentinel, -} LDKNetwork; - -typedef enum LDKSecp256k1Error { - LDKSecp256k1Error_IncorrectSignature, - LDKSecp256k1Error_InvalidMessage, - LDKSecp256k1Error_InvalidPublicKey, - LDKSecp256k1Error_InvalidSignature, - LDKSecp256k1Error_InvalidSecretKey, - LDKSecp256k1Error_InvalidRecoveryId, - LDKSecp256k1Error_InvalidTweak, - LDKSecp256k1Error_TweakCheckFailed, - LDKSecp256k1Error_NotEnoughMemory, - /** - * Must be last for serialization purposes - */ - LDKSecp256k1Error_Sentinel, -} LDKSecp256k1Error; - -/** - * A serialized transaction, in (pointer, length) form. - * - * This type optionally owns its own memory, and thus the semantics around access change based on - * the `data_is_owned` flag. If `data_is_owned` is set, you must call `Transaction_free` to free - * the underlying buffer before the object goes out of scope. If `data_is_owned` is not set, any - * access to the buffer after the scope in which the object was provided to you is invalid. eg, - * access after you return from the call in which a `!data_is_owned` `Transaction` is provided to - * you would be invalid. - * - * Note that, while it may change in the future, because transactions on the Rust side are stored - * in a deserialized form, all `Transaction`s generated on the Rust side will have `data_is_owned` - * set. Similarly, while it may change in the future, all `Transaction`s you pass to Rust may have - * `data_is_owned` either set or unset at your discretion. - */ -typedef struct LDKTransaction { - /** - * This is non-const for your convenience, an object passed to Rust is never written to. - */ - uint8_t *data; - uintptr_t datalen; - bool data_is_owned; -} LDKTransaction; - -typedef struct LDKCVec_u8Z { - uint8_t *data; - uintptr_t datalen; -} LDKCVec_u8Z; - -/** - * A transaction output including a scriptPubKey and value. - * This type *does* own its own memory, so must be free'd appropriately. - */ -typedef struct LDKTxOut { - struct LDKCVec_u8Z script_pubkey; - uint64_t value; -} LDKTxOut; - -typedef struct LDKSecretKey { - uint8_t bytes[32]; -} LDKSecretKey; - -typedef union LDKCResult_SecretKeyErrorZPtr { - struct LDKSecretKey *result; - enum LDKSecp256k1Error *err; -} LDKCResult_SecretKeyErrorZPtr; - -typedef struct LDKCResult_SecretKeyErrorZ { - union LDKCResult_SecretKeyErrorZPtr contents; - bool result_ok; -} LDKCResult_SecretKeyErrorZ; - -typedef struct LDKPublicKey { - uint8_t compressed_form[33]; -} LDKPublicKey; - -typedef union LDKCResult_PublicKeyErrorZPtr { - struct LDKPublicKey *result; - enum LDKSecp256k1Error *err; -} LDKCResult_PublicKeyErrorZPtr; - -typedef struct LDKCResult_PublicKeyErrorZ { - union LDKCResult_PublicKeyErrorZPtr contents; - bool result_ok; -} LDKCResult_PublicKeyErrorZ; - - - -/** - * The set of public keys which are used in the creation of one commitment transaction. - * These are derived from the channel base keys and per-commitment data. - * - * A broadcaster key is provided from potential broadcaster of the computed transaction. - * A countersignatory key is coming from a protocol participant unable to broadcast the - * transaction. - * - * These keys are assumed to be good, either because the code derived them from - * channel basepoints via the new function, or they were obtained via - * CommitmentTransaction.trust().keys() because we trusted the source of the - * pre-calculated keys. - */ -typedef struct MUST_USE_STRUCT LDKTxCreationKeys { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeTxCreationKeys *inner; - bool is_owned; -} LDKTxCreationKeys; - - - -/** - * An error in decoding a message or struct. - */ -typedef struct MUST_USE_STRUCT LDKDecodeError { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeDecodeError *inner; - bool is_owned; -} LDKDecodeError; - -typedef union LDKCResult_TxCreationKeysDecodeErrorZPtr { - struct LDKTxCreationKeys *result; - struct LDKDecodeError *err; -} LDKCResult_TxCreationKeysDecodeErrorZPtr; - -typedef struct LDKCResult_TxCreationKeysDecodeErrorZ { - union LDKCResult_TxCreationKeysDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_TxCreationKeysDecodeErrorZ; - - - -/** - * One counterparty's public keys which do not change over the life of a channel. - */ -typedef struct MUST_USE_STRUCT LDKChannelPublicKeys { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelPublicKeys *inner; - bool is_owned; -} LDKChannelPublicKeys; - -typedef union LDKCResult_ChannelPublicKeysDecodeErrorZPtr { - struct LDKChannelPublicKeys *result; - struct LDKDecodeError *err; -} LDKCResult_ChannelPublicKeysDecodeErrorZPtr; - -typedef struct LDKCResult_ChannelPublicKeysDecodeErrorZ { - union LDKCResult_ChannelPublicKeysDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ChannelPublicKeysDecodeErrorZ; - -typedef union LDKCResult_TxCreationKeysErrorZPtr { - struct LDKTxCreationKeys *result; - enum LDKSecp256k1Error *err; -} LDKCResult_TxCreationKeysErrorZPtr; - -typedef struct LDKCResult_TxCreationKeysErrorZ { - union LDKCResult_TxCreationKeysErrorZPtr contents; - bool result_ok; -} LDKCResult_TxCreationKeysErrorZ; - - - -/** - * Information about an HTLC as it appears in a commitment transaction - */ -typedef struct MUST_USE_STRUCT LDKHTLCOutputInCommitment { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeHTLCOutputInCommitment *inner; - bool is_owned; -} LDKHTLCOutputInCommitment; - -typedef union LDKCResult_HTLCOutputInCommitmentDecodeErrorZPtr { - struct LDKHTLCOutputInCommitment *result; - struct LDKDecodeError *err; -} LDKCResult_HTLCOutputInCommitmentDecodeErrorZPtr; - -typedef struct LDKCResult_HTLCOutputInCommitmentDecodeErrorZ { - union LDKCResult_HTLCOutputInCommitmentDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_HTLCOutputInCommitmentDecodeErrorZ; - - - -/** - * Late-bound per-channel counterparty data used to build transactions. - */ -typedef struct MUST_USE_STRUCT LDKCounterpartyChannelTransactionParameters { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeCounterpartyChannelTransactionParameters *inner; - bool is_owned; -} LDKCounterpartyChannelTransactionParameters; - -typedef union LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZPtr { - struct LDKCounterpartyChannelTransactionParameters *result; - struct LDKDecodeError *err; -} LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZPtr; - -typedef struct LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ { - union LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ; - - - -/** - * Per-channel data used to build transactions in conjunction with the per-commitment data (CommitmentTransaction). - * The fields are organized by holder/counterparty. - * - * Normally, this is converted to the broadcaster/countersignatory-organized DirectedChannelTransactionParameters - * before use, via the as_holder_broadcastable and as_counterparty_broadcastable functions. - */ -typedef struct MUST_USE_STRUCT LDKChannelTransactionParameters { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelTransactionParameters *inner; - bool is_owned; -} LDKChannelTransactionParameters; - -typedef union LDKCResult_ChannelTransactionParametersDecodeErrorZPtr { - struct LDKChannelTransactionParameters *result; - struct LDKDecodeError *err; -} LDKCResult_ChannelTransactionParametersDecodeErrorZPtr; - -typedef struct LDKCResult_ChannelTransactionParametersDecodeErrorZ { - union LDKCResult_ChannelTransactionParametersDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ChannelTransactionParametersDecodeErrorZ; - -typedef struct LDKSignature { - uint8_t compact_form[64]; -} LDKSignature; - -typedef struct LDKCVec_SignatureZ { - struct LDKSignature *data; - uintptr_t datalen; -} LDKCVec_SignatureZ; - - - -/** - * Information needed to build and sign a holder's commitment transaction. - * - * The transaction is only signed once we are ready to broadcast. - */ -typedef struct MUST_USE_STRUCT LDKHolderCommitmentTransaction { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeHolderCommitmentTransaction *inner; - bool is_owned; -} LDKHolderCommitmentTransaction; - -typedef union LDKCResult_HolderCommitmentTransactionDecodeErrorZPtr { - struct LDKHolderCommitmentTransaction *result; - struct LDKDecodeError *err; -} LDKCResult_HolderCommitmentTransactionDecodeErrorZPtr; - -typedef struct LDKCResult_HolderCommitmentTransactionDecodeErrorZ { - union LDKCResult_HolderCommitmentTransactionDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_HolderCommitmentTransactionDecodeErrorZ; - - - -/** - * A pre-built Bitcoin commitment transaction and its txid. - */ -typedef struct MUST_USE_STRUCT LDKBuiltCommitmentTransaction { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeBuiltCommitmentTransaction *inner; - bool is_owned; -} LDKBuiltCommitmentTransaction; - -typedef union LDKCResult_BuiltCommitmentTransactionDecodeErrorZPtr { - struct LDKBuiltCommitmentTransaction *result; - struct LDKDecodeError *err; -} LDKCResult_BuiltCommitmentTransactionDecodeErrorZPtr; - -typedef struct LDKCResult_BuiltCommitmentTransactionDecodeErrorZ { - union LDKCResult_BuiltCommitmentTransactionDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_BuiltCommitmentTransactionDecodeErrorZ; - - - -/** - * This class tracks the per-transaction information needed to build a commitment transaction and to - * actually build it and sign. It is used for holder transactions that we sign only when needed - * and for transactions we sign for the counterparty. - * - * This class can be used inside a signer implementation to generate a signature given the relevant - * secret key. - */ -typedef struct MUST_USE_STRUCT LDKCommitmentTransaction { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeCommitmentTransaction *inner; - bool is_owned; -} LDKCommitmentTransaction; - -typedef union LDKCResult_CommitmentTransactionDecodeErrorZPtr { - struct LDKCommitmentTransaction *result; - struct LDKDecodeError *err; -} LDKCResult_CommitmentTransactionDecodeErrorZPtr; - -typedef struct LDKCResult_CommitmentTransactionDecodeErrorZ { - union LDKCResult_CommitmentTransactionDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_CommitmentTransactionDecodeErrorZ; - - - -/** - * A wrapper on CommitmentTransaction indicating that the derived fields (the built bitcoin - * transaction and the transaction creation keys) are trusted. - * - * See trust() and verify() functions on CommitmentTransaction. - * - * This structure implements Deref. - */ -typedef struct MUST_USE_STRUCT LDKTrustedCommitmentTransaction { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeTrustedCommitmentTransaction *inner; - bool is_owned; -} LDKTrustedCommitmentTransaction; - -typedef union LDKCResult_TrustedCommitmentTransactionNoneZPtr { - struct LDKTrustedCommitmentTransaction *result; - /** - * Note that this value is always NULL, as there are no contents in the Err variant - */ - void *err; -} LDKCResult_TrustedCommitmentTransactionNoneZPtr; - -typedef struct LDKCResult_TrustedCommitmentTransactionNoneZ { - union LDKCResult_TrustedCommitmentTransactionNoneZPtr contents; - bool result_ok; -} LDKCResult_TrustedCommitmentTransactionNoneZ; - -typedef union LDKCResult_CVec_SignatureZNoneZPtr { - struct LDKCVec_SignatureZ *result; - /** - * Note that this value is always NULL, as there are no contents in the Err variant - */ - void *err; -} LDKCResult_CVec_SignatureZNoneZPtr; - -typedef struct LDKCResult_CVec_SignatureZNoneZ { - union LDKCResult_CVec_SignatureZNoneZPtr contents; - bool result_ok; -} LDKCResult_CVec_SignatureZNoneZ; - - - -/** - * An accept_channel message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKAcceptChannel { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeAcceptChannel *inner; - bool is_owned; -} LDKAcceptChannel; - - - -/** - * An open_channel message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKOpenChannel { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeOpenChannel *inner; - bool is_owned; -} LDKOpenChannel; - - - -/** - * A funding_created message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKFundingCreated { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeFundingCreated *inner; - bool is_owned; -} LDKFundingCreated; - - - -/** - * A funding_signed message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKFundingSigned { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeFundingSigned *inner; - bool is_owned; -} LDKFundingSigned; - - - -/** - * A funding_locked message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKFundingLocked { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeFundingLocked *inner; - bool is_owned; -} LDKFundingLocked; - - - -/** - * An announcement_signatures message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKAnnouncementSignatures { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeAnnouncementSignatures *inner; - bool is_owned; -} LDKAnnouncementSignatures; - - - -/** - * Struct used to return values from revoke_and_ack messages, containing a bunch of commitment - * transaction updates if they were pending. - */ -typedef struct MUST_USE_STRUCT LDKCommitmentUpdate { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeCommitmentUpdate *inner; - bool is_owned; -} LDKCommitmentUpdate; - - - -/** - * A revoke_and_ack message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKRevokeAndACK { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeRevokeAndACK *inner; - bool is_owned; -} LDKRevokeAndACK; - - - -/** - * A closing_signed message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKClosingSigned { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeClosingSigned *inner; - bool is_owned; -} LDKClosingSigned; - - - -/** - * A shutdown message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKShutdown { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeShutdown *inner; - bool is_owned; -} LDKShutdown; - - - -/** - * A channel_reestablish message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKChannelReestablish { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelReestablish *inner; - bool is_owned; -} LDKChannelReestablish; - - - -/** - * A channel_announcement message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKChannelAnnouncement { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelAnnouncement *inner; - bool is_owned; -} LDKChannelAnnouncement; - - - -/** - * A channel_update message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKChannelUpdate { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelUpdate *inner; - bool is_owned; -} LDKChannelUpdate; - - - -/** - * A node_announcement message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKNodeAnnouncement { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeNodeAnnouncement *inner; - bool is_owned; -} LDKNodeAnnouncement; - - - -/** - * An error message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKErrorMessage { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeErrorMessage *inner; - bool is_owned; -} LDKErrorMessage; - -/** - * Used to put an error message in a LightningError - */ -typedef enum LDKErrorAction_Tag { - /** - * The peer took some action which made us think they were useless. Disconnect them. - */ - LDKErrorAction_DisconnectPeer, - /** - * The peer did something harmless that we weren't able to process, just log and ignore - */ - LDKErrorAction_IgnoreError, - /** - * The peer did something incorrect. Tell them. - */ - LDKErrorAction_SendErrorMessage, - /** - * Must be last for serialization purposes - */ - LDKErrorAction_Sentinel, -} LDKErrorAction_Tag; - -typedef struct LDKErrorAction_LDKDisconnectPeer_Body { - struct LDKErrorMessage msg; -} LDKErrorAction_LDKDisconnectPeer_Body; - -typedef struct LDKErrorAction_LDKSendErrorMessage_Body { - struct LDKErrorMessage msg; -} LDKErrorAction_LDKSendErrorMessage_Body; - -typedef struct MUST_USE_STRUCT LDKErrorAction { - LDKErrorAction_Tag tag; - union { - LDKErrorAction_LDKDisconnectPeer_Body disconnect_peer; - LDKErrorAction_LDKSendErrorMessage_Body send_error_message; - }; -} LDKErrorAction; - -/** - * The information we received from a peer along the route of a payment we originated. This is - * returned by ChannelMessageHandler::handle_update_fail_htlc to be passed into - * RoutingMessageHandler::handle_htlc_fail_channel_update to update our network map. - */ -typedef enum LDKHTLCFailChannelUpdate_Tag { - /** - * We received an error which included a full ChannelUpdate message. - */ - LDKHTLCFailChannelUpdate_ChannelUpdateMessage, - /** - * We received an error which indicated only that a channel has been closed - */ - LDKHTLCFailChannelUpdate_ChannelClosed, - /** - * We received an error which indicated only that a node has failed - */ - LDKHTLCFailChannelUpdate_NodeFailure, - /** - * Must be last for serialization purposes - */ - LDKHTLCFailChannelUpdate_Sentinel, -} LDKHTLCFailChannelUpdate_Tag; - -typedef struct LDKHTLCFailChannelUpdate_LDKChannelUpdateMessage_Body { - struct LDKChannelUpdate msg; -} LDKHTLCFailChannelUpdate_LDKChannelUpdateMessage_Body; - -typedef struct LDKHTLCFailChannelUpdate_LDKChannelClosed_Body { - uint64_t short_channel_id; - bool is_permanent; -} LDKHTLCFailChannelUpdate_LDKChannelClosed_Body; - -typedef struct LDKHTLCFailChannelUpdate_LDKNodeFailure_Body { - struct LDKPublicKey node_id; - bool is_permanent; -} LDKHTLCFailChannelUpdate_LDKNodeFailure_Body; - -typedef struct MUST_USE_STRUCT LDKHTLCFailChannelUpdate { - LDKHTLCFailChannelUpdate_Tag tag; - union { - LDKHTLCFailChannelUpdate_LDKChannelUpdateMessage_Body channel_update_message; - LDKHTLCFailChannelUpdate_LDKChannelClosed_Body channel_closed; - LDKHTLCFailChannelUpdate_LDKNodeFailure_Body node_failure; - }; -} LDKHTLCFailChannelUpdate; - - - -/** - * A query_channel_range message is used to query a peer for channel - * UTXOs in a range of blocks. The recipient of a query makes a best - * effort to reply to the query using one or more reply_channel_range - * messages. - */ -typedef struct MUST_USE_STRUCT LDKQueryChannelRange { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeQueryChannelRange *inner; - bool is_owned; -} LDKQueryChannelRange; - - - -/** - * A query_short_channel_ids message is used to query a peer for - * routing gossip messages related to one or more short_channel_ids. - * The query recipient will reply with the latest, if available, - * channel_announcement, channel_update and node_announcement messages - * it maintains for the requested short_channel_ids followed by a - * reply_short_channel_ids_end message. The short_channel_ids sent in - * this query are encoded. We only support encoding_type=0 uncompressed - * serialization and do not support encoding_type=1 zlib serialization. - */ -typedef struct MUST_USE_STRUCT LDKQueryShortChannelIds { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeQueryShortChannelIds *inner; - bool is_owned; -} LDKQueryShortChannelIds; - -/** - * An event generated by ChannelManager which indicates a message should be sent to a peer (or - * broadcast to most peers). - * These events are handled by PeerManager::process_events if you are using a PeerManager. - */ -typedef enum LDKMessageSendEvent_Tag { - /** - * Used to indicate that we've accepted a channel open and should send the accept_channel - * message provided to the given peer. - */ - LDKMessageSendEvent_SendAcceptChannel, - /** - * Used to indicate that we've initiated a channel open and should send the open_channel - * message provided to the given peer. - */ - LDKMessageSendEvent_SendOpenChannel, - /** - * Used to indicate that a funding_created message should be sent to the peer with the given node_id. - */ - LDKMessageSendEvent_SendFundingCreated, - /** - * Used to indicate that a funding_signed message should be sent to the peer with the given node_id. - */ - LDKMessageSendEvent_SendFundingSigned, - /** - * Used to indicate that a funding_locked message should be sent to the peer with the given node_id. - */ - LDKMessageSendEvent_SendFundingLocked, - /** - * Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id. - */ - LDKMessageSendEvent_SendAnnouncementSignatures, - /** - * Used to indicate that a series of HTLC update messages, as well as a commitment_signed - * message should be sent to the peer with the given node_id. - */ - LDKMessageSendEvent_UpdateHTLCs, - /** - * Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id. - */ - LDKMessageSendEvent_SendRevokeAndACK, - /** - * Used to indicate that a closing_signed message should be sent to the peer with the given node_id. - */ - LDKMessageSendEvent_SendClosingSigned, - /** - * Used to indicate that a shutdown message should be sent to the peer with the given node_id. - */ - LDKMessageSendEvent_SendShutdown, - /** - * Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id. - */ - LDKMessageSendEvent_SendChannelReestablish, - /** - * Used to indicate that a channel_announcement and channel_update should be broadcast to all - * peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2). - * - * Note that after doing so, you very likely (unless you did so very recently) want to call - * ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event. - * This ensures that any nodes which see our channel_announcement also have a relevant - * node_announcement, including relevant feature flags which may be important for routing - * through or to us. - */ - LDKMessageSendEvent_BroadcastChannelAnnouncement, - /** - * Used to indicate that a node_announcement should be broadcast to all peers. - */ - LDKMessageSendEvent_BroadcastNodeAnnouncement, - /** - * Used to indicate that a channel_update should be broadcast to all peers. - */ - LDKMessageSendEvent_BroadcastChannelUpdate, - /** - * Broadcast an error downstream to be handled - */ - LDKMessageSendEvent_HandleError, - /** - * When a payment fails we may receive updates back from the hop where it failed. In such - * cases this event is generated so that we can inform the network graph of this information. - */ - LDKMessageSendEvent_PaymentFailureNetworkUpdate, - /** - * Query a peer for channels with funding transaction UTXOs in a block range. - */ - LDKMessageSendEvent_SendChannelRangeQuery, - /** - * Request routing gossip messages from a peer for a list of channels identified by - * their short_channel_ids. - */ - LDKMessageSendEvent_SendShortIdsQuery, - /** - * Must be last for serialization purposes - */ - LDKMessageSendEvent_Sentinel, -} LDKMessageSendEvent_Tag; - -typedef struct LDKMessageSendEvent_LDKSendAcceptChannel_Body { - struct LDKPublicKey node_id; - struct LDKAcceptChannel msg; -} LDKMessageSendEvent_LDKSendAcceptChannel_Body; - -typedef struct LDKMessageSendEvent_LDKSendOpenChannel_Body { - struct LDKPublicKey node_id; - struct LDKOpenChannel msg; -} LDKMessageSendEvent_LDKSendOpenChannel_Body; - -typedef struct LDKMessageSendEvent_LDKSendFundingCreated_Body { - struct LDKPublicKey node_id; - struct LDKFundingCreated msg; -} LDKMessageSendEvent_LDKSendFundingCreated_Body; - -typedef struct LDKMessageSendEvent_LDKSendFundingSigned_Body { - struct LDKPublicKey node_id; - struct LDKFundingSigned msg; -} LDKMessageSendEvent_LDKSendFundingSigned_Body; - -typedef struct LDKMessageSendEvent_LDKSendFundingLocked_Body { - struct LDKPublicKey node_id; - struct LDKFundingLocked msg; -} LDKMessageSendEvent_LDKSendFundingLocked_Body; - -typedef struct LDKMessageSendEvent_LDKSendAnnouncementSignatures_Body { - struct LDKPublicKey node_id; - struct LDKAnnouncementSignatures msg; -} LDKMessageSendEvent_LDKSendAnnouncementSignatures_Body; - -typedef struct LDKMessageSendEvent_LDKUpdateHTLCs_Body { - struct LDKPublicKey node_id; - struct LDKCommitmentUpdate updates; -} LDKMessageSendEvent_LDKUpdateHTLCs_Body; - -typedef struct LDKMessageSendEvent_LDKSendRevokeAndACK_Body { - struct LDKPublicKey node_id; - struct LDKRevokeAndACK msg; -} LDKMessageSendEvent_LDKSendRevokeAndACK_Body; - -typedef struct LDKMessageSendEvent_LDKSendClosingSigned_Body { - struct LDKPublicKey node_id; - struct LDKClosingSigned msg; -} LDKMessageSendEvent_LDKSendClosingSigned_Body; - -typedef struct LDKMessageSendEvent_LDKSendShutdown_Body { - struct LDKPublicKey node_id; - struct LDKShutdown msg; -} LDKMessageSendEvent_LDKSendShutdown_Body; - -typedef struct LDKMessageSendEvent_LDKSendChannelReestablish_Body { - struct LDKPublicKey node_id; - struct LDKChannelReestablish msg; -} LDKMessageSendEvent_LDKSendChannelReestablish_Body; - -typedef struct LDKMessageSendEvent_LDKBroadcastChannelAnnouncement_Body { - struct LDKChannelAnnouncement msg; - struct LDKChannelUpdate update_msg; -} LDKMessageSendEvent_LDKBroadcastChannelAnnouncement_Body; - -typedef struct LDKMessageSendEvent_LDKBroadcastNodeAnnouncement_Body { - struct LDKNodeAnnouncement msg; -} LDKMessageSendEvent_LDKBroadcastNodeAnnouncement_Body; - -typedef struct LDKMessageSendEvent_LDKBroadcastChannelUpdate_Body { - struct LDKChannelUpdate msg; -} LDKMessageSendEvent_LDKBroadcastChannelUpdate_Body; - -typedef struct LDKMessageSendEvent_LDKHandleError_Body { - struct LDKPublicKey node_id; - struct LDKErrorAction action; -} LDKMessageSendEvent_LDKHandleError_Body; - -typedef struct LDKMessageSendEvent_LDKPaymentFailureNetworkUpdate_Body { - struct LDKHTLCFailChannelUpdate update; -} LDKMessageSendEvent_LDKPaymentFailureNetworkUpdate_Body; - -typedef struct LDKMessageSendEvent_LDKSendChannelRangeQuery_Body { - struct LDKPublicKey node_id; - struct LDKQueryChannelRange msg; -} LDKMessageSendEvent_LDKSendChannelRangeQuery_Body; - -typedef struct LDKMessageSendEvent_LDKSendShortIdsQuery_Body { - struct LDKPublicKey node_id; - struct LDKQueryShortChannelIds msg; -} LDKMessageSendEvent_LDKSendShortIdsQuery_Body; - -typedef struct MUST_USE_STRUCT LDKMessageSendEvent { - LDKMessageSendEvent_Tag tag; - union { - LDKMessageSendEvent_LDKSendAcceptChannel_Body send_accept_channel; - LDKMessageSendEvent_LDKSendOpenChannel_Body send_open_channel; - LDKMessageSendEvent_LDKSendFundingCreated_Body send_funding_created; - LDKMessageSendEvent_LDKSendFundingSigned_Body send_funding_signed; - LDKMessageSendEvent_LDKSendFundingLocked_Body send_funding_locked; - LDKMessageSendEvent_LDKSendAnnouncementSignatures_Body send_announcement_signatures; - LDKMessageSendEvent_LDKUpdateHTLCs_Body update_htl_cs; - LDKMessageSendEvent_LDKSendRevokeAndACK_Body send_revoke_and_ack; - LDKMessageSendEvent_LDKSendClosingSigned_Body send_closing_signed; - LDKMessageSendEvent_LDKSendShutdown_Body send_shutdown; - LDKMessageSendEvent_LDKSendChannelReestablish_Body send_channel_reestablish; - LDKMessageSendEvent_LDKBroadcastChannelAnnouncement_Body broadcast_channel_announcement; - LDKMessageSendEvent_LDKBroadcastNodeAnnouncement_Body broadcast_node_announcement; - LDKMessageSendEvent_LDKBroadcastChannelUpdate_Body broadcast_channel_update; - LDKMessageSendEvent_LDKHandleError_Body handle_error; - LDKMessageSendEvent_LDKPaymentFailureNetworkUpdate_Body payment_failure_network_update; - LDKMessageSendEvent_LDKSendChannelRangeQuery_Body send_channel_range_query; - LDKMessageSendEvent_LDKSendShortIdsQuery_Body send_short_ids_query; - }; -} LDKMessageSendEvent; - -typedef struct LDKCVec_MessageSendEventZ { - struct LDKMessageSendEvent *data; - uintptr_t datalen; -} LDKCVec_MessageSendEventZ; - - - -/** - * An Err type for failure to process messages. - */ -typedef struct MUST_USE_STRUCT LDKLightningError { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeLightningError *inner; - bool is_owned; -} LDKLightningError; - -typedef union LDKCResult_boolLightningErrorZPtr { - bool *result; - struct LDKLightningError *err; -} LDKCResult_boolLightningErrorZPtr; - -typedef struct LDKCResult_boolLightningErrorZ { - union LDKCResult_boolLightningErrorZPtr contents; - bool result_ok; -} LDKCResult_boolLightningErrorZ; - -typedef struct LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ { - struct LDKChannelAnnouncement a; - struct LDKChannelUpdate b; - struct LDKChannelUpdate c; -} LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ; - -typedef struct LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ { - struct LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *data; - uintptr_t datalen; -} LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ; - -typedef struct LDKCVec_NodeAnnouncementZ { - struct LDKNodeAnnouncement *data; - uintptr_t datalen; -} LDKCVec_NodeAnnouncementZ; - -typedef union LDKCResult_NoneLightningErrorZPtr { - /** - * Note that this value is always NULL, as there are no contents in the OK variant - */ - void *result; - struct LDKLightningError *err; -} LDKCResult_NoneLightningErrorZPtr; - -typedef struct LDKCResult_NoneLightningErrorZ { - union LDKCResult_NoneLightningErrorZPtr contents; - bool result_ok; -} LDKCResult_NoneLightningErrorZ; - -typedef struct LDKCVec_PublicKeyZ { - struct LDKPublicKey *data; - uintptr_t datalen; -} LDKCVec_PublicKeyZ; - - - -/** - * 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 - * descriptor. - */ -typedef struct MUST_USE_STRUCT LDKPeerHandleError { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativePeerHandleError *inner; - bool is_owned; -} LDKPeerHandleError; - -typedef union LDKCResult_CVec_u8ZPeerHandleErrorZPtr { - struct LDKCVec_u8Z *result; - struct LDKPeerHandleError *err; -} LDKCResult_CVec_u8ZPeerHandleErrorZPtr; - -typedef struct LDKCResult_CVec_u8ZPeerHandleErrorZ { - union LDKCResult_CVec_u8ZPeerHandleErrorZPtr contents; - bool result_ok; -} LDKCResult_CVec_u8ZPeerHandleErrorZ; - -typedef union LDKCResult_NonePeerHandleErrorZPtr { - /** - * Note that this value is always NULL, as there are no contents in the OK variant - */ - void *result; - struct LDKPeerHandleError *err; -} LDKCResult_NonePeerHandleErrorZPtr; - -typedef struct LDKCResult_NonePeerHandleErrorZ { - union LDKCResult_NonePeerHandleErrorZPtr contents; - bool result_ok; -} LDKCResult_NonePeerHandleErrorZ; - -typedef union LDKCResult_boolPeerHandleErrorZPtr { - bool *result; - struct LDKPeerHandleError *err; -} LDKCResult_boolPeerHandleErrorZPtr; - -typedef struct LDKCResult_boolPeerHandleErrorZ { - union LDKCResult_boolPeerHandleErrorZPtr contents; - bool result_ok; -} LDKCResult_boolPeerHandleErrorZ; - - - -/** - * Features used within an `init` message. - */ -typedef struct MUST_USE_STRUCT LDKInitFeatures { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeInitFeatures *inner; - bool is_owned; -} LDKInitFeatures; - -typedef union LDKCResult_InitFeaturesDecodeErrorZPtr { - struct LDKInitFeatures *result; - struct LDKDecodeError *err; -} LDKCResult_InitFeaturesDecodeErrorZPtr; - -typedef struct LDKCResult_InitFeaturesDecodeErrorZ { - union LDKCResult_InitFeaturesDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_InitFeaturesDecodeErrorZ; - - - -/** - * Features used within a `node_announcement` message. - */ -typedef struct MUST_USE_STRUCT LDKNodeFeatures { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeNodeFeatures *inner; - bool is_owned; -} LDKNodeFeatures; - -typedef union LDKCResult_NodeFeaturesDecodeErrorZPtr { - struct LDKNodeFeatures *result; - struct LDKDecodeError *err; -} LDKCResult_NodeFeaturesDecodeErrorZPtr; - -typedef struct LDKCResult_NodeFeaturesDecodeErrorZ { - union LDKCResult_NodeFeaturesDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_NodeFeaturesDecodeErrorZ; - - - -/** - * Features used within a `channel_announcement` message. - */ -typedef struct MUST_USE_STRUCT LDKChannelFeatures { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelFeatures *inner; - bool is_owned; -} LDKChannelFeatures; - -typedef union LDKCResult_ChannelFeaturesDecodeErrorZPtr { - struct LDKChannelFeatures *result; - struct LDKDecodeError *err; -} LDKCResult_ChannelFeaturesDecodeErrorZPtr; - -typedef struct LDKCResult_ChannelFeaturesDecodeErrorZ { - union LDKCResult_ChannelFeaturesDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ChannelFeaturesDecodeErrorZ; - - - -/** - * Options which apply on a per-channel basis and may change at runtime or based on negotiation - * with our counterparty. - */ -typedef struct MUST_USE_STRUCT LDKChannelConfig { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelConfig *inner; - bool is_owned; -} LDKChannelConfig; - -typedef union LDKCResult_ChannelConfigDecodeErrorZPtr { - struct LDKChannelConfig *result; - struct LDKDecodeError *err; -} LDKCResult_ChannelConfigDecodeErrorZPtr; - -typedef struct LDKCResult_ChannelConfigDecodeErrorZ { - union LDKCResult_ChannelConfigDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ChannelConfigDecodeErrorZ; - - - -/** - * Details about one direction of a channel. Received - * within a channel update. - */ -typedef struct MUST_USE_STRUCT LDKDirectionalChannelInfo { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeDirectionalChannelInfo *inner; - bool is_owned; -} LDKDirectionalChannelInfo; - -typedef union LDKCResult_DirectionalChannelInfoDecodeErrorZPtr { - struct LDKDirectionalChannelInfo *result; - struct LDKDecodeError *err; -} LDKCResult_DirectionalChannelInfoDecodeErrorZPtr; - -typedef struct LDKCResult_DirectionalChannelInfoDecodeErrorZ { - union LDKCResult_DirectionalChannelInfoDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_DirectionalChannelInfoDecodeErrorZ; - - - -/** - * Details about a channel (both directions). - * Received within a channel announcement. - */ -typedef struct MUST_USE_STRUCT LDKChannelInfo { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelInfo *inner; - bool is_owned; -} LDKChannelInfo; - -typedef union LDKCResult_ChannelInfoDecodeErrorZPtr { - struct LDKChannelInfo *result; - struct LDKDecodeError *err; -} LDKCResult_ChannelInfoDecodeErrorZPtr; - -typedef struct LDKCResult_ChannelInfoDecodeErrorZ { - union LDKCResult_ChannelInfoDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ChannelInfoDecodeErrorZ; - - - -/** - * Fees for routing via a given channel or a node - */ -typedef struct MUST_USE_STRUCT LDKRoutingFees { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeRoutingFees *inner; - bool is_owned; -} LDKRoutingFees; - -typedef union LDKCResult_RoutingFeesDecodeErrorZPtr { - struct LDKRoutingFees *result; - struct LDKDecodeError *err; -} LDKCResult_RoutingFeesDecodeErrorZPtr; - -typedef struct LDKCResult_RoutingFeesDecodeErrorZ { - union LDKCResult_RoutingFeesDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_RoutingFeesDecodeErrorZ; - -typedef struct LDKFourBytes { - uint8_t data[4]; -} LDKFourBytes; - -typedef struct LDKSixteenBytes { - uint8_t data[16]; -} LDKSixteenBytes; - -typedef struct LDKTenBytes { - uint8_t data[10]; -} LDKTenBytes; - -/** - * Arbitrary 32 bytes, which could represent one of a few different things. You probably want to - * look up the corresponding function in rust-lightning's docs. - */ -typedef struct LDKThirtyTwoBytes { - uint8_t data[32]; -} LDKThirtyTwoBytes; - -/** - * An address which can be used to connect to a remote peer - */ -typedef enum LDKNetAddress_Tag { - /** - * An IPv4 address/port on which the peer is listening. - */ - LDKNetAddress_IPv4, - /** - * An IPv6 address/port on which the peer is listening. - */ - LDKNetAddress_IPv6, - /** - * An old-style Tor onion address/port on which the peer is listening. - */ - LDKNetAddress_OnionV2, - /** - * A new-style Tor onion address/port on which the peer is listening. - * To create the human-readable \"hostname\", concatenate ed25519_pubkey, checksum, and version, - * wrap as base32 and append \".onion\". - */ - LDKNetAddress_OnionV3, - /** - * Must be last for serialization purposes - */ - LDKNetAddress_Sentinel, -} LDKNetAddress_Tag; - -typedef struct LDKNetAddress_LDKIPv4_Body { - struct LDKFourBytes addr; - uint16_t port; -} LDKNetAddress_LDKIPv4_Body; - -typedef struct LDKNetAddress_LDKIPv6_Body { - struct LDKSixteenBytes addr; - uint16_t port; -} LDKNetAddress_LDKIPv6_Body; - -typedef struct LDKNetAddress_LDKOnionV2_Body { - struct LDKTenBytes addr; - uint16_t port; -} LDKNetAddress_LDKOnionV2_Body; - -typedef struct LDKNetAddress_LDKOnionV3_Body { - struct LDKThirtyTwoBytes ed25519_pubkey; - uint16_t checksum; - uint8_t version; - uint16_t port; -} LDKNetAddress_LDKOnionV3_Body; - -typedef struct MUST_USE_STRUCT LDKNetAddress { - LDKNetAddress_Tag tag; - union { - LDKNetAddress_LDKIPv4_Body i_pv4; - LDKNetAddress_LDKIPv6_Body i_pv6; - LDKNetAddress_LDKOnionV2_Body onion_v2; - LDKNetAddress_LDKOnionV3_Body onion_v3; - }; -} LDKNetAddress; - -typedef struct LDKCVec_NetAddressZ { - struct LDKNetAddress *data; - uintptr_t datalen; -} LDKCVec_NetAddressZ; - - - -/** - * Information received in the latest node_announcement from this node. - */ -typedef struct MUST_USE_STRUCT LDKNodeAnnouncementInfo { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeNodeAnnouncementInfo *inner; - bool is_owned; -} LDKNodeAnnouncementInfo; - -typedef union LDKCResult_NodeAnnouncementInfoDecodeErrorZPtr { - struct LDKNodeAnnouncementInfo *result; - struct LDKDecodeError *err; -} LDKCResult_NodeAnnouncementInfoDecodeErrorZPtr; - -typedef struct LDKCResult_NodeAnnouncementInfoDecodeErrorZ { - union LDKCResult_NodeAnnouncementInfoDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_NodeAnnouncementInfoDecodeErrorZ; - -typedef struct LDKCVec_u64Z { - uint64_t *data; - uintptr_t datalen; -} LDKCVec_u64Z; - - - -/** - * Details about a node in the network, known from the network announcement. - */ -typedef struct MUST_USE_STRUCT LDKNodeInfo { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeNodeInfo *inner; - bool is_owned; -} LDKNodeInfo; - -typedef union LDKCResult_NodeInfoDecodeErrorZPtr { - struct LDKNodeInfo *result; - struct LDKDecodeError *err; -} LDKCResult_NodeInfoDecodeErrorZPtr; - -typedef struct LDKCResult_NodeInfoDecodeErrorZ { - union LDKCResult_NodeInfoDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_NodeInfoDecodeErrorZ; - - - -/** - * Represents the network as nodes and channels between them - */ -typedef struct MUST_USE_STRUCT LDKNetworkGraph { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeNetworkGraph *inner; - bool is_owned; -} LDKNetworkGraph; - -typedef union LDKCResult_NetworkGraphDecodeErrorZPtr { - struct LDKNetworkGraph *result; - struct LDKDecodeError *err; -} LDKCResult_NetworkGraphDecodeErrorZPtr; - -typedef struct LDKCResult_NetworkGraphDecodeErrorZ { - union LDKCResult_NetworkGraphDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_NetworkGraphDecodeErrorZ; - -typedef struct LDKC2Tuple_usizeTransactionZ { - uintptr_t a; - struct LDKTransaction b; -} LDKC2Tuple_usizeTransactionZ; - -typedef struct LDKCVec_C2Tuple_usizeTransactionZZ { - struct LDKC2Tuple_usizeTransactionZ *data; - uintptr_t datalen; -} LDKCVec_C2Tuple_usizeTransactionZZ; - -typedef union LDKCResult_NoneChannelMonitorUpdateErrZPtr { - /** - * Note that this value is always NULL, as there are no contents in the OK variant - */ - void *result; - enum LDKChannelMonitorUpdateErr *err; -} LDKCResult_NoneChannelMonitorUpdateErrZPtr; - -typedef struct LDKCResult_NoneChannelMonitorUpdateErrZ { - union LDKCResult_NoneChannelMonitorUpdateErrZPtr contents; - bool result_ok; -} LDKCResult_NoneChannelMonitorUpdateErrZ; - - - -/** - * Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on - * chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the - * preimage claim backward will lead to loss of funds. - * - * [`chain::Watch`]: ../trait.Watch.html - */ -typedef struct MUST_USE_STRUCT LDKHTLCUpdate { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeHTLCUpdate *inner; - bool is_owned; -} LDKHTLCUpdate; - - - -/** - * A reference to a transaction output. - * - * Differs from bitcoin::blockdata::transaction::OutPoint as the index is a u16 instead of u32 - * due to LN's restrictions on index values. Should reduce (possibly) unsafe conversions this way. - */ -typedef struct MUST_USE_STRUCT LDKOutPoint { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeOutPoint *inner; - bool is_owned; -} LDKOutPoint; - -/** - * An event to be processed by the ChannelManager. - */ -typedef enum LDKMonitorEvent_Tag { - /** - * A monitor event containing an HTLCUpdate. - */ - LDKMonitorEvent_HTLCEvent, - /** - * A monitor event that the Channel's commitment transaction was broadcasted. - */ - LDKMonitorEvent_CommitmentTxBroadcasted, - /** - * Must be last for serialization purposes - */ - LDKMonitorEvent_Sentinel, -} LDKMonitorEvent_Tag; - -typedef struct MUST_USE_STRUCT LDKMonitorEvent { - LDKMonitorEvent_Tag tag; - union { - struct { - struct LDKHTLCUpdate htlc_event; - }; - struct { - struct LDKOutPoint commitment_tx_broadcasted; - }; - }; -} LDKMonitorEvent; - -typedef struct LDKCVec_MonitorEventZ { - struct LDKMonitorEvent *data; - uintptr_t datalen; -} LDKCVec_MonitorEventZ; - - - -/** - * Information about a spendable output to a P2WSH script. See - * SpendableOutputDescriptor::DelayedPaymentOutput for more details on how to spend this. - */ -typedef struct MUST_USE_STRUCT LDKDelayedPaymentOutputDescriptor { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeDelayedPaymentOutputDescriptor *inner; - bool is_owned; -} LDKDelayedPaymentOutputDescriptor; - - - -/** - * Information about a spendable output to our \"payment key\". See - * SpendableOutputDescriptor::StaticPaymentOutput for more details on how to spend this. - */ -typedef struct MUST_USE_STRUCT LDKStaticPaymentOutputDescriptor { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeStaticPaymentOutputDescriptor *inner; - bool is_owned; -} LDKStaticPaymentOutputDescriptor; - -/** - * When on-chain outputs are created by rust-lightning (which our counterparty is not able to - * claim at any point in the future) an event is generated which you must track and be able to - * spend on-chain. The information needed to do this is provided in this enum, including the - * outpoint describing which txid and output index is available, the full output which exists at - * that txid/index, and any keys or other information required to sign. - */ -typedef enum LDKSpendableOutputDescriptor_Tag { - /** - * An output to a script which was provided via KeysInterface directly, either from - * `get_destination_script()` or `get_shutdown_pubkey()`, thus you should already know how to - * spend it. No secret keys are provided as rust-lightning was never given any key. - * These may include outputs from a transaction punishing our counterparty or claiming an HTLC - * on-chain using the payment preimage or after it has timed out. - */ - LDKSpendableOutputDescriptor_StaticOutput, - /** - * An output to a P2WSH script which can be spent with a single signature after a CSV delay. - * - * The witness in the spending input should be: - * (MINIMALIF standard rule) - * - * Note that the nSequence field in the spending input must be set to to_self_delay - * (which means the transaction is not broadcastable until at least to_self_delay - * blocks after the outpoint confirms). - * - * These are generally the result of a \"revocable\" output to us, spendable only by us unless - * it is an output from an old state which we broadcast (which should never happen). - * - * To derive the delayed_payment key which is used to sign for this input, you must pass the - * holder delayed_payment_base_key (ie the private key which corresponds to the pubkey in - * Sign::pubkeys().delayed_payment_basepoint) and the provided per_commitment_point to - * chan_utils::derive_private_key. The public key can be generated without the secret key - * using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in - * Sign::pubkeys(). - * - * To derive the revocation_pubkey provided here (which is used in the witness - * script generation), you must pass the counterparty revocation_basepoint (which appears in the - * call to Sign::ready_channel) and the provided per_commitment point - * to chan_utils::derive_public_revocation_key. - * - * The witness script which is hashed and included in the output script_pubkey may be - * regenerated by passing the revocation_pubkey (derived as above), our delayed_payment pubkey - * (derived as above), and the to_self_delay contained here to - * chan_utils::get_revokeable_redeemscript. - */ - LDKSpendableOutputDescriptor_DelayedPaymentOutput, - /** - * An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which - * corresponds to the public key in Sign::pubkeys().payment_point). - * The witness in the spending input, is, thus, simply: - * - * - * These are generally the result of our counterparty having broadcast the current state, - * allowing us to claim the non-HTLC-encumbered outputs immediately. - */ - LDKSpendableOutputDescriptor_StaticPaymentOutput, - /** - * Must be last for serialization purposes - */ - LDKSpendableOutputDescriptor_Sentinel, -} LDKSpendableOutputDescriptor_Tag; - -typedef struct LDKSpendableOutputDescriptor_LDKStaticOutput_Body { - struct LDKOutPoint outpoint; - struct LDKTxOut output; -} LDKSpendableOutputDescriptor_LDKStaticOutput_Body; - -typedef struct MUST_USE_STRUCT LDKSpendableOutputDescriptor { - LDKSpendableOutputDescriptor_Tag tag; - union { - LDKSpendableOutputDescriptor_LDKStaticOutput_Body static_output; - struct { - struct LDKDelayedPaymentOutputDescriptor delayed_payment_output; - }; - struct { - struct LDKStaticPaymentOutputDescriptor static_payment_output; - }; - }; -} LDKSpendableOutputDescriptor; - -typedef struct LDKCVec_SpendableOutputDescriptorZ { - struct LDKSpendableOutputDescriptor *data; - uintptr_t datalen; -} LDKCVec_SpendableOutputDescriptorZ; - -/** - * An Event which you should probably take some action in response to. - * - * Note that while Writeable and Readable are implemented for Event, you probably shouldn't use - * them directly as they don't round-trip exactly (for example FundingGenerationReady is never - * written as it makes no sense to respond to it after reconnecting to peers). - */ -typedef enum LDKEvent_Tag { - /** - * Used to indicate that the client should generate a funding transaction with the given - * parameters and then call ChannelManager::funding_transaction_generated. - * Generated in ChannelManager message handling. - * Note that *all inputs* in the funding transaction must spend SegWit outputs or your - * counterparty can steal your funds! - */ - LDKEvent_FundingGenerationReady, - /** - * Used to indicate that the client may now broadcast the funding transaction it created for a - * channel. Broadcasting such a transaction prior to this event may lead to our counterparty - * trivially stealing all funds in the funding transaction! - */ - LDKEvent_FundingBroadcastSafe, - /** - * Indicates we've received money! Just gotta dig out that payment preimage and feed it to - * ChannelManager::claim_funds to get it.... - * Note that if the preimage is not known or the amount paid is incorrect, you should call - * ChannelManager::fail_htlc_backwards to free up resources for this HTLC and avoid - * network congestion. - * The amount paid should be considered 'incorrect' when it is less than or more than twice - * the amount expected. - * If you fail to call either ChannelManager::claim_funds or - * ChannelManager::fail_htlc_backwards within the HTLC's timeout, the HTLC will be - * automatically failed. - */ - LDKEvent_PaymentReceived, - /** - * Indicates an outbound payment we made succeeded (ie it made it all the way to its target - * and we got back the payment preimage for it). - * Note that duplicative PaymentSent Events may be generated - it is your responsibility to - * deduplicate them by payment_preimage (which MUST be unique)! - */ - LDKEvent_PaymentSent, - /** - * Indicates an outbound payment we made failed. Probably some intermediary node dropped - * something. You may wish to retry with a different route. - * Note that duplicative PaymentFailed Events may be generated - it is your responsibility to - * deduplicate them by payment_hash (which MUST be unique)! - */ - LDKEvent_PaymentFailed, - /** - * Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a - * time in the future. - */ - LDKEvent_PendingHTLCsForwardable, - /** - * Used to indicate that an output was generated on-chain which you should know how to spend. - * Such an output will *not* ever be spent by rust-lightning, and are not at risk of your - * counterparty spending them due to some kind of timeout. Thus, you need to store them - * somewhere and spend them when you create on-chain transactions. - */ - LDKEvent_SpendableOutputs, - /** - * Must be last for serialization purposes - */ - LDKEvent_Sentinel, -} LDKEvent_Tag; - -typedef struct LDKEvent_LDKFundingGenerationReady_Body { - struct LDKThirtyTwoBytes temporary_channel_id; - uint64_t channel_value_satoshis; - struct LDKCVec_u8Z output_script; - uint64_t user_channel_id; -} LDKEvent_LDKFundingGenerationReady_Body; - -typedef struct LDKEvent_LDKFundingBroadcastSafe_Body { - struct LDKOutPoint funding_txo; - uint64_t user_channel_id; -} LDKEvent_LDKFundingBroadcastSafe_Body; - -typedef struct LDKEvent_LDKPaymentReceived_Body { - struct LDKThirtyTwoBytes payment_hash; - struct LDKThirtyTwoBytes payment_secret; - uint64_t amt; -} LDKEvent_LDKPaymentReceived_Body; - -typedef struct LDKEvent_LDKPaymentSent_Body { - struct LDKThirtyTwoBytes payment_preimage; -} LDKEvent_LDKPaymentSent_Body; - -typedef struct LDKEvent_LDKPaymentFailed_Body { - struct LDKThirtyTwoBytes payment_hash; - bool rejected_by_dest; -} LDKEvent_LDKPaymentFailed_Body; - -typedef struct LDKEvent_LDKPendingHTLCsForwardable_Body { - uint64_t time_forwardable; -} LDKEvent_LDKPendingHTLCsForwardable_Body; - -typedef struct LDKEvent_LDKSpendableOutputs_Body { - struct LDKCVec_SpendableOutputDescriptorZ outputs; -} LDKEvent_LDKSpendableOutputs_Body; - -typedef struct MUST_USE_STRUCT LDKEvent { - LDKEvent_Tag tag; - union { - LDKEvent_LDKFundingGenerationReady_Body funding_generation_ready; - LDKEvent_LDKFundingBroadcastSafe_Body funding_broadcast_safe; - LDKEvent_LDKPaymentReceived_Body payment_received; - LDKEvent_LDKPaymentSent_Body payment_sent; - LDKEvent_LDKPaymentFailed_Body payment_failed; - LDKEvent_LDKPendingHTLCsForwardable_Body pending_htl_cs_forwardable; - LDKEvent_LDKSpendableOutputs_Body spendable_outputs; - }; -} LDKEvent; - -typedef struct LDKCVec_EventZ { - struct LDKEvent *data; - uintptr_t datalen; -} LDKCVec_EventZ; - -typedef union LDKCResult_OutPointDecodeErrorZPtr { - struct LDKOutPoint *result; - struct LDKDecodeError *err; -} LDKCResult_OutPointDecodeErrorZPtr; - -typedef struct LDKCResult_OutPointDecodeErrorZ { - union LDKCResult_OutPointDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_OutPointDecodeErrorZ; - - - -/** - * An update generated by the underlying Channel itself which contains some new information the - * ChannelMonitor should be made aware of. - */ -typedef struct MUST_USE_STRUCT LDKChannelMonitorUpdate { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelMonitorUpdate *inner; - bool is_owned; -} LDKChannelMonitorUpdate; - -typedef union LDKCResult_ChannelMonitorUpdateDecodeErrorZPtr { - struct LDKChannelMonitorUpdate *result; - struct LDKDecodeError *err; -} LDKCResult_ChannelMonitorUpdateDecodeErrorZPtr; - -typedef struct LDKCResult_ChannelMonitorUpdateDecodeErrorZ { - union LDKCResult_ChannelMonitorUpdateDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ChannelMonitorUpdateDecodeErrorZ; - -typedef union LDKCResult_HTLCUpdateDecodeErrorZPtr { - struct LDKHTLCUpdate *result; - struct LDKDecodeError *err; -} LDKCResult_HTLCUpdateDecodeErrorZPtr; - -typedef struct LDKCResult_HTLCUpdateDecodeErrorZ { - union LDKCResult_HTLCUpdateDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_HTLCUpdateDecodeErrorZ; - - - -/** - * General Err type for ChannelMonitor actions. Generally, this implies that the data provided is - * inconsistent with the ChannelMonitor being called. eg for ChannelMonitor::update_monitor this - * means you tried to update a monitor for a different channel or the ChannelMonitorUpdate was - * corrupted. - * Contains a developer-readable error message. - */ -typedef struct MUST_USE_STRUCT LDKMonitorUpdateError { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeMonitorUpdateError *inner; - bool is_owned; -} LDKMonitorUpdateError; - -typedef union LDKCResult_NoneMonitorUpdateErrorZPtr { - /** - * Note that this value is always NULL, as there are no contents in the OK variant - */ - void *result; - struct LDKMonitorUpdateError *err; -} LDKCResult_NoneMonitorUpdateErrorZPtr; - -typedef struct LDKCResult_NoneMonitorUpdateErrorZ { - union LDKCResult_NoneMonitorUpdateErrorZPtr contents; - bool result_ok; -} LDKCResult_NoneMonitorUpdateErrorZ; - -typedef struct LDKC2Tuple_OutPointScriptZ { - struct LDKOutPoint a; - struct LDKCVec_u8Z b; -} LDKC2Tuple_OutPointScriptZ; - -typedef struct LDKCVec_TransactionZ { - struct LDKTransaction *data; - uintptr_t datalen; -} LDKCVec_TransactionZ; - -typedef struct LDKC2Tuple_u32TxOutZ { - uint32_t a; - struct LDKTxOut b; -} LDKC2Tuple_u32TxOutZ; - -typedef struct LDKCVec_C2Tuple_u32TxOutZZ { - struct LDKC2Tuple_u32TxOutZ *data; - uintptr_t datalen; -} LDKCVec_C2Tuple_u32TxOutZZ; - -typedef struct LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ { - struct LDKThirtyTwoBytes a; - struct LDKCVec_C2Tuple_u32TxOutZZ b; -} LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ; - -typedef struct LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ { - struct LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *data; - uintptr_t datalen; -} LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ; - -typedef struct LDKC2Tuple_SignatureCVec_SignatureZZ { - struct LDKSignature a; - struct LDKCVec_SignatureZ b; -} LDKC2Tuple_SignatureCVec_SignatureZZ; - -typedef union LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZPtr { - struct LDKC2Tuple_SignatureCVec_SignatureZZ *result; - /** - * Note that this value is always NULL, as there are no contents in the Err variant - */ - void *err; -} LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZPtr; - -typedef struct LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { - union LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZPtr contents; - bool result_ok; -} LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ; - -typedef union LDKCResult_SignatureNoneZPtr { - struct LDKSignature *result; - /** - * Note that this value is always NULL, as there are no contents in the Err variant - */ - void *err; -} LDKCResult_SignatureNoneZPtr; - -typedef struct LDKCResult_SignatureNoneZ { - union LDKCResult_SignatureNoneZPtr contents; - bool result_ok; -} LDKCResult_SignatureNoneZ; - - - -/** - * The unsigned part of a channel_announcement - */ -typedef struct MUST_USE_STRUCT LDKUnsignedChannelAnnouncement { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeUnsignedChannelAnnouncement *inner; - bool is_owned; -} LDKUnsignedChannelAnnouncement; - -/** - * A trait to sign lightning channel transactions as described in BOLT 3. - * - * Signing services could be implemented on a hardware wallet. In this case, - * the current Sign would be a front-end on top of a communication - * channel connected to your secure device and lightning key material wouldn't - * reside on a hot server. Nevertheless, a this deployment would still need - * to trust the ChannelManager to avoid loss of funds as this latest component - * could ask to sign commitment transaction with HTLCs paying to attacker pubkeys. - * - * A more secure iteration would be to use hashlock (or payment points) to pair - * invoice/incoming HTLCs with outgoing HTLCs to implement a no-trust-ChannelManager - * at the price of more state and computation on the hardware wallet side. In the future, - * we are looking forward to design such interface. - * - * In any case, ChannelMonitor or fallback watchtowers are always going to be trusted - * to act, as liveness and breach reply correctness are always going to be hard requirements - * of LN security model, orthogonal of key management issues. - */ -typedef struct LDKSign { - void *this_arg; - /** - * Gets the per-commitment point for a specific commitment number - * - * Note that the commitment number starts at (1 << 48) - 1 and counts backwards. - */ - struct LDKPublicKey (*get_per_commitment_point)(const void *this_arg, uint64_t idx); - /** - * Gets the commitment secret for a specific commitment number as part of the revocation process - * - * An external signer implementation should error here if the commitment was already signed - * and should refuse to sign it in the future. - * - * May be called more than once for the same index. - * - * Note that the commitment number starts at (1 << 48) - 1 and counts backwards. - */ - struct LDKThirtyTwoBytes (*release_commitment_secret)(const void *this_arg, uint64_t idx); - /** - * Gets the holder's channel public keys and basepoints - */ - struct LDKChannelPublicKeys pubkeys; - /** - * Fill in the pubkeys field as a reference to it will be given to Rust after this returns - * Note that this takes a pointer to this object, not the this_ptr like other methods do - * This function pointer may be NULL if pubkeys is filled in when this object is created and never needs updating. - */ - void (*set_pubkeys)(const struct LDKSign*NONNULL_PTR ); - /** - * Gets an arbitrary identifier describing the set of keys which are provided back to you in - * some SpendableOutputDescriptor types. This should be sufficient to identify this - * Sign object uniquely and lookup or re-derive its keys. - */ - struct LDKThirtyTwoBytes (*channel_keys_id)(const void *this_arg); - /** - * Create a signature for a counterparty's commitment transaction and associated HTLC transactions. - * - * Note that if signing fails or is rejected, the channel will be force-closed. - */ - struct LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ (*sign_counterparty_commitment)(const void *this_arg, const struct LDKCommitmentTransaction *NONNULL_PTR commitment_tx); - /** - * Create a signatures for a holder's commitment transaction and its claiming HTLC transactions. - * This will only ever be called with a non-revoked commitment_tx. This will be called with the - * latest commitment_tx when we initiate a force-close. - * This will be called with the previous latest, just to get claiming HTLC signatures, if we are - * reacting to a ChannelMonitor replica that decided to broadcast before it had been updated to - * the latest. - * This may be called multiple times for the same transaction. - * - * An external signer implementation should check that the commitment has not been revoked. - * - * May return Err if key derivation fails. Callers, such as ChannelMonitor, will panic in such a case. - */ - struct LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ (*sign_holder_commitment_and_htlcs)(const void *this_arg, const struct LDKHolderCommitmentTransaction *NONNULL_PTR commitment_tx); - /** - * Create a signature for the given input in a transaction spending an HTLC or commitment - * transaction output when our counterparty broadcasts an old state. - * - * A justice transaction may claim multiples outputs at the same time if timelocks are - * similar, but only a signature for the input at index `input` should be signed for here. - * It may be called multiples time for same output(s) if a fee-bump is needed with regards - * to an upcoming timelock expiration. - * - * Amount is value of the output spent by this input, committed to in the BIP 143 signature. - * - * per_commitment_key is revocation secret which was provided by our counterparty when they - * revoked the state which they eventually broadcast. It's not a _holder_ secret key and does - * not allow the spending of any funds by itself (you need our holder revocation_secret to do - * so). - * - * htlc holds HTLC elements (hash, timelock) if the output being spent is a HTLC output, thus - * changing the format of the witness script (which is committed to in the BIP 143 - * signatures). - */ - struct LDKCResult_SignatureNoneZ (*sign_justice_transaction)(const void *this_arg, struct LDKTransaction justice_tx, uintptr_t input, uint64_t amount, const uint8_t (*per_commitment_key)[32], const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc); - /** - * Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment - * transaction, either offered or received. - * - * Such a transaction may claim multiples offered outputs at same time if we know the - * preimage for each when we create it, but only the input at index `input` should be - * signed for here. It may be called multiple times for same output(s) if a fee-bump is - * needed with regards to an upcoming timelock expiration. - * - * Witness_script is either a offered or received script as defined in BOLT3 for HTLC - * outputs. - * - * Amount is value of the output spent by this input, committed to in the BIP 143 signature. - * - * Per_commitment_point is the dynamic point corresponding to the channel state - * detected onchain. It has been generated by our counterparty and is used to derive - * channel state keys, which are then included in the witness script and committed to in the - * BIP 143 signature. - */ - struct LDKCResult_SignatureNoneZ (*sign_counterparty_htlc_transaction)(const void *this_arg, struct LDKTransaction htlc_tx, uintptr_t input, uint64_t amount, struct LDKPublicKey per_commitment_point, const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc); - /** - * Create a signature for a (proposed) closing transaction. - * - * Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have - * chosen to forgo their output as dust. - */ - struct LDKCResult_SignatureNoneZ (*sign_closing_transaction)(const void *this_arg, struct LDKTransaction closing_tx); - /** - * Signs a channel announcement message with our funding key, proving it comes from one - * of the channel participants. - * - * Note that if this fails or is rejected, the channel will not be publicly announced and - * our counterparty may (though likely will not) close the channel on us for violating the - * protocol. - */ - struct LDKCResult_SignatureNoneZ (*sign_channel_announcement)(const void *this_arg, const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR msg); - /** - * Set the counterparty static channel data, including basepoints, - * counterparty_selected/holder_selected_contest_delay and funding outpoint. - * This is done as soon as the funding outpoint is known. Since these are static channel data, - * they MUST NOT be allowed to change to different values once set. - * - * channel_parameters.is_populated() MUST be true. - * - * We bind holder_selected_contest_delay late here for API convenience. - * - * Will be called before any signatures are applied. - */ - void (*ready_channel)(void *this_arg, const struct LDKChannelTransactionParameters *NONNULL_PTR channel_parameters); - void *(*clone)(const void *this_arg); - struct LDKCVec_u8Z (*write)(const void *this_arg); - void (*free)(void *this_arg); -} LDKSign; - - - -/** - * A ChannelMonitor handles chain events (blocks connected and disconnected) and generates - * on-chain transactions to ensure no loss of funds occurs. - * - * You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date - * information and are actively monitoring the chain. - * - * Pending Events or updated HTLCs which have not yet been read out by - * get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and - * reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events - * gotten are fully handled before re-serializing the new state. - * - * Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which - * tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along - * the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the - * returned block hash and the the current chain and then reconnecting blocks to get to the - * best chain) upon deserializing the object! - */ -typedef struct MUST_USE_STRUCT LDKChannelMonitor { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelMonitor *inner; - bool is_owned; -} LDKChannelMonitor; - -typedef struct LDKC2Tuple_BlockHashChannelMonitorZ { - struct LDKThirtyTwoBytes a; - struct LDKChannelMonitor b; -} LDKC2Tuple_BlockHashChannelMonitorZ; - -typedef union LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr { - struct LDKC2Tuple_BlockHashChannelMonitorZ *result; - struct LDKDecodeError *err; -} LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr; - -typedef struct LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { - union LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ; - -typedef union LDKCResult_TxOutAccessErrorZPtr { - struct LDKTxOut *result; - enum LDKAccessError *err; -} LDKCResult_TxOutAccessErrorZPtr; - -typedef struct LDKCResult_TxOutAccessErrorZ { - union LDKCResult_TxOutAccessErrorZPtr contents; - bool result_ok; -} LDKCResult_TxOutAccessErrorZ; - -/** - * A Rust str object, ie a reference to a UTF8-valid string. - * This is *not* null-terminated so cannot be used directly as a C string! - */ -typedef struct LDKStr { - const uint8_t *chars; - uintptr_t len; -} LDKStr; - -/** - * Indicates an error on the client's part (usually some variant of attempting to use too-low or - * too-high values) - */ -typedef enum LDKAPIError_Tag { - /** - * 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. - */ - LDKAPIError_APIMisuseError, - /** - * Due to a high feerate, we were unable to complete the request. - * For example, this may be returned if the feerate implies we cannot open a channel at the - * requested value, but opening a larger channel would succeed. - */ - LDKAPIError_FeeRateTooHigh, - /** - * A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route, - * too-many-hops, etc). - */ - LDKAPIError_RouteError, - /** - * We were unable to complete the request as the Channel required to do so is unable to - * complete the request (or was not found). This can take many forms, including disconnected - * peer, channel at capacity, channel shutting down, etc. - */ - LDKAPIError_ChannelUnavailable, - /** - * An attempt to call watch/update_channel returned an Err (ie you did this!), causing the - * attempted action to fail. - */ - LDKAPIError_MonitorUpdateFailed, - /** - * Must be last for serialization purposes - */ - LDKAPIError_Sentinel, -} LDKAPIError_Tag; - -typedef struct LDKAPIError_LDKAPIMisuseError_Body { - struct LDKCVec_u8Z err; -} LDKAPIError_LDKAPIMisuseError_Body; - -typedef struct LDKAPIError_LDKFeeRateTooHigh_Body { - struct LDKCVec_u8Z err; - uint32_t feerate; -} LDKAPIError_LDKFeeRateTooHigh_Body; - -typedef struct LDKAPIError_LDKRouteError_Body { - struct LDKStr err; -} LDKAPIError_LDKRouteError_Body; - -typedef struct LDKAPIError_LDKChannelUnavailable_Body { - struct LDKCVec_u8Z err; -} LDKAPIError_LDKChannelUnavailable_Body; - -typedef struct MUST_USE_STRUCT LDKAPIError { - LDKAPIError_Tag tag; - union { - LDKAPIError_LDKAPIMisuseError_Body api_misuse_error; - LDKAPIError_LDKFeeRateTooHigh_Body fee_rate_too_high; - LDKAPIError_LDKRouteError_Body route_error; - LDKAPIError_LDKChannelUnavailable_Body channel_unavailable; - }; -} LDKAPIError; - -typedef union LDKCResult_NoneAPIErrorZPtr { - /** - * Note that this value is always NULL, as there are no contents in the OK variant - */ - void *result; - struct LDKAPIError *err; -} LDKCResult_NoneAPIErrorZPtr; - -typedef struct LDKCResult_NoneAPIErrorZ { - union LDKCResult_NoneAPIErrorZPtr contents; - bool result_ok; -} LDKCResult_NoneAPIErrorZ; - -typedef struct LDKCVec_CResult_NoneAPIErrorZZ { - struct LDKCResult_NoneAPIErrorZ *data; - uintptr_t datalen; -} LDKCVec_CResult_NoneAPIErrorZZ; - -typedef struct LDKCVec_APIErrorZ { - struct LDKAPIError *data; - uintptr_t datalen; -} LDKCVec_APIErrorZ; - - - -/** - * Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels - */ -typedef struct MUST_USE_STRUCT LDKChannelDetails { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelDetails *inner; - bool is_owned; -} LDKChannelDetails; - -typedef struct LDKCVec_ChannelDetailsZ { - struct LDKChannelDetails *data; - uintptr_t datalen; -} LDKCVec_ChannelDetailsZ; - -/** - * 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 - * states for more. - */ -typedef enum LDKPaymentSendFailure_Tag { - /** - * 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 - * once you've changed the parameter at error, you can freely retry the payment in full. - */ - LDKPaymentSendFailure_ParameterError, - /** - * A parameter in a single path 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 once you've changed the parameter at error, you can freely retry the - * payment in full. - * - * The results here are ordered the same as the paths in the route object which was passed to - * send_payment. - */ - LDKPaymentSendFailure_PathParameterError, - /** - * All paths which were attempted failed to send, with no channel state change taking place. - * You can freely retry the payment in full (though you probably want to do so over different - * paths than the ones selected). - */ - LDKPaymentSendFailure_AllFailedRetrySafe, - /** - * Some paths which were attempted failed to send, though possibly not all. At least some - * paths have irrevocably committed to the HTLC and retrying the payment in full would result - * in over-/re-payment. - * - * The results here are ordered the same as the paths in the route object which was passed to - * send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely - * retried (though there is currently no API with which to do so). - * - * Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried - * as they will result in over-/re-payment. These HTLCs all either successfully sent (in the - * case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel - * with the latest update_id. - */ - LDKPaymentSendFailure_PartialFailure, - /** - * Must be last for serialization purposes - */ - LDKPaymentSendFailure_Sentinel, -} LDKPaymentSendFailure_Tag; - -typedef struct MUST_USE_STRUCT LDKPaymentSendFailure { - LDKPaymentSendFailure_Tag tag; - union { - struct { - struct LDKAPIError parameter_error; - }; - struct { - struct LDKCVec_CResult_NoneAPIErrorZZ path_parameter_error; - }; - struct { - struct LDKCVec_APIErrorZ all_failed_retry_safe; - }; - struct { - struct LDKCVec_CResult_NoneAPIErrorZZ partial_failure; - }; - }; -} LDKPaymentSendFailure; - -typedef union LDKCResult_NonePaymentSendFailureZPtr { - /** - * Note that this value is always NULL, as there are no contents in the OK variant - */ - void *result; - struct LDKPaymentSendFailure *err; -} LDKCResult_NonePaymentSendFailureZPtr; - -typedef struct LDKCResult_NonePaymentSendFailureZ { - union LDKCResult_NonePaymentSendFailureZPtr contents; - bool result_ok; -} LDKCResult_NonePaymentSendFailureZ; - -typedef struct LDKCVec_ChannelMonitorZ { - struct LDKChannelMonitor *data; - uintptr_t datalen; -} LDKCVec_ChannelMonitorZ; - -/** - * The `Watch` trait defines behavior for watching on-chain activity pertaining to channels as - * blocks are connected and disconnected. - * - * Each channel is associated with a [`ChannelMonitor`]. Implementations of this trait are - * responsible for maintaining a set of monitors such that they can be updated accordingly as - * channel state changes and HTLCs are resolved. See method documentation for specific - * requirements. - * - * Implementations **must** ensure that updates are successfully applied and persisted upon method - * completion. If an update fails with a [`PermanentFailure`], then it must immediately shut down - * without taking any further action such as persisting the current state. - * - * If an implementation maintains multiple instances of a channel's monitor (e.g., by storing - * backup copies), then it must ensure that updates are applied across all instances. Otherwise, it - * could result in a revoked transaction being broadcast, allowing the counterparty to claim all - * funds in the channel. See [`ChannelMonitorUpdateErr`] for more details about how to handle - * multiple instances. - * - * [`ChannelMonitor`]: channelmonitor/struct.ChannelMonitor.html - * [`ChannelMonitorUpdateErr`]: channelmonitor/enum.ChannelMonitorUpdateErr.html - * [`PermanentFailure`]: channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.PermanentFailure - */ -typedef struct LDKWatch { - void *this_arg; - /** - * Watches a channel identified by `funding_txo` using `monitor`. - * - * Implementations are responsible for watching the chain for the funding transaction along - * with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means - * calling [`block_connected`] and [`block_disconnected`] on the monitor. - * - * [`get_outputs_to_watch`]: channelmonitor/struct.ChannelMonitor.html#method.get_outputs_to_watch - * [`block_connected`]: channelmonitor/struct.ChannelMonitor.html#method.block_connected - * [`block_disconnected`]: channelmonitor/struct.ChannelMonitor.html#method.block_disconnected - */ - struct LDKCResult_NoneChannelMonitorUpdateErrZ (*watch_channel)(const void *this_arg, struct LDKOutPoint funding_txo, struct LDKChannelMonitor monitor); - /** - * Updates a channel identified by `funding_txo` by applying `update` to its monitor. - * - * Implementations must call [`update_monitor`] with the given update. See - * [`ChannelMonitorUpdateErr`] for invariants around returning an error. - * - * [`update_monitor`]: channelmonitor/struct.ChannelMonitor.html#method.update_monitor - * [`ChannelMonitorUpdateErr`]: channelmonitor/enum.ChannelMonitorUpdateErr.html - */ - struct LDKCResult_NoneChannelMonitorUpdateErrZ (*update_channel)(const void *this_arg, struct LDKOutPoint funding_txo, struct LDKChannelMonitorUpdate update); - /** - * Returns any monitor events since the last call. Subsequent calls must only return new - * events. - */ - struct LDKCVec_MonitorEventZ (*release_pending_monitor_events)(const void *this_arg); - void (*free)(void *this_arg); -} LDKWatch; - -/** - * An interface to send a transaction to the Bitcoin network. - */ -typedef struct LDKBroadcasterInterface { - void *this_arg; - /** - * Sends a transaction out to (hopefully) be mined. - */ - void (*broadcast_transaction)(const void *this_arg, struct LDKTransaction tx); - void (*free)(void *this_arg); -} LDKBroadcasterInterface; - -typedef union LDKCResult_SignDecodeErrorZPtr { - struct LDKSign *result; - struct LDKDecodeError *err; -} LDKCResult_SignDecodeErrorZPtr; - -typedef struct LDKCResult_SignDecodeErrorZ { - union LDKCResult_SignDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_SignDecodeErrorZ; - -typedef struct LDKu8slice { - const uint8_t *data; - uintptr_t datalen; -} LDKu8slice; - -/** - * A trait to describe an object which can get user secrets and key material. - */ -typedef struct LDKKeysInterface { - void *this_arg; - /** - * Get node secret key (aka node_id or network_key). - * - * This method must return the same value each time it is called. - */ - struct LDKSecretKey (*get_node_secret)(const void *this_arg); - /** - * Get a script pubkey which we send funds to when claiming on-chain contestable outputs. - * - * This method should return a different value each time it is called, to avoid linking - * on-chain funds across channels as controlled to the same user. - */ - struct LDKCVec_u8Z (*get_destination_script)(const void *this_arg); - /** - * Get a public key which we will send funds to (in the form of a P2WPKH output) when closing - * a channel. - * - * This method should return a different value each time it is called, to avoid linking - * on-chain funds across channels as controlled to the same user. - */ - struct LDKPublicKey (*get_shutdown_pubkey)(const void *this_arg); - /** - * Get a new set of Sign for per-channel secrets. These MUST be unique even if you - * restarted with some stale data! - * - * This method must return a different value each time it is called. - */ - struct LDKSign (*get_channel_signer)(const void *this_arg, bool inbound, uint64_t channel_value_satoshis); - /** - * Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting - * onion packets and for temporary channel IDs. There is no requirement that these be - * persisted anywhere, though they must be unique across restarts. - * - * This method must return a different value each time it is called. - */ - struct LDKThirtyTwoBytes (*get_secure_random_bytes)(const void *this_arg); - /** - * Reads a `Signer` for this `KeysInterface` from the given input stream. - * This is only called during deserialization of other objects which contain - * `Sign`-implementing objects (ie `ChannelMonitor`s and `ChannelManager`s). - * The bytes are exactly those which `::write()` writes, and - * contain no versioning scheme. You may wish to include your own version prefix and ensure - * you've read all of the provided bytes to ensure no corruption occurred. - */ - struct LDKCResult_SignDecodeErrorZ (*read_chan_signer)(const void *this_arg, struct LDKu8slice reader); - void (*free)(void *this_arg); -} LDKKeysInterface; - -/** - * A trait which should be implemented to provide feerate information on a number of time - * horizons. - * - * Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're - * called from inside the library in response to chain events, P2P events, or timer events). - */ -typedef struct LDKFeeEstimator { - void *this_arg; - /** - * Gets estimated satoshis of fee required per 1000 Weight-Units. - * - * Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs - * don't put us below 1 satoshi-per-byte). - * - * This translates to: - * * satoshis-per-byte * 250 - * * ceil(satoshis-per-kbyte / 4) - */ - uint32_t (*get_est_sat_per_1000_weight)(const void *this_arg, enum LDKConfirmationTarget confirmation_target); - void (*free)(void *this_arg); -} LDKFeeEstimator; - -/** - * A trait encapsulating the operations required of a logger - */ -typedef struct LDKLogger { - void *this_arg; - /** - * Logs the `Record` - */ - void (*log)(const void *this_arg, const char *record); - void (*free)(void *this_arg); -} LDKLogger; - - - -/** - * Manager which keeps track of a number of channels and sends messages to the appropriate - * channel, also tracking HTLC preimages and forwarding onion packets appropriately. - * - * Implements ChannelMessageHandler, handling the multi-channel parts and passing things through - * to individual Channels. - * - * Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for - * all peers during write/read (though does not modify this instance, only the instance being - * serialized). This will result in any channels which have not yet exchanged funding_created (ie - * called funding_transaction_generated for outbound channels). - * - * Note that you can be a bit lazier about writing out ChannelManager than you can be with - * ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before - * returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates - * happens out-of-band (and will prevent any other ChannelManager operations from occurring during - * the serialization process). If the deserialized version is out-of-date compared to the - * ChannelMonitors passed by reference to read(), those channels will be force-closed based on the - * ChannelMonitor state and no funds will be lost (mod on-chain transaction fees). - * - * Note that the deserializer is only implemented for (BlockHash, ChannelManager), which - * tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along - * the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call - * block_connected() to step towards your best block) upon deserialization before using the - * object! - * - * Note that ChannelManager is responsible for tracking liveness of its channels and generating - * ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid - * spam due to quick disconnection/reconnection, updates are not sent until the channel has been - * offline for a full minute. In order to track this, you must call - * timer_chan_freshness_every_min roughly once per minute, though it doesn't have to be perfect. - * - * Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager - * a SimpleRefChannelManager, for conciseness. See their documentation for more details, but - * essentially you should default to using a SimpleRefChannelManager, and use a - * SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when - * you're using lightning-net-tokio. - */ -typedef struct MUST_USE_STRUCT LDKChannelManager { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelManager *inner; - bool is_owned; -} LDKChannelManager; - -typedef struct LDKC2Tuple_BlockHashChannelManagerZ { - struct LDKThirtyTwoBytes a; - struct LDKChannelManager b; -} LDKC2Tuple_BlockHashChannelManagerZ; - -typedef union LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZPtr { - struct LDKC2Tuple_BlockHashChannelManagerZ *result; - struct LDKDecodeError *err; -} LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZPtr; - -typedef struct LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ { - union LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ; - -typedef union LDKCResult_SpendableOutputDescriptorDecodeErrorZPtr { - struct LDKSpendableOutputDescriptor *result; - struct LDKDecodeError *err; -} LDKCResult_SpendableOutputDescriptorDecodeErrorZPtr; - -typedef struct LDKCResult_SpendableOutputDescriptorDecodeErrorZ { - union LDKCResult_SpendableOutputDescriptorDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_SpendableOutputDescriptorDecodeErrorZ; - -typedef struct LDKCVec_CVec_u8ZZ { - struct LDKCVec_u8Z *data; - uintptr_t datalen; -} LDKCVec_CVec_u8ZZ; - -typedef union LDKCResult_CVec_CVec_u8ZZNoneZPtr { - struct LDKCVec_CVec_u8ZZ *result; - /** - * Note that this value is always NULL, as there are no contents in the Err variant - */ - void *err; -} LDKCResult_CVec_CVec_u8ZZNoneZPtr; - -typedef struct LDKCResult_CVec_CVec_u8ZZNoneZ { - union LDKCResult_CVec_CVec_u8ZZNoneZPtr contents; - bool result_ok; -} LDKCResult_CVec_CVec_u8ZZNoneZ; - - - -/** - * A simple implementation of Sign that just keeps the private keys in memory. - * - * This implementation performs no policy checks and is insufficient by itself as - * a secure external signer. - */ -typedef struct MUST_USE_STRUCT LDKInMemorySigner { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeInMemorySigner *inner; - bool is_owned; -} LDKInMemorySigner; - -typedef union LDKCResult_InMemorySignerDecodeErrorZPtr { - struct LDKInMemorySigner *result; - struct LDKDecodeError *err; -} LDKCResult_InMemorySignerDecodeErrorZPtr; - -typedef struct LDKCResult_InMemorySignerDecodeErrorZ { - union LDKCResult_InMemorySignerDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_InMemorySignerDecodeErrorZ; - -typedef struct LDKCVec_TxOutZ { - struct LDKTxOut *data; - uintptr_t datalen; -} LDKCVec_TxOutZ; - -typedef union LDKCResult_TransactionNoneZPtr { - struct LDKTransaction *result; - /** - * Note that this value is always NULL, as there are no contents in the Err variant - */ - void *err; -} LDKCResult_TransactionNoneZPtr; - -typedef struct LDKCResult_TransactionNoneZ { - union LDKCResult_TransactionNoneZPtr contents; - bool result_ok; -} LDKCResult_TransactionNoneZ; - - - -/** - * A hop in a route - */ -typedef struct MUST_USE_STRUCT LDKRouteHop { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeRouteHop *inner; - bool is_owned; -} LDKRouteHop; - -typedef struct LDKCVec_RouteHopZ { - struct LDKRouteHop *data; - uintptr_t datalen; -} LDKCVec_RouteHopZ; - -typedef struct LDKCVec_CVec_RouteHopZZ { - struct LDKCVec_RouteHopZ *data; - uintptr_t datalen; -} LDKCVec_CVec_RouteHopZZ; - - - -/** - * A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP, - * it can take multiple paths. Each path is composed of one or more hops through the network. - */ -typedef struct MUST_USE_STRUCT LDKRoute { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeRoute *inner; - bool is_owned; -} LDKRoute; - -typedef union LDKCResult_RouteDecodeErrorZPtr { - struct LDKRoute *result; - struct LDKDecodeError *err; -} LDKCResult_RouteDecodeErrorZPtr; - -typedef struct LDKCResult_RouteDecodeErrorZ { - union LDKCResult_RouteDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_RouteDecodeErrorZ; - - - -/** - * A channel descriptor which provides a last-hop route to get_route - */ -typedef struct MUST_USE_STRUCT LDKRouteHint { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeRouteHint *inner; - bool is_owned; -} LDKRouteHint; - -typedef struct LDKCVec_RouteHintZ { - struct LDKRouteHint *data; - uintptr_t datalen; -} LDKCVec_RouteHintZ; - -typedef union LDKCResult_RouteLightningErrorZPtr { - struct LDKRoute *result; - struct LDKLightningError *err; -} LDKCResult_RouteLightningErrorZPtr; - -typedef struct LDKCResult_RouteLightningErrorZ { - union LDKCResult_RouteLightningErrorZPtr contents; - bool result_ok; -} LDKCResult_RouteLightningErrorZ; - -typedef union LDKCResult_NetAddressu8ZPtr { - struct LDKNetAddress *result; - uint8_t *err; -} LDKCResult_NetAddressu8ZPtr; - -typedef struct LDKCResult_NetAddressu8Z { - union LDKCResult_NetAddressu8ZPtr contents; - bool result_ok; -} LDKCResult_NetAddressu8Z; - -typedef union LDKCResult_CResult_NetAddressu8ZDecodeErrorZPtr { - struct LDKCResult_NetAddressu8Z *result; - struct LDKDecodeError *err; -} LDKCResult_CResult_NetAddressu8ZDecodeErrorZPtr; - -typedef struct LDKCResult_CResult_NetAddressu8ZDecodeErrorZ { - union LDKCResult_CResult_NetAddressu8ZDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_CResult_NetAddressu8ZDecodeErrorZ; - - - -/** - * An update_add_htlc message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKUpdateAddHTLC { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeUpdateAddHTLC *inner; - bool is_owned; -} LDKUpdateAddHTLC; - -typedef struct LDKCVec_UpdateAddHTLCZ { - struct LDKUpdateAddHTLC *data; - uintptr_t datalen; -} LDKCVec_UpdateAddHTLCZ; - - - -/** - * An update_fulfill_htlc message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKUpdateFulfillHTLC { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeUpdateFulfillHTLC *inner; - bool is_owned; -} LDKUpdateFulfillHTLC; - -typedef struct LDKCVec_UpdateFulfillHTLCZ { - struct LDKUpdateFulfillHTLC *data; - uintptr_t datalen; -} LDKCVec_UpdateFulfillHTLCZ; - - - -/** - * An update_fail_htlc message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKUpdateFailHTLC { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeUpdateFailHTLC *inner; - bool is_owned; -} LDKUpdateFailHTLC; - -typedef struct LDKCVec_UpdateFailHTLCZ { - struct LDKUpdateFailHTLC *data; - uintptr_t datalen; -} LDKCVec_UpdateFailHTLCZ; - - - -/** - * An update_fail_malformed_htlc message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKUpdateFailMalformedHTLC { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeUpdateFailMalformedHTLC *inner; - bool is_owned; -} LDKUpdateFailMalformedHTLC; - -typedef struct LDKCVec_UpdateFailMalformedHTLCZ { - struct LDKUpdateFailMalformedHTLC *data; - uintptr_t datalen; -} LDKCVec_UpdateFailMalformedHTLCZ; - -typedef union LDKCResult_AcceptChannelDecodeErrorZPtr { - struct LDKAcceptChannel *result; - struct LDKDecodeError *err; -} LDKCResult_AcceptChannelDecodeErrorZPtr; - -typedef struct LDKCResult_AcceptChannelDecodeErrorZ { - union LDKCResult_AcceptChannelDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_AcceptChannelDecodeErrorZ; - -typedef union LDKCResult_AnnouncementSignaturesDecodeErrorZPtr { - struct LDKAnnouncementSignatures *result; - struct LDKDecodeError *err; -} LDKCResult_AnnouncementSignaturesDecodeErrorZPtr; - -typedef struct LDKCResult_AnnouncementSignaturesDecodeErrorZ { - union LDKCResult_AnnouncementSignaturesDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_AnnouncementSignaturesDecodeErrorZ; - -typedef union LDKCResult_ChannelReestablishDecodeErrorZPtr { - struct LDKChannelReestablish *result; - struct LDKDecodeError *err; -} LDKCResult_ChannelReestablishDecodeErrorZPtr; - -typedef struct LDKCResult_ChannelReestablishDecodeErrorZ { - union LDKCResult_ChannelReestablishDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ChannelReestablishDecodeErrorZ; - -typedef union LDKCResult_ClosingSignedDecodeErrorZPtr { - struct LDKClosingSigned *result; - struct LDKDecodeError *err; -} LDKCResult_ClosingSignedDecodeErrorZPtr; - -typedef struct LDKCResult_ClosingSignedDecodeErrorZ { - union LDKCResult_ClosingSignedDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ClosingSignedDecodeErrorZ; - - - -/** - * A commitment_signed message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKCommitmentSigned { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeCommitmentSigned *inner; - bool is_owned; -} LDKCommitmentSigned; - -typedef union LDKCResult_CommitmentSignedDecodeErrorZPtr { - struct LDKCommitmentSigned *result; - struct LDKDecodeError *err; -} LDKCResult_CommitmentSignedDecodeErrorZPtr; - -typedef struct LDKCResult_CommitmentSignedDecodeErrorZ { - union LDKCResult_CommitmentSignedDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_CommitmentSignedDecodeErrorZ; - -typedef union LDKCResult_FundingCreatedDecodeErrorZPtr { - struct LDKFundingCreated *result; - struct LDKDecodeError *err; -} LDKCResult_FundingCreatedDecodeErrorZPtr; - -typedef struct LDKCResult_FundingCreatedDecodeErrorZ { - union LDKCResult_FundingCreatedDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_FundingCreatedDecodeErrorZ; - -typedef union LDKCResult_FundingSignedDecodeErrorZPtr { - struct LDKFundingSigned *result; - struct LDKDecodeError *err; -} LDKCResult_FundingSignedDecodeErrorZPtr; - -typedef struct LDKCResult_FundingSignedDecodeErrorZ { - union LDKCResult_FundingSignedDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_FundingSignedDecodeErrorZ; - -typedef union LDKCResult_FundingLockedDecodeErrorZPtr { - struct LDKFundingLocked *result; - struct LDKDecodeError *err; -} LDKCResult_FundingLockedDecodeErrorZPtr; - -typedef struct LDKCResult_FundingLockedDecodeErrorZ { - union LDKCResult_FundingLockedDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_FundingLockedDecodeErrorZ; - - - -/** - * An init message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKInit { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeInit *inner; - bool is_owned; -} LDKInit; - -typedef union LDKCResult_InitDecodeErrorZPtr { - struct LDKInit *result; - struct LDKDecodeError *err; -} LDKCResult_InitDecodeErrorZPtr; - -typedef struct LDKCResult_InitDecodeErrorZ { - union LDKCResult_InitDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_InitDecodeErrorZ; - -typedef union LDKCResult_OpenChannelDecodeErrorZPtr { - struct LDKOpenChannel *result; - struct LDKDecodeError *err; -} LDKCResult_OpenChannelDecodeErrorZPtr; - -typedef struct LDKCResult_OpenChannelDecodeErrorZ { - union LDKCResult_OpenChannelDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_OpenChannelDecodeErrorZ; - -typedef union LDKCResult_RevokeAndACKDecodeErrorZPtr { - struct LDKRevokeAndACK *result; - struct LDKDecodeError *err; -} LDKCResult_RevokeAndACKDecodeErrorZPtr; - -typedef struct LDKCResult_RevokeAndACKDecodeErrorZ { - union LDKCResult_RevokeAndACKDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_RevokeAndACKDecodeErrorZ; - -typedef union LDKCResult_ShutdownDecodeErrorZPtr { - struct LDKShutdown *result; - struct LDKDecodeError *err; -} LDKCResult_ShutdownDecodeErrorZPtr; - -typedef struct LDKCResult_ShutdownDecodeErrorZ { - union LDKCResult_ShutdownDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ShutdownDecodeErrorZ; - -typedef union LDKCResult_UpdateFailHTLCDecodeErrorZPtr { - struct LDKUpdateFailHTLC *result; - struct LDKDecodeError *err; -} LDKCResult_UpdateFailHTLCDecodeErrorZPtr; - -typedef struct LDKCResult_UpdateFailHTLCDecodeErrorZ { - union LDKCResult_UpdateFailHTLCDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_UpdateFailHTLCDecodeErrorZ; - -typedef union LDKCResult_UpdateFailMalformedHTLCDecodeErrorZPtr { - struct LDKUpdateFailMalformedHTLC *result; - struct LDKDecodeError *err; -} LDKCResult_UpdateFailMalformedHTLCDecodeErrorZPtr; - -typedef struct LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ { - union LDKCResult_UpdateFailMalformedHTLCDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ; - - - -/** - * An update_fee message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKUpdateFee { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeUpdateFee *inner; - bool is_owned; -} LDKUpdateFee; - -typedef union LDKCResult_UpdateFeeDecodeErrorZPtr { - struct LDKUpdateFee *result; - struct LDKDecodeError *err; -} LDKCResult_UpdateFeeDecodeErrorZPtr; - -typedef struct LDKCResult_UpdateFeeDecodeErrorZ { - union LDKCResult_UpdateFeeDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_UpdateFeeDecodeErrorZ; - -typedef union LDKCResult_UpdateFulfillHTLCDecodeErrorZPtr { - struct LDKUpdateFulfillHTLC *result; - struct LDKDecodeError *err; -} LDKCResult_UpdateFulfillHTLCDecodeErrorZPtr; - -typedef struct LDKCResult_UpdateFulfillHTLCDecodeErrorZ { - union LDKCResult_UpdateFulfillHTLCDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_UpdateFulfillHTLCDecodeErrorZ; - -typedef union LDKCResult_UpdateAddHTLCDecodeErrorZPtr { - struct LDKUpdateAddHTLC *result; - struct LDKDecodeError *err; -} LDKCResult_UpdateAddHTLCDecodeErrorZPtr; - -typedef struct LDKCResult_UpdateAddHTLCDecodeErrorZ { - union LDKCResult_UpdateAddHTLCDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_UpdateAddHTLCDecodeErrorZ; - - - -/** - * A ping message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKPing { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativePing *inner; - bool is_owned; -} LDKPing; - -typedef union LDKCResult_PingDecodeErrorZPtr { - struct LDKPing *result; - struct LDKDecodeError *err; -} LDKCResult_PingDecodeErrorZPtr; - -typedef struct LDKCResult_PingDecodeErrorZ { - union LDKCResult_PingDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_PingDecodeErrorZ; - - - -/** - * A pong message to be sent or received from a peer - */ -typedef struct MUST_USE_STRUCT LDKPong { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativePong *inner; - bool is_owned; -} LDKPong; - -typedef union LDKCResult_PongDecodeErrorZPtr { - struct LDKPong *result; - struct LDKDecodeError *err; -} LDKCResult_PongDecodeErrorZPtr; - -typedef struct LDKCResult_PongDecodeErrorZ { - union LDKCResult_PongDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_PongDecodeErrorZ; - -typedef union LDKCResult_UnsignedChannelAnnouncementDecodeErrorZPtr { - struct LDKUnsignedChannelAnnouncement *result; - struct LDKDecodeError *err; -} LDKCResult_UnsignedChannelAnnouncementDecodeErrorZPtr; - -typedef struct LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ { - union LDKCResult_UnsignedChannelAnnouncementDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ; - -typedef union LDKCResult_ChannelAnnouncementDecodeErrorZPtr { - struct LDKChannelAnnouncement *result; - struct LDKDecodeError *err; -} LDKCResult_ChannelAnnouncementDecodeErrorZPtr; - -typedef struct LDKCResult_ChannelAnnouncementDecodeErrorZ { - union LDKCResult_ChannelAnnouncementDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ChannelAnnouncementDecodeErrorZ; - - - -/** - * The unsigned part of a channel_update - */ -typedef struct MUST_USE_STRUCT LDKUnsignedChannelUpdate { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeUnsignedChannelUpdate *inner; - bool is_owned; -} LDKUnsignedChannelUpdate; - -typedef union LDKCResult_UnsignedChannelUpdateDecodeErrorZPtr { - struct LDKUnsignedChannelUpdate *result; - struct LDKDecodeError *err; -} LDKCResult_UnsignedChannelUpdateDecodeErrorZPtr; - -typedef struct LDKCResult_UnsignedChannelUpdateDecodeErrorZ { - union LDKCResult_UnsignedChannelUpdateDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_UnsignedChannelUpdateDecodeErrorZ; - -typedef union LDKCResult_ChannelUpdateDecodeErrorZPtr { - struct LDKChannelUpdate *result; - struct LDKDecodeError *err; -} LDKCResult_ChannelUpdateDecodeErrorZPtr; - -typedef struct LDKCResult_ChannelUpdateDecodeErrorZ { - union LDKCResult_ChannelUpdateDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ChannelUpdateDecodeErrorZ; - -typedef union LDKCResult_ErrorMessageDecodeErrorZPtr { - struct LDKErrorMessage *result; - struct LDKDecodeError *err; -} LDKCResult_ErrorMessageDecodeErrorZPtr; - -typedef struct LDKCResult_ErrorMessageDecodeErrorZ { - union LDKCResult_ErrorMessageDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ErrorMessageDecodeErrorZ; - - - -/** - * The unsigned part of a node_announcement - */ -typedef struct MUST_USE_STRUCT LDKUnsignedNodeAnnouncement { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeUnsignedNodeAnnouncement *inner; - bool is_owned; -} LDKUnsignedNodeAnnouncement; - -typedef union LDKCResult_UnsignedNodeAnnouncementDecodeErrorZPtr { - struct LDKUnsignedNodeAnnouncement *result; - struct LDKDecodeError *err; -} LDKCResult_UnsignedNodeAnnouncementDecodeErrorZPtr; - -typedef struct LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ { - union LDKCResult_UnsignedNodeAnnouncementDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ; - -typedef union LDKCResult_NodeAnnouncementDecodeErrorZPtr { - struct LDKNodeAnnouncement *result; - struct LDKDecodeError *err; -} LDKCResult_NodeAnnouncementDecodeErrorZPtr; - -typedef struct LDKCResult_NodeAnnouncementDecodeErrorZ { - union LDKCResult_NodeAnnouncementDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_NodeAnnouncementDecodeErrorZ; - -typedef union LDKCResult_QueryShortChannelIdsDecodeErrorZPtr { - struct LDKQueryShortChannelIds *result; - struct LDKDecodeError *err; -} LDKCResult_QueryShortChannelIdsDecodeErrorZPtr; - -typedef struct LDKCResult_QueryShortChannelIdsDecodeErrorZ { - union LDKCResult_QueryShortChannelIdsDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_QueryShortChannelIdsDecodeErrorZ; - - - -/** - * A reply_short_channel_ids_end message is sent as a reply to a - * query_short_channel_ids message. The query recipient makes a best - * effort to respond based on their local network view which may not be - * a perfect view of the network. - */ -typedef struct MUST_USE_STRUCT LDKReplyShortChannelIdsEnd { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeReplyShortChannelIdsEnd *inner; - bool is_owned; -} LDKReplyShortChannelIdsEnd; - -typedef union LDKCResult_ReplyShortChannelIdsEndDecodeErrorZPtr { - struct LDKReplyShortChannelIdsEnd *result; - struct LDKDecodeError *err; -} LDKCResult_ReplyShortChannelIdsEndDecodeErrorZPtr; - -typedef struct LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ { - union LDKCResult_ReplyShortChannelIdsEndDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ; - -typedef union LDKCResult_QueryChannelRangeDecodeErrorZPtr { - struct LDKQueryChannelRange *result; - struct LDKDecodeError *err; -} LDKCResult_QueryChannelRangeDecodeErrorZPtr; - -typedef struct LDKCResult_QueryChannelRangeDecodeErrorZ { - union LDKCResult_QueryChannelRangeDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_QueryChannelRangeDecodeErrorZ; - - - -/** - * A reply_channel_range message is a reply to a query_channel_range - * message. Multiple reply_channel_range messages can be sent in reply - * to a single query_channel_range message. The query recipient makes a - * best effort to respond based on their local network view which may - * not be a perfect view of the network. The short_channel_ids in the - * reply are encoded. We only support encoding_type=0 uncompressed - * serialization and do not support encoding_type=1 zlib serialization. - */ -typedef struct MUST_USE_STRUCT LDKReplyChannelRange { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeReplyChannelRange *inner; - bool is_owned; -} LDKReplyChannelRange; - -typedef union LDKCResult_ReplyChannelRangeDecodeErrorZPtr { - struct LDKReplyChannelRange *result; - struct LDKDecodeError *err; -} LDKCResult_ReplyChannelRangeDecodeErrorZPtr; - -typedef struct LDKCResult_ReplyChannelRangeDecodeErrorZ { - union LDKCResult_ReplyChannelRangeDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_ReplyChannelRangeDecodeErrorZ; - - - -/** - * A gossip_timestamp_filter message is used by a node to request - * gossip relay for messages in the requested time range when the - * gossip_queries feature has been negotiated. - */ -typedef struct MUST_USE_STRUCT LDKGossipTimestampFilter { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeGossipTimestampFilter *inner; - bool is_owned; -} LDKGossipTimestampFilter; - -typedef union LDKCResult_GossipTimestampFilterDecodeErrorZPtr { - struct LDKGossipTimestampFilter *result; - struct LDKDecodeError *err; -} LDKCResult_GossipTimestampFilterDecodeErrorZPtr; - -typedef struct LDKCResult_GossipTimestampFilterDecodeErrorZ { - union LDKCResult_GossipTimestampFilterDecodeErrorZPtr contents; - bool result_ok; -} LDKCResult_GossipTimestampFilterDecodeErrorZ; - -/** - * A trait indicating an object may generate message send events - */ -typedef struct LDKMessageSendEventsProvider { - void *this_arg; - /** - * Gets the list of pending events which were generated by previous actions, clearing the list - * in the process. - */ - struct LDKCVec_MessageSendEventZ (*get_and_clear_pending_msg_events)(const void *this_arg); - void (*free)(void *this_arg); -} LDKMessageSendEventsProvider; - -/** - * A trait indicating an object may generate events - */ -typedef struct LDKEventsProvider { - void *this_arg; - /** - * Gets the list of pending events which were generated by previous actions, clearing the list - * in the process. - */ - struct LDKCVec_EventZ (*get_and_clear_pending_events)(const void *this_arg); - void (*free)(void *this_arg); -} LDKEventsProvider; - - - -/** - * Configuration we set when applicable. - * - * Default::default() provides sane defaults. - */ -typedef struct MUST_USE_STRUCT LDKChannelHandshakeConfig { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelHandshakeConfig *inner; - bool is_owned; -} LDKChannelHandshakeConfig; - - - -/** - * Optional channel limits which are applied during channel creation. - * - * These limits are only applied to our counterparty's limits, not our own. - * - * Use 0/::max_value() as appropriate to skip checking. - * - * Provides sane defaults for most configurations. - * - * Most additional limits are disabled except those with which specify a default in individual - * field documentation. Note that this may result in barely-usable channels, but since they - * are applied mostly only to incoming channels that's not much of a problem. - */ -typedef struct MUST_USE_STRUCT LDKChannelHandshakeLimits { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelHandshakeLimits *inner; - bool is_owned; -} LDKChannelHandshakeLimits; - - - -/** - * Top-level config which holds ChannelHandshakeLimits and ChannelConfig. - * - * Default::default() provides sane defaults for most configurations - * (but currently with 0 relay fees!) - */ -typedef struct MUST_USE_STRUCT LDKUserConfig { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeUserConfig *inner; - bool is_owned; -} LDKUserConfig; - -/** - * The `Access` trait defines behavior for accessing chain data and state, such as blocks and - * UTXOs. - */ -typedef struct LDKAccess { - void *this_arg; - /** - * Returns the transaction output of a funding transaction encoded by [`short_channel_id`]. - * Returns an error if `genesis_hash` is for a different chain or if such a transaction output - * is unknown. - * - * [`short_channel_id`]: https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md#definition-of-short_channel_id - */ - struct LDKCResult_TxOutAccessErrorZ (*get_utxo)(const void *this_arg, const uint8_t (*genesis_hash)[32], uint64_t short_channel_id); - void (*free)(void *this_arg); -} LDKAccess; - -/** - * The `Listen` trait is used to be notified of when blocks have been connected or disconnected - * from the chain. - * - * Useful when needing to replay chain data upon startup or as new chain events occur. - */ -typedef struct LDKListen { - void *this_arg; - /** - * Notifies the listener that a block was added at the given height. - */ - void (*block_connected)(const void *this_arg, struct LDKu8slice block, uint32_t height); - /** - * Notifies the listener that a block was removed at the given height. - */ - void (*block_disconnected)(const void *this_arg, const uint8_t (*header)[80], uint32_t height); - void (*free)(void *this_arg); -} LDKListen; - -/** - * The `Filter` trait defines behavior for indicating chain activity of interest pertaining to - * channels. - * - * This is useful in order to have a [`Watch`] implementation convey to a chain source which - * transactions to be notified of. Notification may take the form of pre-filtering blocks or, in - * the case of [BIP 157]/[BIP 158], only fetching a block if the compact filter matches. If - * receiving full blocks from a chain source, any further filtering is unnecessary. - * - * After an output has been registered, subsequent block retrievals from the chain source must not - * exclude any transactions matching the new criteria nor any in-block descendants of such - * transactions. - * - * Note that use as part of a [`Watch`] implementation involves reentrancy. Therefore, the `Filter` - * should not block on I/O. Implementations should instead queue the newly monitored data to be - * processed later. Then, in order to block until the data has been processed, any `Watch` - * invocation that has called the `Filter` must return [`TemporaryFailure`]. - * - * [`Watch`]: trait.Watch.html - * [`TemporaryFailure`]: channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.TemporaryFailure - * [BIP 157]: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki - * [BIP 158]: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki - */ -typedef struct LDKFilter { - void *this_arg; - /** - * Registers interest in a transaction with `txid` and having an output with `script_pubkey` as - * a spending condition. - */ - void (*register_tx)(const void *this_arg, const uint8_t (*txid)[32], struct LDKu8slice script_pubkey); - /** - * Registers interest in spends of a transaction output identified by `outpoint` having - * `script_pubkey` as the spending condition. - */ - void (*register_output)(const void *this_arg, const struct LDKOutPoint *NONNULL_PTR outpoint, struct LDKu8slice script_pubkey); - void (*free)(void *this_arg); -} LDKFilter; - -/** - * `Persist` defines behavior for persisting channel monitors: this could mean - * writing once to disk, and/or uploading to one or more backup services. - * - * Note that for every new monitor, you **must** persist the new `ChannelMonitor` - * to disk/backups. And, on every update, you **must** persist either the - * `ChannelMonitorUpdate` or the updated monitor itself. Otherwise, there is risk - * of situations such as revoking a transaction, then crashing before this - * revocation can be persisted, then unintentionally broadcasting a revoked - * transaction and losing money. This is a risk because previous channel states - * are toxic, so it's important that whatever channel state is persisted is - * kept up-to-date. - */ -typedef struct LDKPersist { - void *this_arg; - /** - * Persist a new channel's data. The data can be stored any way you want, but - * the identifier provided by Rust-Lightning is the channel's outpoint (and - * it is up to you to maintain a correct mapping between the outpoint and the - * stored channel data). Note that you **must** persist every new monitor to - * disk. See the `Persist` trait documentation for more details. - * - * See [`ChannelMonitor::serialize_for_disk`] for writing out a `ChannelMonitor`, - * and [`ChannelMonitorUpdateErr`] for requirements when returning errors. - * - * [`ChannelMonitor::serialize_for_disk`]: struct.ChannelMonitor.html#method.serialize_for_disk - * [`ChannelMonitorUpdateErr`]: enum.ChannelMonitorUpdateErr.html - */ - struct LDKCResult_NoneChannelMonitorUpdateErrZ (*persist_new_channel)(const void *this_arg, struct LDKOutPoint id, const struct LDKChannelMonitor *NONNULL_PTR data); - /** - * Update one channel's data. The provided `ChannelMonitor` has already - * applied the given update. - * - * Note that on every update, you **must** persist either the - * `ChannelMonitorUpdate` or the updated monitor itself to disk/backups. See - * the `Persist` trait documentation for more details. - * - * If an implementer chooses to persist the updates only, they need to make - * sure that all the updates are applied to the `ChannelMonitors` *before* - * the set of channel monitors is given to the `ChannelManager` - * deserialization routine. See [`ChannelMonitor::update_monitor`] for - * applying a monitor update to a monitor. If full `ChannelMonitors` are - * persisted, then there is no need to persist individual updates. - * - * Note that there could be a performance tradeoff between persisting complete - * channel monitors on every update vs. persisting only updates and applying - * them in batches. The size of each monitor grows `O(number of state updates)` - * whereas updates are small and `O(1)`. - * - * See [`ChannelMonitor::serialize_for_disk`] for writing out a `ChannelMonitor`, - * [`ChannelMonitorUpdate::write`] for writing out an update, and - * [`ChannelMonitorUpdateErr`] for requirements when returning errors. - * - * [`ChannelMonitor::update_monitor`]: struct.ChannelMonitor.html#impl-1 - * [`ChannelMonitor::serialize_for_disk`]: struct.ChannelMonitor.html#method.serialize_for_disk - * [`ChannelMonitorUpdate::write`]: struct.ChannelMonitorUpdate.html#method.write - * [`ChannelMonitorUpdateErr`]: enum.ChannelMonitorUpdateErr.html - */ - struct LDKCResult_NoneChannelMonitorUpdateErrZ (*update_persisted_channel)(const void *this_arg, struct LDKOutPoint id, const struct LDKChannelMonitorUpdate *NONNULL_PTR update, const struct LDKChannelMonitor *NONNULL_PTR data); - void (*free)(void *this_arg); -} LDKPersist; - - - -/** - * An implementation of [`chain::Watch`] for monitoring channels. - * - * Connected and disconnected blocks must be provided to `ChainMonitor` as documented by - * [`chain::Watch`]. May be used in conjunction with [`ChannelManager`] to monitor channels locally - * or used independently to monitor channels remotely. See the [module-level documentation] for - * details. - * - * [`chain::Watch`]: ../trait.Watch.html - * [`ChannelManager`]: ../../ln/channelmanager/struct.ChannelManager.html - * [module-level documentation]: index.html - */ -typedef struct MUST_USE_STRUCT LDKChainMonitor { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChainMonitor *inner; - bool is_owned; -} LDKChainMonitor; - - - -/** - * Simple KeysInterface implementor that takes a 32-byte seed for use as a BIP 32 extended key - * and derives keys from that. - * - * Your node_id is seed/0' - * ChannelMonitor closes may use seed/1' - * Cooperative closes may use seed/2' - * The two close keys may be needed to claim on-chain funds! - */ -typedef struct MUST_USE_STRUCT LDKKeysManager { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeKeysManager *inner; - bool is_owned; -} LDKKeysManager; - - - -/** - * Chain-related parameters used to construct a new `ChannelManager`. - * - * Typically, the block-specific parameters are derived from the best block hash for the network, - * as a newly constructed `ChannelManager` will not have created any channels yet. These parameters - * are not needed when deserializing a previously constructed `ChannelManager`. - */ -typedef struct MUST_USE_STRUCT LDKChainParameters { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChainParameters *inner; - bool is_owned; -} LDKChainParameters; - -typedef struct LDKThreeBytes { - uint8_t data[3]; -} LDKThreeBytes; - -/** - * A trait to describe an object which can receive channel messages. - * - * Messages MAY be called in parallel when they originate from different their_node_ids, however - * they MUST NOT be called in parallel when the two calls have the same their_node_id. - */ -typedef struct LDKChannelMessageHandler { - void *this_arg; - /** - * Handle an incoming open_channel message from the given peer. - */ - void (*handle_open_channel)(const void *this_arg, struct LDKPublicKey their_node_id, struct LDKInitFeatures their_features, const struct LDKOpenChannel *NONNULL_PTR msg); - /** - * Handle an incoming accept_channel message from the given peer. - */ - void (*handle_accept_channel)(const void *this_arg, struct LDKPublicKey their_node_id, struct LDKInitFeatures their_features, const struct LDKAcceptChannel *NONNULL_PTR msg); - /** - * Handle an incoming funding_created message from the given peer. - */ - void (*handle_funding_created)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKFundingCreated *NONNULL_PTR msg); - /** - * Handle an incoming funding_signed message from the given peer. - */ - void (*handle_funding_signed)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKFundingSigned *NONNULL_PTR msg); - /** - * Handle an incoming funding_locked message from the given peer. - */ - void (*handle_funding_locked)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKFundingLocked *NONNULL_PTR msg); - /** - * Handle an incoming shutdown message from the given peer. - */ - void (*handle_shutdown)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKInitFeatures *NONNULL_PTR their_features, const struct LDKShutdown *NONNULL_PTR msg); - /** - * Handle an incoming closing_signed message from the given peer. - */ - void (*handle_closing_signed)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKClosingSigned *NONNULL_PTR msg); - /** - * Handle an incoming update_add_htlc message from the given peer. - */ - void (*handle_update_add_htlc)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateAddHTLC *NONNULL_PTR msg); - /** - * Handle an incoming update_fulfill_htlc message from the given peer. - */ - void (*handle_update_fulfill_htlc)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateFulfillHTLC *NONNULL_PTR msg); - /** - * Handle an incoming update_fail_htlc message from the given peer. - */ - void (*handle_update_fail_htlc)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateFailHTLC *NONNULL_PTR msg); - /** - * Handle an incoming update_fail_malformed_htlc message from the given peer. - */ - void (*handle_update_fail_malformed_htlc)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateFailMalformedHTLC *NONNULL_PTR msg); - /** - * Handle an incoming commitment_signed message from the given peer. - */ - void (*handle_commitment_signed)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKCommitmentSigned *NONNULL_PTR msg); - /** - * Handle an incoming revoke_and_ack message from the given peer. - */ - void (*handle_revoke_and_ack)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKRevokeAndACK *NONNULL_PTR msg); - /** - * Handle an incoming update_fee message from the given peer. - */ - void (*handle_update_fee)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateFee *NONNULL_PTR msg); - /** - * Handle an incoming announcement_signatures message from the given peer. - */ - void (*handle_announcement_signatures)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKAnnouncementSignatures *NONNULL_PTR msg); - /** - * Indicates a connection to the peer failed/an existing connection was lost. If no connection - * is believed to be possible in the future (eg they're sending us messages we don't - * understand or indicate they require unknown feature bits), no_connection_possible is set - * and any outstanding channels should be failed. - */ - void (*peer_disconnected)(const void *this_arg, struct LDKPublicKey their_node_id, bool no_connection_possible); - /** - * Handle a peer reconnecting, possibly generating channel_reestablish message(s). - */ - void (*peer_connected)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKInit *NONNULL_PTR msg); - /** - * Handle an incoming channel_reestablish message from the given peer. - */ - void (*handle_channel_reestablish)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKChannelReestablish *NONNULL_PTR msg); - /** - * Handle an incoming error message from the given peer. - */ - void (*handle_error)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKErrorMessage *NONNULL_PTR msg); - struct LDKMessageSendEventsProvider MessageSendEventsProvider; - void (*free)(void *this_arg); -} LDKChannelMessageHandler; - - - -/** - * Arguments for the creation of a ChannelManager that are not deserialized. - * - * At a high-level, the process for deserializing a ChannelManager and resuming normal operation - * is: - * 1) Deserialize all stored ChannelMonitors. - * 2) Deserialize the ChannelManager by filling in this struct and calling: - * <(BlockHash, ChannelManager)>::read(reader, args) - * This may result in closing some Channels if the ChannelMonitor is newer than the stored - * ChannelManager state to ensure no loss of funds. Thus, transactions may be broadcasted. - * 3) If you are not fetching full blocks, register all relevant ChannelMonitor outpoints the same - * way you would handle a `chain::Filter` call using ChannelMonitor::get_outputs_to_watch() and - * ChannelMonitor::get_funding_txo(). - * 4) Reconnect blocks on your ChannelMonitors. - * 5) Disconnect/connect blocks on the ChannelManager. - * 6) Move the ChannelMonitors into your local chain::Watch. - * - * Note that the ordering of #4-6 is not of importance, however all three must occur before you - * call any other methods on the newly-deserialized ChannelManager. - * - * Note that because some channels may be closed during deserialization, it is critical that you - * always deserialize only the latest version of a ChannelManager and ChannelMonitors available to - * you. If you deserialize an old ChannelManager (during which force-closure transactions may be - * broadcast), and then later deserialize a newer version of the same ChannelManager (which will - * not force-close the same channels but consider them live), you may end up revoking a state for - * which you've already broadcasted the transaction. - */ -typedef struct MUST_USE_STRUCT LDKChannelManagerReadArgs { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeChannelManagerReadArgs *inner; - bool is_owned; -} LDKChannelManagerReadArgs; - - - -/** - * Proof that the sender knows the per-commitment secret of the previous commitment transaction. - * This is used to convince the recipient that the channel is at a certain commitment - * number even if they lost that data due to a local failure. Of course, the peer may lie - * and even later commitments may have been revoked. - */ -typedef struct MUST_USE_STRUCT LDKDataLossProtect { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeDataLossProtect *inner; - bool is_owned; -} LDKDataLossProtect; - -/** - * A trait to describe an object which can receive routing messages. - * - * # Implementor DoS Warnings - * - * For `gossip_queries` messages there are potential DoS vectors when handling - * inbound queries. Implementors using an on-disk network graph should be aware of - * repeated disk I/O for queries accessing different parts of the network graph. - */ -typedef struct LDKRoutingMessageHandler { - void *this_arg; - /** - * Handle an incoming node_announcement message, returning true if it should be forwarded on, - * false or returning an Err otherwise. - */ - struct LDKCResult_boolLightningErrorZ (*handle_node_announcement)(const void *this_arg, const struct LDKNodeAnnouncement *NONNULL_PTR msg); - /** - * Handle a channel_announcement message, returning true if it should be forwarded on, false - * or returning an Err otherwise. - */ - struct LDKCResult_boolLightningErrorZ (*handle_channel_announcement)(const void *this_arg, const struct LDKChannelAnnouncement *NONNULL_PTR msg); - /** - * Handle an incoming channel_update message, returning true if it should be forwarded on, - * false or returning an Err otherwise. - */ - struct LDKCResult_boolLightningErrorZ (*handle_channel_update)(const void *this_arg, const struct LDKChannelUpdate *NONNULL_PTR msg); - /** - * Handle some updates to the route graph that we learned due to an outbound failed payment. - */ - void (*handle_htlc_fail_channel_update)(const void *this_arg, const struct LDKHTLCFailChannelUpdate *NONNULL_PTR update); - /** - * Gets a subset of the channel announcements and updates required to dump our routing table - * to a remote node, starting at the short_channel_id indicated by starting_point and - * including the batch_amount entries immediately higher in numerical value than starting_point. - */ - struct LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ (*get_next_channel_announcements)(const void *this_arg, uint64_t starting_point, uint8_t batch_amount); - /** - * Gets a subset of the node announcements required to dump our routing table to a remote node, - * starting at the node *after* the provided publickey and including batch_amount entries - * immediately higher (as defined by ::cmp) than starting_point. - * If None is provided for starting_point, we start at the first node. - */ - struct LDKCVec_NodeAnnouncementZ (*get_next_node_announcements)(const void *this_arg, struct LDKPublicKey starting_point, uint8_t batch_amount); - /** - * Called when a connection is established with a peer. This can be used to - * perform routing table synchronization using a strategy defined by the - * implementor. - */ - void (*sync_routing_table)(const void *this_arg, struct LDKPublicKey their_node_id, const struct LDKInit *NONNULL_PTR init); - /** - * Handles the reply of a query we initiated to learn about channels - * for a given range of blocks. We can expect to receive one or more - * replies to a single query. - */ - struct LDKCResult_NoneLightningErrorZ (*handle_reply_channel_range)(const void *this_arg, struct LDKPublicKey their_node_id, struct LDKReplyChannelRange msg); - /** - * Handles the reply of a query we initiated asking for routing gossip - * messages for a list of channels. We should receive this message when - * a node has completed its best effort to send us the pertaining routing - * gossip messages. - */ - struct LDKCResult_NoneLightningErrorZ (*handle_reply_short_channel_ids_end)(const void *this_arg, struct LDKPublicKey their_node_id, struct LDKReplyShortChannelIdsEnd msg); - /** - * Handles when a peer asks us to send a list of short_channel_ids - * for the requested range of blocks. - */ - struct LDKCResult_NoneLightningErrorZ (*handle_query_channel_range)(const void *this_arg, struct LDKPublicKey their_node_id, struct LDKQueryChannelRange msg); - /** - * Handles when a peer asks us to send routing gossip messages for a - * list of short_channel_ids. - */ - struct LDKCResult_NoneLightningErrorZ (*handle_query_short_channel_ids)(const void *this_arg, struct LDKPublicKey their_node_id, struct LDKQueryShortChannelIds msg); - struct LDKMessageSendEventsProvider MessageSendEventsProvider; - void (*free)(void *this_arg); -} LDKRoutingMessageHandler; - - - -/** - * A dummy struct which implements `RoutingMessageHandler` without storing any routing information - * or doing any processing. You can provide one of these as the route_handler in a MessageHandler. - */ -typedef struct MUST_USE_STRUCT LDKIgnoringMessageHandler { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeIgnoringMessageHandler *inner; - bool is_owned; -} LDKIgnoringMessageHandler; - - - -/** - * A dummy struct which implements `ChannelMessageHandler` without having any channels. - * You can provide one of these as the route_handler in a MessageHandler. - */ -typedef struct MUST_USE_STRUCT LDKErroringMessageHandler { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeErroringMessageHandler *inner; - bool is_owned; -} LDKErroringMessageHandler; - - - -/** - * Provides references to trait impls which handle different types of messages. - */ -typedef struct MUST_USE_STRUCT LDKMessageHandler { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeMessageHandler *inner; - bool is_owned; -} LDKMessageHandler; - -/** - * Provides an object which can be used to send data to and which uniquely identifies a connection - * to a remote host. You will need to be able to generate multiple of these which meet Eq and - * implement Hash to meet the PeerManager API. - * - * For efficiency, Clone should be relatively cheap for this type. - * - * You probably want to just extend an int and put a file descriptor in a struct and implement - * send_data. Note that if you are using a higher-level net library that may call close() itself, - * be careful to ensure you don't have races whereby you might register a new connection with an - * fd which is the same as a previous one which has yet to be removed via - * PeerManager::socket_disconnected(). - */ -typedef struct LDKSocketDescriptor { - void *this_arg; - /** - * Attempts to send some data from the given slice to the peer. - * - * Returns the amount of data which was sent, possibly 0 if the socket has since disconnected. - * Note that in the disconnected case, socket_disconnected must still fire and further write - * attempts may occur until that time. - * - * If the returned size is smaller than data.len(), a write_available event must - * trigger the next time more data can be written. Additionally, until the a send_data event - * completes fully, no further read_events should trigger on the same peer! - * - * If a read_event on this descriptor had previously returned true (indicating that read - * events should be paused to prevent DoS in the send buffer), resume_read may be set - * indicating that read events on this descriptor should resume. A resume_read of false does - * *not* imply that further read events should be paused. - */ - uintptr_t (*send_data)(void *this_arg, struct LDKu8slice data, bool resume_read); - /** - * Disconnect the socket pointed to by this SocketDescriptor. Once this function returns, no - * more calls to write_buffer_space_avail, read_event or socket_disconnected may be made with - * this descriptor. No socket_disconnected call should be generated as a result of this call, - * though races may occur whereby disconnect_socket is called after a call to - * socket_disconnected but prior to socket_disconnected returning. - */ - void (*disconnect_socket)(void *this_arg); - bool (*eq)(const void *this_arg, const struct LDKSocketDescriptor *NONNULL_PTR other_arg); - uint64_t (*hash)(const void *this_arg); - void *(*clone)(const void *this_arg); - void (*free)(void *this_arg); -} LDKSocketDescriptor; - - - -/** - * A PeerManager manages a set of peers, described by their SocketDescriptor and marshalls socket - * events into messages which it passes on to its MessageHandlers. - * - * Rather than using a plain PeerManager, it is preferable to use either a SimpleArcPeerManager - * a SimpleRefPeerManager, for conciseness. See their documentation for more details, but - * essentially you should default to using a SimpleRefPeerManager, and use a - * SimpleArcPeerManager when you require a PeerManager with a static lifetime, such as when - * you're using lightning-net-tokio. - */ -typedef struct MUST_USE_STRUCT LDKPeerManager { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativePeerManager *inner; - bool is_owned; -} LDKPeerManager; - - - -/** - * Static channel fields used to build transactions given per-commitment fields, organized by - * broadcaster/countersignatory. - * - * This is derived from the holder/counterparty-organized ChannelTransactionParameters via the - * as_holder_broadcastable and as_counterparty_broadcastable functions. - */ -typedef struct MUST_USE_STRUCT LDKDirectedChannelTransactionParameters { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeDirectedChannelTransactionParameters *inner; - bool is_owned; -} LDKDirectedChannelTransactionParameters; - - - -/** - * A simple newtype for RwLockReadGuard<'a, NetworkGraph>. - * This exists only to make accessing a RwLock possible from - * the C bindings, as it can be done directly in Rust code. - */ -typedef struct MUST_USE_STRUCT LDKLockedNetworkGraph { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeLockedNetworkGraph *inner; - bool is_owned; -} LDKLockedNetworkGraph; - - - -/** - * Receives and validates network updates from peers, - * stores authentic and relevant data as a network graph. - * This network graph is then used for routing payments. - * Provides interface to help with initial routing sync by - * serving historical announcements. - */ -typedef struct MUST_USE_STRUCT LDKNetGraphMsgHandler { - /** - * Nearly everywhere, inner must be non-null, however in places where - * the Rust equivalent takes an Option, it may be set to null to indicate None. - */ - LDKnativeNetGraphMsgHandler *inner; - bool is_owned; -} LDKNetGraphMsgHandler; - -extern const uintptr_t MAX_BUF_SIZE; - -extern const uint64_t MIN_RELAY_FEE_SAT_PER_1000_WEIGHT; - -extern const uint64_t CLOSED_CHANNEL_UPDATE_ID; - -extern const uintptr_t REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH; - -void Transaction_free(struct LDKTransaction _res); - -void TxOut_free(struct LDKTxOut _res); - -struct LDKTxOut TxOut_clone(const struct LDKTxOut *NONNULL_PTR orig); - -struct LDKCResult_SecretKeyErrorZ CResult_SecretKeyErrorZ_ok(struct LDKSecretKey o); - -struct LDKCResult_SecretKeyErrorZ CResult_SecretKeyErrorZ_err(enum LDKSecp256k1Error e); - -void CResult_SecretKeyErrorZ_free(struct LDKCResult_SecretKeyErrorZ _res); - -struct LDKCResult_PublicKeyErrorZ CResult_PublicKeyErrorZ_ok(struct LDKPublicKey o); - -struct LDKCResult_PublicKeyErrorZ CResult_PublicKeyErrorZ_err(enum LDKSecp256k1Error e); - -void CResult_PublicKeyErrorZ_free(struct LDKCResult_PublicKeyErrorZ _res); - -struct LDKCResult_TxCreationKeysDecodeErrorZ CResult_TxCreationKeysDecodeErrorZ_ok(struct LDKTxCreationKeys o); - -struct LDKCResult_TxCreationKeysDecodeErrorZ CResult_TxCreationKeysDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_TxCreationKeysDecodeErrorZ_free(struct LDKCResult_TxCreationKeysDecodeErrorZ _res); - -struct LDKCResult_TxCreationKeysDecodeErrorZ CResult_TxCreationKeysDecodeErrorZ_clone(const struct LDKCResult_TxCreationKeysDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_ChannelPublicKeysDecodeErrorZ CResult_ChannelPublicKeysDecodeErrorZ_ok(struct LDKChannelPublicKeys o); - -struct LDKCResult_ChannelPublicKeysDecodeErrorZ CResult_ChannelPublicKeysDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ChannelPublicKeysDecodeErrorZ_free(struct LDKCResult_ChannelPublicKeysDecodeErrorZ _res); - -struct LDKCResult_ChannelPublicKeysDecodeErrorZ CResult_ChannelPublicKeysDecodeErrorZ_clone(const struct LDKCResult_ChannelPublicKeysDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_TxCreationKeysErrorZ CResult_TxCreationKeysErrorZ_ok(struct LDKTxCreationKeys o); - -struct LDKCResult_TxCreationKeysErrorZ CResult_TxCreationKeysErrorZ_err(enum LDKSecp256k1Error e); - -void CResult_TxCreationKeysErrorZ_free(struct LDKCResult_TxCreationKeysErrorZ _res); - -struct LDKCResult_HTLCOutputInCommitmentDecodeErrorZ CResult_HTLCOutputInCommitmentDecodeErrorZ_ok(struct LDKHTLCOutputInCommitment o); - -struct LDKCResult_HTLCOutputInCommitmentDecodeErrorZ CResult_HTLCOutputInCommitmentDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_HTLCOutputInCommitmentDecodeErrorZ_free(struct LDKCResult_HTLCOutputInCommitmentDecodeErrorZ _res); - -struct LDKCResult_HTLCOutputInCommitmentDecodeErrorZ CResult_HTLCOutputInCommitmentDecodeErrorZ_clone(const struct LDKCResult_HTLCOutputInCommitmentDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ CResult_CounterpartyChannelTransactionParametersDecodeErrorZ_ok(struct LDKCounterpartyChannelTransactionParameters o); - -struct LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ CResult_CounterpartyChannelTransactionParametersDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_CounterpartyChannelTransactionParametersDecodeErrorZ_free(struct LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ _res); - -struct LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ CResult_CounterpartyChannelTransactionParametersDecodeErrorZ_clone(const struct LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_ChannelTransactionParametersDecodeErrorZ CResult_ChannelTransactionParametersDecodeErrorZ_ok(struct LDKChannelTransactionParameters o); - -struct LDKCResult_ChannelTransactionParametersDecodeErrorZ CResult_ChannelTransactionParametersDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ChannelTransactionParametersDecodeErrorZ_free(struct LDKCResult_ChannelTransactionParametersDecodeErrorZ _res); - -struct LDKCResult_ChannelTransactionParametersDecodeErrorZ CResult_ChannelTransactionParametersDecodeErrorZ_clone(const struct LDKCResult_ChannelTransactionParametersDecodeErrorZ *NONNULL_PTR orig); - -void CVec_SignatureZ_free(struct LDKCVec_SignatureZ _res); - -struct LDKCResult_HolderCommitmentTransactionDecodeErrorZ CResult_HolderCommitmentTransactionDecodeErrorZ_ok(struct LDKHolderCommitmentTransaction o); - -struct LDKCResult_HolderCommitmentTransactionDecodeErrorZ CResult_HolderCommitmentTransactionDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_HolderCommitmentTransactionDecodeErrorZ_free(struct LDKCResult_HolderCommitmentTransactionDecodeErrorZ _res); - -struct LDKCResult_HolderCommitmentTransactionDecodeErrorZ CResult_HolderCommitmentTransactionDecodeErrorZ_clone(const struct LDKCResult_HolderCommitmentTransactionDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_BuiltCommitmentTransactionDecodeErrorZ CResult_BuiltCommitmentTransactionDecodeErrorZ_ok(struct LDKBuiltCommitmentTransaction o); - -struct LDKCResult_BuiltCommitmentTransactionDecodeErrorZ CResult_BuiltCommitmentTransactionDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_BuiltCommitmentTransactionDecodeErrorZ_free(struct LDKCResult_BuiltCommitmentTransactionDecodeErrorZ _res); - -struct LDKCResult_BuiltCommitmentTransactionDecodeErrorZ CResult_BuiltCommitmentTransactionDecodeErrorZ_clone(const struct LDKCResult_BuiltCommitmentTransactionDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_CommitmentTransactionDecodeErrorZ CResult_CommitmentTransactionDecodeErrorZ_ok(struct LDKCommitmentTransaction o); - -struct LDKCResult_CommitmentTransactionDecodeErrorZ CResult_CommitmentTransactionDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_CommitmentTransactionDecodeErrorZ_free(struct LDKCResult_CommitmentTransactionDecodeErrorZ _res); - -struct LDKCResult_CommitmentTransactionDecodeErrorZ CResult_CommitmentTransactionDecodeErrorZ_clone(const struct LDKCResult_CommitmentTransactionDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_TrustedCommitmentTransactionNoneZ CResult_TrustedCommitmentTransactionNoneZ_ok(struct LDKTrustedCommitmentTransaction o); - -struct LDKCResult_TrustedCommitmentTransactionNoneZ CResult_TrustedCommitmentTransactionNoneZ_err(void); - -void CResult_TrustedCommitmentTransactionNoneZ_free(struct LDKCResult_TrustedCommitmentTransactionNoneZ _res); - -struct LDKCResult_CVec_SignatureZNoneZ CResult_CVec_SignatureZNoneZ_ok(struct LDKCVec_SignatureZ o); - -struct LDKCResult_CVec_SignatureZNoneZ CResult_CVec_SignatureZNoneZ_err(void); - -void CResult_CVec_SignatureZNoneZ_free(struct LDKCResult_CVec_SignatureZNoneZ _res); - -struct LDKCResult_CVec_SignatureZNoneZ CResult_CVec_SignatureZNoneZ_clone(const struct LDKCResult_CVec_SignatureZNoneZ *NONNULL_PTR orig); - -void CVec_MessageSendEventZ_free(struct LDKCVec_MessageSendEventZ _res); - -struct LDKCResult_boolLightningErrorZ CResult_boolLightningErrorZ_ok(bool o); - -struct LDKCResult_boolLightningErrorZ CResult_boolLightningErrorZ_err(struct LDKLightningError e); - -void CResult_boolLightningErrorZ_free(struct LDKCResult_boolLightningErrorZ _res); - -struct LDKCResult_boolLightningErrorZ CResult_boolLightningErrorZ_clone(const struct LDKCResult_boolLightningErrorZ *NONNULL_PTR orig); - -struct LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(const struct LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *NONNULL_PTR orig); - -struct LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(struct LDKChannelAnnouncement a, struct LDKChannelUpdate b, struct LDKChannelUpdate c); - -void C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(struct LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ _res); - -void CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(struct LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ _res); - -void CVec_NodeAnnouncementZ_free(struct LDKCVec_NodeAnnouncementZ _res); - -struct LDKCResult_NoneLightningErrorZ CResult_NoneLightningErrorZ_ok(void); - -struct LDKCResult_NoneLightningErrorZ CResult_NoneLightningErrorZ_err(struct LDKLightningError e); - -void CResult_NoneLightningErrorZ_free(struct LDKCResult_NoneLightningErrorZ _res); - -struct LDKCResult_NoneLightningErrorZ CResult_NoneLightningErrorZ_clone(const struct LDKCResult_NoneLightningErrorZ *NONNULL_PTR orig); - -void CVec_PublicKeyZ_free(struct LDKCVec_PublicKeyZ _res); - -void CVec_u8Z_free(struct LDKCVec_u8Z _res); - -struct LDKCResult_CVec_u8ZPeerHandleErrorZ CResult_CVec_u8ZPeerHandleErrorZ_ok(struct LDKCVec_u8Z o); - -struct LDKCResult_CVec_u8ZPeerHandleErrorZ CResult_CVec_u8ZPeerHandleErrorZ_err(struct LDKPeerHandleError e); - -void CResult_CVec_u8ZPeerHandleErrorZ_free(struct LDKCResult_CVec_u8ZPeerHandleErrorZ _res); - -struct LDKCResult_CVec_u8ZPeerHandleErrorZ CResult_CVec_u8ZPeerHandleErrorZ_clone(const struct LDKCResult_CVec_u8ZPeerHandleErrorZ *NONNULL_PTR orig); - -struct LDKCResult_NonePeerHandleErrorZ CResult_NonePeerHandleErrorZ_ok(void); - -struct LDKCResult_NonePeerHandleErrorZ CResult_NonePeerHandleErrorZ_err(struct LDKPeerHandleError e); - -void CResult_NonePeerHandleErrorZ_free(struct LDKCResult_NonePeerHandleErrorZ _res); - -struct LDKCResult_NonePeerHandleErrorZ CResult_NonePeerHandleErrorZ_clone(const struct LDKCResult_NonePeerHandleErrorZ *NONNULL_PTR orig); - -struct LDKCResult_boolPeerHandleErrorZ CResult_boolPeerHandleErrorZ_ok(bool o); - -struct LDKCResult_boolPeerHandleErrorZ CResult_boolPeerHandleErrorZ_err(struct LDKPeerHandleError e); - -void CResult_boolPeerHandleErrorZ_free(struct LDKCResult_boolPeerHandleErrorZ _res); - -struct LDKCResult_boolPeerHandleErrorZ CResult_boolPeerHandleErrorZ_clone(const struct LDKCResult_boolPeerHandleErrorZ *NONNULL_PTR orig); - -struct LDKCResult_InitFeaturesDecodeErrorZ CResult_InitFeaturesDecodeErrorZ_ok(struct LDKInitFeatures o); - -struct LDKCResult_InitFeaturesDecodeErrorZ CResult_InitFeaturesDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_InitFeaturesDecodeErrorZ_free(struct LDKCResult_InitFeaturesDecodeErrorZ _res); - -struct LDKCResult_NodeFeaturesDecodeErrorZ CResult_NodeFeaturesDecodeErrorZ_ok(struct LDKNodeFeatures o); - -struct LDKCResult_NodeFeaturesDecodeErrorZ CResult_NodeFeaturesDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_NodeFeaturesDecodeErrorZ_free(struct LDKCResult_NodeFeaturesDecodeErrorZ _res); - -struct LDKCResult_ChannelFeaturesDecodeErrorZ CResult_ChannelFeaturesDecodeErrorZ_ok(struct LDKChannelFeatures o); - -struct LDKCResult_ChannelFeaturesDecodeErrorZ CResult_ChannelFeaturesDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ChannelFeaturesDecodeErrorZ_free(struct LDKCResult_ChannelFeaturesDecodeErrorZ _res); - -struct LDKCResult_ChannelConfigDecodeErrorZ CResult_ChannelConfigDecodeErrorZ_ok(struct LDKChannelConfig o); - -struct LDKCResult_ChannelConfigDecodeErrorZ CResult_ChannelConfigDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ChannelConfigDecodeErrorZ_free(struct LDKCResult_ChannelConfigDecodeErrorZ _res); - -struct LDKCResult_ChannelConfigDecodeErrorZ CResult_ChannelConfigDecodeErrorZ_clone(const struct LDKCResult_ChannelConfigDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_DirectionalChannelInfoDecodeErrorZ CResult_DirectionalChannelInfoDecodeErrorZ_ok(struct LDKDirectionalChannelInfo o); - -struct LDKCResult_DirectionalChannelInfoDecodeErrorZ CResult_DirectionalChannelInfoDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_DirectionalChannelInfoDecodeErrorZ_free(struct LDKCResult_DirectionalChannelInfoDecodeErrorZ _res); - -struct LDKCResult_DirectionalChannelInfoDecodeErrorZ CResult_DirectionalChannelInfoDecodeErrorZ_clone(const struct LDKCResult_DirectionalChannelInfoDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_ChannelInfoDecodeErrorZ CResult_ChannelInfoDecodeErrorZ_ok(struct LDKChannelInfo o); - -struct LDKCResult_ChannelInfoDecodeErrorZ CResult_ChannelInfoDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ChannelInfoDecodeErrorZ_free(struct LDKCResult_ChannelInfoDecodeErrorZ _res); - -struct LDKCResult_ChannelInfoDecodeErrorZ CResult_ChannelInfoDecodeErrorZ_clone(const struct LDKCResult_ChannelInfoDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_RoutingFeesDecodeErrorZ CResult_RoutingFeesDecodeErrorZ_ok(struct LDKRoutingFees o); - -struct LDKCResult_RoutingFeesDecodeErrorZ CResult_RoutingFeesDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_RoutingFeesDecodeErrorZ_free(struct LDKCResult_RoutingFeesDecodeErrorZ _res); - -struct LDKCResult_RoutingFeesDecodeErrorZ CResult_RoutingFeesDecodeErrorZ_clone(const struct LDKCResult_RoutingFeesDecodeErrorZ *NONNULL_PTR orig); - -void CVec_NetAddressZ_free(struct LDKCVec_NetAddressZ _res); - -struct LDKCResult_NodeAnnouncementInfoDecodeErrorZ CResult_NodeAnnouncementInfoDecodeErrorZ_ok(struct LDKNodeAnnouncementInfo o); - -struct LDKCResult_NodeAnnouncementInfoDecodeErrorZ CResult_NodeAnnouncementInfoDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_NodeAnnouncementInfoDecodeErrorZ_free(struct LDKCResult_NodeAnnouncementInfoDecodeErrorZ _res); - -struct LDKCResult_NodeAnnouncementInfoDecodeErrorZ CResult_NodeAnnouncementInfoDecodeErrorZ_clone(const struct LDKCResult_NodeAnnouncementInfoDecodeErrorZ *NONNULL_PTR orig); - -void CVec_u64Z_free(struct LDKCVec_u64Z _res); - -struct LDKCResult_NodeInfoDecodeErrorZ CResult_NodeInfoDecodeErrorZ_ok(struct LDKNodeInfo o); - -struct LDKCResult_NodeInfoDecodeErrorZ CResult_NodeInfoDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_NodeInfoDecodeErrorZ_free(struct LDKCResult_NodeInfoDecodeErrorZ _res); - -struct LDKCResult_NodeInfoDecodeErrorZ CResult_NodeInfoDecodeErrorZ_clone(const struct LDKCResult_NodeInfoDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_NetworkGraphDecodeErrorZ CResult_NetworkGraphDecodeErrorZ_ok(struct LDKNetworkGraph o); - -struct LDKCResult_NetworkGraphDecodeErrorZ CResult_NetworkGraphDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_NetworkGraphDecodeErrorZ_free(struct LDKCResult_NetworkGraphDecodeErrorZ _res); - -struct LDKCResult_NetworkGraphDecodeErrorZ CResult_NetworkGraphDecodeErrorZ_clone(const struct LDKCResult_NetworkGraphDecodeErrorZ *NONNULL_PTR orig); - -struct LDKC2Tuple_usizeTransactionZ C2Tuple_usizeTransactionZ_new(uintptr_t a, struct LDKTransaction b); - -void C2Tuple_usizeTransactionZ_free(struct LDKC2Tuple_usizeTransactionZ _res); - -void CVec_C2Tuple_usizeTransactionZZ_free(struct LDKCVec_C2Tuple_usizeTransactionZZ _res); - -struct LDKCResult_NoneChannelMonitorUpdateErrZ CResult_NoneChannelMonitorUpdateErrZ_ok(void); - -struct LDKCResult_NoneChannelMonitorUpdateErrZ CResult_NoneChannelMonitorUpdateErrZ_err(enum LDKChannelMonitorUpdateErr e); - -void CResult_NoneChannelMonitorUpdateErrZ_free(struct LDKCResult_NoneChannelMonitorUpdateErrZ _res); - -struct LDKCResult_NoneChannelMonitorUpdateErrZ CResult_NoneChannelMonitorUpdateErrZ_clone(const struct LDKCResult_NoneChannelMonitorUpdateErrZ *NONNULL_PTR orig); - -void CVec_MonitorEventZ_free(struct LDKCVec_MonitorEventZ _res); - -void CVec_EventZ_free(struct LDKCVec_EventZ _res); - -struct LDKCResult_OutPointDecodeErrorZ CResult_OutPointDecodeErrorZ_ok(struct LDKOutPoint o); - -struct LDKCResult_OutPointDecodeErrorZ CResult_OutPointDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_OutPointDecodeErrorZ_free(struct LDKCResult_OutPointDecodeErrorZ _res); - -struct LDKCResult_OutPointDecodeErrorZ CResult_OutPointDecodeErrorZ_clone(const struct LDKCResult_OutPointDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_ChannelMonitorUpdateDecodeErrorZ CResult_ChannelMonitorUpdateDecodeErrorZ_ok(struct LDKChannelMonitorUpdate o); - -struct LDKCResult_ChannelMonitorUpdateDecodeErrorZ CResult_ChannelMonitorUpdateDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ChannelMonitorUpdateDecodeErrorZ_free(struct LDKCResult_ChannelMonitorUpdateDecodeErrorZ _res); - -struct LDKCResult_ChannelMonitorUpdateDecodeErrorZ CResult_ChannelMonitorUpdateDecodeErrorZ_clone(const struct LDKCResult_ChannelMonitorUpdateDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_HTLCUpdateDecodeErrorZ CResult_HTLCUpdateDecodeErrorZ_ok(struct LDKHTLCUpdate o); - -struct LDKCResult_HTLCUpdateDecodeErrorZ CResult_HTLCUpdateDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_HTLCUpdateDecodeErrorZ_free(struct LDKCResult_HTLCUpdateDecodeErrorZ _res); - -struct LDKCResult_HTLCUpdateDecodeErrorZ CResult_HTLCUpdateDecodeErrorZ_clone(const struct LDKCResult_HTLCUpdateDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_NoneMonitorUpdateErrorZ CResult_NoneMonitorUpdateErrorZ_ok(void); - -struct LDKCResult_NoneMonitorUpdateErrorZ CResult_NoneMonitorUpdateErrorZ_err(struct LDKMonitorUpdateError e); - -void CResult_NoneMonitorUpdateErrorZ_free(struct LDKCResult_NoneMonitorUpdateErrorZ _res); - -struct LDKCResult_NoneMonitorUpdateErrorZ CResult_NoneMonitorUpdateErrorZ_clone(const struct LDKCResult_NoneMonitorUpdateErrorZ *NONNULL_PTR orig); - -struct LDKC2Tuple_OutPointScriptZ C2Tuple_OutPointScriptZ_clone(const struct LDKC2Tuple_OutPointScriptZ *NONNULL_PTR orig); - -struct LDKC2Tuple_OutPointScriptZ C2Tuple_OutPointScriptZ_new(struct LDKOutPoint a, struct LDKCVec_u8Z b); - -void C2Tuple_OutPointScriptZ_free(struct LDKC2Tuple_OutPointScriptZ _res); - -void CVec_TransactionZ_free(struct LDKCVec_TransactionZ _res); - -struct LDKC2Tuple_u32TxOutZ C2Tuple_u32TxOutZ_clone(const struct LDKC2Tuple_u32TxOutZ *NONNULL_PTR orig); - -struct LDKC2Tuple_u32TxOutZ C2Tuple_u32TxOutZ_new(uint32_t a, struct LDKTxOut b); - -void C2Tuple_u32TxOutZ_free(struct LDKC2Tuple_u32TxOutZ _res); - -void CVec_C2Tuple_u32TxOutZZ_free(struct LDKCVec_C2Tuple_u32TxOutZZ _res); - -struct LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_new(struct LDKThirtyTwoBytes a, struct LDKCVec_C2Tuple_u32TxOutZZ b); - -void C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_free(struct LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ _res); - -void CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free(struct LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ _res); - -struct LDKC2Tuple_BlockHashChannelMonitorZ C2Tuple_BlockHashChannelMonitorZ_new(struct LDKThirtyTwoBytes a, struct LDKChannelMonitor b); - -void C2Tuple_BlockHashChannelMonitorZ_free(struct LDKC2Tuple_BlockHashChannelMonitorZ _res); - -struct LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_ok(struct LDKC2Tuple_BlockHashChannelMonitorZ o); - -struct LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(struct LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ _res); - -void CVec_SpendableOutputDescriptorZ_free(struct LDKCVec_SpendableOutputDescriptorZ _res); - -struct LDKCResult_TxOutAccessErrorZ CResult_TxOutAccessErrorZ_ok(struct LDKTxOut o); - -struct LDKCResult_TxOutAccessErrorZ CResult_TxOutAccessErrorZ_err(enum LDKAccessError e); - -void CResult_TxOutAccessErrorZ_free(struct LDKCResult_TxOutAccessErrorZ _res); - -struct LDKCResult_TxOutAccessErrorZ CResult_TxOutAccessErrorZ_clone(const struct LDKCResult_TxOutAccessErrorZ *NONNULL_PTR orig); - -struct LDKCResult_NoneAPIErrorZ CResult_NoneAPIErrorZ_ok(void); - -struct LDKCResult_NoneAPIErrorZ CResult_NoneAPIErrorZ_err(struct LDKAPIError e); - -void CResult_NoneAPIErrorZ_free(struct LDKCResult_NoneAPIErrorZ _res); - -struct LDKCResult_NoneAPIErrorZ CResult_NoneAPIErrorZ_clone(const struct LDKCResult_NoneAPIErrorZ *NONNULL_PTR orig); - -void CVec_CResult_NoneAPIErrorZZ_free(struct LDKCVec_CResult_NoneAPIErrorZZ _res); - -void CVec_APIErrorZ_free(struct LDKCVec_APIErrorZ _res); - -void CVec_ChannelDetailsZ_free(struct LDKCVec_ChannelDetailsZ _res); - -struct LDKCResult_NonePaymentSendFailureZ CResult_NonePaymentSendFailureZ_ok(void); - -struct LDKCResult_NonePaymentSendFailureZ CResult_NonePaymentSendFailureZ_err(struct LDKPaymentSendFailure e); - -void CResult_NonePaymentSendFailureZ_free(struct LDKCResult_NonePaymentSendFailureZ _res); - -struct LDKCResult_NonePaymentSendFailureZ CResult_NonePaymentSendFailureZ_clone(const struct LDKCResult_NonePaymentSendFailureZ *NONNULL_PTR orig); - -void CVec_ChannelMonitorZ_free(struct LDKCVec_ChannelMonitorZ _res); - -struct LDKC2Tuple_BlockHashChannelManagerZ C2Tuple_BlockHashChannelManagerZ_new(struct LDKThirtyTwoBytes a, struct LDKChannelManager b); - -void C2Tuple_BlockHashChannelManagerZ_free(struct LDKC2Tuple_BlockHashChannelManagerZ _res); - -struct LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_ok(struct LDKC2Tuple_BlockHashChannelManagerZ o); - -struct LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(struct LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ _res); - -struct LDKCResult_SpendableOutputDescriptorDecodeErrorZ CResult_SpendableOutputDescriptorDecodeErrorZ_ok(struct LDKSpendableOutputDescriptor o); - -struct LDKCResult_SpendableOutputDescriptorDecodeErrorZ CResult_SpendableOutputDescriptorDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_SpendableOutputDescriptorDecodeErrorZ_free(struct LDKCResult_SpendableOutputDescriptorDecodeErrorZ _res); - -struct LDKCResult_SpendableOutputDescriptorDecodeErrorZ CResult_SpendableOutputDescriptorDecodeErrorZ_clone(const struct LDKCResult_SpendableOutputDescriptorDecodeErrorZ *NONNULL_PTR orig); - -struct LDKC2Tuple_SignatureCVec_SignatureZZ C2Tuple_SignatureCVec_SignatureZZ_clone(const struct LDKC2Tuple_SignatureCVec_SignatureZZ *NONNULL_PTR orig); - -struct LDKC2Tuple_SignatureCVec_SignatureZZ C2Tuple_SignatureCVec_SignatureZZ_new(struct LDKSignature a, struct LDKCVec_SignatureZ b); - -void C2Tuple_SignatureCVec_SignatureZZ_free(struct LDKC2Tuple_SignatureCVec_SignatureZZ _res); - -struct LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(struct LDKC2Tuple_SignatureCVec_SignatureZZ o); - -struct LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err(void); - -void CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(struct LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ _res); - -struct LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_clone(const struct LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *NONNULL_PTR orig); - -struct LDKCResult_SignatureNoneZ CResult_SignatureNoneZ_ok(struct LDKSignature o); - -struct LDKCResult_SignatureNoneZ CResult_SignatureNoneZ_err(void); - -void CResult_SignatureNoneZ_free(struct LDKCResult_SignatureNoneZ _res); - -struct LDKCResult_SignatureNoneZ CResult_SignatureNoneZ_clone(const struct LDKCResult_SignatureNoneZ *NONNULL_PTR orig); - -struct LDKCResult_SignDecodeErrorZ CResult_SignDecodeErrorZ_ok(struct LDKSign o); - -struct LDKCResult_SignDecodeErrorZ CResult_SignDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_SignDecodeErrorZ_free(struct LDKCResult_SignDecodeErrorZ _res); - -struct LDKCResult_SignDecodeErrorZ CResult_SignDecodeErrorZ_clone(const struct LDKCResult_SignDecodeErrorZ *NONNULL_PTR orig); - -void CVec_CVec_u8ZZ_free(struct LDKCVec_CVec_u8ZZ _res); - -struct LDKCResult_CVec_CVec_u8ZZNoneZ CResult_CVec_CVec_u8ZZNoneZ_ok(struct LDKCVec_CVec_u8ZZ o); - -struct LDKCResult_CVec_CVec_u8ZZNoneZ CResult_CVec_CVec_u8ZZNoneZ_err(void); - -void CResult_CVec_CVec_u8ZZNoneZ_free(struct LDKCResult_CVec_CVec_u8ZZNoneZ _res); - -struct LDKCResult_CVec_CVec_u8ZZNoneZ CResult_CVec_CVec_u8ZZNoneZ_clone(const struct LDKCResult_CVec_CVec_u8ZZNoneZ *NONNULL_PTR orig); - -struct LDKCResult_InMemorySignerDecodeErrorZ CResult_InMemorySignerDecodeErrorZ_ok(struct LDKInMemorySigner o); - -struct LDKCResult_InMemorySignerDecodeErrorZ CResult_InMemorySignerDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_InMemorySignerDecodeErrorZ_free(struct LDKCResult_InMemorySignerDecodeErrorZ _res); - -struct LDKCResult_InMemorySignerDecodeErrorZ CResult_InMemorySignerDecodeErrorZ_clone(const struct LDKCResult_InMemorySignerDecodeErrorZ *NONNULL_PTR orig); - -void CVec_TxOutZ_free(struct LDKCVec_TxOutZ _res); - -struct LDKCResult_TransactionNoneZ CResult_TransactionNoneZ_ok(struct LDKTransaction o); - -struct LDKCResult_TransactionNoneZ CResult_TransactionNoneZ_err(void); - -void CResult_TransactionNoneZ_free(struct LDKCResult_TransactionNoneZ _res); - -void CVec_RouteHopZ_free(struct LDKCVec_RouteHopZ _res); - -void CVec_CVec_RouteHopZZ_free(struct LDKCVec_CVec_RouteHopZZ _res); - -struct LDKCResult_RouteDecodeErrorZ CResult_RouteDecodeErrorZ_ok(struct LDKRoute o); - -struct LDKCResult_RouteDecodeErrorZ CResult_RouteDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_RouteDecodeErrorZ_free(struct LDKCResult_RouteDecodeErrorZ _res); - -struct LDKCResult_RouteDecodeErrorZ CResult_RouteDecodeErrorZ_clone(const struct LDKCResult_RouteDecodeErrorZ *NONNULL_PTR orig); - -void CVec_RouteHintZ_free(struct LDKCVec_RouteHintZ _res); - -struct LDKCResult_RouteLightningErrorZ CResult_RouteLightningErrorZ_ok(struct LDKRoute o); - -struct LDKCResult_RouteLightningErrorZ CResult_RouteLightningErrorZ_err(struct LDKLightningError e); - -void CResult_RouteLightningErrorZ_free(struct LDKCResult_RouteLightningErrorZ _res); - -struct LDKCResult_RouteLightningErrorZ CResult_RouteLightningErrorZ_clone(const struct LDKCResult_RouteLightningErrorZ *NONNULL_PTR orig); - -struct LDKCResult_NetAddressu8Z CResult_NetAddressu8Z_ok(struct LDKNetAddress o); - -struct LDKCResult_NetAddressu8Z CResult_NetAddressu8Z_err(uint8_t e); - -void CResult_NetAddressu8Z_free(struct LDKCResult_NetAddressu8Z _res); - -struct LDKCResult_NetAddressu8Z CResult_NetAddressu8Z_clone(const struct LDKCResult_NetAddressu8Z *NONNULL_PTR orig); - -struct LDKCResult_CResult_NetAddressu8ZDecodeErrorZ CResult_CResult_NetAddressu8ZDecodeErrorZ_ok(struct LDKCResult_NetAddressu8Z o); - -struct LDKCResult_CResult_NetAddressu8ZDecodeErrorZ CResult_CResult_NetAddressu8ZDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_CResult_NetAddressu8ZDecodeErrorZ_free(struct LDKCResult_CResult_NetAddressu8ZDecodeErrorZ _res); - -struct LDKCResult_CResult_NetAddressu8ZDecodeErrorZ CResult_CResult_NetAddressu8ZDecodeErrorZ_clone(const struct LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *NONNULL_PTR orig); - -void CVec_UpdateAddHTLCZ_free(struct LDKCVec_UpdateAddHTLCZ _res); - -void CVec_UpdateFulfillHTLCZ_free(struct LDKCVec_UpdateFulfillHTLCZ _res); - -void CVec_UpdateFailHTLCZ_free(struct LDKCVec_UpdateFailHTLCZ _res); - -void CVec_UpdateFailMalformedHTLCZ_free(struct LDKCVec_UpdateFailMalformedHTLCZ _res); - -struct LDKCResult_AcceptChannelDecodeErrorZ CResult_AcceptChannelDecodeErrorZ_ok(struct LDKAcceptChannel o); - -struct LDKCResult_AcceptChannelDecodeErrorZ CResult_AcceptChannelDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_AcceptChannelDecodeErrorZ_free(struct LDKCResult_AcceptChannelDecodeErrorZ _res); - -struct LDKCResult_AcceptChannelDecodeErrorZ CResult_AcceptChannelDecodeErrorZ_clone(const struct LDKCResult_AcceptChannelDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_AnnouncementSignaturesDecodeErrorZ CResult_AnnouncementSignaturesDecodeErrorZ_ok(struct LDKAnnouncementSignatures o); - -struct LDKCResult_AnnouncementSignaturesDecodeErrorZ CResult_AnnouncementSignaturesDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_AnnouncementSignaturesDecodeErrorZ_free(struct LDKCResult_AnnouncementSignaturesDecodeErrorZ _res); - -struct LDKCResult_AnnouncementSignaturesDecodeErrorZ CResult_AnnouncementSignaturesDecodeErrorZ_clone(const struct LDKCResult_AnnouncementSignaturesDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_ChannelReestablishDecodeErrorZ CResult_ChannelReestablishDecodeErrorZ_ok(struct LDKChannelReestablish o); - -struct LDKCResult_ChannelReestablishDecodeErrorZ CResult_ChannelReestablishDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ChannelReestablishDecodeErrorZ_free(struct LDKCResult_ChannelReestablishDecodeErrorZ _res); - -struct LDKCResult_ChannelReestablishDecodeErrorZ CResult_ChannelReestablishDecodeErrorZ_clone(const struct LDKCResult_ChannelReestablishDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_ClosingSignedDecodeErrorZ CResult_ClosingSignedDecodeErrorZ_ok(struct LDKClosingSigned o); - -struct LDKCResult_ClosingSignedDecodeErrorZ CResult_ClosingSignedDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ClosingSignedDecodeErrorZ_free(struct LDKCResult_ClosingSignedDecodeErrorZ _res); - -struct LDKCResult_ClosingSignedDecodeErrorZ CResult_ClosingSignedDecodeErrorZ_clone(const struct LDKCResult_ClosingSignedDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_CommitmentSignedDecodeErrorZ CResult_CommitmentSignedDecodeErrorZ_ok(struct LDKCommitmentSigned o); - -struct LDKCResult_CommitmentSignedDecodeErrorZ CResult_CommitmentSignedDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_CommitmentSignedDecodeErrorZ_free(struct LDKCResult_CommitmentSignedDecodeErrorZ _res); - -struct LDKCResult_CommitmentSignedDecodeErrorZ CResult_CommitmentSignedDecodeErrorZ_clone(const struct LDKCResult_CommitmentSignedDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_FundingCreatedDecodeErrorZ CResult_FundingCreatedDecodeErrorZ_ok(struct LDKFundingCreated o); - -struct LDKCResult_FundingCreatedDecodeErrorZ CResult_FundingCreatedDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_FundingCreatedDecodeErrorZ_free(struct LDKCResult_FundingCreatedDecodeErrorZ _res); - -struct LDKCResult_FundingCreatedDecodeErrorZ CResult_FundingCreatedDecodeErrorZ_clone(const struct LDKCResult_FundingCreatedDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_FundingSignedDecodeErrorZ CResult_FundingSignedDecodeErrorZ_ok(struct LDKFundingSigned o); - -struct LDKCResult_FundingSignedDecodeErrorZ CResult_FundingSignedDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_FundingSignedDecodeErrorZ_free(struct LDKCResult_FundingSignedDecodeErrorZ _res); - -struct LDKCResult_FundingSignedDecodeErrorZ CResult_FundingSignedDecodeErrorZ_clone(const struct LDKCResult_FundingSignedDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_FundingLockedDecodeErrorZ CResult_FundingLockedDecodeErrorZ_ok(struct LDKFundingLocked o); - -struct LDKCResult_FundingLockedDecodeErrorZ CResult_FundingLockedDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_FundingLockedDecodeErrorZ_free(struct LDKCResult_FundingLockedDecodeErrorZ _res); - -struct LDKCResult_FundingLockedDecodeErrorZ CResult_FundingLockedDecodeErrorZ_clone(const struct LDKCResult_FundingLockedDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_InitDecodeErrorZ CResult_InitDecodeErrorZ_ok(struct LDKInit o); - -struct LDKCResult_InitDecodeErrorZ CResult_InitDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_InitDecodeErrorZ_free(struct LDKCResult_InitDecodeErrorZ _res); - -struct LDKCResult_InitDecodeErrorZ CResult_InitDecodeErrorZ_clone(const struct LDKCResult_InitDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_OpenChannelDecodeErrorZ CResult_OpenChannelDecodeErrorZ_ok(struct LDKOpenChannel o); - -struct LDKCResult_OpenChannelDecodeErrorZ CResult_OpenChannelDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_OpenChannelDecodeErrorZ_free(struct LDKCResult_OpenChannelDecodeErrorZ _res); - -struct LDKCResult_OpenChannelDecodeErrorZ CResult_OpenChannelDecodeErrorZ_clone(const struct LDKCResult_OpenChannelDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_RevokeAndACKDecodeErrorZ CResult_RevokeAndACKDecodeErrorZ_ok(struct LDKRevokeAndACK o); - -struct LDKCResult_RevokeAndACKDecodeErrorZ CResult_RevokeAndACKDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_RevokeAndACKDecodeErrorZ_free(struct LDKCResult_RevokeAndACKDecodeErrorZ _res); - -struct LDKCResult_RevokeAndACKDecodeErrorZ CResult_RevokeAndACKDecodeErrorZ_clone(const struct LDKCResult_RevokeAndACKDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_ShutdownDecodeErrorZ CResult_ShutdownDecodeErrorZ_ok(struct LDKShutdown o); - -struct LDKCResult_ShutdownDecodeErrorZ CResult_ShutdownDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ShutdownDecodeErrorZ_free(struct LDKCResult_ShutdownDecodeErrorZ _res); - -struct LDKCResult_ShutdownDecodeErrorZ CResult_ShutdownDecodeErrorZ_clone(const struct LDKCResult_ShutdownDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_UpdateFailHTLCDecodeErrorZ CResult_UpdateFailHTLCDecodeErrorZ_ok(struct LDKUpdateFailHTLC o); - -struct LDKCResult_UpdateFailHTLCDecodeErrorZ CResult_UpdateFailHTLCDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_UpdateFailHTLCDecodeErrorZ_free(struct LDKCResult_UpdateFailHTLCDecodeErrorZ _res); - -struct LDKCResult_UpdateFailHTLCDecodeErrorZ CResult_UpdateFailHTLCDecodeErrorZ_clone(const struct LDKCResult_UpdateFailHTLCDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ CResult_UpdateFailMalformedHTLCDecodeErrorZ_ok(struct LDKUpdateFailMalformedHTLC o); - -struct LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ CResult_UpdateFailMalformedHTLCDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_UpdateFailMalformedHTLCDecodeErrorZ_free(struct LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ _res); - -struct LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ CResult_UpdateFailMalformedHTLCDecodeErrorZ_clone(const struct LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_UpdateFeeDecodeErrorZ CResult_UpdateFeeDecodeErrorZ_ok(struct LDKUpdateFee o); - -struct LDKCResult_UpdateFeeDecodeErrorZ CResult_UpdateFeeDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_UpdateFeeDecodeErrorZ_free(struct LDKCResult_UpdateFeeDecodeErrorZ _res); - -struct LDKCResult_UpdateFeeDecodeErrorZ CResult_UpdateFeeDecodeErrorZ_clone(const struct LDKCResult_UpdateFeeDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_UpdateFulfillHTLCDecodeErrorZ CResult_UpdateFulfillHTLCDecodeErrorZ_ok(struct LDKUpdateFulfillHTLC o); - -struct LDKCResult_UpdateFulfillHTLCDecodeErrorZ CResult_UpdateFulfillHTLCDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_UpdateFulfillHTLCDecodeErrorZ_free(struct LDKCResult_UpdateFulfillHTLCDecodeErrorZ _res); - -struct LDKCResult_UpdateFulfillHTLCDecodeErrorZ CResult_UpdateFulfillHTLCDecodeErrorZ_clone(const struct LDKCResult_UpdateFulfillHTLCDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_UpdateAddHTLCDecodeErrorZ CResult_UpdateAddHTLCDecodeErrorZ_ok(struct LDKUpdateAddHTLC o); - -struct LDKCResult_UpdateAddHTLCDecodeErrorZ CResult_UpdateAddHTLCDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_UpdateAddHTLCDecodeErrorZ_free(struct LDKCResult_UpdateAddHTLCDecodeErrorZ _res); - -struct LDKCResult_UpdateAddHTLCDecodeErrorZ CResult_UpdateAddHTLCDecodeErrorZ_clone(const struct LDKCResult_UpdateAddHTLCDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_PingDecodeErrorZ CResult_PingDecodeErrorZ_ok(struct LDKPing o); - -struct LDKCResult_PingDecodeErrorZ CResult_PingDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_PingDecodeErrorZ_free(struct LDKCResult_PingDecodeErrorZ _res); - -struct LDKCResult_PingDecodeErrorZ CResult_PingDecodeErrorZ_clone(const struct LDKCResult_PingDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_PongDecodeErrorZ CResult_PongDecodeErrorZ_ok(struct LDKPong o); - -struct LDKCResult_PongDecodeErrorZ CResult_PongDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_PongDecodeErrorZ_free(struct LDKCResult_PongDecodeErrorZ _res); - -struct LDKCResult_PongDecodeErrorZ CResult_PongDecodeErrorZ_clone(const struct LDKCResult_PongDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ CResult_UnsignedChannelAnnouncementDecodeErrorZ_ok(struct LDKUnsignedChannelAnnouncement o); - -struct LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ CResult_UnsignedChannelAnnouncementDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_UnsignedChannelAnnouncementDecodeErrorZ_free(struct LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ _res); - -struct LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ CResult_UnsignedChannelAnnouncementDecodeErrorZ_clone(const struct LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_ChannelAnnouncementDecodeErrorZ CResult_ChannelAnnouncementDecodeErrorZ_ok(struct LDKChannelAnnouncement o); - -struct LDKCResult_ChannelAnnouncementDecodeErrorZ CResult_ChannelAnnouncementDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ChannelAnnouncementDecodeErrorZ_free(struct LDKCResult_ChannelAnnouncementDecodeErrorZ _res); - -struct LDKCResult_ChannelAnnouncementDecodeErrorZ CResult_ChannelAnnouncementDecodeErrorZ_clone(const struct LDKCResult_ChannelAnnouncementDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_UnsignedChannelUpdateDecodeErrorZ CResult_UnsignedChannelUpdateDecodeErrorZ_ok(struct LDKUnsignedChannelUpdate o); - -struct LDKCResult_UnsignedChannelUpdateDecodeErrorZ CResult_UnsignedChannelUpdateDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_UnsignedChannelUpdateDecodeErrorZ_free(struct LDKCResult_UnsignedChannelUpdateDecodeErrorZ _res); - -struct LDKCResult_UnsignedChannelUpdateDecodeErrorZ CResult_UnsignedChannelUpdateDecodeErrorZ_clone(const struct LDKCResult_UnsignedChannelUpdateDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_ChannelUpdateDecodeErrorZ CResult_ChannelUpdateDecodeErrorZ_ok(struct LDKChannelUpdate o); - -struct LDKCResult_ChannelUpdateDecodeErrorZ CResult_ChannelUpdateDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ChannelUpdateDecodeErrorZ_free(struct LDKCResult_ChannelUpdateDecodeErrorZ _res); - -struct LDKCResult_ChannelUpdateDecodeErrorZ CResult_ChannelUpdateDecodeErrorZ_clone(const struct LDKCResult_ChannelUpdateDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_ErrorMessageDecodeErrorZ CResult_ErrorMessageDecodeErrorZ_ok(struct LDKErrorMessage o); - -struct LDKCResult_ErrorMessageDecodeErrorZ CResult_ErrorMessageDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ErrorMessageDecodeErrorZ_free(struct LDKCResult_ErrorMessageDecodeErrorZ _res); - -struct LDKCResult_ErrorMessageDecodeErrorZ CResult_ErrorMessageDecodeErrorZ_clone(const struct LDKCResult_ErrorMessageDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ CResult_UnsignedNodeAnnouncementDecodeErrorZ_ok(struct LDKUnsignedNodeAnnouncement o); - -struct LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ CResult_UnsignedNodeAnnouncementDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(struct LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ _res); - -struct LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ CResult_UnsignedNodeAnnouncementDecodeErrorZ_clone(const struct LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_NodeAnnouncementDecodeErrorZ CResult_NodeAnnouncementDecodeErrorZ_ok(struct LDKNodeAnnouncement o); - -struct LDKCResult_NodeAnnouncementDecodeErrorZ CResult_NodeAnnouncementDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_NodeAnnouncementDecodeErrorZ_free(struct LDKCResult_NodeAnnouncementDecodeErrorZ _res); - -struct LDKCResult_NodeAnnouncementDecodeErrorZ CResult_NodeAnnouncementDecodeErrorZ_clone(const struct LDKCResult_NodeAnnouncementDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_QueryShortChannelIdsDecodeErrorZ CResult_QueryShortChannelIdsDecodeErrorZ_ok(struct LDKQueryShortChannelIds o); - -struct LDKCResult_QueryShortChannelIdsDecodeErrorZ CResult_QueryShortChannelIdsDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_QueryShortChannelIdsDecodeErrorZ_free(struct LDKCResult_QueryShortChannelIdsDecodeErrorZ _res); - -struct LDKCResult_QueryShortChannelIdsDecodeErrorZ CResult_QueryShortChannelIdsDecodeErrorZ_clone(const struct LDKCResult_QueryShortChannelIdsDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ CResult_ReplyShortChannelIdsEndDecodeErrorZ_ok(struct LDKReplyShortChannelIdsEnd o); - -struct LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ CResult_ReplyShortChannelIdsEndDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ReplyShortChannelIdsEndDecodeErrorZ_free(struct LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ _res); - -struct LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ CResult_ReplyShortChannelIdsEndDecodeErrorZ_clone(const struct LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_QueryChannelRangeDecodeErrorZ CResult_QueryChannelRangeDecodeErrorZ_ok(struct LDKQueryChannelRange o); - -struct LDKCResult_QueryChannelRangeDecodeErrorZ CResult_QueryChannelRangeDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_QueryChannelRangeDecodeErrorZ_free(struct LDKCResult_QueryChannelRangeDecodeErrorZ _res); - -struct LDKCResult_QueryChannelRangeDecodeErrorZ CResult_QueryChannelRangeDecodeErrorZ_clone(const struct LDKCResult_QueryChannelRangeDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_ReplyChannelRangeDecodeErrorZ CResult_ReplyChannelRangeDecodeErrorZ_ok(struct LDKReplyChannelRange o); - -struct LDKCResult_ReplyChannelRangeDecodeErrorZ CResult_ReplyChannelRangeDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_ReplyChannelRangeDecodeErrorZ_free(struct LDKCResult_ReplyChannelRangeDecodeErrorZ _res); - -struct LDKCResult_ReplyChannelRangeDecodeErrorZ CResult_ReplyChannelRangeDecodeErrorZ_clone(const struct LDKCResult_ReplyChannelRangeDecodeErrorZ *NONNULL_PTR orig); - -struct LDKCResult_GossipTimestampFilterDecodeErrorZ CResult_GossipTimestampFilterDecodeErrorZ_ok(struct LDKGossipTimestampFilter o); - -struct LDKCResult_GossipTimestampFilterDecodeErrorZ CResult_GossipTimestampFilterDecodeErrorZ_err(struct LDKDecodeError e); - -void CResult_GossipTimestampFilterDecodeErrorZ_free(struct LDKCResult_GossipTimestampFilterDecodeErrorZ _res); - -struct LDKCResult_GossipTimestampFilterDecodeErrorZ CResult_GossipTimestampFilterDecodeErrorZ_clone(const struct LDKCResult_GossipTimestampFilterDecodeErrorZ *NONNULL_PTR orig); - -void Event_free(struct LDKEvent this_ptr); - -struct LDKEvent Event_clone(const struct LDKEvent *NONNULL_PTR orig); - -struct LDKCVec_u8Z Event_write(const struct LDKEvent *NONNULL_PTR obj); - -void MessageSendEvent_free(struct LDKMessageSendEvent this_ptr); - -struct LDKMessageSendEvent MessageSendEvent_clone(const struct LDKMessageSendEvent *NONNULL_PTR orig); - -/** - * Calls the free function if one is set - */ -void MessageSendEventsProvider_free(struct LDKMessageSendEventsProvider this_ptr); - -/** - * Calls the free function if one is set - */ -void EventsProvider_free(struct LDKEventsProvider this_ptr); - -void APIError_free(struct LDKAPIError this_ptr); - -struct LDKAPIError APIError_clone(const struct LDKAPIError *NONNULL_PTR orig); - -enum LDKLevel Level_clone(const enum LDKLevel *NONNULL_PTR orig); - -/** - * Returns the most verbose logging level. - */ -MUST_USE_RES enum LDKLevel Level_max(void); - -/** - * Calls the free function if one is set - */ -void Logger_free(struct LDKLogger this_ptr); - -void ChannelHandshakeConfig_free(struct LDKChannelHandshakeConfig this_ptr); - -/** - * Confirmations we will wait for before considering the channel locked in. - * Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the - * equivalent limit applied to outbound channels). - * - * Default value: 6. - */ -uint32_t ChannelHandshakeConfig_get_minimum_depth(const struct LDKChannelHandshakeConfig *NONNULL_PTR this_ptr); - -/** - * Confirmations we will wait for before considering the channel locked in. - * Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the - * equivalent limit applied to outbound channels). - * - * Default value: 6. - */ -void ChannelHandshakeConfig_set_minimum_depth(struct LDKChannelHandshakeConfig *NONNULL_PTR this_ptr, uint32_t val); - -/** - * Set to the amount of time we require our counterparty to wait to claim their money. - * - * It's one of the main parameter of our security model. We (or one of our watchtowers) MUST - * be online to check for peer having broadcast a revoked transaction to steal our funds - * at least once every our_to_self_delay blocks. - * - * Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in - * case of an honest unilateral channel close, which implicitly decrease the economic value of - * our channel. - * - * Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel - * opening so you can tweak config to ask for more security, not less. - */ -uint16_t ChannelHandshakeConfig_get_our_to_self_delay(const struct LDKChannelHandshakeConfig *NONNULL_PTR this_ptr); - -/** - * Set to the amount of time we require our counterparty to wait to claim their money. - * - * It's one of the main parameter of our security model. We (or one of our watchtowers) MUST - * be online to check for peer having broadcast a revoked transaction to steal our funds - * at least once every our_to_self_delay blocks. - * - * Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in - * case of an honest unilateral channel close, which implicitly decrease the economic value of - * our channel. - * - * Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel - * opening so you can tweak config to ask for more security, not less. - */ -void ChannelHandshakeConfig_set_our_to_self_delay(struct LDKChannelHandshakeConfig *NONNULL_PTR this_ptr, uint16_t val); - -/** - * Set to the smallest value HTLC we will accept to process. - * - * This value is sent to our counterparty on channel-open and we close the channel any time - * our counterparty misbehaves by sending us an HTLC with a value smaller than this. - * - * Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required - * by the protocol. - */ -uint64_t ChannelHandshakeConfig_get_our_htlc_minimum_msat(const struct LDKChannelHandshakeConfig *NONNULL_PTR this_ptr); - -/** - * Set to the smallest value HTLC we will accept to process. - * - * This value is sent to our counterparty on channel-open and we close the channel any time - * our counterparty misbehaves by sending us an HTLC with a value smaller than this. - * - * Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required - * by the protocol. - */ -void ChannelHandshakeConfig_set_our_htlc_minimum_msat(struct LDKChannelHandshakeConfig *NONNULL_PTR this_ptr, uint64_t val); - -MUST_USE_RES struct LDKChannelHandshakeConfig ChannelHandshakeConfig_new(uint32_t minimum_depth_arg, uint16_t our_to_self_delay_arg, uint64_t our_htlc_minimum_msat_arg); - -struct LDKChannelHandshakeConfig ChannelHandshakeConfig_clone(const struct LDKChannelHandshakeConfig *NONNULL_PTR orig); - -MUST_USE_RES struct LDKChannelHandshakeConfig ChannelHandshakeConfig_default(void); - -void ChannelHandshakeLimits_free(struct LDKChannelHandshakeLimits this_ptr); - -/** - * Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so - * only applies to inbound channels. - * - * Default value: 0. - */ -uint64_t ChannelHandshakeLimits_get_min_funding_satoshis(const struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr); - -/** - * Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so - * only applies to inbound channels. - * - * Default value: 0. - */ -void ChannelHandshakeLimits_set_min_funding_satoshis(struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows - * you to limit the maximum minimum-size they can require. - * - * Default value: u64::max_value. - */ -uint64_t ChannelHandshakeLimits_get_max_htlc_minimum_msat(const struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr); - -/** - * The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows - * you to limit the maximum minimum-size they can require. - * - * Default value: u64::max_value. - */ -void ChannelHandshakeLimits_set_max_htlc_minimum_msat(struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The remote node sets a limit on the maximum value of pending HTLCs to them at any given - * time to limit their funds exposure to HTLCs. This allows you to set a minimum such value. - * - * Default value: 0. - */ -uint64_t ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(const struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr); - -/** - * The remote node sets a limit on the maximum value of pending HTLCs to them at any given - * time to limit their funds exposure to HTLCs. This allows you to set a minimum such value. - * - * Default value: 0. - */ -void ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The remote node will require we keep a certain amount in direct payment to ourselves at all - * time, ensuring that we are able to be punished if we broadcast an old state. This allows to - * you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs). - * - * Default value: u64::max_value. - */ -uint64_t ChannelHandshakeLimits_get_max_channel_reserve_satoshis(const struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr); - -/** - * The remote node will require we keep a certain amount in direct payment to ourselves at all - * time, ensuring that we are able to be punished if we broadcast an old state. This allows to - * you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs). - * - * Default value: u64::max_value. - */ -void ChannelHandshakeLimits_set_max_channel_reserve_satoshis(struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The remote node sets a limit on the maximum number of pending HTLCs to them at any given - * time. This allows you to set a minimum such value. - * - * Default value: 0. - */ -uint16_t ChannelHandshakeLimits_get_min_max_accepted_htlcs(const struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr); - -/** - * The remote node sets a limit on the maximum number of pending HTLCs to them at any given - * time. This allows you to set a minimum such value. - * - * Default value: 0. - */ -void ChannelHandshakeLimits_set_min_max_accepted_htlcs(struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr, uint16_t val); - -/** - * Outputs below a certain value will not be added to on-chain transactions. The dust value is - * required to always be higher than this value so this only applies to HTLC outputs (and - * potentially to-self outputs before any payments have been made). - * Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain. - * This setting allows you to set a minimum dust limit for their commitment transactions, - * reflecting the reality that tiny outputs are not considered standard transactions and will - * not propagate through the Bitcoin network. - * - * Default value: 546, the current dust limit on the Bitcoin network. - */ -uint64_t ChannelHandshakeLimits_get_min_dust_limit_satoshis(const struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr); - -/** - * Outputs below a certain value will not be added to on-chain transactions. The dust value is - * required to always be higher than this value so this only applies to HTLC outputs (and - * potentially to-self outputs before any payments have been made). - * Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain. - * This setting allows you to set a minimum dust limit for their commitment transactions, - * reflecting the reality that tiny outputs are not considered standard transactions and will - * not propagate through the Bitcoin network. - * - * Default value: 546, the current dust limit on the Bitcoin network. - */ -void ChannelHandshakeLimits_set_min_dust_limit_satoshis(struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr, uint64_t val); - -/** - * Maximum allowed threshold above which outputs will not be generated in their commitment - * transactions. - * HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain. - * - * Default value: u64::max_value. - */ -uint64_t ChannelHandshakeLimits_get_max_dust_limit_satoshis(const struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr); - -/** - * Maximum allowed threshold above which outputs will not be generated in their commitment - * transactions. - * HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain. - * - * Default value: u64::max_value. - */ -void ChannelHandshakeLimits_set_max_dust_limit_satoshis(struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr, uint64_t val); - -/** - * Before a channel is usable the funding transaction will need to be confirmed by at least a - * certain number of blocks, specified by the node which is not the funder (as the funder can - * assume they aren't going to double-spend themselves). - * This config allows you to set a limit on the maximum amount of time to wait. - * - * Default value: 144, or roughly one day and only applies to outbound channels. - */ -uint32_t ChannelHandshakeLimits_get_max_minimum_depth(const struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr); - -/** - * Before a channel is usable the funding transaction will need to be confirmed by at least a - * certain number of blocks, specified by the node which is not the funder (as the funder can - * assume they aren't going to double-spend themselves). - * This config allows you to set a limit on the maximum amount of time to wait. - * - * Default value: 144, or roughly one day and only applies to outbound channels. - */ -void ChannelHandshakeLimits_set_max_minimum_depth(struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr, uint32_t val); - -/** - * Set to force the incoming channel to match our announced channel preference in - * ChannelConfig. - * - * Default value: true, to make the default that no announced channels are possible (which is - * appropriate for any nodes which are not online very reliably). - */ -bool ChannelHandshakeLimits_get_force_announced_channel_preference(const struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr); - -/** - * Set to force the incoming channel to match our announced channel preference in - * ChannelConfig. - * - * Default value: true, to make the default that no announced channels are possible (which is - * appropriate for any nodes which are not online very reliably). - */ -void ChannelHandshakeLimits_set_force_announced_channel_preference(struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr, bool val); - -/** - * Set to the amount of time we're willing to wait to claim money back to us. - * - * Not checking this value would be a security issue, as our peer would be able to set it to - * max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time. - * - * Default value: MAX_LOCAL_BREAKDOWN_TIMEOUT (1008), which we also enforce as a maximum value - * so you can tweak config to reduce the loss of having useless locked funds (if your peer accepts) - */ -uint16_t ChannelHandshakeLimits_get_their_to_self_delay(const struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr); - -/** - * Set to the amount of time we're willing to wait to claim money back to us. - * - * Not checking this value would be a security issue, as our peer would be able to set it to - * max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time. - * - * Default value: MAX_LOCAL_BREAKDOWN_TIMEOUT (1008), which we also enforce as a maximum value - * so you can tweak config to reduce the loss of having useless locked funds (if your peer accepts) - */ -void ChannelHandshakeLimits_set_their_to_self_delay(struct LDKChannelHandshakeLimits *NONNULL_PTR this_ptr, uint16_t val); - -MUST_USE_RES struct LDKChannelHandshakeLimits ChannelHandshakeLimits_new(uint64_t min_funding_satoshis_arg, uint64_t max_htlc_minimum_msat_arg, uint64_t min_max_htlc_value_in_flight_msat_arg, uint64_t max_channel_reserve_satoshis_arg, uint16_t min_max_accepted_htlcs_arg, uint64_t min_dust_limit_satoshis_arg, uint64_t max_dust_limit_satoshis_arg, uint32_t max_minimum_depth_arg, bool force_announced_channel_preference_arg, uint16_t their_to_self_delay_arg); - -struct LDKChannelHandshakeLimits ChannelHandshakeLimits_clone(const struct LDKChannelHandshakeLimits *NONNULL_PTR orig); - -MUST_USE_RES struct LDKChannelHandshakeLimits ChannelHandshakeLimits_default(void); - -void ChannelConfig_free(struct LDKChannelConfig this_ptr); - -/** - * 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 - * update messages sent to notify all nodes of our updated relay fee. - * - * Default value: 0. - */ -uint32_t ChannelConfig_get_fee_proportional_millionths(const struct LDKChannelConfig *NONNULL_PTR this_ptr); - -/** - * 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 - * update messages sent to notify all nodes of our updated relay fee. - * - * Default value: 0. - */ -void ChannelConfig_set_fee_proportional_millionths(struct LDKChannelConfig *NONNULL_PTR this_ptr, uint32_t val); - -/** - * Set to announce the channel publicly and notify all nodes that they can route via this - * channel. - * - * This should only be set to true for nodes which expect to be online reliably. - * - * As the node which funds a channel picks this value this will only apply for new outbound - * channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set. - * - * This cannot be changed after the initial channel handshake. - * - * Default value: false. - */ -bool ChannelConfig_get_announced_channel(const struct LDKChannelConfig *NONNULL_PTR this_ptr); - -/** - * Set to announce the channel publicly and notify all nodes that they can route via this - * channel. - * - * This should only be set to true for nodes which expect to be online reliably. - * - * As the node which funds a channel picks this value this will only apply for new outbound - * channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set. - * - * This cannot be changed after the initial channel handshake. - * - * Default value: false. - */ -void ChannelConfig_set_announced_channel(struct LDKChannelConfig *NONNULL_PTR this_ptr, bool val); - -/** - * When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty - * supports it, they will then enforce the mutual-close output to us matches what we provided - * at intialization, preventing us from closing to an alternate pubkey. - * - * This is set to true by default to provide a slight increase in security, though ultimately - * any attacker who is able to take control of a channel can just as easily send the funds via - * lightning payments, so we never require that our counterparties support this option. - * - * This cannot be changed after a channel has been initialized. - * - * Default value: true. - */ -bool ChannelConfig_get_commit_upfront_shutdown_pubkey(const struct LDKChannelConfig *NONNULL_PTR this_ptr); - -/** - * When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty - * supports it, they will then enforce the mutual-close output to us matches what we provided - * at intialization, preventing us from closing to an alternate pubkey. - * - * This is set to true by default to provide a slight increase in security, though ultimately - * any attacker who is able to take control of a channel can just as easily send the funds via - * lightning payments, so we never require that our counterparties support this option. - * - * This cannot be changed after a channel has been initialized. - * - * Default value: true. - */ -void ChannelConfig_set_commit_upfront_shutdown_pubkey(struct LDKChannelConfig *NONNULL_PTR this_ptr, bool val); - -MUST_USE_RES struct LDKChannelConfig ChannelConfig_new(uint32_t fee_proportional_millionths_arg, bool announced_channel_arg, bool commit_upfront_shutdown_pubkey_arg); - -struct LDKChannelConfig ChannelConfig_clone(const struct LDKChannelConfig *NONNULL_PTR orig); - -MUST_USE_RES struct LDKChannelConfig ChannelConfig_default(void); - -struct LDKCVec_u8Z ChannelConfig_write(const struct LDKChannelConfig *NONNULL_PTR obj); - -struct LDKCResult_ChannelConfigDecodeErrorZ ChannelConfig_read(struct LDKu8slice ser); - -void UserConfig_free(struct LDKUserConfig this_ptr); - -/** - * Channel config that we propose to our counterparty. - */ -struct LDKChannelHandshakeConfig UserConfig_get_own_channel_config(const struct LDKUserConfig *NONNULL_PTR this_ptr); - -/** - * Channel config that we propose to our counterparty. - */ -void UserConfig_set_own_channel_config(struct LDKUserConfig *NONNULL_PTR this_ptr, struct LDKChannelHandshakeConfig val); - -/** - * Limits applied to our counterparty's proposed channel config settings. - */ -struct LDKChannelHandshakeLimits UserConfig_get_peer_channel_config_limits(const struct LDKUserConfig *NONNULL_PTR this_ptr); - -/** - * Limits applied to our counterparty's proposed channel config settings. - */ -void UserConfig_set_peer_channel_config_limits(struct LDKUserConfig *NONNULL_PTR this_ptr, struct LDKChannelHandshakeLimits val); - -/** - * Channel config which affects behavior during channel lifetime. - */ -struct LDKChannelConfig UserConfig_get_channel_options(const struct LDKUserConfig *NONNULL_PTR this_ptr); - -/** - * Channel config which affects behavior during channel lifetime. - */ -void UserConfig_set_channel_options(struct LDKUserConfig *NONNULL_PTR this_ptr, struct LDKChannelConfig val); - -MUST_USE_RES struct LDKUserConfig UserConfig_new(struct LDKChannelHandshakeConfig own_channel_config_arg, struct LDKChannelHandshakeLimits peer_channel_config_limits_arg, struct LDKChannelConfig channel_options_arg); - -struct LDKUserConfig UserConfig_clone(const struct LDKUserConfig *NONNULL_PTR orig); - -MUST_USE_RES struct LDKUserConfig UserConfig_default(void); - -enum LDKAccessError AccessError_clone(const enum LDKAccessError *NONNULL_PTR orig); - -/** - * Calls the free function if one is set - */ -void Access_free(struct LDKAccess this_ptr); - -/** - * Calls the free function if one is set - */ -void Listen_free(struct LDKListen this_ptr); - -/** - * Calls the free function if one is set - */ -void Watch_free(struct LDKWatch this_ptr); - -/** - * Calls the free function if one is set - */ -void Filter_free(struct LDKFilter this_ptr); - -/** - * Calls the free function if one is set - */ -void BroadcasterInterface_free(struct LDKBroadcasterInterface this_ptr); - -enum LDKConfirmationTarget ConfirmationTarget_clone(const enum LDKConfirmationTarget *NONNULL_PTR orig); - -/** - * Calls the free function if one is set - */ -void FeeEstimator_free(struct LDKFeeEstimator this_ptr); - -void ChainMonitor_free(struct LDKChainMonitor this_ptr); - -/** - * Dispatches to per-channel monitors, which are responsible for updating their on-chain view - * of a channel and reacting accordingly based on transactions in the connected block. See - * [`ChannelMonitor::block_connected`] for details. Any HTLCs that were resolved on chain will - * be returned by [`chain::Watch::release_pending_monitor_events`]. - * - * Calls back to [`chain::Filter`] if any monitor indicated new outputs to watch. Subsequent - * calls must not exclude any transactions matching the new outputs nor any in-block - * descendants of such transactions. It is not necessary to re-fetch the block to obtain - * updated `txdata`. - * - * [`ChannelMonitor::block_connected`]: ../channelmonitor/struct.ChannelMonitor.html#method.block_connected - * [`chain::Watch::release_pending_monitor_events`]: ../trait.Watch.html#tymethod.release_pending_monitor_events - * [`chain::Filter`]: ../trait.Filter.html - */ -void ChainMonitor_block_connected(const struct LDKChainMonitor *NONNULL_PTR this_arg, const uint8_t (*header)[80], struct LDKCVec_C2Tuple_usizeTransactionZZ txdata, uint32_t height); - -/** - * Dispatches to per-channel monitors, which are responsible for updating their on-chain view - * of a channel based on the disconnected block. See [`ChannelMonitor::block_disconnected`] for - * details. - * - * [`ChannelMonitor::block_disconnected`]: ../channelmonitor/struct.ChannelMonitor.html#method.block_disconnected - */ -void ChainMonitor_block_disconnected(const struct LDKChainMonitor *NONNULL_PTR this_arg, const uint8_t (*header)[80], uint32_t disconnected_height); - -/** - * Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels. - * - * When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor - * will call back to it indicating transactions and outputs of interest. This allows clients to - * pre-filter blocks or only fetch blocks matching a compact filter. Otherwise, clients may - * always need to fetch full blocks absent another means for determining which blocks contain - * transactions relevant to the watched channels. - * - * [`chain::Filter`]: ../trait.Filter.html - */ -MUST_USE_RES struct LDKChainMonitor ChainMonitor_new(struct LDKFilter *chain_source, struct LDKBroadcasterInterface broadcaster, struct LDKLogger logger, struct LDKFeeEstimator feeest, struct LDKPersist persister); - -struct LDKWatch ChainMonitor_as_Watch(const struct LDKChainMonitor *NONNULL_PTR this_arg); - -struct LDKEventsProvider ChainMonitor_as_EventsProvider(const struct LDKChainMonitor *NONNULL_PTR this_arg); - -void ChannelMonitorUpdate_free(struct LDKChannelMonitorUpdate this_ptr); - -/** - * 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 - * increasing and increase by one for each new update, with one exception specified below. - * - * This sequence number is also used to track up to which points updates which returned - * ChannelMonitorUpdateErr::TemporaryFailure have been applied to all copies of a given - * ChannelMonitor when ChannelManager::channel_monitor_updated is called. - * - * The only instance where update_id values are not strictly increasing is the case where we - * allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See - * its docs for more details. - * - * [`CLOSED_CHANNEL_UPDATE_ID`]: constant.CLOSED_CHANNEL_UPDATE_ID.html - */ -uint64_t ChannelMonitorUpdate_get_update_id(const struct LDKChannelMonitorUpdate *NONNULL_PTR this_ptr); - -/** - * 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 - * increasing and increase by one for each new update, with one exception specified below. - * - * This sequence number is also used to track up to which points updates which returned - * ChannelMonitorUpdateErr::TemporaryFailure have been applied to all copies of a given - * ChannelMonitor when ChannelManager::channel_monitor_updated is called. - * - * The only instance where update_id values are not strictly increasing is the case where we - * allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See - * its docs for more details. - * - * [`CLOSED_CHANNEL_UPDATE_ID`]: constant.CLOSED_CHANNEL_UPDATE_ID.html - */ -void ChannelMonitorUpdate_set_update_id(struct LDKChannelMonitorUpdate *NONNULL_PTR this_ptr, uint64_t val); - -struct LDKChannelMonitorUpdate ChannelMonitorUpdate_clone(const struct LDKChannelMonitorUpdate *NONNULL_PTR orig); - -struct LDKCVec_u8Z ChannelMonitorUpdate_write(const struct LDKChannelMonitorUpdate *NONNULL_PTR obj); - -struct LDKCResult_ChannelMonitorUpdateDecodeErrorZ ChannelMonitorUpdate_read(struct LDKu8slice ser); - -enum LDKChannelMonitorUpdateErr ChannelMonitorUpdateErr_clone(const enum LDKChannelMonitorUpdateErr *NONNULL_PTR orig); - -void MonitorUpdateError_free(struct LDKMonitorUpdateError this_ptr); - -struct LDKMonitorUpdateError MonitorUpdateError_clone(const struct LDKMonitorUpdateError *NONNULL_PTR orig); - -void MonitorEvent_free(struct LDKMonitorEvent this_ptr); - -struct LDKMonitorEvent MonitorEvent_clone(const struct LDKMonitorEvent *NONNULL_PTR orig); - -void HTLCUpdate_free(struct LDKHTLCUpdate this_ptr); - -struct LDKHTLCUpdate HTLCUpdate_clone(const struct LDKHTLCUpdate *NONNULL_PTR orig); - -struct LDKCVec_u8Z HTLCUpdate_write(const struct LDKHTLCUpdate *NONNULL_PTR obj); - -struct LDKCResult_HTLCUpdateDecodeErrorZ HTLCUpdate_read(struct LDKu8slice ser); - -void ChannelMonitor_free(struct LDKChannelMonitor this_ptr); - -struct LDKCVec_u8Z ChannelMonitor_write(const struct LDKChannelMonitor *NONNULL_PTR obj); - -/** - * Updates a ChannelMonitor on the basis of some new information provided by the Channel - * itself. - * - * panics if the given update is not the next update by update_id. - */ -MUST_USE_RES struct LDKCResult_NoneMonitorUpdateErrorZ ChannelMonitor_update_monitor(const struct LDKChannelMonitor *NONNULL_PTR this_arg, const struct LDKChannelMonitorUpdate *NONNULL_PTR updates, const struct LDKBroadcasterInterface *NONNULL_PTR broadcaster, const struct LDKFeeEstimator *NONNULL_PTR fee_estimator, const struct LDKLogger *NONNULL_PTR logger); - -/** - * Gets the update_id from the latest ChannelMonitorUpdate which was applied to this - * ChannelMonitor. - */ -MUST_USE_RES uint64_t ChannelMonitor_get_latest_update_id(const struct LDKChannelMonitor *NONNULL_PTR this_arg); - -/** - * Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for. - */ -MUST_USE_RES struct LDKC2Tuple_OutPointScriptZ ChannelMonitor_get_funding_txo(const struct LDKChannelMonitor *NONNULL_PTR this_arg); - -/** - * Get the list of HTLCs who's status has been updated on chain. This should be called by - * ChannelManager via [`chain::Watch::release_pending_monitor_events`]. - * - * [`chain::Watch::release_pending_monitor_events`]: ../trait.Watch.html#tymethod.release_pending_monitor_events - */ -MUST_USE_RES struct LDKCVec_MonitorEventZ ChannelMonitor_get_and_clear_pending_monitor_events(const struct LDKChannelMonitor *NONNULL_PTR this_arg); - -/** - * Gets the list of pending events which were generated by previous actions, clearing the list - * in the process. - * - * This is called by ChainMonitor::get_and_clear_pending_events() and is equivalent to - * EventsProvider::get_and_clear_pending_events() except that it requires &mut self as we do - * no internal locking in ChannelMonitors. - */ -MUST_USE_RES struct LDKCVec_EventZ ChannelMonitor_get_and_clear_pending_events(const struct LDKChannelMonitor *NONNULL_PTR this_arg); - -/** - * Used by ChannelManager deserialization to broadcast the latest holder state if its copy of - * the Channel was out-of-date. You may use it to get a broadcastable holder toxic tx in case of - * fallen-behind, i.e when receiving a channel_reestablish with a proof that our counterparty side knows - * a higher revocation secret than the holder commitment number we are aware of. Broadcasting these - * transactions are UNSAFE, as they allow counterparty side to punish you. Nevertheless you may want to - * broadcast them if counterparty don't close channel with his higher commitment transaction after a - * substantial amount of time (a month or even a year) to get back funds. Best may be to contact - * out-of-band the other node operator to coordinate with him if option is available to you. - * In any-case, choice is up to the user. - */ -MUST_USE_RES struct LDKCVec_TransactionZ ChannelMonitor_get_latest_holder_commitment_txn(const struct LDKChannelMonitor *NONNULL_PTR this_arg, const struct LDKLogger *NONNULL_PTR logger); - -/** - * Processes transactions in a newly connected block, which may result in any of the following: - * - update the monitor's state against resolved HTLCs - * - punish the counterparty in the case of seeing a revoked commitment transaction - * - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration - * - detect settled outputs for later spending - * - schedule and bump any in-flight claims - * - * Returns any new outputs to watch from `txdata`; after called, these are also included in - * [`get_outputs_to_watch`]. - * - * [`get_outputs_to_watch`]: #method.get_outputs_to_watch - */ -MUST_USE_RES struct LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ ChannelMonitor_block_connected(const struct LDKChannelMonitor *NONNULL_PTR this_arg, const uint8_t (*header)[80], struct LDKCVec_C2Tuple_usizeTransactionZZ txdata, uint32_t height, struct LDKBroadcasterInterface broadcaster, struct LDKFeeEstimator fee_estimator, struct LDKLogger logger); - -/** - * Determines if the disconnected block contained any transactions of interest and updates - * appropriately. - */ -void ChannelMonitor_block_disconnected(const struct LDKChannelMonitor *NONNULL_PTR this_arg, const uint8_t (*header)[80], uint32_t height, struct LDKBroadcasterInterface broadcaster, struct LDKFeeEstimator fee_estimator, struct LDKLogger logger); - -/** - * Calls the free function if one is set - */ -void Persist_free(struct LDKPersist this_ptr); - -struct LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ C2Tuple_BlockHashChannelMonitorZ_read(struct LDKu8slice ser, const struct LDKKeysInterface *NONNULL_PTR arg); - -void OutPoint_free(struct LDKOutPoint this_ptr); - -/** - * The referenced transaction's txid. - */ -const uint8_t (*OutPoint_get_txid(const struct LDKOutPoint *NONNULL_PTR this_ptr))[32]; - -/** - * The referenced transaction's txid. - */ -void OutPoint_set_txid(struct LDKOutPoint *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The index of the referenced output in its transaction's vout. - */ -uint16_t OutPoint_get_index(const struct LDKOutPoint *NONNULL_PTR this_ptr); - -/** - * The index of the referenced output in its transaction's vout. - */ -void OutPoint_set_index(struct LDKOutPoint *NONNULL_PTR this_ptr, uint16_t val); - -MUST_USE_RES struct LDKOutPoint OutPoint_new(struct LDKThirtyTwoBytes txid_arg, uint16_t index_arg); - -struct LDKOutPoint OutPoint_clone(const struct LDKOutPoint *NONNULL_PTR orig); - -/** - * Convert an `OutPoint` to a lightning channel id. - */ -MUST_USE_RES struct LDKThirtyTwoBytes OutPoint_to_channel_id(const struct LDKOutPoint *NONNULL_PTR this_arg); - -struct LDKCVec_u8Z OutPoint_write(const struct LDKOutPoint *NONNULL_PTR obj); - -struct LDKCResult_OutPointDecodeErrorZ OutPoint_read(struct LDKu8slice ser); - -void DelayedPaymentOutputDescriptor_free(struct LDKDelayedPaymentOutputDescriptor this_ptr); - -/** - * The outpoint which is spendable - */ -struct LDKOutPoint DelayedPaymentOutputDescriptor_get_outpoint(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr); - -/** - * The outpoint which is spendable - */ -void DelayedPaymentOutputDescriptor_set_outpoint(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKOutPoint val); - -/** - * Per commitment point to derive delayed_payment_key by key holder - */ -struct LDKPublicKey DelayedPaymentOutputDescriptor_get_per_commitment_point(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr); - -/** - * Per commitment point to derive delayed_payment_key by key holder - */ -void DelayedPaymentOutputDescriptor_set_per_commitment_point(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The nSequence value which must be set in the spending input to satisfy the OP_CSV in - * the witness_script. - */ -uint16_t DelayedPaymentOutputDescriptor_get_to_self_delay(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr); - -/** - * The nSequence value which must be set in the spending input to satisfy the OP_CSV in - * the witness_script. - */ -void DelayedPaymentOutputDescriptor_set_to_self_delay(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, uint16_t val); - -/** - * The output which is referenced by the given outpoint - */ -void DelayedPaymentOutputDescriptor_set_output(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKTxOut val); - -/** - * The revocation point specific to the commitment transaction which was broadcast. Used to - * derive the witnessScript for this output. - */ -struct LDKPublicKey DelayedPaymentOutputDescriptor_get_revocation_pubkey(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr); - -/** - * The revocation point specific to the commitment transaction which was broadcast. Used to - * derive the witnessScript for this output. - */ -void DelayedPaymentOutputDescriptor_set_revocation_pubkey(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Arbitrary identification information returned by a call to - * `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in - * the channel to spend the output. - */ -const uint8_t (*DelayedPaymentOutputDescriptor_get_channel_keys_id(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr))[32]; - -/** - * Arbitrary identification information returned by a call to - * `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in - * the channel to spend the output. - */ -void DelayedPaymentOutputDescriptor_set_channel_keys_id(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The value of the channel which this output originated from, possibly indirectly. - */ -uint64_t DelayedPaymentOutputDescriptor_get_channel_value_satoshis(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr); - -/** - * The value of the channel which this output originated from, possibly indirectly. - */ -void DelayedPaymentOutputDescriptor_set_channel_value_satoshis(struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR this_ptr, uint64_t val); - -MUST_USE_RES struct LDKDelayedPaymentOutputDescriptor DelayedPaymentOutputDescriptor_new(struct LDKOutPoint outpoint_arg, struct LDKPublicKey per_commitment_point_arg, uint16_t to_self_delay_arg, struct LDKTxOut output_arg, struct LDKPublicKey revocation_pubkey_arg, struct LDKThirtyTwoBytes channel_keys_id_arg, uint64_t channel_value_satoshis_arg); - -struct LDKDelayedPaymentOutputDescriptor DelayedPaymentOutputDescriptor_clone(const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR orig); - -void StaticPaymentOutputDescriptor_free(struct LDKStaticPaymentOutputDescriptor this_ptr); - -/** - * The outpoint which is spendable - */ -struct LDKOutPoint StaticPaymentOutputDescriptor_get_outpoint(const struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr); - -/** - * The outpoint which is spendable - */ -void StaticPaymentOutputDescriptor_set_outpoint(struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKOutPoint val); - -/** - * The output which is referenced by the given outpoint - */ -void StaticPaymentOutputDescriptor_set_output(struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKTxOut val); - -/** - * Arbitrary identification information returned by a call to - * `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in - * the channel to spend the output. - */ -const uint8_t (*StaticPaymentOutputDescriptor_get_channel_keys_id(const struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr))[32]; - -/** - * Arbitrary identification information returned by a call to - * `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in - * the channel to spend the output. - */ -void StaticPaymentOutputDescriptor_set_channel_keys_id(struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The value of the channel which this transactions spends. - */ -uint64_t StaticPaymentOutputDescriptor_get_channel_value_satoshis(const struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr); - -/** - * The value of the channel which this transactions spends. - */ -void StaticPaymentOutputDescriptor_set_channel_value_satoshis(struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR this_ptr, uint64_t val); - -MUST_USE_RES struct LDKStaticPaymentOutputDescriptor StaticPaymentOutputDescriptor_new(struct LDKOutPoint outpoint_arg, struct LDKTxOut output_arg, struct LDKThirtyTwoBytes channel_keys_id_arg, uint64_t channel_value_satoshis_arg); - -struct LDKStaticPaymentOutputDescriptor StaticPaymentOutputDescriptor_clone(const struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR orig); - -void SpendableOutputDescriptor_free(struct LDKSpendableOutputDescriptor this_ptr); - -struct LDKSpendableOutputDescriptor SpendableOutputDescriptor_clone(const struct LDKSpendableOutputDescriptor *NONNULL_PTR orig); - -struct LDKCVec_u8Z SpendableOutputDescriptor_write(const struct LDKSpendableOutputDescriptor *NONNULL_PTR obj); - -struct LDKCResult_SpendableOutputDescriptorDecodeErrorZ SpendableOutputDescriptor_read(struct LDKu8slice ser); - -struct LDKSign Sign_clone(const struct LDKSign *NONNULL_PTR orig); - -/** - * Calls the free function if one is set - */ -void Sign_free(struct LDKSign this_ptr); - -/** - * Calls the free function if one is set - */ -void KeysInterface_free(struct LDKKeysInterface this_ptr); - -void InMemorySigner_free(struct LDKInMemorySigner this_ptr); - -/** - * Private key of anchor tx - */ -const uint8_t (*InMemorySigner_get_funding_key(const struct LDKInMemorySigner *NONNULL_PTR this_ptr))[32]; - -/** - * Private key of anchor tx - */ -void InMemorySigner_set_funding_key(struct LDKInMemorySigner *NONNULL_PTR this_ptr, struct LDKSecretKey val); - -/** - * Holder secret key for blinded revocation pubkey - */ -const uint8_t (*InMemorySigner_get_revocation_base_key(const struct LDKInMemorySigner *NONNULL_PTR this_ptr))[32]; - -/** - * Holder secret key for blinded revocation pubkey - */ -void InMemorySigner_set_revocation_base_key(struct LDKInMemorySigner *NONNULL_PTR this_ptr, struct LDKSecretKey val); - -/** - * Holder secret key used for our balance in counterparty-broadcasted commitment transactions - */ -const uint8_t (*InMemorySigner_get_payment_key(const struct LDKInMemorySigner *NONNULL_PTR this_ptr))[32]; - -/** - * Holder secret key used for our balance in counterparty-broadcasted commitment transactions - */ -void InMemorySigner_set_payment_key(struct LDKInMemorySigner *NONNULL_PTR this_ptr, struct LDKSecretKey val); - -/** - * Holder secret key used in HTLC tx - */ -const uint8_t (*InMemorySigner_get_delayed_payment_base_key(const struct LDKInMemorySigner *NONNULL_PTR this_ptr))[32]; - -/** - * Holder secret key used in HTLC tx - */ -void InMemorySigner_set_delayed_payment_base_key(struct LDKInMemorySigner *NONNULL_PTR this_ptr, struct LDKSecretKey val); - -/** - * Holder htlc secret key used in commitment tx htlc outputs - */ -const uint8_t (*InMemorySigner_get_htlc_base_key(const struct LDKInMemorySigner *NONNULL_PTR this_ptr))[32]; - -/** - * Holder htlc secret key used in commitment tx htlc outputs - */ -void InMemorySigner_set_htlc_base_key(struct LDKInMemorySigner *NONNULL_PTR this_ptr, struct LDKSecretKey val); - -/** - * Commitment seed - */ -const uint8_t (*InMemorySigner_get_commitment_seed(const struct LDKInMemorySigner *NONNULL_PTR this_ptr))[32]; - -/** - * Commitment seed - */ -void InMemorySigner_set_commitment_seed(struct LDKInMemorySigner *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -struct LDKInMemorySigner InMemorySigner_clone(const struct LDKInMemorySigner *NONNULL_PTR orig); - -/** - * Create a new InMemorySigner - */ -MUST_USE_RES struct LDKInMemorySigner InMemorySigner_new(struct LDKSecretKey funding_key, struct LDKSecretKey revocation_base_key, struct LDKSecretKey payment_key, struct LDKSecretKey delayed_payment_base_key, struct LDKSecretKey htlc_base_key, struct LDKThirtyTwoBytes commitment_seed, uint64_t channel_value_satoshis, struct LDKThirtyTwoBytes channel_keys_id); - -/** - * Counterparty pubkeys. - * Will panic if ready_channel wasn't called. - */ -MUST_USE_RES struct LDKChannelPublicKeys InMemorySigner_counterparty_pubkeys(const struct LDKInMemorySigner *NONNULL_PTR this_arg); - -/** - * The contest_delay value specified by our counterparty and applied on holder-broadcastable - * transactions, ie the amount of time that we have to wait to recover our funds if we - * broadcast a transaction. - * Will panic if ready_channel wasn't called. - */ -MUST_USE_RES uint16_t InMemorySigner_counterparty_selected_contest_delay(const struct LDKInMemorySigner *NONNULL_PTR this_arg); - -/** - * The contest_delay value specified by us and applied on transactions broadcastable - * by our counterparty, ie the amount of time that they have to wait to recover their funds - * if they broadcast a transaction. - * Will panic if ready_channel wasn't called. - */ -MUST_USE_RES uint16_t InMemorySigner_holder_selected_contest_delay(const struct LDKInMemorySigner *NONNULL_PTR this_arg); - -/** - * Whether the holder is the initiator - * Will panic if ready_channel wasn't called. - */ -MUST_USE_RES bool InMemorySigner_is_outbound(const struct LDKInMemorySigner *NONNULL_PTR this_arg); - -/** - * Funding outpoint - * Will panic if ready_channel wasn't called. - */ -MUST_USE_RES struct LDKOutPoint InMemorySigner_funding_outpoint(const struct LDKInMemorySigner *NONNULL_PTR this_arg); - -/** - * Obtain a ChannelTransactionParameters for this channel, to be used when verifying or - * building transactions. - * - * Will panic if ready_channel wasn't called. - */ -MUST_USE_RES struct LDKChannelTransactionParameters InMemorySigner_get_channel_parameters(const struct LDKInMemorySigner *NONNULL_PTR this_arg); - -/** - * Sign the single input of spend_tx at index `input_idx` which spends the output - * described by descriptor, returning the witness stack for the input. - * - * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig, - * or is not spending the outpoint described by `descriptor.outpoint`. - */ -MUST_USE_RES struct LDKCResult_CVec_CVec_u8ZZNoneZ InMemorySigner_sign_counterparty_payment_input(const struct LDKInMemorySigner *NONNULL_PTR this_arg, struct LDKTransaction spend_tx, uintptr_t input_idx, const struct LDKStaticPaymentOutputDescriptor *NONNULL_PTR descriptor); - -/** - * Sign the single input of spend_tx at index `input_idx` which spends the output - * described by descriptor, returning the witness stack for the input. - * - * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig, - * is not spending the outpoint described by `descriptor.outpoint`, or does not have a - * sequence set to `descriptor.to_self_delay`. - */ -MUST_USE_RES struct LDKCResult_CVec_CVec_u8ZZNoneZ InMemorySigner_sign_dynamic_p2wsh_input(const struct LDKInMemorySigner *NONNULL_PTR this_arg, struct LDKTransaction spend_tx, uintptr_t input_idx, const struct LDKDelayedPaymentOutputDescriptor *NONNULL_PTR descriptor); - -struct LDKSign InMemorySigner_as_Sign(const struct LDKInMemorySigner *NONNULL_PTR this_arg); - -struct LDKCVec_u8Z InMemorySigner_write(const struct LDKInMemorySigner *NONNULL_PTR obj); - -struct LDKCResult_InMemorySignerDecodeErrorZ InMemorySigner_read(struct LDKu8slice ser); - -void KeysManager_free(struct LDKKeysManager this_ptr); - -/** - * Constructs a KeysManager from a 32-byte seed. If the seed is in some way biased (eg your - * CSRNG is busted) this may panic (but more importantly, you will possibly lose funds). - * starting_time isn't strictly required to actually be a time, but it must absolutely, - * without a doubt, be unique to this instance. ie if you start multiple times with the same - * seed, starting_time must be unique to each run. Thus, the easiest way to achieve this is to - * simply use the current time (with very high precision). - * - * The seed MUST be backed up safely prior to use so that the keys can be re-created, however, - * obviously, starting_time should be unique every time you reload the library - it is only - * used to generate new ephemeral key data (which will be stored by the individual channel if - * necessary). - * - * Note that the seed is required to recover certain on-chain funds independent of - * ChannelMonitor data, though a current copy of ChannelMonitor data is also required for any - * channel, and some on-chain during-closing funds. - * - * Note that until the 0.1 release there is no guarantee of backward compatibility between - * versions. Once the library is more fully supported, the docs will be updated to include a - * detailed description of the guarantee. - */ -MUST_USE_RES struct LDKKeysManager KeysManager_new(const uint8_t (*seed)[32], uint64_t starting_time_secs, uint32_t starting_time_nanos); - -/** - * Derive an old Sign containing per-channel secrets based on a key derivation parameters. - * - * Key derivation parameters are accessible through a per-channel secrets - * Sign::channel_keys_id and is provided inside DynamicOuputP2WSH in case of - * onchain output detection for which a corresponding delayed_payment_key must be derived. - */ -MUST_USE_RES struct LDKInMemorySigner KeysManager_derive_channel_keys(const struct LDKKeysManager *NONNULL_PTR this_arg, uint64_t channel_value_satoshis, const uint8_t (*params)[32]); - -/** - * Creates a Transaction which spends the given descriptors to the given outputs, plus an - * output to the given change destination (if sufficient change value remains). The - * transaction will have a feerate, at least, of the given value. - * - * Returns `Err(())` if the output value is greater than the input value minus required fee or - * if a descriptor was duplicated. - * - * We do not enforce that outputs meet the dust limit or that any output scripts are standard. - * - * May panic if the `SpendableOutputDescriptor`s were not generated by Channels which used - * this KeysManager or one of the `InMemorySigner` created by this KeysManager. - */ -MUST_USE_RES struct LDKCResult_TransactionNoneZ KeysManager_spend_spendable_outputs(const struct LDKKeysManager *NONNULL_PTR this_arg, struct LDKCVec_SpendableOutputDescriptorZ descriptors, struct LDKCVec_TxOutZ outputs, struct LDKCVec_u8Z change_destination_script, uint32_t feerate_sat_per_1000_weight); - -struct LDKKeysInterface KeysManager_as_KeysInterface(const struct LDKKeysManager *NONNULL_PTR this_arg); - -void ChannelManager_free(struct LDKChannelManager this_ptr); - -void ChainParameters_free(struct LDKChainParameters this_ptr); - -/** - * The network for determining the `chain_hash` in Lightning messages. - */ -enum LDKNetwork ChainParameters_get_network(const struct LDKChainParameters *NONNULL_PTR this_ptr); - -/** - * The network for determining the `chain_hash` in Lightning messages. - */ -void ChainParameters_set_network(struct LDKChainParameters *NONNULL_PTR this_ptr, enum LDKNetwork val); - -/** - * The hash of the latest block successfully connected. - */ -const uint8_t (*ChainParameters_get_latest_hash(const struct LDKChainParameters *NONNULL_PTR this_ptr))[32]; - -/** - * The hash of the latest block successfully connected. - */ -void ChainParameters_set_latest_hash(struct LDKChainParameters *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The height of the latest block successfully connected. - * - * Used to track on-chain channel funding outputs and send payments with reliable timelocks. - */ -uintptr_t ChainParameters_get_latest_height(const struct LDKChainParameters *NONNULL_PTR this_ptr); - -/** - * The height of the latest block successfully connected. - * - * Used to track on-chain channel funding outputs and send payments with reliable timelocks. - */ -void ChainParameters_set_latest_height(struct LDKChainParameters *NONNULL_PTR this_ptr, uintptr_t val); - -MUST_USE_RES struct LDKChainParameters ChainParameters_new(enum LDKNetwork network_arg, struct LDKThirtyTwoBytes latest_hash_arg, uintptr_t latest_height_arg); - -void ChannelDetails_free(struct LDKChannelDetails this_ptr); - -/** - * 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). - * Note that this means this value is *not* persistent - it can change once during the - * lifetime of the channel. - */ -const uint8_t (*ChannelDetails_get_channel_id(const struct LDKChannelDetails *NONNULL_PTR this_ptr))[32]; - -/** - * 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). - * Note that this means this value is *not* persistent - it can change once during the - * lifetime of the channel. - */ -void ChannelDetails_set_channel_id(struct LDKChannelDetails *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The node_id of our counterparty - */ -struct LDKPublicKey ChannelDetails_get_remote_network_id(const struct LDKChannelDetails *NONNULL_PTR this_ptr); - -/** - * The node_id of our counterparty - */ -void ChannelDetails_set_remote_network_id(struct LDKChannelDetails *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The Features the channel counterparty provided upon last connection. - * Useful for routing as it is the most up-to-date copy of the counterparty's features and - * many routing-relevant features are present in the init context. - */ -struct LDKInitFeatures ChannelDetails_get_counterparty_features(const struct LDKChannelDetails *NONNULL_PTR this_ptr); - -/** - * The Features the channel counterparty provided upon last connection. - * Useful for routing as it is the most up-to-date copy of the counterparty's features and - * many routing-relevant features are present in the init context. - */ -void ChannelDetails_set_counterparty_features(struct LDKChannelDetails *NONNULL_PTR this_ptr, struct LDKInitFeatures val); - -/** - * The value, in satoshis, of this channel as appears in the funding output - */ -uint64_t ChannelDetails_get_channel_value_satoshis(const struct LDKChannelDetails *NONNULL_PTR this_ptr); - -/** - * The value, in satoshis, of this channel as appears in the funding output - */ -void ChannelDetails_set_channel_value_satoshis(struct LDKChannelDetails *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The user_id passed in to create_channel, or 0 if the channel was inbound. - */ -uint64_t ChannelDetails_get_user_id(const struct LDKChannelDetails *NONNULL_PTR this_ptr); - -/** - * The user_id passed in to create_channel, or 0 if the channel was inbound. - */ -void ChannelDetails_set_user_id(struct LDKChannelDetails *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The available outbound capacity for sending HTLCs to the remote peer. This does not include - * any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not - * available for inclusion in new outbound HTLCs). This further does not include any pending - * outgoing HTLCs which are awaiting some other resolution to be sent. - */ -uint64_t ChannelDetails_get_outbound_capacity_msat(const struct LDKChannelDetails *NONNULL_PTR this_ptr); - -/** - * The available outbound capacity for sending HTLCs to the remote peer. This does not include - * any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not - * available for inclusion in new outbound HTLCs). This further does not include any pending - * outgoing HTLCs which are awaiting some other resolution to be sent. - */ -void ChannelDetails_set_outbound_capacity_msat(struct LDKChannelDetails *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The available inbound capacity for the remote peer to send HTLCs to us. This does not - * include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not - * available for inclusion in new inbound HTLCs). - * Note that there are some corner cases not fully handled here, so the actual available - * inbound capacity may be slightly higher than this. - */ -uint64_t ChannelDetails_get_inbound_capacity_msat(const struct LDKChannelDetails *NONNULL_PTR this_ptr); - -/** - * The available inbound capacity for the remote peer to send HTLCs to us. This does not - * include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not - * available for inclusion in new inbound HTLCs). - * Note that there are some corner cases not fully handled here, so the actual available - * inbound capacity may be slightly higher than this. - */ -void ChannelDetails_set_inbound_capacity_msat(struct LDKChannelDetails *NONNULL_PTR this_ptr, uint64_t val); - -/** - * True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b) - * the peer is connected, and (c) no monitor update failure is pending resolution. - */ -bool ChannelDetails_get_is_live(const struct LDKChannelDetails *NONNULL_PTR this_ptr); - -/** - * True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b) - * the peer is connected, and (c) no monitor update failure is pending resolution. - */ -void ChannelDetails_set_is_live(struct LDKChannelDetails *NONNULL_PTR this_ptr, bool val); - -struct LDKChannelDetails ChannelDetails_clone(const struct LDKChannelDetails *NONNULL_PTR orig); - -void PaymentSendFailure_free(struct LDKPaymentSendFailure this_ptr); - -struct LDKPaymentSendFailure PaymentSendFailure_clone(const struct LDKPaymentSendFailure *NONNULL_PTR orig); - -/** - * 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 - * ChannelMessageHandler. - * - * Non-proportional fees are fixed according to our risk using the provided fee estimator. - * - * panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`! - * - * Users need to notify the new ChannelManager when a new block is connected or - * disconnected using its `block_connected` and `block_disconnected` methods, starting - * from after `params.latest_hash`. - */ -MUST_USE_RES struct LDKChannelManager ChannelManager_new(struct LDKFeeEstimator fee_est, struct LDKWatch chain_monitor, struct LDKBroadcasterInterface tx_broadcaster, struct LDKLogger logger, struct LDKKeysInterface keys_manager, struct LDKUserConfig config, struct LDKChainParameters params); - -/** - * Creates a new outbound channel to the given remote node and with the given value. - * - * user_id will be provided back as user_channel_id in FundingGenerationReady and - * FundingBroadcastSafe events to allow tracking of which events correspond with which - * create_channel call. Note that user_channel_id defaults to 0 for inbound channels, so you - * may wish to avoid using 0 for user_id here. - * - * If successful, will generate a SendOpenChannel message event, so you should probably poll - * PeerManager::process_events afterwards. - * - * Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat is - * greater than channel_value_satoshis * 1k or channel_value_satoshis is < 1000. - */ -MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_create_channel(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKPublicKey their_network_key, uint64_t channel_value_satoshis, uint64_t push_msat, uint64_t user_id, struct LDKUserConfig override_config); - -/** - * Gets the list of open channels, in random order. See ChannelDetail field documentation for - * more information. - */ -MUST_USE_RES struct LDKCVec_ChannelDetailsZ ChannelManager_list_channels(const struct LDKChannelManager *NONNULL_PTR this_arg); - -/** - * Gets the list of usable channels, in random order. Useful as an argument to - * get_route to ensure non-announced channels are used. - * - * These are guaranteed to have their is_live value set to true, see the documentation for - * ChannelDetails::is_live for more info on exactly what the criteria are. - */ -MUST_USE_RES struct LDKCVec_ChannelDetailsZ ChannelManager_list_usable_channels(const struct LDKChannelManager *NONNULL_PTR this_arg); - -/** - * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs - * will be accepted on the given channel, and after additional timeout/the closing of all - * pending HTLCs, the channel will be closed on chain. - * - * May generate a SendShutdown message event on success, which should be relayed. - */ -MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_close_channel(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*channel_id)[32]); - -/** - * Force closes a channel, immediately broadcasting the latest local commitment transaction to - * the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager. - */ -MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_force_close_channel(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*channel_id)[32]); - -/** - * Force close all channels, immediately broadcasting the latest local commitment transaction - * for each to the chain and rejecting new HTLCs on each. - */ -void ChannelManager_force_close_all_channels(const struct LDKChannelManager *NONNULL_PTR this_arg); - -/** - * Sends a payment along a given route. - * - * Value parameters are provided via the last hop in route, see documentation for RouteHop - * fields for more info. - * - * Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative - * payment), we don't do anything to stop you! We always try to ensure that if the provided - * next hop knows the preimage to payment_hash they can claim an additional amount as - * specified in the last hop in the route! Thus, you should probably do your own - * payment_preimage tracking (which you should already be doing as they represent \"proof of - * payment\") and prevent double-sends yourself. - * - * May generate SendHTLCs message(s) event on success, which should be relayed. - * - * Each path may have a different return value, and PaymentSendValue may return a Vec with - * each entry matching the corresponding-index entry in the route paths, see - * PaymentSendFailure for more info. - * - * In general, a path may raise: - * * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee, - * node public key) is specified. - * * APIError::ChannelUnavailable if the next-hop channel is not available for updates - * (including due to previous monitor update failure or new permanent monitor update - * failure). - * * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the - * relevant updates. - * - * Note that depending on the type of the PaymentSendFailure the HTLC may have been - * irrevocably committed to on our end. In such a case, do NOT retry the payment with a - * different route unless you intend to pay twice! - * - * payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate - * the sender to the recipient and prevent payment-probing (deanonymization) attacks. For - * newer nodes, it will be provided to you in the invoice. If you do not have one, the Route - * must not contain multiple paths as multi-path payments require a recipient-provided - * payment_secret. - * If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature - * bit set (either as required or as available). If multiple paths are present in the Route, - * we assume the invoice had the basic_mpp feature set. - */ -MUST_USE_RES struct LDKCResult_NonePaymentSendFailureZ ChannelManager_send_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_hash, struct LDKThirtyTwoBytes payment_secret); - -/** - * Call this upon creation of a funding transaction for the given channel. - * - * Note that ALL inputs in the transaction pointed to by funding_txo MUST spend SegWit outputs - * or your counterparty can steal your funds! - * - * Panics if a funding transaction has already been provided for this channel. - * - * May panic if the funding_txo is duplicative with some other channel (note that this should - * be trivially prevented by using unique funding transaction keys per-channel). - */ -void ChannelManager_funding_transaction_generated(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*temporary_channel_id)[32], struct LDKOutPoint funding_txo); - -/** - * Generates a signed node_announcement from the given arguments and creates a - * BroadcastNodeAnnouncement event. Note that such messages will be ignored unless peers have - * seen a channel_announcement from us (ie unless we have public channels open). - * - * RGB is a node \"color\" and alias is a printable human-readable string to describe this node - * to humans. They carry no in-protocol meaning. - * - * addresses represent the set (possibly empty) of socket addresses on which this node accepts - * incoming connections. These will be broadcast to the network, publicly tying these - * addresses together. If you wish to preserve user privacy, addresses should likely contain - * only Tor Onion addresses. - * - * Panics if addresses is absurdly large (more than 500). - */ -void ChannelManager_broadcast_node_announcement(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKThreeBytes rgb, struct LDKThirtyTwoBytes alias, struct LDKCVec_NetAddressZ addresses); - -/** - * Processes HTLCs which are pending waiting on random forward delay. - * - * Should only really ever be called in response to a PendingHTLCsForwardable event. - * Will likely generate further events. - */ -void ChannelManager_process_pending_htlc_forwards(const struct LDKChannelManager *NONNULL_PTR this_arg); - -/** - * If a peer is disconnected we mark any channels with that peer as 'disabled'. - * After some time, if channels are still disabled we need to broadcast a ChannelUpdate - * to inform the network about the uselessness of these channels. - * - * This method handles all the details, and must be called roughly once per minute. - * - * Note that in some rare cases this may generate a `chain::Watch::update_channel` call. - */ -void ChannelManager_timer_chan_freshness_every_min(const struct LDKChannelManager *NONNULL_PTR this_arg); - -/** - * Indicates that the preimage for payment_hash is unknown or the received amount is incorrect - * after a PaymentReceived event, failing the HTLC back to its origin and freeing resources - * along the path (including in our own channel on which we received it). - * Returns false if no payment was found to fail backwards, true if the process of failing the - * HTLC backwards has been started. - */ -MUST_USE_RES bool ChannelManager_fail_htlc_backwards(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*payment_hash)[32], struct LDKThirtyTwoBytes payment_secret); - -/** - * Provides a payment preimage in response to a PaymentReceived event, returning true and - * generating message events for the net layer to claim the payment, if possible. Thus, you - * should probably kick the net layer to go send messages if this returns true! - * - * You must specify the expected amounts for this HTLC, and we will only claim HTLCs - * available within a few percent of the expected amount. This is critical for several - * reasons : a) it avoids providing senders with `proof-of-payment` (in the form of the - * payment_preimage without having provided the full value and b) it avoids certain - * privacy-breaking recipient-probing attacks which may reveal payment activity to - * motivated attackers. - * - * Note that the privacy concerns in (b) are not relevant in payments with a payment_secret - * set. Thus, for such payments we will claim any payments which do not under-pay. - * - * May panic if called except in response to a PaymentReceived event. - */ -MUST_USE_RES bool ChannelManager_claim_funds(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKThirtyTwoBytes payment_preimage, struct LDKThirtyTwoBytes payment_secret, uint64_t expected_amount); - -/** - * Gets the node_id held by this ChannelManager - */ -MUST_USE_RES struct LDKPublicKey ChannelManager_get_our_node_id(const struct LDKChannelManager *NONNULL_PTR this_arg); - -/** - * Restores a single, given channel to normal operation after a - * ChannelMonitorUpdateErr::TemporaryFailure was returned from a channel monitor update - * operation. - * - * All ChannelMonitor updates up to and including highest_applied_update_id must have been - * fully committed in every copy of the given channels' ChannelMonitors. - * - * Note that there is no effect to calling with a highest_applied_update_id other than the - * current latest ChannelMonitorUpdate and one call to this function after multiple - * ChannelMonitorUpdateErr::TemporaryFailures is fine. The highest_applied_update_id field - * exists largely only to prevent races between this and concurrent update_monitor calls. - * - * Thus, the anticipated use is, at a high level: - * 1) You register a chain::Watch with this ChannelManager, - * 2) it stores each update to disk, and begins updating any remote (eg watchtower) copies of - * said ChannelMonitors as it can, returning ChannelMonitorUpdateErr::TemporaryFailures - * any time it cannot do so instantly, - * 3) update(s) are applied to each remote copy of a ChannelMonitor, - * 4) once all remote copies are updated, you call this function with the update_id that - * completed, and once it is the latest the Channel will be re-enabled. - */ -void ChannelManager_channel_monitor_updated(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKOutPoint *NONNULL_PTR funding_txo, uint64_t highest_applied_update_id); - -struct LDKMessageSendEventsProvider ChannelManager_as_MessageSendEventsProvider(const struct LDKChannelManager *NONNULL_PTR this_arg); - -struct LDKEventsProvider ChannelManager_as_EventsProvider(const struct LDKChannelManager *NONNULL_PTR this_arg); - -struct LDKListen ChannelManager_as_Listen(const struct LDKChannelManager *NONNULL_PTR this_arg); - -/** - * Updates channel state based on transactions seen in a connected block. - */ -void ChannelManager_block_connected(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*header)[80], struct LDKCVec_C2Tuple_usizeTransactionZZ txdata, uint32_t height); - -/** - * Updates channel state based on a disconnected block. - * - * If necessary, the channel may be force-closed without letting the counterparty participate - * in the shutdown. - */ -void ChannelManager_block_disconnected(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*header)[80]); - -/** - * Blocks until ChannelManager needs to be persisted. Only one listener on - * `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken - * up. - */ -void ChannelManager_await_persistable_update(const struct LDKChannelManager *NONNULL_PTR this_arg); - -struct LDKChannelMessageHandler ChannelManager_as_ChannelMessageHandler(const struct LDKChannelManager *NONNULL_PTR this_arg); - -struct LDKCVec_u8Z ChannelManager_write(const struct LDKChannelManager *NONNULL_PTR obj); - -void ChannelManagerReadArgs_free(struct LDKChannelManagerReadArgs this_ptr); - -/** - * The keys provider which will give us relevant keys. Some keys will be loaded during - * deserialization and KeysInterface::read_chan_signer will be used to read per-Channel - * signing data. - */ -const struct LDKKeysInterface *ChannelManagerReadArgs_get_keys_manager(const struct LDKChannelManagerReadArgs *NONNULL_PTR this_ptr); - -/** - * The keys provider which will give us relevant keys. Some keys will be loaded during - * deserialization and KeysInterface::read_chan_signer will be used to read per-Channel - * signing data. - */ -void ChannelManagerReadArgs_set_keys_manager(struct LDKChannelManagerReadArgs *NONNULL_PTR this_ptr, struct LDKKeysInterface val); - -/** - * The fee_estimator for use in the ChannelManager in the future. - * - * No calls to the FeeEstimator will be made during deserialization. - */ -const struct LDKFeeEstimator *ChannelManagerReadArgs_get_fee_estimator(const struct LDKChannelManagerReadArgs *NONNULL_PTR this_ptr); - -/** - * The fee_estimator for use in the ChannelManager in the future. - * - * No calls to the FeeEstimator will be made during deserialization. - */ -void ChannelManagerReadArgs_set_fee_estimator(struct LDKChannelManagerReadArgs *NONNULL_PTR this_ptr, struct LDKFeeEstimator val); - -/** - * The chain::Watch for use in the ChannelManager in the future. - * - * No calls to the chain::Watch will be made during deserialization. It is assumed that - * you have deserialized ChannelMonitors separately and will add them to your - * chain::Watch after deserializing this ChannelManager. - */ -const struct LDKWatch *ChannelManagerReadArgs_get_chain_monitor(const struct LDKChannelManagerReadArgs *NONNULL_PTR this_ptr); - -/** - * The chain::Watch for use in the ChannelManager in the future. - * - * No calls to the chain::Watch will be made during deserialization. It is assumed that - * you have deserialized ChannelMonitors separately and will add them to your - * chain::Watch after deserializing this ChannelManager. - */ -void ChannelManagerReadArgs_set_chain_monitor(struct LDKChannelManagerReadArgs *NONNULL_PTR this_ptr, struct LDKWatch val); - -/** - * The BroadcasterInterface which will be used in the ChannelManager in the future and may be - * used to broadcast the latest local commitment transactions of channels which must be - * force-closed during deserialization. - */ -const struct LDKBroadcasterInterface *ChannelManagerReadArgs_get_tx_broadcaster(const struct LDKChannelManagerReadArgs *NONNULL_PTR this_ptr); - -/** - * The BroadcasterInterface which will be used in the ChannelManager in the future and may be - * used to broadcast the latest local commitment transactions of channels which must be - * force-closed during deserialization. - */ -void ChannelManagerReadArgs_set_tx_broadcaster(struct LDKChannelManagerReadArgs *NONNULL_PTR this_ptr, struct LDKBroadcasterInterface val); - -/** - * The Logger for use in the ChannelManager and which may be used to log information during - * deserialization. - */ -const struct LDKLogger *ChannelManagerReadArgs_get_logger(const struct LDKChannelManagerReadArgs *NONNULL_PTR this_ptr); - -/** - * The Logger for use in the ChannelManager and which may be used to log information during - * deserialization. - */ -void ChannelManagerReadArgs_set_logger(struct LDKChannelManagerReadArgs *NONNULL_PTR this_ptr, struct LDKLogger val); - -/** - * Default settings used for new channels. Any existing channels will continue to use the - * runtime settings which were stored when the ChannelManager was serialized. - */ -struct LDKUserConfig ChannelManagerReadArgs_get_default_config(const struct LDKChannelManagerReadArgs *NONNULL_PTR this_ptr); - -/** - * Default settings used for new channels. Any existing channels will continue to use the - * runtime settings which were stored when the ChannelManager was serialized. - */ -void ChannelManagerReadArgs_set_default_config(struct LDKChannelManagerReadArgs *NONNULL_PTR this_ptr, struct LDKUserConfig val); - -/** - * Simple utility function to create a ChannelManagerReadArgs which creates the monitor - * HashMap for you. This is primarily useful for C bindings where it is not practical to - * populate a HashMap directly from C. - */ -MUST_USE_RES struct LDKChannelManagerReadArgs ChannelManagerReadArgs_new(struct LDKKeysInterface keys_manager, struct LDKFeeEstimator fee_estimator, struct LDKWatch chain_monitor, struct LDKBroadcasterInterface tx_broadcaster, struct LDKLogger logger, struct LDKUserConfig default_config, struct LDKCVec_ChannelMonitorZ channel_monitors); - -struct LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ C2Tuple_BlockHashChannelManagerZ_read(struct LDKu8slice ser, struct LDKChannelManagerReadArgs arg); - -void DecodeError_free(struct LDKDecodeError this_ptr); - -struct LDKDecodeError DecodeError_clone(const struct LDKDecodeError *NONNULL_PTR orig); - -void Init_free(struct LDKInit this_ptr); - -/** - * The relevant features which the sender supports - */ -struct LDKInitFeatures Init_get_features(const struct LDKInit *NONNULL_PTR this_ptr); - -/** - * The relevant features which the sender supports - */ -void Init_set_features(struct LDKInit *NONNULL_PTR this_ptr, struct LDKInitFeatures val); - -MUST_USE_RES struct LDKInit Init_new(struct LDKInitFeatures features_arg); - -struct LDKInit Init_clone(const struct LDKInit *NONNULL_PTR orig); - -void ErrorMessage_free(struct LDKErrorMessage this_ptr); - -/** - * The channel ID involved in the error - */ -const uint8_t (*ErrorMessage_get_channel_id(const struct LDKErrorMessage *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID involved in the error - */ -void ErrorMessage_set_channel_id(struct LDKErrorMessage *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * A possibly human-readable error description. - * The string should be sanitized before it is used (e.g. emitted to logs - * or printed to stdout). Otherwise, a well crafted error message may trigger a security - * vulnerability in the terminal emulator or the logging subsystem. - */ -struct LDKStr ErrorMessage_get_data(const struct LDKErrorMessage *NONNULL_PTR this_ptr); - -/** - * A possibly human-readable error description. - * The string should be sanitized before it is used (e.g. emitted to logs - * or printed to stdout). Otherwise, a well crafted error message may trigger a security - * vulnerability in the terminal emulator or the logging subsystem. - */ -void ErrorMessage_set_data(struct LDKErrorMessage *NONNULL_PTR this_ptr, struct LDKCVec_u8Z val); - -MUST_USE_RES struct LDKErrorMessage ErrorMessage_new(struct LDKThirtyTwoBytes channel_id_arg, struct LDKCVec_u8Z data_arg); - -struct LDKErrorMessage ErrorMessage_clone(const struct LDKErrorMessage *NONNULL_PTR orig); - -void Ping_free(struct LDKPing this_ptr); - -/** - * The desired response length - */ -uint16_t Ping_get_ponglen(const struct LDKPing *NONNULL_PTR this_ptr); - -/** - * The desired response length - */ -void Ping_set_ponglen(struct LDKPing *NONNULL_PTR this_ptr, uint16_t val); - -/** - * The ping packet size. - * This field is not sent on the wire. byteslen zeros are sent. - */ -uint16_t Ping_get_byteslen(const struct LDKPing *NONNULL_PTR this_ptr); - -/** - * The ping packet size. - * This field is not sent on the wire. byteslen zeros are sent. - */ -void Ping_set_byteslen(struct LDKPing *NONNULL_PTR this_ptr, uint16_t val); - -MUST_USE_RES struct LDKPing Ping_new(uint16_t ponglen_arg, uint16_t byteslen_arg); - -struct LDKPing Ping_clone(const struct LDKPing *NONNULL_PTR orig); - -void Pong_free(struct LDKPong this_ptr); - -/** - * The pong packet size. - * This field is not sent on the wire. byteslen zeros are sent. - */ -uint16_t Pong_get_byteslen(const struct LDKPong *NONNULL_PTR this_ptr); - -/** - * The pong packet size. - * This field is not sent on the wire. byteslen zeros are sent. - */ -void Pong_set_byteslen(struct LDKPong *NONNULL_PTR this_ptr, uint16_t val); - -MUST_USE_RES struct LDKPong Pong_new(uint16_t byteslen_arg); - -struct LDKPong Pong_clone(const struct LDKPong *NONNULL_PTR orig); - -void OpenChannel_free(struct LDKOpenChannel this_ptr); - -/** - * The genesis hash of the blockchain where the channel is to be opened - */ -const uint8_t (*OpenChannel_get_chain_hash(const struct LDKOpenChannel *NONNULL_PTR this_ptr))[32]; - -/** - * The genesis hash of the blockchain where the channel is to be opened - */ -void OpenChannel_set_chain_hash(struct LDKOpenChannel *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * A temporary channel ID, until the funding outpoint is announced - */ -const uint8_t (*OpenChannel_get_temporary_channel_id(const struct LDKOpenChannel *NONNULL_PTR this_ptr))[32]; - -/** - * A temporary channel ID, until the funding outpoint is announced - */ -void OpenChannel_set_temporary_channel_id(struct LDKOpenChannel *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The channel value - */ -uint64_t OpenChannel_get_funding_satoshis(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * The channel value - */ -void OpenChannel_set_funding_satoshis(struct LDKOpenChannel *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The amount to push to the counterparty as part of the open, in milli-satoshi - */ -uint64_t OpenChannel_get_push_msat(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * The amount to push to the counterparty as part of the open, in milli-satoshi - */ -void OpenChannel_set_push_msat(struct LDKOpenChannel *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The threshold below which outputs on transactions broadcast by sender will be omitted - */ -uint64_t OpenChannel_get_dust_limit_satoshis(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * The threshold below which outputs on transactions broadcast by sender will be omitted - */ -void OpenChannel_set_dust_limit_satoshis(struct LDKOpenChannel *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The maximum inbound HTLC value in flight towards sender, in milli-satoshi - */ -uint64_t OpenChannel_get_max_htlc_value_in_flight_msat(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * The maximum inbound HTLC value in flight towards sender, in milli-satoshi - */ -void OpenChannel_set_max_htlc_value_in_flight_msat(struct LDKOpenChannel *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The minimum value unencumbered by HTLCs for the counterparty to keep in the channel - */ -uint64_t OpenChannel_get_channel_reserve_satoshis(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * The minimum value unencumbered by HTLCs for the counterparty to keep in the channel - */ -void OpenChannel_set_channel_reserve_satoshis(struct LDKOpenChannel *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The minimum HTLC size incoming to sender, in milli-satoshi - */ -uint64_t OpenChannel_get_htlc_minimum_msat(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * The minimum HTLC size incoming to sender, in milli-satoshi - */ -void OpenChannel_set_htlc_minimum_msat(struct LDKOpenChannel *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The feerate per 1000-weight of sender generated transactions, until updated by update_fee - */ -uint32_t OpenChannel_get_feerate_per_kw(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * The feerate per 1000-weight of sender generated transactions, until updated by update_fee - */ -void OpenChannel_set_feerate_per_kw(struct LDKOpenChannel *NONNULL_PTR this_ptr, uint32_t val); - -/** - * The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction - */ -uint16_t OpenChannel_get_to_self_delay(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction - */ -void OpenChannel_set_to_self_delay(struct LDKOpenChannel *NONNULL_PTR this_ptr, uint16_t val); - -/** - * The maximum number of inbound HTLCs towards sender - */ -uint16_t OpenChannel_get_max_accepted_htlcs(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * The maximum number of inbound HTLCs towards sender - */ -void OpenChannel_set_max_accepted_htlcs(struct LDKOpenChannel *NONNULL_PTR this_ptr, uint16_t val); - -/** - * The sender's key controlling the funding transaction - */ -struct LDKPublicKey OpenChannel_get_funding_pubkey(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * The sender's key controlling the funding transaction - */ -void OpenChannel_set_funding_pubkey(struct LDKOpenChannel *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Used to derive a revocation key for transactions broadcast by counterparty - */ -struct LDKPublicKey OpenChannel_get_revocation_basepoint(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * Used to derive a revocation key for transactions broadcast by counterparty - */ -void OpenChannel_set_revocation_basepoint(struct LDKOpenChannel *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * A payment key to sender for transactions broadcast by counterparty - */ -struct LDKPublicKey OpenChannel_get_payment_point(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * A payment key to sender for transactions broadcast by counterparty - */ -void OpenChannel_set_payment_point(struct LDKOpenChannel *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Used to derive a payment key to sender for transactions broadcast by sender - */ -struct LDKPublicKey OpenChannel_get_delayed_payment_basepoint(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * Used to derive a payment key to sender for transactions broadcast by sender - */ -void OpenChannel_set_delayed_payment_basepoint(struct LDKOpenChannel *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Used to derive an HTLC payment key to sender - */ -struct LDKPublicKey OpenChannel_get_htlc_basepoint(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * Used to derive an HTLC payment key to sender - */ -void OpenChannel_set_htlc_basepoint(struct LDKOpenChannel *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The first to-be-broadcast-by-sender transaction's per commitment point - */ -struct LDKPublicKey OpenChannel_get_first_per_commitment_point(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * The first to-be-broadcast-by-sender transaction's per commitment point - */ -void OpenChannel_set_first_per_commitment_point(struct LDKOpenChannel *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Channel flags - */ -uint8_t OpenChannel_get_channel_flags(const struct LDKOpenChannel *NONNULL_PTR this_ptr); - -/** - * Channel flags - */ -void OpenChannel_set_channel_flags(struct LDKOpenChannel *NONNULL_PTR this_ptr, uint8_t val); - -struct LDKOpenChannel OpenChannel_clone(const struct LDKOpenChannel *NONNULL_PTR orig); - -void AcceptChannel_free(struct LDKAcceptChannel this_ptr); - -/** - * A temporary channel ID, until the funding outpoint is announced - */ -const uint8_t (*AcceptChannel_get_temporary_channel_id(const struct LDKAcceptChannel *NONNULL_PTR this_ptr))[32]; - -/** - * A temporary channel ID, until the funding outpoint is announced - */ -void AcceptChannel_set_temporary_channel_id(struct LDKAcceptChannel *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The threshold below which outputs on transactions broadcast by sender will be omitted - */ -uint64_t AcceptChannel_get_dust_limit_satoshis(const struct LDKAcceptChannel *NONNULL_PTR this_ptr); - -/** - * The threshold below which outputs on transactions broadcast by sender will be omitted - */ -void AcceptChannel_set_dust_limit_satoshis(struct LDKAcceptChannel *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The maximum inbound HTLC value in flight towards sender, in milli-satoshi - */ -uint64_t AcceptChannel_get_max_htlc_value_in_flight_msat(const struct LDKAcceptChannel *NONNULL_PTR this_ptr); - -/** - * The maximum inbound HTLC value in flight towards sender, in milli-satoshi - */ -void AcceptChannel_set_max_htlc_value_in_flight_msat(struct LDKAcceptChannel *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The minimum value unencumbered by HTLCs for the counterparty to keep in the channel - */ -uint64_t AcceptChannel_get_channel_reserve_satoshis(const struct LDKAcceptChannel *NONNULL_PTR this_ptr); - -/** - * The minimum value unencumbered by HTLCs for the counterparty to keep in the channel - */ -void AcceptChannel_set_channel_reserve_satoshis(struct LDKAcceptChannel *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The minimum HTLC size incoming to sender, in milli-satoshi - */ -uint64_t AcceptChannel_get_htlc_minimum_msat(const struct LDKAcceptChannel *NONNULL_PTR this_ptr); - -/** - * The minimum HTLC size incoming to sender, in milli-satoshi - */ -void AcceptChannel_set_htlc_minimum_msat(struct LDKAcceptChannel *NONNULL_PTR this_ptr, uint64_t val); - -/** - * Minimum depth of the funding transaction before the channel is considered open - */ -uint32_t AcceptChannel_get_minimum_depth(const struct LDKAcceptChannel *NONNULL_PTR this_ptr); - -/** - * Minimum depth of the funding transaction before the channel is considered open - */ -void AcceptChannel_set_minimum_depth(struct LDKAcceptChannel *NONNULL_PTR this_ptr, uint32_t val); - -/** - * The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction - */ -uint16_t AcceptChannel_get_to_self_delay(const struct LDKAcceptChannel *NONNULL_PTR this_ptr); - -/** - * The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction - */ -void AcceptChannel_set_to_self_delay(struct LDKAcceptChannel *NONNULL_PTR this_ptr, uint16_t val); - -/** - * The maximum number of inbound HTLCs towards sender - */ -uint16_t AcceptChannel_get_max_accepted_htlcs(const struct LDKAcceptChannel *NONNULL_PTR this_ptr); - -/** - * The maximum number of inbound HTLCs towards sender - */ -void AcceptChannel_set_max_accepted_htlcs(struct LDKAcceptChannel *NONNULL_PTR this_ptr, uint16_t val); - -/** - * The sender's key controlling the funding transaction - */ -struct LDKPublicKey AcceptChannel_get_funding_pubkey(const struct LDKAcceptChannel *NONNULL_PTR this_ptr); - -/** - * The sender's key controlling the funding transaction - */ -void AcceptChannel_set_funding_pubkey(struct LDKAcceptChannel *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Used to derive a revocation key for transactions broadcast by counterparty - */ -struct LDKPublicKey AcceptChannel_get_revocation_basepoint(const struct LDKAcceptChannel *NONNULL_PTR this_ptr); - -/** - * Used to derive a revocation key for transactions broadcast by counterparty - */ -void AcceptChannel_set_revocation_basepoint(struct LDKAcceptChannel *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * A payment key to sender for transactions broadcast by counterparty - */ -struct LDKPublicKey AcceptChannel_get_payment_point(const struct LDKAcceptChannel *NONNULL_PTR this_ptr); - -/** - * A payment key to sender for transactions broadcast by counterparty - */ -void AcceptChannel_set_payment_point(struct LDKAcceptChannel *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Used to derive a payment key to sender for transactions broadcast by sender - */ -struct LDKPublicKey AcceptChannel_get_delayed_payment_basepoint(const struct LDKAcceptChannel *NONNULL_PTR this_ptr); - -/** - * Used to derive a payment key to sender for transactions broadcast by sender - */ -void AcceptChannel_set_delayed_payment_basepoint(struct LDKAcceptChannel *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Used to derive an HTLC payment key to sender for transactions broadcast by counterparty - */ -struct LDKPublicKey AcceptChannel_get_htlc_basepoint(const struct LDKAcceptChannel *NONNULL_PTR this_ptr); - -/** - * Used to derive an HTLC payment key to sender for transactions broadcast by counterparty - */ -void AcceptChannel_set_htlc_basepoint(struct LDKAcceptChannel *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The first to-be-broadcast-by-sender transaction's per commitment point - */ -struct LDKPublicKey AcceptChannel_get_first_per_commitment_point(const struct LDKAcceptChannel *NONNULL_PTR this_ptr); - -/** - * The first to-be-broadcast-by-sender transaction's per commitment point - */ -void AcceptChannel_set_first_per_commitment_point(struct LDKAcceptChannel *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -struct LDKAcceptChannel AcceptChannel_clone(const struct LDKAcceptChannel *NONNULL_PTR orig); - -void FundingCreated_free(struct LDKFundingCreated this_ptr); - -/** - * A temporary channel ID, until the funding is established - */ -const uint8_t (*FundingCreated_get_temporary_channel_id(const struct LDKFundingCreated *NONNULL_PTR this_ptr))[32]; - -/** - * A temporary channel ID, until the funding is established - */ -void FundingCreated_set_temporary_channel_id(struct LDKFundingCreated *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The funding transaction ID - */ -const uint8_t (*FundingCreated_get_funding_txid(const struct LDKFundingCreated *NONNULL_PTR this_ptr))[32]; - -/** - * The funding transaction ID - */ -void FundingCreated_set_funding_txid(struct LDKFundingCreated *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The specific output index funding this channel - */ -uint16_t FundingCreated_get_funding_output_index(const struct LDKFundingCreated *NONNULL_PTR this_ptr); - -/** - * The specific output index funding this channel - */ -void FundingCreated_set_funding_output_index(struct LDKFundingCreated *NONNULL_PTR this_ptr, uint16_t val); - -/** - * The signature of the channel initiator (funder) on the funding transaction - */ -struct LDKSignature FundingCreated_get_signature(const struct LDKFundingCreated *NONNULL_PTR this_ptr); - -/** - * The signature of the channel initiator (funder) on the funding transaction - */ -void FundingCreated_set_signature(struct LDKFundingCreated *NONNULL_PTR this_ptr, struct LDKSignature val); - -MUST_USE_RES struct LDKFundingCreated FundingCreated_new(struct LDKThirtyTwoBytes temporary_channel_id_arg, struct LDKThirtyTwoBytes funding_txid_arg, uint16_t funding_output_index_arg, struct LDKSignature signature_arg); - -struct LDKFundingCreated FundingCreated_clone(const struct LDKFundingCreated *NONNULL_PTR orig); - -void FundingSigned_free(struct LDKFundingSigned this_ptr); - -/** - * The channel ID - */ -const uint8_t (*FundingSigned_get_channel_id(const struct LDKFundingSigned *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID - */ -void FundingSigned_set_channel_id(struct LDKFundingSigned *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The signature of the channel acceptor (fundee) on the funding transaction - */ -struct LDKSignature FundingSigned_get_signature(const struct LDKFundingSigned *NONNULL_PTR this_ptr); - -/** - * The signature of the channel acceptor (fundee) on the funding transaction - */ -void FundingSigned_set_signature(struct LDKFundingSigned *NONNULL_PTR this_ptr, struct LDKSignature val); - -MUST_USE_RES struct LDKFundingSigned FundingSigned_new(struct LDKThirtyTwoBytes channel_id_arg, struct LDKSignature signature_arg); - -struct LDKFundingSigned FundingSigned_clone(const struct LDKFundingSigned *NONNULL_PTR orig); - -void FundingLocked_free(struct LDKFundingLocked this_ptr); - -/** - * The channel ID - */ -const uint8_t (*FundingLocked_get_channel_id(const struct LDKFundingLocked *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID - */ -void FundingLocked_set_channel_id(struct LDKFundingLocked *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The per-commitment point of the second commitment transaction - */ -struct LDKPublicKey FundingLocked_get_next_per_commitment_point(const struct LDKFundingLocked *NONNULL_PTR this_ptr); - -/** - * The per-commitment point of the second commitment transaction - */ -void FundingLocked_set_next_per_commitment_point(struct LDKFundingLocked *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -MUST_USE_RES struct LDKFundingLocked FundingLocked_new(struct LDKThirtyTwoBytes channel_id_arg, struct LDKPublicKey next_per_commitment_point_arg); - -struct LDKFundingLocked FundingLocked_clone(const struct LDKFundingLocked *NONNULL_PTR orig); - -void Shutdown_free(struct LDKShutdown this_ptr); - -/** - * The channel ID - */ -const uint8_t (*Shutdown_get_channel_id(const struct LDKShutdown *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID - */ -void Shutdown_set_channel_id(struct LDKShutdown *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The destination of this peer's funds on closing. - * Must be in one of these forms: p2pkh, p2sh, p2wpkh, p2wsh. - */ -struct LDKu8slice Shutdown_get_scriptpubkey(const struct LDKShutdown *NONNULL_PTR this_ptr); - -/** - * The destination of this peer's funds on closing. - * Must be in one of these forms: p2pkh, p2sh, p2wpkh, p2wsh. - */ -void Shutdown_set_scriptpubkey(struct LDKShutdown *NONNULL_PTR this_ptr, struct LDKCVec_u8Z val); - -MUST_USE_RES struct LDKShutdown Shutdown_new(struct LDKThirtyTwoBytes channel_id_arg, struct LDKCVec_u8Z scriptpubkey_arg); - -struct LDKShutdown Shutdown_clone(const struct LDKShutdown *NONNULL_PTR orig); - -void ClosingSigned_free(struct LDKClosingSigned this_ptr); - -/** - * The channel ID - */ -const uint8_t (*ClosingSigned_get_channel_id(const struct LDKClosingSigned *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID - */ -void ClosingSigned_set_channel_id(struct LDKClosingSigned *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The proposed total fee for the closing transaction - */ -uint64_t ClosingSigned_get_fee_satoshis(const struct LDKClosingSigned *NONNULL_PTR this_ptr); - -/** - * The proposed total fee for the closing transaction - */ -void ClosingSigned_set_fee_satoshis(struct LDKClosingSigned *NONNULL_PTR this_ptr, uint64_t val); - -/** - * A signature on the closing transaction - */ -struct LDKSignature ClosingSigned_get_signature(const struct LDKClosingSigned *NONNULL_PTR this_ptr); - -/** - * A signature on the closing transaction - */ -void ClosingSigned_set_signature(struct LDKClosingSigned *NONNULL_PTR this_ptr, struct LDKSignature val); - -MUST_USE_RES struct LDKClosingSigned ClosingSigned_new(struct LDKThirtyTwoBytes channel_id_arg, uint64_t fee_satoshis_arg, struct LDKSignature signature_arg); - -struct LDKClosingSigned ClosingSigned_clone(const struct LDKClosingSigned *NONNULL_PTR orig); - -void UpdateAddHTLC_free(struct LDKUpdateAddHTLC this_ptr); - -/** - * The channel ID - */ -const uint8_t (*UpdateAddHTLC_get_channel_id(const struct LDKUpdateAddHTLC *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID - */ -void UpdateAddHTLC_set_channel_id(struct LDKUpdateAddHTLC *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The HTLC ID - */ -uint64_t UpdateAddHTLC_get_htlc_id(const struct LDKUpdateAddHTLC *NONNULL_PTR this_ptr); - -/** - * The HTLC ID - */ -void UpdateAddHTLC_set_htlc_id(struct LDKUpdateAddHTLC *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The HTLC value in milli-satoshi - */ -uint64_t UpdateAddHTLC_get_amount_msat(const struct LDKUpdateAddHTLC *NONNULL_PTR this_ptr); - -/** - * The HTLC value in milli-satoshi - */ -void UpdateAddHTLC_set_amount_msat(struct LDKUpdateAddHTLC *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The payment hash, the pre-image of which controls HTLC redemption - */ -const uint8_t (*UpdateAddHTLC_get_payment_hash(const struct LDKUpdateAddHTLC *NONNULL_PTR this_ptr))[32]; - -/** - * The payment hash, the pre-image of which controls HTLC redemption - */ -void UpdateAddHTLC_set_payment_hash(struct LDKUpdateAddHTLC *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The expiry height of the HTLC - */ -uint32_t UpdateAddHTLC_get_cltv_expiry(const struct LDKUpdateAddHTLC *NONNULL_PTR this_ptr); - -/** - * The expiry height of the HTLC - */ -void UpdateAddHTLC_set_cltv_expiry(struct LDKUpdateAddHTLC *NONNULL_PTR this_ptr, uint32_t val); - -struct LDKUpdateAddHTLC UpdateAddHTLC_clone(const struct LDKUpdateAddHTLC *NONNULL_PTR orig); - -void UpdateFulfillHTLC_free(struct LDKUpdateFulfillHTLC this_ptr); - -/** - * The channel ID - */ -const uint8_t (*UpdateFulfillHTLC_get_channel_id(const struct LDKUpdateFulfillHTLC *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID - */ -void UpdateFulfillHTLC_set_channel_id(struct LDKUpdateFulfillHTLC *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The HTLC ID - */ -uint64_t UpdateFulfillHTLC_get_htlc_id(const struct LDKUpdateFulfillHTLC *NONNULL_PTR this_ptr); - -/** - * The HTLC ID - */ -void UpdateFulfillHTLC_set_htlc_id(struct LDKUpdateFulfillHTLC *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The pre-image of the payment hash, allowing HTLC redemption - */ -const uint8_t (*UpdateFulfillHTLC_get_payment_preimage(const struct LDKUpdateFulfillHTLC *NONNULL_PTR this_ptr))[32]; - -/** - * The pre-image of the payment hash, allowing HTLC redemption - */ -void UpdateFulfillHTLC_set_payment_preimage(struct LDKUpdateFulfillHTLC *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -MUST_USE_RES struct LDKUpdateFulfillHTLC UpdateFulfillHTLC_new(struct LDKThirtyTwoBytes channel_id_arg, uint64_t htlc_id_arg, struct LDKThirtyTwoBytes payment_preimage_arg); - -struct LDKUpdateFulfillHTLC UpdateFulfillHTLC_clone(const struct LDKUpdateFulfillHTLC *NONNULL_PTR orig); - -void UpdateFailHTLC_free(struct LDKUpdateFailHTLC this_ptr); - -/** - * The channel ID - */ -const uint8_t (*UpdateFailHTLC_get_channel_id(const struct LDKUpdateFailHTLC *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID - */ -void UpdateFailHTLC_set_channel_id(struct LDKUpdateFailHTLC *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The HTLC ID - */ -uint64_t UpdateFailHTLC_get_htlc_id(const struct LDKUpdateFailHTLC *NONNULL_PTR this_ptr); - -/** - * The HTLC ID - */ -void UpdateFailHTLC_set_htlc_id(struct LDKUpdateFailHTLC *NONNULL_PTR this_ptr, uint64_t val); - -struct LDKUpdateFailHTLC UpdateFailHTLC_clone(const struct LDKUpdateFailHTLC *NONNULL_PTR orig); - -void UpdateFailMalformedHTLC_free(struct LDKUpdateFailMalformedHTLC this_ptr); - -/** - * The channel ID - */ -const uint8_t (*UpdateFailMalformedHTLC_get_channel_id(const struct LDKUpdateFailMalformedHTLC *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID - */ -void UpdateFailMalformedHTLC_set_channel_id(struct LDKUpdateFailMalformedHTLC *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The HTLC ID - */ -uint64_t UpdateFailMalformedHTLC_get_htlc_id(const struct LDKUpdateFailMalformedHTLC *NONNULL_PTR this_ptr); - -/** - * The HTLC ID - */ -void UpdateFailMalformedHTLC_set_htlc_id(struct LDKUpdateFailMalformedHTLC *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The failure code - */ -uint16_t UpdateFailMalformedHTLC_get_failure_code(const struct LDKUpdateFailMalformedHTLC *NONNULL_PTR this_ptr); - -/** - * The failure code - */ -void UpdateFailMalformedHTLC_set_failure_code(struct LDKUpdateFailMalformedHTLC *NONNULL_PTR this_ptr, uint16_t val); - -struct LDKUpdateFailMalformedHTLC UpdateFailMalformedHTLC_clone(const struct LDKUpdateFailMalformedHTLC *NONNULL_PTR orig); - -void CommitmentSigned_free(struct LDKCommitmentSigned this_ptr); - -/** - * The channel ID - */ -const uint8_t (*CommitmentSigned_get_channel_id(const struct LDKCommitmentSigned *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID - */ -void CommitmentSigned_set_channel_id(struct LDKCommitmentSigned *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * A signature on the commitment transaction - */ -struct LDKSignature CommitmentSigned_get_signature(const struct LDKCommitmentSigned *NONNULL_PTR this_ptr); - -/** - * A signature on the commitment transaction - */ -void CommitmentSigned_set_signature(struct LDKCommitmentSigned *NONNULL_PTR this_ptr, struct LDKSignature val); - -/** - * Signatures on the HTLC transactions - */ -void CommitmentSigned_set_htlc_signatures(struct LDKCommitmentSigned *NONNULL_PTR this_ptr, struct LDKCVec_SignatureZ val); - -MUST_USE_RES struct LDKCommitmentSigned CommitmentSigned_new(struct LDKThirtyTwoBytes channel_id_arg, struct LDKSignature signature_arg, struct LDKCVec_SignatureZ htlc_signatures_arg); - -struct LDKCommitmentSigned CommitmentSigned_clone(const struct LDKCommitmentSigned *NONNULL_PTR orig); - -void RevokeAndACK_free(struct LDKRevokeAndACK this_ptr); - -/** - * The channel ID - */ -const uint8_t (*RevokeAndACK_get_channel_id(const struct LDKRevokeAndACK *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID - */ -void RevokeAndACK_set_channel_id(struct LDKRevokeAndACK *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The secret corresponding to the per-commitment point - */ -const uint8_t (*RevokeAndACK_get_per_commitment_secret(const struct LDKRevokeAndACK *NONNULL_PTR this_ptr))[32]; - -/** - * The secret corresponding to the per-commitment point - */ -void RevokeAndACK_set_per_commitment_secret(struct LDKRevokeAndACK *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The next sender-broadcast commitment transaction's per-commitment point - */ -struct LDKPublicKey RevokeAndACK_get_next_per_commitment_point(const struct LDKRevokeAndACK *NONNULL_PTR this_ptr); - -/** - * The next sender-broadcast commitment transaction's per-commitment point - */ -void RevokeAndACK_set_next_per_commitment_point(struct LDKRevokeAndACK *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -MUST_USE_RES struct LDKRevokeAndACK RevokeAndACK_new(struct LDKThirtyTwoBytes channel_id_arg, struct LDKThirtyTwoBytes per_commitment_secret_arg, struct LDKPublicKey next_per_commitment_point_arg); - -struct LDKRevokeAndACK RevokeAndACK_clone(const struct LDKRevokeAndACK *NONNULL_PTR orig); - -void UpdateFee_free(struct LDKUpdateFee this_ptr); - -/** - * The channel ID - */ -const uint8_t (*UpdateFee_get_channel_id(const struct LDKUpdateFee *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID - */ -void UpdateFee_set_channel_id(struct LDKUpdateFee *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * Fee rate per 1000-weight of the transaction - */ -uint32_t UpdateFee_get_feerate_per_kw(const struct LDKUpdateFee *NONNULL_PTR this_ptr); - -/** - * Fee rate per 1000-weight of the transaction - */ -void UpdateFee_set_feerate_per_kw(struct LDKUpdateFee *NONNULL_PTR this_ptr, uint32_t val); - -MUST_USE_RES struct LDKUpdateFee UpdateFee_new(struct LDKThirtyTwoBytes channel_id_arg, uint32_t feerate_per_kw_arg); - -struct LDKUpdateFee UpdateFee_clone(const struct LDKUpdateFee *NONNULL_PTR orig); - -void DataLossProtect_free(struct LDKDataLossProtect this_ptr); - -/** - * Proof that the sender knows the per-commitment secret of a specific commitment transaction - * belonging to the recipient - */ -const uint8_t (*DataLossProtect_get_your_last_per_commitment_secret(const struct LDKDataLossProtect *NONNULL_PTR this_ptr))[32]; - -/** - * Proof that the sender knows the per-commitment secret of a specific commitment transaction - * belonging to the recipient - */ -void DataLossProtect_set_your_last_per_commitment_secret(struct LDKDataLossProtect *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The sender's per-commitment point for their current commitment transaction - */ -struct LDKPublicKey DataLossProtect_get_my_current_per_commitment_point(const struct LDKDataLossProtect *NONNULL_PTR this_ptr); - -/** - * The sender's per-commitment point for their current commitment transaction - */ -void DataLossProtect_set_my_current_per_commitment_point(struct LDKDataLossProtect *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -MUST_USE_RES struct LDKDataLossProtect DataLossProtect_new(struct LDKThirtyTwoBytes your_last_per_commitment_secret_arg, struct LDKPublicKey my_current_per_commitment_point_arg); - -struct LDKDataLossProtect DataLossProtect_clone(const struct LDKDataLossProtect *NONNULL_PTR orig); - -void ChannelReestablish_free(struct LDKChannelReestablish this_ptr); - -/** - * The channel ID - */ -const uint8_t (*ChannelReestablish_get_channel_id(const struct LDKChannelReestablish *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID - */ -void ChannelReestablish_set_channel_id(struct LDKChannelReestablish *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The next commitment number for the sender - */ -uint64_t ChannelReestablish_get_next_local_commitment_number(const struct LDKChannelReestablish *NONNULL_PTR this_ptr); - -/** - * The next commitment number for the sender - */ -void ChannelReestablish_set_next_local_commitment_number(struct LDKChannelReestablish *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The next commitment number for the recipient - */ -uint64_t ChannelReestablish_get_next_remote_commitment_number(const struct LDKChannelReestablish *NONNULL_PTR this_ptr); - -/** - * The next commitment number for the recipient - */ -void ChannelReestablish_set_next_remote_commitment_number(struct LDKChannelReestablish *NONNULL_PTR this_ptr, uint64_t val); - -struct LDKChannelReestablish ChannelReestablish_clone(const struct LDKChannelReestablish *NONNULL_PTR orig); - -void AnnouncementSignatures_free(struct LDKAnnouncementSignatures this_ptr); - -/** - * The channel ID - */ -const uint8_t (*AnnouncementSignatures_get_channel_id(const struct LDKAnnouncementSignatures *NONNULL_PTR this_ptr))[32]; - -/** - * The channel ID - */ -void AnnouncementSignatures_set_channel_id(struct LDKAnnouncementSignatures *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The short channel ID - */ -uint64_t AnnouncementSignatures_get_short_channel_id(const struct LDKAnnouncementSignatures *NONNULL_PTR this_ptr); - -/** - * The short channel ID - */ -void AnnouncementSignatures_set_short_channel_id(struct LDKAnnouncementSignatures *NONNULL_PTR this_ptr, uint64_t val); - -/** - * A signature by the node key - */ -struct LDKSignature AnnouncementSignatures_get_node_signature(const struct LDKAnnouncementSignatures *NONNULL_PTR this_ptr); - -/** - * A signature by the node key - */ -void AnnouncementSignatures_set_node_signature(struct LDKAnnouncementSignatures *NONNULL_PTR this_ptr, struct LDKSignature val); - -/** - * A signature by the funding key - */ -struct LDKSignature AnnouncementSignatures_get_bitcoin_signature(const struct LDKAnnouncementSignatures *NONNULL_PTR this_ptr); - -/** - * A signature by the funding key - */ -void AnnouncementSignatures_set_bitcoin_signature(struct LDKAnnouncementSignatures *NONNULL_PTR this_ptr, struct LDKSignature val); - -MUST_USE_RES struct LDKAnnouncementSignatures AnnouncementSignatures_new(struct LDKThirtyTwoBytes channel_id_arg, uint64_t short_channel_id_arg, struct LDKSignature node_signature_arg, struct LDKSignature bitcoin_signature_arg); - -struct LDKAnnouncementSignatures AnnouncementSignatures_clone(const struct LDKAnnouncementSignatures *NONNULL_PTR orig); - -void NetAddress_free(struct LDKNetAddress this_ptr); - -struct LDKNetAddress NetAddress_clone(const struct LDKNetAddress *NONNULL_PTR orig); - -struct LDKCVec_u8Z NetAddress_write(const struct LDKNetAddress *NONNULL_PTR obj); - -struct LDKCResult_CResult_NetAddressu8ZDecodeErrorZ Result_read(struct LDKu8slice ser); - -void UnsignedNodeAnnouncement_free(struct LDKUnsignedNodeAnnouncement this_ptr); - -/** - * The advertised features - */ -struct LDKNodeFeatures UnsignedNodeAnnouncement_get_features(const struct LDKUnsignedNodeAnnouncement *NONNULL_PTR this_ptr); - -/** - * The advertised features - */ -void UnsignedNodeAnnouncement_set_features(struct LDKUnsignedNodeAnnouncement *NONNULL_PTR this_ptr, struct LDKNodeFeatures val); - -/** - * A strictly monotonic announcement counter, with gaps allowed - */ -uint32_t UnsignedNodeAnnouncement_get_timestamp(const struct LDKUnsignedNodeAnnouncement *NONNULL_PTR this_ptr); - -/** - * A strictly monotonic announcement counter, with gaps allowed - */ -void UnsignedNodeAnnouncement_set_timestamp(struct LDKUnsignedNodeAnnouncement *NONNULL_PTR this_ptr, uint32_t val); - -/** - * The node_id this announcement originated from (don't rebroadcast the node_announcement back - * to this node). - */ -struct LDKPublicKey UnsignedNodeAnnouncement_get_node_id(const struct LDKUnsignedNodeAnnouncement *NONNULL_PTR this_ptr); - -/** - * The node_id this announcement originated from (don't rebroadcast the node_announcement back - * to this node). - */ -void UnsignedNodeAnnouncement_set_node_id(struct LDKUnsignedNodeAnnouncement *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * An RGB color for UI purposes - */ -const uint8_t (*UnsignedNodeAnnouncement_get_rgb(const struct LDKUnsignedNodeAnnouncement *NONNULL_PTR this_ptr))[3]; - -/** - * An RGB color for UI purposes - */ -void UnsignedNodeAnnouncement_set_rgb(struct LDKUnsignedNodeAnnouncement *NONNULL_PTR this_ptr, struct LDKThreeBytes val); - -/** - * An alias, for UI purposes. This should be sanitized before use. There is no guarantee - * of uniqueness. - */ -const uint8_t (*UnsignedNodeAnnouncement_get_alias(const struct LDKUnsignedNodeAnnouncement *NONNULL_PTR this_ptr))[32]; - -/** - * An alias, for UI purposes. This should be sanitized before use. There is no guarantee - * of uniqueness. - */ -void UnsignedNodeAnnouncement_set_alias(struct LDKUnsignedNodeAnnouncement *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * List of addresses on which this node is reachable - */ -void UnsignedNodeAnnouncement_set_addresses(struct LDKUnsignedNodeAnnouncement *NONNULL_PTR this_ptr, struct LDKCVec_NetAddressZ val); - -struct LDKUnsignedNodeAnnouncement UnsignedNodeAnnouncement_clone(const struct LDKUnsignedNodeAnnouncement *NONNULL_PTR orig); - -void NodeAnnouncement_free(struct LDKNodeAnnouncement this_ptr); - -/** - * The signature by the node key - */ -struct LDKSignature NodeAnnouncement_get_signature(const struct LDKNodeAnnouncement *NONNULL_PTR this_ptr); - -/** - * The signature by the node key - */ -void NodeAnnouncement_set_signature(struct LDKNodeAnnouncement *NONNULL_PTR this_ptr, struct LDKSignature val); - -/** - * The actual content of the announcement - */ -struct LDKUnsignedNodeAnnouncement NodeAnnouncement_get_contents(const struct LDKNodeAnnouncement *NONNULL_PTR this_ptr); - -/** - * The actual content of the announcement - */ -void NodeAnnouncement_set_contents(struct LDKNodeAnnouncement *NONNULL_PTR this_ptr, struct LDKUnsignedNodeAnnouncement val); - -MUST_USE_RES struct LDKNodeAnnouncement NodeAnnouncement_new(struct LDKSignature signature_arg, struct LDKUnsignedNodeAnnouncement contents_arg); - -struct LDKNodeAnnouncement NodeAnnouncement_clone(const struct LDKNodeAnnouncement *NONNULL_PTR orig); - -void UnsignedChannelAnnouncement_free(struct LDKUnsignedChannelAnnouncement this_ptr); - -/** - * The advertised channel features - */ -struct LDKChannelFeatures UnsignedChannelAnnouncement_get_features(const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr); - -/** - * The advertised channel features - */ -void UnsignedChannelAnnouncement_set_features(struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr, struct LDKChannelFeatures val); - -/** - * The genesis hash of the blockchain where the channel is to be opened - */ -const uint8_t (*UnsignedChannelAnnouncement_get_chain_hash(const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr))[32]; - -/** - * The genesis hash of the blockchain where the channel is to be opened - */ -void UnsignedChannelAnnouncement_set_chain_hash(struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The short channel ID - */ -uint64_t UnsignedChannelAnnouncement_get_short_channel_id(const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr); - -/** - * The short channel ID - */ -void UnsignedChannelAnnouncement_set_short_channel_id(struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr, uint64_t val); - -/** - * One of the two node_ids which are endpoints of this channel - */ -struct LDKPublicKey UnsignedChannelAnnouncement_get_node_id_1(const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr); - -/** - * One of the two node_ids which are endpoints of this channel - */ -void UnsignedChannelAnnouncement_set_node_id_1(struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The other of the two node_ids which are endpoints of this channel - */ -struct LDKPublicKey UnsignedChannelAnnouncement_get_node_id_2(const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr); - -/** - * The other of the two node_ids which are endpoints of this channel - */ -void UnsignedChannelAnnouncement_set_node_id_2(struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The funding key for the first node - */ -struct LDKPublicKey UnsignedChannelAnnouncement_get_bitcoin_key_1(const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr); - -/** - * The funding key for the first node - */ -void UnsignedChannelAnnouncement_set_bitcoin_key_1(struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The funding key for the second node - */ -struct LDKPublicKey UnsignedChannelAnnouncement_get_bitcoin_key_2(const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr); - -/** - * The funding key for the second node - */ -void UnsignedChannelAnnouncement_set_bitcoin_key_2(struct LDKUnsignedChannelAnnouncement *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -struct LDKUnsignedChannelAnnouncement UnsignedChannelAnnouncement_clone(const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR orig); - -void ChannelAnnouncement_free(struct LDKChannelAnnouncement this_ptr); - -/** - * Authentication of the announcement by the first public node - */ -struct LDKSignature ChannelAnnouncement_get_node_signature_1(const struct LDKChannelAnnouncement *NONNULL_PTR this_ptr); - -/** - * Authentication of the announcement by the first public node - */ -void ChannelAnnouncement_set_node_signature_1(struct LDKChannelAnnouncement *NONNULL_PTR this_ptr, struct LDKSignature val); - -/** - * Authentication of the announcement by the second public node - */ -struct LDKSignature ChannelAnnouncement_get_node_signature_2(const struct LDKChannelAnnouncement *NONNULL_PTR this_ptr); - -/** - * Authentication of the announcement by the second public node - */ -void ChannelAnnouncement_set_node_signature_2(struct LDKChannelAnnouncement *NONNULL_PTR this_ptr, struct LDKSignature val); - -/** - * Proof of funding UTXO ownership by the first public node - */ -struct LDKSignature ChannelAnnouncement_get_bitcoin_signature_1(const struct LDKChannelAnnouncement *NONNULL_PTR this_ptr); - -/** - * Proof of funding UTXO ownership by the first public node - */ -void ChannelAnnouncement_set_bitcoin_signature_1(struct LDKChannelAnnouncement *NONNULL_PTR this_ptr, struct LDKSignature val); - -/** - * Proof of funding UTXO ownership by the second public node - */ -struct LDKSignature ChannelAnnouncement_get_bitcoin_signature_2(const struct LDKChannelAnnouncement *NONNULL_PTR this_ptr); - -/** - * Proof of funding UTXO ownership by the second public node - */ -void ChannelAnnouncement_set_bitcoin_signature_2(struct LDKChannelAnnouncement *NONNULL_PTR this_ptr, struct LDKSignature val); - -/** - * The actual announcement - */ -struct LDKUnsignedChannelAnnouncement ChannelAnnouncement_get_contents(const struct LDKChannelAnnouncement *NONNULL_PTR this_ptr); - -/** - * The actual announcement - */ -void ChannelAnnouncement_set_contents(struct LDKChannelAnnouncement *NONNULL_PTR this_ptr, struct LDKUnsignedChannelAnnouncement val); - -MUST_USE_RES struct LDKChannelAnnouncement ChannelAnnouncement_new(struct LDKSignature node_signature_1_arg, struct LDKSignature node_signature_2_arg, struct LDKSignature bitcoin_signature_1_arg, struct LDKSignature bitcoin_signature_2_arg, struct LDKUnsignedChannelAnnouncement contents_arg); - -struct LDKChannelAnnouncement ChannelAnnouncement_clone(const struct LDKChannelAnnouncement *NONNULL_PTR orig); - -void UnsignedChannelUpdate_free(struct LDKUnsignedChannelUpdate this_ptr); - -/** - * The genesis hash of the blockchain where the channel is to be opened - */ -const uint8_t (*UnsignedChannelUpdate_get_chain_hash(const struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr))[32]; - -/** - * The genesis hash of the blockchain where the channel is to be opened - */ -void UnsignedChannelUpdate_set_chain_hash(struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The short channel ID - */ -uint64_t UnsignedChannelUpdate_get_short_channel_id(const struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr); - -/** - * The short channel ID - */ -void UnsignedChannelUpdate_set_short_channel_id(struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr, uint64_t val); - -/** - * A strictly monotonic announcement counter, with gaps allowed, specific to this channel - */ -uint32_t UnsignedChannelUpdate_get_timestamp(const struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr); - -/** - * A strictly monotonic announcement counter, with gaps allowed, specific to this channel - */ -void UnsignedChannelUpdate_set_timestamp(struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr, uint32_t val); - -/** - * Channel flags - */ -uint8_t UnsignedChannelUpdate_get_flags(const struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr); - -/** - * Channel flags - */ -void UnsignedChannelUpdate_set_flags(struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr, uint8_t val); - -/** - * The number of blocks to subtract from incoming HTLC cltv_expiry values - */ -uint16_t UnsignedChannelUpdate_get_cltv_expiry_delta(const struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr); - -/** - * The number of blocks to subtract from incoming HTLC cltv_expiry values - */ -void UnsignedChannelUpdate_set_cltv_expiry_delta(struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr, uint16_t val); - -/** - * The minimum HTLC size incoming to sender, in milli-satoshi - */ -uint64_t UnsignedChannelUpdate_get_htlc_minimum_msat(const struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr); - -/** - * The minimum HTLC size incoming to sender, in milli-satoshi - */ -void UnsignedChannelUpdate_set_htlc_minimum_msat(struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The base HTLC fee charged by sender, in milli-satoshi - */ -uint32_t UnsignedChannelUpdate_get_fee_base_msat(const struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr); - -/** - * The base HTLC fee charged by sender, in milli-satoshi - */ -void UnsignedChannelUpdate_set_fee_base_msat(struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr, uint32_t val); - -/** - * The amount to fee multiplier, in micro-satoshi - */ -uint32_t UnsignedChannelUpdate_get_fee_proportional_millionths(const struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr); - -/** - * The amount to fee multiplier, in micro-satoshi - */ -void UnsignedChannelUpdate_set_fee_proportional_millionths(struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr, uint32_t val); - -struct LDKUnsignedChannelUpdate UnsignedChannelUpdate_clone(const struct LDKUnsignedChannelUpdate *NONNULL_PTR orig); - -void ChannelUpdate_free(struct LDKChannelUpdate this_ptr); - -/** - * A signature of the channel update - */ -struct LDKSignature ChannelUpdate_get_signature(const struct LDKChannelUpdate *NONNULL_PTR this_ptr); - -/** - * A signature of the channel update - */ -void ChannelUpdate_set_signature(struct LDKChannelUpdate *NONNULL_PTR this_ptr, struct LDKSignature val); - -/** - * The actual channel update - */ -struct LDKUnsignedChannelUpdate ChannelUpdate_get_contents(const struct LDKChannelUpdate *NONNULL_PTR this_ptr); - -/** - * The actual channel update - */ -void ChannelUpdate_set_contents(struct LDKChannelUpdate *NONNULL_PTR this_ptr, struct LDKUnsignedChannelUpdate val); - -MUST_USE_RES struct LDKChannelUpdate ChannelUpdate_new(struct LDKSignature signature_arg, struct LDKUnsignedChannelUpdate contents_arg); - -struct LDKChannelUpdate ChannelUpdate_clone(const struct LDKChannelUpdate *NONNULL_PTR orig); - -void QueryChannelRange_free(struct LDKQueryChannelRange this_ptr); - -/** - * The genesis hash of the blockchain being queried - */ -const uint8_t (*QueryChannelRange_get_chain_hash(const struct LDKQueryChannelRange *NONNULL_PTR this_ptr))[32]; - -/** - * The genesis hash of the blockchain being queried - */ -void QueryChannelRange_set_chain_hash(struct LDKQueryChannelRange *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The height of the first block for the channel UTXOs being queried - */ -uint32_t QueryChannelRange_get_first_blocknum(const struct LDKQueryChannelRange *NONNULL_PTR this_ptr); - -/** - * The height of the first block for the channel UTXOs being queried - */ -void QueryChannelRange_set_first_blocknum(struct LDKQueryChannelRange *NONNULL_PTR this_ptr, uint32_t val); - -/** - * The number of blocks to include in the query results - */ -uint32_t QueryChannelRange_get_number_of_blocks(const struct LDKQueryChannelRange *NONNULL_PTR this_ptr); - -/** - * The number of blocks to include in the query results - */ -void QueryChannelRange_set_number_of_blocks(struct LDKQueryChannelRange *NONNULL_PTR this_ptr, uint32_t val); - -MUST_USE_RES struct LDKQueryChannelRange QueryChannelRange_new(struct LDKThirtyTwoBytes chain_hash_arg, uint32_t first_blocknum_arg, uint32_t number_of_blocks_arg); - -struct LDKQueryChannelRange QueryChannelRange_clone(const struct LDKQueryChannelRange *NONNULL_PTR orig); - -void ReplyChannelRange_free(struct LDKReplyChannelRange this_ptr); - -/** - * The genesis hash of the blockchain being queried - */ -const uint8_t (*ReplyChannelRange_get_chain_hash(const struct LDKReplyChannelRange *NONNULL_PTR this_ptr))[32]; - -/** - * The genesis hash of the blockchain being queried - */ -void ReplyChannelRange_set_chain_hash(struct LDKReplyChannelRange *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The height of the first block in the range of the reply - */ -uint32_t ReplyChannelRange_get_first_blocknum(const struct LDKReplyChannelRange *NONNULL_PTR this_ptr); - -/** - * The height of the first block in the range of the reply - */ -void ReplyChannelRange_set_first_blocknum(struct LDKReplyChannelRange *NONNULL_PTR this_ptr, uint32_t val); - -/** - * The number of blocks included in the range of the reply - */ -uint32_t ReplyChannelRange_get_number_of_blocks(const struct LDKReplyChannelRange *NONNULL_PTR this_ptr); - -/** - * The number of blocks included in the range of the reply - */ -void ReplyChannelRange_set_number_of_blocks(struct LDKReplyChannelRange *NONNULL_PTR this_ptr, uint32_t val); - -/** - * True when this is the final reply for a query - */ -bool ReplyChannelRange_get_sync_complete(const struct LDKReplyChannelRange *NONNULL_PTR this_ptr); - -/** - * True when this is the final reply for a query - */ -void ReplyChannelRange_set_sync_complete(struct LDKReplyChannelRange *NONNULL_PTR this_ptr, bool val); - -/** - * The short_channel_ids in the channel range - */ -void ReplyChannelRange_set_short_channel_ids(struct LDKReplyChannelRange *NONNULL_PTR this_ptr, struct LDKCVec_u64Z val); - -MUST_USE_RES struct LDKReplyChannelRange ReplyChannelRange_new(struct LDKThirtyTwoBytes chain_hash_arg, uint32_t first_blocknum_arg, uint32_t number_of_blocks_arg, bool sync_complete_arg, struct LDKCVec_u64Z short_channel_ids_arg); - -struct LDKReplyChannelRange ReplyChannelRange_clone(const struct LDKReplyChannelRange *NONNULL_PTR orig); - -void QueryShortChannelIds_free(struct LDKQueryShortChannelIds this_ptr); - -/** - * The genesis hash of the blockchain being queried - */ -const uint8_t (*QueryShortChannelIds_get_chain_hash(const struct LDKQueryShortChannelIds *NONNULL_PTR this_ptr))[32]; - -/** - * The genesis hash of the blockchain being queried - */ -void QueryShortChannelIds_set_chain_hash(struct LDKQueryShortChannelIds *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The short_channel_ids that are being queried - */ -void QueryShortChannelIds_set_short_channel_ids(struct LDKQueryShortChannelIds *NONNULL_PTR this_ptr, struct LDKCVec_u64Z val); - -MUST_USE_RES struct LDKQueryShortChannelIds QueryShortChannelIds_new(struct LDKThirtyTwoBytes chain_hash_arg, struct LDKCVec_u64Z short_channel_ids_arg); - -struct LDKQueryShortChannelIds QueryShortChannelIds_clone(const struct LDKQueryShortChannelIds *NONNULL_PTR orig); - -void ReplyShortChannelIdsEnd_free(struct LDKReplyShortChannelIdsEnd this_ptr); - -/** - * The genesis hash of the blockchain that was queried - */ -const uint8_t (*ReplyShortChannelIdsEnd_get_chain_hash(const struct LDKReplyShortChannelIdsEnd *NONNULL_PTR this_ptr))[32]; - -/** - * The genesis hash of the blockchain that was queried - */ -void ReplyShortChannelIdsEnd_set_chain_hash(struct LDKReplyShortChannelIdsEnd *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * Indicates if the query recipient maintains up-to-date channel - * information for the chain_hash - */ -bool ReplyShortChannelIdsEnd_get_full_information(const struct LDKReplyShortChannelIdsEnd *NONNULL_PTR this_ptr); - -/** - * Indicates if the query recipient maintains up-to-date channel - * information for the chain_hash - */ -void ReplyShortChannelIdsEnd_set_full_information(struct LDKReplyShortChannelIdsEnd *NONNULL_PTR this_ptr, bool val); - -MUST_USE_RES struct LDKReplyShortChannelIdsEnd ReplyShortChannelIdsEnd_new(struct LDKThirtyTwoBytes chain_hash_arg, bool full_information_arg); - -struct LDKReplyShortChannelIdsEnd ReplyShortChannelIdsEnd_clone(const struct LDKReplyShortChannelIdsEnd *NONNULL_PTR orig); - -void GossipTimestampFilter_free(struct LDKGossipTimestampFilter this_ptr); - -/** - * The genesis hash of the blockchain for channel and node information - */ -const uint8_t (*GossipTimestampFilter_get_chain_hash(const struct LDKGossipTimestampFilter *NONNULL_PTR this_ptr))[32]; - -/** - * The genesis hash of the blockchain for channel and node information - */ -void GossipTimestampFilter_set_chain_hash(struct LDKGossipTimestampFilter *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * The starting unix timestamp - */ -uint32_t GossipTimestampFilter_get_first_timestamp(const struct LDKGossipTimestampFilter *NONNULL_PTR this_ptr); - -/** - * The starting unix timestamp - */ -void GossipTimestampFilter_set_first_timestamp(struct LDKGossipTimestampFilter *NONNULL_PTR this_ptr, uint32_t val); - -/** - * The range of information in seconds - */ -uint32_t GossipTimestampFilter_get_timestamp_range(const struct LDKGossipTimestampFilter *NONNULL_PTR this_ptr); - -/** - * The range of information in seconds - */ -void GossipTimestampFilter_set_timestamp_range(struct LDKGossipTimestampFilter *NONNULL_PTR this_ptr, uint32_t val); - -MUST_USE_RES struct LDKGossipTimestampFilter GossipTimestampFilter_new(struct LDKThirtyTwoBytes chain_hash_arg, uint32_t first_timestamp_arg, uint32_t timestamp_range_arg); - -struct LDKGossipTimestampFilter GossipTimestampFilter_clone(const struct LDKGossipTimestampFilter *NONNULL_PTR orig); - -void ErrorAction_free(struct LDKErrorAction this_ptr); - -struct LDKErrorAction ErrorAction_clone(const struct LDKErrorAction *NONNULL_PTR orig); - -void LightningError_free(struct LDKLightningError this_ptr); - -/** - * A human-readable message describing the error - */ -struct LDKStr LightningError_get_err(const struct LDKLightningError *NONNULL_PTR this_ptr); - -/** - * A human-readable message describing the error - */ -void LightningError_set_err(struct LDKLightningError *NONNULL_PTR this_ptr, struct LDKCVec_u8Z val); - -/** - * The action which should be taken against the offending peer. - */ -struct LDKErrorAction LightningError_get_action(const struct LDKLightningError *NONNULL_PTR this_ptr); - -/** - * The action which should be taken against the offending peer. - */ -void LightningError_set_action(struct LDKLightningError *NONNULL_PTR this_ptr, struct LDKErrorAction val); - -MUST_USE_RES struct LDKLightningError LightningError_new(struct LDKCVec_u8Z err_arg, struct LDKErrorAction action_arg); - -struct LDKLightningError LightningError_clone(const struct LDKLightningError *NONNULL_PTR orig); - -void CommitmentUpdate_free(struct LDKCommitmentUpdate this_ptr); - -/** - * update_add_htlc messages which should be sent - */ -void CommitmentUpdate_set_update_add_htlcs(struct LDKCommitmentUpdate *NONNULL_PTR this_ptr, struct LDKCVec_UpdateAddHTLCZ val); - -/** - * update_fulfill_htlc messages which should be sent - */ -void CommitmentUpdate_set_update_fulfill_htlcs(struct LDKCommitmentUpdate *NONNULL_PTR this_ptr, struct LDKCVec_UpdateFulfillHTLCZ val); - -/** - * update_fail_htlc messages which should be sent - */ -void CommitmentUpdate_set_update_fail_htlcs(struct LDKCommitmentUpdate *NONNULL_PTR this_ptr, struct LDKCVec_UpdateFailHTLCZ val); - -/** - * update_fail_malformed_htlc messages which should be sent - */ -void CommitmentUpdate_set_update_fail_malformed_htlcs(struct LDKCommitmentUpdate *NONNULL_PTR this_ptr, struct LDKCVec_UpdateFailMalformedHTLCZ val); - -/** - * An update_fee message which should be sent - */ -struct LDKUpdateFee CommitmentUpdate_get_update_fee(const struct LDKCommitmentUpdate *NONNULL_PTR this_ptr); - -/** - * An update_fee message which should be sent - */ -void CommitmentUpdate_set_update_fee(struct LDKCommitmentUpdate *NONNULL_PTR this_ptr, struct LDKUpdateFee val); - -/** - * Finally, the commitment_signed message which should be sent - */ -struct LDKCommitmentSigned CommitmentUpdate_get_commitment_signed(const struct LDKCommitmentUpdate *NONNULL_PTR this_ptr); - -/** - * Finally, the commitment_signed message which should be sent - */ -void CommitmentUpdate_set_commitment_signed(struct LDKCommitmentUpdate *NONNULL_PTR this_ptr, struct LDKCommitmentSigned val); - -MUST_USE_RES struct LDKCommitmentUpdate CommitmentUpdate_new(struct LDKCVec_UpdateAddHTLCZ update_add_htlcs_arg, struct LDKCVec_UpdateFulfillHTLCZ update_fulfill_htlcs_arg, struct LDKCVec_UpdateFailHTLCZ update_fail_htlcs_arg, struct LDKCVec_UpdateFailMalformedHTLCZ update_fail_malformed_htlcs_arg, struct LDKUpdateFee update_fee_arg, struct LDKCommitmentSigned commitment_signed_arg); - -struct LDKCommitmentUpdate CommitmentUpdate_clone(const struct LDKCommitmentUpdate *NONNULL_PTR orig); - -void HTLCFailChannelUpdate_free(struct LDKHTLCFailChannelUpdate this_ptr); - -struct LDKHTLCFailChannelUpdate HTLCFailChannelUpdate_clone(const struct LDKHTLCFailChannelUpdate *NONNULL_PTR orig); - -/** - * Calls the free function if one is set - */ -void ChannelMessageHandler_free(struct LDKChannelMessageHandler this_ptr); - -/** - * Calls the free function if one is set - */ -void RoutingMessageHandler_free(struct LDKRoutingMessageHandler this_ptr); - -struct LDKCVec_u8Z AcceptChannel_write(const struct LDKAcceptChannel *NONNULL_PTR obj); - -struct LDKCResult_AcceptChannelDecodeErrorZ AcceptChannel_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z AnnouncementSignatures_write(const struct LDKAnnouncementSignatures *NONNULL_PTR obj); - -struct LDKCResult_AnnouncementSignaturesDecodeErrorZ AnnouncementSignatures_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z ChannelReestablish_write(const struct LDKChannelReestablish *NONNULL_PTR obj); - -struct LDKCResult_ChannelReestablishDecodeErrorZ ChannelReestablish_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z ClosingSigned_write(const struct LDKClosingSigned *NONNULL_PTR obj); - -struct LDKCResult_ClosingSignedDecodeErrorZ ClosingSigned_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z CommitmentSigned_write(const struct LDKCommitmentSigned *NONNULL_PTR obj); - -struct LDKCResult_CommitmentSignedDecodeErrorZ CommitmentSigned_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z FundingCreated_write(const struct LDKFundingCreated *NONNULL_PTR obj); - -struct LDKCResult_FundingCreatedDecodeErrorZ FundingCreated_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z FundingSigned_write(const struct LDKFundingSigned *NONNULL_PTR obj); - -struct LDKCResult_FundingSignedDecodeErrorZ FundingSigned_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z FundingLocked_write(const struct LDKFundingLocked *NONNULL_PTR obj); - -struct LDKCResult_FundingLockedDecodeErrorZ FundingLocked_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z Init_write(const struct LDKInit *NONNULL_PTR obj); - -struct LDKCResult_InitDecodeErrorZ Init_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z OpenChannel_write(const struct LDKOpenChannel *NONNULL_PTR obj); - -struct LDKCResult_OpenChannelDecodeErrorZ OpenChannel_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z RevokeAndACK_write(const struct LDKRevokeAndACK *NONNULL_PTR obj); - -struct LDKCResult_RevokeAndACKDecodeErrorZ RevokeAndACK_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z Shutdown_write(const struct LDKShutdown *NONNULL_PTR obj); - -struct LDKCResult_ShutdownDecodeErrorZ Shutdown_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z UpdateFailHTLC_write(const struct LDKUpdateFailHTLC *NONNULL_PTR obj); - -struct LDKCResult_UpdateFailHTLCDecodeErrorZ UpdateFailHTLC_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z UpdateFailMalformedHTLC_write(const struct LDKUpdateFailMalformedHTLC *NONNULL_PTR obj); - -struct LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ UpdateFailMalformedHTLC_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z UpdateFee_write(const struct LDKUpdateFee *NONNULL_PTR obj); - -struct LDKCResult_UpdateFeeDecodeErrorZ UpdateFee_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z UpdateFulfillHTLC_write(const struct LDKUpdateFulfillHTLC *NONNULL_PTR obj); - -struct LDKCResult_UpdateFulfillHTLCDecodeErrorZ UpdateFulfillHTLC_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z UpdateAddHTLC_write(const struct LDKUpdateAddHTLC *NONNULL_PTR obj); - -struct LDKCResult_UpdateAddHTLCDecodeErrorZ UpdateAddHTLC_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z Ping_write(const struct LDKPing *NONNULL_PTR obj); - -struct LDKCResult_PingDecodeErrorZ Ping_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z Pong_write(const struct LDKPong *NONNULL_PTR obj); - -struct LDKCResult_PongDecodeErrorZ Pong_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z UnsignedChannelAnnouncement_write(const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR obj); - -struct LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ UnsignedChannelAnnouncement_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z ChannelAnnouncement_write(const struct LDKChannelAnnouncement *NONNULL_PTR obj); - -struct LDKCResult_ChannelAnnouncementDecodeErrorZ ChannelAnnouncement_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z UnsignedChannelUpdate_write(const struct LDKUnsignedChannelUpdate *NONNULL_PTR obj); - -struct LDKCResult_UnsignedChannelUpdateDecodeErrorZ UnsignedChannelUpdate_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z ChannelUpdate_write(const struct LDKChannelUpdate *NONNULL_PTR obj); - -struct LDKCResult_ChannelUpdateDecodeErrorZ ChannelUpdate_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z ErrorMessage_write(const struct LDKErrorMessage *NONNULL_PTR obj); - -struct LDKCResult_ErrorMessageDecodeErrorZ ErrorMessage_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z UnsignedNodeAnnouncement_write(const struct LDKUnsignedNodeAnnouncement *NONNULL_PTR obj); - -struct LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ UnsignedNodeAnnouncement_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z NodeAnnouncement_write(const struct LDKNodeAnnouncement *NONNULL_PTR obj); - -struct LDKCResult_NodeAnnouncementDecodeErrorZ NodeAnnouncement_read(struct LDKu8slice ser); - -struct LDKCResult_QueryShortChannelIdsDecodeErrorZ QueryShortChannelIds_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z QueryShortChannelIds_write(const struct LDKQueryShortChannelIds *NONNULL_PTR obj); - -struct LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ ReplyShortChannelIdsEnd_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z ReplyShortChannelIdsEnd_write(const struct LDKReplyShortChannelIdsEnd *NONNULL_PTR obj); - -struct LDKCResult_QueryChannelRangeDecodeErrorZ QueryChannelRange_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z QueryChannelRange_write(const struct LDKQueryChannelRange *NONNULL_PTR obj); - -struct LDKCResult_ReplyChannelRangeDecodeErrorZ ReplyChannelRange_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z ReplyChannelRange_write(const struct LDKReplyChannelRange *NONNULL_PTR obj); - -struct LDKCResult_GossipTimestampFilterDecodeErrorZ GossipTimestampFilter_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z GossipTimestampFilter_write(const struct LDKGossipTimestampFilter *NONNULL_PTR obj); - -void IgnoringMessageHandler_free(struct LDKIgnoringMessageHandler this_ptr); - -MUST_USE_RES struct LDKIgnoringMessageHandler IgnoringMessageHandler_new(void); - -struct LDKMessageSendEventsProvider IgnoringMessageHandler_as_MessageSendEventsProvider(const struct LDKIgnoringMessageHandler *NONNULL_PTR this_arg); - -struct LDKRoutingMessageHandler IgnoringMessageHandler_as_RoutingMessageHandler(const struct LDKIgnoringMessageHandler *NONNULL_PTR this_arg); - -void ErroringMessageHandler_free(struct LDKErroringMessageHandler this_ptr); - -/** - * Constructs a new ErroringMessageHandler - */ -MUST_USE_RES struct LDKErroringMessageHandler ErroringMessageHandler_new(void); - -struct LDKMessageSendEventsProvider ErroringMessageHandler_as_MessageSendEventsProvider(const struct LDKErroringMessageHandler *NONNULL_PTR this_arg); - -struct LDKChannelMessageHandler ErroringMessageHandler_as_ChannelMessageHandler(const struct LDKErroringMessageHandler *NONNULL_PTR this_arg); - -void MessageHandler_free(struct LDKMessageHandler this_ptr); - -/** - * A message handler which handles messages specific to channels. Usually this is just a - * ChannelManager object or a ErroringMessageHandler. - */ -const struct LDKChannelMessageHandler *MessageHandler_get_chan_handler(const struct LDKMessageHandler *NONNULL_PTR this_ptr); - -/** - * A message handler which handles messages specific to channels. Usually this is just a - * ChannelManager object or a ErroringMessageHandler. - */ -void MessageHandler_set_chan_handler(struct LDKMessageHandler *NONNULL_PTR this_ptr, struct LDKChannelMessageHandler val); - -/** - * A message handler which handles messages updating our knowledge of the network channel - * graph. Usually this is just a NetGraphMsgHandlerMonitor object or an IgnoringMessageHandler. - */ -const struct LDKRoutingMessageHandler *MessageHandler_get_route_handler(const struct LDKMessageHandler *NONNULL_PTR this_ptr); - -/** - * A message handler which handles messages updating our knowledge of the network channel - * graph. Usually this is just a NetGraphMsgHandlerMonitor object or an IgnoringMessageHandler. - */ -void MessageHandler_set_route_handler(struct LDKMessageHandler *NONNULL_PTR this_ptr, struct LDKRoutingMessageHandler val); - -MUST_USE_RES struct LDKMessageHandler MessageHandler_new(struct LDKChannelMessageHandler chan_handler_arg, struct LDKRoutingMessageHandler route_handler_arg); - -struct LDKSocketDescriptor SocketDescriptor_clone(const struct LDKSocketDescriptor *NONNULL_PTR orig); - -/** - * Calls the free function if one is set - */ -void SocketDescriptor_free(struct LDKSocketDescriptor this_ptr); - -void PeerHandleError_free(struct LDKPeerHandleError this_ptr); - -/** - * 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. - */ -bool PeerHandleError_get_no_connection_possible(const struct LDKPeerHandleError *NONNULL_PTR this_ptr); - -/** - * 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. - */ -void PeerHandleError_set_no_connection_possible(struct LDKPeerHandleError *NONNULL_PTR this_ptr, bool val); - -MUST_USE_RES struct LDKPeerHandleError PeerHandleError_new(bool no_connection_possible_arg); - -struct LDKPeerHandleError PeerHandleError_clone(const struct LDKPeerHandleError *NONNULL_PTR orig); - -void PeerManager_free(struct LDKPeerManager this_ptr); - -/** - * Constructs a new PeerManager with the given message handlers and node_id secret key - * ephemeral_random_data is used to derive per-connection ephemeral keys and must be - * cryptographically secure random bytes. - */ -MUST_USE_RES struct LDKPeerManager PeerManager_new(struct LDKMessageHandler message_handler, struct LDKSecretKey our_node_secret, const uint8_t (*ephemeral_random_data)[32], struct LDKLogger logger); - -/** - * Get the list of node ids for peers which have completed the initial handshake. - * - * For outbound connections, this will be the same as the their_node_id parameter passed in to - * new_outbound_connection, however entries will only appear once the initial handshake has - * completed and we are sure the remote peer has the private key for the given node_id. - */ -MUST_USE_RES struct LDKCVec_PublicKeyZ PeerManager_get_peer_node_ids(const struct LDKPeerManager *NONNULL_PTR this_arg); - -/** - * Indicates a new outbound connection has been established to a node with the given node_id. - * Note that if an Err is returned here you MUST NOT call socket_disconnected for the new - * descriptor but must disconnect the connection immediately. - * - * Returns a small number of bytes to send to the remote node (currently always 50). - * - * Panics if descriptor is duplicative with some other descriptor which has not yet had a - * socket_disconnected(). - */ -MUST_USE_RES struct LDKCResult_CVec_u8ZPeerHandleErrorZ PeerManager_new_outbound_connection(const struct LDKPeerManager *NONNULL_PTR this_arg, struct LDKPublicKey their_node_id, struct LDKSocketDescriptor descriptor); - -/** - * Indicates a new inbound connection has been established. - * - * May refuse the connection by returning an Err, but will never write bytes to the remote end - * (outbound connector always speaks first). Note that if an Err is returned here you MUST NOT - * call socket_disconnected for the new descriptor but must disconnect the connection - * immediately. - * - * Panics if descriptor is duplicative with some other descriptor which has not yet had - * socket_disconnected called. - */ -MUST_USE_RES struct LDKCResult_NonePeerHandleErrorZ PeerManager_new_inbound_connection(const struct LDKPeerManager *NONNULL_PTR this_arg, struct LDKSocketDescriptor descriptor); - -/** - * Indicates that there is room to write data to the given socket descriptor. - * - * May return an Err to indicate that the connection should be closed. - * - * Will most likely call send_data on the descriptor passed in (or the descriptor handed into - * new_*\\_connection) before returning. Thus, be very careful with reentrancy issues! The - * invariants around calling write_buffer_space_avail in case a write did not fully complete - * must still hold - be ready to call write_buffer_space_avail again if a write call generated - * here isn't sufficient! Panics if the descriptor was not previously registered in a - * new_\\*_connection event. - */ -MUST_USE_RES struct LDKCResult_NonePeerHandleErrorZ PeerManager_write_buffer_space_avail(const struct LDKPeerManager *NONNULL_PTR this_arg, struct LDKSocketDescriptor *NONNULL_PTR descriptor); - -/** - * Indicates that data was read from the given socket descriptor. - * - * May return an Err to indicate that the connection should be closed. - * - * Will *not* call back into send_data on any descriptors to avoid reentrancy complexity. - * Thus, however, you almost certainly want to call process_events() after any read_event to - * generate send_data calls to handle responses. - * - * If Ok(true) is returned, further read_events should not be triggered until a send_data call - * on this file descriptor has resume_read set (preventing DoS issues in the send buffer). - * - * Panics if the descriptor was not previously registered in a new_*_connection event. - */ -MUST_USE_RES struct LDKCResult_boolPeerHandleErrorZ PeerManager_read_event(const struct LDKPeerManager *NONNULL_PTR this_arg, struct LDKSocketDescriptor *NONNULL_PTR peer_descriptor, struct LDKu8slice data); - -/** - * Checks for any events generated by our handlers and processes them. Includes sending most - * response messages as well as messages generated by calls to handler functions directly (eg - * functions like ChannelManager::process_pending_htlc_forward or send_payment). - */ -void PeerManager_process_events(const struct LDKPeerManager *NONNULL_PTR this_arg); - -/** - * Indicates that the given socket descriptor's connection is now closed. - * - * This must only be called if the socket has been disconnected by the peer or your own - * decision to disconnect it and must NOT be called in any case where other parts of this - * library (eg PeerHandleError, explicit disconnect_socket calls) instruct you to disconnect - * the peer. - * - * Panics if the descriptor was not previously registered in a successful new_*_connection event. - */ -void PeerManager_socket_disconnected(const struct LDKPeerManager *NONNULL_PTR this_arg, const struct LDKSocketDescriptor *NONNULL_PTR descriptor); - -/** - * Disconnect a peer given its node id. - * - * Set no_connection_possible to true to prevent any further connection with this peer, - * force-closing any channels we have with it. - * - * If a peer is connected, this will call `disconnect_socket` on the descriptor for the peer, - * so be careful about reentrancy issues. - */ -void PeerManager_disconnect_by_node_id(const struct LDKPeerManager *NONNULL_PTR this_arg, struct LDKPublicKey node_id, bool no_connection_possible); - -/** - * This function should be called roughly once every 30 seconds. - * It will send pings to each peer and disconnect those which did not respond to the last round of pings. - * Will most likely call send_data on all of the registered descriptors, thus, be very careful with reentrancy issues! - */ -void PeerManager_timer_tick_occured(const struct LDKPeerManager *NONNULL_PTR this_arg); - -/** - * Build the commitment secret from the seed and the commitment number - */ -struct LDKThirtyTwoBytes build_commitment_secret(const uint8_t (*commitment_seed)[32], uint64_t idx); - -/** - * Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key) - * from the base secret and the per_commitment_point. - * - * Note that this is infallible iff we trust that at least one of the two input keys are randomly - * generated (ie our own). - */ -struct LDKCResult_SecretKeyErrorZ derive_private_key(struct LDKPublicKey per_commitment_point, const uint8_t (*base_secret)[32]); - -/** - * Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key) - * from the base point and the per_commitment_key. This is the public equivalent of - * derive_private_key - using only public keys to derive a public key instead of private keys. - * - * Note that this is infallible iff we trust that at least one of the two input keys are randomly - * generated (ie our own). - */ -struct LDKCResult_PublicKeyErrorZ derive_public_key(struct LDKPublicKey per_commitment_point, struct LDKPublicKey base_point); - -/** - * Derives a per-commitment-transaction revocation key from its constituent parts. - * - * Only the cheating participant owns a valid witness to propagate a revoked - * commitment transaction, thus per_commitment_secret always come from cheater - * and revocation_base_secret always come from punisher, which is the broadcaster - * of the transaction spending with this key knowledge. - * - * Note that this is infallible iff we trust that at least one of the two input keys are randomly - * generated (ie our own). - */ -struct LDKCResult_SecretKeyErrorZ derive_private_revocation_key(const uint8_t (*per_commitment_secret)[32], const uint8_t (*countersignatory_revocation_base_secret)[32]); - -/** - * Derives a per-commitment-transaction revocation public key from its constituent parts. This is - * the public equivalend of derive_private_revocation_key - using only public keys to derive a - * public key instead of private keys. - * - * Only the cheating participant owns a valid witness to propagate a revoked - * commitment transaction, thus per_commitment_point always come from cheater - * and revocation_base_point always come from punisher, which is the broadcaster - * of the transaction spending with this key knowledge. - * - * Note that this is infallible iff we trust that at least one of the two input keys are randomly - * generated (ie our own). - */ -struct LDKCResult_PublicKeyErrorZ derive_public_revocation_key(struct LDKPublicKey per_commitment_point, struct LDKPublicKey countersignatory_revocation_base_point); - -void TxCreationKeys_free(struct LDKTxCreationKeys this_ptr); - -/** - * The broadcaster's per-commitment public key which was used to derive the other keys. - */ -struct LDKPublicKey TxCreationKeys_get_per_commitment_point(const struct LDKTxCreationKeys *NONNULL_PTR this_ptr); - -/** - * The broadcaster's per-commitment public key which was used to derive the other keys. - */ -void TxCreationKeys_set_per_commitment_point(struct LDKTxCreationKeys *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The revocation key which is used to allow the broadcaster of the commitment - * transaction to provide their counterparty the ability to punish them if they broadcast - * an old state. - */ -struct LDKPublicKey TxCreationKeys_get_revocation_key(const struct LDKTxCreationKeys *NONNULL_PTR this_ptr); - -/** - * The revocation key which is used to allow the broadcaster of the commitment - * transaction to provide their counterparty the ability to punish them if they broadcast - * an old state. - */ -void TxCreationKeys_set_revocation_key(struct LDKTxCreationKeys *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Broadcaster's HTLC Key - */ -struct LDKPublicKey TxCreationKeys_get_broadcaster_htlc_key(const struct LDKTxCreationKeys *NONNULL_PTR this_ptr); - -/** - * Broadcaster's HTLC Key - */ -void TxCreationKeys_set_broadcaster_htlc_key(struct LDKTxCreationKeys *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Countersignatory's HTLC Key - */ -struct LDKPublicKey TxCreationKeys_get_countersignatory_htlc_key(const struct LDKTxCreationKeys *NONNULL_PTR this_ptr); - -/** - * Countersignatory's HTLC Key - */ -void TxCreationKeys_set_countersignatory_htlc_key(struct LDKTxCreationKeys *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Broadcaster's Payment Key (which isn't allowed to be spent from for some delay) - */ -struct LDKPublicKey TxCreationKeys_get_broadcaster_delayed_payment_key(const struct LDKTxCreationKeys *NONNULL_PTR this_ptr); - -/** - * Broadcaster's Payment Key (which isn't allowed to be spent from for some delay) - */ -void TxCreationKeys_set_broadcaster_delayed_payment_key(struct LDKTxCreationKeys *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -MUST_USE_RES struct LDKTxCreationKeys TxCreationKeys_new(struct LDKPublicKey per_commitment_point_arg, struct LDKPublicKey revocation_key_arg, struct LDKPublicKey broadcaster_htlc_key_arg, struct LDKPublicKey countersignatory_htlc_key_arg, struct LDKPublicKey broadcaster_delayed_payment_key_arg); - -struct LDKTxCreationKeys TxCreationKeys_clone(const struct LDKTxCreationKeys *NONNULL_PTR orig); - -struct LDKCVec_u8Z TxCreationKeys_write(const struct LDKTxCreationKeys *NONNULL_PTR obj); - -struct LDKCResult_TxCreationKeysDecodeErrorZ TxCreationKeys_read(struct LDKu8slice ser); - -void ChannelPublicKeys_free(struct LDKChannelPublicKeys this_ptr); - -/** - * 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. - */ -struct LDKPublicKey ChannelPublicKeys_get_funding_pubkey(const struct LDKChannelPublicKeys *NONNULL_PTR this_ptr); - -/** - * 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. - */ -void ChannelPublicKeys_set_funding_pubkey(struct LDKChannelPublicKeys *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The base point which is used (with derive_public_revocation_key) to derive per-commitment - * revocation keys. This is combined with the per-commitment-secret generated by the - * counterparty to create a secret which the counterparty can reveal to revoke previous - * states. - */ -struct LDKPublicKey ChannelPublicKeys_get_revocation_basepoint(const struct LDKChannelPublicKeys *NONNULL_PTR this_ptr); - -/** - * The base point which is used (with derive_public_revocation_key) to derive per-commitment - * revocation keys. This is combined with the per-commitment-secret generated by the - * counterparty to create a secret which the counterparty can reveal to revoke previous - * states. - */ -void ChannelPublicKeys_set_revocation_basepoint(struct LDKChannelPublicKeys *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The public key on which the non-broadcaster (ie the countersignatory) receives an immediately - * spendable primary channel balance on the broadcaster's commitment transaction. This key is - * static across every commitment transaction. - */ -struct LDKPublicKey ChannelPublicKeys_get_payment_point(const struct LDKChannelPublicKeys *NONNULL_PTR this_ptr); - -/** - * The public key on which the non-broadcaster (ie the countersignatory) receives an immediately - * spendable primary channel balance on the broadcaster's commitment transaction. This key is - * static across every commitment transaction. - */ -void ChannelPublicKeys_set_payment_point(struct LDKChannelPublicKeys *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The base point which is used (with derive_public_key) to derive a per-commitment payment - * public key which receives non-HTLC-encumbered funds which are only available for spending - * after some delay (or can be claimed via the revocation path). - */ -struct LDKPublicKey ChannelPublicKeys_get_delayed_payment_basepoint(const struct LDKChannelPublicKeys *NONNULL_PTR this_ptr); - -/** - * The base point which is used (with derive_public_key) to derive a per-commitment payment - * public key which receives non-HTLC-encumbered funds which are only available for spending - * after some delay (or can be claimed via the revocation path). - */ -void ChannelPublicKeys_set_delayed_payment_basepoint(struct LDKChannelPublicKeys *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The base point which is used (with derive_public_key) to derive a per-commitment public key - * which is used to encumber HTLC-in-flight outputs. - */ -struct LDKPublicKey ChannelPublicKeys_get_htlc_basepoint(const struct LDKChannelPublicKeys *NONNULL_PTR this_ptr); - -/** - * The base point which is used (with derive_public_key) to derive a per-commitment public key - * which is used to encumber HTLC-in-flight outputs. - */ -void ChannelPublicKeys_set_htlc_basepoint(struct LDKChannelPublicKeys *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -MUST_USE_RES struct LDKChannelPublicKeys ChannelPublicKeys_new(struct LDKPublicKey funding_pubkey_arg, struct LDKPublicKey revocation_basepoint_arg, struct LDKPublicKey payment_point_arg, struct LDKPublicKey delayed_payment_basepoint_arg, struct LDKPublicKey htlc_basepoint_arg); - -struct LDKChannelPublicKeys ChannelPublicKeys_clone(const struct LDKChannelPublicKeys *NONNULL_PTR orig); - -struct LDKCVec_u8Z ChannelPublicKeys_write(const struct LDKChannelPublicKeys *NONNULL_PTR obj); - -struct LDKCResult_ChannelPublicKeysDecodeErrorZ ChannelPublicKeys_read(struct LDKu8slice ser); - -/** - * Create per-state keys from channel base points and the per-commitment point. - * Key set is asymmetric and can't be used as part of counter-signatory set of transactions. - */ -MUST_USE_RES struct LDKCResult_TxCreationKeysErrorZ TxCreationKeys_derive_new(struct LDKPublicKey per_commitment_point, struct LDKPublicKey broadcaster_delayed_payment_base, struct LDKPublicKey broadcaster_htlc_base, struct LDKPublicKey countersignatory_revocation_base, struct LDKPublicKey countersignatory_htlc_base); - -/** - * Generate per-state keys from channel static keys. - * Key set is asymmetric and can't be used as part of counter-signatory set of transactions. - */ -MUST_USE_RES struct LDKCResult_TxCreationKeysErrorZ TxCreationKeys_from_channel_static_keys(struct LDKPublicKey per_commitment_point, const struct LDKChannelPublicKeys *NONNULL_PTR broadcaster_keys, const struct LDKChannelPublicKeys *NONNULL_PTR countersignatory_keys); - -/** - * A script either spendable by the revocation - * key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain. - * Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions. - */ -struct LDKCVec_u8Z get_revokeable_redeemscript(struct LDKPublicKey revocation_key, uint16_t contest_delay, struct LDKPublicKey broadcaster_delayed_payment_key); - -void HTLCOutputInCommitment_free(struct LDKHTLCOutputInCommitment this_ptr); - -/** - * 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 - * need to compare this value to whether the commitment transaction in question is that of - * the counterparty or our own. - */ -bool HTLCOutputInCommitment_get_offered(const struct LDKHTLCOutputInCommitment *NONNULL_PTR this_ptr); - -/** - * 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 - * need to compare this value to whether the commitment transaction in question is that of - * the counterparty or our own. - */ -void HTLCOutputInCommitment_set_offered(struct LDKHTLCOutputInCommitment *NONNULL_PTR this_ptr, bool val); - -/** - * The value, in msat, of the HTLC. The value as it appears in the commitment transaction is - * this divided by 1000. - */ -uint64_t HTLCOutputInCommitment_get_amount_msat(const struct LDKHTLCOutputInCommitment *NONNULL_PTR this_ptr); - -/** - * The value, in msat, of the HTLC. The value as it appears in the commitment transaction is - * this divided by 1000. - */ -void HTLCOutputInCommitment_set_amount_msat(struct LDKHTLCOutputInCommitment *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The CLTV lock-time at which this HTLC expires. - */ -uint32_t HTLCOutputInCommitment_get_cltv_expiry(const struct LDKHTLCOutputInCommitment *NONNULL_PTR this_ptr); - -/** - * The CLTV lock-time at which this HTLC expires. - */ -void HTLCOutputInCommitment_set_cltv_expiry(struct LDKHTLCOutputInCommitment *NONNULL_PTR this_ptr, uint32_t val); - -/** - * The hash of the preimage which unlocks this HTLC. - */ -const uint8_t (*HTLCOutputInCommitment_get_payment_hash(const struct LDKHTLCOutputInCommitment *NONNULL_PTR this_ptr))[32]; - -/** - * The hash of the preimage which unlocks this HTLC. - */ -void HTLCOutputInCommitment_set_payment_hash(struct LDKHTLCOutputInCommitment *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -struct LDKHTLCOutputInCommitment HTLCOutputInCommitment_clone(const struct LDKHTLCOutputInCommitment *NONNULL_PTR orig); - -struct LDKCVec_u8Z HTLCOutputInCommitment_write(const struct LDKHTLCOutputInCommitment *NONNULL_PTR obj); - -struct LDKCResult_HTLCOutputInCommitmentDecodeErrorZ HTLCOutputInCommitment_read(struct LDKu8slice ser); - -/** - * Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc - * does not need to have its previous_output_index filled. - */ -struct LDKCVec_u8Z get_htlc_redeemscript(const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc, const struct LDKTxCreationKeys *NONNULL_PTR keys); - -/** - * Gets the redeemscript for a funding output from the two funding public keys. - * Note that the order of funding public keys does not matter. - */ -struct LDKCVec_u8Z make_funding_redeemscript(struct LDKPublicKey broadcaster, struct LDKPublicKey countersignatory); - -/** - * panics if htlc.transaction_output_index.is_none()! - */ -struct LDKTransaction build_htlc_transaction(const uint8_t (*prev_hash)[32], uint32_t feerate_per_kw, uint16_t contest_delay, const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc, struct LDKPublicKey broadcaster_delayed_payment_key, struct LDKPublicKey revocation_key); - -void ChannelTransactionParameters_free(struct LDKChannelTransactionParameters this_ptr); - -/** - * Holder public keys - */ -struct LDKChannelPublicKeys ChannelTransactionParameters_get_holder_pubkeys(const struct LDKChannelTransactionParameters *NONNULL_PTR this_ptr); - -/** - * Holder public keys - */ -void ChannelTransactionParameters_set_holder_pubkeys(struct LDKChannelTransactionParameters *NONNULL_PTR this_ptr, struct LDKChannelPublicKeys val); - -/** - * The contest delay selected by the holder, which applies to counterparty-broadcast transactions - */ -uint16_t ChannelTransactionParameters_get_holder_selected_contest_delay(const struct LDKChannelTransactionParameters *NONNULL_PTR this_ptr); - -/** - * The contest delay selected by the holder, which applies to counterparty-broadcast transactions - */ -void ChannelTransactionParameters_set_holder_selected_contest_delay(struct LDKChannelTransactionParameters *NONNULL_PTR this_ptr, uint16_t val); - -/** - * Whether the holder is the initiator of this channel. - * This is an input to the commitment number obscure factor computation. - */ -bool ChannelTransactionParameters_get_is_outbound_from_holder(const struct LDKChannelTransactionParameters *NONNULL_PTR this_ptr); - -/** - * Whether the holder is the initiator of this channel. - * This is an input to the commitment number obscure factor computation. - */ -void ChannelTransactionParameters_set_is_outbound_from_holder(struct LDKChannelTransactionParameters *NONNULL_PTR this_ptr, bool val); - -/** - * The late-bound counterparty channel transaction parameters. - * These parameters are populated at the point in the protocol where the counterparty provides them. - */ -struct LDKCounterpartyChannelTransactionParameters ChannelTransactionParameters_get_counterparty_parameters(const struct LDKChannelTransactionParameters *NONNULL_PTR this_ptr); - -/** - * The late-bound counterparty channel transaction parameters. - * These parameters are populated at the point in the protocol where the counterparty provides them. - */ -void ChannelTransactionParameters_set_counterparty_parameters(struct LDKChannelTransactionParameters *NONNULL_PTR this_ptr, struct LDKCounterpartyChannelTransactionParameters val); - -/** - * The late-bound funding outpoint - */ -struct LDKOutPoint ChannelTransactionParameters_get_funding_outpoint(const struct LDKChannelTransactionParameters *NONNULL_PTR this_ptr); - -/** - * The late-bound funding outpoint - */ -void ChannelTransactionParameters_set_funding_outpoint(struct LDKChannelTransactionParameters *NONNULL_PTR this_ptr, struct LDKOutPoint val); - -MUST_USE_RES struct LDKChannelTransactionParameters ChannelTransactionParameters_new(struct LDKChannelPublicKeys holder_pubkeys_arg, uint16_t holder_selected_contest_delay_arg, bool is_outbound_from_holder_arg, struct LDKCounterpartyChannelTransactionParameters counterparty_parameters_arg, struct LDKOutPoint funding_outpoint_arg); - -struct LDKChannelTransactionParameters ChannelTransactionParameters_clone(const struct LDKChannelTransactionParameters *NONNULL_PTR orig); - -void CounterpartyChannelTransactionParameters_free(struct LDKCounterpartyChannelTransactionParameters this_ptr); - -/** - * Counter-party public keys - */ -struct LDKChannelPublicKeys CounterpartyChannelTransactionParameters_get_pubkeys(const struct LDKCounterpartyChannelTransactionParameters *NONNULL_PTR this_ptr); - -/** - * Counter-party public keys - */ -void CounterpartyChannelTransactionParameters_set_pubkeys(struct LDKCounterpartyChannelTransactionParameters *NONNULL_PTR this_ptr, struct LDKChannelPublicKeys val); - -/** - * The contest delay selected by the counterparty, which applies to holder-broadcast transactions - */ -uint16_t CounterpartyChannelTransactionParameters_get_selected_contest_delay(const struct LDKCounterpartyChannelTransactionParameters *NONNULL_PTR this_ptr); - -/** - * The contest delay selected by the counterparty, which applies to holder-broadcast transactions - */ -void CounterpartyChannelTransactionParameters_set_selected_contest_delay(struct LDKCounterpartyChannelTransactionParameters *NONNULL_PTR this_ptr, uint16_t val); - -MUST_USE_RES struct LDKCounterpartyChannelTransactionParameters CounterpartyChannelTransactionParameters_new(struct LDKChannelPublicKeys pubkeys_arg, uint16_t selected_contest_delay_arg); - -struct LDKCounterpartyChannelTransactionParameters CounterpartyChannelTransactionParameters_clone(const struct LDKCounterpartyChannelTransactionParameters *NONNULL_PTR orig); - -/** - * Whether the late bound parameters are populated. - */ -MUST_USE_RES bool ChannelTransactionParameters_is_populated(const struct LDKChannelTransactionParameters *NONNULL_PTR this_arg); - -/** - * Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters, - * given that the holder is the broadcaster. - * - * self.is_populated() must be true before calling this function. - */ -MUST_USE_RES struct LDKDirectedChannelTransactionParameters ChannelTransactionParameters_as_holder_broadcastable(const struct LDKChannelTransactionParameters *NONNULL_PTR this_arg); - -/** - * Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters, - * given that the counterparty is the broadcaster. - * - * self.is_populated() must be true before calling this function. - */ -MUST_USE_RES struct LDKDirectedChannelTransactionParameters ChannelTransactionParameters_as_counterparty_broadcastable(const struct LDKChannelTransactionParameters *NONNULL_PTR this_arg); - -struct LDKCVec_u8Z CounterpartyChannelTransactionParameters_write(const struct LDKCounterpartyChannelTransactionParameters *NONNULL_PTR obj); - -struct LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ CounterpartyChannelTransactionParameters_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z ChannelTransactionParameters_write(const struct LDKChannelTransactionParameters *NONNULL_PTR obj); - -struct LDKCResult_ChannelTransactionParametersDecodeErrorZ ChannelTransactionParameters_read(struct LDKu8slice ser); - -void DirectedChannelTransactionParameters_free(struct LDKDirectedChannelTransactionParameters this_ptr); - -/** - * Get the channel pubkeys for the broadcaster - */ -MUST_USE_RES struct LDKChannelPublicKeys DirectedChannelTransactionParameters_broadcaster_pubkeys(const struct LDKDirectedChannelTransactionParameters *NONNULL_PTR this_arg); - -/** - * Get the channel pubkeys for the countersignatory - */ -MUST_USE_RES struct LDKChannelPublicKeys DirectedChannelTransactionParameters_countersignatory_pubkeys(const struct LDKDirectedChannelTransactionParameters *NONNULL_PTR this_arg); - -/** - * Get the contest delay applicable to the transactions. - * Note that the contest delay was selected by the countersignatory. - */ -MUST_USE_RES uint16_t DirectedChannelTransactionParameters_contest_delay(const struct LDKDirectedChannelTransactionParameters *NONNULL_PTR this_arg); - -/** - * Whether the channel is outbound from the broadcaster. - * - * The boolean representing the side that initiated the channel is - * an input to the commitment number obscure factor computation. - */ -MUST_USE_RES bool DirectedChannelTransactionParameters_is_outbound(const struct LDKDirectedChannelTransactionParameters *NONNULL_PTR this_arg); - -/** - * The funding outpoint - */ -MUST_USE_RES struct LDKOutPoint DirectedChannelTransactionParameters_funding_outpoint(const struct LDKDirectedChannelTransactionParameters *NONNULL_PTR this_arg); - -void HolderCommitmentTransaction_free(struct LDKHolderCommitmentTransaction this_ptr); - -/** - * Our counterparty's signature for the transaction - */ -struct LDKSignature HolderCommitmentTransaction_get_counterparty_sig(const struct LDKHolderCommitmentTransaction *NONNULL_PTR this_ptr); - -/** - * Our counterparty's signature for the transaction - */ -void HolderCommitmentTransaction_set_counterparty_sig(struct LDKHolderCommitmentTransaction *NONNULL_PTR this_ptr, struct LDKSignature val); - -/** - * All non-dust counterparty HTLC signatures, in the order they appear in the transaction - */ -void HolderCommitmentTransaction_set_counterparty_htlc_sigs(struct LDKHolderCommitmentTransaction *NONNULL_PTR this_ptr, struct LDKCVec_SignatureZ val); - -struct LDKHolderCommitmentTransaction HolderCommitmentTransaction_clone(const struct LDKHolderCommitmentTransaction *NONNULL_PTR orig); - -struct LDKCVec_u8Z HolderCommitmentTransaction_write(const struct LDKHolderCommitmentTransaction *NONNULL_PTR obj); - -struct LDKCResult_HolderCommitmentTransactionDecodeErrorZ HolderCommitmentTransaction_read(struct LDKu8slice ser); - -/** - * Create a new holder transaction with the given counterparty signatures. - * The funding keys are used to figure out which signature should go first when building the transaction for broadcast. - */ -MUST_USE_RES struct LDKHolderCommitmentTransaction HolderCommitmentTransaction_new(struct LDKCommitmentTransaction commitment_tx, struct LDKSignature counterparty_sig, struct LDKCVec_SignatureZ counterparty_htlc_sigs, struct LDKPublicKey holder_funding_key, struct LDKPublicKey counterparty_funding_key); - -void BuiltCommitmentTransaction_free(struct LDKBuiltCommitmentTransaction this_ptr); - -/** - * The commitment transaction - */ -struct LDKTransaction BuiltCommitmentTransaction_get_transaction(const struct LDKBuiltCommitmentTransaction *NONNULL_PTR this_ptr); - -/** - * The commitment transaction - */ -void BuiltCommitmentTransaction_set_transaction(struct LDKBuiltCommitmentTransaction *NONNULL_PTR this_ptr, struct LDKTransaction val); - -/** - * The txid for the commitment transaction. - * - * This is provided as a performance optimization, instead of calling transaction.txid() - * multiple times. - */ -const uint8_t (*BuiltCommitmentTransaction_get_txid(const struct LDKBuiltCommitmentTransaction *NONNULL_PTR this_ptr))[32]; - -/** - * The txid for the commitment transaction. - * - * This is provided as a performance optimization, instead of calling transaction.txid() - * multiple times. - */ -void BuiltCommitmentTransaction_set_txid(struct LDKBuiltCommitmentTransaction *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -MUST_USE_RES struct LDKBuiltCommitmentTransaction BuiltCommitmentTransaction_new(struct LDKTransaction transaction_arg, struct LDKThirtyTwoBytes txid_arg); - -struct LDKBuiltCommitmentTransaction BuiltCommitmentTransaction_clone(const struct LDKBuiltCommitmentTransaction *NONNULL_PTR orig); - -struct LDKCVec_u8Z BuiltCommitmentTransaction_write(const struct LDKBuiltCommitmentTransaction *NONNULL_PTR obj); - -struct LDKCResult_BuiltCommitmentTransactionDecodeErrorZ BuiltCommitmentTransaction_read(struct LDKu8slice ser); - -/** - * Get the SIGHASH_ALL sighash value of the transaction. - * - * This can be used to verify a signature. - */ -MUST_USE_RES struct LDKThirtyTwoBytes BuiltCommitmentTransaction_get_sighash_all(const struct LDKBuiltCommitmentTransaction *NONNULL_PTR this_arg, struct LDKu8slice funding_redeemscript, uint64_t channel_value_satoshis); - -/** - * Sign a transaction, either because we are counter-signing the counterparty's transaction or - * because we are about to broadcast a holder transaction. - */ -MUST_USE_RES struct LDKSignature BuiltCommitmentTransaction_sign(const struct LDKBuiltCommitmentTransaction *NONNULL_PTR this_arg, const uint8_t (*funding_key)[32], struct LDKu8slice funding_redeemscript, uint64_t channel_value_satoshis); - -void CommitmentTransaction_free(struct LDKCommitmentTransaction this_ptr); - -struct LDKCommitmentTransaction CommitmentTransaction_clone(const struct LDKCommitmentTransaction *NONNULL_PTR orig); - -struct LDKCVec_u8Z CommitmentTransaction_write(const struct LDKCommitmentTransaction *NONNULL_PTR obj); - -struct LDKCResult_CommitmentTransactionDecodeErrorZ CommitmentTransaction_read(struct LDKu8slice ser); - -/** - * The backwards-counting commitment number - */ -MUST_USE_RES uint64_t CommitmentTransaction_commitment_number(const struct LDKCommitmentTransaction *NONNULL_PTR this_arg); - -/** - * The value to be sent to the broadcaster - */ -MUST_USE_RES uint64_t CommitmentTransaction_to_broadcaster_value_sat(const struct LDKCommitmentTransaction *NONNULL_PTR this_arg); - -/** - * The value to be sent to the counterparty - */ -MUST_USE_RES uint64_t CommitmentTransaction_to_countersignatory_value_sat(const struct LDKCommitmentTransaction *NONNULL_PTR this_arg); - -/** - * The feerate paid per 1000-weight-unit in this commitment transaction. - */ -MUST_USE_RES uint32_t CommitmentTransaction_feerate_per_kw(const struct LDKCommitmentTransaction *NONNULL_PTR this_arg); - -/** - * Trust our pre-built transaction and derived transaction creation public keys. - * - * Applies a wrapper which allows access to these fields. - * - * This should only be used if you fully trust the builder of this object. It should not - *\tbe used by an external signer - instead use the verify function. - */ -MUST_USE_RES struct LDKTrustedCommitmentTransaction CommitmentTransaction_trust(const struct LDKCommitmentTransaction *NONNULL_PTR this_arg); - -/** - * Verify our pre-built transaction and derived transaction creation public keys. - * - * Applies a wrapper which allows access to these fields. - * - * An external validating signer must call this method before signing - * or using the built transaction. - */ -MUST_USE_RES struct LDKCResult_TrustedCommitmentTransactionNoneZ CommitmentTransaction_verify(const struct LDKCommitmentTransaction *NONNULL_PTR this_arg, const struct LDKDirectedChannelTransactionParameters *NONNULL_PTR channel_parameters, const struct LDKChannelPublicKeys *NONNULL_PTR broadcaster_keys, const struct LDKChannelPublicKeys *NONNULL_PTR countersignatory_keys); - -void TrustedCommitmentTransaction_free(struct LDKTrustedCommitmentTransaction this_ptr); - -/** - * The transaction ID of the built Bitcoin transaction - */ -MUST_USE_RES struct LDKThirtyTwoBytes TrustedCommitmentTransaction_txid(const struct LDKTrustedCommitmentTransaction *NONNULL_PTR this_arg); - -/** - * The pre-built Bitcoin commitment transaction - */ -MUST_USE_RES struct LDKBuiltCommitmentTransaction TrustedCommitmentTransaction_built_transaction(const struct LDKTrustedCommitmentTransaction *NONNULL_PTR this_arg); - -/** - * The pre-calculated transaction creation public keys. - */ -MUST_USE_RES struct LDKTxCreationKeys TrustedCommitmentTransaction_keys(const struct LDKTrustedCommitmentTransaction *NONNULL_PTR this_arg); - -/** - * Get a signature for each HTLC which was included in the commitment transaction (ie for - * which HTLCOutputInCommitment::transaction_output_index.is_some()). - * - * The returned Vec has one entry for each HTLC, and in the same order. - */ -MUST_USE_RES struct LDKCResult_CVec_SignatureZNoneZ TrustedCommitmentTransaction_get_htlc_sigs(const struct LDKTrustedCommitmentTransaction *NONNULL_PTR this_arg, const uint8_t (*htlc_base_key)[32], const struct LDKDirectedChannelTransactionParameters *NONNULL_PTR channel_parameters); - -/** - * Get the transaction number obscure factor - */ -uint64_t get_commitment_transaction_number_obscure_factor(struct LDKPublicKey broadcaster_payment_basepoint, struct LDKPublicKey countersignatory_payment_basepoint, bool outbound_from_broadcaster); - -struct LDKInitFeatures InitFeatures_clone(const struct LDKInitFeatures *NONNULL_PTR orig); - -struct LDKNodeFeatures NodeFeatures_clone(const struct LDKNodeFeatures *NONNULL_PTR orig); - -struct LDKChannelFeatures ChannelFeatures_clone(const struct LDKChannelFeatures *NONNULL_PTR orig); - -void InitFeatures_free(struct LDKInitFeatures this_ptr); - -void NodeFeatures_free(struct LDKNodeFeatures this_ptr); - -void ChannelFeatures_free(struct LDKChannelFeatures this_ptr); - -/** - * Create a blank Features with no features set - */ -MUST_USE_RES struct LDKInitFeatures InitFeatures_empty(void); - -/** - * Creates features known by the implementation as defined by [`T::KNOWN_FEATURE_FLAGS`]. - * - * [`T::KNOWN_FEATURE_FLAGS`]: sealed/trait.Context.html#associatedconstant.KNOWN_FEATURE_FLAGS - */ -MUST_USE_RES struct LDKInitFeatures InitFeatures_known(void); - -/** - * Create a blank Features with no features set - */ -MUST_USE_RES struct LDKNodeFeatures NodeFeatures_empty(void); - -/** - * Creates features known by the implementation as defined by [`T::KNOWN_FEATURE_FLAGS`]. - * - * [`T::KNOWN_FEATURE_FLAGS`]: sealed/trait.Context.html#associatedconstant.KNOWN_FEATURE_FLAGS - */ -MUST_USE_RES struct LDKNodeFeatures NodeFeatures_known(void); - -/** - * Create a blank Features with no features set - */ -MUST_USE_RES struct LDKChannelFeatures ChannelFeatures_empty(void); - -/** - * Creates features known by the implementation as defined by [`T::KNOWN_FEATURE_FLAGS`]. - * - * [`T::KNOWN_FEATURE_FLAGS`]: sealed/trait.Context.html#associatedconstant.KNOWN_FEATURE_FLAGS - */ -MUST_USE_RES struct LDKChannelFeatures ChannelFeatures_known(void); - -struct LDKCVec_u8Z InitFeatures_write(const struct LDKInitFeatures *NONNULL_PTR obj); - -struct LDKCVec_u8Z NodeFeatures_write(const struct LDKNodeFeatures *NONNULL_PTR obj); - -struct LDKCVec_u8Z ChannelFeatures_write(const struct LDKChannelFeatures *NONNULL_PTR obj); - -struct LDKCResult_InitFeaturesDecodeErrorZ InitFeatures_read(struct LDKu8slice ser); - -struct LDKCResult_NodeFeaturesDecodeErrorZ NodeFeatures_read(struct LDKu8slice ser); - -struct LDKCResult_ChannelFeaturesDecodeErrorZ ChannelFeatures_read(struct LDKu8slice ser); - -void RouteHop_free(struct LDKRouteHop this_ptr); - -/** - * The node_id of the node at this hop. - */ -struct LDKPublicKey RouteHop_get_pubkey(const struct LDKRouteHop *NONNULL_PTR this_ptr); - -/** - * The node_id of the node at this hop. - */ -void RouteHop_set_pubkey(struct LDKRouteHop *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The node_announcement features of the node at this hop. For the last hop, these may be - * amended to match the features present in the invoice this node generated. - */ -struct LDKNodeFeatures RouteHop_get_node_features(const struct LDKRouteHop *NONNULL_PTR this_ptr); - -/** - * The node_announcement features of the node at this hop. For the last hop, these may be - * amended to match the features present in the invoice this node generated. - */ -void RouteHop_set_node_features(struct LDKRouteHop *NONNULL_PTR this_ptr, struct LDKNodeFeatures val); - -/** - * The channel that should be used from the previous hop to reach this node. - */ -uint64_t RouteHop_get_short_channel_id(const struct LDKRouteHop *NONNULL_PTR this_ptr); - -/** - * The channel that should be used from the previous hop to reach this node. - */ -void RouteHop_set_short_channel_id(struct LDKRouteHop *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The channel_announcement features of the channel that should be used from the previous hop - * to reach this node. - */ -struct LDKChannelFeatures RouteHop_get_channel_features(const struct LDKRouteHop *NONNULL_PTR this_ptr); - -/** - * The channel_announcement features of the channel that should be used from the previous hop - * to reach this node. - */ -void RouteHop_set_channel_features(struct LDKRouteHop *NONNULL_PTR this_ptr, struct LDKChannelFeatures val); - -/** - * The fee taken on this hop (for paying for the use of the *next* channel in the path). - * For the last hop, this should be the full value of the payment (might be more than - * requested if we had to match htlc_minimum_msat). - */ -uint64_t RouteHop_get_fee_msat(const struct LDKRouteHop *NONNULL_PTR this_ptr); - -/** - * The fee taken on this hop (for paying for the use of the *next* channel in the path). - * For the last hop, this should be the full value of the payment (might be more than - * requested if we had to match htlc_minimum_msat). - */ -void RouteHop_set_fee_msat(struct LDKRouteHop *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The CLTV delta added for this hop. For the last hop, this should be the full CLTV value - * expected at the destination, in excess of the current block height. - */ -uint32_t RouteHop_get_cltv_expiry_delta(const struct LDKRouteHop *NONNULL_PTR this_ptr); - -/** - * The CLTV delta added for this hop. For the last hop, this should be the full CLTV value - * expected at the destination, in excess of the current block height. - */ -void RouteHop_set_cltv_expiry_delta(struct LDKRouteHop *NONNULL_PTR this_ptr, uint32_t val); - -MUST_USE_RES struct LDKRouteHop RouteHop_new(struct LDKPublicKey pubkey_arg, struct LDKNodeFeatures node_features_arg, uint64_t short_channel_id_arg, struct LDKChannelFeatures channel_features_arg, uint64_t fee_msat_arg, uint32_t cltv_expiry_delta_arg); - -struct LDKRouteHop RouteHop_clone(const struct LDKRouteHop *NONNULL_PTR orig); - -void Route_free(struct LDKRoute this_ptr); - -/** - * 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. - * Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the - * destination. Thus, this must always be at least length one. While the maximum length of any - * given path is variable, keeping the length of any path to less than 20 should currently - * ensure it is viable. - */ -void Route_set_paths(struct LDKRoute *NONNULL_PTR this_ptr, struct LDKCVec_CVec_RouteHopZZ val); - -MUST_USE_RES struct LDKRoute Route_new(struct LDKCVec_CVec_RouteHopZZ paths_arg); - -struct LDKRoute Route_clone(const struct LDKRoute *NONNULL_PTR orig); - -struct LDKCVec_u8Z Route_write(const struct LDKRoute *NONNULL_PTR obj); - -struct LDKCResult_RouteDecodeErrorZ Route_read(struct LDKu8slice ser); - -void RouteHint_free(struct LDKRouteHint this_ptr); - -/** - * The node_id of the non-target end of the route - */ -struct LDKPublicKey RouteHint_get_src_node_id(const struct LDKRouteHint *NONNULL_PTR this_ptr); - -/** - * The node_id of the non-target end of the route - */ -void RouteHint_set_src_node_id(struct LDKRouteHint *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * The short_channel_id of this channel - */ -uint64_t RouteHint_get_short_channel_id(const struct LDKRouteHint *NONNULL_PTR this_ptr); - -/** - * The short_channel_id of this channel - */ -void RouteHint_set_short_channel_id(struct LDKRouteHint *NONNULL_PTR this_ptr, uint64_t val); - -/** - * The fees which must be paid to use this channel - */ -struct LDKRoutingFees RouteHint_get_fees(const struct LDKRouteHint *NONNULL_PTR this_ptr); - -/** - * The fees which must be paid to use this channel - */ -void RouteHint_set_fees(struct LDKRouteHint *NONNULL_PTR this_ptr, struct LDKRoutingFees val); - -/** - * The difference in CLTV values between this node and the next node. - */ -uint16_t RouteHint_get_cltv_expiry_delta(const struct LDKRouteHint *NONNULL_PTR this_ptr); - -/** - * The difference in CLTV values between this node and the next node. - */ -void RouteHint_set_cltv_expiry_delta(struct LDKRouteHint *NONNULL_PTR this_ptr, uint16_t val); - -struct LDKRouteHint RouteHint_clone(const struct LDKRouteHint *NONNULL_PTR orig); - -/** - * Gets a route from us (payer) to the given target node (payee). - * - * Extra routing hops between known nodes and the target will be used if they are included in - * last_hops. - * - * If some channels aren't announced, it may be useful to fill in a first_hops with the - * results from a local ChannelManager::list_usable_channels() call. If it is filled in, our - * view of our local channels (from net_graph_msg_handler) will be ignored, and only those - * in first_hops will be used. - * - * Panics if first_hops contains channels without short_channel_ids - * (ChannelManager::list_usable_channels will never include such channels). - * - * The fees on channels from us to next-hops are ignored (as they are assumed to all be - * equal), however the enabled/disabled bit on such channels as well as the - * htlc_minimum_msat/htlc_maximum_msat *are* checked as they may change based on the receiving node. - */ -struct LDKCResult_RouteLightningErrorZ get_route(struct LDKPublicKey our_node_id, const struct LDKNetworkGraph *NONNULL_PTR network, struct LDKPublicKey payee, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKCVec_RouteHintZ last_hops, uint64_t final_value_msat, uint32_t final_cltv, struct LDKLogger logger); - -void NetworkGraph_free(struct LDKNetworkGraph this_ptr); - -struct LDKNetworkGraph NetworkGraph_clone(const struct LDKNetworkGraph *NONNULL_PTR orig); - -void LockedNetworkGraph_free(struct LDKLockedNetworkGraph this_ptr); - -void NetGraphMsgHandler_free(struct LDKNetGraphMsgHandler this_ptr); - -/** - * Creates a new tracker of the actual state of the network of channels and nodes, - * assuming a fresh network graph. - * Chain monitor is used to make sure announced channels exist on-chain, - * channel data is correct, and that the announcement is signed with - * channel owners' keys. - */ -MUST_USE_RES struct LDKNetGraphMsgHandler NetGraphMsgHandler_new(struct LDKThirtyTwoBytes genesis_hash, struct LDKAccess *chain_access, struct LDKLogger logger); - -/** - * Creates a new tracker of the actual state of the network of channels and nodes, - * assuming an existing Network Graph. - */ -MUST_USE_RES struct LDKNetGraphMsgHandler NetGraphMsgHandler_from_net_graph(struct LDKAccess *chain_access, struct LDKLogger logger, struct LDKNetworkGraph network_graph); - -/** - * Adds a provider used to check new announcements. Does not affect - * existing announcements unless they are updated. - * Add, update or remove the provider would replace the current one. - */ -void NetGraphMsgHandler_add_chain_access(struct LDKNetGraphMsgHandler *NONNULL_PTR this_arg, struct LDKAccess *chain_access); - -/** - * Take a read lock on the network_graph and return it in the C-bindings - * newtype helper. This is likely only useful when called via the C - * bindings as you can call `self.network_graph.read().unwrap()` in Rust - * yourself. - */ -MUST_USE_RES struct LDKLockedNetworkGraph NetGraphMsgHandler_read_locked_graph(const struct LDKNetGraphMsgHandler *NONNULL_PTR this_arg); - -/** - * Get a reference to the NetworkGraph which this read-lock contains. - */ -MUST_USE_RES struct LDKNetworkGraph LockedNetworkGraph_graph(const struct LDKLockedNetworkGraph *NONNULL_PTR this_arg); - -struct LDKRoutingMessageHandler NetGraphMsgHandler_as_RoutingMessageHandler(const struct LDKNetGraphMsgHandler *NONNULL_PTR this_arg); - -struct LDKMessageSendEventsProvider NetGraphMsgHandler_as_MessageSendEventsProvider(const struct LDKNetGraphMsgHandler *NONNULL_PTR this_arg); - -void DirectionalChannelInfo_free(struct LDKDirectionalChannelInfo this_ptr); - -/** - * When the last update to the channel direction was issued. - * Value is opaque, as set in the announcement. - */ -uint32_t DirectionalChannelInfo_get_last_update(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); - -/** - * When the last update to the channel direction was issued. - * Value is opaque, as set in the announcement. - */ -void DirectionalChannelInfo_set_last_update(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, uint32_t val); - -/** - * Whether the channel can be currently used for payments (in this one direction). - */ -bool DirectionalChannelInfo_get_enabled(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); - -/** - * Whether the channel can be currently used for payments (in this one direction). - */ -void DirectionalChannelInfo_set_enabled(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, bool val); - -/** - * The difference in CLTV values that you must have when routing through this channel. - */ -uint16_t DirectionalChannelInfo_get_cltv_expiry_delta(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); - -/** - * The difference in CLTV values that you must have when routing through this channel. - */ -void DirectionalChannelInfo_set_cltv_expiry_delta(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, uint16_t val); - -/** - * The minimum value, which must be relayed to the next hop via the channel - */ -uint64_t DirectionalChannelInfo_get_htlc_minimum_msat(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); - -/** - * The minimum value, which must be relayed to the next hop via the channel - */ -void DirectionalChannelInfo_set_htlc_minimum_msat(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, uint64_t val); - -/** - * Fees charged when the channel is used for routing - */ -struct LDKRoutingFees DirectionalChannelInfo_get_fees(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); - -/** - * Fees charged when the channel is used for routing - */ -void DirectionalChannelInfo_set_fees(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, struct LDKRoutingFees val); - -/** - * Most recent update for the channel received from the network - * Mostly redundant with the data we store in fields explicitly. - * Everything else is useful only for sending out for initial routing sync. - * Not stored if contains excess data to prevent DoS. - */ -struct LDKChannelUpdate DirectionalChannelInfo_get_last_update_message(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr); - -/** - * Most recent update for the channel received from the network - * Mostly redundant with the data we store in fields explicitly. - * Everything else is useful only for sending out for initial routing sync. - * Not stored if contains excess data to prevent DoS. - */ -void DirectionalChannelInfo_set_last_update_message(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, struct LDKChannelUpdate val); - -struct LDKDirectionalChannelInfo DirectionalChannelInfo_clone(const struct LDKDirectionalChannelInfo *NONNULL_PTR orig); - -struct LDKCVec_u8Z DirectionalChannelInfo_write(const struct LDKDirectionalChannelInfo *NONNULL_PTR obj); - -struct LDKCResult_DirectionalChannelInfoDecodeErrorZ DirectionalChannelInfo_read(struct LDKu8slice ser); - -void ChannelInfo_free(struct LDKChannelInfo this_ptr); - -/** - * Protocol features of a channel communicated during its announcement - */ -struct LDKChannelFeatures ChannelInfo_get_features(const struct LDKChannelInfo *NONNULL_PTR this_ptr); - -/** - * Protocol features of a channel communicated during its announcement - */ -void ChannelInfo_set_features(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKChannelFeatures val); - -/** - * Source node of the first direction of a channel - */ -struct LDKPublicKey ChannelInfo_get_node_one(const struct LDKChannelInfo *NONNULL_PTR this_ptr); - -/** - * Source node of the first direction of a channel - */ -void ChannelInfo_set_node_one(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Details about the first direction of a channel - */ -struct LDKDirectionalChannelInfo ChannelInfo_get_one_to_two(const struct LDKChannelInfo *NONNULL_PTR this_ptr); - -/** - * Details about the first direction of a channel - */ -void ChannelInfo_set_one_to_two(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKDirectionalChannelInfo val); - -/** - * Source node of the second direction of a channel - */ -struct LDKPublicKey ChannelInfo_get_node_two(const struct LDKChannelInfo *NONNULL_PTR this_ptr); - -/** - * Source node of the second direction of a channel - */ -void ChannelInfo_set_node_two(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKPublicKey val); - -/** - * Details about the second direction of a channel - */ -struct LDKDirectionalChannelInfo ChannelInfo_get_two_to_one(const struct LDKChannelInfo *NONNULL_PTR this_ptr); - -/** - * Details about the second direction of a channel - */ -void ChannelInfo_set_two_to_one(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKDirectionalChannelInfo val); - -/** - * An initial announcement of the channel - * Mostly redundant with the data we store in fields explicitly. - * Everything else is useful only for sending out for initial routing sync. - * Not stored if contains excess data to prevent DoS. - */ -struct LDKChannelAnnouncement ChannelInfo_get_announcement_message(const struct LDKChannelInfo *NONNULL_PTR this_ptr); - -/** - * An initial announcement of the channel - * Mostly redundant with the data we store in fields explicitly. - * Everything else is useful only for sending out for initial routing sync. - * Not stored if contains excess data to prevent DoS. - */ -void ChannelInfo_set_announcement_message(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKChannelAnnouncement val); - -struct LDKChannelInfo ChannelInfo_clone(const struct LDKChannelInfo *NONNULL_PTR orig); - -struct LDKCVec_u8Z ChannelInfo_write(const struct LDKChannelInfo *NONNULL_PTR obj); - -struct LDKCResult_ChannelInfoDecodeErrorZ ChannelInfo_read(struct LDKu8slice ser); - -void RoutingFees_free(struct LDKRoutingFees this_ptr); - -/** - * Flat routing fee in satoshis - */ -uint32_t RoutingFees_get_base_msat(const struct LDKRoutingFees *NONNULL_PTR this_ptr); - -/** - * Flat routing fee in satoshis - */ -void RoutingFees_set_base_msat(struct LDKRoutingFees *NONNULL_PTR this_ptr, uint32_t val); - -/** - * Liquidity-based routing fee in millionths of a routed amount. - * In other words, 10000 is 1%. - */ -uint32_t RoutingFees_get_proportional_millionths(const struct LDKRoutingFees *NONNULL_PTR this_ptr); - -/** - * Liquidity-based routing fee in millionths of a routed amount. - * In other words, 10000 is 1%. - */ -void RoutingFees_set_proportional_millionths(struct LDKRoutingFees *NONNULL_PTR this_ptr, uint32_t val); - -MUST_USE_RES struct LDKRoutingFees RoutingFees_new(uint32_t base_msat_arg, uint32_t proportional_millionths_arg); - -struct LDKRoutingFees RoutingFees_clone(const struct LDKRoutingFees *NONNULL_PTR orig); - -struct LDKCResult_RoutingFeesDecodeErrorZ RoutingFees_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z RoutingFees_write(const struct LDKRoutingFees *NONNULL_PTR obj); - -void NodeAnnouncementInfo_free(struct LDKNodeAnnouncementInfo this_ptr); - -/** - * Protocol features the node announced support for - */ -struct LDKNodeFeatures NodeAnnouncementInfo_get_features(const struct LDKNodeAnnouncementInfo *NONNULL_PTR this_ptr); - -/** - * Protocol features the node announced support for - */ -void NodeAnnouncementInfo_set_features(struct LDKNodeAnnouncementInfo *NONNULL_PTR this_ptr, struct LDKNodeFeatures val); - -/** - * When the last known update to the node state was issued. - * Value is opaque, as set in the announcement. - */ -uint32_t NodeAnnouncementInfo_get_last_update(const struct LDKNodeAnnouncementInfo *NONNULL_PTR this_ptr); - -/** - * When the last known update to the node state was issued. - * Value is opaque, as set in the announcement. - */ -void NodeAnnouncementInfo_set_last_update(struct LDKNodeAnnouncementInfo *NONNULL_PTR this_ptr, uint32_t val); - -/** - * Color assigned to the node - */ -const uint8_t (*NodeAnnouncementInfo_get_rgb(const struct LDKNodeAnnouncementInfo *NONNULL_PTR this_ptr))[3]; - -/** - * Color assigned to the node - */ -void NodeAnnouncementInfo_set_rgb(struct LDKNodeAnnouncementInfo *NONNULL_PTR this_ptr, struct LDKThreeBytes val); - -/** - * Moniker assigned to the node. - * May be invalid or malicious (eg control chars), - * should not be exposed to the user. - */ -const uint8_t (*NodeAnnouncementInfo_get_alias(const struct LDKNodeAnnouncementInfo *NONNULL_PTR this_ptr))[32]; - -/** - * Moniker assigned to the node. - * May be invalid or malicious (eg control chars), - * should not be exposed to the user. - */ -void NodeAnnouncementInfo_set_alias(struct LDKNodeAnnouncementInfo *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val); - -/** - * Internet-level addresses via which one can connect to the node - */ -void NodeAnnouncementInfo_set_addresses(struct LDKNodeAnnouncementInfo *NONNULL_PTR this_ptr, struct LDKCVec_NetAddressZ val); - -/** - * An initial announcement of the node - * Mostly redundant with the data we store in fields explicitly. - * Everything else is useful only for sending out for initial routing sync. - * Not stored if contains excess data to prevent DoS. - */ -struct LDKNodeAnnouncement NodeAnnouncementInfo_get_announcement_message(const struct LDKNodeAnnouncementInfo *NONNULL_PTR this_ptr); - -/** - * An initial announcement of the node - * Mostly redundant with the data we store in fields explicitly. - * Everything else is useful only for sending out for initial routing sync. - * Not stored if contains excess data to prevent DoS. - */ -void NodeAnnouncementInfo_set_announcement_message(struct LDKNodeAnnouncementInfo *NONNULL_PTR this_ptr, struct LDKNodeAnnouncement val); - -MUST_USE_RES struct LDKNodeAnnouncementInfo NodeAnnouncementInfo_new(struct LDKNodeFeatures features_arg, uint32_t last_update_arg, struct LDKThreeBytes rgb_arg, struct LDKThirtyTwoBytes alias_arg, struct LDKCVec_NetAddressZ addresses_arg, struct LDKNodeAnnouncement announcement_message_arg); - -struct LDKNodeAnnouncementInfo NodeAnnouncementInfo_clone(const struct LDKNodeAnnouncementInfo *NONNULL_PTR orig); - -struct LDKCVec_u8Z NodeAnnouncementInfo_write(const struct LDKNodeAnnouncementInfo *NONNULL_PTR obj); - -struct LDKCResult_NodeAnnouncementInfoDecodeErrorZ NodeAnnouncementInfo_read(struct LDKu8slice ser); - -void NodeInfo_free(struct LDKNodeInfo this_ptr); - -/** - * All valid channels a node has announced - */ -void NodeInfo_set_channels(struct LDKNodeInfo *NONNULL_PTR this_ptr, struct LDKCVec_u64Z val); - -/** - * Lowest fees enabling routing via any of the enabled, known channels to a node. - * The two fields (flat and proportional fee) are independent, - * meaning they don't have to refer to the same channel. - */ -struct LDKRoutingFees NodeInfo_get_lowest_inbound_channel_fees(const struct LDKNodeInfo *NONNULL_PTR this_ptr); - -/** - * Lowest fees enabling routing via any of the enabled, known channels to a node. - * The two fields (flat and proportional fee) are independent, - * meaning they don't have to refer to the same channel. - */ -void NodeInfo_set_lowest_inbound_channel_fees(struct LDKNodeInfo *NONNULL_PTR this_ptr, struct LDKRoutingFees val); - -/** - * More information about a node from node_announcement. - * Optional because we store a Node entry after learning about it from - * a channel announcement, but before receiving a node announcement. - */ -struct LDKNodeAnnouncementInfo NodeInfo_get_announcement_info(const struct LDKNodeInfo *NONNULL_PTR this_ptr); - -/** - * More information about a node from node_announcement. - * Optional because we store a Node entry after learning about it from - * a channel announcement, but before receiving a node announcement. - */ -void NodeInfo_set_announcement_info(struct LDKNodeInfo *NONNULL_PTR this_ptr, struct LDKNodeAnnouncementInfo val); - -MUST_USE_RES struct LDKNodeInfo NodeInfo_new(struct LDKCVec_u64Z channels_arg, struct LDKRoutingFees lowest_inbound_channel_fees_arg, struct LDKNodeAnnouncementInfo announcement_info_arg); - -struct LDKNodeInfo NodeInfo_clone(const struct LDKNodeInfo *NONNULL_PTR orig); - -struct LDKCVec_u8Z NodeInfo_write(const struct LDKNodeInfo *NONNULL_PTR obj); - -struct LDKCResult_NodeInfoDecodeErrorZ NodeInfo_read(struct LDKu8slice ser); - -struct LDKCVec_u8Z NetworkGraph_write(const struct LDKNetworkGraph *NONNULL_PTR obj); - -struct LDKCResult_NetworkGraphDecodeErrorZ NetworkGraph_read(struct LDKu8slice ser); - -/** - * Creates a new, empty, network graph. - */ -MUST_USE_RES struct LDKNetworkGraph NetworkGraph_new(struct LDKThirtyTwoBytes genesis_hash); - -/** - * For an already known node (from channel announcements), update its stored properties from a - * given node announcement. - * - * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's - * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept - * routing messages from a source using a protocol other than the lightning P2P protocol. - */ -MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_node_from_announcement(struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKNodeAnnouncement *NONNULL_PTR msg); - -/** - * For an already known node (from channel announcements), update its stored properties from a - * given node announcement without verifying the associated signatures. Because we aren't - * given the associated signatures here we cannot relay the node announcement to any of our - * peers. - */ -MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_node_from_unsigned_announcement(struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKUnsignedNodeAnnouncement *NONNULL_PTR msg); - -/** - * Store or update channel info from a channel announcement. - * - * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's - * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept - * routing messages from a source using a protocol other than the lightning P2P protocol. - * - * If a `chain::Access` object is provided via `chain_access`, it will be called to verify - * the corresponding UTXO exists on chain and is correctly-formatted. - */ -MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_from_announcement(struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKChannelAnnouncement *NONNULL_PTR msg, struct LDKAccess *chain_access); - -/** - * Store or update channel info from a channel announcement without verifying the associated - * signatures. Because we aren't given the associated signatures here we cannot relay the - * channel announcement to any of our peers. - * - * If a `chain::Access` object is provided via `chain_access`, it will be called to verify - * the corresponding UTXO exists on chain and is correctly-formatted. - */ -MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_from_unsigned_announcement(struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR msg, struct LDKAccess *chain_access); - -/** - * Close a channel if a corresponding HTLC fail was sent. - * If permanent, removes a channel from the local storage. - * May cause the removal of nodes too, if this was their last channel. - * If not permanent, makes channels unavailable for routing. - */ -void NetworkGraph_close_channel_from_update(struct LDKNetworkGraph *NONNULL_PTR this_arg, uint64_t short_channel_id, bool is_permanent); - -/** - * For an already known (from announcement) channel, update info about one of the directions - * of the channel. - * - * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's - * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept - * routing messages from a source using a protocol other than the lightning P2P protocol. - */ -MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel(struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKChannelUpdate *NONNULL_PTR msg); - -/** - * For an already known (from announcement) channel, update info about one of the directions - * of the channel without verifying the associated signatures. Because we aren't given the - * associated signatures here we cannot relay the channel update to any of our peers. - */ -MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_unsigned(struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKUnsignedChannelUpdate *NONNULL_PTR msg); - -/* Text to put at the end of the generated file */ diff --git a/lightning-c-bindings/include/lightningpp.hpp b/lightning-c-bindings/include/lightningpp.hpp deleted file mode 100644 index 3151b9c0c..000000000 --- a/lightning-c-bindings/include/lightningpp.hpp +++ /dev/null @@ -1,3389 +0,0 @@ -#include -namespace LDK { -class APIError { -private: - LDKAPIError self; -public: - APIError(const APIError&) = delete; - APIError(APIError&& o) : self(o.self) { memset(&o, 0, sizeof(APIError)); } - APIError(LDKAPIError&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKAPIError)); } - operator LDKAPIError() && { LDKAPIError res = self; memset(&self, 0, sizeof(LDKAPIError)); return res; } - ~APIError() { APIError_free(self); } - APIError& operator=(APIError&& o) { APIError_free(self); self = o.self; memset(&o, 0, sizeof(APIError)); return *this; } - LDKAPIError* operator &() { return &self; } - LDKAPIError* operator ->() { return &self; } - const LDKAPIError* operator &() const { return &self; } - const LDKAPIError* operator ->() const { return &self; } -}; -class TxCreationKeys { -private: - LDKTxCreationKeys self; -public: - TxCreationKeys(const TxCreationKeys&) = delete; - TxCreationKeys(TxCreationKeys&& o) : self(o.self) { memset(&o, 0, sizeof(TxCreationKeys)); } - TxCreationKeys(LDKTxCreationKeys&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKTxCreationKeys)); } - operator LDKTxCreationKeys() && { LDKTxCreationKeys res = self; memset(&self, 0, sizeof(LDKTxCreationKeys)); return res; } - ~TxCreationKeys() { TxCreationKeys_free(self); } - TxCreationKeys& operator=(TxCreationKeys&& o) { TxCreationKeys_free(self); self = o.self; memset(&o, 0, sizeof(TxCreationKeys)); return *this; } - LDKTxCreationKeys* operator &() { return &self; } - LDKTxCreationKeys* operator ->() { return &self; } - const LDKTxCreationKeys* operator &() const { return &self; } - const LDKTxCreationKeys* operator ->() const { return &self; } -}; -class ChannelPublicKeys { -private: - LDKChannelPublicKeys self; -public: - ChannelPublicKeys(const ChannelPublicKeys&) = delete; - ChannelPublicKeys(ChannelPublicKeys&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelPublicKeys)); } - ChannelPublicKeys(LDKChannelPublicKeys&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelPublicKeys)); } - operator LDKChannelPublicKeys() && { LDKChannelPublicKeys res = self; memset(&self, 0, sizeof(LDKChannelPublicKeys)); return res; } - ~ChannelPublicKeys() { ChannelPublicKeys_free(self); } - ChannelPublicKeys& operator=(ChannelPublicKeys&& o) { ChannelPublicKeys_free(self); self = o.self; memset(&o, 0, sizeof(ChannelPublicKeys)); return *this; } - LDKChannelPublicKeys* operator &() { return &self; } - LDKChannelPublicKeys* operator ->() { return &self; } - const LDKChannelPublicKeys* operator &() const { return &self; } - const LDKChannelPublicKeys* operator ->() const { return &self; } -}; -class HTLCOutputInCommitment { -private: - LDKHTLCOutputInCommitment self; -public: - HTLCOutputInCommitment(const HTLCOutputInCommitment&) = delete; - HTLCOutputInCommitment(HTLCOutputInCommitment&& o) : self(o.self) { memset(&o, 0, sizeof(HTLCOutputInCommitment)); } - HTLCOutputInCommitment(LDKHTLCOutputInCommitment&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKHTLCOutputInCommitment)); } - operator LDKHTLCOutputInCommitment() && { LDKHTLCOutputInCommitment res = self; memset(&self, 0, sizeof(LDKHTLCOutputInCommitment)); return res; } - ~HTLCOutputInCommitment() { HTLCOutputInCommitment_free(self); } - HTLCOutputInCommitment& operator=(HTLCOutputInCommitment&& o) { HTLCOutputInCommitment_free(self); self = o.self; memset(&o, 0, sizeof(HTLCOutputInCommitment)); return *this; } - LDKHTLCOutputInCommitment* operator &() { return &self; } - LDKHTLCOutputInCommitment* operator ->() { return &self; } - const LDKHTLCOutputInCommitment* operator &() const { return &self; } - const LDKHTLCOutputInCommitment* operator ->() const { return &self; } -}; -class ChannelTransactionParameters { -private: - LDKChannelTransactionParameters self; -public: - ChannelTransactionParameters(const ChannelTransactionParameters&) = delete; - ChannelTransactionParameters(ChannelTransactionParameters&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelTransactionParameters)); } - ChannelTransactionParameters(LDKChannelTransactionParameters&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelTransactionParameters)); } - operator LDKChannelTransactionParameters() && { LDKChannelTransactionParameters res = self; memset(&self, 0, sizeof(LDKChannelTransactionParameters)); return res; } - ~ChannelTransactionParameters() { ChannelTransactionParameters_free(self); } - ChannelTransactionParameters& operator=(ChannelTransactionParameters&& o) { ChannelTransactionParameters_free(self); self = o.self; memset(&o, 0, sizeof(ChannelTransactionParameters)); return *this; } - LDKChannelTransactionParameters* operator &() { return &self; } - LDKChannelTransactionParameters* operator ->() { return &self; } - const LDKChannelTransactionParameters* operator &() const { return &self; } - const LDKChannelTransactionParameters* operator ->() const { return &self; } -}; -class CounterpartyChannelTransactionParameters { -private: - LDKCounterpartyChannelTransactionParameters self; -public: - CounterpartyChannelTransactionParameters(const CounterpartyChannelTransactionParameters&) = delete; - CounterpartyChannelTransactionParameters(CounterpartyChannelTransactionParameters&& o) : self(o.self) { memset(&o, 0, sizeof(CounterpartyChannelTransactionParameters)); } - CounterpartyChannelTransactionParameters(LDKCounterpartyChannelTransactionParameters&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCounterpartyChannelTransactionParameters)); } - operator LDKCounterpartyChannelTransactionParameters() && { LDKCounterpartyChannelTransactionParameters res = self; memset(&self, 0, sizeof(LDKCounterpartyChannelTransactionParameters)); return res; } - ~CounterpartyChannelTransactionParameters() { CounterpartyChannelTransactionParameters_free(self); } - CounterpartyChannelTransactionParameters& operator=(CounterpartyChannelTransactionParameters&& o) { CounterpartyChannelTransactionParameters_free(self); self = o.self; memset(&o, 0, sizeof(CounterpartyChannelTransactionParameters)); return *this; } - LDKCounterpartyChannelTransactionParameters* operator &() { return &self; } - LDKCounterpartyChannelTransactionParameters* operator ->() { return &self; } - const LDKCounterpartyChannelTransactionParameters* operator &() const { return &self; } - const LDKCounterpartyChannelTransactionParameters* operator ->() const { return &self; } -}; -class DirectedChannelTransactionParameters { -private: - LDKDirectedChannelTransactionParameters self; -public: - DirectedChannelTransactionParameters(const DirectedChannelTransactionParameters&) = delete; - DirectedChannelTransactionParameters(DirectedChannelTransactionParameters&& o) : self(o.self) { memset(&o, 0, sizeof(DirectedChannelTransactionParameters)); } - DirectedChannelTransactionParameters(LDKDirectedChannelTransactionParameters&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKDirectedChannelTransactionParameters)); } - operator LDKDirectedChannelTransactionParameters() && { LDKDirectedChannelTransactionParameters res = self; memset(&self, 0, sizeof(LDKDirectedChannelTransactionParameters)); return res; } - ~DirectedChannelTransactionParameters() { DirectedChannelTransactionParameters_free(self); } - DirectedChannelTransactionParameters& operator=(DirectedChannelTransactionParameters&& o) { DirectedChannelTransactionParameters_free(self); self = o.self; memset(&o, 0, sizeof(DirectedChannelTransactionParameters)); return *this; } - LDKDirectedChannelTransactionParameters* operator &() { return &self; } - LDKDirectedChannelTransactionParameters* operator ->() { return &self; } - const LDKDirectedChannelTransactionParameters* operator &() const { return &self; } - const LDKDirectedChannelTransactionParameters* operator ->() const { return &self; } -}; -class HolderCommitmentTransaction { -private: - LDKHolderCommitmentTransaction self; -public: - HolderCommitmentTransaction(const HolderCommitmentTransaction&) = delete; - HolderCommitmentTransaction(HolderCommitmentTransaction&& o) : self(o.self) { memset(&o, 0, sizeof(HolderCommitmentTransaction)); } - HolderCommitmentTransaction(LDKHolderCommitmentTransaction&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKHolderCommitmentTransaction)); } - operator LDKHolderCommitmentTransaction() && { LDKHolderCommitmentTransaction res = self; memset(&self, 0, sizeof(LDKHolderCommitmentTransaction)); return res; } - ~HolderCommitmentTransaction() { HolderCommitmentTransaction_free(self); } - HolderCommitmentTransaction& operator=(HolderCommitmentTransaction&& o) { HolderCommitmentTransaction_free(self); self = o.self; memset(&o, 0, sizeof(HolderCommitmentTransaction)); return *this; } - LDKHolderCommitmentTransaction* operator &() { return &self; } - LDKHolderCommitmentTransaction* operator ->() { return &self; } - const LDKHolderCommitmentTransaction* operator &() const { return &self; } - const LDKHolderCommitmentTransaction* operator ->() const { return &self; } -}; -class BuiltCommitmentTransaction { -private: - LDKBuiltCommitmentTransaction self; -public: - BuiltCommitmentTransaction(const BuiltCommitmentTransaction&) = delete; - BuiltCommitmentTransaction(BuiltCommitmentTransaction&& o) : self(o.self) { memset(&o, 0, sizeof(BuiltCommitmentTransaction)); } - BuiltCommitmentTransaction(LDKBuiltCommitmentTransaction&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKBuiltCommitmentTransaction)); } - operator LDKBuiltCommitmentTransaction() && { LDKBuiltCommitmentTransaction res = self; memset(&self, 0, sizeof(LDKBuiltCommitmentTransaction)); return res; } - ~BuiltCommitmentTransaction() { BuiltCommitmentTransaction_free(self); } - BuiltCommitmentTransaction& operator=(BuiltCommitmentTransaction&& o) { BuiltCommitmentTransaction_free(self); self = o.self; memset(&o, 0, sizeof(BuiltCommitmentTransaction)); return *this; } - LDKBuiltCommitmentTransaction* operator &() { return &self; } - LDKBuiltCommitmentTransaction* operator ->() { return &self; } - const LDKBuiltCommitmentTransaction* operator &() const { return &self; } - const LDKBuiltCommitmentTransaction* operator ->() const { return &self; } -}; -class CommitmentTransaction { -private: - LDKCommitmentTransaction self; -public: - CommitmentTransaction(const CommitmentTransaction&) = delete; - CommitmentTransaction(CommitmentTransaction&& o) : self(o.self) { memset(&o, 0, sizeof(CommitmentTransaction)); } - CommitmentTransaction(LDKCommitmentTransaction&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCommitmentTransaction)); } - operator LDKCommitmentTransaction() && { LDKCommitmentTransaction res = self; memset(&self, 0, sizeof(LDKCommitmentTransaction)); return res; } - ~CommitmentTransaction() { CommitmentTransaction_free(self); } - CommitmentTransaction& operator=(CommitmentTransaction&& o) { CommitmentTransaction_free(self); self = o.self; memset(&o, 0, sizeof(CommitmentTransaction)); return *this; } - LDKCommitmentTransaction* operator &() { return &self; } - LDKCommitmentTransaction* operator ->() { return &self; } - const LDKCommitmentTransaction* operator &() const { return &self; } - const LDKCommitmentTransaction* operator ->() const { return &self; } -}; -class TrustedCommitmentTransaction { -private: - LDKTrustedCommitmentTransaction self; -public: - TrustedCommitmentTransaction(const TrustedCommitmentTransaction&) = delete; - TrustedCommitmentTransaction(TrustedCommitmentTransaction&& o) : self(o.self) { memset(&o, 0, sizeof(TrustedCommitmentTransaction)); } - TrustedCommitmentTransaction(LDKTrustedCommitmentTransaction&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKTrustedCommitmentTransaction)); } - operator LDKTrustedCommitmentTransaction() && { LDKTrustedCommitmentTransaction res = self; memset(&self, 0, sizeof(LDKTrustedCommitmentTransaction)); return res; } - ~TrustedCommitmentTransaction() { TrustedCommitmentTransaction_free(self); } - TrustedCommitmentTransaction& operator=(TrustedCommitmentTransaction&& o) { TrustedCommitmentTransaction_free(self); self = o.self; memset(&o, 0, sizeof(TrustedCommitmentTransaction)); return *this; } - LDKTrustedCommitmentTransaction* operator &() { return &self; } - LDKTrustedCommitmentTransaction* operator ->() { return &self; } - const LDKTrustedCommitmentTransaction* operator &() const { return &self; } - const LDKTrustedCommitmentTransaction* operator ->() const { return &self; } -}; -class IgnoringMessageHandler { -private: - LDKIgnoringMessageHandler self; -public: - IgnoringMessageHandler(const IgnoringMessageHandler&) = delete; - IgnoringMessageHandler(IgnoringMessageHandler&& o) : self(o.self) { memset(&o, 0, sizeof(IgnoringMessageHandler)); } - IgnoringMessageHandler(LDKIgnoringMessageHandler&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKIgnoringMessageHandler)); } - operator LDKIgnoringMessageHandler() && { LDKIgnoringMessageHandler res = self; memset(&self, 0, sizeof(LDKIgnoringMessageHandler)); return res; } - ~IgnoringMessageHandler() { IgnoringMessageHandler_free(self); } - IgnoringMessageHandler& operator=(IgnoringMessageHandler&& o) { IgnoringMessageHandler_free(self); self = o.self; memset(&o, 0, sizeof(IgnoringMessageHandler)); return *this; } - LDKIgnoringMessageHandler* operator &() { return &self; } - LDKIgnoringMessageHandler* operator ->() { return &self; } - const LDKIgnoringMessageHandler* operator &() const { return &self; } - const LDKIgnoringMessageHandler* operator ->() const { return &self; } -}; -class ErroringMessageHandler { -private: - LDKErroringMessageHandler self; -public: - ErroringMessageHandler(const ErroringMessageHandler&) = delete; - ErroringMessageHandler(ErroringMessageHandler&& o) : self(o.self) { memset(&o, 0, sizeof(ErroringMessageHandler)); } - ErroringMessageHandler(LDKErroringMessageHandler&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKErroringMessageHandler)); } - operator LDKErroringMessageHandler() && { LDKErroringMessageHandler res = self; memset(&self, 0, sizeof(LDKErroringMessageHandler)); return res; } - ~ErroringMessageHandler() { ErroringMessageHandler_free(self); } - ErroringMessageHandler& operator=(ErroringMessageHandler&& o) { ErroringMessageHandler_free(self); self = o.self; memset(&o, 0, sizeof(ErroringMessageHandler)); return *this; } - LDKErroringMessageHandler* operator &() { return &self; } - LDKErroringMessageHandler* operator ->() { return &self; } - const LDKErroringMessageHandler* operator &() const { return &self; } - const LDKErroringMessageHandler* operator ->() const { return &self; } -}; -class MessageHandler { -private: - LDKMessageHandler self; -public: - MessageHandler(const MessageHandler&) = delete; - MessageHandler(MessageHandler&& o) : self(o.self) { memset(&o, 0, sizeof(MessageHandler)); } - MessageHandler(LDKMessageHandler&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKMessageHandler)); } - operator LDKMessageHandler() && { LDKMessageHandler res = self; memset(&self, 0, sizeof(LDKMessageHandler)); return res; } - ~MessageHandler() { MessageHandler_free(self); } - MessageHandler& operator=(MessageHandler&& o) { MessageHandler_free(self); self = o.self; memset(&o, 0, sizeof(MessageHandler)); return *this; } - LDKMessageHandler* operator &() { return &self; } - LDKMessageHandler* operator ->() { return &self; } - const LDKMessageHandler* operator &() const { return &self; } - const LDKMessageHandler* operator ->() const { return &self; } -}; -class SocketDescriptor { -private: - LDKSocketDescriptor self; -public: - SocketDescriptor(const SocketDescriptor&) = delete; - SocketDescriptor(SocketDescriptor&& o) : self(o.self) { memset(&o, 0, sizeof(SocketDescriptor)); } - SocketDescriptor(LDKSocketDescriptor&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKSocketDescriptor)); } - operator LDKSocketDescriptor() && { LDKSocketDescriptor res = self; memset(&self, 0, sizeof(LDKSocketDescriptor)); return res; } - ~SocketDescriptor() { SocketDescriptor_free(self); } - SocketDescriptor& operator=(SocketDescriptor&& o) { SocketDescriptor_free(self); self = o.self; memset(&o, 0, sizeof(SocketDescriptor)); return *this; } - LDKSocketDescriptor* operator &() { return &self; } - LDKSocketDescriptor* operator ->() { return &self; } - const LDKSocketDescriptor* operator &() const { return &self; } - const LDKSocketDescriptor* operator ->() const { return &self; } -}; -class PeerHandleError { -private: - LDKPeerHandleError self; -public: - PeerHandleError(const PeerHandleError&) = delete; - PeerHandleError(PeerHandleError&& o) : self(o.self) { memset(&o, 0, sizeof(PeerHandleError)); } - PeerHandleError(LDKPeerHandleError&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKPeerHandleError)); } - operator LDKPeerHandleError() && { LDKPeerHandleError res = self; memset(&self, 0, sizeof(LDKPeerHandleError)); return res; } - ~PeerHandleError() { PeerHandleError_free(self); } - PeerHandleError& operator=(PeerHandleError&& o) { PeerHandleError_free(self); self = o.self; memset(&o, 0, sizeof(PeerHandleError)); return *this; } - LDKPeerHandleError* operator &() { return &self; } - LDKPeerHandleError* operator ->() { return &self; } - const LDKPeerHandleError* operator &() const { return &self; } - const LDKPeerHandleError* operator ->() const { return &self; } -}; -class PeerManager { -private: - LDKPeerManager self; -public: - PeerManager(const PeerManager&) = delete; - PeerManager(PeerManager&& o) : self(o.self) { memset(&o, 0, sizeof(PeerManager)); } - PeerManager(LDKPeerManager&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKPeerManager)); } - operator LDKPeerManager() && { LDKPeerManager res = self; memset(&self, 0, sizeof(LDKPeerManager)); return res; } - ~PeerManager() { PeerManager_free(self); } - PeerManager& operator=(PeerManager&& o) { PeerManager_free(self); self = o.self; memset(&o, 0, sizeof(PeerManager)); return *this; } - LDKPeerManager* operator &() { return &self; } - LDKPeerManager* operator ->() { return &self; } - const LDKPeerManager* operator &() const { return &self; } - const LDKPeerManager* operator ->() const { return &self; } -}; -class InitFeatures { -private: - LDKInitFeatures self; -public: - InitFeatures(const InitFeatures&) = delete; - InitFeatures(InitFeatures&& o) : self(o.self) { memset(&o, 0, sizeof(InitFeatures)); } - InitFeatures(LDKInitFeatures&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKInitFeatures)); } - operator LDKInitFeatures() && { LDKInitFeatures res = self; memset(&self, 0, sizeof(LDKInitFeatures)); return res; } - ~InitFeatures() { InitFeatures_free(self); } - InitFeatures& operator=(InitFeatures&& o) { InitFeatures_free(self); self = o.self; memset(&o, 0, sizeof(InitFeatures)); return *this; } - LDKInitFeatures* operator &() { return &self; } - LDKInitFeatures* operator ->() { return &self; } - const LDKInitFeatures* operator &() const { return &self; } - const LDKInitFeatures* operator ->() const { return &self; } -}; -class NodeFeatures { -private: - LDKNodeFeatures self; -public: - NodeFeatures(const NodeFeatures&) = delete; - NodeFeatures(NodeFeatures&& o) : self(o.self) { memset(&o, 0, sizeof(NodeFeatures)); } - NodeFeatures(LDKNodeFeatures&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKNodeFeatures)); } - operator LDKNodeFeatures() && { LDKNodeFeatures res = self; memset(&self, 0, sizeof(LDKNodeFeatures)); return res; } - ~NodeFeatures() { NodeFeatures_free(self); } - NodeFeatures& operator=(NodeFeatures&& o) { NodeFeatures_free(self); self = o.self; memset(&o, 0, sizeof(NodeFeatures)); return *this; } - LDKNodeFeatures* operator &() { return &self; } - LDKNodeFeatures* operator ->() { return &self; } - const LDKNodeFeatures* operator &() const { return &self; } - const LDKNodeFeatures* operator ->() const { return &self; } -}; -class ChannelFeatures { -private: - LDKChannelFeatures self; -public: - ChannelFeatures(const ChannelFeatures&) = delete; - ChannelFeatures(ChannelFeatures&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelFeatures)); } - ChannelFeatures(LDKChannelFeatures&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelFeatures)); } - operator LDKChannelFeatures() && { LDKChannelFeatures res = self; memset(&self, 0, sizeof(LDKChannelFeatures)); return res; } - ~ChannelFeatures() { ChannelFeatures_free(self); } - ChannelFeatures& operator=(ChannelFeatures&& o) { ChannelFeatures_free(self); self = o.self; memset(&o, 0, sizeof(ChannelFeatures)); return *this; } - LDKChannelFeatures* operator &() { return &self; } - LDKChannelFeatures* operator ->() { return &self; } - const LDKChannelFeatures* operator &() const { return &self; } - const LDKChannelFeatures* operator ->() const { return &self; } -}; -class ChannelHandshakeConfig { -private: - LDKChannelHandshakeConfig self; -public: - ChannelHandshakeConfig(const ChannelHandshakeConfig&) = delete; - ChannelHandshakeConfig(ChannelHandshakeConfig&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelHandshakeConfig)); } - ChannelHandshakeConfig(LDKChannelHandshakeConfig&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelHandshakeConfig)); } - operator LDKChannelHandshakeConfig() && { LDKChannelHandshakeConfig res = self; memset(&self, 0, sizeof(LDKChannelHandshakeConfig)); return res; } - ~ChannelHandshakeConfig() { ChannelHandshakeConfig_free(self); } - ChannelHandshakeConfig& operator=(ChannelHandshakeConfig&& o) { ChannelHandshakeConfig_free(self); self = o.self; memset(&o, 0, sizeof(ChannelHandshakeConfig)); return *this; } - LDKChannelHandshakeConfig* operator &() { return &self; } - LDKChannelHandshakeConfig* operator ->() { return &self; } - const LDKChannelHandshakeConfig* operator &() const { return &self; } - const LDKChannelHandshakeConfig* operator ->() const { return &self; } -}; -class ChannelHandshakeLimits { -private: - LDKChannelHandshakeLimits self; -public: - ChannelHandshakeLimits(const ChannelHandshakeLimits&) = delete; - ChannelHandshakeLimits(ChannelHandshakeLimits&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelHandshakeLimits)); } - ChannelHandshakeLimits(LDKChannelHandshakeLimits&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelHandshakeLimits)); } - operator LDKChannelHandshakeLimits() && { LDKChannelHandshakeLimits res = self; memset(&self, 0, sizeof(LDKChannelHandshakeLimits)); return res; } - ~ChannelHandshakeLimits() { ChannelHandshakeLimits_free(self); } - ChannelHandshakeLimits& operator=(ChannelHandshakeLimits&& o) { ChannelHandshakeLimits_free(self); self = o.self; memset(&o, 0, sizeof(ChannelHandshakeLimits)); return *this; } - LDKChannelHandshakeLimits* operator &() { return &self; } - LDKChannelHandshakeLimits* operator ->() { return &self; } - const LDKChannelHandshakeLimits* operator &() const { return &self; } - const LDKChannelHandshakeLimits* operator ->() const { return &self; } -}; -class ChannelConfig { -private: - LDKChannelConfig self; -public: - ChannelConfig(const ChannelConfig&) = delete; - ChannelConfig(ChannelConfig&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelConfig)); } - ChannelConfig(LDKChannelConfig&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelConfig)); } - operator LDKChannelConfig() && { LDKChannelConfig res = self; memset(&self, 0, sizeof(LDKChannelConfig)); return res; } - ~ChannelConfig() { ChannelConfig_free(self); } - ChannelConfig& operator=(ChannelConfig&& o) { ChannelConfig_free(self); self = o.self; memset(&o, 0, sizeof(ChannelConfig)); return *this; } - LDKChannelConfig* operator &() { return &self; } - LDKChannelConfig* operator ->() { return &self; } - const LDKChannelConfig* operator &() const { return &self; } - const LDKChannelConfig* operator ->() const { return &self; } -}; -class UserConfig { -private: - LDKUserConfig self; -public: - UserConfig(const UserConfig&) = delete; - UserConfig(UserConfig&& o) : self(o.self) { memset(&o, 0, sizeof(UserConfig)); } - UserConfig(LDKUserConfig&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKUserConfig)); } - operator LDKUserConfig() && { LDKUserConfig res = self; memset(&self, 0, sizeof(LDKUserConfig)); return res; } - ~UserConfig() { UserConfig_free(self); } - UserConfig& operator=(UserConfig&& o) { UserConfig_free(self); self = o.self; memset(&o, 0, sizeof(UserConfig)); return *this; } - LDKUserConfig* operator &() { return &self; } - LDKUserConfig* operator ->() { return &self; } - const LDKUserConfig* operator &() const { return &self; } - const LDKUserConfig* operator ->() const { return &self; } -}; -class NetworkGraph { -private: - LDKNetworkGraph self; -public: - NetworkGraph(const NetworkGraph&) = delete; - NetworkGraph(NetworkGraph&& o) : self(o.self) { memset(&o, 0, sizeof(NetworkGraph)); } - NetworkGraph(LDKNetworkGraph&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKNetworkGraph)); } - operator LDKNetworkGraph() && { LDKNetworkGraph res = self; memset(&self, 0, sizeof(LDKNetworkGraph)); return res; } - ~NetworkGraph() { NetworkGraph_free(self); } - NetworkGraph& operator=(NetworkGraph&& o) { NetworkGraph_free(self); self = o.self; memset(&o, 0, sizeof(NetworkGraph)); return *this; } - LDKNetworkGraph* operator &() { return &self; } - LDKNetworkGraph* operator ->() { return &self; } - const LDKNetworkGraph* operator &() const { return &self; } - const LDKNetworkGraph* operator ->() const { return &self; } -}; -class LockedNetworkGraph { -private: - LDKLockedNetworkGraph self; -public: - LockedNetworkGraph(const LockedNetworkGraph&) = delete; - LockedNetworkGraph(LockedNetworkGraph&& o) : self(o.self) { memset(&o, 0, sizeof(LockedNetworkGraph)); } - LockedNetworkGraph(LDKLockedNetworkGraph&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKLockedNetworkGraph)); } - operator LDKLockedNetworkGraph() && { LDKLockedNetworkGraph res = self; memset(&self, 0, sizeof(LDKLockedNetworkGraph)); return res; } - ~LockedNetworkGraph() { LockedNetworkGraph_free(self); } - LockedNetworkGraph& operator=(LockedNetworkGraph&& o) { LockedNetworkGraph_free(self); self = o.self; memset(&o, 0, sizeof(LockedNetworkGraph)); return *this; } - LDKLockedNetworkGraph* operator &() { return &self; } - LDKLockedNetworkGraph* operator ->() { return &self; } - const LDKLockedNetworkGraph* operator &() const { return &self; } - const LDKLockedNetworkGraph* operator ->() const { return &self; } -}; -class NetGraphMsgHandler { -private: - LDKNetGraphMsgHandler self; -public: - NetGraphMsgHandler(const NetGraphMsgHandler&) = delete; - NetGraphMsgHandler(NetGraphMsgHandler&& o) : self(o.self) { memset(&o, 0, sizeof(NetGraphMsgHandler)); } - NetGraphMsgHandler(LDKNetGraphMsgHandler&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKNetGraphMsgHandler)); } - operator LDKNetGraphMsgHandler() && { LDKNetGraphMsgHandler res = self; memset(&self, 0, sizeof(LDKNetGraphMsgHandler)); return res; } - ~NetGraphMsgHandler() { NetGraphMsgHandler_free(self); } - NetGraphMsgHandler& operator=(NetGraphMsgHandler&& o) { NetGraphMsgHandler_free(self); self = o.self; memset(&o, 0, sizeof(NetGraphMsgHandler)); return *this; } - LDKNetGraphMsgHandler* operator &() { return &self; } - LDKNetGraphMsgHandler* operator ->() { return &self; } - const LDKNetGraphMsgHandler* operator &() const { return &self; } - const LDKNetGraphMsgHandler* operator ->() const { return &self; } -}; -class DirectionalChannelInfo { -private: - LDKDirectionalChannelInfo self; -public: - DirectionalChannelInfo(const DirectionalChannelInfo&) = delete; - DirectionalChannelInfo(DirectionalChannelInfo&& o) : self(o.self) { memset(&o, 0, sizeof(DirectionalChannelInfo)); } - DirectionalChannelInfo(LDKDirectionalChannelInfo&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKDirectionalChannelInfo)); } - operator LDKDirectionalChannelInfo() && { LDKDirectionalChannelInfo res = self; memset(&self, 0, sizeof(LDKDirectionalChannelInfo)); return res; } - ~DirectionalChannelInfo() { DirectionalChannelInfo_free(self); } - DirectionalChannelInfo& operator=(DirectionalChannelInfo&& o) { DirectionalChannelInfo_free(self); self = o.self; memset(&o, 0, sizeof(DirectionalChannelInfo)); return *this; } - LDKDirectionalChannelInfo* operator &() { return &self; } - LDKDirectionalChannelInfo* operator ->() { return &self; } - const LDKDirectionalChannelInfo* operator &() const { return &self; } - const LDKDirectionalChannelInfo* operator ->() const { return &self; } -}; -class ChannelInfo { -private: - LDKChannelInfo self; -public: - ChannelInfo(const ChannelInfo&) = delete; - ChannelInfo(ChannelInfo&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelInfo)); } - ChannelInfo(LDKChannelInfo&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelInfo)); } - operator LDKChannelInfo() && { LDKChannelInfo res = self; memset(&self, 0, sizeof(LDKChannelInfo)); return res; } - ~ChannelInfo() { ChannelInfo_free(self); } - ChannelInfo& operator=(ChannelInfo&& o) { ChannelInfo_free(self); self = o.self; memset(&o, 0, sizeof(ChannelInfo)); return *this; } - LDKChannelInfo* operator &() { return &self; } - LDKChannelInfo* operator ->() { return &self; } - const LDKChannelInfo* operator &() const { return &self; } - const LDKChannelInfo* operator ->() const { return &self; } -}; -class RoutingFees { -private: - LDKRoutingFees self; -public: - RoutingFees(const RoutingFees&) = delete; - RoutingFees(RoutingFees&& o) : self(o.self) { memset(&o, 0, sizeof(RoutingFees)); } - RoutingFees(LDKRoutingFees&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKRoutingFees)); } - operator LDKRoutingFees() && { LDKRoutingFees res = self; memset(&self, 0, sizeof(LDKRoutingFees)); return res; } - ~RoutingFees() { RoutingFees_free(self); } - RoutingFees& operator=(RoutingFees&& o) { RoutingFees_free(self); self = o.self; memset(&o, 0, sizeof(RoutingFees)); return *this; } - LDKRoutingFees* operator &() { return &self; } - LDKRoutingFees* operator ->() { return &self; } - const LDKRoutingFees* operator &() const { return &self; } - const LDKRoutingFees* operator ->() const { return &self; } -}; -class NodeAnnouncementInfo { -private: - LDKNodeAnnouncementInfo self; -public: - NodeAnnouncementInfo(const NodeAnnouncementInfo&) = delete; - NodeAnnouncementInfo(NodeAnnouncementInfo&& o) : self(o.self) { memset(&o, 0, sizeof(NodeAnnouncementInfo)); } - NodeAnnouncementInfo(LDKNodeAnnouncementInfo&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKNodeAnnouncementInfo)); } - operator LDKNodeAnnouncementInfo() && { LDKNodeAnnouncementInfo res = self; memset(&self, 0, sizeof(LDKNodeAnnouncementInfo)); return res; } - ~NodeAnnouncementInfo() { NodeAnnouncementInfo_free(self); } - NodeAnnouncementInfo& operator=(NodeAnnouncementInfo&& o) { NodeAnnouncementInfo_free(self); self = o.self; memset(&o, 0, sizeof(NodeAnnouncementInfo)); return *this; } - LDKNodeAnnouncementInfo* operator &() { return &self; } - LDKNodeAnnouncementInfo* operator ->() { return &self; } - const LDKNodeAnnouncementInfo* operator &() const { return &self; } - const LDKNodeAnnouncementInfo* operator ->() const { return &self; } -}; -class NodeInfo { -private: - LDKNodeInfo self; -public: - NodeInfo(const NodeInfo&) = delete; - NodeInfo(NodeInfo&& o) : self(o.self) { memset(&o, 0, sizeof(NodeInfo)); } - NodeInfo(LDKNodeInfo&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKNodeInfo)); } - operator LDKNodeInfo() && { LDKNodeInfo res = self; memset(&self, 0, sizeof(LDKNodeInfo)); return res; } - ~NodeInfo() { NodeInfo_free(self); } - NodeInfo& operator=(NodeInfo&& o) { NodeInfo_free(self); self = o.self; memset(&o, 0, sizeof(NodeInfo)); return *this; } - LDKNodeInfo* operator &() { return &self; } - LDKNodeInfo* operator ->() { return &self; } - const LDKNodeInfo* operator &() const { return &self; } - const LDKNodeInfo* operator ->() const { return &self; } -}; -class Level { -private: - LDKLevel self; -public: - Level(const Level&) = delete; - Level(Level&& o) : self(o.self) { memset(&o, 0, sizeof(Level)); } - Level(LDKLevel&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKLevel)); } - operator LDKLevel() && { LDKLevel res = self; memset(&self, 0, sizeof(LDKLevel)); return res; } - Level& operator=(Level&& o) { self = o.self; memset(&o, 0, sizeof(Level)); return *this; } - LDKLevel* operator &() { return &self; } - LDKLevel* operator ->() { return &self; } - const LDKLevel* operator &() const { return &self; } - const LDKLevel* operator ->() const { return &self; } -}; -class Logger { -private: - LDKLogger self; -public: - Logger(const Logger&) = delete; - Logger(Logger&& o) : self(o.self) { memset(&o, 0, sizeof(Logger)); } - Logger(LDKLogger&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKLogger)); } - operator LDKLogger() && { LDKLogger res = self; memset(&self, 0, sizeof(LDKLogger)); return res; } - ~Logger() { Logger_free(self); } - Logger& operator=(Logger&& o) { Logger_free(self); self = o.self; memset(&o, 0, sizeof(Logger)); return *this; } - LDKLogger* operator &() { return &self; } - LDKLogger* operator ->() { return &self; } - const LDKLogger* operator &() const { return &self; } - const LDKLogger* operator ->() const { return &self; } -}; -class ChainMonitor { -private: - LDKChainMonitor self; -public: - ChainMonitor(const ChainMonitor&) = delete; - ChainMonitor(ChainMonitor&& o) : self(o.self) { memset(&o, 0, sizeof(ChainMonitor)); } - ChainMonitor(LDKChainMonitor&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChainMonitor)); } - operator LDKChainMonitor() && { LDKChainMonitor res = self; memset(&self, 0, sizeof(LDKChainMonitor)); return res; } - ~ChainMonitor() { ChainMonitor_free(self); } - ChainMonitor& operator=(ChainMonitor&& o) { ChainMonitor_free(self); self = o.self; memset(&o, 0, sizeof(ChainMonitor)); return *this; } - LDKChainMonitor* operator &() { return &self; } - LDKChainMonitor* operator ->() { return &self; } - const LDKChainMonitor* operator &() const { return &self; } - const LDKChainMonitor* operator ->() const { return &self; } -}; -class OutPoint { -private: - LDKOutPoint self; -public: - OutPoint(const OutPoint&) = delete; - OutPoint(OutPoint&& o) : self(o.self) { memset(&o, 0, sizeof(OutPoint)); } - OutPoint(LDKOutPoint&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKOutPoint)); } - operator LDKOutPoint() && { LDKOutPoint res = self; memset(&self, 0, sizeof(LDKOutPoint)); return res; } - ~OutPoint() { OutPoint_free(self); } - OutPoint& operator=(OutPoint&& o) { OutPoint_free(self); self = o.self; memset(&o, 0, sizeof(OutPoint)); return *this; } - LDKOutPoint* operator &() { return &self; } - LDKOutPoint* operator ->() { return &self; } - const LDKOutPoint* operator &() const { return &self; } - const LDKOutPoint* operator ->() const { return &self; } -}; -class ChannelMonitorUpdate { -private: - LDKChannelMonitorUpdate self; -public: - ChannelMonitorUpdate(const ChannelMonitorUpdate&) = delete; - ChannelMonitorUpdate(ChannelMonitorUpdate&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelMonitorUpdate)); } - ChannelMonitorUpdate(LDKChannelMonitorUpdate&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelMonitorUpdate)); } - operator LDKChannelMonitorUpdate() && { LDKChannelMonitorUpdate res = self; memset(&self, 0, sizeof(LDKChannelMonitorUpdate)); return res; } - ~ChannelMonitorUpdate() { ChannelMonitorUpdate_free(self); } - ChannelMonitorUpdate& operator=(ChannelMonitorUpdate&& o) { ChannelMonitorUpdate_free(self); self = o.self; memset(&o, 0, sizeof(ChannelMonitorUpdate)); return *this; } - LDKChannelMonitorUpdate* operator &() { return &self; } - LDKChannelMonitorUpdate* operator ->() { return &self; } - const LDKChannelMonitorUpdate* operator &() const { return &self; } - const LDKChannelMonitorUpdate* operator ->() const { return &self; } -}; -class ChannelMonitorUpdateErr { -private: - LDKChannelMonitorUpdateErr self; -public: - ChannelMonitorUpdateErr(const ChannelMonitorUpdateErr&) = delete; - ChannelMonitorUpdateErr(ChannelMonitorUpdateErr&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelMonitorUpdateErr)); } - ChannelMonitorUpdateErr(LDKChannelMonitorUpdateErr&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelMonitorUpdateErr)); } - operator LDKChannelMonitorUpdateErr() && { LDKChannelMonitorUpdateErr res = self; memset(&self, 0, sizeof(LDKChannelMonitorUpdateErr)); return res; } - ChannelMonitorUpdateErr& operator=(ChannelMonitorUpdateErr&& o) { self = o.self; memset(&o, 0, sizeof(ChannelMonitorUpdateErr)); return *this; } - LDKChannelMonitorUpdateErr* operator &() { return &self; } - LDKChannelMonitorUpdateErr* operator ->() { return &self; } - const LDKChannelMonitorUpdateErr* operator &() const { return &self; } - const LDKChannelMonitorUpdateErr* operator ->() const { return &self; } -}; -class MonitorUpdateError { -private: - LDKMonitorUpdateError self; -public: - MonitorUpdateError(const MonitorUpdateError&) = delete; - MonitorUpdateError(MonitorUpdateError&& o) : self(o.self) { memset(&o, 0, sizeof(MonitorUpdateError)); } - MonitorUpdateError(LDKMonitorUpdateError&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKMonitorUpdateError)); } - operator LDKMonitorUpdateError() && { LDKMonitorUpdateError res = self; memset(&self, 0, sizeof(LDKMonitorUpdateError)); return res; } - ~MonitorUpdateError() { MonitorUpdateError_free(self); } - MonitorUpdateError& operator=(MonitorUpdateError&& o) { MonitorUpdateError_free(self); self = o.self; memset(&o, 0, sizeof(MonitorUpdateError)); return *this; } - LDKMonitorUpdateError* operator &() { return &self; } - LDKMonitorUpdateError* operator ->() { return &self; } - const LDKMonitorUpdateError* operator &() const { return &self; } - const LDKMonitorUpdateError* operator ->() const { return &self; } -}; -class MonitorEvent { -private: - LDKMonitorEvent self; -public: - MonitorEvent(const MonitorEvent&) = delete; - MonitorEvent(MonitorEvent&& o) : self(o.self) { memset(&o, 0, sizeof(MonitorEvent)); } - MonitorEvent(LDKMonitorEvent&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKMonitorEvent)); } - operator LDKMonitorEvent() && { LDKMonitorEvent res = self; memset(&self, 0, sizeof(LDKMonitorEvent)); return res; } - ~MonitorEvent() { MonitorEvent_free(self); } - MonitorEvent& operator=(MonitorEvent&& o) { MonitorEvent_free(self); self = o.self; memset(&o, 0, sizeof(MonitorEvent)); return *this; } - LDKMonitorEvent* operator &() { return &self; } - LDKMonitorEvent* operator ->() { return &self; } - const LDKMonitorEvent* operator &() const { return &self; } - const LDKMonitorEvent* operator ->() const { return &self; } -}; -class HTLCUpdate { -private: - LDKHTLCUpdate self; -public: - HTLCUpdate(const HTLCUpdate&) = delete; - HTLCUpdate(HTLCUpdate&& o) : self(o.self) { memset(&o, 0, sizeof(HTLCUpdate)); } - HTLCUpdate(LDKHTLCUpdate&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKHTLCUpdate)); } - operator LDKHTLCUpdate() && { LDKHTLCUpdate res = self; memset(&self, 0, sizeof(LDKHTLCUpdate)); return res; } - ~HTLCUpdate() { HTLCUpdate_free(self); } - HTLCUpdate& operator=(HTLCUpdate&& o) { HTLCUpdate_free(self); self = o.self; memset(&o, 0, sizeof(HTLCUpdate)); return *this; } - LDKHTLCUpdate* operator &() { return &self; } - LDKHTLCUpdate* operator ->() { return &self; } - const LDKHTLCUpdate* operator &() const { return &self; } - const LDKHTLCUpdate* operator ->() const { return &self; } -}; -class ChannelMonitor { -private: - LDKChannelMonitor self; -public: - ChannelMonitor(const ChannelMonitor&) = delete; - ChannelMonitor(ChannelMonitor&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelMonitor)); } - ChannelMonitor(LDKChannelMonitor&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelMonitor)); } - operator LDKChannelMonitor() && { LDKChannelMonitor res = self; memset(&self, 0, sizeof(LDKChannelMonitor)); return res; } - ~ChannelMonitor() { ChannelMonitor_free(self); } - ChannelMonitor& operator=(ChannelMonitor&& o) { ChannelMonitor_free(self); self = o.self; memset(&o, 0, sizeof(ChannelMonitor)); return *this; } - LDKChannelMonitor* operator &() { return &self; } - LDKChannelMonitor* operator ->() { return &self; } - const LDKChannelMonitor* operator &() const { return &self; } - const LDKChannelMonitor* operator ->() const { return &self; } -}; -class Persist { -private: - LDKPersist self; -public: - Persist(const Persist&) = delete; - Persist(Persist&& o) : self(o.self) { memset(&o, 0, sizeof(Persist)); } - Persist(LDKPersist&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKPersist)); } - operator LDKPersist() && { LDKPersist res = self; memset(&self, 0, sizeof(LDKPersist)); return res; } - ~Persist() { Persist_free(self); } - Persist& operator=(Persist&& o) { Persist_free(self); self = o.self; memset(&o, 0, sizeof(Persist)); return *this; } - LDKPersist* operator &() { return &self; } - LDKPersist* operator ->() { return &self; } - const LDKPersist* operator &() const { return &self; } - const LDKPersist* operator ->() const { return &self; } -}; -class Event { -private: - LDKEvent self; -public: - Event(const Event&) = delete; - Event(Event&& o) : self(o.self) { memset(&o, 0, sizeof(Event)); } - Event(LDKEvent&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKEvent)); } - operator LDKEvent() && { LDKEvent res = self; memset(&self, 0, sizeof(LDKEvent)); return res; } - ~Event() { Event_free(self); } - Event& operator=(Event&& o) { Event_free(self); self = o.self; memset(&o, 0, sizeof(Event)); return *this; } - LDKEvent* operator &() { return &self; } - LDKEvent* operator ->() { return &self; } - const LDKEvent* operator &() const { return &self; } - const LDKEvent* operator ->() const { return &self; } -}; -class MessageSendEvent { -private: - LDKMessageSendEvent self; -public: - MessageSendEvent(const MessageSendEvent&) = delete; - MessageSendEvent(MessageSendEvent&& o) : self(o.self) { memset(&o, 0, sizeof(MessageSendEvent)); } - MessageSendEvent(LDKMessageSendEvent&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKMessageSendEvent)); } - operator LDKMessageSendEvent() && { LDKMessageSendEvent res = self; memset(&self, 0, sizeof(LDKMessageSendEvent)); return res; } - ~MessageSendEvent() { MessageSendEvent_free(self); } - MessageSendEvent& operator=(MessageSendEvent&& o) { MessageSendEvent_free(self); self = o.self; memset(&o, 0, sizeof(MessageSendEvent)); return *this; } - LDKMessageSendEvent* operator &() { return &self; } - LDKMessageSendEvent* operator ->() { return &self; } - const LDKMessageSendEvent* operator &() const { return &self; } - const LDKMessageSendEvent* operator ->() const { return &self; } -}; -class MessageSendEventsProvider { -private: - LDKMessageSendEventsProvider self; -public: - MessageSendEventsProvider(const MessageSendEventsProvider&) = delete; - MessageSendEventsProvider(MessageSendEventsProvider&& o) : self(o.self) { memset(&o, 0, sizeof(MessageSendEventsProvider)); } - MessageSendEventsProvider(LDKMessageSendEventsProvider&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKMessageSendEventsProvider)); } - operator LDKMessageSendEventsProvider() && { LDKMessageSendEventsProvider res = self; memset(&self, 0, sizeof(LDKMessageSendEventsProvider)); return res; } - ~MessageSendEventsProvider() { MessageSendEventsProvider_free(self); } - MessageSendEventsProvider& operator=(MessageSendEventsProvider&& o) { MessageSendEventsProvider_free(self); self = o.self; memset(&o, 0, sizeof(MessageSendEventsProvider)); return *this; } - LDKMessageSendEventsProvider* operator &() { return &self; } - LDKMessageSendEventsProvider* operator ->() { return &self; } - const LDKMessageSendEventsProvider* operator &() const { return &self; } - const LDKMessageSendEventsProvider* operator ->() const { return &self; } -}; -class EventsProvider { -private: - LDKEventsProvider self; -public: - EventsProvider(const EventsProvider&) = delete; - EventsProvider(EventsProvider&& o) : self(o.self) { memset(&o, 0, sizeof(EventsProvider)); } - EventsProvider(LDKEventsProvider&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKEventsProvider)); } - operator LDKEventsProvider() && { LDKEventsProvider res = self; memset(&self, 0, sizeof(LDKEventsProvider)); return res; } - ~EventsProvider() { EventsProvider_free(self); } - EventsProvider& operator=(EventsProvider&& o) { EventsProvider_free(self); self = o.self; memset(&o, 0, sizeof(EventsProvider)); return *this; } - LDKEventsProvider* operator &() { return &self; } - LDKEventsProvider* operator ->() { return &self; } - const LDKEventsProvider* operator &() const { return &self; } - const LDKEventsProvider* operator ->() const { return &self; } -}; -class AccessError { -private: - LDKAccessError self; -public: - AccessError(const AccessError&) = delete; - AccessError(AccessError&& o) : self(o.self) { memset(&o, 0, sizeof(AccessError)); } - AccessError(LDKAccessError&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKAccessError)); } - operator LDKAccessError() && { LDKAccessError res = self; memset(&self, 0, sizeof(LDKAccessError)); return res; } - AccessError& operator=(AccessError&& o) { self = o.self; memset(&o, 0, sizeof(AccessError)); return *this; } - LDKAccessError* operator &() { return &self; } - LDKAccessError* operator ->() { return &self; } - const LDKAccessError* operator &() const { return &self; } - const LDKAccessError* operator ->() const { return &self; } -}; -class Access { -private: - LDKAccess self; -public: - Access(const Access&) = delete; - Access(Access&& o) : self(o.self) { memset(&o, 0, sizeof(Access)); } - Access(LDKAccess&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKAccess)); } - operator LDKAccess() && { LDKAccess res = self; memset(&self, 0, sizeof(LDKAccess)); return res; } - ~Access() { Access_free(self); } - Access& operator=(Access&& o) { Access_free(self); self = o.self; memset(&o, 0, sizeof(Access)); return *this; } - LDKAccess* operator &() { return &self; } - LDKAccess* operator ->() { return &self; } - const LDKAccess* operator &() const { return &self; } - const LDKAccess* operator ->() const { return &self; } -}; -class Listen { -private: - LDKListen self; -public: - Listen(const Listen&) = delete; - Listen(Listen&& o) : self(o.self) { memset(&o, 0, sizeof(Listen)); } - Listen(LDKListen&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKListen)); } - operator LDKListen() && { LDKListen res = self; memset(&self, 0, sizeof(LDKListen)); return res; } - ~Listen() { Listen_free(self); } - Listen& operator=(Listen&& o) { Listen_free(self); self = o.self; memset(&o, 0, sizeof(Listen)); return *this; } - LDKListen* operator &() { return &self; } - LDKListen* operator ->() { return &self; } - const LDKListen* operator &() const { return &self; } - const LDKListen* operator ->() const { return &self; } -}; -class Watch { -private: - LDKWatch self; -public: - Watch(const Watch&) = delete; - Watch(Watch&& o) : self(o.self) { memset(&o, 0, sizeof(Watch)); } - Watch(LDKWatch&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKWatch)); } - operator LDKWatch() && { LDKWatch res = self; memset(&self, 0, sizeof(LDKWatch)); return res; } - ~Watch() { Watch_free(self); } - Watch& operator=(Watch&& o) { Watch_free(self); self = o.self; memset(&o, 0, sizeof(Watch)); return *this; } - LDKWatch* operator &() { return &self; } - LDKWatch* operator ->() { return &self; } - const LDKWatch* operator &() const { return &self; } - const LDKWatch* operator ->() const { return &self; } -}; -class Filter { -private: - LDKFilter self; -public: - Filter(const Filter&) = delete; - Filter(Filter&& o) : self(o.self) { memset(&o, 0, sizeof(Filter)); } - Filter(LDKFilter&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKFilter)); } - operator LDKFilter() && { LDKFilter res = self; memset(&self, 0, sizeof(LDKFilter)); return res; } - ~Filter() { Filter_free(self); } - Filter& operator=(Filter&& o) { Filter_free(self); self = o.self; memset(&o, 0, sizeof(Filter)); return *this; } - LDKFilter* operator &() { return &self; } - LDKFilter* operator ->() { return &self; } - const LDKFilter* operator &() const { return &self; } - const LDKFilter* operator ->() const { return &self; } -}; -class BroadcasterInterface { -private: - LDKBroadcasterInterface self; -public: - BroadcasterInterface(const BroadcasterInterface&) = delete; - BroadcasterInterface(BroadcasterInterface&& o) : self(o.self) { memset(&o, 0, sizeof(BroadcasterInterface)); } - BroadcasterInterface(LDKBroadcasterInterface&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKBroadcasterInterface)); } - operator LDKBroadcasterInterface() && { LDKBroadcasterInterface res = self; memset(&self, 0, sizeof(LDKBroadcasterInterface)); return res; } - ~BroadcasterInterface() { BroadcasterInterface_free(self); } - BroadcasterInterface& operator=(BroadcasterInterface&& o) { BroadcasterInterface_free(self); self = o.self; memset(&o, 0, sizeof(BroadcasterInterface)); return *this; } - LDKBroadcasterInterface* operator &() { return &self; } - LDKBroadcasterInterface* operator ->() { return &self; } - const LDKBroadcasterInterface* operator &() const { return &self; } - const LDKBroadcasterInterface* operator ->() const { return &self; } -}; -class ConfirmationTarget { -private: - LDKConfirmationTarget self; -public: - ConfirmationTarget(const ConfirmationTarget&) = delete; - ConfirmationTarget(ConfirmationTarget&& o) : self(o.self) { memset(&o, 0, sizeof(ConfirmationTarget)); } - ConfirmationTarget(LDKConfirmationTarget&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKConfirmationTarget)); } - operator LDKConfirmationTarget() && { LDKConfirmationTarget res = self; memset(&self, 0, sizeof(LDKConfirmationTarget)); return res; } - ConfirmationTarget& operator=(ConfirmationTarget&& o) { self = o.self; memset(&o, 0, sizeof(ConfirmationTarget)); return *this; } - LDKConfirmationTarget* operator &() { return &self; } - LDKConfirmationTarget* operator ->() { return &self; } - const LDKConfirmationTarget* operator &() const { return &self; } - const LDKConfirmationTarget* operator ->() const { return &self; } -}; -class FeeEstimator { -private: - LDKFeeEstimator self; -public: - FeeEstimator(const FeeEstimator&) = delete; - FeeEstimator(FeeEstimator&& o) : self(o.self) { memset(&o, 0, sizeof(FeeEstimator)); } - FeeEstimator(LDKFeeEstimator&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKFeeEstimator)); } - operator LDKFeeEstimator() && { LDKFeeEstimator res = self; memset(&self, 0, sizeof(LDKFeeEstimator)); return res; } - ~FeeEstimator() { FeeEstimator_free(self); } - FeeEstimator& operator=(FeeEstimator&& o) { FeeEstimator_free(self); self = o.self; memset(&o, 0, sizeof(FeeEstimator)); return *this; } - LDKFeeEstimator* operator &() { return &self; } - LDKFeeEstimator* operator ->() { return &self; } - const LDKFeeEstimator* operator &() const { return &self; } - const LDKFeeEstimator* operator ->() const { return &self; } -}; -class ChannelManager { -private: - LDKChannelManager self; -public: - ChannelManager(const ChannelManager&) = delete; - ChannelManager(ChannelManager&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelManager)); } - ChannelManager(LDKChannelManager&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelManager)); } - operator LDKChannelManager() && { LDKChannelManager res = self; memset(&self, 0, sizeof(LDKChannelManager)); return res; } - ~ChannelManager() { ChannelManager_free(self); } - ChannelManager& operator=(ChannelManager&& o) { ChannelManager_free(self); self = o.self; memset(&o, 0, sizeof(ChannelManager)); return *this; } - LDKChannelManager* operator &() { return &self; } - LDKChannelManager* operator ->() { return &self; } - const LDKChannelManager* operator &() const { return &self; } - const LDKChannelManager* operator ->() const { return &self; } -}; -class ChainParameters { -private: - LDKChainParameters self; -public: - ChainParameters(const ChainParameters&) = delete; - ChainParameters(ChainParameters&& o) : self(o.self) { memset(&o, 0, sizeof(ChainParameters)); } - ChainParameters(LDKChainParameters&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChainParameters)); } - operator LDKChainParameters() && { LDKChainParameters res = self; memset(&self, 0, sizeof(LDKChainParameters)); return res; } - ~ChainParameters() { ChainParameters_free(self); } - ChainParameters& operator=(ChainParameters&& o) { ChainParameters_free(self); self = o.self; memset(&o, 0, sizeof(ChainParameters)); return *this; } - LDKChainParameters* operator &() { return &self; } - LDKChainParameters* operator ->() { return &self; } - const LDKChainParameters* operator &() const { return &self; } - const LDKChainParameters* operator ->() const { return &self; } -}; -class ChannelDetails { -private: - LDKChannelDetails self; -public: - ChannelDetails(const ChannelDetails&) = delete; - ChannelDetails(ChannelDetails&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelDetails)); } - ChannelDetails(LDKChannelDetails&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelDetails)); } - operator LDKChannelDetails() && { LDKChannelDetails res = self; memset(&self, 0, sizeof(LDKChannelDetails)); return res; } - ~ChannelDetails() { ChannelDetails_free(self); } - ChannelDetails& operator=(ChannelDetails&& o) { ChannelDetails_free(self); self = o.self; memset(&o, 0, sizeof(ChannelDetails)); return *this; } - LDKChannelDetails* operator &() { return &self; } - LDKChannelDetails* operator ->() { return &self; } - const LDKChannelDetails* operator &() const { return &self; } - const LDKChannelDetails* operator ->() const { return &self; } -}; -class PaymentSendFailure { -private: - LDKPaymentSendFailure self; -public: - PaymentSendFailure(const PaymentSendFailure&) = delete; - PaymentSendFailure(PaymentSendFailure&& o) : self(o.self) { memset(&o, 0, sizeof(PaymentSendFailure)); } - PaymentSendFailure(LDKPaymentSendFailure&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKPaymentSendFailure)); } - operator LDKPaymentSendFailure() && { LDKPaymentSendFailure res = self; memset(&self, 0, sizeof(LDKPaymentSendFailure)); return res; } - ~PaymentSendFailure() { PaymentSendFailure_free(self); } - PaymentSendFailure& operator=(PaymentSendFailure&& o) { PaymentSendFailure_free(self); self = o.self; memset(&o, 0, sizeof(PaymentSendFailure)); return *this; } - LDKPaymentSendFailure* operator &() { return &self; } - LDKPaymentSendFailure* operator ->() { return &self; } - const LDKPaymentSendFailure* operator &() const { return &self; } - const LDKPaymentSendFailure* operator ->() const { return &self; } -}; -class ChannelManagerReadArgs { -private: - LDKChannelManagerReadArgs self; -public: - ChannelManagerReadArgs(const ChannelManagerReadArgs&) = delete; - ChannelManagerReadArgs(ChannelManagerReadArgs&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelManagerReadArgs)); } - ChannelManagerReadArgs(LDKChannelManagerReadArgs&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelManagerReadArgs)); } - operator LDKChannelManagerReadArgs() && { LDKChannelManagerReadArgs res = self; memset(&self, 0, sizeof(LDKChannelManagerReadArgs)); return res; } - ~ChannelManagerReadArgs() { ChannelManagerReadArgs_free(self); } - ChannelManagerReadArgs& operator=(ChannelManagerReadArgs&& o) { ChannelManagerReadArgs_free(self); self = o.self; memset(&o, 0, sizeof(ChannelManagerReadArgs)); return *this; } - LDKChannelManagerReadArgs* operator &() { return &self; } - LDKChannelManagerReadArgs* operator ->() { return &self; } - const LDKChannelManagerReadArgs* operator &() const { return &self; } - const LDKChannelManagerReadArgs* operator ->() const { return &self; } -}; -class DelayedPaymentOutputDescriptor { -private: - LDKDelayedPaymentOutputDescriptor self; -public: - DelayedPaymentOutputDescriptor(const DelayedPaymentOutputDescriptor&) = delete; - DelayedPaymentOutputDescriptor(DelayedPaymentOutputDescriptor&& o) : self(o.self) { memset(&o, 0, sizeof(DelayedPaymentOutputDescriptor)); } - DelayedPaymentOutputDescriptor(LDKDelayedPaymentOutputDescriptor&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKDelayedPaymentOutputDescriptor)); } - operator LDKDelayedPaymentOutputDescriptor() && { LDKDelayedPaymentOutputDescriptor res = self; memset(&self, 0, sizeof(LDKDelayedPaymentOutputDescriptor)); return res; } - ~DelayedPaymentOutputDescriptor() { DelayedPaymentOutputDescriptor_free(self); } - DelayedPaymentOutputDescriptor& operator=(DelayedPaymentOutputDescriptor&& o) { DelayedPaymentOutputDescriptor_free(self); self = o.self; memset(&o, 0, sizeof(DelayedPaymentOutputDescriptor)); return *this; } - LDKDelayedPaymentOutputDescriptor* operator &() { return &self; } - LDKDelayedPaymentOutputDescriptor* operator ->() { return &self; } - const LDKDelayedPaymentOutputDescriptor* operator &() const { return &self; } - const LDKDelayedPaymentOutputDescriptor* operator ->() const { return &self; } -}; -class StaticPaymentOutputDescriptor { -private: - LDKStaticPaymentOutputDescriptor self; -public: - StaticPaymentOutputDescriptor(const StaticPaymentOutputDescriptor&) = delete; - StaticPaymentOutputDescriptor(StaticPaymentOutputDescriptor&& o) : self(o.self) { memset(&o, 0, sizeof(StaticPaymentOutputDescriptor)); } - StaticPaymentOutputDescriptor(LDKStaticPaymentOutputDescriptor&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKStaticPaymentOutputDescriptor)); } - operator LDKStaticPaymentOutputDescriptor() && { LDKStaticPaymentOutputDescriptor res = self; memset(&self, 0, sizeof(LDKStaticPaymentOutputDescriptor)); return res; } - ~StaticPaymentOutputDescriptor() { StaticPaymentOutputDescriptor_free(self); } - StaticPaymentOutputDescriptor& operator=(StaticPaymentOutputDescriptor&& o) { StaticPaymentOutputDescriptor_free(self); self = o.self; memset(&o, 0, sizeof(StaticPaymentOutputDescriptor)); return *this; } - LDKStaticPaymentOutputDescriptor* operator &() { return &self; } - LDKStaticPaymentOutputDescriptor* operator ->() { return &self; } - const LDKStaticPaymentOutputDescriptor* operator &() const { return &self; } - const LDKStaticPaymentOutputDescriptor* operator ->() const { return &self; } -}; -class SpendableOutputDescriptor { -private: - LDKSpendableOutputDescriptor self; -public: - SpendableOutputDescriptor(const SpendableOutputDescriptor&) = delete; - SpendableOutputDescriptor(SpendableOutputDescriptor&& o) : self(o.self) { memset(&o, 0, sizeof(SpendableOutputDescriptor)); } - SpendableOutputDescriptor(LDKSpendableOutputDescriptor&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKSpendableOutputDescriptor)); } - operator LDKSpendableOutputDescriptor() && { LDKSpendableOutputDescriptor res = self; memset(&self, 0, sizeof(LDKSpendableOutputDescriptor)); return res; } - ~SpendableOutputDescriptor() { SpendableOutputDescriptor_free(self); } - SpendableOutputDescriptor& operator=(SpendableOutputDescriptor&& o) { SpendableOutputDescriptor_free(self); self = o.self; memset(&o, 0, sizeof(SpendableOutputDescriptor)); return *this; } - LDKSpendableOutputDescriptor* operator &() { return &self; } - LDKSpendableOutputDescriptor* operator ->() { return &self; } - const LDKSpendableOutputDescriptor* operator &() const { return &self; } - const LDKSpendableOutputDescriptor* operator ->() const { return &self; } -}; -class Sign { -private: - LDKSign self; -public: - Sign(const Sign&) = delete; - Sign(Sign&& o) : self(o.self) { memset(&o, 0, sizeof(Sign)); } - Sign(LDKSign&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKSign)); } - operator LDKSign() && { LDKSign res = self; memset(&self, 0, sizeof(LDKSign)); return res; } - ~Sign() { Sign_free(self); } - Sign& operator=(Sign&& o) { Sign_free(self); self = o.self; memset(&o, 0, sizeof(Sign)); return *this; } - LDKSign* operator &() { return &self; } - LDKSign* operator ->() { return &self; } - const LDKSign* operator &() const { return &self; } - const LDKSign* operator ->() const { return &self; } -}; -class KeysInterface { -private: - LDKKeysInterface self; -public: - KeysInterface(const KeysInterface&) = delete; - KeysInterface(KeysInterface&& o) : self(o.self) { memset(&o, 0, sizeof(KeysInterface)); } - KeysInterface(LDKKeysInterface&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKKeysInterface)); } - operator LDKKeysInterface() && { LDKKeysInterface res = self; memset(&self, 0, sizeof(LDKKeysInterface)); return res; } - ~KeysInterface() { KeysInterface_free(self); } - KeysInterface& operator=(KeysInterface&& o) { KeysInterface_free(self); self = o.self; memset(&o, 0, sizeof(KeysInterface)); return *this; } - LDKKeysInterface* operator &() { return &self; } - LDKKeysInterface* operator ->() { return &self; } - const LDKKeysInterface* operator &() const { return &self; } - const LDKKeysInterface* operator ->() const { return &self; } -}; -class InMemorySigner { -private: - LDKInMemorySigner self; -public: - InMemorySigner(const InMemorySigner&) = delete; - InMemorySigner(InMemorySigner&& o) : self(o.self) { memset(&o, 0, sizeof(InMemorySigner)); } - InMemorySigner(LDKInMemorySigner&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKInMemorySigner)); } - operator LDKInMemorySigner() && { LDKInMemorySigner res = self; memset(&self, 0, sizeof(LDKInMemorySigner)); return res; } - ~InMemorySigner() { InMemorySigner_free(self); } - InMemorySigner& operator=(InMemorySigner&& o) { InMemorySigner_free(self); self = o.self; memset(&o, 0, sizeof(InMemorySigner)); return *this; } - LDKInMemorySigner* operator &() { return &self; } - LDKInMemorySigner* operator ->() { return &self; } - const LDKInMemorySigner* operator &() const { return &self; } - const LDKInMemorySigner* operator ->() const { return &self; } -}; -class KeysManager { -private: - LDKKeysManager self; -public: - KeysManager(const KeysManager&) = delete; - KeysManager(KeysManager&& o) : self(o.self) { memset(&o, 0, sizeof(KeysManager)); } - KeysManager(LDKKeysManager&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKKeysManager)); } - operator LDKKeysManager() && { LDKKeysManager res = self; memset(&self, 0, sizeof(LDKKeysManager)); return res; } - ~KeysManager() { KeysManager_free(self); } - KeysManager& operator=(KeysManager&& o) { KeysManager_free(self); self = o.self; memset(&o, 0, sizeof(KeysManager)); return *this; } - LDKKeysManager* operator &() { return &self; } - LDKKeysManager* operator ->() { return &self; } - const LDKKeysManager* operator &() const { return &self; } - const LDKKeysManager* operator ->() const { return &self; } -}; -class RouteHop { -private: - LDKRouteHop self; -public: - RouteHop(const RouteHop&) = delete; - RouteHop(RouteHop&& o) : self(o.self) { memset(&o, 0, sizeof(RouteHop)); } - RouteHop(LDKRouteHop&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKRouteHop)); } - operator LDKRouteHop() && { LDKRouteHop res = self; memset(&self, 0, sizeof(LDKRouteHop)); return res; } - ~RouteHop() { RouteHop_free(self); } - RouteHop& operator=(RouteHop&& o) { RouteHop_free(self); self = o.self; memset(&o, 0, sizeof(RouteHop)); return *this; } - LDKRouteHop* operator &() { return &self; } - LDKRouteHop* operator ->() { return &self; } - const LDKRouteHop* operator &() const { return &self; } - const LDKRouteHop* operator ->() const { return &self; } -}; -class Route { -private: - LDKRoute self; -public: - Route(const Route&) = delete; - Route(Route&& o) : self(o.self) { memset(&o, 0, sizeof(Route)); } - Route(LDKRoute&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKRoute)); } - operator LDKRoute() && { LDKRoute res = self; memset(&self, 0, sizeof(LDKRoute)); return res; } - ~Route() { Route_free(self); } - Route& operator=(Route&& o) { Route_free(self); self = o.self; memset(&o, 0, sizeof(Route)); return *this; } - LDKRoute* operator &() { return &self; } - LDKRoute* operator ->() { return &self; } - const LDKRoute* operator &() const { return &self; } - const LDKRoute* operator ->() const { return &self; } -}; -class RouteHint { -private: - LDKRouteHint self; -public: - RouteHint(const RouteHint&) = delete; - RouteHint(RouteHint&& o) : self(o.self) { memset(&o, 0, sizeof(RouteHint)); } - RouteHint(LDKRouteHint&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKRouteHint)); } - operator LDKRouteHint() && { LDKRouteHint res = self; memset(&self, 0, sizeof(LDKRouteHint)); return res; } - ~RouteHint() { RouteHint_free(self); } - RouteHint& operator=(RouteHint&& o) { RouteHint_free(self); self = o.self; memset(&o, 0, sizeof(RouteHint)); return *this; } - LDKRouteHint* operator &() { return &self; } - LDKRouteHint* operator ->() { return &self; } - const LDKRouteHint* operator &() const { return &self; } - const LDKRouteHint* operator ->() const { return &self; } -}; -class DecodeError { -private: - LDKDecodeError self; -public: - DecodeError(const DecodeError&) = delete; - DecodeError(DecodeError&& o) : self(o.self) { memset(&o, 0, sizeof(DecodeError)); } - DecodeError(LDKDecodeError&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKDecodeError)); } - operator LDKDecodeError() && { LDKDecodeError res = self; memset(&self, 0, sizeof(LDKDecodeError)); return res; } - ~DecodeError() { DecodeError_free(self); } - DecodeError& operator=(DecodeError&& o) { DecodeError_free(self); self = o.self; memset(&o, 0, sizeof(DecodeError)); return *this; } - LDKDecodeError* operator &() { return &self; } - LDKDecodeError* operator ->() { return &self; } - const LDKDecodeError* operator &() const { return &self; } - const LDKDecodeError* operator ->() const { return &self; } -}; -class Init { -private: - LDKInit self; -public: - Init(const Init&) = delete; - Init(Init&& o) : self(o.self) { memset(&o, 0, sizeof(Init)); } - Init(LDKInit&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKInit)); } - operator LDKInit() && { LDKInit res = self; memset(&self, 0, sizeof(LDKInit)); return res; } - ~Init() { Init_free(self); } - Init& operator=(Init&& o) { Init_free(self); self = o.self; memset(&o, 0, sizeof(Init)); return *this; } - LDKInit* operator &() { return &self; } - LDKInit* operator ->() { return &self; } - const LDKInit* operator &() const { return &self; } - const LDKInit* operator ->() const { return &self; } -}; -class ErrorMessage { -private: - LDKErrorMessage self; -public: - ErrorMessage(const ErrorMessage&) = delete; - ErrorMessage(ErrorMessage&& o) : self(o.self) { memset(&o, 0, sizeof(ErrorMessage)); } - ErrorMessage(LDKErrorMessage&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKErrorMessage)); } - operator LDKErrorMessage() && { LDKErrorMessage res = self; memset(&self, 0, sizeof(LDKErrorMessage)); return res; } - ~ErrorMessage() { ErrorMessage_free(self); } - ErrorMessage& operator=(ErrorMessage&& o) { ErrorMessage_free(self); self = o.self; memset(&o, 0, sizeof(ErrorMessage)); return *this; } - LDKErrorMessage* operator &() { return &self; } - LDKErrorMessage* operator ->() { return &self; } - const LDKErrorMessage* operator &() const { return &self; } - const LDKErrorMessage* operator ->() const { return &self; } -}; -class Ping { -private: - LDKPing self; -public: - Ping(const Ping&) = delete; - Ping(Ping&& o) : self(o.self) { memset(&o, 0, sizeof(Ping)); } - Ping(LDKPing&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKPing)); } - operator LDKPing() && { LDKPing res = self; memset(&self, 0, sizeof(LDKPing)); return res; } - ~Ping() { Ping_free(self); } - Ping& operator=(Ping&& o) { Ping_free(self); self = o.self; memset(&o, 0, sizeof(Ping)); return *this; } - LDKPing* operator &() { return &self; } - LDKPing* operator ->() { return &self; } - const LDKPing* operator &() const { return &self; } - const LDKPing* operator ->() const { return &self; } -}; -class Pong { -private: - LDKPong self; -public: - Pong(const Pong&) = delete; - Pong(Pong&& o) : self(o.self) { memset(&o, 0, sizeof(Pong)); } - Pong(LDKPong&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKPong)); } - operator LDKPong() && { LDKPong res = self; memset(&self, 0, sizeof(LDKPong)); return res; } - ~Pong() { Pong_free(self); } - Pong& operator=(Pong&& o) { Pong_free(self); self = o.self; memset(&o, 0, sizeof(Pong)); return *this; } - LDKPong* operator &() { return &self; } - LDKPong* operator ->() { return &self; } - const LDKPong* operator &() const { return &self; } - const LDKPong* operator ->() const { return &self; } -}; -class OpenChannel { -private: - LDKOpenChannel self; -public: - OpenChannel(const OpenChannel&) = delete; - OpenChannel(OpenChannel&& o) : self(o.self) { memset(&o, 0, sizeof(OpenChannel)); } - OpenChannel(LDKOpenChannel&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKOpenChannel)); } - operator LDKOpenChannel() && { LDKOpenChannel res = self; memset(&self, 0, sizeof(LDKOpenChannel)); return res; } - ~OpenChannel() { OpenChannel_free(self); } - OpenChannel& operator=(OpenChannel&& o) { OpenChannel_free(self); self = o.self; memset(&o, 0, sizeof(OpenChannel)); return *this; } - LDKOpenChannel* operator &() { return &self; } - LDKOpenChannel* operator ->() { return &self; } - const LDKOpenChannel* operator &() const { return &self; } - const LDKOpenChannel* operator ->() const { return &self; } -}; -class AcceptChannel { -private: - LDKAcceptChannel self; -public: - AcceptChannel(const AcceptChannel&) = delete; - AcceptChannel(AcceptChannel&& o) : self(o.self) { memset(&o, 0, sizeof(AcceptChannel)); } - AcceptChannel(LDKAcceptChannel&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKAcceptChannel)); } - operator LDKAcceptChannel() && { LDKAcceptChannel res = self; memset(&self, 0, sizeof(LDKAcceptChannel)); return res; } - ~AcceptChannel() { AcceptChannel_free(self); } - AcceptChannel& operator=(AcceptChannel&& o) { AcceptChannel_free(self); self = o.self; memset(&o, 0, sizeof(AcceptChannel)); return *this; } - LDKAcceptChannel* operator &() { return &self; } - LDKAcceptChannel* operator ->() { return &self; } - const LDKAcceptChannel* operator &() const { return &self; } - const LDKAcceptChannel* operator ->() const { return &self; } -}; -class FundingCreated { -private: - LDKFundingCreated self; -public: - FundingCreated(const FundingCreated&) = delete; - FundingCreated(FundingCreated&& o) : self(o.self) { memset(&o, 0, sizeof(FundingCreated)); } - FundingCreated(LDKFundingCreated&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKFundingCreated)); } - operator LDKFundingCreated() && { LDKFundingCreated res = self; memset(&self, 0, sizeof(LDKFundingCreated)); return res; } - ~FundingCreated() { FundingCreated_free(self); } - FundingCreated& operator=(FundingCreated&& o) { FundingCreated_free(self); self = o.self; memset(&o, 0, sizeof(FundingCreated)); return *this; } - LDKFundingCreated* operator &() { return &self; } - LDKFundingCreated* operator ->() { return &self; } - const LDKFundingCreated* operator &() const { return &self; } - const LDKFundingCreated* operator ->() const { return &self; } -}; -class FundingSigned { -private: - LDKFundingSigned self; -public: - FundingSigned(const FundingSigned&) = delete; - FundingSigned(FundingSigned&& o) : self(o.self) { memset(&o, 0, sizeof(FundingSigned)); } - FundingSigned(LDKFundingSigned&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKFundingSigned)); } - operator LDKFundingSigned() && { LDKFundingSigned res = self; memset(&self, 0, sizeof(LDKFundingSigned)); return res; } - ~FundingSigned() { FundingSigned_free(self); } - FundingSigned& operator=(FundingSigned&& o) { FundingSigned_free(self); self = o.self; memset(&o, 0, sizeof(FundingSigned)); return *this; } - LDKFundingSigned* operator &() { return &self; } - LDKFundingSigned* operator ->() { return &self; } - const LDKFundingSigned* operator &() const { return &self; } - const LDKFundingSigned* operator ->() const { return &self; } -}; -class FundingLocked { -private: - LDKFundingLocked self; -public: - FundingLocked(const FundingLocked&) = delete; - FundingLocked(FundingLocked&& o) : self(o.self) { memset(&o, 0, sizeof(FundingLocked)); } - FundingLocked(LDKFundingLocked&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKFundingLocked)); } - operator LDKFundingLocked() && { LDKFundingLocked res = self; memset(&self, 0, sizeof(LDKFundingLocked)); return res; } - ~FundingLocked() { FundingLocked_free(self); } - FundingLocked& operator=(FundingLocked&& o) { FundingLocked_free(self); self = o.self; memset(&o, 0, sizeof(FundingLocked)); return *this; } - LDKFundingLocked* operator &() { return &self; } - LDKFundingLocked* operator ->() { return &self; } - const LDKFundingLocked* operator &() const { return &self; } - const LDKFundingLocked* operator ->() const { return &self; } -}; -class Shutdown { -private: - LDKShutdown self; -public: - Shutdown(const Shutdown&) = delete; - Shutdown(Shutdown&& o) : self(o.self) { memset(&o, 0, sizeof(Shutdown)); } - Shutdown(LDKShutdown&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKShutdown)); } - operator LDKShutdown() && { LDKShutdown res = self; memset(&self, 0, sizeof(LDKShutdown)); return res; } - ~Shutdown() { Shutdown_free(self); } - Shutdown& operator=(Shutdown&& o) { Shutdown_free(self); self = o.self; memset(&o, 0, sizeof(Shutdown)); return *this; } - LDKShutdown* operator &() { return &self; } - LDKShutdown* operator ->() { return &self; } - const LDKShutdown* operator &() const { return &self; } - const LDKShutdown* operator ->() const { return &self; } -}; -class ClosingSigned { -private: - LDKClosingSigned self; -public: - ClosingSigned(const ClosingSigned&) = delete; - ClosingSigned(ClosingSigned&& o) : self(o.self) { memset(&o, 0, sizeof(ClosingSigned)); } - ClosingSigned(LDKClosingSigned&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKClosingSigned)); } - operator LDKClosingSigned() && { LDKClosingSigned res = self; memset(&self, 0, sizeof(LDKClosingSigned)); return res; } - ~ClosingSigned() { ClosingSigned_free(self); } - ClosingSigned& operator=(ClosingSigned&& o) { ClosingSigned_free(self); self = o.self; memset(&o, 0, sizeof(ClosingSigned)); return *this; } - LDKClosingSigned* operator &() { return &self; } - LDKClosingSigned* operator ->() { return &self; } - const LDKClosingSigned* operator &() const { return &self; } - const LDKClosingSigned* operator ->() const { return &self; } -}; -class UpdateAddHTLC { -private: - LDKUpdateAddHTLC self; -public: - UpdateAddHTLC(const UpdateAddHTLC&) = delete; - UpdateAddHTLC(UpdateAddHTLC&& o) : self(o.self) { memset(&o, 0, sizeof(UpdateAddHTLC)); } - UpdateAddHTLC(LDKUpdateAddHTLC&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKUpdateAddHTLC)); } - operator LDKUpdateAddHTLC() && { LDKUpdateAddHTLC res = self; memset(&self, 0, sizeof(LDKUpdateAddHTLC)); return res; } - ~UpdateAddHTLC() { UpdateAddHTLC_free(self); } - UpdateAddHTLC& operator=(UpdateAddHTLC&& o) { UpdateAddHTLC_free(self); self = o.self; memset(&o, 0, sizeof(UpdateAddHTLC)); return *this; } - LDKUpdateAddHTLC* operator &() { return &self; } - LDKUpdateAddHTLC* operator ->() { return &self; } - const LDKUpdateAddHTLC* operator &() const { return &self; } - const LDKUpdateAddHTLC* operator ->() const { return &self; } -}; -class UpdateFulfillHTLC { -private: - LDKUpdateFulfillHTLC self; -public: - UpdateFulfillHTLC(const UpdateFulfillHTLC&) = delete; - UpdateFulfillHTLC(UpdateFulfillHTLC&& o) : self(o.self) { memset(&o, 0, sizeof(UpdateFulfillHTLC)); } - UpdateFulfillHTLC(LDKUpdateFulfillHTLC&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKUpdateFulfillHTLC)); } - operator LDKUpdateFulfillHTLC() && { LDKUpdateFulfillHTLC res = self; memset(&self, 0, sizeof(LDKUpdateFulfillHTLC)); return res; } - ~UpdateFulfillHTLC() { UpdateFulfillHTLC_free(self); } - UpdateFulfillHTLC& operator=(UpdateFulfillHTLC&& o) { UpdateFulfillHTLC_free(self); self = o.self; memset(&o, 0, sizeof(UpdateFulfillHTLC)); return *this; } - LDKUpdateFulfillHTLC* operator &() { return &self; } - LDKUpdateFulfillHTLC* operator ->() { return &self; } - const LDKUpdateFulfillHTLC* operator &() const { return &self; } - const LDKUpdateFulfillHTLC* operator ->() const { return &self; } -}; -class UpdateFailHTLC { -private: - LDKUpdateFailHTLC self; -public: - UpdateFailHTLC(const UpdateFailHTLC&) = delete; - UpdateFailHTLC(UpdateFailHTLC&& o) : self(o.self) { memset(&o, 0, sizeof(UpdateFailHTLC)); } - UpdateFailHTLC(LDKUpdateFailHTLC&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKUpdateFailHTLC)); } - operator LDKUpdateFailHTLC() && { LDKUpdateFailHTLC res = self; memset(&self, 0, sizeof(LDKUpdateFailHTLC)); return res; } - ~UpdateFailHTLC() { UpdateFailHTLC_free(self); } - UpdateFailHTLC& operator=(UpdateFailHTLC&& o) { UpdateFailHTLC_free(self); self = o.self; memset(&o, 0, sizeof(UpdateFailHTLC)); return *this; } - LDKUpdateFailHTLC* operator &() { return &self; } - LDKUpdateFailHTLC* operator ->() { return &self; } - const LDKUpdateFailHTLC* operator &() const { return &self; } - const LDKUpdateFailHTLC* operator ->() const { return &self; } -}; -class UpdateFailMalformedHTLC { -private: - LDKUpdateFailMalformedHTLC self; -public: - UpdateFailMalformedHTLC(const UpdateFailMalformedHTLC&) = delete; - UpdateFailMalformedHTLC(UpdateFailMalformedHTLC&& o) : self(o.self) { memset(&o, 0, sizeof(UpdateFailMalformedHTLC)); } - UpdateFailMalformedHTLC(LDKUpdateFailMalformedHTLC&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKUpdateFailMalformedHTLC)); } - operator LDKUpdateFailMalformedHTLC() && { LDKUpdateFailMalformedHTLC res = self; memset(&self, 0, sizeof(LDKUpdateFailMalformedHTLC)); return res; } - ~UpdateFailMalformedHTLC() { UpdateFailMalformedHTLC_free(self); } - UpdateFailMalformedHTLC& operator=(UpdateFailMalformedHTLC&& o) { UpdateFailMalformedHTLC_free(self); self = o.self; memset(&o, 0, sizeof(UpdateFailMalformedHTLC)); return *this; } - LDKUpdateFailMalformedHTLC* operator &() { return &self; } - LDKUpdateFailMalformedHTLC* operator ->() { return &self; } - const LDKUpdateFailMalformedHTLC* operator &() const { return &self; } - const LDKUpdateFailMalformedHTLC* operator ->() const { return &self; } -}; -class CommitmentSigned { -private: - LDKCommitmentSigned self; -public: - CommitmentSigned(const CommitmentSigned&) = delete; - CommitmentSigned(CommitmentSigned&& o) : self(o.self) { memset(&o, 0, sizeof(CommitmentSigned)); } - CommitmentSigned(LDKCommitmentSigned&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCommitmentSigned)); } - operator LDKCommitmentSigned() && { LDKCommitmentSigned res = self; memset(&self, 0, sizeof(LDKCommitmentSigned)); return res; } - ~CommitmentSigned() { CommitmentSigned_free(self); } - CommitmentSigned& operator=(CommitmentSigned&& o) { CommitmentSigned_free(self); self = o.self; memset(&o, 0, sizeof(CommitmentSigned)); return *this; } - LDKCommitmentSigned* operator &() { return &self; } - LDKCommitmentSigned* operator ->() { return &self; } - const LDKCommitmentSigned* operator &() const { return &self; } - const LDKCommitmentSigned* operator ->() const { return &self; } -}; -class RevokeAndACK { -private: - LDKRevokeAndACK self; -public: - RevokeAndACK(const RevokeAndACK&) = delete; - RevokeAndACK(RevokeAndACK&& o) : self(o.self) { memset(&o, 0, sizeof(RevokeAndACK)); } - RevokeAndACK(LDKRevokeAndACK&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKRevokeAndACK)); } - operator LDKRevokeAndACK() && { LDKRevokeAndACK res = self; memset(&self, 0, sizeof(LDKRevokeAndACK)); return res; } - ~RevokeAndACK() { RevokeAndACK_free(self); } - RevokeAndACK& operator=(RevokeAndACK&& o) { RevokeAndACK_free(self); self = o.self; memset(&o, 0, sizeof(RevokeAndACK)); return *this; } - LDKRevokeAndACK* operator &() { return &self; } - LDKRevokeAndACK* operator ->() { return &self; } - const LDKRevokeAndACK* operator &() const { return &self; } - const LDKRevokeAndACK* operator ->() const { return &self; } -}; -class UpdateFee { -private: - LDKUpdateFee self; -public: - UpdateFee(const UpdateFee&) = delete; - UpdateFee(UpdateFee&& o) : self(o.self) { memset(&o, 0, sizeof(UpdateFee)); } - UpdateFee(LDKUpdateFee&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKUpdateFee)); } - operator LDKUpdateFee() && { LDKUpdateFee res = self; memset(&self, 0, sizeof(LDKUpdateFee)); return res; } - ~UpdateFee() { UpdateFee_free(self); } - UpdateFee& operator=(UpdateFee&& o) { UpdateFee_free(self); self = o.self; memset(&o, 0, sizeof(UpdateFee)); return *this; } - LDKUpdateFee* operator &() { return &self; } - LDKUpdateFee* operator ->() { return &self; } - const LDKUpdateFee* operator &() const { return &self; } - const LDKUpdateFee* operator ->() const { return &self; } -}; -class DataLossProtect { -private: - LDKDataLossProtect self; -public: - DataLossProtect(const DataLossProtect&) = delete; - DataLossProtect(DataLossProtect&& o) : self(o.self) { memset(&o, 0, sizeof(DataLossProtect)); } - DataLossProtect(LDKDataLossProtect&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKDataLossProtect)); } - operator LDKDataLossProtect() && { LDKDataLossProtect res = self; memset(&self, 0, sizeof(LDKDataLossProtect)); return res; } - ~DataLossProtect() { DataLossProtect_free(self); } - DataLossProtect& operator=(DataLossProtect&& o) { DataLossProtect_free(self); self = o.self; memset(&o, 0, sizeof(DataLossProtect)); return *this; } - LDKDataLossProtect* operator &() { return &self; } - LDKDataLossProtect* operator ->() { return &self; } - const LDKDataLossProtect* operator &() const { return &self; } - const LDKDataLossProtect* operator ->() const { return &self; } -}; -class ChannelReestablish { -private: - LDKChannelReestablish self; -public: - ChannelReestablish(const ChannelReestablish&) = delete; - ChannelReestablish(ChannelReestablish&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelReestablish)); } - ChannelReestablish(LDKChannelReestablish&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelReestablish)); } - operator LDKChannelReestablish() && { LDKChannelReestablish res = self; memset(&self, 0, sizeof(LDKChannelReestablish)); return res; } - ~ChannelReestablish() { ChannelReestablish_free(self); } - ChannelReestablish& operator=(ChannelReestablish&& o) { ChannelReestablish_free(self); self = o.self; memset(&o, 0, sizeof(ChannelReestablish)); return *this; } - LDKChannelReestablish* operator &() { return &self; } - LDKChannelReestablish* operator ->() { return &self; } - const LDKChannelReestablish* operator &() const { return &self; } - const LDKChannelReestablish* operator ->() const { return &self; } -}; -class AnnouncementSignatures { -private: - LDKAnnouncementSignatures self; -public: - AnnouncementSignatures(const AnnouncementSignatures&) = delete; - AnnouncementSignatures(AnnouncementSignatures&& o) : self(o.self) { memset(&o, 0, sizeof(AnnouncementSignatures)); } - AnnouncementSignatures(LDKAnnouncementSignatures&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKAnnouncementSignatures)); } - operator LDKAnnouncementSignatures() && { LDKAnnouncementSignatures res = self; memset(&self, 0, sizeof(LDKAnnouncementSignatures)); return res; } - ~AnnouncementSignatures() { AnnouncementSignatures_free(self); } - AnnouncementSignatures& operator=(AnnouncementSignatures&& o) { AnnouncementSignatures_free(self); self = o.self; memset(&o, 0, sizeof(AnnouncementSignatures)); return *this; } - LDKAnnouncementSignatures* operator &() { return &self; } - LDKAnnouncementSignatures* operator ->() { return &self; } - const LDKAnnouncementSignatures* operator &() const { return &self; } - const LDKAnnouncementSignatures* operator ->() const { return &self; } -}; -class NetAddress { -private: - LDKNetAddress self; -public: - NetAddress(const NetAddress&) = delete; - NetAddress(NetAddress&& o) : self(o.self) { memset(&o, 0, sizeof(NetAddress)); } - NetAddress(LDKNetAddress&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKNetAddress)); } - operator LDKNetAddress() && { LDKNetAddress res = self; memset(&self, 0, sizeof(LDKNetAddress)); return res; } - ~NetAddress() { NetAddress_free(self); } - NetAddress& operator=(NetAddress&& o) { NetAddress_free(self); self = o.self; memset(&o, 0, sizeof(NetAddress)); return *this; } - LDKNetAddress* operator &() { return &self; } - LDKNetAddress* operator ->() { return &self; } - const LDKNetAddress* operator &() const { return &self; } - const LDKNetAddress* operator ->() const { return &self; } -}; -class UnsignedNodeAnnouncement { -private: - LDKUnsignedNodeAnnouncement self; -public: - UnsignedNodeAnnouncement(const UnsignedNodeAnnouncement&) = delete; - UnsignedNodeAnnouncement(UnsignedNodeAnnouncement&& o) : self(o.self) { memset(&o, 0, sizeof(UnsignedNodeAnnouncement)); } - UnsignedNodeAnnouncement(LDKUnsignedNodeAnnouncement&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKUnsignedNodeAnnouncement)); } - operator LDKUnsignedNodeAnnouncement() && { LDKUnsignedNodeAnnouncement res = self; memset(&self, 0, sizeof(LDKUnsignedNodeAnnouncement)); return res; } - ~UnsignedNodeAnnouncement() { UnsignedNodeAnnouncement_free(self); } - UnsignedNodeAnnouncement& operator=(UnsignedNodeAnnouncement&& o) { UnsignedNodeAnnouncement_free(self); self = o.self; memset(&o, 0, sizeof(UnsignedNodeAnnouncement)); return *this; } - LDKUnsignedNodeAnnouncement* operator &() { return &self; } - LDKUnsignedNodeAnnouncement* operator ->() { return &self; } - const LDKUnsignedNodeAnnouncement* operator &() const { return &self; } - const LDKUnsignedNodeAnnouncement* operator ->() const { return &self; } -}; -class NodeAnnouncement { -private: - LDKNodeAnnouncement self; -public: - NodeAnnouncement(const NodeAnnouncement&) = delete; - NodeAnnouncement(NodeAnnouncement&& o) : self(o.self) { memset(&o, 0, sizeof(NodeAnnouncement)); } - NodeAnnouncement(LDKNodeAnnouncement&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKNodeAnnouncement)); } - operator LDKNodeAnnouncement() && { LDKNodeAnnouncement res = self; memset(&self, 0, sizeof(LDKNodeAnnouncement)); return res; } - ~NodeAnnouncement() { NodeAnnouncement_free(self); } - NodeAnnouncement& operator=(NodeAnnouncement&& o) { NodeAnnouncement_free(self); self = o.self; memset(&o, 0, sizeof(NodeAnnouncement)); return *this; } - LDKNodeAnnouncement* operator &() { return &self; } - LDKNodeAnnouncement* operator ->() { return &self; } - const LDKNodeAnnouncement* operator &() const { return &self; } - const LDKNodeAnnouncement* operator ->() const { return &self; } -}; -class UnsignedChannelAnnouncement { -private: - LDKUnsignedChannelAnnouncement self; -public: - UnsignedChannelAnnouncement(const UnsignedChannelAnnouncement&) = delete; - UnsignedChannelAnnouncement(UnsignedChannelAnnouncement&& o) : self(o.self) { memset(&o, 0, sizeof(UnsignedChannelAnnouncement)); } - UnsignedChannelAnnouncement(LDKUnsignedChannelAnnouncement&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKUnsignedChannelAnnouncement)); } - operator LDKUnsignedChannelAnnouncement() && { LDKUnsignedChannelAnnouncement res = self; memset(&self, 0, sizeof(LDKUnsignedChannelAnnouncement)); return res; } - ~UnsignedChannelAnnouncement() { UnsignedChannelAnnouncement_free(self); } - UnsignedChannelAnnouncement& operator=(UnsignedChannelAnnouncement&& o) { UnsignedChannelAnnouncement_free(self); self = o.self; memset(&o, 0, sizeof(UnsignedChannelAnnouncement)); return *this; } - LDKUnsignedChannelAnnouncement* operator &() { return &self; } - LDKUnsignedChannelAnnouncement* operator ->() { return &self; } - const LDKUnsignedChannelAnnouncement* operator &() const { return &self; } - const LDKUnsignedChannelAnnouncement* operator ->() const { return &self; } -}; -class ChannelAnnouncement { -private: - LDKChannelAnnouncement self; -public: - ChannelAnnouncement(const ChannelAnnouncement&) = delete; - ChannelAnnouncement(ChannelAnnouncement&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelAnnouncement)); } - ChannelAnnouncement(LDKChannelAnnouncement&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelAnnouncement)); } - operator LDKChannelAnnouncement() && { LDKChannelAnnouncement res = self; memset(&self, 0, sizeof(LDKChannelAnnouncement)); return res; } - ~ChannelAnnouncement() { ChannelAnnouncement_free(self); } - ChannelAnnouncement& operator=(ChannelAnnouncement&& o) { ChannelAnnouncement_free(self); self = o.self; memset(&o, 0, sizeof(ChannelAnnouncement)); return *this; } - LDKChannelAnnouncement* operator &() { return &self; } - LDKChannelAnnouncement* operator ->() { return &self; } - const LDKChannelAnnouncement* operator &() const { return &self; } - const LDKChannelAnnouncement* operator ->() const { return &self; } -}; -class UnsignedChannelUpdate { -private: - LDKUnsignedChannelUpdate self; -public: - UnsignedChannelUpdate(const UnsignedChannelUpdate&) = delete; - UnsignedChannelUpdate(UnsignedChannelUpdate&& o) : self(o.self) { memset(&o, 0, sizeof(UnsignedChannelUpdate)); } - UnsignedChannelUpdate(LDKUnsignedChannelUpdate&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKUnsignedChannelUpdate)); } - operator LDKUnsignedChannelUpdate() && { LDKUnsignedChannelUpdate res = self; memset(&self, 0, sizeof(LDKUnsignedChannelUpdate)); return res; } - ~UnsignedChannelUpdate() { UnsignedChannelUpdate_free(self); } - UnsignedChannelUpdate& operator=(UnsignedChannelUpdate&& o) { UnsignedChannelUpdate_free(self); self = o.self; memset(&o, 0, sizeof(UnsignedChannelUpdate)); return *this; } - LDKUnsignedChannelUpdate* operator &() { return &self; } - LDKUnsignedChannelUpdate* operator ->() { return &self; } - const LDKUnsignedChannelUpdate* operator &() const { return &self; } - const LDKUnsignedChannelUpdate* operator ->() const { return &self; } -}; -class ChannelUpdate { -private: - LDKChannelUpdate self; -public: - ChannelUpdate(const ChannelUpdate&) = delete; - ChannelUpdate(ChannelUpdate&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelUpdate)); } - ChannelUpdate(LDKChannelUpdate&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelUpdate)); } - operator LDKChannelUpdate() && { LDKChannelUpdate res = self; memset(&self, 0, sizeof(LDKChannelUpdate)); return res; } - ~ChannelUpdate() { ChannelUpdate_free(self); } - ChannelUpdate& operator=(ChannelUpdate&& o) { ChannelUpdate_free(self); self = o.self; memset(&o, 0, sizeof(ChannelUpdate)); return *this; } - LDKChannelUpdate* operator &() { return &self; } - LDKChannelUpdate* operator ->() { return &self; } - const LDKChannelUpdate* operator &() const { return &self; } - const LDKChannelUpdate* operator ->() const { return &self; } -}; -class QueryChannelRange { -private: - LDKQueryChannelRange self; -public: - QueryChannelRange(const QueryChannelRange&) = delete; - QueryChannelRange(QueryChannelRange&& o) : self(o.self) { memset(&o, 0, sizeof(QueryChannelRange)); } - QueryChannelRange(LDKQueryChannelRange&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKQueryChannelRange)); } - operator LDKQueryChannelRange() && { LDKQueryChannelRange res = self; memset(&self, 0, sizeof(LDKQueryChannelRange)); return res; } - ~QueryChannelRange() { QueryChannelRange_free(self); } - QueryChannelRange& operator=(QueryChannelRange&& o) { QueryChannelRange_free(self); self = o.self; memset(&o, 0, sizeof(QueryChannelRange)); return *this; } - LDKQueryChannelRange* operator &() { return &self; } - LDKQueryChannelRange* operator ->() { return &self; } - const LDKQueryChannelRange* operator &() const { return &self; } - const LDKQueryChannelRange* operator ->() const { return &self; } -}; -class ReplyChannelRange { -private: - LDKReplyChannelRange self; -public: - ReplyChannelRange(const ReplyChannelRange&) = delete; - ReplyChannelRange(ReplyChannelRange&& o) : self(o.self) { memset(&o, 0, sizeof(ReplyChannelRange)); } - ReplyChannelRange(LDKReplyChannelRange&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKReplyChannelRange)); } - operator LDKReplyChannelRange() && { LDKReplyChannelRange res = self; memset(&self, 0, sizeof(LDKReplyChannelRange)); return res; } - ~ReplyChannelRange() { ReplyChannelRange_free(self); } - ReplyChannelRange& operator=(ReplyChannelRange&& o) { ReplyChannelRange_free(self); self = o.self; memset(&o, 0, sizeof(ReplyChannelRange)); return *this; } - LDKReplyChannelRange* operator &() { return &self; } - LDKReplyChannelRange* operator ->() { return &self; } - const LDKReplyChannelRange* operator &() const { return &self; } - const LDKReplyChannelRange* operator ->() const { return &self; } -}; -class QueryShortChannelIds { -private: - LDKQueryShortChannelIds self; -public: - QueryShortChannelIds(const QueryShortChannelIds&) = delete; - QueryShortChannelIds(QueryShortChannelIds&& o) : self(o.self) { memset(&o, 0, sizeof(QueryShortChannelIds)); } - QueryShortChannelIds(LDKQueryShortChannelIds&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKQueryShortChannelIds)); } - operator LDKQueryShortChannelIds() && { LDKQueryShortChannelIds res = self; memset(&self, 0, sizeof(LDKQueryShortChannelIds)); return res; } - ~QueryShortChannelIds() { QueryShortChannelIds_free(self); } - QueryShortChannelIds& operator=(QueryShortChannelIds&& o) { QueryShortChannelIds_free(self); self = o.self; memset(&o, 0, sizeof(QueryShortChannelIds)); return *this; } - LDKQueryShortChannelIds* operator &() { return &self; } - LDKQueryShortChannelIds* operator ->() { return &self; } - const LDKQueryShortChannelIds* operator &() const { return &self; } - const LDKQueryShortChannelIds* operator ->() const { return &self; } -}; -class ReplyShortChannelIdsEnd { -private: - LDKReplyShortChannelIdsEnd self; -public: - ReplyShortChannelIdsEnd(const ReplyShortChannelIdsEnd&) = delete; - ReplyShortChannelIdsEnd(ReplyShortChannelIdsEnd&& o) : self(o.self) { memset(&o, 0, sizeof(ReplyShortChannelIdsEnd)); } - ReplyShortChannelIdsEnd(LDKReplyShortChannelIdsEnd&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKReplyShortChannelIdsEnd)); } - operator LDKReplyShortChannelIdsEnd() && { LDKReplyShortChannelIdsEnd res = self; memset(&self, 0, sizeof(LDKReplyShortChannelIdsEnd)); return res; } - ~ReplyShortChannelIdsEnd() { ReplyShortChannelIdsEnd_free(self); } - ReplyShortChannelIdsEnd& operator=(ReplyShortChannelIdsEnd&& o) { ReplyShortChannelIdsEnd_free(self); self = o.self; memset(&o, 0, sizeof(ReplyShortChannelIdsEnd)); return *this; } - LDKReplyShortChannelIdsEnd* operator &() { return &self; } - LDKReplyShortChannelIdsEnd* operator ->() { return &self; } - const LDKReplyShortChannelIdsEnd* operator &() const { return &self; } - const LDKReplyShortChannelIdsEnd* operator ->() const { return &self; } -}; -class GossipTimestampFilter { -private: - LDKGossipTimestampFilter self; -public: - GossipTimestampFilter(const GossipTimestampFilter&) = delete; - GossipTimestampFilter(GossipTimestampFilter&& o) : self(o.self) { memset(&o, 0, sizeof(GossipTimestampFilter)); } - GossipTimestampFilter(LDKGossipTimestampFilter&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKGossipTimestampFilter)); } - operator LDKGossipTimestampFilter() && { LDKGossipTimestampFilter res = self; memset(&self, 0, sizeof(LDKGossipTimestampFilter)); return res; } - ~GossipTimestampFilter() { GossipTimestampFilter_free(self); } - GossipTimestampFilter& operator=(GossipTimestampFilter&& o) { GossipTimestampFilter_free(self); self = o.self; memset(&o, 0, sizeof(GossipTimestampFilter)); return *this; } - LDKGossipTimestampFilter* operator &() { return &self; } - LDKGossipTimestampFilter* operator ->() { return &self; } - const LDKGossipTimestampFilter* operator &() const { return &self; } - const LDKGossipTimestampFilter* operator ->() const { return &self; } -}; -class ErrorAction { -private: - LDKErrorAction self; -public: - ErrorAction(const ErrorAction&) = delete; - ErrorAction(ErrorAction&& o) : self(o.self) { memset(&o, 0, sizeof(ErrorAction)); } - ErrorAction(LDKErrorAction&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKErrorAction)); } - operator LDKErrorAction() && { LDKErrorAction res = self; memset(&self, 0, sizeof(LDKErrorAction)); return res; } - ~ErrorAction() { ErrorAction_free(self); } - ErrorAction& operator=(ErrorAction&& o) { ErrorAction_free(self); self = o.self; memset(&o, 0, sizeof(ErrorAction)); return *this; } - LDKErrorAction* operator &() { return &self; } - LDKErrorAction* operator ->() { return &self; } - const LDKErrorAction* operator &() const { return &self; } - const LDKErrorAction* operator ->() const { return &self; } -}; -class LightningError { -private: - LDKLightningError self; -public: - LightningError(const LightningError&) = delete; - LightningError(LightningError&& o) : self(o.self) { memset(&o, 0, sizeof(LightningError)); } - LightningError(LDKLightningError&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKLightningError)); } - operator LDKLightningError() && { LDKLightningError res = self; memset(&self, 0, sizeof(LDKLightningError)); return res; } - ~LightningError() { LightningError_free(self); } - LightningError& operator=(LightningError&& o) { LightningError_free(self); self = o.self; memset(&o, 0, sizeof(LightningError)); return *this; } - LDKLightningError* operator &() { return &self; } - LDKLightningError* operator ->() { return &self; } - const LDKLightningError* operator &() const { return &self; } - const LDKLightningError* operator ->() const { return &self; } -}; -class CommitmentUpdate { -private: - LDKCommitmentUpdate self; -public: - CommitmentUpdate(const CommitmentUpdate&) = delete; - CommitmentUpdate(CommitmentUpdate&& o) : self(o.self) { memset(&o, 0, sizeof(CommitmentUpdate)); } - CommitmentUpdate(LDKCommitmentUpdate&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCommitmentUpdate)); } - operator LDKCommitmentUpdate() && { LDKCommitmentUpdate res = self; memset(&self, 0, sizeof(LDKCommitmentUpdate)); return res; } - ~CommitmentUpdate() { CommitmentUpdate_free(self); } - CommitmentUpdate& operator=(CommitmentUpdate&& o) { CommitmentUpdate_free(self); self = o.self; memset(&o, 0, sizeof(CommitmentUpdate)); return *this; } - LDKCommitmentUpdate* operator &() { return &self; } - LDKCommitmentUpdate* operator ->() { return &self; } - const LDKCommitmentUpdate* operator &() const { return &self; } - const LDKCommitmentUpdate* operator ->() const { return &self; } -}; -class HTLCFailChannelUpdate { -private: - LDKHTLCFailChannelUpdate self; -public: - HTLCFailChannelUpdate(const HTLCFailChannelUpdate&) = delete; - HTLCFailChannelUpdate(HTLCFailChannelUpdate&& o) : self(o.self) { memset(&o, 0, sizeof(HTLCFailChannelUpdate)); } - HTLCFailChannelUpdate(LDKHTLCFailChannelUpdate&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKHTLCFailChannelUpdate)); } - operator LDKHTLCFailChannelUpdate() && { LDKHTLCFailChannelUpdate res = self; memset(&self, 0, sizeof(LDKHTLCFailChannelUpdate)); return res; } - ~HTLCFailChannelUpdate() { HTLCFailChannelUpdate_free(self); } - HTLCFailChannelUpdate& operator=(HTLCFailChannelUpdate&& o) { HTLCFailChannelUpdate_free(self); self = o.self; memset(&o, 0, sizeof(HTLCFailChannelUpdate)); return *this; } - LDKHTLCFailChannelUpdate* operator &() { return &self; } - LDKHTLCFailChannelUpdate* operator ->() { return &self; } - const LDKHTLCFailChannelUpdate* operator &() const { return &self; } - const LDKHTLCFailChannelUpdate* operator ->() const { return &self; } -}; -class ChannelMessageHandler { -private: - LDKChannelMessageHandler self; -public: - ChannelMessageHandler(const ChannelMessageHandler&) = delete; - ChannelMessageHandler(ChannelMessageHandler&& o) : self(o.self) { memset(&o, 0, sizeof(ChannelMessageHandler)); } - ChannelMessageHandler(LDKChannelMessageHandler&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKChannelMessageHandler)); } - operator LDKChannelMessageHandler() && { LDKChannelMessageHandler res = self; memset(&self, 0, sizeof(LDKChannelMessageHandler)); return res; } - ~ChannelMessageHandler() { ChannelMessageHandler_free(self); } - ChannelMessageHandler& operator=(ChannelMessageHandler&& o) { ChannelMessageHandler_free(self); self = o.self; memset(&o, 0, sizeof(ChannelMessageHandler)); return *this; } - LDKChannelMessageHandler* operator &() { return &self; } - LDKChannelMessageHandler* operator ->() { return &self; } - const LDKChannelMessageHandler* operator &() const { return &self; } - const LDKChannelMessageHandler* operator ->() const { return &self; } -}; -class RoutingMessageHandler { -private: - LDKRoutingMessageHandler self; -public: - RoutingMessageHandler(const RoutingMessageHandler&) = delete; - RoutingMessageHandler(RoutingMessageHandler&& o) : self(o.self) { memset(&o, 0, sizeof(RoutingMessageHandler)); } - RoutingMessageHandler(LDKRoutingMessageHandler&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKRoutingMessageHandler)); } - operator LDKRoutingMessageHandler() && { LDKRoutingMessageHandler res = self; memset(&self, 0, sizeof(LDKRoutingMessageHandler)); return res; } - ~RoutingMessageHandler() { RoutingMessageHandler_free(self); } - RoutingMessageHandler& operator=(RoutingMessageHandler&& o) { RoutingMessageHandler_free(self); self = o.self; memset(&o, 0, sizeof(RoutingMessageHandler)); return *this; } - LDKRoutingMessageHandler* operator &() { return &self; } - LDKRoutingMessageHandler* operator ->() { return &self; } - const LDKRoutingMessageHandler* operator &() const { return &self; } - const LDKRoutingMessageHandler* operator ->() const { return &self; } -}; -class CVec_SpendableOutputDescriptorZ { -private: - LDKCVec_SpendableOutputDescriptorZ self; -public: - CVec_SpendableOutputDescriptorZ(const CVec_SpendableOutputDescriptorZ&) = delete; - CVec_SpendableOutputDescriptorZ(CVec_SpendableOutputDescriptorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_SpendableOutputDescriptorZ)); } - CVec_SpendableOutputDescriptorZ(LDKCVec_SpendableOutputDescriptorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_SpendableOutputDescriptorZ)); } - operator LDKCVec_SpendableOutputDescriptorZ() && { LDKCVec_SpendableOutputDescriptorZ res = self; memset(&self, 0, sizeof(LDKCVec_SpendableOutputDescriptorZ)); return res; } - ~CVec_SpendableOutputDescriptorZ() { CVec_SpendableOutputDescriptorZ_free(self); } - CVec_SpendableOutputDescriptorZ& operator=(CVec_SpendableOutputDescriptorZ&& o) { CVec_SpendableOutputDescriptorZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_SpendableOutputDescriptorZ)); return *this; } - LDKCVec_SpendableOutputDescriptorZ* operator &() { return &self; } - LDKCVec_SpendableOutputDescriptorZ* operator ->() { return &self; } - const LDKCVec_SpendableOutputDescriptorZ* operator &() const { return &self; } - const LDKCVec_SpendableOutputDescriptorZ* operator ->() const { return &self; } -}; -class CResult_FundingCreatedDecodeErrorZ { -private: - LDKCResult_FundingCreatedDecodeErrorZ self; -public: - CResult_FundingCreatedDecodeErrorZ(const CResult_FundingCreatedDecodeErrorZ&) = delete; - CResult_FundingCreatedDecodeErrorZ(CResult_FundingCreatedDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_FundingCreatedDecodeErrorZ)); } - CResult_FundingCreatedDecodeErrorZ(LDKCResult_FundingCreatedDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_FundingCreatedDecodeErrorZ)); } - operator LDKCResult_FundingCreatedDecodeErrorZ() && { LDKCResult_FundingCreatedDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_FundingCreatedDecodeErrorZ)); return res; } - ~CResult_FundingCreatedDecodeErrorZ() { CResult_FundingCreatedDecodeErrorZ_free(self); } - CResult_FundingCreatedDecodeErrorZ& operator=(CResult_FundingCreatedDecodeErrorZ&& o) { CResult_FundingCreatedDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_FundingCreatedDecodeErrorZ)); return *this; } - LDKCResult_FundingCreatedDecodeErrorZ* operator &() { return &self; } - LDKCResult_FundingCreatedDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_FundingCreatedDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_FundingCreatedDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_ChannelAnnouncementDecodeErrorZ { -private: - LDKCResult_ChannelAnnouncementDecodeErrorZ self; -public: - CResult_ChannelAnnouncementDecodeErrorZ(const CResult_ChannelAnnouncementDecodeErrorZ&) = delete; - CResult_ChannelAnnouncementDecodeErrorZ(CResult_ChannelAnnouncementDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ChannelAnnouncementDecodeErrorZ)); } - CResult_ChannelAnnouncementDecodeErrorZ(LDKCResult_ChannelAnnouncementDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ChannelAnnouncementDecodeErrorZ)); } - operator LDKCResult_ChannelAnnouncementDecodeErrorZ() && { LDKCResult_ChannelAnnouncementDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ChannelAnnouncementDecodeErrorZ)); return res; } - ~CResult_ChannelAnnouncementDecodeErrorZ() { CResult_ChannelAnnouncementDecodeErrorZ_free(self); } - CResult_ChannelAnnouncementDecodeErrorZ& operator=(CResult_ChannelAnnouncementDecodeErrorZ&& o) { CResult_ChannelAnnouncementDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ChannelAnnouncementDecodeErrorZ)); return *this; } - LDKCResult_ChannelAnnouncementDecodeErrorZ* operator &() { return &self; } - LDKCResult_ChannelAnnouncementDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ChannelAnnouncementDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ChannelAnnouncementDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_HTLCUpdateDecodeErrorZ { -private: - LDKCResult_HTLCUpdateDecodeErrorZ self; -public: - CResult_HTLCUpdateDecodeErrorZ(const CResult_HTLCUpdateDecodeErrorZ&) = delete; - CResult_HTLCUpdateDecodeErrorZ(CResult_HTLCUpdateDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_HTLCUpdateDecodeErrorZ)); } - CResult_HTLCUpdateDecodeErrorZ(LDKCResult_HTLCUpdateDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_HTLCUpdateDecodeErrorZ)); } - operator LDKCResult_HTLCUpdateDecodeErrorZ() && { LDKCResult_HTLCUpdateDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_HTLCUpdateDecodeErrorZ)); return res; } - ~CResult_HTLCUpdateDecodeErrorZ() { CResult_HTLCUpdateDecodeErrorZ_free(self); } - CResult_HTLCUpdateDecodeErrorZ& operator=(CResult_HTLCUpdateDecodeErrorZ&& o) { CResult_HTLCUpdateDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_HTLCUpdateDecodeErrorZ)); return *this; } - LDKCResult_HTLCUpdateDecodeErrorZ* operator &() { return &self; } - LDKCResult_HTLCUpdateDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_HTLCUpdateDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_HTLCUpdateDecodeErrorZ* operator ->() const { return &self; } -}; -class CVec_C2Tuple_u32TxOutZZ { -private: - LDKCVec_C2Tuple_u32TxOutZZ self; -public: - CVec_C2Tuple_u32TxOutZZ(const CVec_C2Tuple_u32TxOutZZ&) = delete; - CVec_C2Tuple_u32TxOutZZ(CVec_C2Tuple_u32TxOutZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_C2Tuple_u32TxOutZZ)); } - CVec_C2Tuple_u32TxOutZZ(LDKCVec_C2Tuple_u32TxOutZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_C2Tuple_u32TxOutZZ)); } - operator LDKCVec_C2Tuple_u32TxOutZZ() && { LDKCVec_C2Tuple_u32TxOutZZ res = self; memset(&self, 0, sizeof(LDKCVec_C2Tuple_u32TxOutZZ)); return res; } - ~CVec_C2Tuple_u32TxOutZZ() { CVec_C2Tuple_u32TxOutZZ_free(self); } - CVec_C2Tuple_u32TxOutZZ& operator=(CVec_C2Tuple_u32TxOutZZ&& o) { CVec_C2Tuple_u32TxOutZZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_C2Tuple_u32TxOutZZ)); return *this; } - LDKCVec_C2Tuple_u32TxOutZZ* operator &() { return &self; } - LDKCVec_C2Tuple_u32TxOutZZ* operator ->() { return &self; } - const LDKCVec_C2Tuple_u32TxOutZZ* operator &() const { return &self; } - const LDKCVec_C2Tuple_u32TxOutZZ* operator ->() const { return &self; } -}; -class C2Tuple_SignatureCVec_SignatureZZ { -private: - LDKC2Tuple_SignatureCVec_SignatureZZ self; -public: - C2Tuple_SignatureCVec_SignatureZZ(const C2Tuple_SignatureCVec_SignatureZZ&) = delete; - C2Tuple_SignatureCVec_SignatureZZ(C2Tuple_SignatureCVec_SignatureZZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_SignatureCVec_SignatureZZ)); } - C2Tuple_SignatureCVec_SignatureZZ(LDKC2Tuple_SignatureCVec_SignatureZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ)); } - operator LDKC2Tuple_SignatureCVec_SignatureZZ() && { LDKC2Tuple_SignatureCVec_SignatureZZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ)); return res; } - ~C2Tuple_SignatureCVec_SignatureZZ() { C2Tuple_SignatureCVec_SignatureZZ_free(self); } - C2Tuple_SignatureCVec_SignatureZZ& operator=(C2Tuple_SignatureCVec_SignatureZZ&& o) { C2Tuple_SignatureCVec_SignatureZZ_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_SignatureCVec_SignatureZZ)); return *this; } - LDKC2Tuple_SignatureCVec_SignatureZZ* operator &() { return &self; } - LDKC2Tuple_SignatureCVec_SignatureZZ* operator ->() { return &self; } - const LDKC2Tuple_SignatureCVec_SignatureZZ* operator &() const { return &self; } - const LDKC2Tuple_SignatureCVec_SignatureZZ* operator ->() const { return &self; } -}; -class CResult_ChannelInfoDecodeErrorZ { -private: - LDKCResult_ChannelInfoDecodeErrorZ self; -public: - CResult_ChannelInfoDecodeErrorZ(const CResult_ChannelInfoDecodeErrorZ&) = delete; - CResult_ChannelInfoDecodeErrorZ(CResult_ChannelInfoDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ChannelInfoDecodeErrorZ)); } - CResult_ChannelInfoDecodeErrorZ(LDKCResult_ChannelInfoDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ChannelInfoDecodeErrorZ)); } - operator LDKCResult_ChannelInfoDecodeErrorZ() && { LDKCResult_ChannelInfoDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ChannelInfoDecodeErrorZ)); return res; } - ~CResult_ChannelInfoDecodeErrorZ() { CResult_ChannelInfoDecodeErrorZ_free(self); } - CResult_ChannelInfoDecodeErrorZ& operator=(CResult_ChannelInfoDecodeErrorZ&& o) { CResult_ChannelInfoDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ChannelInfoDecodeErrorZ)); return *this; } - LDKCResult_ChannelInfoDecodeErrorZ* operator &() { return &self; } - LDKCResult_ChannelInfoDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ChannelInfoDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ChannelInfoDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_CVec_u8ZPeerHandleErrorZ { -private: - LDKCResult_CVec_u8ZPeerHandleErrorZ self; -public: - CResult_CVec_u8ZPeerHandleErrorZ(const CResult_CVec_u8ZPeerHandleErrorZ&) = delete; - CResult_CVec_u8ZPeerHandleErrorZ(CResult_CVec_u8ZPeerHandleErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_CVec_u8ZPeerHandleErrorZ)); } - CResult_CVec_u8ZPeerHandleErrorZ(LDKCResult_CVec_u8ZPeerHandleErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ)); } - operator LDKCResult_CVec_u8ZPeerHandleErrorZ() && { LDKCResult_CVec_u8ZPeerHandleErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ)); return res; } - ~CResult_CVec_u8ZPeerHandleErrorZ() { CResult_CVec_u8ZPeerHandleErrorZ_free(self); } - CResult_CVec_u8ZPeerHandleErrorZ& operator=(CResult_CVec_u8ZPeerHandleErrorZ&& o) { CResult_CVec_u8ZPeerHandleErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_CVec_u8ZPeerHandleErrorZ)); return *this; } - LDKCResult_CVec_u8ZPeerHandleErrorZ* operator &() { return &self; } - LDKCResult_CVec_u8ZPeerHandleErrorZ* operator ->() { return &self; } - const LDKCResult_CVec_u8ZPeerHandleErrorZ* operator &() const { return &self; } - const LDKCResult_CVec_u8ZPeerHandleErrorZ* operator ->() const { return &self; } -}; -class CResult_ChannelMonitorUpdateDecodeErrorZ { -private: - LDKCResult_ChannelMonitorUpdateDecodeErrorZ self; -public: - CResult_ChannelMonitorUpdateDecodeErrorZ(const CResult_ChannelMonitorUpdateDecodeErrorZ&) = delete; - CResult_ChannelMonitorUpdateDecodeErrorZ(CResult_ChannelMonitorUpdateDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ChannelMonitorUpdateDecodeErrorZ)); } - CResult_ChannelMonitorUpdateDecodeErrorZ(LDKCResult_ChannelMonitorUpdateDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ)); } - operator LDKCResult_ChannelMonitorUpdateDecodeErrorZ() && { LDKCResult_ChannelMonitorUpdateDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ)); return res; } - ~CResult_ChannelMonitorUpdateDecodeErrorZ() { CResult_ChannelMonitorUpdateDecodeErrorZ_free(self); } - CResult_ChannelMonitorUpdateDecodeErrorZ& operator=(CResult_ChannelMonitorUpdateDecodeErrorZ&& o) { CResult_ChannelMonitorUpdateDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ChannelMonitorUpdateDecodeErrorZ)); return *this; } - LDKCResult_ChannelMonitorUpdateDecodeErrorZ* operator &() { return &self; } - LDKCResult_ChannelMonitorUpdateDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ChannelMonitorUpdateDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ChannelMonitorUpdateDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_ReplyChannelRangeDecodeErrorZ { -private: - LDKCResult_ReplyChannelRangeDecodeErrorZ self; -public: - CResult_ReplyChannelRangeDecodeErrorZ(const CResult_ReplyChannelRangeDecodeErrorZ&) = delete; - CResult_ReplyChannelRangeDecodeErrorZ(CResult_ReplyChannelRangeDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ReplyChannelRangeDecodeErrorZ)); } - CResult_ReplyChannelRangeDecodeErrorZ(LDKCResult_ReplyChannelRangeDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ)); } - operator LDKCResult_ReplyChannelRangeDecodeErrorZ() && { LDKCResult_ReplyChannelRangeDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ)); return res; } - ~CResult_ReplyChannelRangeDecodeErrorZ() { CResult_ReplyChannelRangeDecodeErrorZ_free(self); } - CResult_ReplyChannelRangeDecodeErrorZ& operator=(CResult_ReplyChannelRangeDecodeErrorZ&& o) { CResult_ReplyChannelRangeDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ReplyChannelRangeDecodeErrorZ)); return *this; } - LDKCResult_ReplyChannelRangeDecodeErrorZ* operator &() { return &self; } - LDKCResult_ReplyChannelRangeDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ReplyChannelRangeDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ReplyChannelRangeDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_GossipTimestampFilterDecodeErrorZ { -private: - LDKCResult_GossipTimestampFilterDecodeErrorZ self; -public: - CResult_GossipTimestampFilterDecodeErrorZ(const CResult_GossipTimestampFilterDecodeErrorZ&) = delete; - CResult_GossipTimestampFilterDecodeErrorZ(CResult_GossipTimestampFilterDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_GossipTimestampFilterDecodeErrorZ)); } - CResult_GossipTimestampFilterDecodeErrorZ(LDKCResult_GossipTimestampFilterDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ)); } - operator LDKCResult_GossipTimestampFilterDecodeErrorZ() && { LDKCResult_GossipTimestampFilterDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ)); return res; } - ~CResult_GossipTimestampFilterDecodeErrorZ() { CResult_GossipTimestampFilterDecodeErrorZ_free(self); } - CResult_GossipTimestampFilterDecodeErrorZ& operator=(CResult_GossipTimestampFilterDecodeErrorZ&& o) { CResult_GossipTimestampFilterDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_GossipTimestampFilterDecodeErrorZ)); return *this; } - LDKCResult_GossipTimestampFilterDecodeErrorZ* operator &() { return &self; } - LDKCResult_GossipTimestampFilterDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_GossipTimestampFilterDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_GossipTimestampFilterDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_TxOutAccessErrorZ { -private: - LDKCResult_TxOutAccessErrorZ self; -public: - CResult_TxOutAccessErrorZ(const CResult_TxOutAccessErrorZ&) = delete; - CResult_TxOutAccessErrorZ(CResult_TxOutAccessErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_TxOutAccessErrorZ)); } - CResult_TxOutAccessErrorZ(LDKCResult_TxOutAccessErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_TxOutAccessErrorZ)); } - operator LDKCResult_TxOutAccessErrorZ() && { LDKCResult_TxOutAccessErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_TxOutAccessErrorZ)); return res; } - ~CResult_TxOutAccessErrorZ() { CResult_TxOutAccessErrorZ_free(self); } - CResult_TxOutAccessErrorZ& operator=(CResult_TxOutAccessErrorZ&& o) { CResult_TxOutAccessErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_TxOutAccessErrorZ)); return *this; } - LDKCResult_TxOutAccessErrorZ* operator &() { return &self; } - LDKCResult_TxOutAccessErrorZ* operator ->() { return &self; } - const LDKCResult_TxOutAccessErrorZ* operator &() const { return &self; } - const LDKCResult_TxOutAccessErrorZ* operator ->() const { return &self; } -}; -class CResult_UnsignedNodeAnnouncementDecodeErrorZ { -private: - LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ self; -public: - CResult_UnsignedNodeAnnouncementDecodeErrorZ(const CResult_UnsignedNodeAnnouncementDecodeErrorZ&) = delete; - CResult_UnsignedNodeAnnouncementDecodeErrorZ(CResult_UnsignedNodeAnnouncementDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_UnsignedNodeAnnouncementDecodeErrorZ)); } - CResult_UnsignedNodeAnnouncementDecodeErrorZ(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ)); } - operator LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ() && { LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ)); return res; } - ~CResult_UnsignedNodeAnnouncementDecodeErrorZ() { CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(self); } - CResult_UnsignedNodeAnnouncementDecodeErrorZ& operator=(CResult_UnsignedNodeAnnouncementDecodeErrorZ&& o) { CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_UnsignedNodeAnnouncementDecodeErrorZ)); return *this; } - LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* operator &() { return &self; } - LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_ChannelReestablishDecodeErrorZ { -private: - LDKCResult_ChannelReestablishDecodeErrorZ self; -public: - CResult_ChannelReestablishDecodeErrorZ(const CResult_ChannelReestablishDecodeErrorZ&) = delete; - CResult_ChannelReestablishDecodeErrorZ(CResult_ChannelReestablishDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ChannelReestablishDecodeErrorZ)); } - CResult_ChannelReestablishDecodeErrorZ(LDKCResult_ChannelReestablishDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ChannelReestablishDecodeErrorZ)); } - operator LDKCResult_ChannelReestablishDecodeErrorZ() && { LDKCResult_ChannelReestablishDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ChannelReestablishDecodeErrorZ)); return res; } - ~CResult_ChannelReestablishDecodeErrorZ() { CResult_ChannelReestablishDecodeErrorZ_free(self); } - CResult_ChannelReestablishDecodeErrorZ& operator=(CResult_ChannelReestablishDecodeErrorZ&& o) { CResult_ChannelReestablishDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ChannelReestablishDecodeErrorZ)); return *this; } - LDKCResult_ChannelReestablishDecodeErrorZ* operator &() { return &self; } - LDKCResult_ChannelReestablishDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ChannelReestablishDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ChannelReestablishDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_CommitmentSignedDecodeErrorZ { -private: - LDKCResult_CommitmentSignedDecodeErrorZ self; -public: - CResult_CommitmentSignedDecodeErrorZ(const CResult_CommitmentSignedDecodeErrorZ&) = delete; - CResult_CommitmentSignedDecodeErrorZ(CResult_CommitmentSignedDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_CommitmentSignedDecodeErrorZ)); } - CResult_CommitmentSignedDecodeErrorZ(LDKCResult_CommitmentSignedDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_CommitmentSignedDecodeErrorZ)); } - operator LDKCResult_CommitmentSignedDecodeErrorZ() && { LDKCResult_CommitmentSignedDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_CommitmentSignedDecodeErrorZ)); return res; } - ~CResult_CommitmentSignedDecodeErrorZ() { CResult_CommitmentSignedDecodeErrorZ_free(self); } - CResult_CommitmentSignedDecodeErrorZ& operator=(CResult_CommitmentSignedDecodeErrorZ&& o) { CResult_CommitmentSignedDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_CommitmentSignedDecodeErrorZ)); return *this; } - LDKCResult_CommitmentSignedDecodeErrorZ* operator &() { return &self; } - LDKCResult_CommitmentSignedDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_CommitmentSignedDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_CommitmentSignedDecodeErrorZ* operator ->() const { return &self; } -}; -class CVec_UpdateAddHTLCZ { -private: - LDKCVec_UpdateAddHTLCZ self; -public: - CVec_UpdateAddHTLCZ(const CVec_UpdateAddHTLCZ&) = delete; - CVec_UpdateAddHTLCZ(CVec_UpdateAddHTLCZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_UpdateAddHTLCZ)); } - CVec_UpdateAddHTLCZ(LDKCVec_UpdateAddHTLCZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_UpdateAddHTLCZ)); } - operator LDKCVec_UpdateAddHTLCZ() && { LDKCVec_UpdateAddHTLCZ res = self; memset(&self, 0, sizeof(LDKCVec_UpdateAddHTLCZ)); return res; } - ~CVec_UpdateAddHTLCZ() { CVec_UpdateAddHTLCZ_free(self); } - CVec_UpdateAddHTLCZ& operator=(CVec_UpdateAddHTLCZ&& o) { CVec_UpdateAddHTLCZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_UpdateAddHTLCZ)); return *this; } - LDKCVec_UpdateAddHTLCZ* operator &() { return &self; } - LDKCVec_UpdateAddHTLCZ* operator ->() { return &self; } - const LDKCVec_UpdateAddHTLCZ* operator &() const { return &self; } - const LDKCVec_UpdateAddHTLCZ* operator ->() const { return &self; } -}; -class CResult_InitFeaturesDecodeErrorZ { -private: - LDKCResult_InitFeaturesDecodeErrorZ self; -public: - CResult_InitFeaturesDecodeErrorZ(const CResult_InitFeaturesDecodeErrorZ&) = delete; - CResult_InitFeaturesDecodeErrorZ(CResult_InitFeaturesDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_InitFeaturesDecodeErrorZ)); } - CResult_InitFeaturesDecodeErrorZ(LDKCResult_InitFeaturesDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_InitFeaturesDecodeErrorZ)); } - operator LDKCResult_InitFeaturesDecodeErrorZ() && { LDKCResult_InitFeaturesDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_InitFeaturesDecodeErrorZ)); return res; } - ~CResult_InitFeaturesDecodeErrorZ() { CResult_InitFeaturesDecodeErrorZ_free(self); } - CResult_InitFeaturesDecodeErrorZ& operator=(CResult_InitFeaturesDecodeErrorZ&& o) { CResult_InitFeaturesDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_InitFeaturesDecodeErrorZ)); return *this; } - LDKCResult_InitFeaturesDecodeErrorZ* operator &() { return &self; } - LDKCResult_InitFeaturesDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_InitFeaturesDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_InitFeaturesDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_CommitmentTransactionDecodeErrorZ { -private: - LDKCResult_CommitmentTransactionDecodeErrorZ self; -public: - CResult_CommitmentTransactionDecodeErrorZ(const CResult_CommitmentTransactionDecodeErrorZ&) = delete; - CResult_CommitmentTransactionDecodeErrorZ(CResult_CommitmentTransactionDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_CommitmentTransactionDecodeErrorZ)); } - CResult_CommitmentTransactionDecodeErrorZ(LDKCResult_CommitmentTransactionDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_CommitmentTransactionDecodeErrorZ)); } - operator LDKCResult_CommitmentTransactionDecodeErrorZ() && { LDKCResult_CommitmentTransactionDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_CommitmentTransactionDecodeErrorZ)); return res; } - ~CResult_CommitmentTransactionDecodeErrorZ() { CResult_CommitmentTransactionDecodeErrorZ_free(self); } - CResult_CommitmentTransactionDecodeErrorZ& operator=(CResult_CommitmentTransactionDecodeErrorZ&& o) { CResult_CommitmentTransactionDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_CommitmentTransactionDecodeErrorZ)); return *this; } - LDKCResult_CommitmentTransactionDecodeErrorZ* operator &() { return &self; } - LDKCResult_CommitmentTransactionDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_CommitmentTransactionDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_CommitmentTransactionDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_TransactionNoneZ { -private: - LDKCResult_TransactionNoneZ self; -public: - CResult_TransactionNoneZ(const CResult_TransactionNoneZ&) = delete; - CResult_TransactionNoneZ(CResult_TransactionNoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_TransactionNoneZ)); } - CResult_TransactionNoneZ(LDKCResult_TransactionNoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_TransactionNoneZ)); } - operator LDKCResult_TransactionNoneZ() && { LDKCResult_TransactionNoneZ res = self; memset(&self, 0, sizeof(LDKCResult_TransactionNoneZ)); return res; } - ~CResult_TransactionNoneZ() { CResult_TransactionNoneZ_free(self); } - CResult_TransactionNoneZ& operator=(CResult_TransactionNoneZ&& o) { CResult_TransactionNoneZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_TransactionNoneZ)); return *this; } - LDKCResult_TransactionNoneZ* operator &() { return &self; } - LDKCResult_TransactionNoneZ* operator ->() { return &self; } - const LDKCResult_TransactionNoneZ* operator &() const { return &self; } - const LDKCResult_TransactionNoneZ* operator ->() const { return &self; } -}; -class CResult_PingDecodeErrorZ { -private: - LDKCResult_PingDecodeErrorZ self; -public: - CResult_PingDecodeErrorZ(const CResult_PingDecodeErrorZ&) = delete; - CResult_PingDecodeErrorZ(CResult_PingDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PingDecodeErrorZ)); } - CResult_PingDecodeErrorZ(LDKCResult_PingDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PingDecodeErrorZ)); } - operator LDKCResult_PingDecodeErrorZ() && { LDKCResult_PingDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_PingDecodeErrorZ)); return res; } - ~CResult_PingDecodeErrorZ() { CResult_PingDecodeErrorZ_free(self); } - CResult_PingDecodeErrorZ& operator=(CResult_PingDecodeErrorZ&& o) { CResult_PingDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PingDecodeErrorZ)); return *this; } - LDKCResult_PingDecodeErrorZ* operator &() { return &self; } - LDKCResult_PingDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_PingDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_PingDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_ErrorMessageDecodeErrorZ { -private: - LDKCResult_ErrorMessageDecodeErrorZ self; -public: - CResult_ErrorMessageDecodeErrorZ(const CResult_ErrorMessageDecodeErrorZ&) = delete; - CResult_ErrorMessageDecodeErrorZ(CResult_ErrorMessageDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ErrorMessageDecodeErrorZ)); } - CResult_ErrorMessageDecodeErrorZ(LDKCResult_ErrorMessageDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ErrorMessageDecodeErrorZ)); } - operator LDKCResult_ErrorMessageDecodeErrorZ() && { LDKCResult_ErrorMessageDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ErrorMessageDecodeErrorZ)); return res; } - ~CResult_ErrorMessageDecodeErrorZ() { CResult_ErrorMessageDecodeErrorZ_free(self); } - CResult_ErrorMessageDecodeErrorZ& operator=(CResult_ErrorMessageDecodeErrorZ&& o) { CResult_ErrorMessageDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ErrorMessageDecodeErrorZ)); return *this; } - LDKCResult_ErrorMessageDecodeErrorZ* operator &() { return &self; } - LDKCResult_ErrorMessageDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ErrorMessageDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ErrorMessageDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_OpenChannelDecodeErrorZ { -private: - LDKCResult_OpenChannelDecodeErrorZ self; -public: - CResult_OpenChannelDecodeErrorZ(const CResult_OpenChannelDecodeErrorZ&) = delete; - CResult_OpenChannelDecodeErrorZ(CResult_OpenChannelDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_OpenChannelDecodeErrorZ)); } - CResult_OpenChannelDecodeErrorZ(LDKCResult_OpenChannelDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_OpenChannelDecodeErrorZ)); } - operator LDKCResult_OpenChannelDecodeErrorZ() && { LDKCResult_OpenChannelDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_OpenChannelDecodeErrorZ)); return res; } - ~CResult_OpenChannelDecodeErrorZ() { CResult_OpenChannelDecodeErrorZ_free(self); } - CResult_OpenChannelDecodeErrorZ& operator=(CResult_OpenChannelDecodeErrorZ&& o) { CResult_OpenChannelDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_OpenChannelDecodeErrorZ)); return *this; } - LDKCResult_OpenChannelDecodeErrorZ* operator &() { return &self; } - LDKCResult_OpenChannelDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_OpenChannelDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_OpenChannelDecodeErrorZ* operator ->() const { return &self; } -}; -class CVec_CVec_u8ZZ { -private: - LDKCVec_CVec_u8ZZ self; -public: - CVec_CVec_u8ZZ(const CVec_CVec_u8ZZ&) = delete; - CVec_CVec_u8ZZ(CVec_CVec_u8ZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_CVec_u8ZZ)); } - CVec_CVec_u8ZZ(LDKCVec_CVec_u8ZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_CVec_u8ZZ)); } - operator LDKCVec_CVec_u8ZZ() && { LDKCVec_CVec_u8ZZ res = self; memset(&self, 0, sizeof(LDKCVec_CVec_u8ZZ)); return res; } - ~CVec_CVec_u8ZZ() { CVec_CVec_u8ZZ_free(self); } - CVec_CVec_u8ZZ& operator=(CVec_CVec_u8ZZ&& o) { CVec_CVec_u8ZZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_CVec_u8ZZ)); return *this; } - LDKCVec_CVec_u8ZZ* operator &() { return &self; } - LDKCVec_CVec_u8ZZ* operator ->() { return &self; } - const LDKCVec_CVec_u8ZZ* operator &() const { return &self; } - const LDKCVec_CVec_u8ZZ* operator ->() const { return &self; } -}; -class CResult_SecretKeyErrorZ { -private: - LDKCResult_SecretKeyErrorZ self; -public: - CResult_SecretKeyErrorZ(const CResult_SecretKeyErrorZ&) = delete; - CResult_SecretKeyErrorZ(CResult_SecretKeyErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_SecretKeyErrorZ)); } - CResult_SecretKeyErrorZ(LDKCResult_SecretKeyErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_SecretKeyErrorZ)); } - operator LDKCResult_SecretKeyErrorZ() && { LDKCResult_SecretKeyErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_SecretKeyErrorZ)); return res; } - ~CResult_SecretKeyErrorZ() { CResult_SecretKeyErrorZ_free(self); } - CResult_SecretKeyErrorZ& operator=(CResult_SecretKeyErrorZ&& o) { CResult_SecretKeyErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_SecretKeyErrorZ)); return *this; } - LDKCResult_SecretKeyErrorZ* operator &() { return &self; } - LDKCResult_SecretKeyErrorZ* operator ->() { return &self; } - const LDKCResult_SecretKeyErrorZ* operator &() const { return &self; } - const LDKCResult_SecretKeyErrorZ* operator ->() const { return &self; } -}; -class CResult_QueryChannelRangeDecodeErrorZ { -private: - LDKCResult_QueryChannelRangeDecodeErrorZ self; -public: - CResult_QueryChannelRangeDecodeErrorZ(const CResult_QueryChannelRangeDecodeErrorZ&) = delete; - CResult_QueryChannelRangeDecodeErrorZ(CResult_QueryChannelRangeDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_QueryChannelRangeDecodeErrorZ)); } - CResult_QueryChannelRangeDecodeErrorZ(LDKCResult_QueryChannelRangeDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ)); } - operator LDKCResult_QueryChannelRangeDecodeErrorZ() && { LDKCResult_QueryChannelRangeDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ)); return res; } - ~CResult_QueryChannelRangeDecodeErrorZ() { CResult_QueryChannelRangeDecodeErrorZ_free(self); } - CResult_QueryChannelRangeDecodeErrorZ& operator=(CResult_QueryChannelRangeDecodeErrorZ&& o) { CResult_QueryChannelRangeDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_QueryChannelRangeDecodeErrorZ)); return *this; } - LDKCResult_QueryChannelRangeDecodeErrorZ* operator &() { return &self; } - LDKCResult_QueryChannelRangeDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_QueryChannelRangeDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_QueryChannelRangeDecodeErrorZ* operator ->() const { return &self; } -}; -class CVec_TransactionZ { -private: - LDKCVec_TransactionZ self; -public: - CVec_TransactionZ(const CVec_TransactionZ&) = delete; - CVec_TransactionZ(CVec_TransactionZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_TransactionZ)); } - CVec_TransactionZ(LDKCVec_TransactionZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_TransactionZ)); } - operator LDKCVec_TransactionZ() && { LDKCVec_TransactionZ res = self; memset(&self, 0, sizeof(LDKCVec_TransactionZ)); return res; } - ~CVec_TransactionZ() { CVec_TransactionZ_free(self); } - CVec_TransactionZ& operator=(CVec_TransactionZ&& o) { CVec_TransactionZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_TransactionZ)); return *this; } - LDKCVec_TransactionZ* operator &() { return &self; } - LDKCVec_TransactionZ* operator ->() { return &self; } - const LDKCVec_TransactionZ* operator &() const { return &self; } - const LDKCVec_TransactionZ* operator ->() const { return &self; } -}; -class CResult_TxCreationKeysDecodeErrorZ { -private: - LDKCResult_TxCreationKeysDecodeErrorZ self; -public: - CResult_TxCreationKeysDecodeErrorZ(const CResult_TxCreationKeysDecodeErrorZ&) = delete; - CResult_TxCreationKeysDecodeErrorZ(CResult_TxCreationKeysDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_TxCreationKeysDecodeErrorZ)); } - CResult_TxCreationKeysDecodeErrorZ(LDKCResult_TxCreationKeysDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_TxCreationKeysDecodeErrorZ)); } - operator LDKCResult_TxCreationKeysDecodeErrorZ() && { LDKCResult_TxCreationKeysDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_TxCreationKeysDecodeErrorZ)); return res; } - ~CResult_TxCreationKeysDecodeErrorZ() { CResult_TxCreationKeysDecodeErrorZ_free(self); } - CResult_TxCreationKeysDecodeErrorZ& operator=(CResult_TxCreationKeysDecodeErrorZ&& o) { CResult_TxCreationKeysDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_TxCreationKeysDecodeErrorZ)); return *this; } - LDKCResult_TxCreationKeysDecodeErrorZ* operator &() { return &self; } - LDKCResult_TxCreationKeysDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_TxCreationKeysDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_TxCreationKeysDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_ChannelFeaturesDecodeErrorZ { -private: - LDKCResult_ChannelFeaturesDecodeErrorZ self; -public: - CResult_ChannelFeaturesDecodeErrorZ(const CResult_ChannelFeaturesDecodeErrorZ&) = delete; - CResult_ChannelFeaturesDecodeErrorZ(CResult_ChannelFeaturesDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ChannelFeaturesDecodeErrorZ)); } - CResult_ChannelFeaturesDecodeErrorZ(LDKCResult_ChannelFeaturesDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ChannelFeaturesDecodeErrorZ)); } - operator LDKCResult_ChannelFeaturesDecodeErrorZ() && { LDKCResult_ChannelFeaturesDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ChannelFeaturesDecodeErrorZ)); return res; } - ~CResult_ChannelFeaturesDecodeErrorZ() { CResult_ChannelFeaturesDecodeErrorZ_free(self); } - CResult_ChannelFeaturesDecodeErrorZ& operator=(CResult_ChannelFeaturesDecodeErrorZ&& o) { CResult_ChannelFeaturesDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ChannelFeaturesDecodeErrorZ)); return *this; } - LDKCResult_ChannelFeaturesDecodeErrorZ* operator &() { return &self; } - LDKCResult_ChannelFeaturesDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ChannelFeaturesDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ChannelFeaturesDecodeErrorZ* operator ->() const { return &self; } -}; -class C2Tuple_usizeTransactionZ { -private: - LDKC2Tuple_usizeTransactionZ self; -public: - C2Tuple_usizeTransactionZ(const C2Tuple_usizeTransactionZ&) = delete; - C2Tuple_usizeTransactionZ(C2Tuple_usizeTransactionZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_usizeTransactionZ)); } - C2Tuple_usizeTransactionZ(LDKC2Tuple_usizeTransactionZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_usizeTransactionZ)); } - operator LDKC2Tuple_usizeTransactionZ() && { LDKC2Tuple_usizeTransactionZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_usizeTransactionZ)); return res; } - ~C2Tuple_usizeTransactionZ() { C2Tuple_usizeTransactionZ_free(self); } - C2Tuple_usizeTransactionZ& operator=(C2Tuple_usizeTransactionZ&& o) { C2Tuple_usizeTransactionZ_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_usizeTransactionZ)); return *this; } - LDKC2Tuple_usizeTransactionZ* operator &() { return &self; } - LDKC2Tuple_usizeTransactionZ* operator ->() { return &self; } - const LDKC2Tuple_usizeTransactionZ* operator &() const { return &self; } - const LDKC2Tuple_usizeTransactionZ* operator ->() const { return &self; } -}; -class CVec_ChannelMonitorZ { -private: - LDKCVec_ChannelMonitorZ self; -public: - CVec_ChannelMonitorZ(const CVec_ChannelMonitorZ&) = delete; - CVec_ChannelMonitorZ(CVec_ChannelMonitorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_ChannelMonitorZ)); } - CVec_ChannelMonitorZ(LDKCVec_ChannelMonitorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_ChannelMonitorZ)); } - operator LDKCVec_ChannelMonitorZ() && { LDKCVec_ChannelMonitorZ res = self; memset(&self, 0, sizeof(LDKCVec_ChannelMonitorZ)); return res; } - ~CVec_ChannelMonitorZ() { CVec_ChannelMonitorZ_free(self); } - CVec_ChannelMonitorZ& operator=(CVec_ChannelMonitorZ&& o) { CVec_ChannelMonitorZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_ChannelMonitorZ)); return *this; } - LDKCVec_ChannelMonitorZ* operator &() { return &self; } - LDKCVec_ChannelMonitorZ* operator ->() { return &self; } - const LDKCVec_ChannelMonitorZ* operator &() const { return &self; } - const LDKCVec_ChannelMonitorZ* operator ->() const { return &self; } -}; -class CResult_UpdateFeeDecodeErrorZ { -private: - LDKCResult_UpdateFeeDecodeErrorZ self; -public: - CResult_UpdateFeeDecodeErrorZ(const CResult_UpdateFeeDecodeErrorZ&) = delete; - CResult_UpdateFeeDecodeErrorZ(CResult_UpdateFeeDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_UpdateFeeDecodeErrorZ)); } - CResult_UpdateFeeDecodeErrorZ(LDKCResult_UpdateFeeDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_UpdateFeeDecodeErrorZ)); } - operator LDKCResult_UpdateFeeDecodeErrorZ() && { LDKCResult_UpdateFeeDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_UpdateFeeDecodeErrorZ)); return res; } - ~CResult_UpdateFeeDecodeErrorZ() { CResult_UpdateFeeDecodeErrorZ_free(self); } - CResult_UpdateFeeDecodeErrorZ& operator=(CResult_UpdateFeeDecodeErrorZ&& o) { CResult_UpdateFeeDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_UpdateFeeDecodeErrorZ)); return *this; } - LDKCResult_UpdateFeeDecodeErrorZ* operator &() { return &self; } - LDKCResult_UpdateFeeDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_UpdateFeeDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_UpdateFeeDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_NodeAnnouncementDecodeErrorZ { -private: - LDKCResult_NodeAnnouncementDecodeErrorZ self; -public: - CResult_NodeAnnouncementDecodeErrorZ(const CResult_NodeAnnouncementDecodeErrorZ&) = delete; - CResult_NodeAnnouncementDecodeErrorZ(CResult_NodeAnnouncementDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NodeAnnouncementDecodeErrorZ)); } - CResult_NodeAnnouncementDecodeErrorZ(LDKCResult_NodeAnnouncementDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NodeAnnouncementDecodeErrorZ)); } - operator LDKCResult_NodeAnnouncementDecodeErrorZ() && { LDKCResult_NodeAnnouncementDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NodeAnnouncementDecodeErrorZ)); return res; } - ~CResult_NodeAnnouncementDecodeErrorZ() { CResult_NodeAnnouncementDecodeErrorZ_free(self); } - CResult_NodeAnnouncementDecodeErrorZ& operator=(CResult_NodeAnnouncementDecodeErrorZ&& o) { CResult_NodeAnnouncementDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NodeAnnouncementDecodeErrorZ)); return *this; } - LDKCResult_NodeAnnouncementDecodeErrorZ* operator &() { return &self; } - LDKCResult_NodeAnnouncementDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_NodeAnnouncementDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_NodeAnnouncementDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_HTLCOutputInCommitmentDecodeErrorZ { -private: - LDKCResult_HTLCOutputInCommitmentDecodeErrorZ self; -public: - CResult_HTLCOutputInCommitmentDecodeErrorZ(const CResult_HTLCOutputInCommitmentDecodeErrorZ&) = delete; - CResult_HTLCOutputInCommitmentDecodeErrorZ(CResult_HTLCOutputInCommitmentDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_HTLCOutputInCommitmentDecodeErrorZ)); } - CResult_HTLCOutputInCommitmentDecodeErrorZ(LDKCResult_HTLCOutputInCommitmentDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_HTLCOutputInCommitmentDecodeErrorZ)); } - operator LDKCResult_HTLCOutputInCommitmentDecodeErrorZ() && { LDKCResult_HTLCOutputInCommitmentDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_HTLCOutputInCommitmentDecodeErrorZ)); return res; } - ~CResult_HTLCOutputInCommitmentDecodeErrorZ() { CResult_HTLCOutputInCommitmentDecodeErrorZ_free(self); } - CResult_HTLCOutputInCommitmentDecodeErrorZ& operator=(CResult_HTLCOutputInCommitmentDecodeErrorZ&& o) { CResult_HTLCOutputInCommitmentDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_HTLCOutputInCommitmentDecodeErrorZ)); return *this; } - LDKCResult_HTLCOutputInCommitmentDecodeErrorZ* operator &() { return &self; } - LDKCResult_HTLCOutputInCommitmentDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_HTLCOutputInCommitmentDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_HTLCOutputInCommitmentDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_boolLightningErrorZ { -private: - LDKCResult_boolLightningErrorZ self; -public: - CResult_boolLightningErrorZ(const CResult_boolLightningErrorZ&) = delete; - CResult_boolLightningErrorZ(CResult_boolLightningErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_boolLightningErrorZ)); } - CResult_boolLightningErrorZ(LDKCResult_boolLightningErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_boolLightningErrorZ)); } - operator LDKCResult_boolLightningErrorZ() && { LDKCResult_boolLightningErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_boolLightningErrorZ)); return res; } - ~CResult_boolLightningErrorZ() { CResult_boolLightningErrorZ_free(self); } - CResult_boolLightningErrorZ& operator=(CResult_boolLightningErrorZ&& o) { CResult_boolLightningErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_boolLightningErrorZ)); return *this; } - LDKCResult_boolLightningErrorZ* operator &() { return &self; } - LDKCResult_boolLightningErrorZ* operator ->() { return &self; } - const LDKCResult_boolLightningErrorZ* operator &() const { return &self; } - const LDKCResult_boolLightningErrorZ* operator ->() const { return &self; } -}; -class CResult_TxCreationKeysErrorZ { -private: - LDKCResult_TxCreationKeysErrorZ self; -public: - CResult_TxCreationKeysErrorZ(const CResult_TxCreationKeysErrorZ&) = delete; - CResult_TxCreationKeysErrorZ(CResult_TxCreationKeysErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_TxCreationKeysErrorZ)); } - CResult_TxCreationKeysErrorZ(LDKCResult_TxCreationKeysErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_TxCreationKeysErrorZ)); } - operator LDKCResult_TxCreationKeysErrorZ() && { LDKCResult_TxCreationKeysErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_TxCreationKeysErrorZ)); return res; } - ~CResult_TxCreationKeysErrorZ() { CResult_TxCreationKeysErrorZ_free(self); } - CResult_TxCreationKeysErrorZ& operator=(CResult_TxCreationKeysErrorZ&& o) { CResult_TxCreationKeysErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_TxCreationKeysErrorZ)); return *this; } - LDKCResult_TxCreationKeysErrorZ* operator &() { return &self; } - LDKCResult_TxCreationKeysErrorZ* operator ->() { return &self; } - const LDKCResult_TxCreationKeysErrorZ* operator &() const { return &self; } - const LDKCResult_TxCreationKeysErrorZ* operator ->() const { return &self; } -}; -class C2Tuple_BlockHashChannelMonitorZ { -private: - LDKC2Tuple_BlockHashChannelMonitorZ self; -public: - C2Tuple_BlockHashChannelMonitorZ(const C2Tuple_BlockHashChannelMonitorZ&) = delete; - C2Tuple_BlockHashChannelMonitorZ(C2Tuple_BlockHashChannelMonitorZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_BlockHashChannelMonitorZ)); } - C2Tuple_BlockHashChannelMonitorZ(LDKC2Tuple_BlockHashChannelMonitorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_BlockHashChannelMonitorZ)); } - operator LDKC2Tuple_BlockHashChannelMonitorZ() && { LDKC2Tuple_BlockHashChannelMonitorZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_BlockHashChannelMonitorZ)); return res; } - ~C2Tuple_BlockHashChannelMonitorZ() { C2Tuple_BlockHashChannelMonitorZ_free(self); } - C2Tuple_BlockHashChannelMonitorZ& operator=(C2Tuple_BlockHashChannelMonitorZ&& o) { C2Tuple_BlockHashChannelMonitorZ_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_BlockHashChannelMonitorZ)); return *this; } - LDKC2Tuple_BlockHashChannelMonitorZ* operator &() { return &self; } - LDKC2Tuple_BlockHashChannelMonitorZ* operator ->() { return &self; } - const LDKC2Tuple_BlockHashChannelMonitorZ* operator &() const { return &self; } - const LDKC2Tuple_BlockHashChannelMonitorZ* operator ->() const { return &self; } -}; -class CResult_FundingSignedDecodeErrorZ { -private: - LDKCResult_FundingSignedDecodeErrorZ self; -public: - CResult_FundingSignedDecodeErrorZ(const CResult_FundingSignedDecodeErrorZ&) = delete; - CResult_FundingSignedDecodeErrorZ(CResult_FundingSignedDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_FundingSignedDecodeErrorZ)); } - CResult_FundingSignedDecodeErrorZ(LDKCResult_FundingSignedDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_FundingSignedDecodeErrorZ)); } - operator LDKCResult_FundingSignedDecodeErrorZ() && { LDKCResult_FundingSignedDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_FundingSignedDecodeErrorZ)); return res; } - ~CResult_FundingSignedDecodeErrorZ() { CResult_FundingSignedDecodeErrorZ_free(self); } - CResult_FundingSignedDecodeErrorZ& operator=(CResult_FundingSignedDecodeErrorZ&& o) { CResult_FundingSignedDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_FundingSignedDecodeErrorZ)); return *this; } - LDKCResult_FundingSignedDecodeErrorZ* operator &() { return &self; } - LDKCResult_FundingSignedDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_FundingSignedDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_FundingSignedDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_NodeAnnouncementInfoDecodeErrorZ { -private: - LDKCResult_NodeAnnouncementInfoDecodeErrorZ self; -public: - CResult_NodeAnnouncementInfoDecodeErrorZ(const CResult_NodeAnnouncementInfoDecodeErrorZ&) = delete; - CResult_NodeAnnouncementInfoDecodeErrorZ(CResult_NodeAnnouncementInfoDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NodeAnnouncementInfoDecodeErrorZ)); } - CResult_NodeAnnouncementInfoDecodeErrorZ(LDKCResult_NodeAnnouncementInfoDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ)); } - operator LDKCResult_NodeAnnouncementInfoDecodeErrorZ() && { LDKCResult_NodeAnnouncementInfoDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ)); return res; } - ~CResult_NodeAnnouncementInfoDecodeErrorZ() { CResult_NodeAnnouncementInfoDecodeErrorZ_free(self); } - CResult_NodeAnnouncementInfoDecodeErrorZ& operator=(CResult_NodeAnnouncementInfoDecodeErrorZ&& o) { CResult_NodeAnnouncementInfoDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NodeAnnouncementInfoDecodeErrorZ)); return *this; } - LDKCResult_NodeAnnouncementInfoDecodeErrorZ* operator &() { return &self; } - LDKCResult_NodeAnnouncementInfoDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_NodeAnnouncementInfoDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_NodeAnnouncementInfoDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_NetAddressu8Z { -private: - LDKCResult_NetAddressu8Z self; -public: - CResult_NetAddressu8Z(const CResult_NetAddressu8Z&) = delete; - CResult_NetAddressu8Z(CResult_NetAddressu8Z&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NetAddressu8Z)); } - CResult_NetAddressu8Z(LDKCResult_NetAddressu8Z&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NetAddressu8Z)); } - operator LDKCResult_NetAddressu8Z() && { LDKCResult_NetAddressu8Z res = self; memset(&self, 0, sizeof(LDKCResult_NetAddressu8Z)); return res; } - ~CResult_NetAddressu8Z() { CResult_NetAddressu8Z_free(self); } - CResult_NetAddressu8Z& operator=(CResult_NetAddressu8Z&& o) { CResult_NetAddressu8Z_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NetAddressu8Z)); return *this; } - LDKCResult_NetAddressu8Z* operator &() { return &self; } - LDKCResult_NetAddressu8Z* operator ->() { return &self; } - const LDKCResult_NetAddressu8Z* operator &() const { return &self; } - const LDKCResult_NetAddressu8Z* operator ->() const { return &self; } -}; -class CVec_UpdateFailMalformedHTLCZ { -private: - LDKCVec_UpdateFailMalformedHTLCZ self; -public: - CVec_UpdateFailMalformedHTLCZ(const CVec_UpdateFailMalformedHTLCZ&) = delete; - CVec_UpdateFailMalformedHTLCZ(CVec_UpdateFailMalformedHTLCZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_UpdateFailMalformedHTLCZ)); } - CVec_UpdateFailMalformedHTLCZ(LDKCVec_UpdateFailMalformedHTLCZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_UpdateFailMalformedHTLCZ)); } - operator LDKCVec_UpdateFailMalformedHTLCZ() && { LDKCVec_UpdateFailMalformedHTLCZ res = self; memset(&self, 0, sizeof(LDKCVec_UpdateFailMalformedHTLCZ)); return res; } - ~CVec_UpdateFailMalformedHTLCZ() { CVec_UpdateFailMalformedHTLCZ_free(self); } - CVec_UpdateFailMalformedHTLCZ& operator=(CVec_UpdateFailMalformedHTLCZ&& o) { CVec_UpdateFailMalformedHTLCZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_UpdateFailMalformedHTLCZ)); return *this; } - LDKCVec_UpdateFailMalformedHTLCZ* operator &() { return &self; } - LDKCVec_UpdateFailMalformedHTLCZ* operator ->() { return &self; } - const LDKCVec_UpdateFailMalformedHTLCZ* operator &() const { return &self; } - const LDKCVec_UpdateFailMalformedHTLCZ* operator ->() const { return &self; } -}; -class CResult_NetworkGraphDecodeErrorZ { -private: - LDKCResult_NetworkGraphDecodeErrorZ self; -public: - CResult_NetworkGraphDecodeErrorZ(const CResult_NetworkGraphDecodeErrorZ&) = delete; - CResult_NetworkGraphDecodeErrorZ(CResult_NetworkGraphDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NetworkGraphDecodeErrorZ)); } - CResult_NetworkGraphDecodeErrorZ(LDKCResult_NetworkGraphDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NetworkGraphDecodeErrorZ)); } - operator LDKCResult_NetworkGraphDecodeErrorZ() && { LDKCResult_NetworkGraphDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NetworkGraphDecodeErrorZ)); return res; } - ~CResult_NetworkGraphDecodeErrorZ() { CResult_NetworkGraphDecodeErrorZ_free(self); } - CResult_NetworkGraphDecodeErrorZ& operator=(CResult_NetworkGraphDecodeErrorZ&& o) { CResult_NetworkGraphDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NetworkGraphDecodeErrorZ)); return *this; } - LDKCResult_NetworkGraphDecodeErrorZ* operator &() { return &self; } - LDKCResult_NetworkGraphDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_NetworkGraphDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_NetworkGraphDecodeErrorZ* operator ->() const { return &self; } -}; -class CVec_RouteHopZ { -private: - LDKCVec_RouteHopZ self; -public: - CVec_RouteHopZ(const CVec_RouteHopZ&) = delete; - CVec_RouteHopZ(CVec_RouteHopZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_RouteHopZ)); } - CVec_RouteHopZ(LDKCVec_RouteHopZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_RouteHopZ)); } - operator LDKCVec_RouteHopZ() && { LDKCVec_RouteHopZ res = self; memset(&self, 0, sizeof(LDKCVec_RouteHopZ)); return res; } - ~CVec_RouteHopZ() { CVec_RouteHopZ_free(self); } - CVec_RouteHopZ& operator=(CVec_RouteHopZ&& o) { CVec_RouteHopZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_RouteHopZ)); return *this; } - LDKCVec_RouteHopZ* operator &() { return &self; } - LDKCVec_RouteHopZ* operator ->() { return &self; } - const LDKCVec_RouteHopZ* operator &() const { return &self; } - const LDKCVec_RouteHopZ* operator ->() const { return &self; } -}; -class CResult_NodeInfoDecodeErrorZ { -private: - LDKCResult_NodeInfoDecodeErrorZ self; -public: - CResult_NodeInfoDecodeErrorZ(const CResult_NodeInfoDecodeErrorZ&) = delete; - CResult_NodeInfoDecodeErrorZ(CResult_NodeInfoDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NodeInfoDecodeErrorZ)); } - CResult_NodeInfoDecodeErrorZ(LDKCResult_NodeInfoDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NodeInfoDecodeErrorZ)); } - operator LDKCResult_NodeInfoDecodeErrorZ() && { LDKCResult_NodeInfoDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NodeInfoDecodeErrorZ)); return res; } - ~CResult_NodeInfoDecodeErrorZ() { CResult_NodeInfoDecodeErrorZ_free(self); } - CResult_NodeInfoDecodeErrorZ& operator=(CResult_NodeInfoDecodeErrorZ&& o) { CResult_NodeInfoDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NodeInfoDecodeErrorZ)); return *this; } - LDKCResult_NodeInfoDecodeErrorZ* operator &() { return &self; } - LDKCResult_NodeInfoDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_NodeInfoDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_NodeInfoDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_NonePaymentSendFailureZ { -private: - LDKCResult_NonePaymentSendFailureZ self; -public: - CResult_NonePaymentSendFailureZ(const CResult_NonePaymentSendFailureZ&) = delete; - CResult_NonePaymentSendFailureZ(CResult_NonePaymentSendFailureZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NonePaymentSendFailureZ)); } - CResult_NonePaymentSendFailureZ(LDKCResult_NonePaymentSendFailureZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NonePaymentSendFailureZ)); } - operator LDKCResult_NonePaymentSendFailureZ() && { LDKCResult_NonePaymentSendFailureZ res = self; memset(&self, 0, sizeof(LDKCResult_NonePaymentSendFailureZ)); return res; } - ~CResult_NonePaymentSendFailureZ() { CResult_NonePaymentSendFailureZ_free(self); } - CResult_NonePaymentSendFailureZ& operator=(CResult_NonePaymentSendFailureZ&& o) { CResult_NonePaymentSendFailureZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NonePaymentSendFailureZ)); return *this; } - LDKCResult_NonePaymentSendFailureZ* operator &() { return &self; } - LDKCResult_NonePaymentSendFailureZ* operator ->() { return &self; } - const LDKCResult_NonePaymentSendFailureZ* operator &() const { return &self; } - const LDKCResult_NonePaymentSendFailureZ* operator ->() const { return &self; } -}; -class CVec_u8Z { -private: - LDKCVec_u8Z self; -public: - CVec_u8Z(const CVec_u8Z&) = delete; - CVec_u8Z(CVec_u8Z&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_u8Z)); } - CVec_u8Z(LDKCVec_u8Z&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_u8Z)); } - operator LDKCVec_u8Z() && { LDKCVec_u8Z res = self; memset(&self, 0, sizeof(LDKCVec_u8Z)); return res; } - ~CVec_u8Z() { CVec_u8Z_free(self); } - CVec_u8Z& operator=(CVec_u8Z&& o) { CVec_u8Z_free(self); self = o.self; memset(&o, 0, sizeof(CVec_u8Z)); return *this; } - LDKCVec_u8Z* operator &() { return &self; } - LDKCVec_u8Z* operator ->() { return &self; } - const LDKCVec_u8Z* operator &() const { return &self; } - const LDKCVec_u8Z* operator ->() const { return &self; } -}; -class CResult_ChannelPublicKeysDecodeErrorZ { -private: - LDKCResult_ChannelPublicKeysDecodeErrorZ self; -public: - CResult_ChannelPublicKeysDecodeErrorZ(const CResult_ChannelPublicKeysDecodeErrorZ&) = delete; - CResult_ChannelPublicKeysDecodeErrorZ(CResult_ChannelPublicKeysDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ChannelPublicKeysDecodeErrorZ)); } - CResult_ChannelPublicKeysDecodeErrorZ(LDKCResult_ChannelPublicKeysDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ChannelPublicKeysDecodeErrorZ)); } - operator LDKCResult_ChannelPublicKeysDecodeErrorZ() && { LDKCResult_ChannelPublicKeysDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ChannelPublicKeysDecodeErrorZ)); return res; } - ~CResult_ChannelPublicKeysDecodeErrorZ() { CResult_ChannelPublicKeysDecodeErrorZ_free(self); } - CResult_ChannelPublicKeysDecodeErrorZ& operator=(CResult_ChannelPublicKeysDecodeErrorZ&& o) { CResult_ChannelPublicKeysDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ChannelPublicKeysDecodeErrorZ)); return *this; } - LDKCResult_ChannelPublicKeysDecodeErrorZ* operator &() { return &self; } - LDKCResult_ChannelPublicKeysDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ChannelPublicKeysDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ChannelPublicKeysDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_RouteLightningErrorZ { -private: - LDKCResult_RouteLightningErrorZ self; -public: - CResult_RouteLightningErrorZ(const CResult_RouteLightningErrorZ&) = delete; - CResult_RouteLightningErrorZ(CResult_RouteLightningErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_RouteLightningErrorZ)); } - CResult_RouteLightningErrorZ(LDKCResult_RouteLightningErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_RouteLightningErrorZ)); } - operator LDKCResult_RouteLightningErrorZ() && { LDKCResult_RouteLightningErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_RouteLightningErrorZ)); return res; } - ~CResult_RouteLightningErrorZ() { CResult_RouteLightningErrorZ_free(self); } - CResult_RouteLightningErrorZ& operator=(CResult_RouteLightningErrorZ&& o) { CResult_RouteLightningErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_RouteLightningErrorZ)); return *this; } - LDKCResult_RouteLightningErrorZ* operator &() { return &self; } - LDKCResult_RouteLightningErrorZ* operator ->() { return &self; } - const LDKCResult_RouteLightningErrorZ* operator &() const { return &self; } - const LDKCResult_RouteLightningErrorZ* operator ->() const { return &self; } -}; -class CResult_ClosingSignedDecodeErrorZ { -private: - LDKCResult_ClosingSignedDecodeErrorZ self; -public: - CResult_ClosingSignedDecodeErrorZ(const CResult_ClosingSignedDecodeErrorZ&) = delete; - CResult_ClosingSignedDecodeErrorZ(CResult_ClosingSignedDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ClosingSignedDecodeErrorZ)); } - CResult_ClosingSignedDecodeErrorZ(LDKCResult_ClosingSignedDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ClosingSignedDecodeErrorZ)); } - operator LDKCResult_ClosingSignedDecodeErrorZ() && { LDKCResult_ClosingSignedDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ClosingSignedDecodeErrorZ)); return res; } - ~CResult_ClosingSignedDecodeErrorZ() { CResult_ClosingSignedDecodeErrorZ_free(self); } - CResult_ClosingSignedDecodeErrorZ& operator=(CResult_ClosingSignedDecodeErrorZ&& o) { CResult_ClosingSignedDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ClosingSignedDecodeErrorZ)); return *this; } - LDKCResult_ClosingSignedDecodeErrorZ* operator &() { return &self; } - LDKCResult_ClosingSignedDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ClosingSignedDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ClosingSignedDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_HolderCommitmentTransactionDecodeErrorZ { -private: - LDKCResult_HolderCommitmentTransactionDecodeErrorZ self; -public: - CResult_HolderCommitmentTransactionDecodeErrorZ(const CResult_HolderCommitmentTransactionDecodeErrorZ&) = delete; - CResult_HolderCommitmentTransactionDecodeErrorZ(CResult_HolderCommitmentTransactionDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_HolderCommitmentTransactionDecodeErrorZ)); } - CResult_HolderCommitmentTransactionDecodeErrorZ(LDKCResult_HolderCommitmentTransactionDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_HolderCommitmentTransactionDecodeErrorZ)); } - operator LDKCResult_HolderCommitmentTransactionDecodeErrorZ() && { LDKCResult_HolderCommitmentTransactionDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_HolderCommitmentTransactionDecodeErrorZ)); return res; } - ~CResult_HolderCommitmentTransactionDecodeErrorZ() { CResult_HolderCommitmentTransactionDecodeErrorZ_free(self); } - CResult_HolderCommitmentTransactionDecodeErrorZ& operator=(CResult_HolderCommitmentTransactionDecodeErrorZ&& o) { CResult_HolderCommitmentTransactionDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_HolderCommitmentTransactionDecodeErrorZ)); return *this; } - LDKCResult_HolderCommitmentTransactionDecodeErrorZ* operator &() { return &self; } - LDKCResult_HolderCommitmentTransactionDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_HolderCommitmentTransactionDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_HolderCommitmentTransactionDecodeErrorZ* operator ->() const { return &self; } -}; -class CVec_CResult_NoneAPIErrorZZ { -private: - LDKCVec_CResult_NoneAPIErrorZZ self; -public: - CVec_CResult_NoneAPIErrorZZ(const CVec_CResult_NoneAPIErrorZZ&) = delete; - CVec_CResult_NoneAPIErrorZZ(CVec_CResult_NoneAPIErrorZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_CResult_NoneAPIErrorZZ)); } - CVec_CResult_NoneAPIErrorZZ(LDKCVec_CResult_NoneAPIErrorZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_CResult_NoneAPIErrorZZ)); } - operator LDKCVec_CResult_NoneAPIErrorZZ() && { LDKCVec_CResult_NoneAPIErrorZZ res = self; memset(&self, 0, sizeof(LDKCVec_CResult_NoneAPIErrorZZ)); return res; } - ~CVec_CResult_NoneAPIErrorZZ() { CVec_CResult_NoneAPIErrorZZ_free(self); } - CVec_CResult_NoneAPIErrorZZ& operator=(CVec_CResult_NoneAPIErrorZZ&& o) { CVec_CResult_NoneAPIErrorZZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_CResult_NoneAPIErrorZZ)); return *this; } - LDKCVec_CResult_NoneAPIErrorZZ* operator &() { return &self; } - LDKCVec_CResult_NoneAPIErrorZZ* operator ->() { return &self; } - const LDKCVec_CResult_NoneAPIErrorZZ* operator &() const { return &self; } - const LDKCVec_CResult_NoneAPIErrorZZ* operator ->() const { return &self; } -}; -class CResult_SignatureNoneZ { -private: - LDKCResult_SignatureNoneZ self; -public: - CResult_SignatureNoneZ(const CResult_SignatureNoneZ&) = delete; - CResult_SignatureNoneZ(CResult_SignatureNoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_SignatureNoneZ)); } - CResult_SignatureNoneZ(LDKCResult_SignatureNoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_SignatureNoneZ)); } - operator LDKCResult_SignatureNoneZ() && { LDKCResult_SignatureNoneZ res = self; memset(&self, 0, sizeof(LDKCResult_SignatureNoneZ)); return res; } - ~CResult_SignatureNoneZ() { CResult_SignatureNoneZ_free(self); } - CResult_SignatureNoneZ& operator=(CResult_SignatureNoneZ&& o) { CResult_SignatureNoneZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_SignatureNoneZ)); return *this; } - LDKCResult_SignatureNoneZ* operator &() { return &self; } - LDKCResult_SignatureNoneZ* operator ->() { return &self; } - const LDKCResult_SignatureNoneZ* operator &() const { return &self; } - const LDKCResult_SignatureNoneZ* operator ->() const { return &self; } -}; -class C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ { -private: - LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ self; -public: - C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ(const C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ&) = delete; - C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ(C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ)); } - C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ)); } - operator LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ() && { LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ)); return res; } - ~C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ() { C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_free(self); } - C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ& operator=(C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ&& o) { C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ)); return *this; } - LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* operator &() { return &self; } - LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* operator ->() { return &self; } - const LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* operator &() const { return &self; } - const LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* operator ->() const { return &self; } -}; -class CResult_InitDecodeErrorZ { -private: - LDKCResult_InitDecodeErrorZ self; -public: - CResult_InitDecodeErrorZ(const CResult_InitDecodeErrorZ&) = delete; - CResult_InitDecodeErrorZ(CResult_InitDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_InitDecodeErrorZ)); } - CResult_InitDecodeErrorZ(LDKCResult_InitDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_InitDecodeErrorZ)); } - operator LDKCResult_InitDecodeErrorZ() && { LDKCResult_InitDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_InitDecodeErrorZ)); return res; } - ~CResult_InitDecodeErrorZ() { CResult_InitDecodeErrorZ_free(self); } - CResult_InitDecodeErrorZ& operator=(CResult_InitDecodeErrorZ&& o) { CResult_InitDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_InitDecodeErrorZ)); return *this; } - LDKCResult_InitDecodeErrorZ* operator &() { return &self; } - LDKCResult_InitDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_InitDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_InitDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_OutPointDecodeErrorZ { -private: - LDKCResult_OutPointDecodeErrorZ self; -public: - CResult_OutPointDecodeErrorZ(const CResult_OutPointDecodeErrorZ&) = delete; - CResult_OutPointDecodeErrorZ(CResult_OutPointDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_OutPointDecodeErrorZ)); } - CResult_OutPointDecodeErrorZ(LDKCResult_OutPointDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_OutPointDecodeErrorZ)); } - operator LDKCResult_OutPointDecodeErrorZ() && { LDKCResult_OutPointDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_OutPointDecodeErrorZ)); return res; } - ~CResult_OutPointDecodeErrorZ() { CResult_OutPointDecodeErrorZ_free(self); } - CResult_OutPointDecodeErrorZ& operator=(CResult_OutPointDecodeErrorZ&& o) { CResult_OutPointDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_OutPointDecodeErrorZ)); return *this; } - LDKCResult_OutPointDecodeErrorZ* operator &() { return &self; } - LDKCResult_OutPointDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_OutPointDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_OutPointDecodeErrorZ* operator ->() const { return &self; } -}; -class CVec_ChannelDetailsZ { -private: - LDKCVec_ChannelDetailsZ self; -public: - CVec_ChannelDetailsZ(const CVec_ChannelDetailsZ&) = delete; - CVec_ChannelDetailsZ(CVec_ChannelDetailsZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_ChannelDetailsZ)); } - CVec_ChannelDetailsZ(LDKCVec_ChannelDetailsZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_ChannelDetailsZ)); } - operator LDKCVec_ChannelDetailsZ() && { LDKCVec_ChannelDetailsZ res = self; memset(&self, 0, sizeof(LDKCVec_ChannelDetailsZ)); return res; } - ~CVec_ChannelDetailsZ() { CVec_ChannelDetailsZ_free(self); } - CVec_ChannelDetailsZ& operator=(CVec_ChannelDetailsZ&& o) { CVec_ChannelDetailsZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_ChannelDetailsZ)); return *this; } - LDKCVec_ChannelDetailsZ* operator &() { return &self; } - LDKCVec_ChannelDetailsZ* operator ->() { return &self; } - const LDKCVec_ChannelDetailsZ* operator &() const { return &self; } - const LDKCVec_ChannelDetailsZ* operator ->() const { return &self; } -}; -class CResult_SignDecodeErrorZ { -private: - LDKCResult_SignDecodeErrorZ self; -public: - CResult_SignDecodeErrorZ(const CResult_SignDecodeErrorZ&) = delete; - CResult_SignDecodeErrorZ(CResult_SignDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_SignDecodeErrorZ)); } - CResult_SignDecodeErrorZ(LDKCResult_SignDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_SignDecodeErrorZ)); } - operator LDKCResult_SignDecodeErrorZ() && { LDKCResult_SignDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_SignDecodeErrorZ)); return res; } - ~CResult_SignDecodeErrorZ() { CResult_SignDecodeErrorZ_free(self); } - CResult_SignDecodeErrorZ& operator=(CResult_SignDecodeErrorZ&& o) { CResult_SignDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_SignDecodeErrorZ)); return *this; } - LDKCResult_SignDecodeErrorZ* operator &() { return &self; } - LDKCResult_SignDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_SignDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_SignDecodeErrorZ* operator ->() const { return &self; } -}; -class CVec_MessageSendEventZ { -private: - LDKCVec_MessageSendEventZ self; -public: - CVec_MessageSendEventZ(const CVec_MessageSendEventZ&) = delete; - CVec_MessageSendEventZ(CVec_MessageSendEventZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_MessageSendEventZ)); } - CVec_MessageSendEventZ(LDKCVec_MessageSendEventZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_MessageSendEventZ)); } - operator LDKCVec_MessageSendEventZ() && { LDKCVec_MessageSendEventZ res = self; memset(&self, 0, sizeof(LDKCVec_MessageSendEventZ)); return res; } - ~CVec_MessageSendEventZ() { CVec_MessageSendEventZ_free(self); } - CVec_MessageSendEventZ& operator=(CVec_MessageSendEventZ&& o) { CVec_MessageSendEventZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_MessageSendEventZ)); return *this; } - LDKCVec_MessageSendEventZ* operator &() { return &self; } - LDKCVec_MessageSendEventZ* operator ->() { return &self; } - const LDKCVec_MessageSendEventZ* operator &() const { return &self; } - const LDKCVec_MessageSendEventZ* operator ->() const { return &self; } -}; -class CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ { -private: - LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ self; -public: - CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ(const CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ&) = delete; - CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ(CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ)); } - CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ(LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ)); } - operator LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ() && { LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ res = self; memset(&self, 0, sizeof(LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ)); return res; } - ~CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ() { CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free(self); } - CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ& operator=(CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ&& o) { CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ)); return *this; } - LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ* operator &() { return &self; } - LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ* operator ->() { return &self; } - const LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ* operator &() const { return &self; } - const LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ* operator ->() const { return &self; } -}; -class C2Tuple_OutPointScriptZ { -private: - LDKC2Tuple_OutPointScriptZ self; -public: - C2Tuple_OutPointScriptZ(const C2Tuple_OutPointScriptZ&) = delete; - C2Tuple_OutPointScriptZ(C2Tuple_OutPointScriptZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_OutPointScriptZ)); } - C2Tuple_OutPointScriptZ(LDKC2Tuple_OutPointScriptZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_OutPointScriptZ)); } - operator LDKC2Tuple_OutPointScriptZ() && { LDKC2Tuple_OutPointScriptZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_OutPointScriptZ)); return res; } - ~C2Tuple_OutPointScriptZ() { C2Tuple_OutPointScriptZ_free(self); } - C2Tuple_OutPointScriptZ& operator=(C2Tuple_OutPointScriptZ&& o) { C2Tuple_OutPointScriptZ_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_OutPointScriptZ)); return *this; } - LDKC2Tuple_OutPointScriptZ* operator &() { return &self; } - LDKC2Tuple_OutPointScriptZ* operator ->() { return &self; } - const LDKC2Tuple_OutPointScriptZ* operator &() const { return &self; } - const LDKC2Tuple_OutPointScriptZ* operator ->() const { return &self; } -}; -class CResult_UpdateFailMalformedHTLCDecodeErrorZ { -private: - LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ self; -public: - CResult_UpdateFailMalformedHTLCDecodeErrorZ(const CResult_UpdateFailMalformedHTLCDecodeErrorZ&) = delete; - CResult_UpdateFailMalformedHTLCDecodeErrorZ(CResult_UpdateFailMalformedHTLCDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_UpdateFailMalformedHTLCDecodeErrorZ)); } - CResult_UpdateFailMalformedHTLCDecodeErrorZ(LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ)); } - operator LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ() && { LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ)); return res; } - ~CResult_UpdateFailMalformedHTLCDecodeErrorZ() { CResult_UpdateFailMalformedHTLCDecodeErrorZ_free(self); } - CResult_UpdateFailMalformedHTLCDecodeErrorZ& operator=(CResult_UpdateFailMalformedHTLCDecodeErrorZ&& o) { CResult_UpdateFailMalformedHTLCDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_UpdateFailMalformedHTLCDecodeErrorZ)); return *this; } - LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ* operator &() { return &self; } - LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_UpdateFailMalformedHTLCDecodeErrorZ* operator ->() const { return &self; } -}; -class CVec_NodeAnnouncementZ { -private: - LDKCVec_NodeAnnouncementZ self; -public: - CVec_NodeAnnouncementZ(const CVec_NodeAnnouncementZ&) = delete; - CVec_NodeAnnouncementZ(CVec_NodeAnnouncementZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_NodeAnnouncementZ)); } - CVec_NodeAnnouncementZ(LDKCVec_NodeAnnouncementZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_NodeAnnouncementZ)); } - operator LDKCVec_NodeAnnouncementZ() && { LDKCVec_NodeAnnouncementZ res = self; memset(&self, 0, sizeof(LDKCVec_NodeAnnouncementZ)); return res; } - ~CVec_NodeAnnouncementZ() { CVec_NodeAnnouncementZ_free(self); } - CVec_NodeAnnouncementZ& operator=(CVec_NodeAnnouncementZ&& o) { CVec_NodeAnnouncementZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_NodeAnnouncementZ)); return *this; } - LDKCVec_NodeAnnouncementZ* operator &() { return &self; } - LDKCVec_NodeAnnouncementZ* operator ->() { return &self; } - const LDKCVec_NodeAnnouncementZ* operator &() const { return &self; } - const LDKCVec_NodeAnnouncementZ* operator ->() const { return &self; } -}; -class CResult_UnsignedChannelAnnouncementDecodeErrorZ { -private: - LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ self; -public: - CResult_UnsignedChannelAnnouncementDecodeErrorZ(const CResult_UnsignedChannelAnnouncementDecodeErrorZ&) = delete; - CResult_UnsignedChannelAnnouncementDecodeErrorZ(CResult_UnsignedChannelAnnouncementDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_UnsignedChannelAnnouncementDecodeErrorZ)); } - CResult_UnsignedChannelAnnouncementDecodeErrorZ(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ)); } - operator LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ() && { LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ)); return res; } - ~CResult_UnsignedChannelAnnouncementDecodeErrorZ() { CResult_UnsignedChannelAnnouncementDecodeErrorZ_free(self); } - CResult_UnsignedChannelAnnouncementDecodeErrorZ& operator=(CResult_UnsignedChannelAnnouncementDecodeErrorZ&& o) { CResult_UnsignedChannelAnnouncementDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_UnsignedChannelAnnouncementDecodeErrorZ)); return *this; } - LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* operator &() { return &self; } - LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_PongDecodeErrorZ { -private: - LDKCResult_PongDecodeErrorZ self; -public: - CResult_PongDecodeErrorZ(const CResult_PongDecodeErrorZ&) = delete; - CResult_PongDecodeErrorZ(CResult_PongDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PongDecodeErrorZ)); } - CResult_PongDecodeErrorZ(LDKCResult_PongDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PongDecodeErrorZ)); } - operator LDKCResult_PongDecodeErrorZ() && { LDKCResult_PongDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_PongDecodeErrorZ)); return res; } - ~CResult_PongDecodeErrorZ() { CResult_PongDecodeErrorZ_free(self); } - CResult_PongDecodeErrorZ& operator=(CResult_PongDecodeErrorZ&& o) { CResult_PongDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PongDecodeErrorZ)); return *this; } - LDKCResult_PongDecodeErrorZ* operator &() { return &self; } - LDKCResult_PongDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_PongDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_PongDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_NoneMonitorUpdateErrorZ { -private: - LDKCResult_NoneMonitorUpdateErrorZ self; -public: - CResult_NoneMonitorUpdateErrorZ(const CResult_NoneMonitorUpdateErrorZ&) = delete; - CResult_NoneMonitorUpdateErrorZ(CResult_NoneMonitorUpdateErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneMonitorUpdateErrorZ)); } - CResult_NoneMonitorUpdateErrorZ(LDKCResult_NoneMonitorUpdateErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneMonitorUpdateErrorZ)); } - operator LDKCResult_NoneMonitorUpdateErrorZ() && { LDKCResult_NoneMonitorUpdateErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneMonitorUpdateErrorZ)); return res; } - ~CResult_NoneMonitorUpdateErrorZ() { CResult_NoneMonitorUpdateErrorZ_free(self); } - CResult_NoneMonitorUpdateErrorZ& operator=(CResult_NoneMonitorUpdateErrorZ&& o) { CResult_NoneMonitorUpdateErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NoneMonitorUpdateErrorZ)); return *this; } - LDKCResult_NoneMonitorUpdateErrorZ* operator &() { return &self; } - LDKCResult_NoneMonitorUpdateErrorZ* operator ->() { return &self; } - const LDKCResult_NoneMonitorUpdateErrorZ* operator &() const { return &self; } - const LDKCResult_NoneMonitorUpdateErrorZ* operator ->() const { return &self; } -}; -class CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { -private: - LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ self; -public: - CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ(const CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ&) = delete; - CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ(CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ)); } - CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ)); } - operator LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ() && { LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ res = self; memset(&self, 0, sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ)); return res; } - ~CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ() { CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(self); } - CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ& operator=(CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ&& o) { CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ)); return *this; } - LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* operator &() { return &self; } - LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* operator ->() { return &self; } - const LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* operator &() const { return &self; } - const LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* operator ->() const { return &self; } -}; -class CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ { -private: - LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ self; -public: - CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ(const CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ&) = delete; - CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ(CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ)); } - CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ(LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ)); } - operator LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ() && { LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ res = self; memset(&self, 0, sizeof(LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ)); return res; } - ~CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ() { CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(self); } - CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ& operator=(CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ&& o) { CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ)); return *this; } - LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ* operator &() { return &self; } - LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ* operator ->() { return &self; } - const LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ* operator &() const { return &self; } - const LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ* operator ->() const { return &self; } -}; -class CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ { -private: - LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ self; -public: - CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ(const CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ&) = delete; - CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ(CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ)); } - CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ)); } - operator LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ() && { LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ)); return res; } - ~CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ() { CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(self); } - CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ& operator=(CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ&& o) { CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ)); return *this; } - LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* operator &() { return &self; } - LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_CVec_CVec_u8ZZNoneZ { -private: - LDKCResult_CVec_CVec_u8ZZNoneZ self; -public: - CResult_CVec_CVec_u8ZZNoneZ(const CResult_CVec_CVec_u8ZZNoneZ&) = delete; - CResult_CVec_CVec_u8ZZNoneZ(CResult_CVec_CVec_u8ZZNoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_CVec_CVec_u8ZZNoneZ)); } - CResult_CVec_CVec_u8ZZNoneZ(LDKCResult_CVec_CVec_u8ZZNoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_CVec_CVec_u8ZZNoneZ)); } - operator LDKCResult_CVec_CVec_u8ZZNoneZ() && { LDKCResult_CVec_CVec_u8ZZNoneZ res = self; memset(&self, 0, sizeof(LDKCResult_CVec_CVec_u8ZZNoneZ)); return res; } - ~CResult_CVec_CVec_u8ZZNoneZ() { CResult_CVec_CVec_u8ZZNoneZ_free(self); } - CResult_CVec_CVec_u8ZZNoneZ& operator=(CResult_CVec_CVec_u8ZZNoneZ&& o) { CResult_CVec_CVec_u8ZZNoneZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_CVec_CVec_u8ZZNoneZ)); return *this; } - LDKCResult_CVec_CVec_u8ZZNoneZ* operator &() { return &self; } - LDKCResult_CVec_CVec_u8ZZNoneZ* operator ->() { return &self; } - const LDKCResult_CVec_CVec_u8ZZNoneZ* operator &() const { return &self; } - const LDKCResult_CVec_CVec_u8ZZNoneZ* operator ->() const { return &self; } -}; -class CResult_AcceptChannelDecodeErrorZ { -private: - LDKCResult_AcceptChannelDecodeErrorZ self; -public: - CResult_AcceptChannelDecodeErrorZ(const CResult_AcceptChannelDecodeErrorZ&) = delete; - CResult_AcceptChannelDecodeErrorZ(CResult_AcceptChannelDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_AcceptChannelDecodeErrorZ)); } - CResult_AcceptChannelDecodeErrorZ(LDKCResult_AcceptChannelDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_AcceptChannelDecodeErrorZ)); } - operator LDKCResult_AcceptChannelDecodeErrorZ() && { LDKCResult_AcceptChannelDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_AcceptChannelDecodeErrorZ)); return res; } - ~CResult_AcceptChannelDecodeErrorZ() { CResult_AcceptChannelDecodeErrorZ_free(self); } - CResult_AcceptChannelDecodeErrorZ& operator=(CResult_AcceptChannelDecodeErrorZ&& o) { CResult_AcceptChannelDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_AcceptChannelDecodeErrorZ)); return *this; } - LDKCResult_AcceptChannelDecodeErrorZ* operator &() { return &self; } - LDKCResult_AcceptChannelDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_AcceptChannelDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_AcceptChannelDecodeErrorZ* operator ->() const { return &self; } -}; -class C2Tuple_BlockHashChannelManagerZ { -private: - LDKC2Tuple_BlockHashChannelManagerZ self; -public: - C2Tuple_BlockHashChannelManagerZ(const C2Tuple_BlockHashChannelManagerZ&) = delete; - C2Tuple_BlockHashChannelManagerZ(C2Tuple_BlockHashChannelManagerZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_BlockHashChannelManagerZ)); } - C2Tuple_BlockHashChannelManagerZ(LDKC2Tuple_BlockHashChannelManagerZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_BlockHashChannelManagerZ)); } - operator LDKC2Tuple_BlockHashChannelManagerZ() && { LDKC2Tuple_BlockHashChannelManagerZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_BlockHashChannelManagerZ)); return res; } - ~C2Tuple_BlockHashChannelManagerZ() { C2Tuple_BlockHashChannelManagerZ_free(self); } - C2Tuple_BlockHashChannelManagerZ& operator=(C2Tuple_BlockHashChannelManagerZ&& o) { C2Tuple_BlockHashChannelManagerZ_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_BlockHashChannelManagerZ)); return *this; } - LDKC2Tuple_BlockHashChannelManagerZ* operator &() { return &self; } - LDKC2Tuple_BlockHashChannelManagerZ* operator ->() { return &self; } - const LDKC2Tuple_BlockHashChannelManagerZ* operator &() const { return &self; } - const LDKC2Tuple_BlockHashChannelManagerZ* operator ->() const { return &self; } -}; -class CResult_ChannelTransactionParametersDecodeErrorZ { -private: - LDKCResult_ChannelTransactionParametersDecodeErrorZ self; -public: - CResult_ChannelTransactionParametersDecodeErrorZ(const CResult_ChannelTransactionParametersDecodeErrorZ&) = delete; - CResult_ChannelTransactionParametersDecodeErrorZ(CResult_ChannelTransactionParametersDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ChannelTransactionParametersDecodeErrorZ)); } - CResult_ChannelTransactionParametersDecodeErrorZ(LDKCResult_ChannelTransactionParametersDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ChannelTransactionParametersDecodeErrorZ)); } - operator LDKCResult_ChannelTransactionParametersDecodeErrorZ() && { LDKCResult_ChannelTransactionParametersDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ChannelTransactionParametersDecodeErrorZ)); return res; } - ~CResult_ChannelTransactionParametersDecodeErrorZ() { CResult_ChannelTransactionParametersDecodeErrorZ_free(self); } - CResult_ChannelTransactionParametersDecodeErrorZ& operator=(CResult_ChannelTransactionParametersDecodeErrorZ&& o) { CResult_ChannelTransactionParametersDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ChannelTransactionParametersDecodeErrorZ)); return *this; } - LDKCResult_ChannelTransactionParametersDecodeErrorZ* operator &() { return &self; } - LDKCResult_ChannelTransactionParametersDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ChannelTransactionParametersDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ChannelTransactionParametersDecodeErrorZ* operator ->() const { return &self; } -}; -class CVec_SignatureZ { -private: - LDKCVec_SignatureZ self; -public: - CVec_SignatureZ(const CVec_SignatureZ&) = delete; - CVec_SignatureZ(CVec_SignatureZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_SignatureZ)); } - CVec_SignatureZ(LDKCVec_SignatureZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_SignatureZ)); } - operator LDKCVec_SignatureZ() && { LDKCVec_SignatureZ res = self; memset(&self, 0, sizeof(LDKCVec_SignatureZ)); return res; } - ~CVec_SignatureZ() { CVec_SignatureZ_free(self); } - CVec_SignatureZ& operator=(CVec_SignatureZ&& o) { CVec_SignatureZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_SignatureZ)); return *this; } - LDKCVec_SignatureZ* operator &() { return &self; } - LDKCVec_SignatureZ* operator ->() { return &self; } - const LDKCVec_SignatureZ* operator &() const { return &self; } - const LDKCVec_SignatureZ* operator ->() const { return &self; } -}; -class CVec_u64Z { -private: - LDKCVec_u64Z self; -public: - CVec_u64Z(const CVec_u64Z&) = delete; - CVec_u64Z(CVec_u64Z&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_u64Z)); } - CVec_u64Z(LDKCVec_u64Z&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_u64Z)); } - operator LDKCVec_u64Z() && { LDKCVec_u64Z res = self; memset(&self, 0, sizeof(LDKCVec_u64Z)); return res; } - ~CVec_u64Z() { CVec_u64Z_free(self); } - CVec_u64Z& operator=(CVec_u64Z&& o) { CVec_u64Z_free(self); self = o.self; memset(&o, 0, sizeof(CVec_u64Z)); return *this; } - LDKCVec_u64Z* operator &() { return &self; } - LDKCVec_u64Z* operator ->() { return &self; } - const LDKCVec_u64Z* operator &() const { return &self; } - const LDKCVec_u64Z* operator ->() const { return &self; } -}; -class CVec_RouteHintZ { -private: - LDKCVec_RouteHintZ self; -public: - CVec_RouteHintZ(const CVec_RouteHintZ&) = delete; - CVec_RouteHintZ(CVec_RouteHintZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_RouteHintZ)); } - CVec_RouteHintZ(LDKCVec_RouteHintZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_RouteHintZ)); } - operator LDKCVec_RouteHintZ() && { LDKCVec_RouteHintZ res = self; memset(&self, 0, sizeof(LDKCVec_RouteHintZ)); return res; } - ~CVec_RouteHintZ() { CVec_RouteHintZ_free(self); } - CVec_RouteHintZ& operator=(CVec_RouteHintZ&& o) { CVec_RouteHintZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_RouteHintZ)); return *this; } - LDKCVec_RouteHintZ* operator &() { return &self; } - LDKCVec_RouteHintZ* operator ->() { return &self; } - const LDKCVec_RouteHintZ* operator &() const { return &self; } - const LDKCVec_RouteHintZ* operator ->() const { return &self; } -}; -class CVec_CVec_RouteHopZZ { -private: - LDKCVec_CVec_RouteHopZZ self; -public: - CVec_CVec_RouteHopZZ(const CVec_CVec_RouteHopZZ&) = delete; - CVec_CVec_RouteHopZZ(CVec_CVec_RouteHopZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_CVec_RouteHopZZ)); } - CVec_CVec_RouteHopZZ(LDKCVec_CVec_RouteHopZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_CVec_RouteHopZZ)); } - operator LDKCVec_CVec_RouteHopZZ() && { LDKCVec_CVec_RouteHopZZ res = self; memset(&self, 0, sizeof(LDKCVec_CVec_RouteHopZZ)); return res; } - ~CVec_CVec_RouteHopZZ() { CVec_CVec_RouteHopZZ_free(self); } - CVec_CVec_RouteHopZZ& operator=(CVec_CVec_RouteHopZZ&& o) { CVec_CVec_RouteHopZZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_CVec_RouteHopZZ)); return *this; } - LDKCVec_CVec_RouteHopZZ* operator &() { return &self; } - LDKCVec_CVec_RouteHopZZ* operator ->() { return &self; } - const LDKCVec_CVec_RouteHopZZ* operator &() const { return &self; } - const LDKCVec_CVec_RouteHopZZ* operator ->() const { return &self; } -}; -class CResult_TrustedCommitmentTransactionNoneZ { -private: - LDKCResult_TrustedCommitmentTransactionNoneZ self; -public: - CResult_TrustedCommitmentTransactionNoneZ(const CResult_TrustedCommitmentTransactionNoneZ&) = delete; - CResult_TrustedCommitmentTransactionNoneZ(CResult_TrustedCommitmentTransactionNoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_TrustedCommitmentTransactionNoneZ)); } - CResult_TrustedCommitmentTransactionNoneZ(LDKCResult_TrustedCommitmentTransactionNoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ)); } - operator LDKCResult_TrustedCommitmentTransactionNoneZ() && { LDKCResult_TrustedCommitmentTransactionNoneZ res = self; memset(&self, 0, sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ)); return res; } - ~CResult_TrustedCommitmentTransactionNoneZ() { CResult_TrustedCommitmentTransactionNoneZ_free(self); } - CResult_TrustedCommitmentTransactionNoneZ& operator=(CResult_TrustedCommitmentTransactionNoneZ&& o) { CResult_TrustedCommitmentTransactionNoneZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_TrustedCommitmentTransactionNoneZ)); return *this; } - LDKCResult_TrustedCommitmentTransactionNoneZ* operator &() { return &self; } - LDKCResult_TrustedCommitmentTransactionNoneZ* operator ->() { return &self; } - const LDKCResult_TrustedCommitmentTransactionNoneZ* operator &() const { return &self; } - const LDKCResult_TrustedCommitmentTransactionNoneZ* operator ->() const { return &self; } -}; -class CResult_NoneLightningErrorZ { -private: - LDKCResult_NoneLightningErrorZ self; -public: - CResult_NoneLightningErrorZ(const CResult_NoneLightningErrorZ&) = delete; - CResult_NoneLightningErrorZ(CResult_NoneLightningErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneLightningErrorZ)); } - CResult_NoneLightningErrorZ(LDKCResult_NoneLightningErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneLightningErrorZ)); } - operator LDKCResult_NoneLightningErrorZ() && { LDKCResult_NoneLightningErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneLightningErrorZ)); return res; } - ~CResult_NoneLightningErrorZ() { CResult_NoneLightningErrorZ_free(self); } - CResult_NoneLightningErrorZ& operator=(CResult_NoneLightningErrorZ&& o) { CResult_NoneLightningErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NoneLightningErrorZ)); return *this; } - LDKCResult_NoneLightningErrorZ* operator &() { return &self; } - LDKCResult_NoneLightningErrorZ* operator ->() { return &self; } - const LDKCResult_NoneLightningErrorZ* operator &() const { return &self; } - const LDKCResult_NoneLightningErrorZ* operator ->() const { return &self; } -}; -class CResult_NonePeerHandleErrorZ { -private: - LDKCResult_NonePeerHandleErrorZ self; -public: - CResult_NonePeerHandleErrorZ(const CResult_NonePeerHandleErrorZ&) = delete; - CResult_NonePeerHandleErrorZ(CResult_NonePeerHandleErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NonePeerHandleErrorZ)); } - CResult_NonePeerHandleErrorZ(LDKCResult_NonePeerHandleErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NonePeerHandleErrorZ)); } - operator LDKCResult_NonePeerHandleErrorZ() && { LDKCResult_NonePeerHandleErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NonePeerHandleErrorZ)); return res; } - ~CResult_NonePeerHandleErrorZ() { CResult_NonePeerHandleErrorZ_free(self); } - CResult_NonePeerHandleErrorZ& operator=(CResult_NonePeerHandleErrorZ&& o) { CResult_NonePeerHandleErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NonePeerHandleErrorZ)); return *this; } - LDKCResult_NonePeerHandleErrorZ* operator &() { return &self; } - LDKCResult_NonePeerHandleErrorZ* operator ->() { return &self; } - const LDKCResult_NonePeerHandleErrorZ* operator &() const { return &self; } - const LDKCResult_NonePeerHandleErrorZ* operator ->() const { return &self; } -}; -class CResult_CVec_SignatureZNoneZ { -private: - LDKCResult_CVec_SignatureZNoneZ self; -public: - CResult_CVec_SignatureZNoneZ(const CResult_CVec_SignatureZNoneZ&) = delete; - CResult_CVec_SignatureZNoneZ(CResult_CVec_SignatureZNoneZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_CVec_SignatureZNoneZ)); } - CResult_CVec_SignatureZNoneZ(LDKCResult_CVec_SignatureZNoneZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_CVec_SignatureZNoneZ)); } - operator LDKCResult_CVec_SignatureZNoneZ() && { LDKCResult_CVec_SignatureZNoneZ res = self; memset(&self, 0, sizeof(LDKCResult_CVec_SignatureZNoneZ)); return res; } - ~CResult_CVec_SignatureZNoneZ() { CResult_CVec_SignatureZNoneZ_free(self); } - CResult_CVec_SignatureZNoneZ& operator=(CResult_CVec_SignatureZNoneZ&& o) { CResult_CVec_SignatureZNoneZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_CVec_SignatureZNoneZ)); return *this; } - LDKCResult_CVec_SignatureZNoneZ* operator &() { return &self; } - LDKCResult_CVec_SignatureZNoneZ* operator ->() { return &self; } - const LDKCResult_CVec_SignatureZNoneZ* operator &() const { return &self; } - const LDKCResult_CVec_SignatureZNoneZ* operator ->() const { return &self; } -}; -class CResult_RoutingFeesDecodeErrorZ { -private: - LDKCResult_RoutingFeesDecodeErrorZ self; -public: - CResult_RoutingFeesDecodeErrorZ(const CResult_RoutingFeesDecodeErrorZ&) = delete; - CResult_RoutingFeesDecodeErrorZ(CResult_RoutingFeesDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_RoutingFeesDecodeErrorZ)); } - CResult_RoutingFeesDecodeErrorZ(LDKCResult_RoutingFeesDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_RoutingFeesDecodeErrorZ)); } - operator LDKCResult_RoutingFeesDecodeErrorZ() && { LDKCResult_RoutingFeesDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_RoutingFeesDecodeErrorZ)); return res; } - ~CResult_RoutingFeesDecodeErrorZ() { CResult_RoutingFeesDecodeErrorZ_free(self); } - CResult_RoutingFeesDecodeErrorZ& operator=(CResult_RoutingFeesDecodeErrorZ&& o) { CResult_RoutingFeesDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_RoutingFeesDecodeErrorZ)); return *this; } - LDKCResult_RoutingFeesDecodeErrorZ* operator &() { return &self; } - LDKCResult_RoutingFeesDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_RoutingFeesDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_RoutingFeesDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_QueryShortChannelIdsDecodeErrorZ { -private: - LDKCResult_QueryShortChannelIdsDecodeErrorZ self; -public: - CResult_QueryShortChannelIdsDecodeErrorZ(const CResult_QueryShortChannelIdsDecodeErrorZ&) = delete; - CResult_QueryShortChannelIdsDecodeErrorZ(CResult_QueryShortChannelIdsDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_QueryShortChannelIdsDecodeErrorZ)); } - CResult_QueryShortChannelIdsDecodeErrorZ(LDKCResult_QueryShortChannelIdsDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ)); } - operator LDKCResult_QueryShortChannelIdsDecodeErrorZ() && { LDKCResult_QueryShortChannelIdsDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ)); return res; } - ~CResult_QueryShortChannelIdsDecodeErrorZ() { CResult_QueryShortChannelIdsDecodeErrorZ_free(self); } - CResult_QueryShortChannelIdsDecodeErrorZ& operator=(CResult_QueryShortChannelIdsDecodeErrorZ&& o) { CResult_QueryShortChannelIdsDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_QueryShortChannelIdsDecodeErrorZ)); return *this; } - LDKCResult_QueryShortChannelIdsDecodeErrorZ* operator &() { return &self; } - LDKCResult_QueryShortChannelIdsDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_QueryShortChannelIdsDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_QueryShortChannelIdsDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_UpdateAddHTLCDecodeErrorZ { -private: - LDKCResult_UpdateAddHTLCDecodeErrorZ self; -public: - CResult_UpdateAddHTLCDecodeErrorZ(const CResult_UpdateAddHTLCDecodeErrorZ&) = delete; - CResult_UpdateAddHTLCDecodeErrorZ(CResult_UpdateAddHTLCDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_UpdateAddHTLCDecodeErrorZ)); } - CResult_UpdateAddHTLCDecodeErrorZ(LDKCResult_UpdateAddHTLCDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_UpdateAddHTLCDecodeErrorZ)); } - operator LDKCResult_UpdateAddHTLCDecodeErrorZ() && { LDKCResult_UpdateAddHTLCDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_UpdateAddHTLCDecodeErrorZ)); return res; } - ~CResult_UpdateAddHTLCDecodeErrorZ() { CResult_UpdateAddHTLCDecodeErrorZ_free(self); } - CResult_UpdateAddHTLCDecodeErrorZ& operator=(CResult_UpdateAddHTLCDecodeErrorZ&& o) { CResult_UpdateAddHTLCDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_UpdateAddHTLCDecodeErrorZ)); return *this; } - LDKCResult_UpdateAddHTLCDecodeErrorZ* operator &() { return &self; } - LDKCResult_UpdateAddHTLCDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_UpdateAddHTLCDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_UpdateAddHTLCDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_CounterpartyChannelTransactionParametersDecodeErrorZ { -private: - LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ self; -public: - CResult_CounterpartyChannelTransactionParametersDecodeErrorZ(const CResult_CounterpartyChannelTransactionParametersDecodeErrorZ&) = delete; - CResult_CounterpartyChannelTransactionParametersDecodeErrorZ(CResult_CounterpartyChannelTransactionParametersDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_CounterpartyChannelTransactionParametersDecodeErrorZ)); } - CResult_CounterpartyChannelTransactionParametersDecodeErrorZ(LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ)); } - operator LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ() && { LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ)); return res; } - ~CResult_CounterpartyChannelTransactionParametersDecodeErrorZ() { CResult_CounterpartyChannelTransactionParametersDecodeErrorZ_free(self); } - CResult_CounterpartyChannelTransactionParametersDecodeErrorZ& operator=(CResult_CounterpartyChannelTransactionParametersDecodeErrorZ&& o) { CResult_CounterpartyChannelTransactionParametersDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_CounterpartyChannelTransactionParametersDecodeErrorZ)); return *this; } - LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ* operator &() { return &self; } - LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_NoneAPIErrorZ { -private: - LDKCResult_NoneAPIErrorZ self; -public: - CResult_NoneAPIErrorZ(const CResult_NoneAPIErrorZ&) = delete; - CResult_NoneAPIErrorZ(CResult_NoneAPIErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneAPIErrorZ)); } - CResult_NoneAPIErrorZ(LDKCResult_NoneAPIErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneAPIErrorZ)); } - operator LDKCResult_NoneAPIErrorZ() && { LDKCResult_NoneAPIErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneAPIErrorZ)); return res; } - ~CResult_NoneAPIErrorZ() { CResult_NoneAPIErrorZ_free(self); } - CResult_NoneAPIErrorZ& operator=(CResult_NoneAPIErrorZ&& o) { CResult_NoneAPIErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NoneAPIErrorZ)); return *this; } - LDKCResult_NoneAPIErrorZ* operator &() { return &self; } - LDKCResult_NoneAPIErrorZ* operator ->() { return &self; } - const LDKCResult_NoneAPIErrorZ* operator &() const { return &self; } - const LDKCResult_NoneAPIErrorZ* operator ->() const { return &self; } -}; -class CVec_NetAddressZ { -private: - LDKCVec_NetAddressZ self; -public: - CVec_NetAddressZ(const CVec_NetAddressZ&) = delete; - CVec_NetAddressZ(CVec_NetAddressZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_NetAddressZ)); } - CVec_NetAddressZ(LDKCVec_NetAddressZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_NetAddressZ)); } - operator LDKCVec_NetAddressZ() && { LDKCVec_NetAddressZ res = self; memset(&self, 0, sizeof(LDKCVec_NetAddressZ)); return res; } - ~CVec_NetAddressZ() { CVec_NetAddressZ_free(self); } - CVec_NetAddressZ& operator=(CVec_NetAddressZ&& o) { CVec_NetAddressZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_NetAddressZ)); return *this; } - LDKCVec_NetAddressZ* operator &() { return &self; } - LDKCVec_NetAddressZ* operator ->() { return &self; } - const LDKCVec_NetAddressZ* operator &() const { return &self; } - const LDKCVec_NetAddressZ* operator ->() const { return &self; } -}; -class CVec_PublicKeyZ { -private: - LDKCVec_PublicKeyZ self; -public: - CVec_PublicKeyZ(const CVec_PublicKeyZ&) = delete; - CVec_PublicKeyZ(CVec_PublicKeyZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_PublicKeyZ)); } - CVec_PublicKeyZ(LDKCVec_PublicKeyZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_PublicKeyZ)); } - operator LDKCVec_PublicKeyZ() && { LDKCVec_PublicKeyZ res = self; memset(&self, 0, sizeof(LDKCVec_PublicKeyZ)); return res; } - ~CVec_PublicKeyZ() { CVec_PublicKeyZ_free(self); } - CVec_PublicKeyZ& operator=(CVec_PublicKeyZ&& o) { CVec_PublicKeyZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_PublicKeyZ)); return *this; } - LDKCVec_PublicKeyZ* operator &() { return &self; } - LDKCVec_PublicKeyZ* operator ->() { return &self; } - const LDKCVec_PublicKeyZ* operator &() const { return &self; } - const LDKCVec_PublicKeyZ* operator ->() const { return &self; } -}; -class CVec_C2Tuple_usizeTransactionZZ { -private: - LDKCVec_C2Tuple_usizeTransactionZZ self; -public: - CVec_C2Tuple_usizeTransactionZZ(const CVec_C2Tuple_usizeTransactionZZ&) = delete; - CVec_C2Tuple_usizeTransactionZZ(CVec_C2Tuple_usizeTransactionZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_C2Tuple_usizeTransactionZZ)); } - CVec_C2Tuple_usizeTransactionZZ(LDKCVec_C2Tuple_usizeTransactionZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_C2Tuple_usizeTransactionZZ)); } - operator LDKCVec_C2Tuple_usizeTransactionZZ() && { LDKCVec_C2Tuple_usizeTransactionZZ res = self; memset(&self, 0, sizeof(LDKCVec_C2Tuple_usizeTransactionZZ)); return res; } - ~CVec_C2Tuple_usizeTransactionZZ() { CVec_C2Tuple_usizeTransactionZZ_free(self); } - CVec_C2Tuple_usizeTransactionZZ& operator=(CVec_C2Tuple_usizeTransactionZZ&& o) { CVec_C2Tuple_usizeTransactionZZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_C2Tuple_usizeTransactionZZ)); return *this; } - LDKCVec_C2Tuple_usizeTransactionZZ* operator &() { return &self; } - LDKCVec_C2Tuple_usizeTransactionZZ* operator ->() { return &self; } - const LDKCVec_C2Tuple_usizeTransactionZZ* operator &() const { return &self; } - const LDKCVec_C2Tuple_usizeTransactionZZ* operator ->() const { return &self; } -}; -class CResult_DirectionalChannelInfoDecodeErrorZ { -private: - LDKCResult_DirectionalChannelInfoDecodeErrorZ self; -public: - CResult_DirectionalChannelInfoDecodeErrorZ(const CResult_DirectionalChannelInfoDecodeErrorZ&) = delete; - CResult_DirectionalChannelInfoDecodeErrorZ(CResult_DirectionalChannelInfoDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_DirectionalChannelInfoDecodeErrorZ)); } - CResult_DirectionalChannelInfoDecodeErrorZ(LDKCResult_DirectionalChannelInfoDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_DirectionalChannelInfoDecodeErrorZ)); } - operator LDKCResult_DirectionalChannelInfoDecodeErrorZ() && { LDKCResult_DirectionalChannelInfoDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_DirectionalChannelInfoDecodeErrorZ)); return res; } - ~CResult_DirectionalChannelInfoDecodeErrorZ() { CResult_DirectionalChannelInfoDecodeErrorZ_free(self); } - CResult_DirectionalChannelInfoDecodeErrorZ& operator=(CResult_DirectionalChannelInfoDecodeErrorZ&& o) { CResult_DirectionalChannelInfoDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_DirectionalChannelInfoDecodeErrorZ)); return *this; } - LDKCResult_DirectionalChannelInfoDecodeErrorZ* operator &() { return &self; } - LDKCResult_DirectionalChannelInfoDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_DirectionalChannelInfoDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_DirectionalChannelInfoDecodeErrorZ* operator ->() const { return &self; } -}; -class C2Tuple_u32TxOutZ { -private: - LDKC2Tuple_u32TxOutZ self; -public: - C2Tuple_u32TxOutZ(const C2Tuple_u32TxOutZ&) = delete; - C2Tuple_u32TxOutZ(C2Tuple_u32TxOutZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_u32TxOutZ)); } - C2Tuple_u32TxOutZ(LDKC2Tuple_u32TxOutZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_u32TxOutZ)); } - operator LDKC2Tuple_u32TxOutZ() && { LDKC2Tuple_u32TxOutZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_u32TxOutZ)); return res; } - ~C2Tuple_u32TxOutZ() { C2Tuple_u32TxOutZ_free(self); } - C2Tuple_u32TxOutZ& operator=(C2Tuple_u32TxOutZ&& o) { C2Tuple_u32TxOutZ_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_u32TxOutZ)); return *this; } - LDKC2Tuple_u32TxOutZ* operator &() { return &self; } - LDKC2Tuple_u32TxOutZ* operator ->() { return &self; } - const LDKC2Tuple_u32TxOutZ* operator &() const { return &self; } - const LDKC2Tuple_u32TxOutZ* operator ->() const { return &self; } -}; -class CResult_UpdateFailHTLCDecodeErrorZ { -private: - LDKCResult_UpdateFailHTLCDecodeErrorZ self; -public: - CResult_UpdateFailHTLCDecodeErrorZ(const CResult_UpdateFailHTLCDecodeErrorZ&) = delete; - CResult_UpdateFailHTLCDecodeErrorZ(CResult_UpdateFailHTLCDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_UpdateFailHTLCDecodeErrorZ)); } - CResult_UpdateFailHTLCDecodeErrorZ(LDKCResult_UpdateFailHTLCDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_UpdateFailHTLCDecodeErrorZ)); } - operator LDKCResult_UpdateFailHTLCDecodeErrorZ() && { LDKCResult_UpdateFailHTLCDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_UpdateFailHTLCDecodeErrorZ)); return res; } - ~CResult_UpdateFailHTLCDecodeErrorZ() { CResult_UpdateFailHTLCDecodeErrorZ_free(self); } - CResult_UpdateFailHTLCDecodeErrorZ& operator=(CResult_UpdateFailHTLCDecodeErrorZ&& o) { CResult_UpdateFailHTLCDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_UpdateFailHTLCDecodeErrorZ)); return *this; } - LDKCResult_UpdateFailHTLCDecodeErrorZ* operator &() { return &self; } - LDKCResult_UpdateFailHTLCDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_UpdateFailHTLCDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_UpdateFailHTLCDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_ChannelConfigDecodeErrorZ { -private: - LDKCResult_ChannelConfigDecodeErrorZ self; -public: - CResult_ChannelConfigDecodeErrorZ(const CResult_ChannelConfigDecodeErrorZ&) = delete; - CResult_ChannelConfigDecodeErrorZ(CResult_ChannelConfigDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ChannelConfigDecodeErrorZ)); } - CResult_ChannelConfigDecodeErrorZ(LDKCResult_ChannelConfigDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ChannelConfigDecodeErrorZ)); } - operator LDKCResult_ChannelConfigDecodeErrorZ() && { LDKCResult_ChannelConfigDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ChannelConfigDecodeErrorZ)); return res; } - ~CResult_ChannelConfigDecodeErrorZ() { CResult_ChannelConfigDecodeErrorZ_free(self); } - CResult_ChannelConfigDecodeErrorZ& operator=(CResult_ChannelConfigDecodeErrorZ&& o) { CResult_ChannelConfigDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ChannelConfigDecodeErrorZ)); return *this; } - LDKCResult_ChannelConfigDecodeErrorZ* operator &() { return &self; } - LDKCResult_ChannelConfigDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ChannelConfigDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ChannelConfigDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_RevokeAndACKDecodeErrorZ { -private: - LDKCResult_RevokeAndACKDecodeErrorZ self; -public: - CResult_RevokeAndACKDecodeErrorZ(const CResult_RevokeAndACKDecodeErrorZ&) = delete; - CResult_RevokeAndACKDecodeErrorZ(CResult_RevokeAndACKDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_RevokeAndACKDecodeErrorZ)); } - CResult_RevokeAndACKDecodeErrorZ(LDKCResult_RevokeAndACKDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_RevokeAndACKDecodeErrorZ)); } - operator LDKCResult_RevokeAndACKDecodeErrorZ() && { LDKCResult_RevokeAndACKDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_RevokeAndACKDecodeErrorZ)); return res; } - ~CResult_RevokeAndACKDecodeErrorZ() { CResult_RevokeAndACKDecodeErrorZ_free(self); } - CResult_RevokeAndACKDecodeErrorZ& operator=(CResult_RevokeAndACKDecodeErrorZ&& o) { CResult_RevokeAndACKDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_RevokeAndACKDecodeErrorZ)); return *this; } - LDKCResult_RevokeAndACKDecodeErrorZ* operator &() { return &self; } - LDKCResult_RevokeAndACKDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_RevokeAndACKDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_RevokeAndACKDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_SpendableOutputDescriptorDecodeErrorZ { -private: - LDKCResult_SpendableOutputDescriptorDecodeErrorZ self; -public: - CResult_SpendableOutputDescriptorDecodeErrorZ(const CResult_SpendableOutputDescriptorDecodeErrorZ&) = delete; - CResult_SpendableOutputDescriptorDecodeErrorZ(CResult_SpendableOutputDescriptorDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_SpendableOutputDescriptorDecodeErrorZ)); } - CResult_SpendableOutputDescriptorDecodeErrorZ(LDKCResult_SpendableOutputDescriptorDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ)); } - operator LDKCResult_SpendableOutputDescriptorDecodeErrorZ() && { LDKCResult_SpendableOutputDescriptorDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ)); return res; } - ~CResult_SpendableOutputDescriptorDecodeErrorZ() { CResult_SpendableOutputDescriptorDecodeErrorZ_free(self); } - CResult_SpendableOutputDescriptorDecodeErrorZ& operator=(CResult_SpendableOutputDescriptorDecodeErrorZ&& o) { CResult_SpendableOutputDescriptorDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_SpendableOutputDescriptorDecodeErrorZ)); return *this; } - LDKCResult_SpendableOutputDescriptorDecodeErrorZ* operator &() { return &self; } - LDKCResult_SpendableOutputDescriptorDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_SpendableOutputDescriptorDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_SpendableOutputDescriptorDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_UnsignedChannelUpdateDecodeErrorZ { -private: - LDKCResult_UnsignedChannelUpdateDecodeErrorZ self; -public: - CResult_UnsignedChannelUpdateDecodeErrorZ(const CResult_UnsignedChannelUpdateDecodeErrorZ&) = delete; - CResult_UnsignedChannelUpdateDecodeErrorZ(CResult_UnsignedChannelUpdateDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_UnsignedChannelUpdateDecodeErrorZ)); } - CResult_UnsignedChannelUpdateDecodeErrorZ(LDKCResult_UnsignedChannelUpdateDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ)); } - operator LDKCResult_UnsignedChannelUpdateDecodeErrorZ() && { LDKCResult_UnsignedChannelUpdateDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ)); return res; } - ~CResult_UnsignedChannelUpdateDecodeErrorZ() { CResult_UnsignedChannelUpdateDecodeErrorZ_free(self); } - CResult_UnsignedChannelUpdateDecodeErrorZ& operator=(CResult_UnsignedChannelUpdateDecodeErrorZ&& o) { CResult_UnsignedChannelUpdateDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_UnsignedChannelUpdateDecodeErrorZ)); return *this; } - LDKCResult_UnsignedChannelUpdateDecodeErrorZ* operator &() { return &self; } - LDKCResult_UnsignedChannelUpdateDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_UnsignedChannelUpdateDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_UnsignedChannelUpdateDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_ShutdownDecodeErrorZ { -private: - LDKCResult_ShutdownDecodeErrorZ self; -public: - CResult_ShutdownDecodeErrorZ(const CResult_ShutdownDecodeErrorZ&) = delete; - CResult_ShutdownDecodeErrorZ(CResult_ShutdownDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ShutdownDecodeErrorZ)); } - CResult_ShutdownDecodeErrorZ(LDKCResult_ShutdownDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ShutdownDecodeErrorZ)); } - operator LDKCResult_ShutdownDecodeErrorZ() && { LDKCResult_ShutdownDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ShutdownDecodeErrorZ)); return res; } - ~CResult_ShutdownDecodeErrorZ() { CResult_ShutdownDecodeErrorZ_free(self); } - CResult_ShutdownDecodeErrorZ& operator=(CResult_ShutdownDecodeErrorZ&& o) { CResult_ShutdownDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ShutdownDecodeErrorZ)); return *this; } - LDKCResult_ShutdownDecodeErrorZ* operator &() { return &self; } - LDKCResult_ShutdownDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ShutdownDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ShutdownDecodeErrorZ* operator ->() const { return &self; } -}; -class CVec_EventZ { -private: - LDKCVec_EventZ self; -public: - CVec_EventZ(const CVec_EventZ&) = delete; - CVec_EventZ(CVec_EventZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_EventZ)); } - CVec_EventZ(LDKCVec_EventZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_EventZ)); } - operator LDKCVec_EventZ() && { LDKCVec_EventZ res = self; memset(&self, 0, sizeof(LDKCVec_EventZ)); return res; } - ~CVec_EventZ() { CVec_EventZ_free(self); } - CVec_EventZ& operator=(CVec_EventZ&& o) { CVec_EventZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_EventZ)); return *this; } - LDKCVec_EventZ* operator &() { return &self; } - LDKCVec_EventZ* operator ->() { return &self; } - const LDKCVec_EventZ* operator &() const { return &self; } - const LDKCVec_EventZ* operator ->() const { return &self; } -}; -class CVec_MonitorEventZ { -private: - LDKCVec_MonitorEventZ self; -public: - CVec_MonitorEventZ(const CVec_MonitorEventZ&) = delete; - CVec_MonitorEventZ(CVec_MonitorEventZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_MonitorEventZ)); } - CVec_MonitorEventZ(LDKCVec_MonitorEventZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_MonitorEventZ)); } - operator LDKCVec_MonitorEventZ() && { LDKCVec_MonitorEventZ res = self; memset(&self, 0, sizeof(LDKCVec_MonitorEventZ)); return res; } - ~CVec_MonitorEventZ() { CVec_MonitorEventZ_free(self); } - CVec_MonitorEventZ& operator=(CVec_MonitorEventZ&& o) { CVec_MonitorEventZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_MonitorEventZ)); return *this; } - LDKCVec_MonitorEventZ* operator &() { return &self; } - LDKCVec_MonitorEventZ* operator ->() { return &self; } - const LDKCVec_MonitorEventZ* operator &() const { return &self; } - const LDKCVec_MonitorEventZ* operator ->() const { return &self; } -}; -class CResult_NoneChannelMonitorUpdateErrZ { -private: - LDKCResult_NoneChannelMonitorUpdateErrZ self; -public: - CResult_NoneChannelMonitorUpdateErrZ(const CResult_NoneChannelMonitorUpdateErrZ&) = delete; - CResult_NoneChannelMonitorUpdateErrZ(CResult_NoneChannelMonitorUpdateErrZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneChannelMonitorUpdateErrZ)); } - CResult_NoneChannelMonitorUpdateErrZ(LDKCResult_NoneChannelMonitorUpdateErrZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ)); } - operator LDKCResult_NoneChannelMonitorUpdateErrZ() && { LDKCResult_NoneChannelMonitorUpdateErrZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ)); return res; } - ~CResult_NoneChannelMonitorUpdateErrZ() { CResult_NoneChannelMonitorUpdateErrZ_free(self); } - CResult_NoneChannelMonitorUpdateErrZ& operator=(CResult_NoneChannelMonitorUpdateErrZ&& o) { CResult_NoneChannelMonitorUpdateErrZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NoneChannelMonitorUpdateErrZ)); return *this; } - LDKCResult_NoneChannelMonitorUpdateErrZ* operator &() { return &self; } - LDKCResult_NoneChannelMonitorUpdateErrZ* operator ->() { return &self; } - const LDKCResult_NoneChannelMonitorUpdateErrZ* operator &() const { return &self; } - const LDKCResult_NoneChannelMonitorUpdateErrZ* operator ->() const { return &self; } -}; -class CResult_PublicKeyErrorZ { -private: - LDKCResult_PublicKeyErrorZ self; -public: - CResult_PublicKeyErrorZ(const CResult_PublicKeyErrorZ&) = delete; - CResult_PublicKeyErrorZ(CResult_PublicKeyErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_PublicKeyErrorZ)); } - CResult_PublicKeyErrorZ(LDKCResult_PublicKeyErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_PublicKeyErrorZ)); } - operator LDKCResult_PublicKeyErrorZ() && { LDKCResult_PublicKeyErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_PublicKeyErrorZ)); return res; } - ~CResult_PublicKeyErrorZ() { CResult_PublicKeyErrorZ_free(self); } - CResult_PublicKeyErrorZ& operator=(CResult_PublicKeyErrorZ&& o) { CResult_PublicKeyErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_PublicKeyErrorZ)); return *this; } - LDKCResult_PublicKeyErrorZ* operator &() { return &self; } - LDKCResult_PublicKeyErrorZ* operator ->() { return &self; } - const LDKCResult_PublicKeyErrorZ* operator &() const { return &self; } - const LDKCResult_PublicKeyErrorZ* operator ->() const { return &self; } -}; -class C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ { -private: - LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ self; -public: - C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ(const C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ&) = delete; - C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ(C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ&& o) : self(o.self) { memset(&o, 0, sizeof(C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ)); } - C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ)); } - operator LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ() && { LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ res = self; memset(&self, 0, sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ)); return res; } - ~C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ() { C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(self); } - C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ& operator=(C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ&& o) { C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(self); self = o.self; memset(&o, 0, sizeof(C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ)); return *this; } - LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* operator &() { return &self; } - LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* operator ->() { return &self; } - const LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* operator &() const { return &self; } - const LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* operator ->() const { return &self; } -}; -class CResult_boolPeerHandleErrorZ { -private: - LDKCResult_boolPeerHandleErrorZ self; -public: - CResult_boolPeerHandleErrorZ(const CResult_boolPeerHandleErrorZ&) = delete; - CResult_boolPeerHandleErrorZ(CResult_boolPeerHandleErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_boolPeerHandleErrorZ)); } - CResult_boolPeerHandleErrorZ(LDKCResult_boolPeerHandleErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_boolPeerHandleErrorZ)); } - operator LDKCResult_boolPeerHandleErrorZ() && { LDKCResult_boolPeerHandleErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_boolPeerHandleErrorZ)); return res; } - ~CResult_boolPeerHandleErrorZ() { CResult_boolPeerHandleErrorZ_free(self); } - CResult_boolPeerHandleErrorZ& operator=(CResult_boolPeerHandleErrorZ&& o) { CResult_boolPeerHandleErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_boolPeerHandleErrorZ)); return *this; } - LDKCResult_boolPeerHandleErrorZ* operator &() { return &self; } - LDKCResult_boolPeerHandleErrorZ* operator ->() { return &self; } - const LDKCResult_boolPeerHandleErrorZ* operator &() const { return &self; } - const LDKCResult_boolPeerHandleErrorZ* operator ->() const { return &self; } -}; -class CResult_ChannelUpdateDecodeErrorZ { -private: - LDKCResult_ChannelUpdateDecodeErrorZ self; -public: - CResult_ChannelUpdateDecodeErrorZ(const CResult_ChannelUpdateDecodeErrorZ&) = delete; - CResult_ChannelUpdateDecodeErrorZ(CResult_ChannelUpdateDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ChannelUpdateDecodeErrorZ)); } - CResult_ChannelUpdateDecodeErrorZ(LDKCResult_ChannelUpdateDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ChannelUpdateDecodeErrorZ)); } - operator LDKCResult_ChannelUpdateDecodeErrorZ() && { LDKCResult_ChannelUpdateDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ChannelUpdateDecodeErrorZ)); return res; } - ~CResult_ChannelUpdateDecodeErrorZ() { CResult_ChannelUpdateDecodeErrorZ_free(self); } - CResult_ChannelUpdateDecodeErrorZ& operator=(CResult_ChannelUpdateDecodeErrorZ&& o) { CResult_ChannelUpdateDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ChannelUpdateDecodeErrorZ)); return *this; } - LDKCResult_ChannelUpdateDecodeErrorZ* operator &() { return &self; } - LDKCResult_ChannelUpdateDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ChannelUpdateDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ChannelUpdateDecodeErrorZ* operator ->() const { return &self; } -}; -class CVec_APIErrorZ { -private: - LDKCVec_APIErrorZ self; -public: - CVec_APIErrorZ(const CVec_APIErrorZ&) = delete; - CVec_APIErrorZ(CVec_APIErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_APIErrorZ)); } - CVec_APIErrorZ(LDKCVec_APIErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_APIErrorZ)); } - operator LDKCVec_APIErrorZ() && { LDKCVec_APIErrorZ res = self; memset(&self, 0, sizeof(LDKCVec_APIErrorZ)); return res; } - ~CVec_APIErrorZ() { CVec_APIErrorZ_free(self); } - CVec_APIErrorZ& operator=(CVec_APIErrorZ&& o) { CVec_APIErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_APIErrorZ)); return *this; } - LDKCVec_APIErrorZ* operator &() { return &self; } - LDKCVec_APIErrorZ* operator ->() { return &self; } - const LDKCVec_APIErrorZ* operator &() const { return &self; } - const LDKCVec_APIErrorZ* operator ->() const { return &self; } -}; -class CVec_UpdateFulfillHTLCZ { -private: - LDKCVec_UpdateFulfillHTLCZ self; -public: - CVec_UpdateFulfillHTLCZ(const CVec_UpdateFulfillHTLCZ&) = delete; - CVec_UpdateFulfillHTLCZ(CVec_UpdateFulfillHTLCZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_UpdateFulfillHTLCZ)); } - CVec_UpdateFulfillHTLCZ(LDKCVec_UpdateFulfillHTLCZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_UpdateFulfillHTLCZ)); } - operator LDKCVec_UpdateFulfillHTLCZ() && { LDKCVec_UpdateFulfillHTLCZ res = self; memset(&self, 0, sizeof(LDKCVec_UpdateFulfillHTLCZ)); return res; } - ~CVec_UpdateFulfillHTLCZ() { CVec_UpdateFulfillHTLCZ_free(self); } - CVec_UpdateFulfillHTLCZ& operator=(CVec_UpdateFulfillHTLCZ&& o) { CVec_UpdateFulfillHTLCZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_UpdateFulfillHTLCZ)); return *this; } - LDKCVec_UpdateFulfillHTLCZ* operator &() { return &self; } - LDKCVec_UpdateFulfillHTLCZ* operator ->() { return &self; } - const LDKCVec_UpdateFulfillHTLCZ* operator &() const { return &self; } - const LDKCVec_UpdateFulfillHTLCZ* operator ->() const { return &self; } -}; -class CResult_AnnouncementSignaturesDecodeErrorZ { -private: - LDKCResult_AnnouncementSignaturesDecodeErrorZ self; -public: - CResult_AnnouncementSignaturesDecodeErrorZ(const CResult_AnnouncementSignaturesDecodeErrorZ&) = delete; - CResult_AnnouncementSignaturesDecodeErrorZ(CResult_AnnouncementSignaturesDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_AnnouncementSignaturesDecodeErrorZ)); } - CResult_AnnouncementSignaturesDecodeErrorZ(LDKCResult_AnnouncementSignaturesDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_AnnouncementSignaturesDecodeErrorZ)); } - operator LDKCResult_AnnouncementSignaturesDecodeErrorZ() && { LDKCResult_AnnouncementSignaturesDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_AnnouncementSignaturesDecodeErrorZ)); return res; } - ~CResult_AnnouncementSignaturesDecodeErrorZ() { CResult_AnnouncementSignaturesDecodeErrorZ_free(self); } - CResult_AnnouncementSignaturesDecodeErrorZ& operator=(CResult_AnnouncementSignaturesDecodeErrorZ&& o) { CResult_AnnouncementSignaturesDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_AnnouncementSignaturesDecodeErrorZ)); return *this; } - LDKCResult_AnnouncementSignaturesDecodeErrorZ* operator &() { return &self; } - LDKCResult_AnnouncementSignaturesDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_AnnouncementSignaturesDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_AnnouncementSignaturesDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_UpdateFulfillHTLCDecodeErrorZ { -private: - LDKCResult_UpdateFulfillHTLCDecodeErrorZ self; -public: - CResult_UpdateFulfillHTLCDecodeErrorZ(const CResult_UpdateFulfillHTLCDecodeErrorZ&) = delete; - CResult_UpdateFulfillHTLCDecodeErrorZ(CResult_UpdateFulfillHTLCDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_UpdateFulfillHTLCDecodeErrorZ)); } - CResult_UpdateFulfillHTLCDecodeErrorZ(LDKCResult_UpdateFulfillHTLCDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_UpdateFulfillHTLCDecodeErrorZ)); } - operator LDKCResult_UpdateFulfillHTLCDecodeErrorZ() && { LDKCResult_UpdateFulfillHTLCDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_UpdateFulfillHTLCDecodeErrorZ)); return res; } - ~CResult_UpdateFulfillHTLCDecodeErrorZ() { CResult_UpdateFulfillHTLCDecodeErrorZ_free(self); } - CResult_UpdateFulfillHTLCDecodeErrorZ& operator=(CResult_UpdateFulfillHTLCDecodeErrorZ&& o) { CResult_UpdateFulfillHTLCDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_UpdateFulfillHTLCDecodeErrorZ)); return *this; } - LDKCResult_UpdateFulfillHTLCDecodeErrorZ* operator &() { return &self; } - LDKCResult_UpdateFulfillHTLCDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_UpdateFulfillHTLCDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_UpdateFulfillHTLCDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_NodeFeaturesDecodeErrorZ { -private: - LDKCResult_NodeFeaturesDecodeErrorZ self; -public: - CResult_NodeFeaturesDecodeErrorZ(const CResult_NodeFeaturesDecodeErrorZ&) = delete; - CResult_NodeFeaturesDecodeErrorZ(CResult_NodeFeaturesDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NodeFeaturesDecodeErrorZ)); } - CResult_NodeFeaturesDecodeErrorZ(LDKCResult_NodeFeaturesDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NodeFeaturesDecodeErrorZ)); } - operator LDKCResult_NodeFeaturesDecodeErrorZ() && { LDKCResult_NodeFeaturesDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NodeFeaturesDecodeErrorZ)); return res; } - ~CResult_NodeFeaturesDecodeErrorZ() { CResult_NodeFeaturesDecodeErrorZ_free(self); } - CResult_NodeFeaturesDecodeErrorZ& operator=(CResult_NodeFeaturesDecodeErrorZ&& o) { CResult_NodeFeaturesDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NodeFeaturesDecodeErrorZ)); return *this; } - LDKCResult_NodeFeaturesDecodeErrorZ* operator &() { return &self; } - LDKCResult_NodeFeaturesDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_NodeFeaturesDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_NodeFeaturesDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_InMemorySignerDecodeErrorZ { -private: - LDKCResult_InMemorySignerDecodeErrorZ self; -public: - CResult_InMemorySignerDecodeErrorZ(const CResult_InMemorySignerDecodeErrorZ&) = delete; - CResult_InMemorySignerDecodeErrorZ(CResult_InMemorySignerDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_InMemorySignerDecodeErrorZ)); } - CResult_InMemorySignerDecodeErrorZ(LDKCResult_InMemorySignerDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_InMemorySignerDecodeErrorZ)); } - operator LDKCResult_InMemorySignerDecodeErrorZ() && { LDKCResult_InMemorySignerDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_InMemorySignerDecodeErrorZ)); return res; } - ~CResult_InMemorySignerDecodeErrorZ() { CResult_InMemorySignerDecodeErrorZ_free(self); } - CResult_InMemorySignerDecodeErrorZ& operator=(CResult_InMemorySignerDecodeErrorZ&& o) { CResult_InMemorySignerDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_InMemorySignerDecodeErrorZ)); return *this; } - LDKCResult_InMemorySignerDecodeErrorZ* operator &() { return &self; } - LDKCResult_InMemorySignerDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_InMemorySignerDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_InMemorySignerDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_ReplyShortChannelIdsEndDecodeErrorZ { -private: - LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ self; -public: - CResult_ReplyShortChannelIdsEndDecodeErrorZ(const CResult_ReplyShortChannelIdsEndDecodeErrorZ&) = delete; - CResult_ReplyShortChannelIdsEndDecodeErrorZ(CResult_ReplyShortChannelIdsEndDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_ReplyShortChannelIdsEndDecodeErrorZ)); } - CResult_ReplyShortChannelIdsEndDecodeErrorZ(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ)); } - operator LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ() && { LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ)); return res; } - ~CResult_ReplyShortChannelIdsEndDecodeErrorZ() { CResult_ReplyShortChannelIdsEndDecodeErrorZ_free(self); } - CResult_ReplyShortChannelIdsEndDecodeErrorZ& operator=(CResult_ReplyShortChannelIdsEndDecodeErrorZ&& o) { CResult_ReplyShortChannelIdsEndDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_ReplyShortChannelIdsEndDecodeErrorZ)); return *this; } - LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* operator &() { return &self; } - LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_CResult_NetAddressu8ZDecodeErrorZ { -private: - LDKCResult_CResult_NetAddressu8ZDecodeErrorZ self; -public: - CResult_CResult_NetAddressu8ZDecodeErrorZ(const CResult_CResult_NetAddressu8ZDecodeErrorZ&) = delete; - CResult_CResult_NetAddressu8ZDecodeErrorZ(CResult_CResult_NetAddressu8ZDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_CResult_NetAddressu8ZDecodeErrorZ)); } - CResult_CResult_NetAddressu8ZDecodeErrorZ(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ)); } - operator LDKCResult_CResult_NetAddressu8ZDecodeErrorZ() && { LDKCResult_CResult_NetAddressu8ZDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ)); return res; } - ~CResult_CResult_NetAddressu8ZDecodeErrorZ() { CResult_CResult_NetAddressu8ZDecodeErrorZ_free(self); } - CResult_CResult_NetAddressu8ZDecodeErrorZ& operator=(CResult_CResult_NetAddressu8ZDecodeErrorZ&& o) { CResult_CResult_NetAddressu8ZDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_CResult_NetAddressu8ZDecodeErrorZ)); return *this; } - LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* operator &() { return &self; } - LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { -private: - LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ self; -public: - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(const CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&) = delete; - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); } - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); } - operator LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ() && { LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); return res; } - ~CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ() { CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(self); } - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ& operator=(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& o) { CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); return *this; } - LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator &() { return &self; } - LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_BuiltCommitmentTransactionDecodeErrorZ { -private: - LDKCResult_BuiltCommitmentTransactionDecodeErrorZ self; -public: - CResult_BuiltCommitmentTransactionDecodeErrorZ(const CResult_BuiltCommitmentTransactionDecodeErrorZ&) = delete; - CResult_BuiltCommitmentTransactionDecodeErrorZ(CResult_BuiltCommitmentTransactionDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_BuiltCommitmentTransactionDecodeErrorZ)); } - CResult_BuiltCommitmentTransactionDecodeErrorZ(LDKCResult_BuiltCommitmentTransactionDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_BuiltCommitmentTransactionDecodeErrorZ)); } - operator LDKCResult_BuiltCommitmentTransactionDecodeErrorZ() && { LDKCResult_BuiltCommitmentTransactionDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_BuiltCommitmentTransactionDecodeErrorZ)); return res; } - ~CResult_BuiltCommitmentTransactionDecodeErrorZ() { CResult_BuiltCommitmentTransactionDecodeErrorZ_free(self); } - CResult_BuiltCommitmentTransactionDecodeErrorZ& operator=(CResult_BuiltCommitmentTransactionDecodeErrorZ&& o) { CResult_BuiltCommitmentTransactionDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_BuiltCommitmentTransactionDecodeErrorZ)); return *this; } - LDKCResult_BuiltCommitmentTransactionDecodeErrorZ* operator &() { return &self; } - LDKCResult_BuiltCommitmentTransactionDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_BuiltCommitmentTransactionDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_BuiltCommitmentTransactionDecodeErrorZ* operator ->() const { return &self; } -}; -class CResult_RouteDecodeErrorZ { -private: - LDKCResult_RouteDecodeErrorZ self; -public: - CResult_RouteDecodeErrorZ(const CResult_RouteDecodeErrorZ&) = delete; - CResult_RouteDecodeErrorZ(CResult_RouteDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_RouteDecodeErrorZ)); } - CResult_RouteDecodeErrorZ(LDKCResult_RouteDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_RouteDecodeErrorZ)); } - operator LDKCResult_RouteDecodeErrorZ() && { LDKCResult_RouteDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_RouteDecodeErrorZ)); return res; } - ~CResult_RouteDecodeErrorZ() { CResult_RouteDecodeErrorZ_free(self); } - CResult_RouteDecodeErrorZ& operator=(CResult_RouteDecodeErrorZ&& o) { CResult_RouteDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_RouteDecodeErrorZ)); return *this; } - LDKCResult_RouteDecodeErrorZ* operator &() { return &self; } - LDKCResult_RouteDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_RouteDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_RouteDecodeErrorZ* operator ->() const { return &self; } -}; -class CVec_TxOutZ { -private: - LDKCVec_TxOutZ self; -public: - CVec_TxOutZ(const CVec_TxOutZ&) = delete; - CVec_TxOutZ(CVec_TxOutZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_TxOutZ)); } - CVec_TxOutZ(LDKCVec_TxOutZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_TxOutZ)); } - operator LDKCVec_TxOutZ() && { LDKCVec_TxOutZ res = self; memset(&self, 0, sizeof(LDKCVec_TxOutZ)); return res; } - ~CVec_TxOutZ() { CVec_TxOutZ_free(self); } - CVec_TxOutZ& operator=(CVec_TxOutZ&& o) { CVec_TxOutZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_TxOutZ)); return *this; } - LDKCVec_TxOutZ* operator &() { return &self; } - LDKCVec_TxOutZ* operator ->() { return &self; } - const LDKCVec_TxOutZ* operator &() const { return &self; } - const LDKCVec_TxOutZ* operator ->() const { return &self; } -}; -class CVec_UpdateFailHTLCZ { -private: - LDKCVec_UpdateFailHTLCZ self; -public: - CVec_UpdateFailHTLCZ(const CVec_UpdateFailHTLCZ&) = delete; - CVec_UpdateFailHTLCZ(CVec_UpdateFailHTLCZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_UpdateFailHTLCZ)); } - CVec_UpdateFailHTLCZ(LDKCVec_UpdateFailHTLCZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_UpdateFailHTLCZ)); } - operator LDKCVec_UpdateFailHTLCZ() && { LDKCVec_UpdateFailHTLCZ res = self; memset(&self, 0, sizeof(LDKCVec_UpdateFailHTLCZ)); return res; } - ~CVec_UpdateFailHTLCZ() { CVec_UpdateFailHTLCZ_free(self); } - CVec_UpdateFailHTLCZ& operator=(CVec_UpdateFailHTLCZ&& o) { CVec_UpdateFailHTLCZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_UpdateFailHTLCZ)); return *this; } - LDKCVec_UpdateFailHTLCZ* operator &() { return &self; } - LDKCVec_UpdateFailHTLCZ* operator ->() { return &self; } - const LDKCVec_UpdateFailHTLCZ* operator &() const { return &self; } - const LDKCVec_UpdateFailHTLCZ* operator ->() const { return &self; } -}; -class CResult_FundingLockedDecodeErrorZ { -private: - LDKCResult_FundingLockedDecodeErrorZ self; -public: - CResult_FundingLockedDecodeErrorZ(const CResult_FundingLockedDecodeErrorZ&) = delete; - CResult_FundingLockedDecodeErrorZ(CResult_FundingLockedDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_FundingLockedDecodeErrorZ)); } - CResult_FundingLockedDecodeErrorZ(LDKCResult_FundingLockedDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_FundingLockedDecodeErrorZ)); } - operator LDKCResult_FundingLockedDecodeErrorZ() && { LDKCResult_FundingLockedDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_FundingLockedDecodeErrorZ)); return res; } - ~CResult_FundingLockedDecodeErrorZ() { CResult_FundingLockedDecodeErrorZ_free(self); } - CResult_FundingLockedDecodeErrorZ& operator=(CResult_FundingLockedDecodeErrorZ&& o) { CResult_FundingLockedDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_FundingLockedDecodeErrorZ)); return *this; } - LDKCResult_FundingLockedDecodeErrorZ* operator &() { return &self; } - LDKCResult_FundingLockedDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_FundingLockedDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_FundingLockedDecodeErrorZ* operator ->() const { return &self; } -}; -} diff --git a/lightning-c-bindings/include/rust_types.h b/lightning-c-bindings/include/rust_types.h deleted file mode 100644 index 6d573e907..000000000 --- a/lightning-c-bindings/include/rust_types.h +++ /dev/null @@ -1,179 +0,0 @@ -#if defined(__GNUC__) -#define MUST_USE_STRUCT __attribute__((warn_unused)) -#define MUST_USE_RES __attribute__((warn_unused_result)) -#else -#define MUST_USE_STRUCT -#define MUST_USE_RES -#endif -#if defined(__clang__) -#define NONNULL_PTR _Nonnull -#else -#define NONNULL_PTR -#endif -struct nativeTxCreationKeysOpaque; -typedef struct nativeTxCreationKeysOpaque LDKnativeTxCreationKeys; -struct nativeChannelPublicKeysOpaque; -typedef struct nativeChannelPublicKeysOpaque LDKnativeChannelPublicKeys; -struct nativeHTLCOutputInCommitmentOpaque; -typedef struct nativeHTLCOutputInCommitmentOpaque LDKnativeHTLCOutputInCommitment; -struct nativeChannelTransactionParametersOpaque; -typedef struct nativeChannelTransactionParametersOpaque LDKnativeChannelTransactionParameters; -struct nativeCounterpartyChannelTransactionParametersOpaque; -typedef struct nativeCounterpartyChannelTransactionParametersOpaque LDKnativeCounterpartyChannelTransactionParameters; -struct nativeDirectedChannelTransactionParametersOpaque; -typedef struct nativeDirectedChannelTransactionParametersOpaque LDKnativeDirectedChannelTransactionParameters; -struct nativeHolderCommitmentTransactionOpaque; -typedef struct nativeHolderCommitmentTransactionOpaque LDKnativeHolderCommitmentTransaction; -struct nativeBuiltCommitmentTransactionOpaque; -typedef struct nativeBuiltCommitmentTransactionOpaque LDKnativeBuiltCommitmentTransaction; -struct nativeCommitmentTransactionOpaque; -typedef struct nativeCommitmentTransactionOpaque LDKnativeCommitmentTransaction; -struct nativeTrustedCommitmentTransactionOpaque; -typedef struct nativeTrustedCommitmentTransactionOpaque LDKnativeTrustedCommitmentTransaction; -struct nativeIgnoringMessageHandlerOpaque; -typedef struct nativeIgnoringMessageHandlerOpaque LDKnativeIgnoringMessageHandler; -struct nativeErroringMessageHandlerOpaque; -typedef struct nativeErroringMessageHandlerOpaque LDKnativeErroringMessageHandler; -struct nativeMessageHandlerOpaque; -typedef struct nativeMessageHandlerOpaque LDKnativeMessageHandler; -typedef struct LDKSocketDescriptor LDKSocketDescriptor; -struct nativePeerHandleErrorOpaque; -typedef struct nativePeerHandleErrorOpaque LDKnativePeerHandleError; -struct nativePeerManagerOpaque; -typedef struct nativePeerManagerOpaque LDKnativePeerManager; -struct nativeInitFeaturesOpaque; -typedef struct nativeInitFeaturesOpaque LDKnativeInitFeatures; -struct nativeNodeFeaturesOpaque; -typedef struct nativeNodeFeaturesOpaque LDKnativeNodeFeatures; -struct nativeChannelFeaturesOpaque; -typedef struct nativeChannelFeaturesOpaque LDKnativeChannelFeatures; -struct nativeChannelHandshakeConfigOpaque; -typedef struct nativeChannelHandshakeConfigOpaque LDKnativeChannelHandshakeConfig; -struct nativeChannelHandshakeLimitsOpaque; -typedef struct nativeChannelHandshakeLimitsOpaque LDKnativeChannelHandshakeLimits; -struct nativeChannelConfigOpaque; -typedef struct nativeChannelConfigOpaque LDKnativeChannelConfig; -struct nativeUserConfigOpaque; -typedef struct nativeUserConfigOpaque LDKnativeUserConfig; -struct nativeNetworkGraphOpaque; -typedef struct nativeNetworkGraphOpaque LDKnativeNetworkGraph; -struct nativeLockedNetworkGraphOpaque; -typedef struct nativeLockedNetworkGraphOpaque LDKnativeLockedNetworkGraph; -struct nativeNetGraphMsgHandlerOpaque; -typedef struct nativeNetGraphMsgHandlerOpaque LDKnativeNetGraphMsgHandler; -struct nativeDirectionalChannelInfoOpaque; -typedef struct nativeDirectionalChannelInfoOpaque LDKnativeDirectionalChannelInfo; -struct nativeChannelInfoOpaque; -typedef struct nativeChannelInfoOpaque LDKnativeChannelInfo; -struct nativeRoutingFeesOpaque; -typedef struct nativeRoutingFeesOpaque LDKnativeRoutingFees; -struct nativeNodeAnnouncementInfoOpaque; -typedef struct nativeNodeAnnouncementInfoOpaque LDKnativeNodeAnnouncementInfo; -struct nativeNodeInfoOpaque; -typedef struct nativeNodeInfoOpaque LDKnativeNodeInfo; -struct nativeChainMonitorOpaque; -typedef struct nativeChainMonitorOpaque LDKnativeChainMonitor; -struct nativeOutPointOpaque; -typedef struct nativeOutPointOpaque LDKnativeOutPoint; -struct nativeChannelMonitorUpdateOpaque; -typedef struct nativeChannelMonitorUpdateOpaque LDKnativeChannelMonitorUpdate; -struct nativeMonitorUpdateErrorOpaque; -typedef struct nativeMonitorUpdateErrorOpaque LDKnativeMonitorUpdateError; -struct nativeHTLCUpdateOpaque; -typedef struct nativeHTLCUpdateOpaque LDKnativeHTLCUpdate; -struct nativeChannelMonitorOpaque; -typedef struct nativeChannelMonitorOpaque LDKnativeChannelMonitor; -struct nativeChannelManagerOpaque; -typedef struct nativeChannelManagerOpaque LDKnativeChannelManager; -struct nativeChainParametersOpaque; -typedef struct nativeChainParametersOpaque LDKnativeChainParameters; -struct nativeChannelDetailsOpaque; -typedef struct nativeChannelDetailsOpaque LDKnativeChannelDetails; -struct nativeChannelManagerReadArgsOpaque; -typedef struct nativeChannelManagerReadArgsOpaque LDKnativeChannelManagerReadArgs; -struct nativeDelayedPaymentOutputDescriptorOpaque; -typedef struct nativeDelayedPaymentOutputDescriptorOpaque LDKnativeDelayedPaymentOutputDescriptor; -struct nativeStaticPaymentOutputDescriptorOpaque; -typedef struct nativeStaticPaymentOutputDescriptorOpaque LDKnativeStaticPaymentOutputDescriptor; -struct LDKSign; -typedef struct LDKSign LDKSign; -struct nativeInMemorySignerOpaque; -typedef struct nativeInMemorySignerOpaque LDKnativeInMemorySigner; -struct nativeKeysManagerOpaque; -typedef struct nativeKeysManagerOpaque LDKnativeKeysManager; -struct nativeRouteHopOpaque; -typedef struct nativeRouteHopOpaque LDKnativeRouteHop; -struct nativeRouteOpaque; -typedef struct nativeRouteOpaque LDKnativeRoute; -struct nativeRouteHintOpaque; -typedef struct nativeRouteHintOpaque LDKnativeRouteHint; -struct nativeDecodeErrorOpaque; -typedef struct nativeDecodeErrorOpaque LDKnativeDecodeError; -struct nativeInitOpaque; -typedef struct nativeInitOpaque LDKnativeInit; -struct nativeErrorMessageOpaque; -typedef struct nativeErrorMessageOpaque LDKnativeErrorMessage; -struct nativePingOpaque; -typedef struct nativePingOpaque LDKnativePing; -struct nativePongOpaque; -typedef struct nativePongOpaque LDKnativePong; -struct nativeOpenChannelOpaque; -typedef struct nativeOpenChannelOpaque LDKnativeOpenChannel; -struct nativeAcceptChannelOpaque; -typedef struct nativeAcceptChannelOpaque LDKnativeAcceptChannel; -struct nativeFundingCreatedOpaque; -typedef struct nativeFundingCreatedOpaque LDKnativeFundingCreated; -struct nativeFundingSignedOpaque; -typedef struct nativeFundingSignedOpaque LDKnativeFundingSigned; -struct nativeFundingLockedOpaque; -typedef struct nativeFundingLockedOpaque LDKnativeFundingLocked; -struct nativeShutdownOpaque; -typedef struct nativeShutdownOpaque LDKnativeShutdown; -struct nativeClosingSignedOpaque; -typedef struct nativeClosingSignedOpaque LDKnativeClosingSigned; -struct nativeUpdateAddHTLCOpaque; -typedef struct nativeUpdateAddHTLCOpaque LDKnativeUpdateAddHTLC; -struct nativeUpdateFulfillHTLCOpaque; -typedef struct nativeUpdateFulfillHTLCOpaque LDKnativeUpdateFulfillHTLC; -struct nativeUpdateFailHTLCOpaque; -typedef struct nativeUpdateFailHTLCOpaque LDKnativeUpdateFailHTLC; -struct nativeUpdateFailMalformedHTLCOpaque; -typedef struct nativeUpdateFailMalformedHTLCOpaque LDKnativeUpdateFailMalformedHTLC; -struct nativeCommitmentSignedOpaque; -typedef struct nativeCommitmentSignedOpaque LDKnativeCommitmentSigned; -struct nativeRevokeAndACKOpaque; -typedef struct nativeRevokeAndACKOpaque LDKnativeRevokeAndACK; -struct nativeUpdateFeeOpaque; -typedef struct nativeUpdateFeeOpaque LDKnativeUpdateFee; -struct nativeDataLossProtectOpaque; -typedef struct nativeDataLossProtectOpaque LDKnativeDataLossProtect; -struct nativeChannelReestablishOpaque; -typedef struct nativeChannelReestablishOpaque LDKnativeChannelReestablish; -struct nativeAnnouncementSignaturesOpaque; -typedef struct nativeAnnouncementSignaturesOpaque LDKnativeAnnouncementSignatures; -struct nativeUnsignedNodeAnnouncementOpaque; -typedef struct nativeUnsignedNodeAnnouncementOpaque LDKnativeUnsignedNodeAnnouncement; -struct nativeNodeAnnouncementOpaque; -typedef struct nativeNodeAnnouncementOpaque LDKnativeNodeAnnouncement; -struct nativeUnsignedChannelAnnouncementOpaque; -typedef struct nativeUnsignedChannelAnnouncementOpaque LDKnativeUnsignedChannelAnnouncement; -struct nativeChannelAnnouncementOpaque; -typedef struct nativeChannelAnnouncementOpaque LDKnativeChannelAnnouncement; -struct nativeUnsignedChannelUpdateOpaque; -typedef struct nativeUnsignedChannelUpdateOpaque LDKnativeUnsignedChannelUpdate; -struct nativeChannelUpdateOpaque; -typedef struct nativeChannelUpdateOpaque LDKnativeChannelUpdate; -struct nativeQueryChannelRangeOpaque; -typedef struct nativeQueryChannelRangeOpaque LDKnativeQueryChannelRange; -struct nativeReplyChannelRangeOpaque; -typedef struct nativeReplyChannelRangeOpaque LDKnativeReplyChannelRange; -struct nativeQueryShortChannelIdsOpaque; -typedef struct nativeQueryShortChannelIdsOpaque LDKnativeQueryShortChannelIds; -struct nativeReplyShortChannelIdsEndOpaque; -typedef struct nativeReplyShortChannelIdsEndOpaque LDKnativeReplyShortChannelIdsEnd; -struct nativeGossipTimestampFilterOpaque; -typedef struct nativeGossipTimestampFilterOpaque LDKnativeGossipTimestampFilter; -struct nativeLightningErrorOpaque; -typedef struct nativeLightningErrorOpaque LDKnativeLightningError; -struct nativeCommitmentUpdateOpaque; -typedef struct nativeCommitmentUpdateOpaque LDKnativeCommitmentUpdate; diff --git a/lightning-c-bindings/src/bitcoin/mod.rs b/lightning-c-bindings/src/bitcoin/mod.rs deleted file mode 100644 index a61610bd4..000000000 --- a/lightning-c-bindings/src/bitcoin/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod network; diff --git a/lightning-c-bindings/src/bitcoin/network.rs b/lightning-c-bindings/src/bitcoin/network.rs deleted file mode 100644 index 52cb2ce68..000000000 --- a/lightning-c-bindings/src/bitcoin/network.rs +++ /dev/null @@ -1,28 +0,0 @@ -use bitcoin::network::constants::Network as BitcoinNetwork; - -#[repr(C)] -pub enum Network { - Bitcoin, - Testnet, - Regtest, - Signet, -} - -impl Network { - pub(crate) fn into_bitcoin(&self) -> BitcoinNetwork { - match self { - Network::Bitcoin => BitcoinNetwork::Bitcoin, - Network::Testnet => BitcoinNetwork::Testnet, - Network::Regtest => BitcoinNetwork::Regtest, - Network::Signet => BitcoinNetwork::Signet, - } - } - pub(crate) fn from_bitcoin(net: BitcoinNetwork) -> Self { - match net { - BitcoinNetwork::Bitcoin => Network::Bitcoin, - BitcoinNetwork::Testnet => Network::Testnet, - BitcoinNetwork::Regtest => Network::Regtest, - BitcoinNetwork::Signet => Network::Signet, - } - } -} diff --git a/lightning-c-bindings/src/c_types/derived.rs b/lightning-c-bindings/src/c_types/derived.rs deleted file mode 100644 index c16f9a21c..000000000 --- a/lightning-c-bindings/src/c_types/derived.rs +++ /dev/null @@ -1,7149 +0,0 @@ -#[repr(C)] -pub union CResult_SecretKeyErrorZPtr { - pub result: *mut crate::c_types::SecretKey, - pub err: *mut crate::c_types::Secp256k1Error, -} -#[repr(C)] -pub struct CResult_SecretKeyErrorZ { - pub contents: CResult_SecretKeyErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_SecretKeyErrorZ_ok(o: crate::c_types::SecretKey) -> CResult_SecretKeyErrorZ { - CResult_SecretKeyErrorZ { - contents: CResult_SecretKeyErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_SecretKeyErrorZ_err(e: crate::c_types::Secp256k1Error) -> CResult_SecretKeyErrorZ { - CResult_SecretKeyErrorZ { - contents: CResult_SecretKeyErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_SecretKeyErrorZ_free(_res: CResult_SecretKeyErrorZ) { } -impl Drop for CResult_SecretKeyErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_SecretKeyErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_SecretKeyErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_SecretKeyErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -#[repr(C)] -pub union CResult_PublicKeyErrorZPtr { - pub result: *mut crate::c_types::PublicKey, - pub err: *mut crate::c_types::Secp256k1Error, -} -#[repr(C)] -pub struct CResult_PublicKeyErrorZ { - pub contents: CResult_PublicKeyErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_PublicKeyErrorZ_ok(o: crate::c_types::PublicKey) -> CResult_PublicKeyErrorZ { - CResult_PublicKeyErrorZ { - contents: CResult_PublicKeyErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_PublicKeyErrorZ_err(e: crate::c_types::Secp256k1Error) -> CResult_PublicKeyErrorZ { - CResult_PublicKeyErrorZ { - contents: CResult_PublicKeyErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_PublicKeyErrorZ_free(_res: CResult_PublicKeyErrorZ) { } -impl Drop for CResult_PublicKeyErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_PublicKeyErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_PublicKeyErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_PublicKeyErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -#[repr(C)] -pub union CResult_TxCreationKeysDecodeErrorZPtr { - pub result: *mut crate::ln::chan_utils::TxCreationKeys, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_TxCreationKeysDecodeErrorZ { - pub contents: CResult_TxCreationKeysDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_TxCreationKeysDecodeErrorZ_ok(o: crate::ln::chan_utils::TxCreationKeys) -> CResult_TxCreationKeysDecodeErrorZ { - CResult_TxCreationKeysDecodeErrorZ { - contents: CResult_TxCreationKeysDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_TxCreationKeysDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_TxCreationKeysDecodeErrorZ { - CResult_TxCreationKeysDecodeErrorZ { - contents: CResult_TxCreationKeysDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_TxCreationKeysDecodeErrorZ_free(_res: CResult_TxCreationKeysDecodeErrorZ) { } -impl Drop for CResult_TxCreationKeysDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_TxCreationKeysDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_TxCreationKeysDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_TxCreationKeysDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_TxCreationKeysDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_TxCreationKeysDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_TxCreationKeysDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_TxCreationKeysDecodeErrorZ_clone(orig: &CResult_TxCreationKeysDecodeErrorZ) -> CResult_TxCreationKeysDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_ChannelPublicKeysDecodeErrorZPtr { - pub result: *mut crate::ln::chan_utils::ChannelPublicKeys, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ChannelPublicKeysDecodeErrorZ { - pub contents: CResult_ChannelPublicKeysDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ChannelPublicKeysDecodeErrorZ_ok(o: crate::ln::chan_utils::ChannelPublicKeys) -> CResult_ChannelPublicKeysDecodeErrorZ { - CResult_ChannelPublicKeysDecodeErrorZ { - contents: CResult_ChannelPublicKeysDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelPublicKeysDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ChannelPublicKeysDecodeErrorZ { - CResult_ChannelPublicKeysDecodeErrorZ { - contents: CResult_ChannelPublicKeysDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelPublicKeysDecodeErrorZ_free(_res: CResult_ChannelPublicKeysDecodeErrorZ) { } -impl Drop for CResult_ChannelPublicKeysDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ChannelPublicKeysDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ChannelPublicKeysDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ChannelPublicKeysDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ChannelPublicKeysDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ChannelPublicKeysDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ChannelPublicKeysDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelPublicKeysDecodeErrorZ_clone(orig: &CResult_ChannelPublicKeysDecodeErrorZ) -> CResult_ChannelPublicKeysDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_TxCreationKeysErrorZPtr { - pub result: *mut crate::ln::chan_utils::TxCreationKeys, - pub err: *mut crate::c_types::Secp256k1Error, -} -#[repr(C)] -pub struct CResult_TxCreationKeysErrorZ { - pub contents: CResult_TxCreationKeysErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_TxCreationKeysErrorZ_ok(o: crate::ln::chan_utils::TxCreationKeys) -> CResult_TxCreationKeysErrorZ { - CResult_TxCreationKeysErrorZ { - contents: CResult_TxCreationKeysErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_TxCreationKeysErrorZ_err(e: crate::c_types::Secp256k1Error) -> CResult_TxCreationKeysErrorZ { - CResult_TxCreationKeysErrorZ { - contents: CResult_TxCreationKeysErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_TxCreationKeysErrorZ_free(_res: CResult_TxCreationKeysErrorZ) { } -impl Drop for CResult_TxCreationKeysErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_TxCreationKeysErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_TxCreationKeysErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_TxCreationKeysErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -#[repr(C)] -pub union CResult_HTLCOutputInCommitmentDecodeErrorZPtr { - pub result: *mut crate::ln::chan_utils::HTLCOutputInCommitment, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_HTLCOutputInCommitmentDecodeErrorZ { - pub contents: CResult_HTLCOutputInCommitmentDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_HTLCOutputInCommitmentDecodeErrorZ_ok(o: crate::ln::chan_utils::HTLCOutputInCommitment) -> CResult_HTLCOutputInCommitmentDecodeErrorZ { - CResult_HTLCOutputInCommitmentDecodeErrorZ { - contents: CResult_HTLCOutputInCommitmentDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_HTLCOutputInCommitmentDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_HTLCOutputInCommitmentDecodeErrorZ { - CResult_HTLCOutputInCommitmentDecodeErrorZ { - contents: CResult_HTLCOutputInCommitmentDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_HTLCOutputInCommitmentDecodeErrorZ_free(_res: CResult_HTLCOutputInCommitmentDecodeErrorZ) { } -impl Drop for CResult_HTLCOutputInCommitmentDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_HTLCOutputInCommitmentDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_HTLCOutputInCommitmentDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_HTLCOutputInCommitmentDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_HTLCOutputInCommitmentDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_HTLCOutputInCommitmentDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_HTLCOutputInCommitmentDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_HTLCOutputInCommitmentDecodeErrorZ_clone(orig: &CResult_HTLCOutputInCommitmentDecodeErrorZ) -> CResult_HTLCOutputInCommitmentDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_CounterpartyChannelTransactionParametersDecodeErrorZPtr { - pub result: *mut crate::ln::chan_utils::CounterpartyChannelTransactionParameters, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_CounterpartyChannelTransactionParametersDecodeErrorZ { - pub contents: CResult_CounterpartyChannelTransactionParametersDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_CounterpartyChannelTransactionParametersDecodeErrorZ_ok(o: crate::ln::chan_utils::CounterpartyChannelTransactionParameters) -> CResult_CounterpartyChannelTransactionParametersDecodeErrorZ { - CResult_CounterpartyChannelTransactionParametersDecodeErrorZ { - contents: CResult_CounterpartyChannelTransactionParametersDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_CounterpartyChannelTransactionParametersDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_CounterpartyChannelTransactionParametersDecodeErrorZ { - CResult_CounterpartyChannelTransactionParametersDecodeErrorZ { - contents: CResult_CounterpartyChannelTransactionParametersDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_CounterpartyChannelTransactionParametersDecodeErrorZ_free(_res: CResult_CounterpartyChannelTransactionParametersDecodeErrorZ) { } -impl Drop for CResult_CounterpartyChannelTransactionParametersDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_CounterpartyChannelTransactionParametersDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_CounterpartyChannelTransactionParametersDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_CounterpartyChannelTransactionParametersDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_CounterpartyChannelTransactionParametersDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_CounterpartyChannelTransactionParametersDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_CounterpartyChannelTransactionParametersDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_CounterpartyChannelTransactionParametersDecodeErrorZ_clone(orig: &CResult_CounterpartyChannelTransactionParametersDecodeErrorZ) -> CResult_CounterpartyChannelTransactionParametersDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_ChannelTransactionParametersDecodeErrorZPtr { - pub result: *mut crate::ln::chan_utils::ChannelTransactionParameters, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ChannelTransactionParametersDecodeErrorZ { - pub contents: CResult_ChannelTransactionParametersDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ChannelTransactionParametersDecodeErrorZ_ok(o: crate::ln::chan_utils::ChannelTransactionParameters) -> CResult_ChannelTransactionParametersDecodeErrorZ { - CResult_ChannelTransactionParametersDecodeErrorZ { - contents: CResult_ChannelTransactionParametersDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelTransactionParametersDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ChannelTransactionParametersDecodeErrorZ { - CResult_ChannelTransactionParametersDecodeErrorZ { - contents: CResult_ChannelTransactionParametersDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelTransactionParametersDecodeErrorZ_free(_res: CResult_ChannelTransactionParametersDecodeErrorZ) { } -impl Drop for CResult_ChannelTransactionParametersDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ChannelTransactionParametersDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ChannelTransactionParametersDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ChannelTransactionParametersDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ChannelTransactionParametersDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ChannelTransactionParametersDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ChannelTransactionParametersDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelTransactionParametersDecodeErrorZ_clone(orig: &CResult_ChannelTransactionParametersDecodeErrorZ) -> CResult_ChannelTransactionParametersDecodeErrorZ { orig.clone() } -#[repr(C)] -pub struct CVec_SignatureZ { - pub data: *mut crate::c_types::Signature, - pub datalen: usize -} -impl CVec_SignatureZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::Signature] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_SignatureZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_SignatureZ_free(_res: CVec_SignatureZ) { } -impl Drop for CVec_SignatureZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_SignatureZ { - 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 union CResult_HolderCommitmentTransactionDecodeErrorZPtr { - pub result: *mut crate::ln::chan_utils::HolderCommitmentTransaction, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_HolderCommitmentTransactionDecodeErrorZ { - pub contents: CResult_HolderCommitmentTransactionDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_HolderCommitmentTransactionDecodeErrorZ_ok(o: crate::ln::chan_utils::HolderCommitmentTransaction) -> CResult_HolderCommitmentTransactionDecodeErrorZ { - CResult_HolderCommitmentTransactionDecodeErrorZ { - contents: CResult_HolderCommitmentTransactionDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_HolderCommitmentTransactionDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_HolderCommitmentTransactionDecodeErrorZ { - CResult_HolderCommitmentTransactionDecodeErrorZ { - contents: CResult_HolderCommitmentTransactionDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_HolderCommitmentTransactionDecodeErrorZ_free(_res: CResult_HolderCommitmentTransactionDecodeErrorZ) { } -impl Drop for CResult_HolderCommitmentTransactionDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_HolderCommitmentTransactionDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_HolderCommitmentTransactionDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_HolderCommitmentTransactionDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_HolderCommitmentTransactionDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_HolderCommitmentTransactionDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_HolderCommitmentTransactionDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_HolderCommitmentTransactionDecodeErrorZ_clone(orig: &CResult_HolderCommitmentTransactionDecodeErrorZ) -> CResult_HolderCommitmentTransactionDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_BuiltCommitmentTransactionDecodeErrorZPtr { - pub result: *mut crate::ln::chan_utils::BuiltCommitmentTransaction, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_BuiltCommitmentTransactionDecodeErrorZ { - pub contents: CResult_BuiltCommitmentTransactionDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_BuiltCommitmentTransactionDecodeErrorZ_ok(o: crate::ln::chan_utils::BuiltCommitmentTransaction) -> CResult_BuiltCommitmentTransactionDecodeErrorZ { - CResult_BuiltCommitmentTransactionDecodeErrorZ { - contents: CResult_BuiltCommitmentTransactionDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_BuiltCommitmentTransactionDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_BuiltCommitmentTransactionDecodeErrorZ { - CResult_BuiltCommitmentTransactionDecodeErrorZ { - contents: CResult_BuiltCommitmentTransactionDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_BuiltCommitmentTransactionDecodeErrorZ_free(_res: CResult_BuiltCommitmentTransactionDecodeErrorZ) { } -impl Drop for CResult_BuiltCommitmentTransactionDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_BuiltCommitmentTransactionDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_BuiltCommitmentTransactionDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_BuiltCommitmentTransactionDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_BuiltCommitmentTransactionDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_BuiltCommitmentTransactionDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_BuiltCommitmentTransactionDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_BuiltCommitmentTransactionDecodeErrorZ_clone(orig: &CResult_BuiltCommitmentTransactionDecodeErrorZ) -> CResult_BuiltCommitmentTransactionDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_CommitmentTransactionDecodeErrorZPtr { - pub result: *mut crate::ln::chan_utils::CommitmentTransaction, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_CommitmentTransactionDecodeErrorZ { - pub contents: CResult_CommitmentTransactionDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_CommitmentTransactionDecodeErrorZ_ok(o: crate::ln::chan_utils::CommitmentTransaction) -> CResult_CommitmentTransactionDecodeErrorZ { - CResult_CommitmentTransactionDecodeErrorZ { - contents: CResult_CommitmentTransactionDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_CommitmentTransactionDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_CommitmentTransactionDecodeErrorZ { - CResult_CommitmentTransactionDecodeErrorZ { - contents: CResult_CommitmentTransactionDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_CommitmentTransactionDecodeErrorZ_free(_res: CResult_CommitmentTransactionDecodeErrorZ) { } -impl Drop for CResult_CommitmentTransactionDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_CommitmentTransactionDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_CommitmentTransactionDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_CommitmentTransactionDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_CommitmentTransactionDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_CommitmentTransactionDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_CommitmentTransactionDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_CommitmentTransactionDecodeErrorZ_clone(orig: &CResult_CommitmentTransactionDecodeErrorZ) -> CResult_CommitmentTransactionDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_TrustedCommitmentTransactionNoneZPtr { - pub result: *mut crate::ln::chan_utils::TrustedCommitmentTransaction, - /// Note that this value is always NULL, as there are no contents in the Err variant - pub err: *mut std::ffi::c_void, -} -#[repr(C)] -pub struct CResult_TrustedCommitmentTransactionNoneZ { - pub contents: CResult_TrustedCommitmentTransactionNoneZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_TrustedCommitmentTransactionNoneZ_ok(o: crate::ln::chan_utils::TrustedCommitmentTransaction) -> CResult_TrustedCommitmentTransactionNoneZ { - CResult_TrustedCommitmentTransactionNoneZ { - contents: CResult_TrustedCommitmentTransactionNoneZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_TrustedCommitmentTransactionNoneZ_err() -> CResult_TrustedCommitmentTransactionNoneZ { - CResult_TrustedCommitmentTransactionNoneZ { - contents: CResult_TrustedCommitmentTransactionNoneZPtr { - err: std::ptr::null_mut(), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_TrustedCommitmentTransactionNoneZ_free(_res: CResult_TrustedCommitmentTransactionNoneZ) { } -impl Drop for CResult_TrustedCommitmentTransactionNoneZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - } - } -} -impl From> for CResult_TrustedCommitmentTransactionNoneZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_TrustedCommitmentTransactionNoneZPtr { result } - } else { - let _ = unsafe { Box::from_raw(o.contents.err) }; - o.contents.err = std::ptr::null_mut(); - CResult_TrustedCommitmentTransactionNoneZPtr { err: std::ptr::null_mut() } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -#[repr(C)] -pub union CResult_CVec_SignatureZNoneZPtr { - pub result: *mut crate::c_types::derived::CVec_SignatureZ, - /// Note that this value is always NULL, as there are no contents in the Err variant - pub err: *mut std::ffi::c_void, -} -#[repr(C)] -pub struct CResult_CVec_SignatureZNoneZ { - pub contents: CResult_CVec_SignatureZNoneZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_CVec_SignatureZNoneZ_ok(o: crate::c_types::derived::CVec_SignatureZ) -> CResult_CVec_SignatureZNoneZ { - CResult_CVec_SignatureZNoneZ { - contents: CResult_CVec_SignatureZNoneZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_CVec_SignatureZNoneZ_err() -> CResult_CVec_SignatureZNoneZ { - CResult_CVec_SignatureZNoneZ { - contents: CResult_CVec_SignatureZNoneZPtr { - err: std::ptr::null_mut(), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_CVec_SignatureZNoneZ_free(_res: CResult_CVec_SignatureZNoneZ) { } -impl Drop for CResult_CVec_SignatureZNoneZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - } - } -} -impl From> for CResult_CVec_SignatureZNoneZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_CVec_SignatureZNoneZPtr { result } - } else { - let _ = unsafe { Box::from_raw(o.contents.err) }; - o.contents.err = std::ptr::null_mut(); - CResult_CVec_SignatureZNoneZPtr { err: std::ptr::null_mut() } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_CVec_SignatureZNoneZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_CVec_SignatureZNoneZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_CVec_SignatureZNoneZPtr { - err: std::ptr::null_mut() - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_CVec_SignatureZNoneZ_clone(orig: &CResult_CVec_SignatureZNoneZ) -> CResult_CVec_SignatureZNoneZ { orig.clone() } -#[repr(C)] -pub struct CVec_MessageSendEventZ { - pub data: *mut crate::util::events::MessageSendEvent, - pub datalen: usize -} -impl CVec_MessageSendEventZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::util::events::MessageSendEvent] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_MessageSendEventZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_MessageSendEventZ_free(_res: CVec_MessageSendEventZ) { } -impl Drop for CVec_MessageSendEventZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_MessageSendEventZ { - 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 union CResult_boolLightningErrorZPtr { - pub result: *mut bool, - pub err: *mut crate::ln::msgs::LightningError, -} -#[repr(C)] -pub struct CResult_boolLightningErrorZ { - pub contents: CResult_boolLightningErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_boolLightningErrorZ_ok(o: bool) -> CResult_boolLightningErrorZ { - CResult_boolLightningErrorZ { - contents: CResult_boolLightningErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_boolLightningErrorZ_err(e: crate::ln::msgs::LightningError) -> CResult_boolLightningErrorZ { - CResult_boolLightningErrorZ { - contents: CResult_boolLightningErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_boolLightningErrorZ_free(_res: CResult_boolLightningErrorZ) { } -impl Drop for CResult_boolLightningErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_boolLightningErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_boolLightningErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_boolLightningErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_boolLightningErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_boolLightningErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_boolLightningErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_boolLightningErrorZ_clone(orig: &CResult_boolLightningErrorZ) -> CResult_boolLightningErrorZ { orig.clone() } -#[repr(C)] -pub struct C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ { - pub a: crate::ln::msgs::ChannelAnnouncement, - pub b: crate::ln::msgs::ChannelUpdate, - pub c: crate::ln::msgs::ChannelUpdate, -} -impl From<(crate::ln::msgs::ChannelAnnouncement, crate::ln::msgs::ChannelUpdate, crate::ln::msgs::ChannelUpdate)> for C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ { - fn from (tup: (crate::ln::msgs::ChannelAnnouncement, crate::ln::msgs::ChannelUpdate, crate::ln::msgs::ChannelUpdate)) -> Self { - Self { - a: tup.0, - b: tup.1, - c: tup.2, - } - } -} -impl C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ { - #[allow(unused)] pub(crate) fn to_rust(mut self) -> (crate::ln::msgs::ChannelAnnouncement, crate::ln::msgs::ChannelUpdate, crate::ln::msgs::ChannelUpdate) { - (self.a, self.b, self.c) - } -} -impl Clone for C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ { - fn clone(&self) -> Self { - Self { - a: self.a.clone(), - b: self.b.clone(), - c: self.c.clone(), - } - } -} -#[no_mangle] -pub extern "C" fn C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(orig: &C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) -> C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ { orig.clone() } -#[no_mangle] -pub extern "C" fn C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(a: crate::ln::msgs::ChannelAnnouncement, b: crate::ln::msgs::ChannelUpdate, c: crate::ln::msgs::ChannelUpdate) -> C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ { - C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ { a, b, c, } -} - -#[no_mangle] -pub extern "C" fn C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(_res: C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) { } -#[repr(C)] -pub struct CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ { - pub data: *mut crate::c_types::derived::C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ, - pub datalen: usize -} -impl CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::derived::C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(_res: CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ) { } -impl Drop for CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ { - 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 CVec_NodeAnnouncementZ { - pub data: *mut crate::ln::msgs::NodeAnnouncement, - pub datalen: usize -} -impl CVec_NodeAnnouncementZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::ln::msgs::NodeAnnouncement] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_NodeAnnouncementZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_NodeAnnouncementZ_free(_res: CVec_NodeAnnouncementZ) { } -impl Drop for CVec_NodeAnnouncementZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_NodeAnnouncementZ { - 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 union CResult_NoneLightningErrorZPtr { - /// Note that this value is always NULL, as there are no contents in the OK variant - pub result: *mut std::ffi::c_void, - pub err: *mut crate::ln::msgs::LightningError, -} -#[repr(C)] -pub struct CResult_NoneLightningErrorZ { - pub contents: CResult_NoneLightningErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_NoneLightningErrorZ_ok() -> CResult_NoneLightningErrorZ { - CResult_NoneLightningErrorZ { - contents: CResult_NoneLightningErrorZPtr { - result: std::ptr::null_mut(), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_NoneLightningErrorZ_err(e: crate::ln::msgs::LightningError) -> CResult_NoneLightningErrorZ { - CResult_NoneLightningErrorZ { - contents: CResult_NoneLightningErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_NoneLightningErrorZ_free(_res: CResult_NoneLightningErrorZ) { } -impl Drop for CResult_NoneLightningErrorZ { - fn drop(&mut self) { - if self.result_ok { - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_NoneLightningErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let _ = unsafe { Box::from_raw(o.contents.result) }; - o.contents.result = std::ptr::null_mut(); - CResult_NoneLightningErrorZPtr { result: std::ptr::null_mut() } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NoneLightningErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_NoneLightningErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_NoneLightningErrorZPtr { - result: std::ptr::null_mut() - } } - } else { - Self { result_ok: false, contents: CResult_NoneLightningErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_NoneLightningErrorZ_clone(orig: &CResult_NoneLightningErrorZ) -> CResult_NoneLightningErrorZ { orig.clone() } -#[repr(C)] -pub struct CVec_PublicKeyZ { - pub data: *mut crate::c_types::PublicKey, - pub datalen: usize -} -impl CVec_PublicKeyZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::PublicKey] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_PublicKeyZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_PublicKeyZ_free(_res: CVec_PublicKeyZ) { } -impl Drop for CVec_PublicKeyZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -#[repr(C)] -pub struct CVec_u8Z { - pub data: *mut u8, - pub datalen: usize -} -impl CVec_u8Z { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[u8] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_u8Z { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_u8Z_free(_res: CVec_u8Z) { } -impl Drop for CVec_u8Z { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_u8Z { - 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 union CResult_CVec_u8ZPeerHandleErrorZPtr { - pub result: *mut crate::c_types::derived::CVec_u8Z, - pub err: *mut crate::ln::peer_handler::PeerHandleError, -} -#[repr(C)] -pub struct CResult_CVec_u8ZPeerHandleErrorZ { - pub contents: CResult_CVec_u8ZPeerHandleErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_CVec_u8ZPeerHandleErrorZ_ok(o: crate::c_types::derived::CVec_u8Z) -> CResult_CVec_u8ZPeerHandleErrorZ { - CResult_CVec_u8ZPeerHandleErrorZ { - contents: CResult_CVec_u8ZPeerHandleErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_CVec_u8ZPeerHandleErrorZ_err(e: crate::ln::peer_handler::PeerHandleError) -> CResult_CVec_u8ZPeerHandleErrorZ { - CResult_CVec_u8ZPeerHandleErrorZ { - contents: CResult_CVec_u8ZPeerHandleErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_CVec_u8ZPeerHandleErrorZ_free(_res: CResult_CVec_u8ZPeerHandleErrorZ) { } -impl Drop for CResult_CVec_u8ZPeerHandleErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_CVec_u8ZPeerHandleErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_CVec_u8ZPeerHandleErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_CVec_u8ZPeerHandleErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_CVec_u8ZPeerHandleErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_CVec_u8ZPeerHandleErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_CVec_u8ZPeerHandleErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_CVec_u8ZPeerHandleErrorZ_clone(orig: &CResult_CVec_u8ZPeerHandleErrorZ) -> CResult_CVec_u8ZPeerHandleErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_NonePeerHandleErrorZPtr { - /// Note that this value is always NULL, as there are no contents in the OK variant - pub result: *mut std::ffi::c_void, - pub err: *mut crate::ln::peer_handler::PeerHandleError, -} -#[repr(C)] -pub struct CResult_NonePeerHandleErrorZ { - pub contents: CResult_NonePeerHandleErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_NonePeerHandleErrorZ_ok() -> CResult_NonePeerHandleErrorZ { - CResult_NonePeerHandleErrorZ { - contents: CResult_NonePeerHandleErrorZPtr { - result: std::ptr::null_mut(), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_NonePeerHandleErrorZ_err(e: crate::ln::peer_handler::PeerHandleError) -> CResult_NonePeerHandleErrorZ { - CResult_NonePeerHandleErrorZ { - contents: CResult_NonePeerHandleErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_NonePeerHandleErrorZ_free(_res: CResult_NonePeerHandleErrorZ) { } -impl Drop for CResult_NonePeerHandleErrorZ { - fn drop(&mut self) { - if self.result_ok { - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_NonePeerHandleErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let _ = unsafe { Box::from_raw(o.contents.result) }; - o.contents.result = std::ptr::null_mut(); - CResult_NonePeerHandleErrorZPtr { result: std::ptr::null_mut() } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NonePeerHandleErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_NonePeerHandleErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_NonePeerHandleErrorZPtr { - result: std::ptr::null_mut() - } } - } else { - Self { result_ok: false, contents: CResult_NonePeerHandleErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_NonePeerHandleErrorZ_clone(orig: &CResult_NonePeerHandleErrorZ) -> CResult_NonePeerHandleErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_boolPeerHandleErrorZPtr { - pub result: *mut bool, - pub err: *mut crate::ln::peer_handler::PeerHandleError, -} -#[repr(C)] -pub struct CResult_boolPeerHandleErrorZ { - pub contents: CResult_boolPeerHandleErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_boolPeerHandleErrorZ_ok(o: bool) -> CResult_boolPeerHandleErrorZ { - CResult_boolPeerHandleErrorZ { - contents: CResult_boolPeerHandleErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_boolPeerHandleErrorZ_err(e: crate::ln::peer_handler::PeerHandleError) -> CResult_boolPeerHandleErrorZ { - CResult_boolPeerHandleErrorZ { - contents: CResult_boolPeerHandleErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_boolPeerHandleErrorZ_free(_res: CResult_boolPeerHandleErrorZ) { } -impl Drop for CResult_boolPeerHandleErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_boolPeerHandleErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_boolPeerHandleErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_boolPeerHandleErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_boolPeerHandleErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_boolPeerHandleErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_boolPeerHandleErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_boolPeerHandleErrorZ_clone(orig: &CResult_boolPeerHandleErrorZ) -> CResult_boolPeerHandleErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_InitFeaturesDecodeErrorZPtr { - pub result: *mut crate::ln::features::InitFeatures, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_InitFeaturesDecodeErrorZ { - pub contents: CResult_InitFeaturesDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_InitFeaturesDecodeErrorZ_ok(o: crate::ln::features::InitFeatures) -> CResult_InitFeaturesDecodeErrorZ { - CResult_InitFeaturesDecodeErrorZ { - contents: CResult_InitFeaturesDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_InitFeaturesDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_InitFeaturesDecodeErrorZ { - CResult_InitFeaturesDecodeErrorZ { - contents: CResult_InitFeaturesDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_InitFeaturesDecodeErrorZ_free(_res: CResult_InitFeaturesDecodeErrorZ) { } -impl Drop for CResult_InitFeaturesDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_InitFeaturesDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_InitFeaturesDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_InitFeaturesDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -#[repr(C)] -pub union CResult_NodeFeaturesDecodeErrorZPtr { - pub result: *mut crate::ln::features::NodeFeatures, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_NodeFeaturesDecodeErrorZ { - pub contents: CResult_NodeFeaturesDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_NodeFeaturesDecodeErrorZ_ok(o: crate::ln::features::NodeFeatures) -> CResult_NodeFeaturesDecodeErrorZ { - CResult_NodeFeaturesDecodeErrorZ { - contents: CResult_NodeFeaturesDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_NodeFeaturesDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_NodeFeaturesDecodeErrorZ { - CResult_NodeFeaturesDecodeErrorZ { - contents: CResult_NodeFeaturesDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_NodeFeaturesDecodeErrorZ_free(_res: CResult_NodeFeaturesDecodeErrorZ) { } -impl Drop for CResult_NodeFeaturesDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_NodeFeaturesDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_NodeFeaturesDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NodeFeaturesDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -#[repr(C)] -pub union CResult_ChannelFeaturesDecodeErrorZPtr { - pub result: *mut crate::ln::features::ChannelFeatures, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ChannelFeaturesDecodeErrorZ { - pub contents: CResult_ChannelFeaturesDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ChannelFeaturesDecodeErrorZ_ok(o: crate::ln::features::ChannelFeatures) -> CResult_ChannelFeaturesDecodeErrorZ { - CResult_ChannelFeaturesDecodeErrorZ { - contents: CResult_ChannelFeaturesDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelFeaturesDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ChannelFeaturesDecodeErrorZ { - CResult_ChannelFeaturesDecodeErrorZ { - contents: CResult_ChannelFeaturesDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelFeaturesDecodeErrorZ_free(_res: CResult_ChannelFeaturesDecodeErrorZ) { } -impl Drop for CResult_ChannelFeaturesDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ChannelFeaturesDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ChannelFeaturesDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ChannelFeaturesDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -#[repr(C)] -pub union CResult_ChannelConfigDecodeErrorZPtr { - pub result: *mut crate::util::config::ChannelConfig, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ChannelConfigDecodeErrorZ { - pub contents: CResult_ChannelConfigDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ChannelConfigDecodeErrorZ_ok(o: crate::util::config::ChannelConfig) -> CResult_ChannelConfigDecodeErrorZ { - CResult_ChannelConfigDecodeErrorZ { - contents: CResult_ChannelConfigDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelConfigDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ChannelConfigDecodeErrorZ { - CResult_ChannelConfigDecodeErrorZ { - contents: CResult_ChannelConfigDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelConfigDecodeErrorZ_free(_res: CResult_ChannelConfigDecodeErrorZ) { } -impl Drop for CResult_ChannelConfigDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ChannelConfigDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ChannelConfigDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ChannelConfigDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ChannelConfigDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ChannelConfigDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ChannelConfigDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelConfigDecodeErrorZ_clone(orig: &CResult_ChannelConfigDecodeErrorZ) -> CResult_ChannelConfigDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_DirectionalChannelInfoDecodeErrorZPtr { - pub result: *mut crate::routing::network_graph::DirectionalChannelInfo, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_DirectionalChannelInfoDecodeErrorZ { - pub contents: CResult_DirectionalChannelInfoDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_DirectionalChannelInfoDecodeErrorZ_ok(o: crate::routing::network_graph::DirectionalChannelInfo) -> CResult_DirectionalChannelInfoDecodeErrorZ { - CResult_DirectionalChannelInfoDecodeErrorZ { - contents: CResult_DirectionalChannelInfoDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_DirectionalChannelInfoDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_DirectionalChannelInfoDecodeErrorZ { - CResult_DirectionalChannelInfoDecodeErrorZ { - contents: CResult_DirectionalChannelInfoDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_DirectionalChannelInfoDecodeErrorZ_free(_res: CResult_DirectionalChannelInfoDecodeErrorZ) { } -impl Drop for CResult_DirectionalChannelInfoDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_DirectionalChannelInfoDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_DirectionalChannelInfoDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_DirectionalChannelInfoDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_DirectionalChannelInfoDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_DirectionalChannelInfoDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_DirectionalChannelInfoDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_DirectionalChannelInfoDecodeErrorZ_clone(orig: &CResult_DirectionalChannelInfoDecodeErrorZ) -> CResult_DirectionalChannelInfoDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_ChannelInfoDecodeErrorZPtr { - pub result: *mut crate::routing::network_graph::ChannelInfo, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ChannelInfoDecodeErrorZ { - pub contents: CResult_ChannelInfoDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ChannelInfoDecodeErrorZ_ok(o: crate::routing::network_graph::ChannelInfo) -> CResult_ChannelInfoDecodeErrorZ { - CResult_ChannelInfoDecodeErrorZ { - contents: CResult_ChannelInfoDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelInfoDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ChannelInfoDecodeErrorZ { - CResult_ChannelInfoDecodeErrorZ { - contents: CResult_ChannelInfoDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelInfoDecodeErrorZ_free(_res: CResult_ChannelInfoDecodeErrorZ) { } -impl Drop for CResult_ChannelInfoDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ChannelInfoDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ChannelInfoDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ChannelInfoDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ChannelInfoDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ChannelInfoDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ChannelInfoDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelInfoDecodeErrorZ_clone(orig: &CResult_ChannelInfoDecodeErrorZ) -> CResult_ChannelInfoDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_RoutingFeesDecodeErrorZPtr { - pub result: *mut crate::routing::network_graph::RoutingFees, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_RoutingFeesDecodeErrorZ { - pub contents: CResult_RoutingFeesDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_RoutingFeesDecodeErrorZ_ok(o: crate::routing::network_graph::RoutingFees) -> CResult_RoutingFeesDecodeErrorZ { - CResult_RoutingFeesDecodeErrorZ { - contents: CResult_RoutingFeesDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_RoutingFeesDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_RoutingFeesDecodeErrorZ { - CResult_RoutingFeesDecodeErrorZ { - contents: CResult_RoutingFeesDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_RoutingFeesDecodeErrorZ_free(_res: CResult_RoutingFeesDecodeErrorZ) { } -impl Drop for CResult_RoutingFeesDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_RoutingFeesDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_RoutingFeesDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_RoutingFeesDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_RoutingFeesDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_RoutingFeesDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_RoutingFeesDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_RoutingFeesDecodeErrorZ_clone(orig: &CResult_RoutingFeesDecodeErrorZ) -> CResult_RoutingFeesDecodeErrorZ { orig.clone() } -#[repr(C)] -pub struct CVec_NetAddressZ { - pub data: *mut crate::ln::msgs::NetAddress, - pub datalen: usize -} -impl CVec_NetAddressZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::ln::msgs::NetAddress] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_NetAddressZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_NetAddressZ_free(_res: CVec_NetAddressZ) { } -impl Drop for CVec_NetAddressZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_NetAddressZ { - 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 union CResult_NodeAnnouncementInfoDecodeErrorZPtr { - pub result: *mut crate::routing::network_graph::NodeAnnouncementInfo, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_NodeAnnouncementInfoDecodeErrorZ { - pub contents: CResult_NodeAnnouncementInfoDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_NodeAnnouncementInfoDecodeErrorZ_ok(o: crate::routing::network_graph::NodeAnnouncementInfo) -> CResult_NodeAnnouncementInfoDecodeErrorZ { - CResult_NodeAnnouncementInfoDecodeErrorZ { - contents: CResult_NodeAnnouncementInfoDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_NodeAnnouncementInfoDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_NodeAnnouncementInfoDecodeErrorZ { - CResult_NodeAnnouncementInfoDecodeErrorZ { - contents: CResult_NodeAnnouncementInfoDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_NodeAnnouncementInfoDecodeErrorZ_free(_res: CResult_NodeAnnouncementInfoDecodeErrorZ) { } -impl Drop for CResult_NodeAnnouncementInfoDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_NodeAnnouncementInfoDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_NodeAnnouncementInfoDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NodeAnnouncementInfoDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_NodeAnnouncementInfoDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_NodeAnnouncementInfoDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_NodeAnnouncementInfoDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_NodeAnnouncementInfoDecodeErrorZ_clone(orig: &CResult_NodeAnnouncementInfoDecodeErrorZ) -> CResult_NodeAnnouncementInfoDecodeErrorZ { orig.clone() } -#[repr(C)] -pub struct CVec_u64Z { - pub data: *mut u64, - pub datalen: usize -} -impl CVec_u64Z { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[u64] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_u64Z { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_u64Z_free(_res: CVec_u64Z) { } -impl Drop for CVec_u64Z { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_u64Z { - 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 union CResult_NodeInfoDecodeErrorZPtr { - pub result: *mut crate::routing::network_graph::NodeInfo, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_NodeInfoDecodeErrorZ { - pub contents: CResult_NodeInfoDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_NodeInfoDecodeErrorZ_ok(o: crate::routing::network_graph::NodeInfo) -> CResult_NodeInfoDecodeErrorZ { - CResult_NodeInfoDecodeErrorZ { - contents: CResult_NodeInfoDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_NodeInfoDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_NodeInfoDecodeErrorZ { - CResult_NodeInfoDecodeErrorZ { - contents: CResult_NodeInfoDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_NodeInfoDecodeErrorZ_free(_res: CResult_NodeInfoDecodeErrorZ) { } -impl Drop for CResult_NodeInfoDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_NodeInfoDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_NodeInfoDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NodeInfoDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_NodeInfoDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_NodeInfoDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_NodeInfoDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_NodeInfoDecodeErrorZ_clone(orig: &CResult_NodeInfoDecodeErrorZ) -> CResult_NodeInfoDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_NetworkGraphDecodeErrorZPtr { - pub result: *mut crate::routing::network_graph::NetworkGraph, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_NetworkGraphDecodeErrorZ { - pub contents: CResult_NetworkGraphDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_NetworkGraphDecodeErrorZ_ok(o: crate::routing::network_graph::NetworkGraph) -> CResult_NetworkGraphDecodeErrorZ { - CResult_NetworkGraphDecodeErrorZ { - contents: CResult_NetworkGraphDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_NetworkGraphDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_NetworkGraphDecodeErrorZ { - CResult_NetworkGraphDecodeErrorZ { - contents: CResult_NetworkGraphDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_NetworkGraphDecodeErrorZ_free(_res: CResult_NetworkGraphDecodeErrorZ) { } -impl Drop for CResult_NetworkGraphDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_NetworkGraphDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_NetworkGraphDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NetworkGraphDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_NetworkGraphDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_NetworkGraphDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_NetworkGraphDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_NetworkGraphDecodeErrorZ_clone(orig: &CResult_NetworkGraphDecodeErrorZ) -> CResult_NetworkGraphDecodeErrorZ { orig.clone() } -#[repr(C)] -pub struct C2Tuple_usizeTransactionZ { - pub a: usize, - pub b: crate::c_types::Transaction, -} -impl From<(usize, crate::c_types::Transaction)> for C2Tuple_usizeTransactionZ { - fn from (tup: (usize, crate::c_types::Transaction)) -> Self { - Self { - a: tup.0, - b: tup.1, - } - } -} -impl C2Tuple_usizeTransactionZ { - #[allow(unused)] pub(crate) fn to_rust(mut self) -> (usize, crate::c_types::Transaction) { - (self.a, self.b) - } -} -#[no_mangle] -pub extern "C" fn C2Tuple_usizeTransactionZ_new(a: usize, b: crate::c_types::Transaction) -> C2Tuple_usizeTransactionZ { - C2Tuple_usizeTransactionZ { a, b, } -} - -#[no_mangle] -pub extern "C" fn C2Tuple_usizeTransactionZ_free(_res: C2Tuple_usizeTransactionZ) { } -#[repr(C)] -pub struct CVec_C2Tuple_usizeTransactionZZ { - pub data: *mut crate::c_types::derived::C2Tuple_usizeTransactionZ, - pub datalen: usize -} -impl CVec_C2Tuple_usizeTransactionZZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::derived::C2Tuple_usizeTransactionZ] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_C2Tuple_usizeTransactionZZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_C2Tuple_usizeTransactionZZ_free(_res: CVec_C2Tuple_usizeTransactionZZ) { } -impl Drop for CVec_C2Tuple_usizeTransactionZZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -#[repr(C)] -pub union CResult_NoneChannelMonitorUpdateErrZPtr { - /// Note that this value is always NULL, as there are no contents in the OK variant - pub result: *mut std::ffi::c_void, - pub err: *mut crate::chain::channelmonitor::ChannelMonitorUpdateErr, -} -#[repr(C)] -pub struct CResult_NoneChannelMonitorUpdateErrZ { - pub contents: CResult_NoneChannelMonitorUpdateErrZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_NoneChannelMonitorUpdateErrZ_ok() -> CResult_NoneChannelMonitorUpdateErrZ { - CResult_NoneChannelMonitorUpdateErrZ { - contents: CResult_NoneChannelMonitorUpdateErrZPtr { - result: std::ptr::null_mut(), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_NoneChannelMonitorUpdateErrZ_err(e: crate::chain::channelmonitor::ChannelMonitorUpdateErr) -> CResult_NoneChannelMonitorUpdateErrZ { - CResult_NoneChannelMonitorUpdateErrZ { - contents: CResult_NoneChannelMonitorUpdateErrZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_NoneChannelMonitorUpdateErrZ_free(_res: CResult_NoneChannelMonitorUpdateErrZ) { } -impl Drop for CResult_NoneChannelMonitorUpdateErrZ { - fn drop(&mut self) { - if self.result_ok { - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_NoneChannelMonitorUpdateErrZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let _ = unsafe { Box::from_raw(o.contents.result) }; - o.contents.result = std::ptr::null_mut(); - CResult_NoneChannelMonitorUpdateErrZPtr { result: std::ptr::null_mut() } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NoneChannelMonitorUpdateErrZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_NoneChannelMonitorUpdateErrZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_NoneChannelMonitorUpdateErrZPtr { - result: std::ptr::null_mut() - } } - } else { - Self { result_ok: false, contents: CResult_NoneChannelMonitorUpdateErrZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_NoneChannelMonitorUpdateErrZ_clone(orig: &CResult_NoneChannelMonitorUpdateErrZ) -> CResult_NoneChannelMonitorUpdateErrZ { orig.clone() } -#[repr(C)] -pub struct CVec_MonitorEventZ { - pub data: *mut crate::chain::channelmonitor::MonitorEvent, - pub datalen: usize -} -impl CVec_MonitorEventZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::chain::channelmonitor::MonitorEvent] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_MonitorEventZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_MonitorEventZ_free(_res: CVec_MonitorEventZ) { } -impl Drop for CVec_MonitorEventZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_MonitorEventZ { - 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 CVec_EventZ { - pub data: *mut crate::util::events::Event, - pub datalen: usize -} -impl CVec_EventZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::util::events::Event] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_EventZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_EventZ_free(_res: CVec_EventZ) { } -impl Drop for CVec_EventZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_EventZ { - 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 union CResult_OutPointDecodeErrorZPtr { - pub result: *mut crate::chain::transaction::OutPoint, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_OutPointDecodeErrorZ { - pub contents: CResult_OutPointDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_OutPointDecodeErrorZ_ok(o: crate::chain::transaction::OutPoint) -> CResult_OutPointDecodeErrorZ { - CResult_OutPointDecodeErrorZ { - contents: CResult_OutPointDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_OutPointDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_OutPointDecodeErrorZ { - CResult_OutPointDecodeErrorZ { - contents: CResult_OutPointDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_OutPointDecodeErrorZ_free(_res: CResult_OutPointDecodeErrorZ) { } -impl Drop for CResult_OutPointDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_OutPointDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_OutPointDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_OutPointDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_OutPointDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_OutPointDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_OutPointDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_OutPointDecodeErrorZ_clone(orig: &CResult_OutPointDecodeErrorZ) -> CResult_OutPointDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_ChannelMonitorUpdateDecodeErrorZPtr { - pub result: *mut crate::chain::channelmonitor::ChannelMonitorUpdate, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ChannelMonitorUpdateDecodeErrorZ { - pub contents: CResult_ChannelMonitorUpdateDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ChannelMonitorUpdateDecodeErrorZ_ok(o: crate::chain::channelmonitor::ChannelMonitorUpdate) -> CResult_ChannelMonitorUpdateDecodeErrorZ { - CResult_ChannelMonitorUpdateDecodeErrorZ { - contents: CResult_ChannelMonitorUpdateDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelMonitorUpdateDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ChannelMonitorUpdateDecodeErrorZ { - CResult_ChannelMonitorUpdateDecodeErrorZ { - contents: CResult_ChannelMonitorUpdateDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelMonitorUpdateDecodeErrorZ_free(_res: CResult_ChannelMonitorUpdateDecodeErrorZ) { } -impl Drop for CResult_ChannelMonitorUpdateDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ChannelMonitorUpdateDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ChannelMonitorUpdateDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ChannelMonitorUpdateDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ChannelMonitorUpdateDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ChannelMonitorUpdateDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ChannelMonitorUpdateDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelMonitorUpdateDecodeErrorZ_clone(orig: &CResult_ChannelMonitorUpdateDecodeErrorZ) -> CResult_ChannelMonitorUpdateDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_HTLCUpdateDecodeErrorZPtr { - pub result: *mut crate::chain::channelmonitor::HTLCUpdate, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_HTLCUpdateDecodeErrorZ { - pub contents: CResult_HTLCUpdateDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_HTLCUpdateDecodeErrorZ_ok(o: crate::chain::channelmonitor::HTLCUpdate) -> CResult_HTLCUpdateDecodeErrorZ { - CResult_HTLCUpdateDecodeErrorZ { - contents: CResult_HTLCUpdateDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_HTLCUpdateDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_HTLCUpdateDecodeErrorZ { - CResult_HTLCUpdateDecodeErrorZ { - contents: CResult_HTLCUpdateDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_HTLCUpdateDecodeErrorZ_free(_res: CResult_HTLCUpdateDecodeErrorZ) { } -impl Drop for CResult_HTLCUpdateDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_HTLCUpdateDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_HTLCUpdateDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_HTLCUpdateDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_HTLCUpdateDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_HTLCUpdateDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_HTLCUpdateDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_HTLCUpdateDecodeErrorZ_clone(orig: &CResult_HTLCUpdateDecodeErrorZ) -> CResult_HTLCUpdateDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_NoneMonitorUpdateErrorZPtr { - /// Note that this value is always NULL, as there are no contents in the OK variant - pub result: *mut std::ffi::c_void, - pub err: *mut crate::chain::channelmonitor::MonitorUpdateError, -} -#[repr(C)] -pub struct CResult_NoneMonitorUpdateErrorZ { - pub contents: CResult_NoneMonitorUpdateErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_NoneMonitorUpdateErrorZ_ok() -> CResult_NoneMonitorUpdateErrorZ { - CResult_NoneMonitorUpdateErrorZ { - contents: CResult_NoneMonitorUpdateErrorZPtr { - result: std::ptr::null_mut(), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_NoneMonitorUpdateErrorZ_err(e: crate::chain::channelmonitor::MonitorUpdateError) -> CResult_NoneMonitorUpdateErrorZ { - CResult_NoneMonitorUpdateErrorZ { - contents: CResult_NoneMonitorUpdateErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_NoneMonitorUpdateErrorZ_free(_res: CResult_NoneMonitorUpdateErrorZ) { } -impl Drop for CResult_NoneMonitorUpdateErrorZ { - fn drop(&mut self) { - if self.result_ok { - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_NoneMonitorUpdateErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let _ = unsafe { Box::from_raw(o.contents.result) }; - o.contents.result = std::ptr::null_mut(); - CResult_NoneMonitorUpdateErrorZPtr { result: std::ptr::null_mut() } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NoneMonitorUpdateErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_NoneMonitorUpdateErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_NoneMonitorUpdateErrorZPtr { - result: std::ptr::null_mut() - } } - } else { - Self { result_ok: false, contents: CResult_NoneMonitorUpdateErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_NoneMonitorUpdateErrorZ_clone(orig: &CResult_NoneMonitorUpdateErrorZ) -> CResult_NoneMonitorUpdateErrorZ { orig.clone() } -#[repr(C)] -pub struct C2Tuple_OutPointScriptZ { - pub a: crate::chain::transaction::OutPoint, - pub b: crate::c_types::derived::CVec_u8Z, -} -impl From<(crate::chain::transaction::OutPoint, crate::c_types::derived::CVec_u8Z)> for C2Tuple_OutPointScriptZ { - fn from (tup: (crate::chain::transaction::OutPoint, crate::c_types::derived::CVec_u8Z)) -> Self { - Self { - a: tup.0, - b: tup.1, - } - } -} -impl C2Tuple_OutPointScriptZ { - #[allow(unused)] pub(crate) fn to_rust(mut self) -> (crate::chain::transaction::OutPoint, crate::c_types::derived::CVec_u8Z) { - (self.a, self.b) - } -} -impl Clone for C2Tuple_OutPointScriptZ { - fn clone(&self) -> Self { - Self { - a: self.a.clone(), - b: self.b.clone(), - } - } -} -#[no_mangle] -pub extern "C" fn C2Tuple_OutPointScriptZ_clone(orig: &C2Tuple_OutPointScriptZ) -> C2Tuple_OutPointScriptZ { orig.clone() } -#[no_mangle] -pub extern "C" fn C2Tuple_OutPointScriptZ_new(a: crate::chain::transaction::OutPoint, b: crate::c_types::derived::CVec_u8Z) -> C2Tuple_OutPointScriptZ { - C2Tuple_OutPointScriptZ { a, b, } -} - -#[no_mangle] -pub extern "C" fn C2Tuple_OutPointScriptZ_free(_res: C2Tuple_OutPointScriptZ) { } -#[repr(C)] -pub struct CVec_TransactionZ { - pub data: *mut crate::c_types::Transaction, - pub datalen: usize -} -impl CVec_TransactionZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::Transaction] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_TransactionZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_TransactionZ_free(_res: CVec_TransactionZ) { } -impl Drop for CVec_TransactionZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -#[repr(C)] -pub struct C2Tuple_u32TxOutZ { - pub a: u32, - pub b: crate::c_types::TxOut, -} -impl From<(u32, crate::c_types::TxOut)> for C2Tuple_u32TxOutZ { - fn from (tup: (u32, crate::c_types::TxOut)) -> Self { - Self { - a: tup.0, - b: tup.1, - } - } -} -impl C2Tuple_u32TxOutZ { - #[allow(unused)] pub(crate) fn to_rust(mut self) -> (u32, crate::c_types::TxOut) { - (self.a, self.b) - } -} -impl Clone for C2Tuple_u32TxOutZ { - fn clone(&self) -> Self { - Self { - a: self.a.clone(), - b: self.b.clone(), - } - } -} -#[no_mangle] -pub extern "C" fn C2Tuple_u32TxOutZ_clone(orig: &C2Tuple_u32TxOutZ) -> C2Tuple_u32TxOutZ { orig.clone() } -#[no_mangle] -pub extern "C" fn C2Tuple_u32TxOutZ_new(a: u32, b: crate::c_types::TxOut) -> C2Tuple_u32TxOutZ { - C2Tuple_u32TxOutZ { a, b, } -} - -#[no_mangle] -pub extern "C" fn C2Tuple_u32TxOutZ_free(_res: C2Tuple_u32TxOutZ) { } -#[repr(C)] -pub struct CVec_C2Tuple_u32TxOutZZ { - pub data: *mut crate::c_types::derived::C2Tuple_u32TxOutZ, - pub datalen: usize -} -impl CVec_C2Tuple_u32TxOutZZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::derived::C2Tuple_u32TxOutZ] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_C2Tuple_u32TxOutZZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_C2Tuple_u32TxOutZZ_free(_res: CVec_C2Tuple_u32TxOutZZ) { } -impl Drop for CVec_C2Tuple_u32TxOutZZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_C2Tuple_u32TxOutZZ { - 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 C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ { - pub a: crate::c_types::ThirtyTwoBytes, - pub b: crate::c_types::derived::CVec_C2Tuple_u32TxOutZZ, -} -impl From<(crate::c_types::ThirtyTwoBytes, crate::c_types::derived::CVec_C2Tuple_u32TxOutZZ)> for C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ { - fn from (tup: (crate::c_types::ThirtyTwoBytes, crate::c_types::derived::CVec_C2Tuple_u32TxOutZZ)) -> Self { - Self { - a: tup.0, - b: tup.1, - } - } -} -impl C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ { - #[allow(unused)] pub(crate) fn to_rust(mut self) -> (crate::c_types::ThirtyTwoBytes, crate::c_types::derived::CVec_C2Tuple_u32TxOutZZ) { - (self.a, self.b) - } -} -#[no_mangle] -pub extern "C" fn C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_new(a: crate::c_types::ThirtyTwoBytes, b: crate::c_types::derived::CVec_C2Tuple_u32TxOutZZ) -> C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ { - C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ { a, b, } -} - -#[no_mangle] -pub extern "C" fn C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_free(_res: C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ) { } -#[repr(C)] -pub struct CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ { - pub data: *mut crate::c_types::derived::C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ, - pub datalen: usize -} -impl CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::derived::C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free(_res: CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ) { } -impl Drop for CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -#[repr(C)] -pub struct C2Tuple_BlockHashChannelMonitorZ { - pub a: crate::c_types::ThirtyTwoBytes, - pub b: crate::chain::channelmonitor::ChannelMonitor, -} -impl From<(crate::c_types::ThirtyTwoBytes, crate::chain::channelmonitor::ChannelMonitor)> for C2Tuple_BlockHashChannelMonitorZ { - fn from (tup: (crate::c_types::ThirtyTwoBytes, crate::chain::channelmonitor::ChannelMonitor)) -> Self { - Self { - a: tup.0, - b: tup.1, - } - } -} -impl C2Tuple_BlockHashChannelMonitorZ { - #[allow(unused)] pub(crate) fn to_rust(mut self) -> (crate::c_types::ThirtyTwoBytes, crate::chain::channelmonitor::ChannelMonitor) { - (self.a, self.b) - } -} -#[no_mangle] -pub extern "C" fn C2Tuple_BlockHashChannelMonitorZ_new(a: crate::c_types::ThirtyTwoBytes, b: crate::chain::channelmonitor::ChannelMonitor) -> C2Tuple_BlockHashChannelMonitorZ { - C2Tuple_BlockHashChannelMonitorZ { a, b, } -} - -#[no_mangle] -pub extern "C" fn C2Tuple_BlockHashChannelMonitorZ_free(_res: C2Tuple_BlockHashChannelMonitorZ) { } -#[repr(C)] -pub union CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr { - pub result: *mut crate::c_types::derived::C2Tuple_BlockHashChannelMonitorZ, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { - pub contents: CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_ok(o: crate::c_types::derived::C2Tuple_BlockHashChannelMonitorZ) -> CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { - contents: CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { - contents: CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(_res: CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ) { } -impl Drop for CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -#[repr(C)] -pub struct CVec_SpendableOutputDescriptorZ { - pub data: *mut crate::chain::keysinterface::SpendableOutputDescriptor, - pub datalen: usize -} -impl CVec_SpendableOutputDescriptorZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::chain::keysinterface::SpendableOutputDescriptor] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_SpendableOutputDescriptorZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_SpendableOutputDescriptorZ_free(_res: CVec_SpendableOutputDescriptorZ) { } -impl Drop for CVec_SpendableOutputDescriptorZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_SpendableOutputDescriptorZ { - 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 union CResult_TxOutAccessErrorZPtr { - pub result: *mut crate::c_types::TxOut, - pub err: *mut crate::chain::AccessError, -} -#[repr(C)] -pub struct CResult_TxOutAccessErrorZ { - pub contents: CResult_TxOutAccessErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_TxOutAccessErrorZ_ok(o: crate::c_types::TxOut) -> CResult_TxOutAccessErrorZ { - CResult_TxOutAccessErrorZ { - contents: CResult_TxOutAccessErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_TxOutAccessErrorZ_err(e: crate::chain::AccessError) -> CResult_TxOutAccessErrorZ { - CResult_TxOutAccessErrorZ { - contents: CResult_TxOutAccessErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_TxOutAccessErrorZ_free(_res: CResult_TxOutAccessErrorZ) { } -impl Drop for CResult_TxOutAccessErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_TxOutAccessErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_TxOutAccessErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_TxOutAccessErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_TxOutAccessErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_TxOutAccessErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_TxOutAccessErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_TxOutAccessErrorZ_clone(orig: &CResult_TxOutAccessErrorZ) -> CResult_TxOutAccessErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_NoneAPIErrorZPtr { - /// Note that this value is always NULL, as there are no contents in the OK variant - pub result: *mut std::ffi::c_void, - pub err: *mut crate::util::errors::APIError, -} -#[repr(C)] -pub struct CResult_NoneAPIErrorZ { - pub contents: CResult_NoneAPIErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_NoneAPIErrorZ_ok() -> CResult_NoneAPIErrorZ { - CResult_NoneAPIErrorZ { - contents: CResult_NoneAPIErrorZPtr { - result: std::ptr::null_mut(), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_NoneAPIErrorZ_err(e: crate::util::errors::APIError) -> CResult_NoneAPIErrorZ { - CResult_NoneAPIErrorZ { - contents: CResult_NoneAPIErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_NoneAPIErrorZ_free(_res: CResult_NoneAPIErrorZ) { } -impl Drop for CResult_NoneAPIErrorZ { - fn drop(&mut self) { - if self.result_ok { - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_NoneAPIErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let _ = unsafe { Box::from_raw(o.contents.result) }; - o.contents.result = std::ptr::null_mut(); - CResult_NoneAPIErrorZPtr { result: std::ptr::null_mut() } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NoneAPIErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_NoneAPIErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_NoneAPIErrorZPtr { - result: std::ptr::null_mut() - } } - } else { - Self { result_ok: false, contents: CResult_NoneAPIErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_NoneAPIErrorZ_clone(orig: &CResult_NoneAPIErrorZ) -> CResult_NoneAPIErrorZ { orig.clone() } -#[repr(C)] -pub struct CVec_CResult_NoneAPIErrorZZ { - pub data: *mut crate::c_types::derived::CResult_NoneAPIErrorZ, - pub datalen: usize -} -impl CVec_CResult_NoneAPIErrorZZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::derived::CResult_NoneAPIErrorZ] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_CResult_NoneAPIErrorZZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_CResult_NoneAPIErrorZZ_free(_res: CVec_CResult_NoneAPIErrorZZ) { } -impl Drop for CVec_CResult_NoneAPIErrorZZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_CResult_NoneAPIErrorZZ { - 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 CVec_APIErrorZ { - pub data: *mut crate::util::errors::APIError, - pub datalen: usize -} -impl CVec_APIErrorZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::util::errors::APIError] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_APIErrorZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_APIErrorZ_free(_res: CVec_APIErrorZ) { } -impl Drop for CVec_APIErrorZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_APIErrorZ { - 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 CVec_ChannelDetailsZ { - pub data: *mut crate::ln::channelmanager::ChannelDetails, - pub datalen: usize -} -impl CVec_ChannelDetailsZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::ln::channelmanager::ChannelDetails] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_ChannelDetailsZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_ChannelDetailsZ_free(_res: CVec_ChannelDetailsZ) { } -impl Drop for CVec_ChannelDetailsZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_ChannelDetailsZ { - 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 union CResult_NonePaymentSendFailureZPtr { - /// Note that this value is always NULL, as there are no contents in the OK variant - pub result: *mut std::ffi::c_void, - pub err: *mut crate::ln::channelmanager::PaymentSendFailure, -} -#[repr(C)] -pub struct CResult_NonePaymentSendFailureZ { - pub contents: CResult_NonePaymentSendFailureZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_NonePaymentSendFailureZ_ok() -> CResult_NonePaymentSendFailureZ { - CResult_NonePaymentSendFailureZ { - contents: CResult_NonePaymentSendFailureZPtr { - result: std::ptr::null_mut(), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_NonePaymentSendFailureZ_err(e: crate::ln::channelmanager::PaymentSendFailure) -> CResult_NonePaymentSendFailureZ { - CResult_NonePaymentSendFailureZ { - contents: CResult_NonePaymentSendFailureZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_NonePaymentSendFailureZ_free(_res: CResult_NonePaymentSendFailureZ) { } -impl Drop for CResult_NonePaymentSendFailureZ { - fn drop(&mut self) { - if self.result_ok { - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_NonePaymentSendFailureZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let _ = unsafe { Box::from_raw(o.contents.result) }; - o.contents.result = std::ptr::null_mut(); - CResult_NonePaymentSendFailureZPtr { result: std::ptr::null_mut() } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NonePaymentSendFailureZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_NonePaymentSendFailureZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_NonePaymentSendFailureZPtr { - result: std::ptr::null_mut() - } } - } else { - Self { result_ok: false, contents: CResult_NonePaymentSendFailureZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_NonePaymentSendFailureZ_clone(orig: &CResult_NonePaymentSendFailureZ) -> CResult_NonePaymentSendFailureZ { orig.clone() } -#[repr(C)] -pub struct CVec_ChannelMonitorZ { - pub data: *mut crate::chain::channelmonitor::ChannelMonitor, - pub datalen: usize -} -impl CVec_ChannelMonitorZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::chain::channelmonitor::ChannelMonitor] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_ChannelMonitorZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_ChannelMonitorZ_free(_res: CVec_ChannelMonitorZ) { } -impl Drop for CVec_ChannelMonitorZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -#[repr(C)] -pub struct C2Tuple_BlockHashChannelManagerZ { - pub a: crate::c_types::ThirtyTwoBytes, - pub b: crate::ln::channelmanager::ChannelManager, -} -impl From<(crate::c_types::ThirtyTwoBytes, crate::ln::channelmanager::ChannelManager)> for C2Tuple_BlockHashChannelManagerZ { - fn from (tup: (crate::c_types::ThirtyTwoBytes, crate::ln::channelmanager::ChannelManager)) -> Self { - Self { - a: tup.0, - b: tup.1, - } - } -} -impl C2Tuple_BlockHashChannelManagerZ { - #[allow(unused)] pub(crate) fn to_rust(mut self) -> (crate::c_types::ThirtyTwoBytes, crate::ln::channelmanager::ChannelManager) { - (self.a, self.b) - } -} -#[no_mangle] -pub extern "C" fn C2Tuple_BlockHashChannelManagerZ_new(a: crate::c_types::ThirtyTwoBytes, b: crate::ln::channelmanager::ChannelManager) -> C2Tuple_BlockHashChannelManagerZ { - C2Tuple_BlockHashChannelManagerZ { a, b, } -} - -#[no_mangle] -pub extern "C" fn C2Tuple_BlockHashChannelManagerZ_free(_res: C2Tuple_BlockHashChannelManagerZ) { } -#[repr(C)] -pub union CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZPtr { - pub result: *mut crate::c_types::derived::C2Tuple_BlockHashChannelManagerZ, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ { - pub contents: CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_ok(o: crate::c_types::derived::C2Tuple_BlockHashChannelManagerZ) -> CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ { - CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ { - contents: CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ { - CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ { - contents: CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(_res: CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ) { } -impl Drop for CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -#[repr(C)] -pub union CResult_SpendableOutputDescriptorDecodeErrorZPtr { - pub result: *mut crate::chain::keysinterface::SpendableOutputDescriptor, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_SpendableOutputDescriptorDecodeErrorZ { - pub contents: CResult_SpendableOutputDescriptorDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_SpendableOutputDescriptorDecodeErrorZ_ok(o: crate::chain::keysinterface::SpendableOutputDescriptor) -> CResult_SpendableOutputDescriptorDecodeErrorZ { - CResult_SpendableOutputDescriptorDecodeErrorZ { - contents: CResult_SpendableOutputDescriptorDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_SpendableOutputDescriptorDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_SpendableOutputDescriptorDecodeErrorZ { - CResult_SpendableOutputDescriptorDecodeErrorZ { - contents: CResult_SpendableOutputDescriptorDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_SpendableOutputDescriptorDecodeErrorZ_free(_res: CResult_SpendableOutputDescriptorDecodeErrorZ) { } -impl Drop for CResult_SpendableOutputDescriptorDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_SpendableOutputDescriptorDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_SpendableOutputDescriptorDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_SpendableOutputDescriptorDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_SpendableOutputDescriptorDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_SpendableOutputDescriptorDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_SpendableOutputDescriptorDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_SpendableOutputDescriptorDecodeErrorZ_clone(orig: &CResult_SpendableOutputDescriptorDecodeErrorZ) -> CResult_SpendableOutputDescriptorDecodeErrorZ { orig.clone() } -#[repr(C)] -pub struct C2Tuple_SignatureCVec_SignatureZZ { - pub a: crate::c_types::Signature, - pub b: crate::c_types::derived::CVec_SignatureZ, -} -impl From<(crate::c_types::Signature, crate::c_types::derived::CVec_SignatureZ)> for C2Tuple_SignatureCVec_SignatureZZ { - fn from (tup: (crate::c_types::Signature, crate::c_types::derived::CVec_SignatureZ)) -> Self { - Self { - a: tup.0, - b: tup.1, - } - } -} -impl C2Tuple_SignatureCVec_SignatureZZ { - #[allow(unused)] pub(crate) fn to_rust(mut self) -> (crate::c_types::Signature, crate::c_types::derived::CVec_SignatureZ) { - (self.a, self.b) - } -} -impl Clone for C2Tuple_SignatureCVec_SignatureZZ { - fn clone(&self) -> Self { - Self { - a: self.a.clone(), - b: self.b.clone(), - } - } -} -#[no_mangle] -pub extern "C" fn C2Tuple_SignatureCVec_SignatureZZ_clone(orig: &C2Tuple_SignatureCVec_SignatureZZ) -> C2Tuple_SignatureCVec_SignatureZZ { orig.clone() } -#[no_mangle] -pub extern "C" fn C2Tuple_SignatureCVec_SignatureZZ_new(a: crate::c_types::Signature, b: crate::c_types::derived::CVec_SignatureZ) -> C2Tuple_SignatureCVec_SignatureZZ { - C2Tuple_SignatureCVec_SignatureZZ { a, b, } -} - -#[no_mangle] -pub extern "C" fn C2Tuple_SignatureCVec_SignatureZZ_free(_res: C2Tuple_SignatureCVec_SignatureZZ) { } -#[repr(C)] -pub union CResult_C2Tuple_SignatureCVec_SignatureZZNoneZPtr { - pub result: *mut crate::c_types::derived::C2Tuple_SignatureCVec_SignatureZZ, - /// Note that this value is always NULL, as there are no contents in the Err variant - pub err: *mut std::ffi::c_void, -} -#[repr(C)] -pub struct CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { - pub contents: CResult_C2Tuple_SignatureCVec_SignatureZZNoneZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(o: crate::c_types::derived::C2Tuple_SignatureCVec_SignatureZZ) -> CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { - CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { - contents: CResult_C2Tuple_SignatureCVec_SignatureZZNoneZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err() -> CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { - CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { - contents: CResult_C2Tuple_SignatureCVec_SignatureZZNoneZPtr { - err: std::ptr::null_mut(), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(_res: CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ) { } -impl Drop for CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - } - } -} -impl From> for CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_C2Tuple_SignatureCVec_SignatureZZNoneZPtr { result } - } else { - let _ = unsafe { Box::from_raw(o.contents.err) }; - o.contents.err = std::ptr::null_mut(); - CResult_C2Tuple_SignatureCVec_SignatureZZNoneZPtr { err: std::ptr::null_mut() } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_C2Tuple_SignatureCVec_SignatureZZNoneZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_C2Tuple_SignatureCVec_SignatureZZNoneZPtr { - err: std::ptr::null_mut() - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_clone(orig: &CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ) -> CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { orig.clone() } -#[repr(C)] -pub union CResult_SignatureNoneZPtr { - pub result: *mut crate::c_types::Signature, - /// Note that this value is always NULL, as there are no contents in the Err variant - pub err: *mut std::ffi::c_void, -} -#[repr(C)] -pub struct CResult_SignatureNoneZ { - pub contents: CResult_SignatureNoneZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_SignatureNoneZ_ok(o: crate::c_types::Signature) -> CResult_SignatureNoneZ { - CResult_SignatureNoneZ { - contents: CResult_SignatureNoneZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_SignatureNoneZ_err() -> CResult_SignatureNoneZ { - CResult_SignatureNoneZ { - contents: CResult_SignatureNoneZPtr { - err: std::ptr::null_mut(), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_SignatureNoneZ_free(_res: CResult_SignatureNoneZ) { } -impl Drop for CResult_SignatureNoneZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - } - } -} -impl From> for CResult_SignatureNoneZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_SignatureNoneZPtr { result } - } else { - let _ = unsafe { Box::from_raw(o.contents.err) }; - o.contents.err = std::ptr::null_mut(); - CResult_SignatureNoneZPtr { err: std::ptr::null_mut() } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_SignatureNoneZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_SignatureNoneZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_SignatureNoneZPtr { - err: std::ptr::null_mut() - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_SignatureNoneZ_clone(orig: &CResult_SignatureNoneZ) -> CResult_SignatureNoneZ { orig.clone() } -#[repr(C)] -pub union CResult_SignDecodeErrorZPtr { - pub result: *mut crate::chain::keysinterface::Sign, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_SignDecodeErrorZ { - pub contents: CResult_SignDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_SignDecodeErrorZ_ok(o: crate::chain::keysinterface::Sign) -> CResult_SignDecodeErrorZ { - CResult_SignDecodeErrorZ { - contents: CResult_SignDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_SignDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_SignDecodeErrorZ { - CResult_SignDecodeErrorZ { - contents: CResult_SignDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_SignDecodeErrorZ_free(_res: CResult_SignDecodeErrorZ) { } -impl Drop for CResult_SignDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_SignDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_SignDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_SignDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_SignDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_SignDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_SignDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_SignDecodeErrorZ_clone(orig: &CResult_SignDecodeErrorZ) -> CResult_SignDecodeErrorZ { orig.clone() } -#[repr(C)] -pub struct CVec_CVec_u8ZZ { - pub data: *mut crate::c_types::derived::CVec_u8Z, - pub datalen: usize -} -impl CVec_CVec_u8ZZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::derived::CVec_u8Z] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_CVec_u8ZZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_CVec_u8ZZ_free(_res: CVec_CVec_u8ZZ) { } -impl Drop for CVec_CVec_u8ZZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_CVec_u8ZZ { - 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 union CResult_CVec_CVec_u8ZZNoneZPtr { - pub result: *mut crate::c_types::derived::CVec_CVec_u8ZZ, - /// Note that this value is always NULL, as there are no contents in the Err variant - pub err: *mut std::ffi::c_void, -} -#[repr(C)] -pub struct CResult_CVec_CVec_u8ZZNoneZ { - pub contents: CResult_CVec_CVec_u8ZZNoneZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_CVec_CVec_u8ZZNoneZ_ok(o: crate::c_types::derived::CVec_CVec_u8ZZ) -> CResult_CVec_CVec_u8ZZNoneZ { - CResult_CVec_CVec_u8ZZNoneZ { - contents: CResult_CVec_CVec_u8ZZNoneZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_CVec_CVec_u8ZZNoneZ_err() -> CResult_CVec_CVec_u8ZZNoneZ { - CResult_CVec_CVec_u8ZZNoneZ { - contents: CResult_CVec_CVec_u8ZZNoneZPtr { - err: std::ptr::null_mut(), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_CVec_CVec_u8ZZNoneZ_free(_res: CResult_CVec_CVec_u8ZZNoneZ) { } -impl Drop for CResult_CVec_CVec_u8ZZNoneZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - } - } -} -impl From> for CResult_CVec_CVec_u8ZZNoneZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_CVec_CVec_u8ZZNoneZPtr { result } - } else { - let _ = unsafe { Box::from_raw(o.contents.err) }; - o.contents.err = std::ptr::null_mut(); - CResult_CVec_CVec_u8ZZNoneZPtr { err: std::ptr::null_mut() } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_CVec_CVec_u8ZZNoneZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_CVec_CVec_u8ZZNoneZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_CVec_CVec_u8ZZNoneZPtr { - err: std::ptr::null_mut() - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_CVec_CVec_u8ZZNoneZ_clone(orig: &CResult_CVec_CVec_u8ZZNoneZ) -> CResult_CVec_CVec_u8ZZNoneZ { orig.clone() } -#[repr(C)] -pub union CResult_InMemorySignerDecodeErrorZPtr { - pub result: *mut crate::chain::keysinterface::InMemorySigner, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_InMemorySignerDecodeErrorZ { - pub contents: CResult_InMemorySignerDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_InMemorySignerDecodeErrorZ_ok(o: crate::chain::keysinterface::InMemorySigner) -> CResult_InMemorySignerDecodeErrorZ { - CResult_InMemorySignerDecodeErrorZ { - contents: CResult_InMemorySignerDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_InMemorySignerDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_InMemorySignerDecodeErrorZ { - CResult_InMemorySignerDecodeErrorZ { - contents: CResult_InMemorySignerDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_InMemorySignerDecodeErrorZ_free(_res: CResult_InMemorySignerDecodeErrorZ) { } -impl Drop for CResult_InMemorySignerDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_InMemorySignerDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_InMemorySignerDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_InMemorySignerDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_InMemorySignerDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_InMemorySignerDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_InMemorySignerDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_InMemorySignerDecodeErrorZ_clone(orig: &CResult_InMemorySignerDecodeErrorZ) -> CResult_InMemorySignerDecodeErrorZ { orig.clone() } -#[repr(C)] -pub struct CVec_TxOutZ { - pub data: *mut crate::c_types::TxOut, - pub datalen: usize -} -impl CVec_TxOutZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::TxOut] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_TxOutZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_TxOutZ_free(_res: CVec_TxOutZ) { } -impl Drop for CVec_TxOutZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_TxOutZ { - 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 union CResult_TransactionNoneZPtr { - pub result: *mut crate::c_types::Transaction, - /// Note that this value is always NULL, as there are no contents in the Err variant - pub err: *mut std::ffi::c_void, -} -#[repr(C)] -pub struct CResult_TransactionNoneZ { - pub contents: CResult_TransactionNoneZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_TransactionNoneZ_ok(o: crate::c_types::Transaction) -> CResult_TransactionNoneZ { - CResult_TransactionNoneZ { - contents: CResult_TransactionNoneZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_TransactionNoneZ_err() -> CResult_TransactionNoneZ { - CResult_TransactionNoneZ { - contents: CResult_TransactionNoneZPtr { - err: std::ptr::null_mut(), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_TransactionNoneZ_free(_res: CResult_TransactionNoneZ) { } -impl Drop for CResult_TransactionNoneZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - } - } -} -impl From> for CResult_TransactionNoneZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_TransactionNoneZPtr { result } - } else { - let _ = unsafe { Box::from_raw(o.contents.err) }; - o.contents.err = std::ptr::null_mut(); - CResult_TransactionNoneZPtr { err: std::ptr::null_mut() } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -#[repr(C)] -pub struct CVec_RouteHopZ { - pub data: *mut crate::routing::router::RouteHop, - pub datalen: usize -} -impl CVec_RouteHopZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::routing::router::RouteHop] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_RouteHopZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_RouteHopZ_free(_res: CVec_RouteHopZ) { } -impl Drop for CVec_RouteHopZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_RouteHopZ { - 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 CVec_CVec_RouteHopZZ { - pub data: *mut crate::c_types::derived::CVec_RouteHopZ, - pub datalen: usize -} -impl CVec_CVec_RouteHopZZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::derived::CVec_RouteHopZ] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_CVec_RouteHopZZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_CVec_RouteHopZZ_free(_res: CVec_CVec_RouteHopZZ) { } -impl Drop for CVec_CVec_RouteHopZZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_CVec_RouteHopZZ { - 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 union CResult_RouteDecodeErrorZPtr { - pub result: *mut crate::routing::router::Route, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_RouteDecodeErrorZ { - pub contents: CResult_RouteDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_RouteDecodeErrorZ_ok(o: crate::routing::router::Route) -> CResult_RouteDecodeErrorZ { - CResult_RouteDecodeErrorZ { - contents: CResult_RouteDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_RouteDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_RouteDecodeErrorZ { - CResult_RouteDecodeErrorZ { - contents: CResult_RouteDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_RouteDecodeErrorZ_free(_res: CResult_RouteDecodeErrorZ) { } -impl Drop for CResult_RouteDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_RouteDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_RouteDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_RouteDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_RouteDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_RouteDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_RouteDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_RouteDecodeErrorZ_clone(orig: &CResult_RouteDecodeErrorZ) -> CResult_RouteDecodeErrorZ { orig.clone() } -#[repr(C)] -pub struct CVec_RouteHintZ { - pub data: *mut crate::routing::router::RouteHint, - pub datalen: usize -} -impl CVec_RouteHintZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::routing::router::RouteHint] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_RouteHintZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_RouteHintZ_free(_res: CVec_RouteHintZ) { } -impl Drop for CVec_RouteHintZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_RouteHintZ { - 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 union CResult_RouteLightningErrorZPtr { - pub result: *mut crate::routing::router::Route, - pub err: *mut crate::ln::msgs::LightningError, -} -#[repr(C)] -pub struct CResult_RouteLightningErrorZ { - pub contents: CResult_RouteLightningErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_RouteLightningErrorZ_ok(o: crate::routing::router::Route) -> CResult_RouteLightningErrorZ { - CResult_RouteLightningErrorZ { - contents: CResult_RouteLightningErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_RouteLightningErrorZ_err(e: crate::ln::msgs::LightningError) -> CResult_RouteLightningErrorZ { - CResult_RouteLightningErrorZ { - contents: CResult_RouteLightningErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_RouteLightningErrorZ_free(_res: CResult_RouteLightningErrorZ) { } -impl Drop for CResult_RouteLightningErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_RouteLightningErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_RouteLightningErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_RouteLightningErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_RouteLightningErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_RouteLightningErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_RouteLightningErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_RouteLightningErrorZ_clone(orig: &CResult_RouteLightningErrorZ) -> CResult_RouteLightningErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_NetAddressu8ZPtr { - pub result: *mut crate::ln::msgs::NetAddress, - pub err: *mut u8, -} -#[repr(C)] -pub struct CResult_NetAddressu8Z { - pub contents: CResult_NetAddressu8ZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_NetAddressu8Z_ok(o: crate::ln::msgs::NetAddress) -> CResult_NetAddressu8Z { - CResult_NetAddressu8Z { - contents: CResult_NetAddressu8ZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_NetAddressu8Z_err(e: u8) -> CResult_NetAddressu8Z { - CResult_NetAddressu8Z { - contents: CResult_NetAddressu8ZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_NetAddressu8Z_free(_res: CResult_NetAddressu8Z) { } -impl Drop for CResult_NetAddressu8Z { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_NetAddressu8Z { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_NetAddressu8ZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NetAddressu8ZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_NetAddressu8Z { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_NetAddressu8ZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_NetAddressu8ZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_NetAddressu8Z_clone(orig: &CResult_NetAddressu8Z) -> CResult_NetAddressu8Z { orig.clone() } -#[repr(C)] -pub union CResult_CResult_NetAddressu8ZDecodeErrorZPtr { - pub result: *mut crate::c_types::derived::CResult_NetAddressu8Z, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_CResult_NetAddressu8ZDecodeErrorZ { - pub contents: CResult_CResult_NetAddressu8ZDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_CResult_NetAddressu8ZDecodeErrorZ_ok(o: crate::c_types::derived::CResult_NetAddressu8Z) -> CResult_CResult_NetAddressu8ZDecodeErrorZ { - CResult_CResult_NetAddressu8ZDecodeErrorZ { - contents: CResult_CResult_NetAddressu8ZDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_CResult_NetAddressu8ZDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_CResult_NetAddressu8ZDecodeErrorZ { - CResult_CResult_NetAddressu8ZDecodeErrorZ { - contents: CResult_CResult_NetAddressu8ZDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_CResult_NetAddressu8ZDecodeErrorZ_free(_res: CResult_CResult_NetAddressu8ZDecodeErrorZ) { } -impl Drop for CResult_CResult_NetAddressu8ZDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_CResult_NetAddressu8ZDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_CResult_NetAddressu8ZDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_CResult_NetAddressu8ZDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_CResult_NetAddressu8ZDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_CResult_NetAddressu8ZDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_CResult_NetAddressu8ZDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_CResult_NetAddressu8ZDecodeErrorZ_clone(orig: &CResult_CResult_NetAddressu8ZDecodeErrorZ) -> CResult_CResult_NetAddressu8ZDecodeErrorZ { orig.clone() } -#[repr(C)] -pub struct CVec_UpdateAddHTLCZ { - pub data: *mut crate::ln::msgs::UpdateAddHTLC, - pub datalen: usize -} -impl CVec_UpdateAddHTLCZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::ln::msgs::UpdateAddHTLC] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_UpdateAddHTLCZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_UpdateAddHTLCZ_free(_res: CVec_UpdateAddHTLCZ) { } -impl Drop for CVec_UpdateAddHTLCZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_UpdateAddHTLCZ { - 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 CVec_UpdateFulfillHTLCZ { - pub data: *mut crate::ln::msgs::UpdateFulfillHTLC, - pub datalen: usize -} -impl CVec_UpdateFulfillHTLCZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::ln::msgs::UpdateFulfillHTLC] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_UpdateFulfillHTLCZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_UpdateFulfillHTLCZ_free(_res: CVec_UpdateFulfillHTLCZ) { } -impl Drop for CVec_UpdateFulfillHTLCZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_UpdateFulfillHTLCZ { - 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 CVec_UpdateFailHTLCZ { - pub data: *mut crate::ln::msgs::UpdateFailHTLC, - pub datalen: usize -} -impl CVec_UpdateFailHTLCZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::ln::msgs::UpdateFailHTLC] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_UpdateFailHTLCZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_UpdateFailHTLCZ_free(_res: CVec_UpdateFailHTLCZ) { } -impl Drop for CVec_UpdateFailHTLCZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_UpdateFailHTLCZ { - 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 CVec_UpdateFailMalformedHTLCZ { - pub data: *mut crate::ln::msgs::UpdateFailMalformedHTLC, - pub datalen: usize -} -impl CVec_UpdateFailMalformedHTLCZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - 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 - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::ln::msgs::UpdateFailMalformedHTLC] { - unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_UpdateFailMalformedHTLCZ { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -pub extern "C" fn CVec_UpdateFailMalformedHTLCZ_free(_res: CVec_UpdateFailMalformedHTLCZ) { } -impl Drop for CVec_UpdateFailMalformedHTLCZ { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_UpdateFailMalformedHTLCZ { - 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 union CResult_AcceptChannelDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::AcceptChannel, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_AcceptChannelDecodeErrorZ { - pub contents: CResult_AcceptChannelDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_AcceptChannelDecodeErrorZ_ok(o: crate::ln::msgs::AcceptChannel) -> CResult_AcceptChannelDecodeErrorZ { - CResult_AcceptChannelDecodeErrorZ { - contents: CResult_AcceptChannelDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_AcceptChannelDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_AcceptChannelDecodeErrorZ { - CResult_AcceptChannelDecodeErrorZ { - contents: CResult_AcceptChannelDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_AcceptChannelDecodeErrorZ_free(_res: CResult_AcceptChannelDecodeErrorZ) { } -impl Drop for CResult_AcceptChannelDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_AcceptChannelDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_AcceptChannelDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_AcceptChannelDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_AcceptChannelDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_AcceptChannelDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_AcceptChannelDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_AcceptChannelDecodeErrorZ_clone(orig: &CResult_AcceptChannelDecodeErrorZ) -> CResult_AcceptChannelDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_AnnouncementSignaturesDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::AnnouncementSignatures, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_AnnouncementSignaturesDecodeErrorZ { - pub contents: CResult_AnnouncementSignaturesDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_AnnouncementSignaturesDecodeErrorZ_ok(o: crate::ln::msgs::AnnouncementSignatures) -> CResult_AnnouncementSignaturesDecodeErrorZ { - CResult_AnnouncementSignaturesDecodeErrorZ { - contents: CResult_AnnouncementSignaturesDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_AnnouncementSignaturesDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_AnnouncementSignaturesDecodeErrorZ { - CResult_AnnouncementSignaturesDecodeErrorZ { - contents: CResult_AnnouncementSignaturesDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_AnnouncementSignaturesDecodeErrorZ_free(_res: CResult_AnnouncementSignaturesDecodeErrorZ) { } -impl Drop for CResult_AnnouncementSignaturesDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_AnnouncementSignaturesDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_AnnouncementSignaturesDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_AnnouncementSignaturesDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_AnnouncementSignaturesDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_AnnouncementSignaturesDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_AnnouncementSignaturesDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_AnnouncementSignaturesDecodeErrorZ_clone(orig: &CResult_AnnouncementSignaturesDecodeErrorZ) -> CResult_AnnouncementSignaturesDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_ChannelReestablishDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::ChannelReestablish, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ChannelReestablishDecodeErrorZ { - pub contents: CResult_ChannelReestablishDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ChannelReestablishDecodeErrorZ_ok(o: crate::ln::msgs::ChannelReestablish) -> CResult_ChannelReestablishDecodeErrorZ { - CResult_ChannelReestablishDecodeErrorZ { - contents: CResult_ChannelReestablishDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelReestablishDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ChannelReestablishDecodeErrorZ { - CResult_ChannelReestablishDecodeErrorZ { - contents: CResult_ChannelReestablishDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelReestablishDecodeErrorZ_free(_res: CResult_ChannelReestablishDecodeErrorZ) { } -impl Drop for CResult_ChannelReestablishDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ChannelReestablishDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ChannelReestablishDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ChannelReestablishDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ChannelReestablishDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ChannelReestablishDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ChannelReestablishDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelReestablishDecodeErrorZ_clone(orig: &CResult_ChannelReestablishDecodeErrorZ) -> CResult_ChannelReestablishDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_ClosingSignedDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::ClosingSigned, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ClosingSignedDecodeErrorZ { - pub contents: CResult_ClosingSignedDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ClosingSignedDecodeErrorZ_ok(o: crate::ln::msgs::ClosingSigned) -> CResult_ClosingSignedDecodeErrorZ { - CResult_ClosingSignedDecodeErrorZ { - contents: CResult_ClosingSignedDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ClosingSignedDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ClosingSignedDecodeErrorZ { - CResult_ClosingSignedDecodeErrorZ { - contents: CResult_ClosingSignedDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ClosingSignedDecodeErrorZ_free(_res: CResult_ClosingSignedDecodeErrorZ) { } -impl Drop for CResult_ClosingSignedDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ClosingSignedDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ClosingSignedDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ClosingSignedDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ClosingSignedDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ClosingSignedDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ClosingSignedDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_ClosingSignedDecodeErrorZ_clone(orig: &CResult_ClosingSignedDecodeErrorZ) -> CResult_ClosingSignedDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_CommitmentSignedDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::CommitmentSigned, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_CommitmentSignedDecodeErrorZ { - pub contents: CResult_CommitmentSignedDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_CommitmentSignedDecodeErrorZ_ok(o: crate::ln::msgs::CommitmentSigned) -> CResult_CommitmentSignedDecodeErrorZ { - CResult_CommitmentSignedDecodeErrorZ { - contents: CResult_CommitmentSignedDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_CommitmentSignedDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_CommitmentSignedDecodeErrorZ { - CResult_CommitmentSignedDecodeErrorZ { - contents: CResult_CommitmentSignedDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_CommitmentSignedDecodeErrorZ_free(_res: CResult_CommitmentSignedDecodeErrorZ) { } -impl Drop for CResult_CommitmentSignedDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_CommitmentSignedDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_CommitmentSignedDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_CommitmentSignedDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_CommitmentSignedDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_CommitmentSignedDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_CommitmentSignedDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_CommitmentSignedDecodeErrorZ_clone(orig: &CResult_CommitmentSignedDecodeErrorZ) -> CResult_CommitmentSignedDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_FundingCreatedDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::FundingCreated, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_FundingCreatedDecodeErrorZ { - pub contents: CResult_FundingCreatedDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_FundingCreatedDecodeErrorZ_ok(o: crate::ln::msgs::FundingCreated) -> CResult_FundingCreatedDecodeErrorZ { - CResult_FundingCreatedDecodeErrorZ { - contents: CResult_FundingCreatedDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_FundingCreatedDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_FundingCreatedDecodeErrorZ { - CResult_FundingCreatedDecodeErrorZ { - contents: CResult_FundingCreatedDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_FundingCreatedDecodeErrorZ_free(_res: CResult_FundingCreatedDecodeErrorZ) { } -impl Drop for CResult_FundingCreatedDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_FundingCreatedDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_FundingCreatedDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_FundingCreatedDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_FundingCreatedDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_FundingCreatedDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_FundingCreatedDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_FundingCreatedDecodeErrorZ_clone(orig: &CResult_FundingCreatedDecodeErrorZ) -> CResult_FundingCreatedDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_FundingSignedDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::FundingSigned, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_FundingSignedDecodeErrorZ { - pub contents: CResult_FundingSignedDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_FundingSignedDecodeErrorZ_ok(o: crate::ln::msgs::FundingSigned) -> CResult_FundingSignedDecodeErrorZ { - CResult_FundingSignedDecodeErrorZ { - contents: CResult_FundingSignedDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_FundingSignedDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_FundingSignedDecodeErrorZ { - CResult_FundingSignedDecodeErrorZ { - contents: CResult_FundingSignedDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_FundingSignedDecodeErrorZ_free(_res: CResult_FundingSignedDecodeErrorZ) { } -impl Drop for CResult_FundingSignedDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_FundingSignedDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_FundingSignedDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_FundingSignedDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_FundingSignedDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_FundingSignedDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_FundingSignedDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_FundingSignedDecodeErrorZ_clone(orig: &CResult_FundingSignedDecodeErrorZ) -> CResult_FundingSignedDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_FundingLockedDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::FundingLocked, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_FundingLockedDecodeErrorZ { - pub contents: CResult_FundingLockedDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_FundingLockedDecodeErrorZ_ok(o: crate::ln::msgs::FundingLocked) -> CResult_FundingLockedDecodeErrorZ { - CResult_FundingLockedDecodeErrorZ { - contents: CResult_FundingLockedDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_FundingLockedDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_FundingLockedDecodeErrorZ { - CResult_FundingLockedDecodeErrorZ { - contents: CResult_FundingLockedDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_FundingLockedDecodeErrorZ_free(_res: CResult_FundingLockedDecodeErrorZ) { } -impl Drop for CResult_FundingLockedDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_FundingLockedDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_FundingLockedDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_FundingLockedDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_FundingLockedDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_FundingLockedDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_FundingLockedDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_FundingLockedDecodeErrorZ_clone(orig: &CResult_FundingLockedDecodeErrorZ) -> CResult_FundingLockedDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_InitDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::Init, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_InitDecodeErrorZ { - pub contents: CResult_InitDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_InitDecodeErrorZ_ok(o: crate::ln::msgs::Init) -> CResult_InitDecodeErrorZ { - CResult_InitDecodeErrorZ { - contents: CResult_InitDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_InitDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_InitDecodeErrorZ { - CResult_InitDecodeErrorZ { - contents: CResult_InitDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_InitDecodeErrorZ_free(_res: CResult_InitDecodeErrorZ) { } -impl Drop for CResult_InitDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_InitDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_InitDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_InitDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_InitDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_InitDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_InitDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_InitDecodeErrorZ_clone(orig: &CResult_InitDecodeErrorZ) -> CResult_InitDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_OpenChannelDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::OpenChannel, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_OpenChannelDecodeErrorZ { - pub contents: CResult_OpenChannelDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_OpenChannelDecodeErrorZ_ok(o: crate::ln::msgs::OpenChannel) -> CResult_OpenChannelDecodeErrorZ { - CResult_OpenChannelDecodeErrorZ { - contents: CResult_OpenChannelDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_OpenChannelDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_OpenChannelDecodeErrorZ { - CResult_OpenChannelDecodeErrorZ { - contents: CResult_OpenChannelDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_OpenChannelDecodeErrorZ_free(_res: CResult_OpenChannelDecodeErrorZ) { } -impl Drop for CResult_OpenChannelDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_OpenChannelDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_OpenChannelDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_OpenChannelDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_OpenChannelDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_OpenChannelDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_OpenChannelDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_OpenChannelDecodeErrorZ_clone(orig: &CResult_OpenChannelDecodeErrorZ) -> CResult_OpenChannelDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_RevokeAndACKDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::RevokeAndACK, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_RevokeAndACKDecodeErrorZ { - pub contents: CResult_RevokeAndACKDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_RevokeAndACKDecodeErrorZ_ok(o: crate::ln::msgs::RevokeAndACK) -> CResult_RevokeAndACKDecodeErrorZ { - CResult_RevokeAndACKDecodeErrorZ { - contents: CResult_RevokeAndACKDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_RevokeAndACKDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_RevokeAndACKDecodeErrorZ { - CResult_RevokeAndACKDecodeErrorZ { - contents: CResult_RevokeAndACKDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_RevokeAndACKDecodeErrorZ_free(_res: CResult_RevokeAndACKDecodeErrorZ) { } -impl Drop for CResult_RevokeAndACKDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_RevokeAndACKDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_RevokeAndACKDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_RevokeAndACKDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_RevokeAndACKDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_RevokeAndACKDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_RevokeAndACKDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_RevokeAndACKDecodeErrorZ_clone(orig: &CResult_RevokeAndACKDecodeErrorZ) -> CResult_RevokeAndACKDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_ShutdownDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::Shutdown, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ShutdownDecodeErrorZ { - pub contents: CResult_ShutdownDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ShutdownDecodeErrorZ_ok(o: crate::ln::msgs::Shutdown) -> CResult_ShutdownDecodeErrorZ { - CResult_ShutdownDecodeErrorZ { - contents: CResult_ShutdownDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ShutdownDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ShutdownDecodeErrorZ { - CResult_ShutdownDecodeErrorZ { - contents: CResult_ShutdownDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ShutdownDecodeErrorZ_free(_res: CResult_ShutdownDecodeErrorZ) { } -impl Drop for CResult_ShutdownDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ShutdownDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ShutdownDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ShutdownDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ShutdownDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ShutdownDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ShutdownDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_ShutdownDecodeErrorZ_clone(orig: &CResult_ShutdownDecodeErrorZ) -> CResult_ShutdownDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_UpdateFailHTLCDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::UpdateFailHTLC, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_UpdateFailHTLCDecodeErrorZ { - pub contents: CResult_UpdateFailHTLCDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFailHTLCDecodeErrorZ_ok(o: crate::ln::msgs::UpdateFailHTLC) -> CResult_UpdateFailHTLCDecodeErrorZ { - CResult_UpdateFailHTLCDecodeErrorZ { - contents: CResult_UpdateFailHTLCDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFailHTLCDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_UpdateFailHTLCDecodeErrorZ { - CResult_UpdateFailHTLCDecodeErrorZ { - contents: CResult_UpdateFailHTLCDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFailHTLCDecodeErrorZ_free(_res: CResult_UpdateFailHTLCDecodeErrorZ) { } -impl Drop for CResult_UpdateFailHTLCDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_UpdateFailHTLCDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_UpdateFailHTLCDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_UpdateFailHTLCDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_UpdateFailHTLCDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_UpdateFailHTLCDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_UpdateFailHTLCDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFailHTLCDecodeErrorZ_clone(orig: &CResult_UpdateFailHTLCDecodeErrorZ) -> CResult_UpdateFailHTLCDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_UpdateFailMalformedHTLCDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::UpdateFailMalformedHTLC, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_UpdateFailMalformedHTLCDecodeErrorZ { - pub contents: CResult_UpdateFailMalformedHTLCDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFailMalformedHTLCDecodeErrorZ_ok(o: crate::ln::msgs::UpdateFailMalformedHTLC) -> CResult_UpdateFailMalformedHTLCDecodeErrorZ { - CResult_UpdateFailMalformedHTLCDecodeErrorZ { - contents: CResult_UpdateFailMalformedHTLCDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFailMalformedHTLCDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_UpdateFailMalformedHTLCDecodeErrorZ { - CResult_UpdateFailMalformedHTLCDecodeErrorZ { - contents: CResult_UpdateFailMalformedHTLCDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFailMalformedHTLCDecodeErrorZ_free(_res: CResult_UpdateFailMalformedHTLCDecodeErrorZ) { } -impl Drop for CResult_UpdateFailMalformedHTLCDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_UpdateFailMalformedHTLCDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_UpdateFailMalformedHTLCDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_UpdateFailMalformedHTLCDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_UpdateFailMalformedHTLCDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_UpdateFailMalformedHTLCDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_UpdateFailMalformedHTLCDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFailMalformedHTLCDecodeErrorZ_clone(orig: &CResult_UpdateFailMalformedHTLCDecodeErrorZ) -> CResult_UpdateFailMalformedHTLCDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_UpdateFeeDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::UpdateFee, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_UpdateFeeDecodeErrorZ { - pub contents: CResult_UpdateFeeDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFeeDecodeErrorZ_ok(o: crate::ln::msgs::UpdateFee) -> CResult_UpdateFeeDecodeErrorZ { - CResult_UpdateFeeDecodeErrorZ { - contents: CResult_UpdateFeeDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFeeDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_UpdateFeeDecodeErrorZ { - CResult_UpdateFeeDecodeErrorZ { - contents: CResult_UpdateFeeDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFeeDecodeErrorZ_free(_res: CResult_UpdateFeeDecodeErrorZ) { } -impl Drop for CResult_UpdateFeeDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_UpdateFeeDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_UpdateFeeDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_UpdateFeeDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_UpdateFeeDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_UpdateFeeDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_UpdateFeeDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFeeDecodeErrorZ_clone(orig: &CResult_UpdateFeeDecodeErrorZ) -> CResult_UpdateFeeDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_UpdateFulfillHTLCDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::UpdateFulfillHTLC, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_UpdateFulfillHTLCDecodeErrorZ { - pub contents: CResult_UpdateFulfillHTLCDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFulfillHTLCDecodeErrorZ_ok(o: crate::ln::msgs::UpdateFulfillHTLC) -> CResult_UpdateFulfillHTLCDecodeErrorZ { - CResult_UpdateFulfillHTLCDecodeErrorZ { - contents: CResult_UpdateFulfillHTLCDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFulfillHTLCDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_UpdateFulfillHTLCDecodeErrorZ { - CResult_UpdateFulfillHTLCDecodeErrorZ { - contents: CResult_UpdateFulfillHTLCDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFulfillHTLCDecodeErrorZ_free(_res: CResult_UpdateFulfillHTLCDecodeErrorZ) { } -impl Drop for CResult_UpdateFulfillHTLCDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_UpdateFulfillHTLCDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_UpdateFulfillHTLCDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_UpdateFulfillHTLCDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_UpdateFulfillHTLCDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_UpdateFulfillHTLCDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_UpdateFulfillHTLCDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateFulfillHTLCDecodeErrorZ_clone(orig: &CResult_UpdateFulfillHTLCDecodeErrorZ) -> CResult_UpdateFulfillHTLCDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_UpdateAddHTLCDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::UpdateAddHTLC, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_UpdateAddHTLCDecodeErrorZ { - pub contents: CResult_UpdateAddHTLCDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_UpdateAddHTLCDecodeErrorZ_ok(o: crate::ln::msgs::UpdateAddHTLC) -> CResult_UpdateAddHTLCDecodeErrorZ { - CResult_UpdateAddHTLCDecodeErrorZ { - contents: CResult_UpdateAddHTLCDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateAddHTLCDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_UpdateAddHTLCDecodeErrorZ { - CResult_UpdateAddHTLCDecodeErrorZ { - contents: CResult_UpdateAddHTLCDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateAddHTLCDecodeErrorZ_free(_res: CResult_UpdateAddHTLCDecodeErrorZ) { } -impl Drop for CResult_UpdateAddHTLCDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_UpdateAddHTLCDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_UpdateAddHTLCDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_UpdateAddHTLCDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_UpdateAddHTLCDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_UpdateAddHTLCDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_UpdateAddHTLCDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_UpdateAddHTLCDecodeErrorZ_clone(orig: &CResult_UpdateAddHTLCDecodeErrorZ) -> CResult_UpdateAddHTLCDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_PingDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::Ping, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_PingDecodeErrorZ { - pub contents: CResult_PingDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_PingDecodeErrorZ_ok(o: crate::ln::msgs::Ping) -> CResult_PingDecodeErrorZ { - CResult_PingDecodeErrorZ { - contents: CResult_PingDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_PingDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_PingDecodeErrorZ { - CResult_PingDecodeErrorZ { - contents: CResult_PingDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_PingDecodeErrorZ_free(_res: CResult_PingDecodeErrorZ) { } -impl Drop for CResult_PingDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_PingDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_PingDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_PingDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_PingDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_PingDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_PingDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_PingDecodeErrorZ_clone(orig: &CResult_PingDecodeErrorZ) -> CResult_PingDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_PongDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::Pong, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_PongDecodeErrorZ { - pub contents: CResult_PongDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_PongDecodeErrorZ_ok(o: crate::ln::msgs::Pong) -> CResult_PongDecodeErrorZ { - CResult_PongDecodeErrorZ { - contents: CResult_PongDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_PongDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_PongDecodeErrorZ { - CResult_PongDecodeErrorZ { - contents: CResult_PongDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_PongDecodeErrorZ_free(_res: CResult_PongDecodeErrorZ) { } -impl Drop for CResult_PongDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_PongDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_PongDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_PongDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_PongDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_PongDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_PongDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_PongDecodeErrorZ_clone(orig: &CResult_PongDecodeErrorZ) -> CResult_PongDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_UnsignedChannelAnnouncementDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::UnsignedChannelAnnouncement, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_UnsignedChannelAnnouncementDecodeErrorZ { - pub contents: CResult_UnsignedChannelAnnouncementDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_UnsignedChannelAnnouncementDecodeErrorZ_ok(o: crate::ln::msgs::UnsignedChannelAnnouncement) -> CResult_UnsignedChannelAnnouncementDecodeErrorZ { - CResult_UnsignedChannelAnnouncementDecodeErrorZ { - contents: CResult_UnsignedChannelAnnouncementDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_UnsignedChannelAnnouncementDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_UnsignedChannelAnnouncementDecodeErrorZ { - CResult_UnsignedChannelAnnouncementDecodeErrorZ { - contents: CResult_UnsignedChannelAnnouncementDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_UnsignedChannelAnnouncementDecodeErrorZ_free(_res: CResult_UnsignedChannelAnnouncementDecodeErrorZ) { } -impl Drop for CResult_UnsignedChannelAnnouncementDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_UnsignedChannelAnnouncementDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_UnsignedChannelAnnouncementDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_UnsignedChannelAnnouncementDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_UnsignedChannelAnnouncementDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_UnsignedChannelAnnouncementDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_UnsignedChannelAnnouncementDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_UnsignedChannelAnnouncementDecodeErrorZ_clone(orig: &CResult_UnsignedChannelAnnouncementDecodeErrorZ) -> CResult_UnsignedChannelAnnouncementDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_ChannelAnnouncementDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::ChannelAnnouncement, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ChannelAnnouncementDecodeErrorZ { - pub contents: CResult_ChannelAnnouncementDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ChannelAnnouncementDecodeErrorZ_ok(o: crate::ln::msgs::ChannelAnnouncement) -> CResult_ChannelAnnouncementDecodeErrorZ { - CResult_ChannelAnnouncementDecodeErrorZ { - contents: CResult_ChannelAnnouncementDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelAnnouncementDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ChannelAnnouncementDecodeErrorZ { - CResult_ChannelAnnouncementDecodeErrorZ { - contents: CResult_ChannelAnnouncementDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelAnnouncementDecodeErrorZ_free(_res: CResult_ChannelAnnouncementDecodeErrorZ) { } -impl Drop for CResult_ChannelAnnouncementDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ChannelAnnouncementDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ChannelAnnouncementDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ChannelAnnouncementDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ChannelAnnouncementDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ChannelAnnouncementDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ChannelAnnouncementDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelAnnouncementDecodeErrorZ_clone(orig: &CResult_ChannelAnnouncementDecodeErrorZ) -> CResult_ChannelAnnouncementDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_UnsignedChannelUpdateDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::UnsignedChannelUpdate, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_UnsignedChannelUpdateDecodeErrorZ { - pub contents: CResult_UnsignedChannelUpdateDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_UnsignedChannelUpdateDecodeErrorZ_ok(o: crate::ln::msgs::UnsignedChannelUpdate) -> CResult_UnsignedChannelUpdateDecodeErrorZ { - CResult_UnsignedChannelUpdateDecodeErrorZ { - contents: CResult_UnsignedChannelUpdateDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_UnsignedChannelUpdateDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_UnsignedChannelUpdateDecodeErrorZ { - CResult_UnsignedChannelUpdateDecodeErrorZ { - contents: CResult_UnsignedChannelUpdateDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_UnsignedChannelUpdateDecodeErrorZ_free(_res: CResult_UnsignedChannelUpdateDecodeErrorZ) { } -impl Drop for CResult_UnsignedChannelUpdateDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_UnsignedChannelUpdateDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_UnsignedChannelUpdateDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_UnsignedChannelUpdateDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_UnsignedChannelUpdateDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_UnsignedChannelUpdateDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_UnsignedChannelUpdateDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_UnsignedChannelUpdateDecodeErrorZ_clone(orig: &CResult_UnsignedChannelUpdateDecodeErrorZ) -> CResult_UnsignedChannelUpdateDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_ChannelUpdateDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::ChannelUpdate, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ChannelUpdateDecodeErrorZ { - pub contents: CResult_ChannelUpdateDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ChannelUpdateDecodeErrorZ_ok(o: crate::ln::msgs::ChannelUpdate) -> CResult_ChannelUpdateDecodeErrorZ { - CResult_ChannelUpdateDecodeErrorZ { - contents: CResult_ChannelUpdateDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelUpdateDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ChannelUpdateDecodeErrorZ { - CResult_ChannelUpdateDecodeErrorZ { - contents: CResult_ChannelUpdateDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelUpdateDecodeErrorZ_free(_res: CResult_ChannelUpdateDecodeErrorZ) { } -impl Drop for CResult_ChannelUpdateDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ChannelUpdateDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ChannelUpdateDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ChannelUpdateDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ChannelUpdateDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ChannelUpdateDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ChannelUpdateDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_ChannelUpdateDecodeErrorZ_clone(orig: &CResult_ChannelUpdateDecodeErrorZ) -> CResult_ChannelUpdateDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_ErrorMessageDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::ErrorMessage, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ErrorMessageDecodeErrorZ { - pub contents: CResult_ErrorMessageDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ErrorMessageDecodeErrorZ_ok(o: crate::ln::msgs::ErrorMessage) -> CResult_ErrorMessageDecodeErrorZ { - CResult_ErrorMessageDecodeErrorZ { - contents: CResult_ErrorMessageDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ErrorMessageDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ErrorMessageDecodeErrorZ { - CResult_ErrorMessageDecodeErrorZ { - contents: CResult_ErrorMessageDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ErrorMessageDecodeErrorZ_free(_res: CResult_ErrorMessageDecodeErrorZ) { } -impl Drop for CResult_ErrorMessageDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ErrorMessageDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ErrorMessageDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ErrorMessageDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ErrorMessageDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ErrorMessageDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ErrorMessageDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_ErrorMessageDecodeErrorZ_clone(orig: &CResult_ErrorMessageDecodeErrorZ) -> CResult_ErrorMessageDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_UnsignedNodeAnnouncementDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::UnsignedNodeAnnouncement, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_UnsignedNodeAnnouncementDecodeErrorZ { - pub contents: CResult_UnsignedNodeAnnouncementDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_UnsignedNodeAnnouncementDecodeErrorZ_ok(o: crate::ln::msgs::UnsignedNodeAnnouncement) -> CResult_UnsignedNodeAnnouncementDecodeErrorZ { - CResult_UnsignedNodeAnnouncementDecodeErrorZ { - contents: CResult_UnsignedNodeAnnouncementDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_UnsignedNodeAnnouncementDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_UnsignedNodeAnnouncementDecodeErrorZ { - CResult_UnsignedNodeAnnouncementDecodeErrorZ { - contents: CResult_UnsignedNodeAnnouncementDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(_res: CResult_UnsignedNodeAnnouncementDecodeErrorZ) { } -impl Drop for CResult_UnsignedNodeAnnouncementDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_UnsignedNodeAnnouncementDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_UnsignedNodeAnnouncementDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_UnsignedNodeAnnouncementDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_UnsignedNodeAnnouncementDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_UnsignedNodeAnnouncementDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_UnsignedNodeAnnouncementDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_UnsignedNodeAnnouncementDecodeErrorZ_clone(orig: &CResult_UnsignedNodeAnnouncementDecodeErrorZ) -> CResult_UnsignedNodeAnnouncementDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_NodeAnnouncementDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::NodeAnnouncement, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_NodeAnnouncementDecodeErrorZ { - pub contents: CResult_NodeAnnouncementDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_NodeAnnouncementDecodeErrorZ_ok(o: crate::ln::msgs::NodeAnnouncement) -> CResult_NodeAnnouncementDecodeErrorZ { - CResult_NodeAnnouncementDecodeErrorZ { - contents: CResult_NodeAnnouncementDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_NodeAnnouncementDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_NodeAnnouncementDecodeErrorZ { - CResult_NodeAnnouncementDecodeErrorZ { - contents: CResult_NodeAnnouncementDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_NodeAnnouncementDecodeErrorZ_free(_res: CResult_NodeAnnouncementDecodeErrorZ) { } -impl Drop for CResult_NodeAnnouncementDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_NodeAnnouncementDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_NodeAnnouncementDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_NodeAnnouncementDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_NodeAnnouncementDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_NodeAnnouncementDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_NodeAnnouncementDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_NodeAnnouncementDecodeErrorZ_clone(orig: &CResult_NodeAnnouncementDecodeErrorZ) -> CResult_NodeAnnouncementDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_QueryShortChannelIdsDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::QueryShortChannelIds, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_QueryShortChannelIdsDecodeErrorZ { - pub contents: CResult_QueryShortChannelIdsDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_QueryShortChannelIdsDecodeErrorZ_ok(o: crate::ln::msgs::QueryShortChannelIds) -> CResult_QueryShortChannelIdsDecodeErrorZ { - CResult_QueryShortChannelIdsDecodeErrorZ { - contents: CResult_QueryShortChannelIdsDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_QueryShortChannelIdsDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_QueryShortChannelIdsDecodeErrorZ { - CResult_QueryShortChannelIdsDecodeErrorZ { - contents: CResult_QueryShortChannelIdsDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_QueryShortChannelIdsDecodeErrorZ_free(_res: CResult_QueryShortChannelIdsDecodeErrorZ) { } -impl Drop for CResult_QueryShortChannelIdsDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_QueryShortChannelIdsDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_QueryShortChannelIdsDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_QueryShortChannelIdsDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_QueryShortChannelIdsDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_QueryShortChannelIdsDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_QueryShortChannelIdsDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_QueryShortChannelIdsDecodeErrorZ_clone(orig: &CResult_QueryShortChannelIdsDecodeErrorZ) -> CResult_QueryShortChannelIdsDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_ReplyShortChannelIdsEndDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::ReplyShortChannelIdsEnd, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ReplyShortChannelIdsEndDecodeErrorZ { - pub contents: CResult_ReplyShortChannelIdsEndDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ReplyShortChannelIdsEndDecodeErrorZ_ok(o: crate::ln::msgs::ReplyShortChannelIdsEnd) -> CResult_ReplyShortChannelIdsEndDecodeErrorZ { - CResult_ReplyShortChannelIdsEndDecodeErrorZ { - contents: CResult_ReplyShortChannelIdsEndDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ReplyShortChannelIdsEndDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ReplyShortChannelIdsEndDecodeErrorZ { - CResult_ReplyShortChannelIdsEndDecodeErrorZ { - contents: CResult_ReplyShortChannelIdsEndDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ReplyShortChannelIdsEndDecodeErrorZ_free(_res: CResult_ReplyShortChannelIdsEndDecodeErrorZ) { } -impl Drop for CResult_ReplyShortChannelIdsEndDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ReplyShortChannelIdsEndDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ReplyShortChannelIdsEndDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ReplyShortChannelIdsEndDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ReplyShortChannelIdsEndDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ReplyShortChannelIdsEndDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ReplyShortChannelIdsEndDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_ReplyShortChannelIdsEndDecodeErrorZ_clone(orig: &CResult_ReplyShortChannelIdsEndDecodeErrorZ) -> CResult_ReplyShortChannelIdsEndDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_QueryChannelRangeDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::QueryChannelRange, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_QueryChannelRangeDecodeErrorZ { - pub contents: CResult_QueryChannelRangeDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_QueryChannelRangeDecodeErrorZ_ok(o: crate::ln::msgs::QueryChannelRange) -> CResult_QueryChannelRangeDecodeErrorZ { - CResult_QueryChannelRangeDecodeErrorZ { - contents: CResult_QueryChannelRangeDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_QueryChannelRangeDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_QueryChannelRangeDecodeErrorZ { - CResult_QueryChannelRangeDecodeErrorZ { - contents: CResult_QueryChannelRangeDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_QueryChannelRangeDecodeErrorZ_free(_res: CResult_QueryChannelRangeDecodeErrorZ) { } -impl Drop for CResult_QueryChannelRangeDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_QueryChannelRangeDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_QueryChannelRangeDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_QueryChannelRangeDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_QueryChannelRangeDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_QueryChannelRangeDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_QueryChannelRangeDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_QueryChannelRangeDecodeErrorZ_clone(orig: &CResult_QueryChannelRangeDecodeErrorZ) -> CResult_QueryChannelRangeDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_ReplyChannelRangeDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::ReplyChannelRange, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_ReplyChannelRangeDecodeErrorZ { - pub contents: CResult_ReplyChannelRangeDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_ReplyChannelRangeDecodeErrorZ_ok(o: crate::ln::msgs::ReplyChannelRange) -> CResult_ReplyChannelRangeDecodeErrorZ { - CResult_ReplyChannelRangeDecodeErrorZ { - contents: CResult_ReplyChannelRangeDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_ReplyChannelRangeDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_ReplyChannelRangeDecodeErrorZ { - CResult_ReplyChannelRangeDecodeErrorZ { - contents: CResult_ReplyChannelRangeDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_ReplyChannelRangeDecodeErrorZ_free(_res: CResult_ReplyChannelRangeDecodeErrorZ) { } -impl Drop for CResult_ReplyChannelRangeDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_ReplyChannelRangeDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_ReplyChannelRangeDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_ReplyChannelRangeDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_ReplyChannelRangeDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_ReplyChannelRangeDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_ReplyChannelRangeDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_ReplyChannelRangeDecodeErrorZ_clone(orig: &CResult_ReplyChannelRangeDecodeErrorZ) -> CResult_ReplyChannelRangeDecodeErrorZ { orig.clone() } -#[repr(C)] -pub union CResult_GossipTimestampFilterDecodeErrorZPtr { - pub result: *mut crate::ln::msgs::GossipTimestampFilter, - pub err: *mut crate::ln::msgs::DecodeError, -} -#[repr(C)] -pub struct CResult_GossipTimestampFilterDecodeErrorZ { - pub contents: CResult_GossipTimestampFilterDecodeErrorZPtr, - pub result_ok: bool, -} -#[no_mangle] -pub extern "C" fn CResult_GossipTimestampFilterDecodeErrorZ_ok(o: crate::ln::msgs::GossipTimestampFilter) -> CResult_GossipTimestampFilterDecodeErrorZ { - CResult_GossipTimestampFilterDecodeErrorZ { - contents: CResult_GossipTimestampFilterDecodeErrorZPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } -} -#[no_mangle] -pub extern "C" fn CResult_GossipTimestampFilterDecodeErrorZ_err(e: crate::ln::msgs::DecodeError) -> CResult_GossipTimestampFilterDecodeErrorZ { - CResult_GossipTimestampFilterDecodeErrorZ { - contents: CResult_GossipTimestampFilterDecodeErrorZPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } -} -#[no_mangle] -pub extern "C" fn CResult_GossipTimestampFilterDecodeErrorZ_free(_res: CResult_GossipTimestampFilterDecodeErrorZ) { } -impl Drop for CResult_GossipTimestampFilterDecodeErrorZ { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !(self.contents.result as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.result) }; - } - } else { - if unsafe { !(self.contents.err as *mut ()).is_null() } { - let _ = unsafe { Box::from_raw(self.contents.err) }; - } - } - } -} -impl From> for CResult_GossipTimestampFilterDecodeErrorZ { - fn from(mut o: crate::c_types::CResultTempl) -> Self { - let contents = if o.result_ok { - let result = unsafe { o.contents.result }; - unsafe { o.contents.result = std::ptr::null_mut() }; - CResult_GossipTimestampFilterDecodeErrorZPtr { result } - } else { - let err = unsafe { o.contents.err }; - unsafe { o.contents.err = std::ptr::null_mut(); } - CResult_GossipTimestampFilterDecodeErrorZPtr { err } - }; - Self { - contents, - result_ok: o.result_ok, - } - } -} -impl Clone for CResult_GossipTimestampFilterDecodeErrorZ { - fn clone(&self) -> Self { - if self.result_ok { - Self { result_ok: true, contents: CResult_GossipTimestampFilterDecodeErrorZPtr { - result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) - } } - } else { - Self { result_ok: false, contents: CResult_GossipTimestampFilterDecodeErrorZPtr { - err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) - } } - } - } -} -#[no_mangle] -pub extern "C" fn CResult_GossipTimestampFilterDecodeErrorZ_clone(orig: &CResult_GossipTimestampFilterDecodeErrorZ) -> CResult_GossipTimestampFilterDecodeErrorZ { orig.clone() } diff --git a/lightning-c-bindings/src/c_types/mod.rs b/lightning-c-bindings/src/c_types/mod.rs deleted file mode 100644 index 0a96f3e7d..000000000 --- a/lightning-c-bindings/src/c_types/mod.rs +++ /dev/null @@ -1,319 +0,0 @@ -pub mod derived; - -use bitcoin::Script as BitcoinScript; -use bitcoin::Transaction as BitcoinTransaction; -use bitcoin::hashes::Hash; -use bitcoin::secp256k1::key::PublicKey as SecpPublicKey; -use bitcoin::secp256k1::key::SecretKey as SecpSecretKey; -use bitcoin::secp256k1::Signature as SecpSignature; -use bitcoin::secp256k1::Error as SecpError; - -use std::convert::TryInto; // Bindings need at least rustc 1.34 - -#[derive(Clone)] -#[repr(C)] -pub struct PublicKey { - pub compressed_form: [u8; 33], -} -impl PublicKey { - pub(crate) fn from_rust(pk: &SecpPublicKey) -> Self { - Self { - compressed_form: pk.serialize(), - } - } - pub(crate) fn into_rust(&self) -> SecpPublicKey { - SecpPublicKey::from_slice(&self.compressed_form).unwrap() - } - pub(crate) fn is_null(&self) -> bool { self.compressed_form[..] == [0; 33][..] } - pub(crate) fn null() -> Self { Self { compressed_form: [0; 33] } } -} - -#[repr(C)] -pub struct SecretKey { - pub bytes: [u8; 32], -} -impl SecretKey { - // from_rust isn't implemented for a ref since we just return byte array refs directly - pub(crate) fn from_rust(sk: SecpSecretKey) -> Self { - let mut bytes = [0; 32]; - bytes.copy_from_slice(&sk[..]); - Self { bytes } - } - pub(crate) fn into_rust(&self) -> SecpSecretKey { - SecpSecretKey::from_slice(&self.bytes).unwrap() - } -} - -#[repr(C)] -#[derive(Clone)] -pub struct Signature { - pub compact_form: [u8; 64], -} -impl Signature { - pub(crate) fn from_rust(pk: &SecpSignature) -> Self { - Self { - compact_form: pk.serialize_compact(), - } - } - pub(crate) fn into_rust(&self) -> SecpSignature { - SecpSignature::from_compact(&self.compact_form).unwrap() - } - // The following are used for Option which we support, but don't use anymore - #[allow(unused)] pub(crate) fn is_null(&self) -> bool { self.compact_form[..] == [0; 64][..] } - #[allow(unused)] pub(crate) fn null() -> Self { Self { compact_form: [0; 64] } } -} - -#[repr(C)] -pub enum Secp256k1Error { - IncorrectSignature, - InvalidMessage, - InvalidPublicKey, - InvalidSignature, - InvalidSecretKey, - InvalidRecoveryId, - InvalidTweak, - TweakCheckFailed, - NotEnoughMemory, -} -impl Secp256k1Error { - pub(crate) fn from_rust(err: SecpError) -> Self { - match err { - SecpError::IncorrectSignature => Secp256k1Error::IncorrectSignature, - SecpError::InvalidMessage => Secp256k1Error::InvalidMessage, - SecpError::InvalidPublicKey => Secp256k1Error::InvalidPublicKey, - SecpError::InvalidSignature => Secp256k1Error::InvalidSignature, - SecpError::InvalidSecretKey => Secp256k1Error::InvalidSecretKey, - SecpError::InvalidRecoveryId => Secp256k1Error::InvalidRecoveryId, - SecpError::InvalidTweak => Secp256k1Error::InvalidTweak, - SecpError::TweakCheckFailed => Secp256k1Error::TweakCheckFailed, - SecpError::NotEnoughMemory => Secp256k1Error::NotEnoughMemory, - } - } -} - -#[repr(C)] -/// A serialized transaction, in (pointer, length) form. -/// -/// This type optionally owns its own memory, and thus the semantics around access change based on -/// the `data_is_owned` flag. If `data_is_owned` is set, you must call `Transaction_free` to free -/// the underlying buffer before the object goes out of scope. If `data_is_owned` is not set, any -/// access to the buffer after the scope in which the object was provided to you is invalid. eg, -/// access after you return from the call in which a `!data_is_owned` `Transaction` is provided to -/// you would be invalid. -/// -/// Note that, while it may change in the future, because transactions on the Rust side are stored -/// in a deserialized form, all `Transaction`s generated on the Rust side will have `data_is_owned` -/// set. Similarly, while it may change in the future, all `Transaction`s you pass to Rust may have -/// `data_is_owned` either set or unset at your discretion. -pub struct Transaction { - /// This is non-const for your convenience, an object passed to Rust is never written to. - pub data: *mut u8, - pub datalen: usize, - pub data_is_owned: bool, -} -impl Transaction { - pub(crate) fn into_bitcoin(&self) -> BitcoinTransaction { - if self.datalen == 0 { panic!("0-length buffer can never represent a valid Transaction"); } - ::bitcoin::consensus::encode::deserialize(unsafe { std::slice::from_raw_parts(self.data, self.datalen) }).unwrap() - } - pub(crate) fn from_vec(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { - data: unsafe { (*data).as_mut_ptr() }, - datalen, - data_is_owned: true, - } - } -} -impl Drop for Transaction { - fn drop(&mut self) { - if self.data_is_owned && self.datalen != 0 { - let _ = derived::CVec_u8Z { data: self.data as *mut u8, datalen: self.datalen }; - } - } -} -#[no_mangle] -pub extern "C" fn Transaction_free(_res: Transaction) { } - -pub(crate) fn bitcoin_to_C_outpoint(outpoint: ::bitcoin::blockdata::transaction::OutPoint) -> crate::chain::transaction::OutPoint { - crate::chain::transaction::OutPoint_new(ThirtyTwoBytes { data: outpoint.txid.into_inner() }, outpoint.vout.try_into().unwrap()) -} - -#[repr(C)] -#[derive(Clone)] -/// A transaction output including a scriptPubKey and value. -/// This type *does* own its own memory, so must be free'd appropriately. -pub struct TxOut { - pub script_pubkey: derived::CVec_u8Z, - pub value: u64, -} - -impl TxOut { - pub(crate) fn into_rust(mut self) -> ::bitcoin::blockdata::transaction::TxOut { - ::bitcoin::blockdata::transaction::TxOut { - script_pubkey: self.script_pubkey.into_rust().into(), - value: self.value, - } - } - pub(crate) fn from_rust(txout: ::bitcoin::blockdata::transaction::TxOut) -> Self { - Self { - script_pubkey: derived::CVec_u8Z::from(txout.script_pubkey.into_bytes()), - value: txout.value - } - } -} -#[no_mangle] -pub extern "C" fn TxOut_free(_res: TxOut) { } -#[no_mangle] -pub extern "C" fn TxOut_clone(orig: &TxOut) -> TxOut { orig.clone() } - -#[repr(C)] -pub struct u8slice { - pub data: *const u8, - pub datalen: usize -} -impl u8slice { - pub(crate) fn from_slice(s: &[u8]) -> Self { - Self { - data: s.as_ptr(), - datalen: s.len(), - } - } - pub(crate) fn to_slice(&self) -> &[u8] { - if self.datalen == 0 { return &[]; } - unsafe { std::slice::from_raw_parts(self.data, self.datalen) } - } -} - -#[repr(C)] -#[derive(Copy, Clone)] -/// Arbitrary 32 bytes, which could represent one of a few different things. You probably want to -/// look up the corresponding function in rust-lightning's docs. -pub struct ThirtyTwoBytes { - pub data: [u8; 32], -} -impl ThirtyTwoBytes { - pub(crate) fn null() -> Self { - Self { data: [0; 32] } - } -} - -#[repr(C)] -pub struct ThreeBytes { pub data: [u8; 3], } -#[derive(Clone)] -#[repr(C)] -pub struct FourBytes { pub data: [u8; 4], } -#[derive(Clone)] -#[repr(C)] -pub struct TenBytes { pub data: [u8; 10], } -#[derive(Clone)] -#[repr(C)] -pub struct SixteenBytes { pub data: [u8; 16], } - -pub(crate) struct VecWriter(pub Vec); -impl lightning::util::ser::Writer for VecWriter { - fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> { - self.0.extend_from_slice(buf); - Ok(()) - } - fn size_hint(&mut self, size: usize) { - self.0.reserve_exact(size); - } -} -pub(crate) fn serialize_obj(i: &I) -> derived::CVec_u8Z { - let mut out = VecWriter(Vec::new()); - i.write(&mut out).unwrap(); - derived::CVec_u8Z::from(out.0) -} -pub(crate) fn deserialize_obj(s: u8slice) -> Result { - I::read(&mut s.to_slice()) -} -pub(crate) fn deserialize_obj_arg>(s: u8slice, args: A) -> Result { - I::read(&mut s.to_slice(), args) -} - -#[repr(C)] -#[derive(Copy, Clone)] -/// A Rust str object, ie a reference to a UTF8-valid string. -/// This is *not* null-terminated so cannot be used directly as a C string! -pub struct Str { - pub chars: *const u8, - pub len: usize -} -impl Into for &'static str { - fn into(self) -> Str { - Str { chars: self.as_ptr(), len: self.len() } - } -} -impl Into<&'static str> for Str { - fn into(self) -> &'static str { - if self.len == 0 { return ""; } - std::str::from_utf8(unsafe { std::slice::from_raw_parts(self.chars, self.len) }).unwrap() - } -} - -// Note that the C++ headers memset(0) all the Templ types to avoid deallocation! -// Thus, they must gracefully handle being completely null in _free. - -// TODO: Integer/bool primitives should avoid the pointer indirection for underlying types -// everywhere in the containers. - -#[repr(C)] -pub(crate) union CResultPtr { - pub(crate) result: *mut O, - pub(crate) err: *mut E, -} -#[repr(C)] -pub(crate) struct CResultTempl { - pub(crate) contents: CResultPtr, - pub(crate) result_ok: bool, -} -impl CResultTempl { - pub(crate) extern "C" fn ok(o: O) -> Self { - CResultTempl { - contents: CResultPtr { - result: Box::into_raw(Box::new(o)), - }, - result_ok: true, - } - } - pub(crate) extern "C" fn err(e: E) -> Self { - CResultTempl { - contents: CResultPtr { - err: Box::into_raw(Box::new(e)), - }, - result_ok: false, - } - } -} -impl Drop for CResultTempl { - fn drop(&mut self) { - if self.result_ok { - if unsafe { !self.contents.result.is_null() } { - unsafe { Box::from_raw(self.contents.result) }; - } - } else if unsafe { !self.contents.err.is_null() } { - unsafe { Box::from_raw(self.contents.err) }; - } - } -} - -/// Utility to make it easy to set a pointer to null and get its original value in line. -pub(crate) trait TakePointer { - fn take_ptr(&mut self) -> T; -} -impl TakePointer<*const T> for *const T { - fn take_ptr(&mut self) -> *const T { - let ret = *self; - *self = std::ptr::null(); - ret - } -} -impl TakePointer<*mut T> for *mut T { - fn take_ptr(&mut self) -> *mut T { - let ret = *self; - *self = std::ptr::null_mut(); - ret - } -} diff --git a/lightning-c-bindings/src/chain/chaininterface.rs b/lightning-c-bindings/src/chain/chaininterface.rs deleted file mode 100644 index b5f510323..000000000 --- a/lightning-c-bindings/src/chain/chaininterface.rs +++ /dev/null @@ -1,151 +0,0 @@ -//! Traits and utility impls which allow other parts of rust-lightning to interact with the -//! blockchain. -//! -//! Includes traits for monitoring and receiving notifications of new blocks and block -//! disconnections, transaction broadcasting, and feerate information requests. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - -/// An interface to send a transaction to the Bitcoin network. -#[repr(C)] -pub struct BroadcasterInterface { - pub this_arg: *mut c_void, - /// Sends a transaction out to (hopefully) be mined. - pub broadcast_transaction: extern "C" fn (this_arg: *const c_void, tx: crate::c_types::Transaction), - pub free: Option, -} -unsafe impl Sync for BroadcasterInterface {} -unsafe impl Send for BroadcasterInterface {} - -use lightning::chain::chaininterface::BroadcasterInterface as rustBroadcasterInterface; -impl rustBroadcasterInterface for BroadcasterInterface { - fn broadcast_transaction(&self, tx: &bitcoin::blockdata::transaction::Transaction) { - let mut local_tx = ::bitcoin::consensus::encode::serialize(tx); - (self.broadcast_transaction)(self.this_arg, crate::c_types::Transaction::from_vec(local_tx)) - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for BroadcasterInterface { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn BroadcasterInterface_free(this_ptr: BroadcasterInterface) { } -impl Drop for BroadcasterInterface { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} -/// An enum that represents the speed at which we want a transaction to confirm used for feerate -/// estimation. -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum ConfirmationTarget { - /// We are happy with this transaction confirming slowly when feerate drops some. - Background, - /// We'd like this transaction to confirm without major delay, but 12-18 blocks is fine. - Normal, - /// We'd like this transaction to confirm in the next few blocks. - HighPriority, -} -use lightning::chain::chaininterface::ConfirmationTarget as nativeConfirmationTarget; -impl ConfirmationTarget { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeConfirmationTarget { - match self { - ConfirmationTarget::Background => nativeConfirmationTarget::Background, - ConfirmationTarget::Normal => nativeConfirmationTarget::Normal, - ConfirmationTarget::HighPriority => nativeConfirmationTarget::HighPriority, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativeConfirmationTarget { - match self { - ConfirmationTarget::Background => nativeConfirmationTarget::Background, - ConfirmationTarget::Normal => nativeConfirmationTarget::Normal, - ConfirmationTarget::HighPriority => nativeConfirmationTarget::HighPriority, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativeConfirmationTarget) -> Self { - match native { - nativeConfirmationTarget::Background => ConfirmationTarget::Background, - nativeConfirmationTarget::Normal => ConfirmationTarget::Normal, - nativeConfirmationTarget::HighPriority => ConfirmationTarget::HighPriority, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativeConfirmationTarget) -> Self { - match native { - nativeConfirmationTarget::Background => ConfirmationTarget::Background, - nativeConfirmationTarget::Normal => ConfirmationTarget::Normal, - nativeConfirmationTarget::HighPriority => ConfirmationTarget::HighPriority, - } - } -} -#[no_mangle] -pub extern "C" fn ConfirmationTarget_clone(orig: &ConfirmationTarget) -> ConfirmationTarget { - orig.clone() -} -/// A trait which should be implemented to provide feerate information on a number of time -/// horizons. -/// -/// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're -/// called from inside the library in response to chain events, P2P events, or timer events). -#[repr(C)] -pub struct FeeEstimator { - pub this_arg: *mut c_void, - /// Gets estimated satoshis of fee required per 1000 Weight-Units. - /// - /// Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs - /// don't put us below 1 satoshi-per-byte). - /// - /// This translates to: - /// * satoshis-per-byte * 250 - /// * ceil(satoshis-per-kbyte / 4) - #[must_use] - pub get_est_sat_per_1000_weight: extern "C" fn (this_arg: *const c_void, confirmation_target: crate::chain::chaininterface::ConfirmationTarget) -> u32, - pub free: Option, -} -unsafe impl Sync for FeeEstimator {} -unsafe impl Send for FeeEstimator {} - -use lightning::chain::chaininterface::FeeEstimator as rustFeeEstimator; -impl rustFeeEstimator for FeeEstimator { - fn get_est_sat_per_1000_weight(&self, confirmation_target: lightning::chain::chaininterface::ConfirmationTarget) -> u32 { - let mut ret = (self.get_est_sat_per_1000_weight)(self.this_arg, crate::chain::chaininterface::ConfirmationTarget::native_into(confirmation_target)); - ret - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for FeeEstimator { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn FeeEstimator_free(this_ptr: FeeEstimator) { } -impl Drop for FeeEstimator { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} - -#[no_mangle] -pub static MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = lightning::chain::chaininterface::MIN_RELAY_FEE_SAT_PER_1000_WEIGHT; diff --git a/lightning-c-bindings/src/chain/chainmonitor.rs b/lightning-c-bindings/src/chain/chainmonitor.rs deleted file mode 100644 index c05f9017c..000000000 --- a/lightning-c-bindings/src/chain/chainmonitor.rs +++ /dev/null @@ -1,185 +0,0 @@ -//! Logic to connect off-chain channel management with on-chain transaction monitoring. -//! -//! [`ChainMonitor`] is an implementation of [`chain::Watch`] used both to process blocks and to -//! update [`ChannelMonitor`]s accordingly. If any on-chain events need further processing, it will -//! make those available as [`MonitorEvent`]s to be consumed. -//! -//! `ChainMonitor` is parameterized by an optional chain source, which must implement the -//! [`chain::Filter`] trait. This provides a mechanism to signal new relevant outputs back to light -//! clients, such that transactions spending those outputs are included in block data. -//! -//! `ChainMonitor` may be used directly to monitor channels locally or as a part of a distributed -//! setup to monitor channels remotely. In the latter case, a custom `chain::Watch` implementation -//! would be responsible for routing each update to a remote server and for retrieving monitor -//! events. The remote server would make use of `ChainMonitor` for block processing and for -//! servicing `ChannelMonitor` updates from the client. -//! -//! [`ChainMonitor`]: struct.ChainMonitor.html -//! [`chain::Filter`]: ../trait.Filter.html -//! [`chain::Watch`]: ../trait.Watch.html -//! [`ChannelMonitor`]: ../channelmonitor/struct.ChannelMonitor.html -//! [`MonitorEvent`]: ../channelmonitor/enum.MonitorEvent.html - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - - -use lightning::chain::chainmonitor::ChainMonitor as nativeChainMonitorImport; -type nativeChainMonitor = nativeChainMonitorImport; - -/// An implementation of [`chain::Watch`] for monitoring channels. -/// -/// Connected and disconnected blocks must be provided to `ChainMonitor` as documented by -/// [`chain::Watch`]. May be used in conjunction with [`ChannelManager`] to monitor channels locally -/// or used independently to monitor channels remotely. See the [module-level documentation] for -/// details. -/// -/// [`chain::Watch`]: ../trait.Watch.html -/// [`ChannelManager`]: ../../ln/channelmanager/struct.ChannelManager.html -/// [module-level documentation]: index.html -#[must_use] -#[repr(C)] -pub struct ChainMonitor { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChainMonitor, - pub is_owned: bool, -} - -impl Drop for ChainMonitor { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChainMonitor>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChainMonitor_free(this_ptr: ChainMonitor) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChainMonitor_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainMonitor); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChainMonitor { - pub(crate) fn take_inner(mut self) -> *mut nativeChainMonitor { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Dispatches to per-channel monitors, which are responsible for updating their on-chain view -/// of a channel and reacting accordingly based on transactions in the connected block. See -/// [`ChannelMonitor::block_connected`] for details. Any HTLCs that were resolved on chain will -/// be returned by [`chain::Watch::release_pending_monitor_events`]. -/// -/// Calls back to [`chain::Filter`] if any monitor indicated new outputs to watch. Subsequent -/// calls must not exclude any transactions matching the new outputs nor any in-block -/// descendants of such transactions. It is not necessary to re-fetch the block to obtain -/// updated `txdata`. -/// -/// [`ChannelMonitor::block_connected`]: ../channelmonitor/struct.ChannelMonitor.html#method.block_connected -/// [`chain::Watch::release_pending_monitor_events`]: ../trait.Watch.html#tymethod.release_pending_monitor_events -/// [`chain::Filter`]: ../trait.Filter.html -#[no_mangle] -pub extern "C" fn ChainMonitor_block_connected(this_arg: &ChainMonitor, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32) { - let mut local_txdata = Vec::new(); for mut item in txdata.into_rust().drain(..) { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item.to_rust(); let mut local_txdata_0 = (orig_txdata_0_0, orig_txdata_0_1.into_bitcoin()); local_txdata_0 }); }; - unsafe { &*this_arg.inner }.block_connected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::>()[..], height) -} - -/// Dispatches to per-channel monitors, which are responsible for updating their on-chain view -/// of a channel based on the disconnected block. See [`ChannelMonitor::block_disconnected`] for -/// details. -/// -/// [`ChannelMonitor::block_disconnected`]: ../channelmonitor/struct.ChannelMonitor.html#method.block_disconnected -#[no_mangle] -pub extern "C" fn ChainMonitor_block_disconnected(this_arg: &ChainMonitor, header: *const [u8; 80], mut disconnected_height: u32) { - unsafe { &*this_arg.inner }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), disconnected_height) -} - -/// Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels. -/// -/// When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor -/// will call back to it indicating transactions and outputs of interest. This allows clients to -/// pre-filter blocks or only fetch blocks matching a compact filter. Otherwise, clients may -/// always need to fetch full blocks absent another means for determining which blocks contain -/// transactions relevant to the watched channels. -/// -/// [`chain::Filter`]: ../trait.Filter.html -#[must_use] -#[no_mangle] -pub extern "C" fn ChainMonitor_new(chain_source: *mut crate::chain::Filter, mut broadcaster: crate::chain::chaininterface::BroadcasterInterface, mut logger: crate::util::logger::Logger, mut feeest: crate::chain::chaininterface::FeeEstimator, mut persister: crate::chain::channelmonitor::Persist) -> ChainMonitor { - let mut local_chain_source = if chain_source == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_source) } }) }; - let mut ret = lightning::chain::chainmonitor::ChainMonitor::new(local_chain_source, broadcaster, logger, feeest, persister); - ChainMonitor { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -impl From for crate::chain::Watch { - fn from(obj: nativeChainMonitor) -> Self { - let mut rust_obj = ChainMonitor { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = ChainMonitor_as_Watch(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(ChainMonitor_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn ChainMonitor_as_Watch(this_arg: &ChainMonitor) -> crate::chain::Watch { - crate::chain::Watch { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - watch_channel: ChainMonitor_Watch_watch_channel, - update_channel: ChainMonitor_Watch_update_channel, - release_pending_monitor_events: ChainMonitor_Watch_release_pending_monitor_events, - } -} - -#[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 { - let mut ret = >::watch_channel(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, *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*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() }; - local_ret -} -#[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 { - let mut ret = >::update_channel(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, *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*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() }; - local_ret -} -#[must_use] -extern "C" fn ChainMonitor_Watch_release_pending_monitor_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MonitorEventZ { - let mut ret = >::release_pending_monitor_events(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::chain::channelmonitor::MonitorEvent::native_into(item) }); }; - local_ret.into() -} - -impl From for crate::util::events::EventsProvider { - fn from(obj: nativeChainMonitor) -> Self { - let mut rust_obj = ChainMonitor { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = ChainMonitor_as_EventsProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(ChainMonitor_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn ChainMonitor_as_EventsProvider(this_arg: &ChainMonitor) -> crate::util::events::EventsProvider { - crate::util::events::EventsProvider { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - get_and_clear_pending_events: ChainMonitor_EventsProvider_get_and_clear_pending_events, - } -} - -#[must_use] -extern "C" fn ChainMonitor_EventsProvider_get_and_clear_pending_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_EventZ { - let mut ret = >::get_and_clear_pending_events(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::Event::native_into(item) }); }; - local_ret.into() -} - diff --git a/lightning-c-bindings/src/chain/channelmonitor.rs b/lightning-c-bindings/src/chain/channelmonitor.rs deleted file mode 100644 index 9fab7e046..000000000 --- a/lightning-c-bindings/src/chain/channelmonitor.rs +++ /dev/null @@ -1,703 +0,0 @@ -//! The logic to monitor for on-chain transactions and create the relevant claim responses lives -//! here. -//! -//! ChannelMonitor objects are generated by ChannelManager in response to relevant -//! messages/actions, and MUST be persisted to disk (and, preferably, remotely) before progress can -//! be made in responding to certain messages, see [`chain::Watch`] for more. -//! -//! Note that ChannelMonitors are an important part of the lightning trust model and a copy of the -//! latest ChannelMonitor must always be actively monitoring for chain updates (and no out-of-date -//! ChannelMonitors should do so). Thus, if you're building rust-lightning into an HSM or other -//! security-domain-separated system design, you should consider having multiple paths for -//! ChannelMonitors to get out of the HSM and onto monitoring devices. -//! -//! [`chain::Watch`]: ../trait.Watch.html - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - - -use lightning::chain::channelmonitor::ChannelMonitorUpdate as nativeChannelMonitorUpdateImport; -type nativeChannelMonitorUpdate = nativeChannelMonitorUpdateImport; - -/// An update generated by the underlying Channel itself which contains some new information the -/// ChannelMonitor should be made aware of. -#[must_use] -#[repr(C)] -pub struct ChannelMonitorUpdate { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelMonitorUpdate, - pub is_owned: bool, -} - -impl Drop for ChannelMonitorUpdate { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelMonitorUpdate>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelMonitorUpdate_free(this_ptr: ChannelMonitorUpdate) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelMonitorUpdate_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitorUpdate); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelMonitorUpdate { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitorUpdate { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// 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 -/// increasing and increase by one for each new update, with one exception specified below. -/// -/// This sequence number is also used to track up to which points updates which returned -/// ChannelMonitorUpdateErr::TemporaryFailure have been applied to all copies of a given -/// ChannelMonitor when ChannelManager::channel_monitor_updated is called. -/// -/// The only instance where update_id values are not strictly increasing is the case where we -/// allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See -/// its docs for more details. -/// -/// [`CLOSED_CHANNEL_UPDATE_ID`]: constant.CLOSED_CHANNEL_UPDATE_ID.html -#[no_mangle] -pub extern "C" fn ChannelMonitorUpdate_get_update_id(this_ptr: &ChannelMonitorUpdate) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.update_id; - (*inner_val) -} -/// 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 -/// increasing and increase by one for each new update, with one exception specified below. -/// -/// This sequence number is also used to track up to which points updates which returned -/// ChannelMonitorUpdateErr::TemporaryFailure have been applied to all copies of a given -/// ChannelMonitor when ChannelManager::channel_monitor_updated is called. -/// -/// The only instance where update_id values are not strictly increasing is the case where we -/// allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See -/// its docs for more details. -/// -/// [`CLOSED_CHANNEL_UPDATE_ID`]: constant.CLOSED_CHANNEL_UPDATE_ID.html -#[no_mangle] -pub extern "C" fn ChannelMonitorUpdate_set_update_id(this_ptr: &mut ChannelMonitorUpdate, mut val: u64) { - unsafe { &mut *this_ptr.inner }.update_id = val; -} -impl Clone for ChannelMonitorUpdate { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeChannelMonitorUpdate>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelMonitorUpdate)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate { - orig.clone() -} - -#[no_mangle] -pub static CLOSED_CHANNEL_UPDATE_ID: u64 = lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID; -#[no_mangle] -pub extern "C" fn ChannelMonitorUpdate_write(obj: &ChannelMonitorUpdate) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ChannelMonitorUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitorUpdate) }) -} -#[no_mangle] -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 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 -} -/// An error enum representing a failure to persist a channel monitor update. -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum ChannelMonitorUpdateErr { - /// Used to indicate a temporary failure (eg connection to a watchtower or remote backup of - /// our state failed, but is expected to succeed at some point in the future). - /// - /// Such a failure will \"freeze\" a channel, preventing us from revoking old states or - /// submitting new commitment transactions to the counterparty. Once the update(s) which failed - /// have been successfully applied, ChannelManager::channel_monitor_updated can be used to - /// restore the channel to an operational state. - /// - /// Note that a given ChannelManager will *never* re-generate a given ChannelMonitorUpdate. If - /// you return a TemporaryFailure you must ensure that it is written to disk safely before - /// writing out the latest ChannelManager state. - /// - /// Even when a channel has been \"frozen\" updates to the ChannelMonitor can continue to occur - /// (eg if an inbound HTLC which we forwarded was claimed upstream resulting in us attempting - /// to claim it on this channel) and those updates must be applied wherever they can be. At - /// least one such updated ChannelMonitor must be persisted otherwise PermanentFailure should - /// be returned to get things on-chain ASAP using only the in-memory copy. Obviously updates to - /// the channel which would invalidate previous ChannelMonitors are not made when a channel has - /// been \"frozen\". - /// - /// Note that even if updates made after TemporaryFailure succeed you must still call - /// channel_monitor_updated to ensure you have the latest monitor and re-enable normal channel - /// operation. - /// - /// Note that the update being processed here will not be replayed for you when you call - /// ChannelManager::channel_monitor_updated, so you must store the update itself along - /// with the persisted ChannelMonitor on your own local disk prior to returning a - /// TemporaryFailure. You may, of course, employ a journaling approach, storing only the - /// ChannelMonitorUpdate on disk without updating the monitor itself, replaying the journal at - /// reload-time. - /// - /// For deployments where a copy of ChannelMonitors and other local state are backed up in a - /// remote location (with local copies persisted immediately), it is anticipated that all - /// updates will return TemporaryFailure until the remote copies could be updated. - TemporaryFailure, - /// Used to indicate no further channel monitor updates will be allowed (eg we've moved on to a - /// different watchtower and cannot update with all watchtowers that were previously informed - /// of this channel). - /// - /// At reception of this error, ChannelManager will force-close the channel and return at - /// least a final ChannelMonitorUpdate::ChannelForceClosed which must be delivered to at - /// least one ChannelMonitor copy. Revocation secret MUST NOT be released and offchain channel - /// update must be rejected. - /// - /// This failure may also signal a failure to update the local persisted copy of one of - /// the channel monitor instance. - /// - /// Note that even when you fail a holder commitment transaction update, you must store the - /// update to ensure you can claim from it in case of a duplicate copy of this ChannelMonitor - /// broadcasts it (e.g distributed channel-monitor deployment) - /// - /// In case of distributed watchtowers deployment, the new version must be written to disk, as - /// state may have been stored but rejected due to a block forcing a commitment broadcast. This - /// storage is used to claim outputs of rejected state confirmed onchain by another watchtower, - /// lagging behind on block processing. - PermanentFailure, -} -use lightning::chain::channelmonitor::ChannelMonitorUpdateErr as nativeChannelMonitorUpdateErr; -impl ChannelMonitorUpdateErr { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeChannelMonitorUpdateErr { - match self { - ChannelMonitorUpdateErr::TemporaryFailure => nativeChannelMonitorUpdateErr::TemporaryFailure, - ChannelMonitorUpdateErr::PermanentFailure => nativeChannelMonitorUpdateErr::PermanentFailure, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativeChannelMonitorUpdateErr { - match self { - ChannelMonitorUpdateErr::TemporaryFailure => nativeChannelMonitorUpdateErr::TemporaryFailure, - ChannelMonitorUpdateErr::PermanentFailure => nativeChannelMonitorUpdateErr::PermanentFailure, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativeChannelMonitorUpdateErr) -> Self { - match native { - nativeChannelMonitorUpdateErr::TemporaryFailure => ChannelMonitorUpdateErr::TemporaryFailure, - nativeChannelMonitorUpdateErr::PermanentFailure => ChannelMonitorUpdateErr::PermanentFailure, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativeChannelMonitorUpdateErr) -> Self { - match native { - nativeChannelMonitorUpdateErr::TemporaryFailure => ChannelMonitorUpdateErr::TemporaryFailure, - nativeChannelMonitorUpdateErr::PermanentFailure => ChannelMonitorUpdateErr::PermanentFailure, - } - } -} -#[no_mangle] -pub extern "C" fn ChannelMonitorUpdateErr_clone(orig: &ChannelMonitorUpdateErr) -> ChannelMonitorUpdateErr { - orig.clone() -} - -use lightning::chain::channelmonitor::MonitorUpdateError as nativeMonitorUpdateErrorImport; -type nativeMonitorUpdateError = nativeMonitorUpdateErrorImport; - -/// General Err type for ChannelMonitor actions. Generally, this implies that the data provided is -/// inconsistent with the ChannelMonitor being called. eg for ChannelMonitor::update_monitor this -/// means you tried to update a monitor for a different channel or the ChannelMonitorUpdate was -/// corrupted. -/// Contains a developer-readable error message. -#[must_use] -#[repr(C)] -pub struct MonitorUpdateError { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeMonitorUpdateError, - pub is_owned: bool, -} - -impl Drop for MonitorUpdateError { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeMonitorUpdateError>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn MonitorUpdateError_free(this_ptr: MonitorUpdateError) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn MonitorUpdateError_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMonitorUpdateError); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl MonitorUpdateError { - pub(crate) fn take_inner(mut self) -> *mut nativeMonitorUpdateError { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -impl Clone for MonitorUpdateError { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeMonitorUpdateError>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn 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() -} -/// An event to be processed by the ChannelManager. -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum MonitorEvent { - /// A monitor event containing an HTLCUpdate. - HTLCEvent(crate::chain::channelmonitor::HTLCUpdate), - /// A monitor event that the Channel's commitment transaction was broadcasted. - CommitmentTxBroadcasted(crate::chain::transaction::OutPoint), -} -use lightning::chain::channelmonitor::MonitorEvent as nativeMonitorEvent; -impl MonitorEvent { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeMonitorEvent { - match self { - MonitorEvent::HTLCEvent (ref a, ) => { - let mut a_nonref = (*a).clone(); - nativeMonitorEvent::HTLCEvent ( - *unsafe { Box::from_raw(a_nonref.take_inner()) }, - ) - }, - MonitorEvent::CommitmentTxBroadcasted (ref a, ) => { - let mut a_nonref = (*a).clone(); - nativeMonitorEvent::CommitmentTxBroadcasted ( - *unsafe { Box::from_raw(a_nonref.take_inner()) }, - ) - }, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativeMonitorEvent { - match self { - MonitorEvent::HTLCEvent (mut a, ) => { - nativeMonitorEvent::HTLCEvent ( - *unsafe { Box::from_raw(a.take_inner()) }, - ) - }, - MonitorEvent::CommitmentTxBroadcasted (mut a, ) => { - nativeMonitorEvent::CommitmentTxBroadcasted ( - *unsafe { Box::from_raw(a.take_inner()) }, - ) - }, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativeMonitorEvent) -> Self { - match native { - nativeMonitorEvent::HTLCEvent (ref a, ) => { - let mut a_nonref = (*a).clone(); - MonitorEvent::HTLCEvent ( - crate::chain::channelmonitor::HTLCUpdate { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true }, - ) - }, - nativeMonitorEvent::CommitmentTxBroadcasted (ref a, ) => { - let mut a_nonref = (*a).clone(); - MonitorEvent::CommitmentTxBroadcasted ( - crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true }, - ) - }, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativeMonitorEvent) -> Self { - match native { - nativeMonitorEvent::HTLCEvent (mut a, ) => { - MonitorEvent::HTLCEvent ( - crate::chain::channelmonitor::HTLCUpdate { inner: Box::into_raw(Box::new(a)), is_owned: true }, - ) - }, - nativeMonitorEvent::CommitmentTxBroadcasted (mut a, ) => { - MonitorEvent::CommitmentTxBroadcasted ( - crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(a)), is_owned: true }, - ) - }, - } - } -} -#[no_mangle] -pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { } -#[no_mangle] -pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent { - orig.clone() -} - -use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport; -type nativeHTLCUpdate = nativeHTLCUpdateImport; - -/// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on -/// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the -/// preimage claim backward will lead to loss of funds. -/// -/// [`chain::Watch`]: ../trait.Watch.html -#[must_use] -#[repr(C)] -pub struct HTLCUpdate { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeHTLCUpdate, - pub is_owned: bool, -} - -impl Drop for HTLCUpdate { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeHTLCUpdate>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn HTLCUpdate_free(this_ptr: HTLCUpdate) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCUpdate); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl HTLCUpdate { - pub(crate) fn take_inner(mut self) -> *mut nativeHTLCUpdate { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -impl Clone for HTLCUpdate { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeHTLCUpdate>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCUpdate)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate { - orig.clone() -} -#[no_mangle] -pub extern "C" fn HTLCUpdate_write(obj: &HTLCUpdate) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) }) -} -#[no_mangle] -pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCUpdateDecodeErrorZ { - 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::HTLCUpdate { 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 -} - -use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport; -type nativeChannelMonitor = nativeChannelMonitorImport; - -/// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates -/// on-chain transactions to ensure no loss of funds occurs. -/// -/// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date -/// information and are actively monitoring the chain. -/// -/// Pending Events or updated HTLCs which have not yet been read out by -/// get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and -/// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events -/// gotten are fully handled before re-serializing the new state. -/// -/// Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which -/// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along -/// the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the -/// returned block hash and the the current chain and then reconnecting blocks to get to the -/// best chain) upon deserializing the object! -#[must_use] -#[repr(C)] -pub struct ChannelMonitor { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelMonitor, - pub is_owned: bool, -} - -impl Drop for ChannelMonitor { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelMonitor>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelMonitor_free(this_ptr: ChannelMonitor) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitor); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelMonitor { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitor { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -#[no_mangle] -pub extern "C" fn ChannelMonitor_write(obj: &ChannelMonitor) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitor) }) -} -/// Updates a ChannelMonitor on the basis of some new information provided by the Channel -/// itself. -/// -/// panics if the given update is not the next update by update_id. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelMonitor_update_monitor(this_arg: &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 { &*this_arg.inner }.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*/ }).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 -} - -/// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this -/// ChannelMonitor. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &ChannelMonitor) -> u64 { - let mut ret = unsafe { &*this_arg.inner }.get_latest_update_id(); - ret -} - -/// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointScriptZ { - let mut ret = unsafe { &*this_arg.inner }.get_funding_txo(); - let (mut orig_ret_0, mut orig_ret_1) = ret; let mut local_ret = (crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(orig_ret_0)), is_owned: true }, orig_ret_1.into_bytes().into()).into(); - local_ret -} - -/// Get the list of HTLCs who's status has been updated on chain. This should be called by -/// ChannelManager via [`chain::Watch::release_pending_monitor_events`]. -/// -/// [`chain::Watch::release_pending_monitor_events`]: ../trait.Watch.html#tymethod.release_pending_monitor_events -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ { - let mut ret = unsafe { &*this_arg.inner }.get_and_clear_pending_monitor_events(); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::chain::channelmonitor::MonitorEvent::native_into(item) }); }; - local_ret.into() -} - -/// Gets the list of pending events which were generated by previous actions, clearing the list -/// in the process. -/// -/// This is called by ChainMonitor::get_and_clear_pending_events() and is equivalent to -/// EventsProvider::get_and_clear_pending_events() except that it requires &mut self as we do -/// no internal locking in ChannelMonitors. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &ChannelMonitor) -> crate::c_types::derived::CVec_EventZ { - let mut ret = unsafe { &*this_arg.inner }.get_and_clear_pending_events(); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::Event::native_into(item) }); }; - local_ret.into() -} - -/// Used by ChannelManager deserialization to broadcast the latest holder state if its copy of -/// the Channel was out-of-date. You may use it to get a broadcastable holder toxic tx in case of -/// fallen-behind, i.e when receiving a channel_reestablish with a proof that our counterparty side knows -/// a higher revocation secret than the holder commitment number we are aware of. Broadcasting these -/// transactions are UNSAFE, as they allow counterparty side to punish you. Nevertheless you may want to -/// broadcast them if counterparty don't close channel with his higher commitment transaction after a -/// substantial amount of time (a month or even a year) to get back funds. Best may be to contact -/// out-of-band the other node operator to coordinate with him if option is available to you. -/// In any-case, choice is up to the user. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelMonitor_get_latest_holder_commitment_txn(this_arg: &ChannelMonitor, logger: &crate::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionZ { - let mut ret = unsafe { &*this_arg.inner }.get_latest_holder_commitment_txn(logger); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let mut local_ret_0 = ::bitcoin::consensus::encode::serialize(&item); crate::c_types::Transaction::from_vec(local_ret_0) }); }; - local_ret.into() -} - -/// Processes transactions in a newly connected block, which may result in any of the following: -/// - update the monitor's state against resolved HTLCs -/// - punish the counterparty in the case of seeing a revoked commitment transaction -/// - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration -/// - detect settled outputs for later spending -/// - schedule and bump any in-flight claims -/// -/// Returns any new outputs to watch from `txdata`; after called, these are also included in -/// [`get_outputs_to_watch`]. -/// -/// [`get_outputs_to_watch`]: #method.get_outputs_to_watch -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelMonitor_block_connected(this_arg: &ChannelMonitor, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32, mut broadcaster: crate::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::chain::chaininterface::FeeEstimator, mut logger: crate::util::logger::Logger) -> crate::c_types::derived::CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ { - let mut local_txdata = Vec::new(); for mut item in txdata.into_rust().drain(..) { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item.to_rust(); let mut local_txdata_0 = (orig_txdata_0_0, orig_txdata_0_1.into_bitcoin()); local_txdata_0 }); }; - let mut ret = unsafe { &*this_arg.inner }.block_connected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::>()[..], height, broadcaster, fee_estimator, logger); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, crate::c_types::TxOut::from_rust(orig_orig_ret_0_1_0_1)).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); }; - local_ret.into() -} - -/// Determines if the disconnected block contained any transactions of interest and updates -/// appropriately. -#[no_mangle] -pub extern "C" fn ChannelMonitor_block_disconnected(this_arg: &ChannelMonitor, header: *const [u8; 80], mut height: u32, mut broadcaster: crate::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::chain::chaininterface::FeeEstimator, mut logger: crate::util::logger::Logger) { - unsafe { &*this_arg.inner }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger) -} - -/// `Persist` defines behavior for persisting channel monitors: this could mean -/// writing once to disk, and/or uploading to one or more backup services. -/// -/// Note that for every new monitor, you **must** persist the new `ChannelMonitor` -/// to disk/backups. And, on every update, you **must** persist either the -/// `ChannelMonitorUpdate` or the updated monitor itself. Otherwise, there is risk -/// of situations such as revoking a transaction, then crashing before this -/// revocation can be persisted, then unintentionally broadcasting a revoked -/// transaction and losing money. This is a risk because previous channel states -/// are toxic, so it's important that whatever channel state is persisted is -/// kept up-to-date. -#[repr(C)] -pub struct Persist { - pub this_arg: *mut c_void, - /// Persist a new channel's data. The data can be stored any way you want, but - /// the identifier provided by Rust-Lightning is the channel's outpoint (and - /// it is up to you to maintain a correct mapping between the outpoint and the - /// stored channel data). Note that you **must** persist every new monitor to - /// disk. See the `Persist` trait documentation for more details. - /// - /// See [`ChannelMonitor::serialize_for_disk`] for writing out a `ChannelMonitor`, - /// and [`ChannelMonitorUpdateErr`] for requirements when returning errors. - /// - /// [`ChannelMonitor::serialize_for_disk`]: struct.ChannelMonitor.html#method.serialize_for_disk - /// [`ChannelMonitorUpdateErr`]: enum.ChannelMonitorUpdateErr.html - #[must_use] - pub persist_new_channel: extern "C" fn (this_arg: *const c_void, id: crate::chain::transaction::OutPoint, data: &crate::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ, - /// Update one channel's data. The provided `ChannelMonitor` has already - /// applied the given update. - /// - /// Note that on every update, you **must** persist either the - /// `ChannelMonitorUpdate` or the updated monitor itself to disk/backups. See - /// the `Persist` trait documentation for more details. - /// - /// If an implementer chooses to persist the updates only, they need to make - /// sure that all the updates are applied to the `ChannelMonitors` *before* - /// the set of channel monitors is given to the `ChannelManager` - /// deserialization routine. See [`ChannelMonitor::update_monitor`] for - /// applying a monitor update to a monitor. If full `ChannelMonitors` are - /// persisted, then there is no need to persist individual updates. - /// - /// Note that there could be a performance tradeoff between persisting complete - /// channel monitors on every update vs. persisting only updates and applying - /// them in batches. The size of each monitor grows `O(number of state updates)` - /// whereas updates are small and `O(1)`. - /// - /// See [`ChannelMonitor::serialize_for_disk`] for writing out a `ChannelMonitor`, - /// [`ChannelMonitorUpdate::write`] for writing out an update, and - /// [`ChannelMonitorUpdateErr`] for requirements when returning errors. - /// - /// [`ChannelMonitor::update_monitor`]: struct.ChannelMonitor.html#impl-1 - /// [`ChannelMonitor::serialize_for_disk`]: struct.ChannelMonitor.html#method.serialize_for_disk - /// [`ChannelMonitorUpdate::write`]: struct.ChannelMonitorUpdate.html#method.write - /// [`ChannelMonitorUpdateErr`]: enum.ChannelMonitorUpdateErr.html - #[must_use] - pub update_persisted_channel: extern "C" fn (this_arg: *const c_void, id: crate::chain::transaction::OutPoint, update: &crate::chain::channelmonitor::ChannelMonitorUpdate, data: &crate::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ, - pub free: Option, -} -unsafe impl Send for Persist {} -unsafe impl Sync for Persist {} - -use lightning::chain::channelmonitor::Persist as rustPersist; -impl rustPersist for Persist { - fn persist_new_channel(&self, id: lightning::chain::transaction::OutPoint, data: &lightning::chain::channelmonitor::ChannelMonitor) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> { - let mut ret = (self.persist_new_channel)(self.this_arg, crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(id)), is_owned: true }, &crate::chain::channelmonitor::ChannelMonitor { inner: unsafe { (data as *const _) as *mut _ }, is_owned: false }); - let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })}; - local_ret - } - fn update_persisted_channel(&self, id: lightning::chain::transaction::OutPoint, update: &lightning::chain::channelmonitor::ChannelMonitorUpdate, data: &lightning::chain::channelmonitor::ChannelMonitor) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> { - let mut ret = (self.update_persisted_channel)(self.this_arg, crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(id)), is_owned: true }, &crate::chain::channelmonitor::ChannelMonitorUpdate { inner: unsafe { (update as *const _) as *mut _ }, is_owned: false }, &crate::chain::channelmonitor::ChannelMonitor { inner: unsafe { (data as *const _) as *mut _ }, is_owned: false }); - let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })}; - local_ret - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for Persist { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn Persist_free(this_ptr: Persist) { } -impl Drop for Persist { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} -#[no_mangle] -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 res: Result<(bitcoin::hash_types::BlockHash, lightning::chain::channelmonitor::ChannelMonitor), 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 }).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 -} diff --git a/lightning-c-bindings/src/chain/keysinterface.rs b/lightning-c-bindings/src/chain/keysinterface.rs deleted file mode 100644 index abd779693..000000000 --- a/lightning-c-bindings/src/chain/keysinterface.rs +++ /dev/null @@ -1,1267 +0,0 @@ -//! keysinterface provides keys into rust-lightning and defines some useful enums which describe -//! spendable on-chain outputs which the user owns and is responsible for using just as any other -//! on-chain output which is theirs. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - - -use lightning::chain::keysinterface::DelayedPaymentOutputDescriptor as nativeDelayedPaymentOutputDescriptorImport; -type nativeDelayedPaymentOutputDescriptor = nativeDelayedPaymentOutputDescriptorImport; - -/// Information about a spendable output to a P2WSH script. See -/// SpendableOutputDescriptor::DelayedPaymentOutput for more details on how to spend this. -#[must_use] -#[repr(C)] -pub struct DelayedPaymentOutputDescriptor { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeDelayedPaymentOutputDescriptor, - pub is_owned: bool, -} - -impl Drop for DelayedPaymentOutputDescriptor { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_free(this_ptr: DelayedPaymentOutputDescriptor) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn DelayedPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDelayedPaymentOutputDescriptor); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl DelayedPaymentOutputDescriptor { - pub(crate) fn take_inner(mut self) -> *mut nativeDelayedPaymentOutputDescriptor { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The outpoint which is spendable -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_get_outpoint(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::chain::transaction::OutPoint { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.outpoint; - crate::chain::transaction::OutPoint { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// The outpoint which is spendable -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_set_outpoint(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::chain::transaction::OutPoint) { - unsafe { &mut *this_ptr.inner }.outpoint = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// Per commitment point to derive delayed_payment_key by key holder -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_get_per_commitment_point(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.per_commitment_point; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// Per commitment point to derive delayed_payment_key by key holder -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_set_per_commitment_point(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.per_commitment_point = val.into_rust(); -} -/// The nSequence value which must be set in the spending input to satisfy the OP_CSV in -/// the witness_script. -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_get_to_self_delay(this_ptr: &DelayedPaymentOutputDescriptor) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.to_self_delay; - (*inner_val) -} -/// The nSequence value which must be set in the spending input to satisfy the OP_CSV in -/// the witness_script. -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_set_to_self_delay(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u16) { - unsafe { &mut *this_ptr.inner }.to_self_delay = val; -} -/// The output which is referenced by the given outpoint -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_set_output(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::TxOut) { - unsafe { &mut *this_ptr.inner }.output = val.into_rust(); -} -/// The revocation point specific to the commitment transaction which was broadcast. Used to -/// derive the witnessScript for this output. -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_get_revocation_pubkey(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_pubkey; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The revocation point specific to the commitment transaction which was broadcast. Used to -/// derive the witnessScript for this output. -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_set_revocation_pubkey(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.revocation_pubkey = val.into_rust(); -} -/// Arbitrary identification information returned by a call to -/// `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in -/// the channel to spend the output. -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &DelayedPaymentOutputDescriptor) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_keys_id; - &(*inner_val) -} -/// Arbitrary identification information returned by a call to -/// `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in -/// the channel to spend the output. -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_keys_id = val.data; -} -/// The value of the channel which this output originated from, possibly indirectly. -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &DelayedPaymentOutputDescriptor) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_value_satoshis; - (*inner_val) -} -/// The value of the channel which this output originated from, possibly indirectly. -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u64) { - unsafe { &mut *this_ptr.inner }.channel_value_satoshis = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_new(mut outpoint_arg: crate::chain::transaction::OutPoint, mut per_commitment_point_arg: crate::c_types::PublicKey, mut to_self_delay_arg: u16, mut output_arg: crate::c_types::TxOut, mut revocation_pubkey_arg: crate::c_types::PublicKey, mut channel_keys_id_arg: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis_arg: u64) -> DelayedPaymentOutputDescriptor { - DelayedPaymentOutputDescriptor { inner: Box::into_raw(Box::new(nativeDelayedPaymentOutputDescriptor { - outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) }, - per_commitment_point: per_commitment_point_arg.into_rust(), - to_self_delay: to_self_delay_arg, - output: output_arg.into_rust(), - revocation_pubkey: revocation_pubkey_arg.into_rust(), - channel_keys_id: channel_keys_id_arg.data, - channel_value_satoshis: channel_value_satoshis_arg, - })), is_owned: true } -} -impl Clone for DelayedPaymentOutputDescriptor { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDelayedPaymentOutputDescriptor)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn DelayedPaymentOutputDescriptor_clone(orig: &DelayedPaymentOutputDescriptor) -> DelayedPaymentOutputDescriptor { - orig.clone() -} - -use lightning::chain::keysinterface::StaticPaymentOutputDescriptor as nativeStaticPaymentOutputDescriptorImport; -type nativeStaticPaymentOutputDescriptor = nativeStaticPaymentOutputDescriptorImport; - -/// Information about a spendable output to our \"payment key\". See -/// SpendableOutputDescriptor::StaticPaymentOutput for more details on how to spend this. -#[must_use] -#[repr(C)] -pub struct StaticPaymentOutputDescriptor { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeStaticPaymentOutputDescriptor, - pub is_owned: bool, -} - -impl Drop for StaticPaymentOutputDescriptor { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn StaticPaymentOutputDescriptor_free(this_ptr: StaticPaymentOutputDescriptor) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn StaticPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeStaticPaymentOutputDescriptor); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl StaticPaymentOutputDescriptor { - pub(crate) fn take_inner(mut self) -> *mut nativeStaticPaymentOutputDescriptor { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The outpoint which is spendable -#[no_mangle] -pub extern "C" fn StaticPaymentOutputDescriptor_get_outpoint(this_ptr: &StaticPaymentOutputDescriptor) -> crate::chain::transaction::OutPoint { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.outpoint; - crate::chain::transaction::OutPoint { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// The outpoint which is spendable -#[no_mangle] -pub extern "C" fn StaticPaymentOutputDescriptor_set_outpoint(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::chain::transaction::OutPoint) { - unsafe { &mut *this_ptr.inner }.outpoint = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// The output which is referenced by the given outpoint -#[no_mangle] -pub extern "C" fn StaticPaymentOutputDescriptor_set_output(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::TxOut) { - unsafe { &mut *this_ptr.inner }.output = val.into_rust(); -} -/// Arbitrary identification information returned by a call to -/// `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in -/// the channel to spend the output. -#[no_mangle] -pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &StaticPaymentOutputDescriptor) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_keys_id; - &(*inner_val) -} -/// Arbitrary identification information returned by a call to -/// `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in -/// the channel to spend the output. -#[no_mangle] -pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_keys_id = val.data; -} -/// The value of the channel which this transactions spends. -#[no_mangle] -pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &StaticPaymentOutputDescriptor) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_value_satoshis; - (*inner_val) -} -/// The value of the channel which this transactions spends. -#[no_mangle] -pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: u64) { - unsafe { &mut *this_ptr.inner }.channel_value_satoshis = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn StaticPaymentOutputDescriptor_new(mut outpoint_arg: crate::chain::transaction::OutPoint, mut output_arg: crate::c_types::TxOut, mut channel_keys_id_arg: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis_arg: u64) -> StaticPaymentOutputDescriptor { - StaticPaymentOutputDescriptor { inner: Box::into_raw(Box::new(nativeStaticPaymentOutputDescriptor { - outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) }, - output: output_arg.into_rust(), - channel_keys_id: channel_keys_id_arg.data, - channel_value_satoshis: channel_value_satoshis_arg, - })), is_owned: true } -} -impl Clone for StaticPaymentOutputDescriptor { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn StaticPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeStaticPaymentOutputDescriptor)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn StaticPaymentOutputDescriptor_clone(orig: &StaticPaymentOutputDescriptor) -> StaticPaymentOutputDescriptor { - orig.clone() -} -/// When on-chain outputs are created by rust-lightning (which our counterparty is not able to -/// claim at any point in the future) an event is generated which you must track and be able to -/// spend on-chain. The information needed to do this is provided in this enum, including the -/// outpoint describing which txid and output index is available, the full output which exists at -/// that txid/index, and any keys or other information required to sign. -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum SpendableOutputDescriptor { - /// An output to a script which was provided via KeysInterface directly, either from - /// `get_destination_script()` or `get_shutdown_pubkey()`, thus you should already know how to - /// spend it. No secret keys are provided as rust-lightning was never given any key. - /// These may include outputs from a transaction punishing our counterparty or claiming an HTLC - /// on-chain using the payment preimage or after it has timed out. - StaticOutput { - outpoint: crate::chain::transaction::OutPoint, - output: crate::c_types::TxOut, - }, - /// An output to a P2WSH script which can be spent with a single signature after a CSV delay. - /// - /// The witness in the spending input should be: - /// (MINIMALIF standard rule) - /// - /// Note that the nSequence field in the spending input must be set to to_self_delay - /// (which means the transaction is not broadcastable until at least to_self_delay - /// blocks after the outpoint confirms). - /// - /// These are generally the result of a \"revocable\" output to us, spendable only by us unless - /// it is an output from an old state which we broadcast (which should never happen). - /// - /// To derive the delayed_payment key which is used to sign for this input, you must pass the - /// holder delayed_payment_base_key (ie the private key which corresponds to the pubkey in - /// Sign::pubkeys().delayed_payment_basepoint) and the provided per_commitment_point to - /// chan_utils::derive_private_key. The public key can be generated without the secret key - /// using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in - /// Sign::pubkeys(). - /// - /// To derive the revocation_pubkey provided here (which is used in the witness - /// script generation), you must pass the counterparty revocation_basepoint (which appears in the - /// call to Sign::ready_channel) and the provided per_commitment point - /// to chan_utils::derive_public_revocation_key. - /// - /// The witness script which is hashed and included in the output script_pubkey may be - /// regenerated by passing the revocation_pubkey (derived as above), our delayed_payment pubkey - /// (derived as above), and the to_self_delay contained here to - /// chan_utils::get_revokeable_redeemscript. - DelayedPaymentOutput(crate::chain::keysinterface::DelayedPaymentOutputDescriptor), - /// An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which - /// corresponds to the public key in Sign::pubkeys().payment_point). - /// The witness in the spending input, is, thus, simply: - /// - /// - /// These are generally the result of our counterparty having broadcast the current state, - /// allowing us to claim the non-HTLC-encumbered outputs immediately. - StaticPaymentOutput(crate::chain::keysinterface::StaticPaymentOutputDescriptor), -} -use lightning::chain::keysinterface::SpendableOutputDescriptor as nativeSpendableOutputDescriptor; -impl SpendableOutputDescriptor { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeSpendableOutputDescriptor { - match self { - SpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => { - let mut outpoint_nonref = (*outpoint).clone(); - let mut output_nonref = (*output).clone(); - nativeSpendableOutputDescriptor::StaticOutput { - outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) }, - output: output_nonref.into_rust(), - } - }, - SpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => { - let mut a_nonref = (*a).clone(); - nativeSpendableOutputDescriptor::DelayedPaymentOutput ( - *unsafe { Box::from_raw(a_nonref.take_inner()) }, - ) - }, - SpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => { - let mut a_nonref = (*a).clone(); - nativeSpendableOutputDescriptor::StaticPaymentOutput ( - *unsafe { Box::from_raw(a_nonref.take_inner()) }, - ) - }, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativeSpendableOutputDescriptor { - match self { - SpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => { - nativeSpendableOutputDescriptor::StaticOutput { - outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) }, - output: output.into_rust(), - } - }, - SpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => { - nativeSpendableOutputDescriptor::DelayedPaymentOutput ( - *unsafe { Box::from_raw(a.take_inner()) }, - ) - }, - SpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => { - nativeSpendableOutputDescriptor::StaticPaymentOutput ( - *unsafe { Box::from_raw(a.take_inner()) }, - ) - }, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativeSpendableOutputDescriptor) -> Self { - match native { - nativeSpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => { - let mut outpoint_nonref = (*outpoint).clone(); - let mut output_nonref = (*output).clone(); - SpendableOutputDescriptor::StaticOutput { - outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint_nonref)), is_owned: true }, - output: crate::c_types::TxOut::from_rust(output_nonref), - } - }, - nativeSpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => { - let mut a_nonref = (*a).clone(); - SpendableOutputDescriptor::DelayedPaymentOutput ( - crate::chain::keysinterface::DelayedPaymentOutputDescriptor { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true }, - ) - }, - nativeSpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => { - let mut a_nonref = (*a).clone(); - SpendableOutputDescriptor::StaticPaymentOutput ( - crate::chain::keysinterface::StaticPaymentOutputDescriptor { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true }, - ) - }, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativeSpendableOutputDescriptor) -> Self { - match native { - nativeSpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => { - SpendableOutputDescriptor::StaticOutput { - outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint)), is_owned: true }, - output: crate::c_types::TxOut::from_rust(output), - } - }, - nativeSpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => { - SpendableOutputDescriptor::DelayedPaymentOutput ( - crate::chain::keysinterface::DelayedPaymentOutputDescriptor { inner: Box::into_raw(Box::new(a)), is_owned: true }, - ) - }, - nativeSpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => { - SpendableOutputDescriptor::StaticPaymentOutput ( - crate::chain::keysinterface::StaticPaymentOutputDescriptor { inner: Box::into_raw(Box::new(a)), is_owned: true }, - ) - }, - } - } -} -#[no_mangle] -pub extern "C" fn SpendableOutputDescriptor_free(this_ptr: SpendableOutputDescriptor) { } -#[no_mangle] -pub extern "C" fn SpendableOutputDescriptor_clone(orig: &SpendableOutputDescriptor) -> SpendableOutputDescriptor { - orig.clone() -} -#[no_mangle] -pub extern "C" fn SpendableOutputDescriptor_write(obj: &SpendableOutputDescriptor) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) -} -#[no_mangle] -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 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 -} -/// A trait to sign lightning channel transactions as described in BOLT 3. -/// -/// Signing services could be implemented on a hardware wallet. In this case, -/// the current Sign would be a front-end on top of a communication -/// channel connected to your secure device and lightning key material wouldn't -/// reside on a hot server. Nevertheless, a this deployment would still need -/// to trust the ChannelManager to avoid loss of funds as this latest component -/// could ask to sign commitment transaction with HTLCs paying to attacker pubkeys. -/// -/// A more secure iteration would be to use hashlock (or payment points) to pair -/// invoice/incoming HTLCs with outgoing HTLCs to implement a no-trust-ChannelManager -/// at the price of more state and computation on the hardware wallet side. In the future, -/// we are looking forward to design such interface. -/// -/// In any case, ChannelMonitor or fallback watchtowers are always going to be trusted -/// to act, as liveness and breach reply correctness are always going to be hard requirements -/// of LN security model, orthogonal of key management issues. -#[repr(C)] -pub struct Sign { - pub this_arg: *mut c_void, - /// Gets the per-commitment point for a specific commitment number - /// - /// Note that the commitment number starts at (1 << 48) - 1 and counts backwards. - #[must_use] - pub get_per_commitment_point: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::PublicKey, - /// Gets the commitment secret for a specific commitment number as part of the revocation process - /// - /// An external signer implementation should error here if the commitment was already signed - /// and should refuse to sign it in the future. - /// - /// May be called more than once for the same index. - /// - /// Note that the commitment number starts at (1 << 48) - 1 and counts backwards. - #[must_use] - pub release_commitment_secret: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::ThirtyTwoBytes, - /// Gets the holder's channel public keys and basepoints - pub pubkeys: crate::ln::chan_utils::ChannelPublicKeys, - /// Fill in the pubkeys field as a reference to it will be given to Rust after this returns - /// Note that this takes a pointer to this object, not the this_ptr like other methods do - /// This function pointer may be NULL if pubkeys is filled in when this object is created and never needs updating. - pub set_pubkeys: Option, - /// Gets an arbitrary identifier describing the set of keys which are provided back to you in - /// some SpendableOutputDescriptor types. This should be sufficient to identify this - /// Sign object uniquely and lookup or re-derive its keys. - #[must_use] - pub channel_keys_id: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes, - /// Create a signature for a counterparty's commitment transaction and associated HTLC transactions. - /// - /// Note that if signing fails or is rejected, the channel will be force-closed. - #[must_use] - pub sign_counterparty_commitment: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::CommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ, - /// Create a signatures for a holder's commitment transaction and its claiming HTLC transactions. - /// This will only ever be called with a non-revoked commitment_tx. This will be called with the - /// latest commitment_tx when we initiate a force-close. - /// This will be called with the previous latest, just to get claiming HTLC signatures, if we are - /// reacting to a ChannelMonitor replica that decided to broadcast before it had been updated to - /// the latest. - /// This may be called multiple times for the same transaction. - /// - /// An external signer implementation should check that the commitment has not been revoked. - /// - /// May return Err if key derivation fails. Callers, such as ChannelMonitor, will panic in such a case. - #[must_use] - pub sign_holder_commitment_and_htlcs: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ, - /// Create a signature for the given input in a transaction spending an HTLC or commitment - /// transaction output when our counterparty broadcasts an old state. - /// - /// A justice transaction may claim multiples outputs at the same time if timelocks are - /// similar, but only a signature for the input at index `input` should be signed for here. - /// It may be called multiples time for same output(s) if a fee-bump is needed with regards - /// to an upcoming timelock expiration. - /// - /// Amount is value of the output spent by this input, committed to in the BIP 143 signature. - /// - /// per_commitment_key is revocation secret which was provided by our counterparty when they - /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does - /// not allow the spending of any funds by itself (you need our holder revocation_secret to do - /// so). - /// - /// htlc holds HTLC elements (hash, timelock) if the output being spent is a HTLC output, thus - /// changing the format of the witness script (which is committed to in the BIP 143 - /// signatures). - #[must_use] - pub sign_justice_transaction: extern "C" fn (this_arg: *const c_void, justice_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_key: *const [u8; 32], htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ, - /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment - /// transaction, either offered or received. - /// - /// Such a transaction may claim multiples offered outputs at same time if we know the - /// preimage for each when we create it, but only the input at index `input` should be - /// signed for here. It may be called multiple times for same output(s) if a fee-bump is - /// needed with regards to an upcoming timelock expiration. - /// - /// Witness_script is either a offered or received script as defined in BOLT3 for HTLC - /// outputs. - /// - /// Amount is value of the output spent by this input, committed to in the BIP 143 signature. - /// - /// Per_commitment_point is the dynamic point corresponding to the channel state - /// detected onchain. It has been generated by our counterparty and is used to derive - /// channel state keys, which are then included in the witness script and committed to in the - /// BIP 143 signature. - #[must_use] - pub sign_counterparty_htlc_transaction: extern "C" fn (this_arg: *const c_void, htlc_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_point: crate::c_types::PublicKey, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ, - /// Create a signature for a (proposed) closing transaction. - /// - /// Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have - /// chosen to forgo their output as dust. - #[must_use] - pub sign_closing_transaction: extern "C" fn (this_arg: *const c_void, closing_tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_SignatureNoneZ, - /// Signs a channel announcement message with our funding key, proving it comes from one - /// of the channel participants. - /// - /// Note that if this fails or is rejected, the channel will not be publicly announced and - /// our counterparty may (though likely will not) close the channel on us for violating the - /// protocol. - #[must_use] - pub sign_channel_announcement: extern "C" fn (this_arg: *const c_void, msg: &crate::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_SignatureNoneZ, - /// Set the counterparty static channel data, including basepoints, - /// counterparty_selected/holder_selected_contest_delay and funding outpoint. - /// This is done as soon as the funding outpoint is known. Since these are static channel data, - /// they MUST NOT be allowed to change to different values once set. - /// - /// channel_parameters.is_populated() MUST be true. - /// - /// We bind holder_selected_contest_delay late here for API convenience. - /// - /// Will be called before any signatures are applied. - pub ready_channel: extern "C" fn (this_arg: *mut c_void, channel_parameters: &crate::ln::chan_utils::ChannelTransactionParameters), - pub clone: Option *mut c_void>, - pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z, - pub free: Option, -} -unsafe impl Send for Sign {} -#[no_mangle] -pub extern "C" fn Sign_clone(orig: &Sign) -> Sign { - Sign { - this_arg: if let Some(f) = orig.clone { (f)(orig.this_arg) } else { orig.this_arg }, - get_per_commitment_point: orig.get_per_commitment_point.clone(), - release_commitment_secret: orig.release_commitment_secret.clone(), - pubkeys: orig.pubkeys.clone(), - set_pubkeys: orig.set_pubkeys.clone(), - channel_keys_id: orig.channel_keys_id.clone(), - sign_counterparty_commitment: orig.sign_counterparty_commitment.clone(), - sign_holder_commitment_and_htlcs: orig.sign_holder_commitment_and_htlcs.clone(), - sign_justice_transaction: orig.sign_justice_transaction.clone(), - sign_counterparty_htlc_transaction: orig.sign_counterparty_htlc_transaction.clone(), - sign_closing_transaction: orig.sign_closing_transaction.clone(), - sign_channel_announcement: orig.sign_channel_announcement.clone(), - ready_channel: orig.ready_channel.clone(), - clone: orig.clone.clone(), - write: orig.write.clone(), - free: orig.free.clone(), - } -} -impl Clone for Sign { - fn clone(&self) -> Self { - Sign_clone(self) - } -} -impl lightning::util::ser::Writeable for Sign { - fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { - let vec = (self.write)(self.this_arg); - w.write_all(vec.as_slice()) - } -} - -use lightning::chain::keysinterface::Sign as rustSign; -impl rustSign for Sign { - fn get_per_commitment_point(&self, idx: u64, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> bitcoin::secp256k1::key::PublicKey { - let mut ret = (self.get_per_commitment_point)(self.this_arg, idx); - ret.into_rust() - } - fn release_commitment_secret(&self, idx: u64) -> [u8; 32] { - let mut ret = (self.release_commitment_secret)(self.this_arg, idx); - ret.data - } - fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys { - if let Some(f) = self.set_pubkeys { - (f)(self); - } - unsafe { &*self.pubkeys.inner } - } - fn channel_keys_id(&self) -> [u8; 32] { - let mut ret = (self.channel_keys_id)(self.this_arg); - ret.data - } - fn sign_counterparty_commitment(&self, commitment_tx: &lightning::ln::chan_utils::CommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result<(bitcoin::secp256k1::Signature, Vec), ()> { - let mut ret = (self.sign_counterparty_commitment)(self.this_arg, &crate::ln::chan_utils::CommitmentTransaction { inner: unsafe { (commitment_tx as *const _) as *mut _ }, is_owned: false }); - let mut local_ret = match ret.result_ok { true => Ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_rust() }); }; let mut local_ret_0 = (orig_ret_0_0.into_rust(), local_orig_ret_0_1); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; - local_ret - } - fn sign_holder_commitment_and_htlcs(&self, commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result<(bitcoin::secp256k1::Signature, Vec), ()> { - let mut ret = (self.sign_holder_commitment_and_htlcs)(self.this_arg, &crate::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { (commitment_tx as *const _) as *mut _ }, is_owned: false }); - let mut local_ret = match ret.result_ok { true => Ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_rust() }); }; let mut local_ret_0 = (orig_ret_0_0.into_rust(), local_orig_ret_0_1); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; - local_ret - } - fn sign_justice_transaction(&self, justice_tx: &bitcoin::blockdata::transaction::Transaction, input: usize, amount: u64, per_commitment_key: &bitcoin::secp256k1::key::SecretKey, htlc: &Option, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { - let mut local_justice_tx = ::bitcoin::consensus::encode::serialize(justice_tx); - let mut local_htlc = &crate::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { (if htlc.is_none() { std::ptr::null() } else { { (htlc.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; - let mut ret = (self.sign_justice_transaction)(self.this_arg, crate::c_types::Transaction::from_vec(local_justice_tx), input, amount, per_commitment_key.as_ref(), local_htlc); - let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; - local_ret - } - fn sign_counterparty_htlc_transaction(&self, htlc_tx: &bitcoin::blockdata::transaction::Transaction, input: usize, amount: u64, per_commitment_point: &bitcoin::secp256k1::key::PublicKey, htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { - let mut local_htlc_tx = ::bitcoin::consensus::encode::serialize(htlc_tx); - let mut ret = (self.sign_counterparty_htlc_transaction)(self.this_arg, crate::c_types::Transaction::from_vec(local_htlc_tx), input, amount, crate::c_types::PublicKey::from_rust(&per_commitment_point), &crate::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { (htlc as *const _) as *mut _ }, is_owned: false }); - let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; - local_ret - } - fn sign_closing_transaction(&self, closing_tx: &bitcoin::blockdata::transaction::Transaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { - let mut local_closing_tx = ::bitcoin::consensus::encode::serialize(closing_tx); - let mut ret = (self.sign_closing_transaction)(self.this_arg, crate::c_types::Transaction::from_vec(local_closing_tx)); - let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; - local_ret - } - fn sign_channel_announcement(&self, msg: &lightning::ln::msgs::UnsignedChannelAnnouncement, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result { - let mut ret = (self.sign_channel_announcement)(self.this_arg, &crate::ln::msgs::UnsignedChannelAnnouncement { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }); - let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; - local_ret - } - fn ready_channel(&mut self, channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) { - (self.ready_channel)(self.this_arg, &crate::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { (channel_parameters as *const _) as *mut _ }, is_owned: false }) - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for Sign { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn Sign_free(this_ptr: Sign) { } -impl Drop for Sign { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} -/// A trait to describe an object which can get user secrets and key material. -#[repr(C)] -pub struct KeysInterface { - pub this_arg: *mut c_void, - /// Get node secret key (aka node_id or network_key). - /// - /// This method must return the same value each time it is called. - #[must_use] - pub get_node_secret: extern "C" fn (this_arg: *const c_void) -> crate::c_types::SecretKey, - /// Get a script pubkey which we send funds to when claiming on-chain contestable outputs. - /// - /// This method should return a different value each time it is called, to avoid linking - /// on-chain funds across channels as controlled to the same user. - #[must_use] - pub get_destination_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z, - /// Get a public key which we will send funds to (in the form of a P2WPKH output) when closing - /// a channel. - /// - /// This method should return a different value each time it is called, to avoid linking - /// on-chain funds across channels as controlled to the same user. - #[must_use] - pub get_shutdown_pubkey: extern "C" fn (this_arg: *const c_void) -> crate::c_types::PublicKey, - /// Get a new set of Sign for per-channel secrets. These MUST be unique even if you - /// restarted with some stale data! - /// - /// This method must return a different value each time it is called. - #[must_use] - pub get_channel_signer: extern "C" fn (this_arg: *const c_void, inbound: bool, channel_value_satoshis: u64) -> crate::chain::keysinterface::Sign, - /// Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting - /// onion packets and for temporary channel IDs. There is no requirement that these be - /// persisted anywhere, though they must be unique across restarts. - /// - /// This method must return a different value each time it is called. - #[must_use] - pub get_secure_random_bytes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes, - /// Reads a `Signer` for this `KeysInterface` from the given input stream. - /// This is only called during deserialization of other objects which contain - /// `Sign`-implementing objects (ie `ChannelMonitor`s and `ChannelManager`s). - /// The bytes are exactly those which `::write()` writes, and - /// contain no versioning scheme. You may wish to include your own version prefix and ensure - /// you've read all of the provided bytes to ensure no corruption occurred. - #[must_use] - pub read_chan_signer: extern "C" fn (this_arg: *const c_void, reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SignDecodeErrorZ, - pub free: Option, -} -unsafe impl Send for KeysInterface {} -unsafe impl Sync for KeysInterface {} - -use lightning::chain::keysinterface::KeysInterface as rustKeysInterface; -impl rustKeysInterface for KeysInterface { - type Signer = crate::chain::keysinterface::Sign; - fn get_node_secret(&self) -> bitcoin::secp256k1::key::SecretKey { - let mut ret = (self.get_node_secret)(self.this_arg); - ret.into_rust() - } - fn get_destination_script(&self) -> bitcoin::blockdata::script::Script { - let mut ret = (self.get_destination_script)(self.this_arg); - ::bitcoin::blockdata::script::Script::from(ret.into_rust()) - } - fn get_shutdown_pubkey(&self) -> bitcoin::secp256k1::key::PublicKey { - let mut ret = (self.get_shutdown_pubkey)(self.this_arg); - ret.into_rust() - } - fn get_channel_signer(&self, inbound: bool, channel_value_satoshis: u64) -> crate::chain::keysinterface::Sign { - let mut ret = (self.get_channel_signer)(self.this_arg, inbound, channel_value_satoshis); - ret - } - fn get_secure_random_bytes(&self) -> [u8; 32] { - let mut ret = (self.get_secure_random_bytes)(self.this_arg); - ret.data - } - fn read_chan_signer(&self, reader: &[u8]) -> Result { - let mut local_reader = crate::c_types::u8slice::from_slice(reader); - let mut ret = (self.read_chan_signer)(self.this_arg, local_reader); - let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; - local_ret - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for KeysInterface { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn KeysInterface_free(this_ptr: KeysInterface) { } -impl Drop for KeysInterface { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} - -use lightning::chain::keysinterface::InMemorySigner as nativeInMemorySignerImport; -type nativeInMemorySigner = nativeInMemorySignerImport; - -/// A simple implementation of Sign that just keeps the private keys in memory. -/// -/// This implementation performs no policy checks and is insufficient by itself as -/// a secure external signer. -#[must_use] -#[repr(C)] -pub struct InMemorySigner { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeInMemorySigner, - pub is_owned: bool, -} - -impl Drop for InMemorySigner { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeInMemorySigner>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn InMemorySigner_free(this_ptr: InMemorySigner) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn InMemorySigner_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInMemorySigner); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl InMemorySigner { - pub(crate) fn take_inner(mut self) -> *mut nativeInMemorySigner { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Private key of anchor tx -#[no_mangle] -pub extern "C" fn InMemorySigner_get_funding_key(this_ptr: &InMemorySigner) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_key; - (*inner_val).as_ref() -} -/// Private key of anchor tx -#[no_mangle] -pub extern "C" fn InMemorySigner_set_funding_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) { - unsafe { &mut *this_ptr.inner }.funding_key = val.into_rust(); -} -/// Holder secret key for blinded revocation pubkey -#[no_mangle] -pub extern "C" fn InMemorySigner_get_revocation_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_base_key; - (*inner_val).as_ref() -} -/// Holder secret key for blinded revocation pubkey -#[no_mangle] -pub extern "C" fn InMemorySigner_set_revocation_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) { - unsafe { &mut *this_ptr.inner }.revocation_base_key = val.into_rust(); -} -/// Holder secret key used for our balance in counterparty-broadcasted commitment transactions -#[no_mangle] -pub extern "C" fn InMemorySigner_get_payment_key(this_ptr: &InMemorySigner) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_key; - (*inner_val).as_ref() -} -/// Holder secret key used for our balance in counterparty-broadcasted commitment transactions -#[no_mangle] -pub extern "C" fn InMemorySigner_set_payment_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) { - unsafe { &mut *this_ptr.inner }.payment_key = val.into_rust(); -} -/// Holder secret key used in HTLC tx -#[no_mangle] -pub extern "C" fn InMemorySigner_get_delayed_payment_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.delayed_payment_base_key; - (*inner_val).as_ref() -} -/// Holder secret key used in HTLC tx -#[no_mangle] -pub extern "C" fn InMemorySigner_set_delayed_payment_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) { - unsafe { &mut *this_ptr.inner }.delayed_payment_base_key = val.into_rust(); -} -/// Holder htlc secret key used in commitment tx htlc outputs -#[no_mangle] -pub extern "C" fn InMemorySigner_get_htlc_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_base_key; - (*inner_val).as_ref() -} -/// Holder htlc secret key used in commitment tx htlc outputs -#[no_mangle] -pub extern "C" fn InMemorySigner_set_htlc_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) { - unsafe { &mut *this_ptr.inner }.htlc_base_key = val.into_rust(); -} -/// Commitment seed -#[no_mangle] -pub extern "C" fn InMemorySigner_get_commitment_seed(this_ptr: &InMemorySigner) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.commitment_seed; - &(*inner_val) -} -/// Commitment seed -#[no_mangle] -pub extern "C" fn InMemorySigner_set_commitment_seed(this_ptr: &mut InMemorySigner, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.commitment_seed = val.data; -} -impl Clone for InMemorySigner { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeInMemorySigner>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn InMemorySigner_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInMemorySigner)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn InMemorySigner_clone(orig: &InMemorySigner) -> InMemorySigner { - orig.clone() -} -/// Create a new InMemorySigner -#[must_use] -#[no_mangle] -pub extern "C" fn InMemorySigner_new(mut funding_key: crate::c_types::SecretKey, mut revocation_base_key: crate::c_types::SecretKey, mut payment_key: crate::c_types::SecretKey, mut delayed_payment_base_key: crate::c_types::SecretKey, mut htlc_base_key: crate::c_types::SecretKey, mut commitment_seed: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis: u64, mut channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::chain::keysinterface::InMemorySigner { - let mut ret = lightning::chain::keysinterface::InMemorySigner::new(secp256k1::SECP256K1, funding_key.into_rust(), revocation_base_key.into_rust(), payment_key.into_rust(), delayed_payment_base_key.into_rust(), htlc_base_key.into_rust(), commitment_seed.data, channel_value_satoshis, channel_keys_id.data); - crate::chain::keysinterface::InMemorySigner { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Counterparty pubkeys. -/// Will panic if ready_channel wasn't called. -#[must_use] -#[no_mangle] -pub extern "C" fn InMemorySigner_counterparty_pubkeys(this_arg: &InMemorySigner) -> crate::ln::chan_utils::ChannelPublicKeys { - let mut ret = unsafe { &*this_arg.inner }.counterparty_pubkeys(); - crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } -} - -/// The contest_delay value specified by our counterparty and applied on holder-broadcastable -/// transactions, ie the amount of time that we have to wait to recover our funds if we -/// broadcast a transaction. -/// Will panic if ready_channel wasn't called. -#[must_use] -#[no_mangle] -pub extern "C" fn InMemorySigner_counterparty_selected_contest_delay(this_arg: &InMemorySigner) -> u16 { - let mut ret = unsafe { &*this_arg.inner }.counterparty_selected_contest_delay(); - ret -} - -/// The contest_delay value specified by us and applied on transactions broadcastable -/// by our counterparty, ie the amount of time that they have to wait to recover their funds -/// if they broadcast a transaction. -/// Will panic if ready_channel wasn't called. -#[must_use] -#[no_mangle] -pub extern "C" fn InMemorySigner_holder_selected_contest_delay(this_arg: &InMemorySigner) -> u16 { - let mut ret = unsafe { &*this_arg.inner }.holder_selected_contest_delay(); - ret -} - -/// Whether the holder is the initiator -/// Will panic if ready_channel wasn't called. -#[must_use] -#[no_mangle] -pub extern "C" fn InMemorySigner_is_outbound(this_arg: &InMemorySigner) -> bool { - let mut ret = unsafe { &*this_arg.inner }.is_outbound(); - ret -} - -/// Funding outpoint -/// Will panic if ready_channel wasn't called. -#[must_use] -#[no_mangle] -pub extern "C" fn InMemorySigner_funding_outpoint(this_arg: &InMemorySigner) -> crate::chain::transaction::OutPoint { - let mut ret = unsafe { &*this_arg.inner }.funding_outpoint(); - crate::chain::transaction::OutPoint { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } -} - -/// Obtain a ChannelTransactionParameters for this channel, to be used when verifying or -/// building transactions. -/// -/// Will panic if ready_channel wasn't called. -#[must_use] -#[no_mangle] -pub extern "C" fn InMemorySigner_get_channel_parameters(this_arg: &InMemorySigner) -> crate::ln::chan_utils::ChannelTransactionParameters { - let mut ret = unsafe { &*this_arg.inner }.get_channel_parameters(); - crate::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } -} - -/// Sign the single input of spend_tx at index `input_idx` which spends the output -/// described by descriptor, returning the witness stack for the input. -/// -/// Returns an Err if the input at input_idx does not exist, has a non-empty script_sig, -/// or is not spending the outpoint described by `descriptor.outpoint`. -#[must_use] -#[no_mangle] -pub extern "C" fn InMemorySigner_sign_counterparty_payment_input(this_arg: &InMemorySigner, mut spend_tx: crate::c_types::Transaction, mut input_idx: usize, descriptor: &crate::chain::keysinterface::StaticPaymentOutputDescriptor) -> crate::c_types::derived::CResult_CVec_CVec_u8ZZNoneZ { - let mut ret = unsafe { &*this_arg.inner }.sign_counterparty_payment_input(&spend_tx.into_bitcoin(), input_idx, unsafe { &*descriptor.inner }, secp256k1::SECP256K1); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for mut item in o.drain(..) { local_ret_0.push( { let mut local_ret_0_0 = Vec::new(); for mut item in item.drain(..) { local_ret_0_0.push( { item }); }; local_ret_0_0.into() }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }).into() }; - local_ret -} - -/// Sign the single input of spend_tx at index `input_idx` which spends the output -/// described by descriptor, returning the witness stack for the input. -/// -/// Returns an Err if the input at input_idx does not exist, has a non-empty script_sig, -/// is not spending the outpoint described by `descriptor.outpoint`, or does not have a -/// sequence set to `descriptor.to_self_delay`. -#[must_use] -#[no_mangle] -pub extern "C" fn InMemorySigner_sign_dynamic_p2wsh_input(this_arg: &InMemorySigner, mut spend_tx: crate::c_types::Transaction, mut input_idx: usize, descriptor: &crate::chain::keysinterface::DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CResult_CVec_CVec_u8ZZNoneZ { - let mut ret = unsafe { &*this_arg.inner }.sign_dynamic_p2wsh_input(&spend_tx.into_bitcoin(), input_idx, unsafe { &*descriptor.inner }, secp256k1::SECP256K1); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for mut item in o.drain(..) { local_ret_0.push( { let mut local_ret_0_0 = Vec::new(); for mut item in item.drain(..) { local_ret_0_0.push( { item }); }; local_ret_0_0.into() }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }).into() }; - local_ret -} - -impl From for crate::chain::keysinterface::Sign { - fn from(obj: nativeInMemorySigner) -> Self { - let mut rust_obj = InMemorySigner { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = InMemorySigner_as_Sign(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(InMemorySigner_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn InMemorySigner_as_Sign(this_arg: &InMemorySigner) -> crate::chain::keysinterface::Sign { - crate::chain::keysinterface::Sign { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - get_per_commitment_point: InMemorySigner_Sign_get_per_commitment_point, - release_commitment_secret: InMemorySigner_Sign_release_commitment_secret, - - pubkeys: crate::ln::chan_utils::ChannelPublicKeys { inner: std::ptr::null_mut(), is_owned: true }, - set_pubkeys: Some(InMemorySigner_Sign_set_pubkeys), - channel_keys_id: InMemorySigner_Sign_channel_keys_id, - sign_counterparty_commitment: InMemorySigner_Sign_sign_counterparty_commitment, - sign_holder_commitment_and_htlcs: InMemorySigner_Sign_sign_holder_commitment_and_htlcs, - sign_justice_transaction: InMemorySigner_Sign_sign_justice_transaction, - sign_counterparty_htlc_transaction: InMemorySigner_Sign_sign_counterparty_htlc_transaction, - sign_closing_transaction: InMemorySigner_Sign_sign_closing_transaction, - sign_channel_announcement: InMemorySigner_Sign_sign_channel_announcement, - ready_channel: InMemorySigner_Sign_ready_channel, - clone: Some(InMemorySigner_clone_void), - write: InMemorySigner_write_void, - } -} - -#[must_use] -extern "C" fn InMemorySigner_Sign_get_per_commitment_point(this_arg: *const c_void, mut idx: u64) -> crate::c_types::PublicKey { - let mut ret = >::get_per_commitment_point(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, secp256k1::SECP256K1); - crate::c_types::PublicKey::from_rust(&ret) -} -#[must_use] -extern "C" fn InMemorySigner_Sign_release_commitment_secret(this_arg: *const c_void, mut idx: u64) -> crate::c_types::ThirtyTwoBytes { - let mut ret = >::release_commitment_secret(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx); - crate::c_types::ThirtyTwoBytes { data: ret } -} -#[must_use] -extern "C" fn InMemorySigner_Sign_pubkeys(this_arg: *const c_void) -> crate::ln::chan_utils::ChannelPublicKeys { - let mut ret = >::pubkeys(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, ); - crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } -} -extern "C" fn InMemorySigner_Sign_set_pubkeys(trait_self_arg: &Sign) { - // This is a bit race-y in the general case, but for our specific use-cases today, we're safe - // Specifically, we must ensure that the first time we're called it can never be in parallel - if trait_self_arg.pubkeys.inner.is_null() { - unsafe { &mut *(trait_self_arg as *const Sign as *mut Sign) }.pubkeys = InMemorySigner_Sign_pubkeys(trait_self_arg.this_arg); - } -} -#[must_use] -extern "C" fn InMemorySigner_Sign_channel_keys_id(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes { - let mut ret = >::channel_keys_id(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, ); - crate::c_types::ThirtyTwoBytes { data: ret } -} -#[must_use] -extern "C" fn InMemorySigner_Sign_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 = >::sign_counterparty_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, unsafe { &*commitment_tx.inner }, secp256k1::SECP256K1); - 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 mut 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 -} -#[must_use] -extern "C" fn InMemorySigner_Sign_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 = >::sign_holder_commitment_and_htlcs(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, unsafe { &*commitment_tx.inner }, secp256k1::SECP256K1); - 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 mut 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 -} -#[must_use] -extern "C" fn InMemorySigner_Sign_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 ret = >::sign_justice_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &justice_tx.into_bitcoin(), input, amount, &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *per_commitment_key}[..]).unwrap(), &local_htlc, secp256k1::SECP256K1); - 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 -} -#[must_use] -extern "C" fn InMemorySigner_Sign_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 = >::sign_counterparty_htlc_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &htlc_tx.into_bitcoin(), input, amount, &per_commitment_point.into_rust(), unsafe { &*htlc.inner }, secp256k1::SECP256K1); - 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 -} -#[must_use] -extern "C" fn InMemorySigner_Sign_sign_closing_transaction(this_arg: *const c_void, mut closing_tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_SignatureNoneZ { - let mut ret = >::sign_closing_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &closing_tx.into_bitcoin(), secp256k1::SECP256K1); - 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 -} -#[must_use] -extern "C" fn InMemorySigner_Sign_sign_channel_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_SignatureNoneZ { - let mut ret = >::sign_channel_announcement(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, unsafe { &*msg.inner }, secp256k1::SECP256K1); - 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 -} -extern "C" fn InMemorySigner_Sign_ready_channel(this_arg: *mut c_void, channel_parameters: &crate::ln::chan_utils::ChannelTransactionParameters) { - >::ready_channel(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, unsafe { &*channel_parameters.inner }) -} - -#[no_mangle] -pub extern "C" fn InMemorySigner_write(obj: &InMemorySigner) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn InMemorySigner_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInMemorySigner) }) -} -#[no_mangle] -pub extern "C" fn InMemorySigner_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InMemorySignerDecodeErrorZ { - 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::InMemorySigner { 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 -} - -use lightning::chain::keysinterface::KeysManager as nativeKeysManagerImport; -type nativeKeysManager = nativeKeysManagerImport; - -/// Simple KeysInterface implementor that takes a 32-byte seed for use as a BIP 32 extended key -/// and derives keys from that. -/// -/// Your node_id is seed/0' -/// ChannelMonitor closes may use seed/1' -/// Cooperative closes may use seed/2' -/// The two close keys may be needed to claim on-chain funds! -#[must_use] -#[repr(C)] -pub struct KeysManager { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeKeysManager, - pub is_owned: bool, -} - -impl Drop for KeysManager { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeKeysManager>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn KeysManager_free(this_ptr: KeysManager) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn KeysManager_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeKeysManager); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl KeysManager { - pub(crate) fn take_inner(mut self) -> *mut nativeKeysManager { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Constructs a KeysManager from a 32-byte seed. If the seed is in some way biased (eg your -/// CSRNG is busted) this may panic (but more importantly, you will possibly lose funds). -/// starting_time isn't strictly required to actually be a time, but it must absolutely, -/// without a doubt, be unique to this instance. ie if you start multiple times with the same -/// seed, starting_time must be unique to each run. Thus, the easiest way to achieve this is to -/// simply use the current time (with very high precision). -/// -/// The seed MUST be backed up safely prior to use so that the keys can be re-created, however, -/// obviously, starting_time should be unique every time you reload the library - it is only -/// used to generate new ephemeral key data (which will be stored by the individual channel if -/// necessary). -/// -/// Note that the seed is required to recover certain on-chain funds independent of -/// ChannelMonitor data, though a current copy of ChannelMonitor data is also required for any -/// channel, and some on-chain during-closing funds. -/// -/// Note that until the 0.1 release there is no guarantee of backward compatibility between -/// versions. Once the library is more fully supported, the docs will be updated to include a -/// detailed description of the guarantee. -#[must_use] -#[no_mangle] -pub extern "C" fn KeysManager_new(seed: *const [u8; 32], mut starting_time_secs: u64, mut starting_time_nanos: u32) -> KeysManager { - let mut ret = lightning::chain::keysinterface::KeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos); - KeysManager { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Derive an old Sign containing per-channel secrets based on a key derivation parameters. -/// -/// Key derivation parameters are accessible through a per-channel secrets -/// Sign::channel_keys_id and is provided inside DynamicOuputP2WSH in case of -/// onchain output detection for which a corresponding delayed_payment_key must be derived. -#[must_use] -#[no_mangle] -pub extern "C" fn KeysManager_derive_channel_keys(this_arg: &KeysManager, mut channel_value_satoshis: u64, params: *const [u8; 32]) -> crate::chain::keysinterface::InMemorySigner { - let mut ret = unsafe { &*this_arg.inner }.derive_channel_keys(channel_value_satoshis, unsafe { &*params}); - crate::chain::keysinterface::InMemorySigner { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Creates a Transaction which spends the given descriptors to the given outputs, plus an -/// output to the given change destination (if sufficient change value remains). The -/// transaction will have a feerate, at least, of the given value. -/// -/// Returns `Err(())` if the output value is greater than the input value minus required fee or -/// if a descriptor was duplicated. -/// -/// We do not enforce that outputs meet the dust limit or that any output scripts are standard. -/// -/// May panic if the `SpendableOutputDescriptor`s were not generated by Channels which used -/// this KeysManager or one of the `InMemorySigner` created by this KeysManager. -#[must_use] -#[no_mangle] -pub extern "C" fn KeysManager_spend_spendable_outputs(this_arg: &KeysManager, mut descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, mut outputs: crate::c_types::derived::CVec_TxOutZ, mut change_destination_script: crate::c_types::derived::CVec_u8Z, mut feerate_sat_per_1000_weight: u32) -> crate::c_types::derived::CResult_TransactionNoneZ { - let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); }; - let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); }; - let mut ret = unsafe { &*this_arg.inner }.spend_spendable_outputs(&local_descriptors.iter().collect::>()[..], local_outputs, ::bitcoin::blockdata::script::Script::from(change_destination_script.into_rust()), feerate_sat_per_1000_weight, secp256k1::SECP256K1); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = ::bitcoin::consensus::encode::serialize(&o); crate::c_types::Transaction::from_vec(local_ret_0) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }).into() }; - local_ret -} - -impl From for crate::chain::keysinterface::KeysInterface { - fn from(obj: nativeKeysManager) -> Self { - let mut rust_obj = KeysManager { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = KeysManager_as_KeysInterface(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(KeysManager_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn KeysManager_as_KeysInterface(this_arg: &KeysManager) -> crate::chain::keysinterface::KeysInterface { - crate::chain::keysinterface::KeysInterface { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - get_node_secret: KeysManager_KeysInterface_get_node_secret, - get_destination_script: KeysManager_KeysInterface_get_destination_script, - get_shutdown_pubkey: KeysManager_KeysInterface_get_shutdown_pubkey, - get_channel_signer: KeysManager_KeysInterface_get_channel_signer, - get_secure_random_bytes: KeysManager_KeysInterface_get_secure_random_bytes, - read_chan_signer: KeysManager_KeysInterface_read_chan_signer, - } -} - -#[must_use] -extern "C" fn KeysManager_KeysInterface_get_node_secret(this_arg: *const c_void) -> crate::c_types::SecretKey { - let mut ret = >::get_node_secret(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, ); - crate::c_types::SecretKey::from_rust(ret) -} -#[must_use] -extern "C" fn KeysManager_KeysInterface_get_destination_script(this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z { - let mut ret = >::get_destination_script(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, ); - ret.into_bytes().into() -} -#[must_use] -extern "C" fn KeysManager_KeysInterface_get_shutdown_pubkey(this_arg: *const c_void) -> crate::c_types::PublicKey { - let mut ret = >::get_shutdown_pubkey(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, ); - crate::c_types::PublicKey::from_rust(&ret) -} -#[must_use] -extern "C" fn KeysManager_KeysInterface_get_channel_signer(this_arg: *const c_void, mut _inbound: bool, mut channel_value_satoshis: u64) -> crate::chain::keysinterface::Sign { - let mut ret = >::get_channel_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, _inbound, channel_value_satoshis); - ret.into() -} -#[must_use] -extern "C" fn KeysManager_KeysInterface_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes { - let mut ret = >::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, ); - crate::c_types::ThirtyTwoBytes { data: ret } -} -#[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_SignDecodeErrorZ { - let mut ret = >::read_chan_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, reader.to_slice()); - 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 -} - diff --git a/lightning-c-bindings/src/chain/mod.rs b/lightning-c-bindings/src/chain/mod.rs deleted file mode 100644 index fb72263f3..000000000 --- a/lightning-c-bindings/src/chain/mod.rs +++ /dev/null @@ -1,299 +0,0 @@ -//! Structs and traits which allow other parts of rust-lightning to interact with the blockchain. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - -pub mod chaininterface; -pub mod chainmonitor; -pub mod channelmonitor; -pub mod transaction; -pub mod keysinterface; -/// An error when accessing the chain via [`Access`]. -/// -/// [`Access`]: trait.Access.html -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum AccessError { - /// The requested chain is unknown. - UnknownChain, - /// The requested transaction doesn't exist or hasn't confirmed. - UnknownTx, -} -use lightning::chain::AccessError as nativeAccessError; -impl AccessError { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeAccessError { - match self { - AccessError::UnknownChain => nativeAccessError::UnknownChain, - AccessError::UnknownTx => nativeAccessError::UnknownTx, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativeAccessError { - match self { - AccessError::UnknownChain => nativeAccessError::UnknownChain, - AccessError::UnknownTx => nativeAccessError::UnknownTx, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativeAccessError) -> Self { - match native { - nativeAccessError::UnknownChain => AccessError::UnknownChain, - nativeAccessError::UnknownTx => AccessError::UnknownTx, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativeAccessError) -> Self { - match native { - nativeAccessError::UnknownChain => AccessError::UnknownChain, - nativeAccessError::UnknownTx => AccessError::UnknownTx, - } - } -} -#[no_mangle] -pub extern "C" fn AccessError_clone(orig: &AccessError) -> AccessError { - orig.clone() -} -/// The `Access` trait defines behavior for accessing chain data and state, such as blocks and -/// UTXOs. -#[repr(C)] -pub struct Access { - pub this_arg: *mut c_void, - /// Returns the transaction output of a funding transaction encoded by [`short_channel_id`]. - /// Returns an error if `genesis_hash` is for a different chain or if such a transaction output - /// is unknown. - /// - /// [`short_channel_id`]: https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md#definition-of-short_channel_id - #[must_use] - pub get_utxo: extern "C" fn (this_arg: *const c_void, genesis_hash: *const [u8; 32], short_channel_id: u64) -> crate::c_types::derived::CResult_TxOutAccessErrorZ, - pub free: Option, -} -unsafe impl Send for Access {} -unsafe impl Sync for Access {} - -use lightning::chain::Access as rustAccess; -impl rustAccess for Access { - fn get_utxo(&self, genesis_hash: &bitcoin::hash_types::BlockHash, short_channel_id: u64) -> Result { - let mut ret = (self.get_utxo)(self.this_arg, genesis_hash.as_inner(), short_channel_id); - let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })}; - local_ret - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for Access { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn Access_free(this_ptr: Access) { } -impl Drop for Access { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} -/// The `Listen` trait is used to be notified of when blocks have been connected or disconnected -/// from the chain. -/// -/// Useful when needing to replay chain data upon startup or as new chain events occur. -#[repr(C)] -pub struct Listen { - pub this_arg: *mut c_void, - /// Notifies the listener that a block was added at the given height. - pub block_connected: extern "C" fn (this_arg: *const c_void, block: crate::c_types::u8slice, height: u32), - /// Notifies the listener that a block was removed at the given height. - pub block_disconnected: extern "C" fn (this_arg: *const c_void, header: *const [u8; 80], height: u32), - pub free: Option, -} - -use lightning::chain::Listen as rustListen; -impl rustListen for Listen { - fn block_connected(&self, block: &bitcoin::blockdata::block::Block, height: u32) { - let mut local_block = ::bitcoin::consensus::encode::serialize(block); - (self.block_connected)(self.this_arg, crate::c_types::u8slice::from_slice(&local_block), height) - } - fn block_disconnected(&self, header: &bitcoin::blockdata::block::BlockHeader, height: u32) { - let mut local_header = { let mut s = [0u8; 80]; s[..].copy_from_slice(&::bitcoin::consensus::encode::serialize(header)); s }; - (self.block_disconnected)(self.this_arg, &local_header, height) - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for Listen { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn Listen_free(this_ptr: Listen) { } -impl Drop for Listen { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} -/// The `Watch` trait defines behavior for watching on-chain activity pertaining to channels as -/// blocks are connected and disconnected. -/// -/// Each channel is associated with a [`ChannelMonitor`]. Implementations of this trait are -/// responsible for maintaining a set of monitors such that they can be updated accordingly as -/// channel state changes and HTLCs are resolved. See method documentation for specific -/// requirements. -/// -/// Implementations **must** ensure that updates are successfully applied and persisted upon method -/// completion. If an update fails with a [`PermanentFailure`], then it must immediately shut down -/// without taking any further action such as persisting the current state. -/// -/// If an implementation maintains multiple instances of a channel's monitor (e.g., by storing -/// backup copies), then it must ensure that updates are applied across all instances. Otherwise, it -/// could result in a revoked transaction being broadcast, allowing the counterparty to claim all -/// funds in the channel. See [`ChannelMonitorUpdateErr`] for more details about how to handle -/// multiple instances. -/// -/// [`ChannelMonitor`]: channelmonitor/struct.ChannelMonitor.html -/// [`ChannelMonitorUpdateErr`]: channelmonitor/enum.ChannelMonitorUpdateErr.html -/// [`PermanentFailure`]: channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.PermanentFailure -#[repr(C)] -pub struct Watch { - pub this_arg: *mut c_void, - /// Watches a channel identified by `funding_txo` using `monitor`. - /// - /// Implementations are responsible for watching the chain for the funding transaction along - /// with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means - /// calling [`block_connected`] and [`block_disconnected`] on the monitor. - /// - /// [`get_outputs_to_watch`]: channelmonitor/struct.ChannelMonitor.html#method.get_outputs_to_watch - /// [`block_connected`]: channelmonitor/struct.ChannelMonitor.html#method.block_connected - /// [`block_disconnected`]: channelmonitor/struct.ChannelMonitor.html#method.block_disconnected - #[must_use] - pub watch_channel: extern "C" fn (this_arg: *const c_void, funding_txo: crate::chain::transaction::OutPoint, monitor: crate::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ, - /// Updates a channel identified by `funding_txo` by applying `update` to its monitor. - /// - /// Implementations must call [`update_monitor`] with the given update. See - /// [`ChannelMonitorUpdateErr`] for invariants around returning an error. - /// - /// [`update_monitor`]: channelmonitor/struct.ChannelMonitor.html#method.update_monitor - /// [`ChannelMonitorUpdateErr`]: channelmonitor/enum.ChannelMonitorUpdateErr.html - #[must_use] - pub update_channel: extern "C" fn (this_arg: *const c_void, funding_txo: crate::chain::transaction::OutPoint, update: crate::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ, - /// Returns any monitor events since the last call. Subsequent calls must only return new - /// events. - #[must_use] - pub release_pending_monitor_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MonitorEventZ, - pub free: Option, -} -unsafe impl Send for Watch {} -unsafe impl Sync for Watch {} - -use lightning::chain::Watch as rustWatch; -impl rustWatch for Watch { - fn watch_channel(&self, funding_txo: lightning::chain::transaction::OutPoint, monitor: lightning::chain::channelmonitor::ChannelMonitor) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> { - let mut ret = (self.watch_channel)(self.this_arg, crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo)), is_owned: true }, crate::chain::channelmonitor::ChannelMonitor { inner: Box::into_raw(Box::new(monitor)), is_owned: true }); - let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })}; - local_ret - } - fn update_channel(&self, funding_txo: lightning::chain::transaction::OutPoint, update: lightning::chain::channelmonitor::ChannelMonitorUpdate) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> { - let mut ret = (self.update_channel)(self.this_arg, crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo)), is_owned: true }, crate::chain::channelmonitor::ChannelMonitorUpdate { inner: Box::into_raw(Box::new(update)), is_owned: true }); - let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })}; - local_ret - } - fn release_pending_monitor_events(&self) -> Vec { - let mut ret = (self.release_pending_monitor_events)(self.this_arg); - let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); }; - local_ret - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for Watch { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn Watch_free(this_ptr: Watch) { } -impl Drop for Watch { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} -/// The `Filter` trait defines behavior for indicating chain activity of interest pertaining to -/// channels. -/// -/// This is useful in order to have a [`Watch`] implementation convey to a chain source which -/// transactions to be notified of. Notification may take the form of pre-filtering blocks or, in -/// the case of [BIP 157]/[BIP 158], only fetching a block if the compact filter matches. If -/// receiving full blocks from a chain source, any further filtering is unnecessary. -/// -/// After an output has been registered, subsequent block retrievals from the chain source must not -/// exclude any transactions matching the new criteria nor any in-block descendants of such -/// transactions. -/// -/// Note that use as part of a [`Watch`] implementation involves reentrancy. Therefore, the `Filter` -/// should not block on I/O. Implementations should instead queue the newly monitored data to be -/// processed later. Then, in order to block until the data has been processed, any `Watch` -/// invocation that has called the `Filter` must return [`TemporaryFailure`]. -/// -/// [`Watch`]: trait.Watch.html -/// [`TemporaryFailure`]: channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.TemporaryFailure -/// [BIP 157]: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki -/// [BIP 158]: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki -#[repr(C)] -pub struct Filter { - pub this_arg: *mut c_void, - /// Registers interest in a transaction with `txid` and having an output with `script_pubkey` as - /// a spending condition. - pub register_tx: extern "C" fn (this_arg: *const c_void, txid: *const [u8; 32], script_pubkey: crate::c_types::u8slice), - /// Registers interest in spends of a transaction output identified by `outpoint` having - /// `script_pubkey` as the spending condition. - pub register_output: extern "C" fn (this_arg: *const c_void, outpoint: &crate::chain::transaction::OutPoint, script_pubkey: crate::c_types::u8slice), - pub free: Option, -} -unsafe impl Send for Filter {} -unsafe impl Sync for Filter {} - -use lightning::chain::Filter as rustFilter; -impl rustFilter for Filter { - fn register_tx(&self, txid: &bitcoin::hash_types::Txid, script_pubkey: &bitcoin::blockdata::script::Script) { - (self.register_tx)(self.this_arg, txid.as_inner(), crate::c_types::u8slice::from_slice(&script_pubkey[..])) - } - fn register_output(&self, outpoint: &lightning::chain::transaction::OutPoint, script_pubkey: &bitcoin::blockdata::script::Script) { - (self.register_output)(self.this_arg, &crate::chain::transaction::OutPoint { inner: unsafe { (outpoint as *const _) as *mut _ }, is_owned: false }, crate::c_types::u8slice::from_slice(&script_pubkey[..])) - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for Filter { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn Filter_free(this_ptr: Filter) { } -impl Drop for Filter { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} diff --git a/lightning-c-bindings/src/chain/transaction.rs b/lightning-c-bindings/src/chain/transaction.rs deleted file mode 100644 index f9432230f..000000000 --- a/lightning-c-bindings/src/chain/transaction.rs +++ /dev/null @@ -1,117 +0,0 @@ -//! Types describing on-chain transactions. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - - -use lightning::chain::transaction::OutPoint as nativeOutPointImport; -type nativeOutPoint = nativeOutPointImport; - -/// A reference to a transaction output. -/// -/// Differs from bitcoin::blockdata::transaction::OutPoint as the index is a u16 instead of u32 -/// due to LN's restrictions on index values. Should reduce (possibly) unsafe conversions this way. -#[must_use] -#[repr(C)] -pub struct OutPoint { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeOutPoint, - pub is_owned: bool, -} - -impl Drop for OutPoint { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeOutPoint>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn OutPoint_free(this_ptr: OutPoint) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn OutPoint_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeOutPoint); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl OutPoint { - pub(crate) fn take_inner(mut self) -> *mut nativeOutPoint { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The referenced transaction's txid. -#[no_mangle] -pub extern "C" fn OutPoint_get_txid(this_ptr: &OutPoint) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.txid; - (*inner_val).as_inner() -} -/// The referenced transaction's txid. -#[no_mangle] -pub extern "C" fn OutPoint_set_txid(this_ptr: &mut OutPoint, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap(); -} -/// The index of the referenced output in its transaction's vout. -#[no_mangle] -pub extern "C" fn OutPoint_get_index(this_ptr: &OutPoint) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.index; - (*inner_val) -} -/// The index of the referenced output in its transaction's vout. -#[no_mangle] -pub extern "C" fn OutPoint_set_index(this_ptr: &mut OutPoint, mut val: u16) { - unsafe { &mut *this_ptr.inner }.index = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn OutPoint_new(mut txid_arg: crate::c_types::ThirtyTwoBytes, mut index_arg: u16) -> OutPoint { - OutPoint { inner: Box::into_raw(Box::new(nativeOutPoint { - txid: ::bitcoin::hash_types::Txid::from_slice(&txid_arg.data[..]).unwrap(), - index: index_arg, - })), is_owned: true } -} -impl Clone for OutPoint { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeOutPoint>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn OutPoint_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeOutPoint)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn OutPoint_clone(orig: &OutPoint) -> OutPoint { - orig.clone() -} -/// Convert an `OutPoint` to a lightning channel id. -#[must_use] -#[no_mangle] -pub extern "C" fn OutPoint_to_channel_id(this_arg: &OutPoint) -> crate::c_types::ThirtyTwoBytes { - let mut ret = unsafe { &*this_arg.inner }.to_channel_id(); - crate::c_types::ThirtyTwoBytes { data: ret } -} - -#[no_mangle] -pub extern "C" fn OutPoint_write(obj: &OutPoint) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn OutPoint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOutPoint) }) -} -#[no_mangle] -pub extern "C" fn OutPoint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_OutPointDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::chain::transaction::OutPoint { 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 -} diff --git a/lightning-c-bindings/src/lib.rs b/lightning-c-bindings/src/lib.rs deleted file mode 100644 index 89dfc0903..000000000 --- a/lightning-c-bindings/src/lib.rs +++ /dev/null @@ -1,24 +0,0 @@ -//!lightning -//! Rust-Lightning, not Rusty's Lightning! -//! -//! A full-featured but also flexible lightning implementation, in library form. This allows the -//! user (you) to decide how they wish to use it instead of being a fully self-contained daemon. -//! This means there is no built-in threading/execution environment and it's up to the user to -//! figure out how best to make networking happen/timers fire/things get written to disk/keys get -//! generated/etc. This makes it a good candidate for tight integration into an existing wallet -//! instead of having a rather-separate lightning appendage to a wallet. -#![allow(unknown_lints)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(unused_imports)] -#![allow(unused_variables)] -#![allow(unused_mut)] -#![allow(unused_parens)] -#![allow(unused_unsafe)] -#![allow(unused_braces)] -mod c_types; -mod bitcoin; -pub mod util; -pub mod chain; -pub mod ln; -pub mod routing; diff --git a/lightning-c-bindings/src/ln/chan_utils.rs b/lightning-c-bindings/src/ln/chan_utils.rs deleted file mode 100644 index 4a2656780..000000000 --- a/lightning-c-bindings/src/ln/chan_utils.rs +++ /dev/null @@ -1,1366 +0,0 @@ -//! Various utilities for building scripts and deriving keys related to channels. These are -//! largely of interest for those implementing chain::keysinterface::Sign message signing by hand. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - -/// Build the commitment secret from the seed and the commitment number -#[no_mangle] -pub extern "C" fn build_commitment_secret(commitment_seed: *const [u8; 32], mut idx: u64) -> crate::c_types::ThirtyTwoBytes { - let mut ret = lightning::ln::chan_utils::build_commitment_secret(unsafe { &*commitment_seed}, idx); - crate::c_types::ThirtyTwoBytes { data: ret } -} - -/// Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key) -/// from the base secret and the per_commitment_point. -/// -/// Note that this is infallible iff we trust that at least one of the two input keys are randomly -/// generated (ie our own). -#[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_SecretKeyErrorZ { - let mut ret = lightning::ln::chan_utils::derive_private_key(secp256k1::SECP256K1, &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) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() }; - local_ret -} - -/// Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key) -/// from the base point and the per_commitment_key. This is the public equivalent of -/// derive_private_key - using only public keys to derive a public key instead of private keys. -/// -/// Note that this is infallible iff we trust that at least one of the two input keys are randomly -/// generated (ie our own). -#[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_PublicKeyErrorZ { - let mut ret = lightning::ln::chan_utils::derive_public_key(secp256k1::SECP256K1, &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) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() }; - local_ret -} - -/// Derives a per-commitment-transaction revocation key from its constituent parts. -/// -/// Only the cheating participant owns a valid witness to propagate a revoked -/// commitment transaction, thus per_commitment_secret always come from cheater -/// and revocation_base_secret always come from punisher, which is the broadcaster -/// of the transaction spending with this key knowledge. -/// -/// Note that this is infallible iff we trust that at least one of the two input keys are randomly -/// generated (ie our own). -#[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_SecretKeyErrorZ { - let mut ret = lightning::ln::chan_utils::derive_private_revocation_key(secp256k1::SECP256K1, &::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) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() }; - local_ret -} - -/// Derives a per-commitment-transaction revocation public key from its constituent parts. This is -/// the public equivalend of derive_private_revocation_key - using only public keys to derive a -/// public key instead of private keys. -/// -/// Only the cheating participant owns a valid witness to propagate a revoked -/// commitment transaction, thus per_commitment_point always come from cheater -/// and revocation_base_point always come from punisher, which is the broadcaster -/// of the transaction spending with this key knowledge. -/// -/// Note that this is infallible iff we trust that at least one of the two input keys are randomly -/// generated (ie our own). -#[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_PublicKeyErrorZ { - let mut ret = lightning::ln::chan_utils::derive_public_revocation_key(secp256k1::SECP256K1, &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) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() }; - local_ret -} - - -use lightning::ln::chan_utils::TxCreationKeys as nativeTxCreationKeysImport; -type nativeTxCreationKeys = nativeTxCreationKeysImport; - -/// The set of public keys which are used in the creation of one commitment transaction. -/// These are derived from the channel base keys and per-commitment data. -/// -/// A broadcaster key is provided from potential broadcaster of the computed transaction. -/// A countersignatory key is coming from a protocol participant unable to broadcast the -/// transaction. -/// -/// These keys are assumed to be good, either because the code derived them from -/// channel basepoints via the new function, or they were obtained via -/// CommitmentTransaction.trust().keys() because we trusted the source of the -/// pre-calculated keys. -#[must_use] -#[repr(C)] -pub struct TxCreationKeys { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeTxCreationKeys, - pub is_owned: bool, -} - -impl Drop for TxCreationKeys { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeTxCreationKeys>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn TxCreationKeys_free(this_ptr: TxCreationKeys) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn TxCreationKeys_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTxCreationKeys); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl TxCreationKeys { - pub(crate) fn take_inner(mut self) -> *mut nativeTxCreationKeys { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The broadcaster's per-commitment public key which was used to derive the other keys. -#[no_mangle] -pub extern "C" fn TxCreationKeys_get_per_commitment_point(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.per_commitment_point; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The broadcaster's per-commitment public key which was used to derive the other keys. -#[no_mangle] -pub extern "C" fn TxCreationKeys_set_per_commitment_point(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.per_commitment_point = val.into_rust(); -} -/// The revocation key which is used to allow the broadcaster of the commitment -/// transaction to provide their counterparty the ability to punish them if they broadcast -/// an old state. -#[no_mangle] -pub extern "C" fn TxCreationKeys_get_revocation_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_key; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The revocation key which is used to allow the broadcaster of the commitment -/// transaction to provide their counterparty the ability to punish them if they broadcast -/// an old state. -#[no_mangle] -pub extern "C" fn TxCreationKeys_set_revocation_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.revocation_key = val.into_rust(); -} -/// Broadcaster's HTLC Key -#[no_mangle] -pub extern "C" fn TxCreationKeys_get_broadcaster_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.broadcaster_htlc_key; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// Broadcaster's HTLC Key -#[no_mangle] -pub extern "C" fn TxCreationKeys_set_broadcaster_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.broadcaster_htlc_key = val.into_rust(); -} -/// Countersignatory's HTLC Key -#[no_mangle] -pub extern "C" fn TxCreationKeys_get_countersignatory_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.countersignatory_htlc_key; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// Countersignatory's HTLC Key -#[no_mangle] -pub extern "C" fn TxCreationKeys_set_countersignatory_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.countersignatory_htlc_key = val.into_rust(); -} -/// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay) -#[no_mangle] -pub extern "C" fn TxCreationKeys_get_broadcaster_delayed_payment_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.broadcaster_delayed_payment_key; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay) -#[no_mangle] -pub extern "C" fn TxCreationKeys_set_broadcaster_delayed_payment_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.broadcaster_delayed_payment_key = val.into_rust(); -} -#[must_use] -#[no_mangle] -pub extern "C" fn TxCreationKeys_new(mut per_commitment_point_arg: crate::c_types::PublicKey, mut revocation_key_arg: crate::c_types::PublicKey, mut broadcaster_htlc_key_arg: crate::c_types::PublicKey, mut countersignatory_htlc_key_arg: crate::c_types::PublicKey, mut broadcaster_delayed_payment_key_arg: crate::c_types::PublicKey) -> TxCreationKeys { - TxCreationKeys { inner: Box::into_raw(Box::new(nativeTxCreationKeys { - per_commitment_point: per_commitment_point_arg.into_rust(), - revocation_key: revocation_key_arg.into_rust(), - broadcaster_htlc_key: broadcaster_htlc_key_arg.into_rust(), - countersignatory_htlc_key: countersignatory_htlc_key_arg.into_rust(), - broadcaster_delayed_payment_key: broadcaster_delayed_payment_key_arg.into_rust(), - })), is_owned: true } -} -impl Clone for TxCreationKeys { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeTxCreationKeys>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn TxCreationKeys_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxCreationKeys)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn TxCreationKeys_clone(orig: &TxCreationKeys) -> TxCreationKeys { - orig.clone() -} -#[no_mangle] -pub extern "C" fn TxCreationKeys_write(obj: &TxCreationKeys) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn TxCreationKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxCreationKeys) }) -} -#[no_mangle] -pub extern "C" fn TxCreationKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_TxCreationKeysDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { 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::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() }; - local_res -} - -use lightning::ln::chan_utils::ChannelPublicKeys as nativeChannelPublicKeysImport; -type nativeChannelPublicKeys = nativeChannelPublicKeysImport; - -/// One counterparty's public keys which do not change over the life of a channel. -#[must_use] -#[repr(C)] -pub struct ChannelPublicKeys { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelPublicKeys, - pub is_owned: bool, -} - -impl Drop for ChannelPublicKeys { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelPublicKeys>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_free(this_ptr: ChannelPublicKeys) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelPublicKeys_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelPublicKeys); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelPublicKeys { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelPublicKeys { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// 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. -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_get_funding_pubkey(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_pubkey; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// 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. -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_set_funding_pubkey(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.funding_pubkey = val.into_rust(); -} -/// The base point which is used (with derive_public_revocation_key) to derive per-commitment -/// revocation keys. This is combined with the per-commitment-secret generated by the -/// counterparty to create a secret which the counterparty can reveal to revoke previous -/// states. -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_get_revocation_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_basepoint; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The base point which is used (with derive_public_revocation_key) to derive per-commitment -/// revocation keys. This is combined with the per-commitment-secret generated by the -/// counterparty to create a secret which the counterparty can reveal to revoke previous -/// states. -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_set_revocation_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.revocation_basepoint = val.into_rust(); -} -/// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately -/// spendable primary channel balance on the broadcaster's commitment transaction. This key is -/// static across every commitment transaction. -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_get_payment_point(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_point; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately -/// spendable primary channel balance on the broadcaster's commitment transaction. This key is -/// static across every commitment transaction. -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_set_payment_point(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.payment_point = val.into_rust(); -} -/// The base point which is used (with derive_public_key) to derive a per-commitment payment -/// public key which receives non-HTLC-encumbered funds which are only available for spending -/// after some delay (or can be claimed via the revocation path). -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_get_delayed_payment_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The base point which is used (with derive_public_key) to derive a per-commitment payment -/// public key which receives non-HTLC-encumbered funds which are only available for spending -/// after some delay (or can be claimed via the revocation path). -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_set_delayed_payment_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint = val.into_rust(); -} -/// The base point which is used (with derive_public_key) to derive a per-commitment public key -/// which is used to encumber HTLC-in-flight outputs. -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_get_htlc_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_basepoint; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The base point which is used (with derive_public_key) to derive a per-commitment public key -/// which is used to encumber HTLC-in-flight outputs. -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_set_htlc_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.htlc_basepoint = val.into_rust(); -} -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_new(mut funding_pubkey_arg: crate::c_types::PublicKey, mut revocation_basepoint_arg: crate::c_types::PublicKey, mut payment_point_arg: crate::c_types::PublicKey, mut delayed_payment_basepoint_arg: crate::c_types::PublicKey, mut htlc_basepoint_arg: crate::c_types::PublicKey) -> ChannelPublicKeys { - ChannelPublicKeys { inner: Box::into_raw(Box::new(nativeChannelPublicKeys { - funding_pubkey: funding_pubkey_arg.into_rust(), - revocation_basepoint: revocation_basepoint_arg.into_rust(), - payment_point: payment_point_arg.into_rust(), - delayed_payment_basepoint: delayed_payment_basepoint_arg.into_rust(), - htlc_basepoint: htlc_basepoint_arg.into_rust(), - })), is_owned: true } -} -impl Clone for ChannelPublicKeys { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeChannelPublicKeys>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelPublicKeys_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelPublicKeys)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_clone(orig: &ChannelPublicKeys) -> ChannelPublicKeys { - orig.clone() -} -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_write(obj: &ChannelPublicKeys) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ChannelPublicKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelPublicKeys) }) -} -#[no_mangle] -pub extern "C" fn ChannelPublicKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelPublicKeysDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::ChannelPublicKeys { 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 -} -/// Create per-state keys from channel base points and the per-commitment point. -/// Key set is asymmetric and can't be used as part of counter-signatory set of transactions. -#[must_use] -#[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_TxCreationKeysErrorZ { - let mut ret = lightning::ln::chan_utils::TxCreationKeys::derive_new(secp256k1::SECP256K1, &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 } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() }; - local_ret -} - -/// Generate per-state keys from channel static keys. -/// Key set is asymmetric and can't be used as part of counter-signatory set of transactions. -#[must_use] -#[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_TxCreationKeysErrorZ { - 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 }, secp256k1::SECP256K1); - 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 -} - - -#[no_mangle] -pub static REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH: usize = lightning::ln::chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH; -/// A script either spendable by the revocation -/// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain. -/// Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions. -#[no_mangle] -pub extern "C" fn get_revokeable_redeemscript(mut revocation_key: crate::c_types::PublicKey, mut contest_delay: u16, mut broadcaster_delayed_payment_key: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z { - let mut ret = lightning::ln::chan_utils::get_revokeable_redeemscript(&revocation_key.into_rust(), contest_delay, &broadcaster_delayed_payment_key.into_rust()); - ret.into_bytes().into() -} - - -use lightning::ln::chan_utils::HTLCOutputInCommitment as nativeHTLCOutputInCommitmentImport; -type nativeHTLCOutputInCommitment = nativeHTLCOutputInCommitmentImport; - -/// Information about an HTLC as it appears in a commitment transaction -#[must_use] -#[repr(C)] -pub struct HTLCOutputInCommitment { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeHTLCOutputInCommitment, - pub is_owned: bool, -} - -impl Drop for HTLCOutputInCommitment { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeHTLCOutputInCommitment>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn HTLCOutputInCommitment_free(this_ptr: HTLCOutputInCommitment) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn HTLCOutputInCommitment_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCOutputInCommitment); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl HTLCOutputInCommitment { - pub(crate) fn take_inner(mut self) -> *mut nativeHTLCOutputInCommitment { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// 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 -/// need to compare this value to whether the commitment transaction in question is that of -/// the counterparty or our own. -#[no_mangle] -pub extern "C" fn HTLCOutputInCommitment_get_offered(this_ptr: &HTLCOutputInCommitment) -> bool { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.offered; - (*inner_val) -} -/// 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 -/// need to compare this value to whether the commitment transaction in question is that of -/// the counterparty or our own. -#[no_mangle] -pub extern "C" fn HTLCOutputInCommitment_set_offered(this_ptr: &mut HTLCOutputInCommitment, mut val: bool) { - unsafe { &mut *this_ptr.inner }.offered = val; -} -/// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is -/// this divided by 1000. -#[no_mangle] -pub extern "C" fn HTLCOutputInCommitment_get_amount_msat(this_ptr: &HTLCOutputInCommitment) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.amount_msat; - (*inner_val) -} -/// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is -/// this divided by 1000. -#[no_mangle] -pub extern "C" fn HTLCOutputInCommitment_set_amount_msat(this_ptr: &mut HTLCOutputInCommitment, mut val: u64) { - unsafe { &mut *this_ptr.inner }.amount_msat = val; -} -/// The CLTV lock-time at which this HTLC expires. -#[no_mangle] -pub extern "C" fn HTLCOutputInCommitment_get_cltv_expiry(this_ptr: &HTLCOutputInCommitment) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry; - (*inner_val) -} -/// The CLTV lock-time at which this HTLC expires. -#[no_mangle] -pub extern "C" fn HTLCOutputInCommitment_set_cltv_expiry(this_ptr: &mut HTLCOutputInCommitment, mut val: u32) { - unsafe { &mut *this_ptr.inner }.cltv_expiry = val; -} -/// The hash of the preimage which unlocks this HTLC. -#[no_mangle] -pub extern "C" fn HTLCOutputInCommitment_get_payment_hash(this_ptr: &HTLCOutputInCommitment) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_hash; - &(*inner_val).0 -} -/// The hash of the preimage which unlocks this HTLC. -#[no_mangle] -pub extern "C" fn HTLCOutputInCommitment_set_payment_hash(this_ptr: &mut HTLCOutputInCommitment, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.payment_hash = ::lightning::ln::channelmanager::PaymentHash(val.data); -} -impl Clone for HTLCOutputInCommitment { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeHTLCOutputInCommitment>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn HTLCOutputInCommitment_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCOutputInCommitment)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn HTLCOutputInCommitment_clone(orig: &HTLCOutputInCommitment) -> HTLCOutputInCommitment { - orig.clone() -} -#[no_mangle] -pub extern "C" fn HTLCOutputInCommitment_write(obj: &HTLCOutputInCommitment) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn HTLCOutputInCommitment_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCOutputInCommitment) }) -} -#[no_mangle] -pub extern "C" fn HTLCOutputInCommitment_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCOutputInCommitmentDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::HTLCOutputInCommitment { 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 -} -/// Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc -/// does not need to have its previous_output_index filled. -#[no_mangle] -pub extern "C" fn get_htlc_redeemscript(htlc: &crate::ln::chan_utils::HTLCOutputInCommitment, keys: &crate::ln::chan_utils::TxCreationKeys) -> crate::c_types::derived::CVec_u8Z { - let mut ret = lightning::ln::chan_utils::get_htlc_redeemscript(unsafe { &*htlc.inner }, unsafe { &*keys.inner }); - ret.into_bytes().into() -} - -/// Gets the redeemscript for a funding output from the two funding public keys. -/// Note that the order of funding public keys does not matter. -#[no_mangle] -pub extern "C" fn make_funding_redeemscript(mut broadcaster: crate::c_types::PublicKey, mut countersignatory: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z { - let mut ret = lightning::ln::chan_utils::make_funding_redeemscript(&broadcaster.into_rust(), &countersignatory.into_rust()); - ret.into_bytes().into() -} - -/// panics if htlc.transaction_output_index.is_none()! -#[no_mangle] -pub extern "C" fn build_htlc_transaction(prev_hash: *const [u8; 32], mut feerate_per_kw: u32, mut contest_delay: u16, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment, mut broadcaster_delayed_payment_key: crate::c_types::PublicKey, mut revocation_key: crate::c_types::PublicKey) -> crate::c_types::Transaction { - let mut ret = lightning::ln::chan_utils::build_htlc_transaction(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*prev_hash }[..]).unwrap(), feerate_per_kw, contest_delay, unsafe { &*htlc.inner }, &broadcaster_delayed_payment_key.into_rust(), &revocation_key.into_rust()); - let mut local_ret = ::bitcoin::consensus::encode::serialize(&ret); - crate::c_types::Transaction::from_vec(local_ret) -} - - -use lightning::ln::chan_utils::ChannelTransactionParameters as nativeChannelTransactionParametersImport; -type nativeChannelTransactionParameters = nativeChannelTransactionParametersImport; - -/// Per-channel data used to build transactions in conjunction with the per-commitment data (CommitmentTransaction). -/// The fields are organized by holder/counterparty. -/// -/// Normally, this is converted to the broadcaster/countersignatory-organized DirectedChannelTransactionParameters -/// before use, via the as_holder_broadcastable and as_counterparty_broadcastable functions. -#[must_use] -#[repr(C)] -pub struct ChannelTransactionParameters { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelTransactionParameters, - pub is_owned: bool, -} - -impl Drop for ChannelTransactionParameters { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelTransactionParameters>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_free(this_ptr: ChannelTransactionParameters) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelTransactionParameters_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelTransactionParameters); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelTransactionParameters { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelTransactionParameters { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Holder public keys -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_get_holder_pubkeys(this_ptr: &ChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.holder_pubkeys; - crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// Holder public keys -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_set_holder_pubkeys(this_ptr: &mut ChannelTransactionParameters, mut val: crate::ln::chan_utils::ChannelPublicKeys) { - unsafe { &mut *this_ptr.inner }.holder_pubkeys = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// The contest delay selected by the holder, which applies to counterparty-broadcast transactions -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_get_holder_selected_contest_delay(this_ptr: &ChannelTransactionParameters) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.holder_selected_contest_delay; - (*inner_val) -} -/// The contest delay selected by the holder, which applies to counterparty-broadcast transactions -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_set_holder_selected_contest_delay(this_ptr: &mut ChannelTransactionParameters, mut val: u16) { - unsafe { &mut *this_ptr.inner }.holder_selected_contest_delay = val; -} -/// Whether the holder is the initiator of this channel. -/// This is an input to the commitment number obscure factor computation. -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_get_is_outbound_from_holder(this_ptr: &ChannelTransactionParameters) -> bool { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.is_outbound_from_holder; - (*inner_val) -} -/// Whether the holder is the initiator of this channel. -/// This is an input to the commitment number obscure factor computation. -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_set_is_outbound_from_holder(this_ptr: &mut ChannelTransactionParameters, mut val: bool) { - unsafe { &mut *this_ptr.inner }.is_outbound_from_holder = val; -} -/// The late-bound counterparty channel transaction parameters. -/// These parameters are populated at the point in the protocol where the counterparty provides them. -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_get_counterparty_parameters(this_ptr: &ChannelTransactionParameters) -> crate::ln::chan_utils::CounterpartyChannelTransactionParameters { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_parameters; - let mut local_inner_val = crate::ln::chan_utils::CounterpartyChannelTransactionParameters { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; - local_inner_val -} -/// The late-bound counterparty channel transaction parameters. -/// These parameters are populated at the point in the protocol where the counterparty provides them. -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_set_counterparty_parameters(this_ptr: &mut ChannelTransactionParameters, mut val: crate::ln::chan_utils::CounterpartyChannelTransactionParameters) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *this_ptr.inner }.counterparty_parameters = local_val; -} -/// The late-bound funding outpoint -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_get_funding_outpoint(this_ptr: &ChannelTransactionParameters) -> crate::chain::transaction::OutPoint { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_outpoint; - let mut local_inner_val = crate::chain::transaction::OutPoint { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; - local_inner_val -} -/// The late-bound funding outpoint -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_set_funding_outpoint(this_ptr: &mut ChannelTransactionParameters, mut val: crate::chain::transaction::OutPoint) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *this_ptr.inner }.funding_outpoint = local_val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_new(mut holder_pubkeys_arg: crate::ln::chan_utils::ChannelPublicKeys, mut holder_selected_contest_delay_arg: u16, mut is_outbound_from_holder_arg: bool, mut counterparty_parameters_arg: crate::ln::chan_utils::CounterpartyChannelTransactionParameters, mut funding_outpoint_arg: crate::chain::transaction::OutPoint) -> ChannelTransactionParameters { - let mut local_counterparty_parameters_arg = if counterparty_parameters_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(counterparty_parameters_arg.take_inner()) } }) }; - let mut local_funding_outpoint_arg = if funding_outpoint_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(funding_outpoint_arg.take_inner()) } }) }; - ChannelTransactionParameters { inner: Box::into_raw(Box::new(nativeChannelTransactionParameters { - holder_pubkeys: *unsafe { Box::from_raw(holder_pubkeys_arg.take_inner()) }, - holder_selected_contest_delay: holder_selected_contest_delay_arg, - is_outbound_from_holder: is_outbound_from_holder_arg, - counterparty_parameters: local_counterparty_parameters_arg, - funding_outpoint: local_funding_outpoint_arg, - })), is_owned: true } -} -impl Clone for ChannelTransactionParameters { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeChannelTransactionParameters>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelTransactionParameters)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_clone(orig: &ChannelTransactionParameters) -> ChannelTransactionParameters { - orig.clone() -} - -use lightning::ln::chan_utils::CounterpartyChannelTransactionParameters as nativeCounterpartyChannelTransactionParametersImport; -type nativeCounterpartyChannelTransactionParameters = nativeCounterpartyChannelTransactionParametersImport; - -/// Late-bound per-channel counterparty data used to build transactions. -#[must_use] -#[repr(C)] -pub struct CounterpartyChannelTransactionParameters { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeCounterpartyChannelTransactionParameters, - pub is_owned: bool, -} - -impl Drop for CounterpartyChannelTransactionParameters { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeCounterpartyChannelTransactionParameters>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn CounterpartyChannelTransactionParameters_free(this_ptr: CounterpartyChannelTransactionParameters) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn CounterpartyChannelTransactionParameters_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyChannelTransactionParameters); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl CounterpartyChannelTransactionParameters { - pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyChannelTransactionParameters { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Counter-party public keys -#[no_mangle] -pub extern "C" fn CounterpartyChannelTransactionParameters_get_pubkeys(this_ptr: &CounterpartyChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.pubkeys; - crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// Counter-party public keys -#[no_mangle] -pub extern "C" fn CounterpartyChannelTransactionParameters_set_pubkeys(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: crate::ln::chan_utils::ChannelPublicKeys) { - unsafe { &mut *this_ptr.inner }.pubkeys = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// The contest delay selected by the counterparty, which applies to holder-broadcast transactions -#[no_mangle] -pub extern "C" fn CounterpartyChannelTransactionParameters_get_selected_contest_delay(this_ptr: &CounterpartyChannelTransactionParameters) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.selected_contest_delay; - (*inner_val) -} -/// The contest delay selected by the counterparty, which applies to holder-broadcast transactions -#[no_mangle] -pub extern "C" fn CounterpartyChannelTransactionParameters_set_selected_contest_delay(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: u16) { - unsafe { &mut *this_ptr.inner }.selected_contest_delay = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn CounterpartyChannelTransactionParameters_new(mut pubkeys_arg: crate::ln::chan_utils::ChannelPublicKeys, mut selected_contest_delay_arg: u16) -> CounterpartyChannelTransactionParameters { - CounterpartyChannelTransactionParameters { inner: Box::into_raw(Box::new(nativeCounterpartyChannelTransactionParameters { - pubkeys: *unsafe { Box::from_raw(pubkeys_arg.take_inner()) }, - selected_contest_delay: selected_contest_delay_arg, - })), is_owned: true } -} -impl Clone for CounterpartyChannelTransactionParameters { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeCounterpartyChannelTransactionParameters>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyChannelTransactionParameters)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn CounterpartyChannelTransactionParameters_clone(orig: &CounterpartyChannelTransactionParameters) -> CounterpartyChannelTransactionParameters { - orig.clone() -} -/// Whether the late bound parameters are populated. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_is_populated(this_arg: &ChannelTransactionParameters) -> bool { - let mut ret = unsafe { &*this_arg.inner }.is_populated(); - ret -} - -/// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters, -/// given that the holder is the broadcaster. -/// -/// self.is_populated() must be true before calling this function. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_as_holder_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::ln::chan_utils::DirectedChannelTransactionParameters { - let mut ret = unsafe { &*this_arg.inner }.as_holder_broadcastable(); - crate::ln::chan_utils::DirectedChannelTransactionParameters { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters, -/// given that the counterparty is the broadcaster. -/// -/// self.is_populated() must be true before calling this function. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_as_counterparty_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::ln::chan_utils::DirectedChannelTransactionParameters { - let mut ret = unsafe { &*this_arg.inner }.as_counterparty_broadcastable(); - crate::ln::chan_utils::DirectedChannelTransactionParameters { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -#[no_mangle] -pub extern "C" fn CounterpartyChannelTransactionParameters_write(obj: &CounterpartyChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyChannelTransactionParameters) }) -} -#[no_mangle] -pub extern "C" fn CounterpartyChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CounterpartyChannelTransactionParametersDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::CounterpartyChannelTransactionParameters { 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 -} -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_write(obj: &ChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelTransactionParameters) }) -} -#[no_mangle] -pub extern "C" fn ChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelTransactionParametersDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::ChannelTransactionParameters { 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 -} - -use lightning::ln::chan_utils::DirectedChannelTransactionParameters as nativeDirectedChannelTransactionParametersImport; -type nativeDirectedChannelTransactionParameters = nativeDirectedChannelTransactionParametersImport<'static>; - -/// Static channel fields used to build transactions given per-commitment fields, organized by -/// broadcaster/countersignatory. -/// -/// This is derived from the holder/counterparty-organized ChannelTransactionParameters via the -/// as_holder_broadcastable and as_counterparty_broadcastable functions. -#[must_use] -#[repr(C)] -pub struct DirectedChannelTransactionParameters { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeDirectedChannelTransactionParameters, - pub is_owned: bool, -} - -impl Drop for DirectedChannelTransactionParameters { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeDirectedChannelTransactionParameters>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn DirectedChannelTransactionParameters_free(this_ptr: DirectedChannelTransactionParameters) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn DirectedChannelTransactionParameters_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectedChannelTransactionParameters); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl DirectedChannelTransactionParameters { - pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelTransactionParameters { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Get the channel pubkeys for the broadcaster -#[must_use] -#[no_mangle] -pub extern "C" fn DirectedChannelTransactionParameters_broadcaster_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys { - let mut ret = unsafe { &*this_arg.inner }.broadcaster_pubkeys(); - crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } -} - -/// Get the channel pubkeys for the countersignatory -#[must_use] -#[no_mangle] -pub extern "C" fn DirectedChannelTransactionParameters_countersignatory_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys { - let mut ret = unsafe { &*this_arg.inner }.countersignatory_pubkeys(); - crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } -} - -/// Get the contest delay applicable to the transactions. -/// Note that the contest delay was selected by the countersignatory. -#[must_use] -#[no_mangle] -pub extern "C" fn DirectedChannelTransactionParameters_contest_delay(this_arg: &DirectedChannelTransactionParameters) -> u16 { - let mut ret = unsafe { &*this_arg.inner }.contest_delay(); - ret -} - -/// Whether the channel is outbound from the broadcaster. -/// -/// The boolean representing the side that initiated the channel is -/// an input to the commitment number obscure factor computation. -#[must_use] -#[no_mangle] -pub extern "C" fn DirectedChannelTransactionParameters_is_outbound(this_arg: &DirectedChannelTransactionParameters) -> bool { - let mut ret = unsafe { &*this_arg.inner }.is_outbound(); - ret -} - -/// The funding outpoint -#[must_use] -#[no_mangle] -pub extern "C" fn DirectedChannelTransactionParameters_funding_outpoint(this_arg: &DirectedChannelTransactionParameters) -> crate::chain::transaction::OutPoint { - let mut ret = unsafe { &*this_arg.inner }.funding_outpoint(); - crate::c_types::bitcoin_to_C_outpoint(ret) -} - - -use lightning::ln::chan_utils::HolderCommitmentTransaction as nativeHolderCommitmentTransactionImport; -type nativeHolderCommitmentTransaction = nativeHolderCommitmentTransactionImport; - -/// Information needed to build and sign a holder's commitment transaction. -/// -/// The transaction is only signed once we are ready to broadcast. -#[must_use] -#[repr(C)] -pub struct HolderCommitmentTransaction { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeHolderCommitmentTransaction, - pub is_owned: bool, -} - -impl Drop for HolderCommitmentTransaction { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeHolderCommitmentTransaction>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_free(this_ptr: HolderCommitmentTransaction) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn HolderCommitmentTransaction_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHolderCommitmentTransaction); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl HolderCommitmentTransaction { - pub(crate) fn take_inner(mut self) -> *mut nativeHolderCommitmentTransaction { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Our counterparty's signature for the transaction -#[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_get_counterparty_sig(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_sig; - crate::c_types::Signature::from_rust(&(*inner_val)) -} -/// Our counterparty's signature for the transaction -#[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_set_counterparty_sig(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.counterparty_sig = val.into_rust(); -} -/// All non-dust counterparty HTLC signatures, in the order they appear in the transaction -#[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_set_counterparty_htlc_sigs(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::derived::CVec_SignatureZ) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_rust() }); }; - unsafe { &mut *this_ptr.inner }.counterparty_htlc_sigs = local_val; -} -impl Clone for HolderCommitmentTransaction { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeHolderCommitmentTransaction>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn HolderCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHolderCommitmentTransaction)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_clone(orig: &HolderCommitmentTransaction) -> HolderCommitmentTransaction { - orig.clone() -} -#[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_write(obj: &HolderCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn HolderCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHolderCommitmentTransaction) }) -} -#[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HolderCommitmentTransactionDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::HolderCommitmentTransaction { 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 -} -/// Create a new holder transaction with the given counterparty signatures. -/// The funding keys are used to figure out which signature should go first when building the transaction for broadcast. -#[must_use] -#[no_mangle] -pub extern "C" fn HolderCommitmentTransaction_new(mut commitment_tx: crate::ln::chan_utils::CommitmentTransaction, mut counterparty_sig: crate::c_types::Signature, mut counterparty_htlc_sigs: crate::c_types::derived::CVec_SignatureZ, mut holder_funding_key: crate::c_types::PublicKey, mut counterparty_funding_key: crate::c_types::PublicKey) -> HolderCommitmentTransaction { - let mut local_counterparty_htlc_sigs = Vec::new(); for mut item in counterparty_htlc_sigs.into_rust().drain(..) { local_counterparty_htlc_sigs.push( { item.into_rust() }); }; - let mut ret = lightning::ln::chan_utils::HolderCommitmentTransaction::new(*unsafe { Box::from_raw(commitment_tx.take_inner()) }, counterparty_sig.into_rust(), local_counterparty_htlc_sigs, &holder_funding_key.into_rust(), &counterparty_funding_key.into_rust()); - HolderCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - - -use lightning::ln::chan_utils::BuiltCommitmentTransaction as nativeBuiltCommitmentTransactionImport; -type nativeBuiltCommitmentTransaction = nativeBuiltCommitmentTransactionImport; - -/// A pre-built Bitcoin commitment transaction and its txid. -#[must_use] -#[repr(C)] -pub struct BuiltCommitmentTransaction { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeBuiltCommitmentTransaction, - pub is_owned: bool, -} - -impl Drop for BuiltCommitmentTransaction { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeBuiltCommitmentTransaction>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn BuiltCommitmentTransaction_free(this_ptr: BuiltCommitmentTransaction) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn BuiltCommitmentTransaction_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeBuiltCommitmentTransaction); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl BuiltCommitmentTransaction { - pub(crate) fn take_inner(mut self) -> *mut nativeBuiltCommitmentTransaction { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The commitment transaction -#[no_mangle] -pub extern "C" fn BuiltCommitmentTransaction_get_transaction(this_ptr: &BuiltCommitmentTransaction) -> crate::c_types::Transaction { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.transaction; - let mut local_inner_val = ::bitcoin::consensus::encode::serialize(inner_val); - crate::c_types::Transaction::from_vec(local_inner_val) -} -/// The commitment transaction -#[no_mangle] -pub extern "C" fn BuiltCommitmentTransaction_set_transaction(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::Transaction) { - unsafe { &mut *this_ptr.inner }.transaction = val.into_bitcoin(); -} -/// The txid for the commitment transaction. -/// -/// This is provided as a performance optimization, instead of calling transaction.txid() -/// multiple times. -#[no_mangle] -pub extern "C" fn BuiltCommitmentTransaction_get_txid(this_ptr: &BuiltCommitmentTransaction) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.txid; - (*inner_val).as_inner() -} -/// The txid for the commitment transaction. -/// -/// This is provided as a performance optimization, instead of calling transaction.txid() -/// multiple times. -#[no_mangle] -pub extern "C" fn BuiltCommitmentTransaction_set_txid(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap(); -} -#[must_use] -#[no_mangle] -pub extern "C" fn BuiltCommitmentTransaction_new(mut transaction_arg: crate::c_types::Transaction, mut txid_arg: crate::c_types::ThirtyTwoBytes) -> BuiltCommitmentTransaction { - BuiltCommitmentTransaction { inner: Box::into_raw(Box::new(nativeBuiltCommitmentTransaction { - transaction: transaction_arg.into_bitcoin(), - txid: ::bitcoin::hash_types::Txid::from_slice(&txid_arg.data[..]).unwrap(), - })), is_owned: true } -} -impl Clone for BuiltCommitmentTransaction { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeBuiltCommitmentTransaction>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn BuiltCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBuiltCommitmentTransaction)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn BuiltCommitmentTransaction_clone(orig: &BuiltCommitmentTransaction) -> BuiltCommitmentTransaction { - orig.clone() -} -#[no_mangle] -pub extern "C" fn BuiltCommitmentTransaction_write(obj: &BuiltCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn BuiltCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBuiltCommitmentTransaction) }) -} -#[no_mangle] -pub extern "C" fn BuiltCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BuiltCommitmentTransactionDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::BuiltCommitmentTransaction { 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 -} -/// Get the SIGHASH_ALL sighash value of the transaction. -/// -/// This can be used to verify a signature. -#[must_use] -#[no_mangle] -pub extern "C" fn BuiltCommitmentTransaction_get_sighash_all(this_arg: &BuiltCommitmentTransaction, mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::ThirtyTwoBytes { - let mut ret = unsafe { &*this_arg.inner }.get_sighash_all(&::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis); - crate::c_types::ThirtyTwoBytes { data: ret.as_ref().clone() } -} - -/// Sign a transaction, either because we are counter-signing the counterparty's transaction or -/// because we are about to broadcast a holder transaction. -#[must_use] -#[no_mangle] -pub extern "C" fn BuiltCommitmentTransaction_sign(this_arg: &BuiltCommitmentTransaction, funding_key: *const [u8; 32], mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::Signature { - let mut ret = unsafe { &*this_arg.inner }.sign(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *funding_key}[..]).unwrap(), &::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis, secp256k1::SECP256K1); - crate::c_types::Signature::from_rust(&ret) -} - - -use lightning::ln::chan_utils::CommitmentTransaction as nativeCommitmentTransactionImport; -type nativeCommitmentTransaction = nativeCommitmentTransactionImport; - -/// This class tracks the per-transaction information needed to build a commitment transaction and to -/// actually build it and sign. It is used for holder transactions that we sign only when needed -/// and for transactions we sign for the counterparty. -/// -/// This class can be used inside a signer implementation to generate a signature given the relevant -/// secret key. -#[must_use] -#[repr(C)] -pub struct CommitmentTransaction { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeCommitmentTransaction, - pub is_owned: bool, -} - -impl Drop for CommitmentTransaction { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeCommitmentTransaction>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn CommitmentTransaction_free(this_ptr: CommitmentTransaction) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn CommitmentTransaction_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCommitmentTransaction); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl CommitmentTransaction { - pub(crate) fn take_inner(mut self) -> *mut nativeCommitmentTransaction { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -impl Clone for CommitmentTransaction { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeCommitmentTransaction>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn CommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentTransaction)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn CommitmentTransaction_clone(orig: &CommitmentTransaction) -> CommitmentTransaction { - orig.clone() -} -#[no_mangle] -pub extern "C" fn CommitmentTransaction_write(obj: &CommitmentTransaction) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn CommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentTransaction) }) -} -#[no_mangle] -pub extern "C" fn CommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CommitmentTransactionDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::CommitmentTransaction { 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 -} -/// The backwards-counting commitment number -#[must_use] -#[no_mangle] -pub extern "C" fn CommitmentTransaction_commitment_number(this_arg: &CommitmentTransaction) -> u64 { - let mut ret = unsafe { &*this_arg.inner }.commitment_number(); - ret -} - -/// The value to be sent to the broadcaster -#[must_use] -#[no_mangle] -pub extern "C" fn CommitmentTransaction_to_broadcaster_value_sat(this_arg: &CommitmentTransaction) -> u64 { - let mut ret = unsafe { &*this_arg.inner }.to_broadcaster_value_sat(); - ret -} - -/// The value to be sent to the counterparty -#[must_use] -#[no_mangle] -pub extern "C" fn CommitmentTransaction_to_countersignatory_value_sat(this_arg: &CommitmentTransaction) -> u64 { - let mut ret = unsafe { &*this_arg.inner }.to_countersignatory_value_sat(); - ret -} - -/// The feerate paid per 1000-weight-unit in this commitment transaction. -#[must_use] -#[no_mangle] -pub extern "C" fn CommitmentTransaction_feerate_per_kw(this_arg: &CommitmentTransaction) -> u32 { - let mut ret = unsafe { &*this_arg.inner }.feerate_per_kw(); - ret -} - -/// Trust our pre-built transaction and derived transaction creation public keys. -/// -/// Applies a wrapper which allows access to these fields. -/// -/// This should only be used if you fully trust the builder of this object. It should not -///\tbe used by an external signer - instead use the verify function. -#[must_use] -#[no_mangle] -pub extern "C" fn CommitmentTransaction_trust(this_arg: &CommitmentTransaction) -> crate::ln::chan_utils::TrustedCommitmentTransaction { - let mut ret = unsafe { &*this_arg.inner }.trust(); - crate::ln::chan_utils::TrustedCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Verify our pre-built transaction and derived transaction creation public keys. -/// -/// Applies a wrapper which allows access to these fields. -/// -/// An external validating signer must call this method before signing -/// or using the built transaction. -#[must_use] -#[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 { - let mut ret = unsafe { &*this_arg.inner }.verify(unsafe { &*channel_parameters.inner }, unsafe { &*broadcaster_keys.inner }, unsafe { &*countersignatory_keys.inner }, secp256k1::SECP256K1); - 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 -} - - -use lightning::ln::chan_utils::TrustedCommitmentTransaction as nativeTrustedCommitmentTransactionImport; -type nativeTrustedCommitmentTransaction = nativeTrustedCommitmentTransactionImport<'static>; - -/// A wrapper on CommitmentTransaction indicating that the derived fields (the built bitcoin -/// transaction and the transaction creation keys) are trusted. -/// -/// See trust() and verify() functions on CommitmentTransaction. -/// -/// This structure implements Deref. -#[must_use] -#[repr(C)] -pub struct TrustedCommitmentTransaction { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeTrustedCommitmentTransaction, - pub is_owned: bool, -} - -impl Drop for TrustedCommitmentTransaction { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeTrustedCommitmentTransaction>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn TrustedCommitmentTransaction_free(this_ptr: TrustedCommitmentTransaction) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn TrustedCommitmentTransaction_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTrustedCommitmentTransaction); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl TrustedCommitmentTransaction { - pub(crate) fn take_inner(mut self) -> *mut nativeTrustedCommitmentTransaction { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The transaction ID of the built Bitcoin transaction -#[must_use] -#[no_mangle] -pub extern "C" fn TrustedCommitmentTransaction_txid(this_arg: &TrustedCommitmentTransaction) -> crate::c_types::ThirtyTwoBytes { - let mut ret = unsafe { &*this_arg.inner }.txid(); - crate::c_types::ThirtyTwoBytes { data: ret.into_inner() } -} - -/// The pre-built Bitcoin commitment transaction -#[must_use] -#[no_mangle] -pub extern "C" fn TrustedCommitmentTransaction_built_transaction(this_arg: &TrustedCommitmentTransaction) -> crate::ln::chan_utils::BuiltCommitmentTransaction { - let mut ret = unsafe { &*this_arg.inner }.built_transaction(); - crate::ln::chan_utils::BuiltCommitmentTransaction { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } -} - -/// The pre-calculated transaction creation public keys. -#[must_use] -#[no_mangle] -pub extern "C" fn TrustedCommitmentTransaction_keys(this_arg: &TrustedCommitmentTransaction) -> crate::ln::chan_utils::TxCreationKeys { - let mut ret = unsafe { &*this_arg.inner }.keys(); - crate::ln::chan_utils::TxCreationKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } -} - -/// Get a signature for each HTLC which was included in the commitment transaction (ie for -/// which HTLCOutputInCommitment::transaction_output_index.is_some()). -/// -/// The returned Vec has one entry for each HTLC, and in the same order. -#[must_use] -#[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 { - 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 }, secp256k1::SECP256K1); - let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for mut 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 -} - -/// Get the transaction number obscure factor -#[no_mangle] -pub extern "C" fn get_commitment_transaction_number_obscure_factor(mut broadcaster_payment_basepoint: crate::c_types::PublicKey, mut countersignatory_payment_basepoint: crate::c_types::PublicKey, mut outbound_from_broadcaster: bool) -> u64 { - let mut ret = lightning::ln::chan_utils::get_commitment_transaction_number_obscure_factor(&broadcaster_payment_basepoint.into_rust(), &countersignatory_payment_basepoint.into_rust(), outbound_from_broadcaster); - ret -} - diff --git a/lightning-c-bindings/src/ln/channelmanager.rs b/lightning-c-bindings/src/ln/channelmanager.rs deleted file mode 100644 index 86257f77e..000000000 --- a/lightning-c-bindings/src/ln/channelmanager.rs +++ /dev/null @@ -1,1163 +0,0 @@ -//! The top-level channel management and payment tracking stuff lives here. -//! -//! The ChannelManager is the main chunk of logic implementing the lightning protocol and is -//! responsible for tracking which channels are open, HTLCs are in flight and reestablishing those -//! upon reconnect to the relevant peer(s). -//! -//! It does not manage routing logic (see routing::router::get_route for that) nor does it manage constructing -//! on-chain transactions (it only monitors the chain to watch for any force-closes that might -//! imply it needs to fail HTLCs/payments/channels it manages). -//! - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - - -use lightning::ln::channelmanager::ChannelManager as nativeChannelManagerImport; -type nativeChannelManager = nativeChannelManagerImport; - -/// Manager which keeps track of a number of channels and sends messages to the appropriate -/// channel, also tracking HTLC preimages and forwarding onion packets appropriately. -/// -/// Implements ChannelMessageHandler, handling the multi-channel parts and passing things through -/// to individual Channels. -/// -/// Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for -/// all peers during write/read (though does not modify this instance, only the instance being -/// serialized). This will result in any channels which have not yet exchanged funding_created (ie -/// called funding_transaction_generated for outbound channels). -/// -/// Note that you can be a bit lazier about writing out ChannelManager than you can be with -/// ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before -/// returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates -/// happens out-of-band (and will prevent any other ChannelManager operations from occurring during -/// the serialization process). If the deserialized version is out-of-date compared to the -/// ChannelMonitors passed by reference to read(), those channels will be force-closed based on the -/// ChannelMonitor state and no funds will be lost (mod on-chain transaction fees). -/// -/// Note that the deserializer is only implemented for (BlockHash, ChannelManager), which -/// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along -/// the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call -/// block_connected() to step towards your best block) upon deserialization before using the -/// object! -/// -/// Note that ChannelManager is responsible for tracking liveness of its channels and generating -/// ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid -/// spam due to quick disconnection/reconnection, updates are not sent until the channel has been -/// offline for a full minute. In order to track this, you must call -/// timer_chan_freshness_every_min roughly once per minute, though it doesn't have to be perfect. -/// -/// Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager -/// a SimpleRefChannelManager, for conciseness. See their documentation for more details, but -/// essentially you should default to using a SimpleRefChannelManager, and use a -/// SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when -/// you're using lightning-net-tokio. -#[must_use] -#[repr(C)] -pub struct ChannelManager { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelManager, - pub is_owned: bool, -} - -impl Drop for ChannelManager { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelManager>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelManager_free(this_ptr: ChannelManager) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelManager_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManager); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelManager { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelManager { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} - -use lightning::ln::channelmanager::ChainParameters as nativeChainParametersImport; -type nativeChainParameters = nativeChainParametersImport; - -/// Chain-related parameters used to construct a new `ChannelManager`. -/// -/// Typically, the block-specific parameters are derived from the best block hash for the network, -/// as a newly constructed `ChannelManager` will not have created any channels yet. These parameters -/// are not needed when deserializing a previously constructed `ChannelManager`. -#[must_use] -#[repr(C)] -pub struct ChainParameters { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChainParameters, - pub is_owned: bool, -} - -impl Drop for ChainParameters { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChainParameters>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChainParameters_free(this_ptr: ChainParameters) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChainParameters_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainParameters); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChainParameters { - pub(crate) fn take_inner(mut self) -> *mut nativeChainParameters { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The network for determining the `chain_hash` in Lightning messages. -#[no_mangle] -pub extern "C" fn ChainParameters_get_network(this_ptr: &ChainParameters) -> crate::bitcoin::network::Network { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.network; - crate::bitcoin::network::Network::from_bitcoin((*inner_val)) -} -/// The network for determining the `chain_hash` in Lightning messages. -#[no_mangle] -pub extern "C" fn ChainParameters_set_network(this_ptr: &mut ChainParameters, mut val: crate::bitcoin::network::Network) { - unsafe { &mut *this_ptr.inner }.network = val.into_bitcoin(); -} -/// The hash of the latest block successfully connected. -#[no_mangle] -pub extern "C" fn ChainParameters_get_latest_hash(this_ptr: &ChainParameters) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.latest_hash; - (*inner_val).as_inner() -} -/// The hash of the latest block successfully connected. -#[no_mangle] -pub extern "C" fn ChainParameters_set_latest_hash(this_ptr: &mut ChainParameters, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.latest_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); -} -/// The height of the latest block successfully connected. -/// -/// Used to track on-chain channel funding outputs and send payments with reliable timelocks. -#[no_mangle] -pub extern "C" fn ChainParameters_get_latest_height(this_ptr: &ChainParameters) -> usize { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.latest_height; - (*inner_val) -} -/// The height of the latest block successfully connected. -/// -/// Used to track on-chain channel funding outputs and send payments with reliable timelocks. -#[no_mangle] -pub extern "C" fn ChainParameters_set_latest_height(this_ptr: &mut ChainParameters, mut val: usize) { - unsafe { &mut *this_ptr.inner }.latest_height = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network::Network, mut latest_hash_arg: crate::c_types::ThirtyTwoBytes, mut latest_height_arg: usize) -> ChainParameters { - ChainParameters { inner: Box::into_raw(Box::new(nativeChainParameters { - network: network_arg.into_bitcoin(), - latest_hash: ::bitcoin::hash_types::BlockHash::from_slice(&latest_hash_arg.data[..]).unwrap(), - latest_height: latest_height_arg, - })), is_owned: true } -} - -use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport; -type nativeChannelDetails = nativeChannelDetailsImport; - -/// Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels -#[must_use] -#[repr(C)] -pub struct ChannelDetails { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelDetails, - pub is_owned: bool, -} - -impl Drop for ChannelDetails { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelDetails>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelDetails_free(this_ptr: ChannelDetails) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelDetails_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelDetails); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelDetails { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelDetails { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// 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). -/// Note that this means this value is *not* persistent - it can change once during the -/// lifetime of the channel. -#[no_mangle] -pub extern "C" fn ChannelDetails_get_channel_id(this_ptr: &ChannelDetails) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// 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). -/// Note that this means this value is *not* persistent - it can change once during the -/// lifetime of the channel. -#[no_mangle] -pub extern "C" fn ChannelDetails_set_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// The node_id of our counterparty -#[no_mangle] -pub extern "C" fn ChannelDetails_get_remote_network_id(this_ptr: &ChannelDetails) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.remote_network_id; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The node_id of our counterparty -#[no_mangle] -pub extern "C" fn ChannelDetails_set_remote_network_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.remote_network_id = val.into_rust(); -} -/// The Features the channel counterparty provided upon last connection. -/// Useful for routing as it is the most up-to-date copy of the counterparty's features and -/// many routing-relevant features are present in the init context. -#[no_mangle] -pub extern "C" fn ChannelDetails_get_counterparty_features(this_ptr: &ChannelDetails) -> crate::ln::features::InitFeatures { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_features; - crate::ln::features::InitFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// The Features the channel counterparty provided upon last connection. -/// Useful for routing as it is the most up-to-date copy of the counterparty's features and -/// many routing-relevant features are present in the init context. -#[no_mangle] -pub extern "C" fn ChannelDetails_set_counterparty_features(this_ptr: &mut ChannelDetails, mut val: crate::ln::features::InitFeatures) { - unsafe { &mut *this_ptr.inner }.counterparty_features = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// The value, in satoshis, of this channel as appears in the funding output -#[no_mangle] -pub extern "C" fn ChannelDetails_get_channel_value_satoshis(this_ptr: &ChannelDetails) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_value_satoshis; - (*inner_val) -} -/// The value, in satoshis, of this channel as appears in the funding output -#[no_mangle] -pub extern "C" fn ChannelDetails_set_channel_value_satoshis(this_ptr: &mut ChannelDetails, mut val: u64) { - unsafe { &mut *this_ptr.inner }.channel_value_satoshis = val; -} -/// The user_id passed in to create_channel, or 0 if the channel was inbound. -#[no_mangle] -pub extern "C" fn ChannelDetails_get_user_id(this_ptr: &ChannelDetails) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.user_id; - (*inner_val) -} -/// The user_id passed in to create_channel, or 0 if the channel was inbound. -#[no_mangle] -pub extern "C" fn ChannelDetails_set_user_id(this_ptr: &mut ChannelDetails, mut val: u64) { - unsafe { &mut *this_ptr.inner }.user_id = val; -} -/// The available outbound capacity for sending HTLCs to the remote peer. This does not include -/// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not -/// available for inclusion in new outbound HTLCs). This further does not include any pending -/// outgoing HTLCs which are awaiting some other resolution to be sent. -#[no_mangle] -pub extern "C" fn ChannelDetails_get_outbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.outbound_capacity_msat; - (*inner_val) -} -/// The available outbound capacity for sending HTLCs to the remote peer. This does not include -/// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not -/// available for inclusion in new outbound HTLCs). This further does not include any pending -/// outgoing HTLCs which are awaiting some other resolution to be sent. -#[no_mangle] -pub extern "C" fn ChannelDetails_set_outbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) { - unsafe { &mut *this_ptr.inner }.outbound_capacity_msat = val; -} -/// The available inbound capacity for the remote peer to send HTLCs to us. This does not -/// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not -/// available for inclusion in new inbound HTLCs). -/// Note that there are some corner cases not fully handled here, so the actual available -/// inbound capacity may be slightly higher than this. -#[no_mangle] -pub extern "C" fn ChannelDetails_get_inbound_capacity_msat(this_ptr: &ChannelDetails) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.inbound_capacity_msat; - (*inner_val) -} -/// The available inbound capacity for the remote peer to send HTLCs to us. This does not -/// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not -/// available for inclusion in new inbound HTLCs). -/// Note that there are some corner cases not fully handled here, so the actual available -/// inbound capacity may be slightly higher than this. -#[no_mangle] -pub extern "C" fn ChannelDetails_set_inbound_capacity_msat(this_ptr: &mut ChannelDetails, mut val: u64) { - unsafe { &mut *this_ptr.inner }.inbound_capacity_msat = val; -} -/// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b) -/// the peer is connected, and (c) no monitor update failure is pending resolution. -#[no_mangle] -pub extern "C" fn ChannelDetails_get_is_live(this_ptr: &ChannelDetails) -> bool { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.is_live; - (*inner_val) -} -/// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b) -/// the peer is connected, and (c) no monitor update failure is pending resolution. -#[no_mangle] -pub extern "C" fn ChannelDetails_set_is_live(this_ptr: &mut ChannelDetails, mut val: bool) { - unsafe { &mut *this_ptr.inner }.is_live = val; -} -impl Clone for ChannelDetails { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeChannelDetails>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelDetails_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDetails)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ChannelDetails_clone(orig: &ChannelDetails) -> ChannelDetails { - orig.clone() -} -/// 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 -/// states for more. -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum PaymentSendFailure { - /// 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 - /// once you've changed the parameter at error, you can freely retry the payment in full. - ParameterError(crate::util::errors::APIError), - /// A parameter in a single path 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 once you've changed the parameter at error, you can freely retry the - /// payment in full. - /// - /// The results here are ordered the same as the paths in the route object which was passed to - /// send_payment. - PathParameterError(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ), - /// All paths which were attempted failed to send, with no channel state change taking place. - /// You can freely retry the payment in full (though you probably want to do so over different - /// paths than the ones selected). - AllFailedRetrySafe(crate::c_types::derived::CVec_APIErrorZ), - /// Some paths which were attempted failed to send, though possibly not all. At least some - /// paths have irrevocably committed to the HTLC and retrying the payment in full would result - /// in over-/re-payment. - /// - /// The results here are ordered the same as the paths in the route object which was passed to - /// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely - /// retried (though there is currently no API with which to do so). - /// - /// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried - /// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the - /// case of Ok(())) or will send once channel_monitor_updated is called on the next-hop channel - /// with the latest update_id. - PartialFailure(crate::c_types::derived::CVec_CResult_NoneAPIErrorZZ), -} -use lightning::ln::channelmanager::PaymentSendFailure as nativePaymentSendFailure; -impl PaymentSendFailure { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativePaymentSendFailure { - match self { - PaymentSendFailure::ParameterError (ref a, ) => { - let mut a_nonref = (*a).clone(); - nativePaymentSendFailure::ParameterError ( - a_nonref.into_native(), - ) - }, - PaymentSendFailure::PathParameterError (ref a, ) => { - let mut a_nonref = (*a).clone(); - let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { let mut local_a_nonref_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_a_nonref_0 }); }; - nativePaymentSendFailure::PathParameterError ( - local_a_nonref, - ) - }, - PaymentSendFailure::AllFailedRetrySafe (ref a, ) => { - let mut a_nonref = (*a).clone(); - let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into_native() }); }; - nativePaymentSendFailure::AllFailedRetrySafe ( - local_a_nonref, - ) - }, - PaymentSendFailure::PartialFailure (ref a, ) => { - let mut a_nonref = (*a).clone(); - let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { let mut local_a_nonref_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_a_nonref_0 }); }; - nativePaymentSendFailure::PartialFailure ( - local_a_nonref, - ) - }, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativePaymentSendFailure { - match self { - PaymentSendFailure::ParameterError (mut a, ) => { - nativePaymentSendFailure::ParameterError ( - a.into_native(), - ) - }, - PaymentSendFailure::PathParameterError (mut a, ) => { - let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { let mut local_a_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_a_0 }); }; - nativePaymentSendFailure::PathParameterError ( - local_a, - ) - }, - PaymentSendFailure::AllFailedRetrySafe (mut a, ) => { - let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into_native() }); }; - nativePaymentSendFailure::AllFailedRetrySafe ( - local_a, - ) - }, - PaymentSendFailure::PartialFailure (mut a, ) => { - let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { let mut local_a_0 = match item.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut item.contents.err)) }).into_native() })}; local_a_0 }); }; - nativePaymentSendFailure::PartialFailure ( - local_a, - ) - }, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativePaymentSendFailure) -> Self { - match native { - nativePaymentSendFailure::ParameterError (ref a, ) => { - let mut a_nonref = (*a).clone(); - PaymentSendFailure::ParameterError ( - crate::util::errors::APIError::native_into(a_nonref), - ) - }, - nativePaymentSendFailure::PathParameterError (ref a, ) => { - let mut a_nonref = (*a).clone(); - let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { let mut local_a_nonref_0 = match item { 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_a_nonref_0 }); }; - PaymentSendFailure::PathParameterError ( - local_a_nonref.into(), - ) - }, - nativePaymentSendFailure::AllFailedRetrySafe (ref a, ) => { - let mut a_nonref = (*a).clone(); - let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { crate::util::errors::APIError::native_into(item) }); }; - PaymentSendFailure::AllFailedRetrySafe ( - local_a_nonref.into(), - ) - }, - nativePaymentSendFailure::PartialFailure (ref a, ) => { - let mut a_nonref = (*a).clone(); - let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { let mut local_a_nonref_0 = match item { 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_a_nonref_0 }); }; - PaymentSendFailure::PartialFailure ( - local_a_nonref.into(), - ) - }, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativePaymentSendFailure) -> Self { - match native { - nativePaymentSendFailure::ParameterError (mut a, ) => { - PaymentSendFailure::ParameterError ( - crate::util::errors::APIError::native_into(a), - ) - }, - nativePaymentSendFailure::PathParameterError (mut a, ) => { - let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { let mut local_a_0 = match item { 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_a_0 }); }; - PaymentSendFailure::PathParameterError ( - local_a.into(), - ) - }, - nativePaymentSendFailure::AllFailedRetrySafe (mut a, ) => { - let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::util::errors::APIError::native_into(item) }); }; - PaymentSendFailure::AllFailedRetrySafe ( - local_a.into(), - ) - }, - nativePaymentSendFailure::PartialFailure (mut a, ) => { - let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { let mut local_a_0 = match item { 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_a_0 }); }; - PaymentSendFailure::PartialFailure ( - local_a.into(), - ) - }, - } - } -} -#[no_mangle] -pub extern "C" fn PaymentSendFailure_free(this_ptr: PaymentSendFailure) { } -#[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. -/// -/// This is the main \"logic hub\" for all channel-related actions, and implements -/// ChannelMessageHandler. -/// -/// Non-proportional fees are fixed according to our risk using the provided fee estimator. -/// -/// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`! -/// -/// Users need to notify the new ChannelManager when a new block is connected or -/// disconnected using its `block_connected` and `block_disconnected` methods, starting -/// from after `params.latest_hash`. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelManager_new(mut fee_est: crate::chain::chaininterface::FeeEstimator, mut chain_monitor: crate::chain::Watch, mut tx_broadcaster: crate::chain::chaininterface::BroadcasterInterface, mut logger: crate::util::logger::Logger, mut keys_manager: crate::chain::keysinterface::KeysInterface, mut config: crate::util::config::UserConfig, mut params: crate::ln::channelmanager::ChainParameters) -> ChannelManager { - let mut ret = lightning::ln::channelmanager::ChannelManager::new(fee_est, chain_monitor, tx_broadcaster, logger, keys_manager, *unsafe { Box::from_raw(config.take_inner()) }, *unsafe { Box::from_raw(params.take_inner()) }); - ChannelManager { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Creates a new outbound channel to the given remote node and with the given value. -/// -/// user_id will be provided back as user_channel_id in FundingGenerationReady and -/// FundingBroadcastSafe events to allow tracking of which events correspond with which -/// create_channel call. Note that user_channel_id defaults to 0 for inbound channels, so you -/// may wish to avoid using 0 for user_id here. -/// -/// If successful, will generate a SendOpenChannel message event, so you should probably poll -/// PeerManager::process_events afterwards. -/// -/// Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat is -/// greater than channel_value_satoshis * 1k or channel_value_satoshis is < 1000. -#[must_use] -#[no_mangle] -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 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*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::util::errors::APIError::native_into(e) }).into() }; - local_ret -} - -/// Gets the list of open channels, in random order. See ChannelDetail field documentation for -/// more information. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelManager_list_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ { - let mut ret = unsafe { &*this_arg.inner }.list_channels(); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::ln::channelmanager::ChannelDetails { inner: Box::into_raw(Box::new(item)), is_owned: true } }); }; - local_ret.into() -} - -/// Gets the list of usable channels, in random order. Useful as an argument to -/// get_route to ensure non-announced channels are used. -/// -/// These are guaranteed to have their is_live value set to true, see the documentation for -/// ChannelDetails::is_live for more info on exactly what the criteria are. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelManager_list_usable_channels(this_arg: &ChannelManager) -> crate::c_types::derived::CVec_ChannelDetailsZ { - let mut ret = unsafe { &*this_arg.inner }.list_usable_channels(); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::ln::channelmanager::ChannelDetails { inner: Box::into_raw(Box::new(item)), is_owned: true } }); }; - local_ret.into() -} - -/// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs -/// will be accepted on the given channel, and after additional timeout/the closing of all -/// pending HTLCs, the channel will be closed on chain. -/// -/// May generate a SendShutdown message event on success, which should be relayed. -#[must_use] -#[no_mangle] -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 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 -} - -/// Force closes a channel, immediately broadcasting the latest local commitment transaction to -/// the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager. -#[must_use] -#[no_mangle] -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 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 -} - -/// Force close all channels, immediately broadcasting the latest local commitment transaction -/// for each to the chain and rejecting new HTLCs on each. -#[no_mangle] -pub extern "C" fn ChannelManager_force_close_all_channels(this_arg: &ChannelManager) { - unsafe { &*this_arg.inner }.force_close_all_channels() -} - -/// Sends a payment along a given route. -/// -/// Value parameters are provided via the last hop in route, see documentation for RouteHop -/// fields for more info. -/// -/// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative -/// payment), we don't do anything to stop you! We always try to ensure that if the provided -/// next hop knows the preimage to payment_hash they can claim an additional amount as -/// specified in the last hop in the route! Thus, you should probably do your own -/// payment_preimage tracking (which you should already be doing as they represent \"proof of -/// payment\") and prevent double-sends yourself. -/// -/// May generate SendHTLCs message(s) event on success, which should be relayed. -/// -/// Each path may have a different return value, and PaymentSendValue may return a Vec with -/// each entry matching the corresponding-index entry in the route paths, see -/// PaymentSendFailure for more info. -/// -/// In general, a path may raise: -/// * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee, -/// node public key) is specified. -/// * APIError::ChannelUnavailable if the next-hop channel is not available for updates -/// (including due to previous monitor update failure or new permanent monitor update -/// failure). -/// * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the -/// relevant updates. -/// -/// Note that depending on the type of the PaymentSendFailure the HTLC may have been -/// irrevocably committed to on our end. In such a case, do NOT retry the payment with a -/// different route unless you intend to pay twice! -/// -/// payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate -/// the sender to the recipient and prevent payment-probing (deanonymization) attacks. For -/// newer nodes, it will be provided to you in the invoice. If you do not have one, the Route -/// must not contain multiple paths as multi-path payments require a recipient-provided -/// payment_secret. -/// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature -/// bit set (either as required or as available). If multiple paths are present in the Route, -/// we assume the invoice had the basic_mpp feature set. -#[must_use] -#[no_mangle] -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 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*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::channelmanager::PaymentSendFailure::native_into(e) }).into() }; - local_ret -} - -/// Call this upon creation of a funding transaction for the given channel. -/// -/// Note that ALL inputs in the transaction pointed to by funding_txo MUST spend SegWit outputs -/// or your counterparty can steal your funds! -/// -/// Panics if a funding transaction has already been provided for this channel. -/// -/// May panic if the funding_txo is duplicative with some other channel (note that this should -/// be trivially prevented by using unique funding transaction keys per-channel). -#[no_mangle] -pub extern "C" fn ChannelManager_funding_transaction_generated(this_arg: &ChannelManager, temporary_channel_id: *const [u8; 32], mut funding_txo: crate::chain::transaction::OutPoint) { - unsafe { &*this_arg.inner }.funding_transaction_generated(unsafe { &*temporary_channel_id}, *unsafe { Box::from_raw(funding_txo.take_inner()) }) -} - -/// Generates a signed node_announcement from the given arguments and creates a -/// BroadcastNodeAnnouncement event. Note that such messages will be ignored unless peers have -/// seen a channel_announcement from us (ie unless we have public channels open). -/// -/// RGB is a node \"color\" and alias is a printable human-readable string to describe this node -/// to humans. They carry no in-protocol meaning. -/// -/// addresses represent the set (possibly empty) of socket addresses on which this node accepts -/// incoming connections. These will be broadcast to the network, publicly tying these -/// addresses together. If you wish to preserve user privacy, addresses should likely contain -/// only Tor Onion addresses. -/// -/// Panics if addresses is absurdly large (more than 500). -#[no_mangle] -pub extern "C" fn ChannelManager_broadcast_node_announcement(this_arg: &ChannelManager, mut rgb: crate::c_types::ThreeBytes, mut alias: crate::c_types::ThirtyTwoBytes, mut addresses: crate::c_types::derived::CVec_NetAddressZ) { - let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); }; - unsafe { &*this_arg.inner }.broadcast_node_announcement(rgb.data, alias.data, local_addresses) -} - -/// Processes HTLCs which are pending waiting on random forward delay. -/// -/// Should only really ever be called in response to a PendingHTLCsForwardable event. -/// Will likely generate further events. -#[no_mangle] -pub extern "C" fn ChannelManager_process_pending_htlc_forwards(this_arg: &ChannelManager) { - unsafe { &*this_arg.inner }.process_pending_htlc_forwards() -} - -/// If a peer is disconnected we mark any channels with that peer as 'disabled'. -/// After some time, if channels are still disabled we need to broadcast a ChannelUpdate -/// to inform the network about the uselessness of these channels. -/// -/// This method handles all the details, and must be called roughly once per minute. -/// -/// Note that in some rare cases this may generate a `chain::Watch::update_channel` call. -#[no_mangle] -pub extern "C" fn ChannelManager_timer_chan_freshness_every_min(this_arg: &ChannelManager) { - unsafe { &*this_arg.inner }.timer_chan_freshness_every_min() -} - -/// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect -/// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources -/// along the path (including in our own channel on which we received it). -/// Returns false if no payment was found to fail backwards, true if the process of failing the -/// HTLC backwards has been started. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelManager_fail_htlc_backwards(this_arg: &ChannelManager, payment_hash: *const [u8; 32], mut payment_secret: crate::c_types::ThirtyTwoBytes) -> bool { - 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 }.fail_htlc_backwards(&::lightning::ln::channelmanager::PaymentHash(unsafe { *payment_hash }), &local_payment_secret); - ret -} - -/// Provides a payment preimage in response to a PaymentReceived event, returning true and -/// generating message events for the net layer to claim the payment, if possible. Thus, you -/// should probably kick the net layer to go send messages if this returns true! -/// -/// You must specify the expected amounts for this HTLC, and we will only claim HTLCs -/// available within a few percent of the expected amount. This is critical for several -/// reasons : a) it avoids providing senders with `proof-of-payment` (in the form of the -/// payment_preimage without having provided the full value and b) it avoids certain -/// privacy-breaking recipient-probing attacks which may reveal payment activity to -/// motivated attackers. -/// -/// Note that the privacy concerns in (b) are not relevant in payments with a payment_secret -/// set. Thus, for such payments we will claim any payments which do not under-pay. -/// -/// May panic if called except in response to a PaymentReceived event. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelManager_claim_funds(this_arg: &ChannelManager, mut payment_preimage: crate::c_types::ThirtyTwoBytes, mut payment_secret: crate::c_types::ThirtyTwoBytes, mut expected_amount: u64) -> bool { - 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 }.claim_funds(::lightning::ln::channelmanager::PaymentPreimage(payment_preimage.data), &local_payment_secret, expected_amount); - ret -} - -/// Gets the node_id held by this ChannelManager -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelManager_get_our_node_id(this_arg: &ChannelManager) -> crate::c_types::PublicKey { - let mut ret = unsafe { &*this_arg.inner }.get_our_node_id(); - crate::c_types::PublicKey::from_rust(&ret) -} - -/// Restores a single, given channel to normal operation after a -/// ChannelMonitorUpdateErr::TemporaryFailure was returned from a channel monitor update -/// operation. -/// -/// All ChannelMonitor updates up to and including highest_applied_update_id must have been -/// fully committed in every copy of the given channels' ChannelMonitors. -/// -/// Note that there is no effect to calling with a highest_applied_update_id other than the -/// current latest ChannelMonitorUpdate and one call to this function after multiple -/// ChannelMonitorUpdateErr::TemporaryFailures is fine. The highest_applied_update_id field -/// exists largely only to prevent races between this and concurrent update_monitor calls. -/// -/// Thus, the anticipated use is, at a high level: -/// 1) You register a chain::Watch with this ChannelManager, -/// 2) it stores each update to disk, and begins updating any remote (eg watchtower) copies of -/// said ChannelMonitors as it can, returning ChannelMonitorUpdateErr::TemporaryFailures -/// any time it cannot do so instantly, -/// 3) update(s) are applied to each remote copy of a ChannelMonitor, -/// 4) once all remote copies are updated, you call this function with the update_id that -/// completed, and once it is the latest the Channel will be re-enabled. -#[no_mangle] -pub extern "C" fn ChannelManager_channel_monitor_updated(this_arg: &ChannelManager, funding_txo: &crate::chain::transaction::OutPoint, mut highest_applied_update_id: u64) { - unsafe { &*this_arg.inner }.channel_monitor_updated(unsafe { &*funding_txo.inner }, highest_applied_update_id) -} - -impl From for crate::util::events::MessageSendEventsProvider { - fn from(obj: nativeChannelManager) -> Self { - let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = ChannelManager_as_MessageSendEventsProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(ChannelManager_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn ChannelManager_as_MessageSendEventsProvider(this_arg: &ChannelManager) -> crate::util::events::MessageSendEventsProvider { - crate::util::events::MessageSendEventsProvider { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - get_and_clear_pending_msg_events: ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events, - } -} - -#[must_use] -extern "C" fn ChannelManager_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { - let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); }; - local_ret.into() -} - -impl From for crate::util::events::EventsProvider { - fn from(obj: nativeChannelManager) -> Self { - let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = ChannelManager_as_EventsProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(ChannelManager_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn ChannelManager_as_EventsProvider(this_arg: &ChannelManager) -> crate::util::events::EventsProvider { - crate::util::events::EventsProvider { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - get_and_clear_pending_events: ChannelManager_EventsProvider_get_and_clear_pending_events, - } -} - -#[must_use] -extern "C" fn ChannelManager_EventsProvider_get_and_clear_pending_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_EventZ { - let mut ret = >::get_and_clear_pending_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::Event::native_into(item) }); }; - local_ret.into() -} - -impl From for crate::chain::Listen { - fn from(obj: nativeChannelManager) -> Self { - let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = ChannelManager_as_Listen(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(ChannelManager_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn ChannelManager_as_Listen(this_arg: &ChannelManager) -> crate::chain::Listen { - crate::chain::Listen { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - block_connected: ChannelManager_Listen_block_connected, - block_disconnected: ChannelManager_Listen_block_disconnected, - } -} - -extern "C" fn ChannelManager_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) { - >::block_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height) -} -extern "C" fn ChannelManager_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut _height: u32) { - >::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), _height) -} - -/// Updates channel state based on transactions seen in a connected block. -#[no_mangle] -pub extern "C" fn ChannelManager_block_connected(this_arg: &ChannelManager, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32) { - let mut local_txdata = Vec::new(); for mut item in txdata.into_rust().drain(..) { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item.to_rust(); let mut local_txdata_0 = (orig_txdata_0_0, orig_txdata_0_1.into_bitcoin()); local_txdata_0 }); }; - unsafe { &*this_arg.inner }.block_connected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::>()[..], height) -} - -/// Updates channel state based on a disconnected block. -/// -/// If necessary, the channel may be force-closed without letting the counterparty participate -/// in the shutdown. -#[no_mangle] -pub extern "C" fn ChannelManager_block_disconnected(this_arg: &ChannelManager, header: *const [u8; 80]) { - unsafe { &*this_arg.inner }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap()) -} - -/// Blocks until ChannelManager needs to be persisted. Only one listener on -/// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken -/// up. -#[no_mangle] -pub extern "C" fn ChannelManager_await_persistable_update(this_arg: &ChannelManager) { - unsafe { &*this_arg.inner }.await_persistable_update() -} - -impl From for crate::ln::msgs::ChannelMessageHandler { - fn from(obj: nativeChannelManager) -> Self { - let mut rust_obj = ChannelManager { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = ChannelManager_as_ChannelMessageHandler(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(ChannelManager_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn ChannelManager_as_ChannelMessageHandler(this_arg: &ChannelManager) -> crate::ln::msgs::ChannelMessageHandler { - crate::ln::msgs::ChannelMessageHandler { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - handle_open_channel: ChannelManager_ChannelMessageHandler_handle_open_channel, - handle_accept_channel: ChannelManager_ChannelMessageHandler_handle_accept_channel, - handle_funding_created: ChannelManager_ChannelMessageHandler_handle_funding_created, - handle_funding_signed: ChannelManager_ChannelMessageHandler_handle_funding_signed, - handle_funding_locked: ChannelManager_ChannelMessageHandler_handle_funding_locked, - handle_shutdown: ChannelManager_ChannelMessageHandler_handle_shutdown, - handle_closing_signed: ChannelManager_ChannelMessageHandler_handle_closing_signed, - handle_update_add_htlc: ChannelManager_ChannelMessageHandler_handle_update_add_htlc, - handle_update_fulfill_htlc: ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc, - handle_update_fail_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_htlc, - handle_update_fail_malformed_htlc: ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc, - handle_commitment_signed: ChannelManager_ChannelMessageHandler_handle_commitment_signed, - handle_revoke_and_ack: ChannelManager_ChannelMessageHandler_handle_revoke_and_ack, - handle_update_fee: ChannelManager_ChannelMessageHandler_handle_update_fee, - handle_announcement_signatures: ChannelManager_ChannelMessageHandler_handle_announcement_signatures, - peer_disconnected: ChannelManager_ChannelMessageHandler_peer_disconnected, - peer_connected: ChannelManager_ChannelMessageHandler_peer_connected, - handle_channel_reestablish: ChannelManager_ChannelMessageHandler_handle_channel_reestablish, - handle_error: ChannelManager_ChannelMessageHandler_handle_error, - MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - get_and_clear_pending_msg_events: ChannelManager_ChannelMessageHandler_get_and_clear_pending_msg_events, - }, - } -} - -extern "C" fn ChannelManager_ChannelMessageHandler_handle_open_channel(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, mut their_features: crate::ln::features::InitFeatures, msg: &crate::ln::msgs::OpenChannel) { - >::handle_open_channel(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), *unsafe { Box::from_raw(their_features.take_inner()) }, unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_accept_channel(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, mut their_features: crate::ln::features::InitFeatures, msg: &crate::ln::msgs::AcceptChannel) { - >::handle_accept_channel(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), *unsafe { Box::from_raw(their_features.take_inner()) }, unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_created(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingCreated) { - >::handle_funding_created(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_signed(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingSigned) { - >::handle_funding_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_funding_locked(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingLocked) { - >::handle_funding_locked(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_shutdown(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, their_features: &crate::ln::features::InitFeatures, msg: &crate::ln::msgs::Shutdown) { - >::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*their_features.inner }, unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_closing_signed(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ClosingSigned) { - >::handle_closing_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_add_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateAddHTLC) { - >::handle_update_add_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fulfill_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFulfillHTLC) { - >::handle_update_fulfill_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fail_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFailHTLC) { - >::handle_update_fail_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fail_malformed_htlc(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFailMalformedHTLC) { - >::handle_update_fail_malformed_htlc(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_commitment_signed(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::CommitmentSigned) { - >::handle_commitment_signed(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_revoke_and_ack(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::RevokeAndACK) { - >::handle_revoke_and_ack(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_update_fee(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFee) { - >::handle_update_fee(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_announcement_signatures(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::AnnouncementSignatures) { - >::handle_announcement_signatures(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_channel_reestablish(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ChannelReestablish) { - >::handle_channel_reestablish(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_peer_disconnected(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, mut no_connection_possible: bool) { - >::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), no_connection_possible) -} -extern "C" fn ChannelManager_ChannelMessageHandler_peer_connected(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, init_msg: &crate::ln::msgs::Init) { - >::peer_connected(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*init_msg.inner }) -} -extern "C" fn ChannelManager_ChannelMessageHandler_handle_error(this_arg: *const c_void, mut counterparty_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ErrorMessage) { - >::handle_error(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, &counterparty_node_id.into_rust(), unsafe { &*msg.inner }) -} -#[must_use] -extern "C" fn ChannelManager_ChannelMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { - let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeChannelManager) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); }; - local_ret.into() -} - -#[no_mangle] -pub extern "C" fn ChannelManager_write(obj: &ChannelManager) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ChannelManager_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelManager) }) -} - -use lightning::ln::channelmanager::ChannelManagerReadArgs as nativeChannelManagerReadArgsImport; -type nativeChannelManagerReadArgs = nativeChannelManagerReadArgsImport<'static, crate::chain::keysinterface::Sign, crate::chain::Watch, crate::chain::chaininterface::BroadcasterInterface, crate::chain::keysinterface::KeysInterface, crate::chain::chaininterface::FeeEstimator, crate::util::logger::Logger>; - -/// Arguments for the creation of a ChannelManager that are not deserialized. -/// -/// At a high-level, the process for deserializing a ChannelManager and resuming normal operation -/// is: -/// 1) Deserialize all stored ChannelMonitors. -/// 2) Deserialize the ChannelManager by filling in this struct and calling: -/// <(BlockHash, ChannelManager)>::read(reader, args) -/// This may result in closing some Channels if the ChannelMonitor is newer than the stored -/// ChannelManager state to ensure no loss of funds. Thus, transactions may be broadcasted. -/// 3) If you are not fetching full blocks, register all relevant ChannelMonitor outpoints the same -/// way you would handle a `chain::Filter` call using ChannelMonitor::get_outputs_to_watch() and -/// ChannelMonitor::get_funding_txo(). -/// 4) Reconnect blocks on your ChannelMonitors. -/// 5) Disconnect/connect blocks on the ChannelManager. -/// 6) Move the ChannelMonitors into your local chain::Watch. -/// -/// Note that the ordering of #4-6 is not of importance, however all three must occur before you -/// call any other methods on the newly-deserialized ChannelManager. -/// -/// Note that because some channels may be closed during deserialization, it is critical that you -/// always deserialize only the latest version of a ChannelManager and ChannelMonitors available to -/// you. If you deserialize an old ChannelManager (during which force-closure transactions may be -/// broadcast), and then later deserialize a newer version of the same ChannelManager (which will -/// not force-close the same channels but consider them live), you may end up revoking a state for -/// which you've already broadcasted the transaction. -#[must_use] -#[repr(C)] -pub struct ChannelManagerReadArgs { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelManagerReadArgs, - pub is_owned: bool, -} - -impl Drop for ChannelManagerReadArgs { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelManagerReadArgs>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_free(this_ptr: ChannelManagerReadArgs) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelManagerReadArgs_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelManagerReadArgs); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelManagerReadArgs { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelManagerReadArgs { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The keys provider which will give us relevant keys. Some keys will be loaded during -/// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel -/// signing data. -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_get_keys_manager(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::keysinterface::KeysInterface { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.keys_manager; - &(*inner_val) -} -/// The keys provider which will give us relevant keys. Some keys will be loaded during -/// deserialization and KeysInterface::read_chan_signer will be used to read per-Channel -/// signing data. -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_set_keys_manager(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::keysinterface::KeysInterface) { - unsafe { &mut *this_ptr.inner }.keys_manager = val; -} -/// The fee_estimator for use in the ChannelManager in the future. -/// -/// No calls to the FeeEstimator will be made during deserialization. -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_get_fee_estimator(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::chaininterface::FeeEstimator { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_estimator; - &(*inner_val) -} -/// The fee_estimator for use in the ChannelManager in the future. -/// -/// No calls to the FeeEstimator will be made during deserialization. -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_set_fee_estimator(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::chaininterface::FeeEstimator) { - unsafe { &mut *this_ptr.inner }.fee_estimator = val; -} -/// The chain::Watch for use in the ChannelManager in the future. -/// -/// No calls to the chain::Watch will be made during deserialization. It is assumed that -/// you have deserialized ChannelMonitors separately and will add them to your -/// chain::Watch after deserializing this ChannelManager. -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_get_chain_monitor(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::Watch { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chain_monitor; - &(*inner_val) -} -/// The chain::Watch for use in the ChannelManager in the future. -/// -/// No calls to the chain::Watch will be made during deserialization. It is assumed that -/// you have deserialized ChannelMonitors separately and will add them to your -/// chain::Watch after deserializing this ChannelManager. -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_set_chain_monitor(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::Watch) { - unsafe { &mut *this_ptr.inner }.chain_monitor = val; -} -/// The BroadcasterInterface which will be used in the ChannelManager in the future and may be -/// used to broadcast the latest local commitment transactions of channels which must be -/// force-closed during deserialization. -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_get_tx_broadcaster(this_ptr: &ChannelManagerReadArgs) -> *const crate::chain::chaininterface::BroadcasterInterface { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.tx_broadcaster; - &(*inner_val) -} -/// The BroadcasterInterface which will be used in the ChannelManager in the future and may be -/// used to broadcast the latest local commitment transactions of channels which must be -/// force-closed during deserialization. -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_set_tx_broadcaster(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::chain::chaininterface::BroadcasterInterface) { - unsafe { &mut *this_ptr.inner }.tx_broadcaster = val; -} -/// The Logger for use in the ChannelManager and which may be used to log information during -/// deserialization. -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_get_logger(this_ptr: &ChannelManagerReadArgs) -> *const crate::util::logger::Logger { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.logger; - &(*inner_val) -} -/// The Logger for use in the ChannelManager and which may be used to log information during -/// deserialization. -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_set_logger(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::util::logger::Logger) { - unsafe { &mut *this_ptr.inner }.logger = val; -} -/// Default settings used for new channels. Any existing channels will continue to use the -/// runtime settings which were stored when the ChannelManager was serialized. -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_get_default_config(this_ptr: &ChannelManagerReadArgs) -> crate::util::config::UserConfig { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.default_config; - crate::util::config::UserConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// Default settings used for new channels. Any existing channels will continue to use the -/// runtime settings which were stored when the ChannelManager was serialized. -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_set_default_config(this_ptr: &mut ChannelManagerReadArgs, mut val: crate::util::config::UserConfig) { - unsafe { &mut *this_ptr.inner }.default_config = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// Simple utility function to create a ChannelManagerReadArgs which creates the monitor -/// HashMap for you. This is primarily useful for C bindings where it is not practical to -/// populate a HashMap directly from C. -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelManagerReadArgs_new(mut keys_manager: crate::chain::keysinterface::KeysInterface, mut fee_estimator: crate::chain::chaininterface::FeeEstimator, mut chain_monitor: crate::chain::Watch, mut tx_broadcaster: crate::chain::chaininterface::BroadcasterInterface, mut logger: crate::util::logger::Logger, mut default_config: crate::util::config::UserConfig, mut channel_monitors: crate::c_types::derived::CVec_ChannelMonitorZ) -> ChannelManagerReadArgs { - let mut local_channel_monitors = Vec::new(); for mut item in channel_monitors.into_rust().drain(..) { local_channel_monitors.push( { unsafe { &mut *item.inner } }); }; - let mut ret = lightning::ln::channelmanager::ChannelManagerReadArgs::new(keys_manager, fee_estimator, chain_monitor, tx_broadcaster, logger, *unsafe { Box::from_raw(default_config.take_inner()) }, local_channel_monitors); - ChannelManagerReadArgs { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -#[no_mangle] -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 res: Result<(bitcoin::hash_types::BlockHash, lightning::ln::channelmanager::ChannelManager), 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 }).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 -} diff --git a/lightning-c-bindings/src/ln/features.rs b/lightning-c-bindings/src/ln/features.rs deleted file mode 100644 index 06dc42020..000000000 --- a/lightning-c-bindings/src/ln/features.rs +++ /dev/null @@ -1,286 +0,0 @@ -//! Feature flag definitions for the Lightning protocol according to [BOLT #9]. -//! -//! Lightning nodes advertise a supported set of operation through feature flags. Features are -//! applicable for a specific context as indicated in some [messages]. [`Features`] encapsulates -//! behavior for specifying and checking feature flags for a particular context. Each feature is -//! defined internally by a trait specifying the corresponding flags (i.e., even and odd bits). A -//! [`Context`] is used to parameterize [`Features`] and defines which features it can support. -//! -//! Whether a feature is considered \"known\" or \"unknown\" is relative to the implementation, whereas -//! the term \"supports\" is used in reference to a particular set of [`Features`]. That is, a node -//! supports a feature if it advertises the feature (as either required or optional) to its peers. -//! And the implementation can interpret a feature if the feature is known to it. -//! -//! [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md -//! [messages]: ../msgs/index.html -//! [`Features`]: struct.Features.html -//! [`Context`]: sealed/trait.Context.html - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - -impl Clone for InitFeatures { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeInitFeatures>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn InitFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInitFeatures)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn InitFeatures_clone(orig: &InitFeatures) -> InitFeatures { - orig.clone() -} -impl Clone for NodeFeatures { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeNodeFeatures>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn NodeFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeFeatures)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn NodeFeatures_clone(orig: &NodeFeatures) -> NodeFeatures { - orig.clone() -} -impl Clone for ChannelFeatures { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeChannelFeatures>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelFeatures)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ChannelFeatures_clone(orig: &ChannelFeatures) -> ChannelFeatures { - orig.clone() -} - -use lightning::ln::features::InitFeatures as nativeInitFeaturesImport; -type nativeInitFeatures = nativeInitFeaturesImport; - -/// Features used within an `init` message. -#[must_use] -#[repr(C)] -pub struct InitFeatures { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeInitFeatures, - pub is_owned: bool, -} - -impl Drop for InitFeatures { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeInitFeatures>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn InitFeatures_free(this_ptr: InitFeatures) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn InitFeatures_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInitFeatures); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl InitFeatures { - pub(crate) fn take_inner(mut self) -> *mut nativeInitFeatures { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} - -use lightning::ln::features::NodeFeatures as nativeNodeFeaturesImport; -type nativeNodeFeatures = nativeNodeFeaturesImport; - -/// Features used within a `node_announcement` message. -#[must_use] -#[repr(C)] -pub struct NodeFeatures { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeNodeFeatures, - pub is_owned: bool, -} - -impl Drop for NodeFeatures { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeNodeFeatures>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn NodeFeatures_free(this_ptr: NodeFeatures) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn NodeFeatures_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeFeatures); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl NodeFeatures { - pub(crate) fn take_inner(mut self) -> *mut nativeNodeFeatures { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} - -use lightning::ln::features::ChannelFeatures as nativeChannelFeaturesImport; -type nativeChannelFeatures = nativeChannelFeaturesImport; - -/// Features used within a `channel_announcement` message. -#[must_use] -#[repr(C)] -pub struct ChannelFeatures { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelFeatures, - pub is_owned: bool, -} - -impl Drop for ChannelFeatures { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelFeatures>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelFeatures_free(this_ptr: ChannelFeatures) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelFeatures_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelFeatures); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelFeatures { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelFeatures { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Create a blank Features with no features set -#[must_use] -#[no_mangle] -pub extern "C" fn InitFeatures_empty() -> InitFeatures { - let mut ret = lightning::ln::features::InitFeatures::empty(); - InitFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Creates features known by the implementation as defined by [`T::KNOWN_FEATURE_FLAGS`]. -/// -/// [`T::KNOWN_FEATURE_FLAGS`]: sealed/trait.Context.html#associatedconstant.KNOWN_FEATURE_FLAGS -#[must_use] -#[no_mangle] -pub extern "C" fn InitFeatures_known() -> InitFeatures { - let mut ret = lightning::ln::features::InitFeatures::known(); - InitFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Create a blank Features with no features set -#[must_use] -#[no_mangle] -pub extern "C" fn NodeFeatures_empty() -> NodeFeatures { - let mut ret = lightning::ln::features::NodeFeatures::empty(); - NodeFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Creates features known by the implementation as defined by [`T::KNOWN_FEATURE_FLAGS`]. -/// -/// [`T::KNOWN_FEATURE_FLAGS`]: sealed/trait.Context.html#associatedconstant.KNOWN_FEATURE_FLAGS -#[must_use] -#[no_mangle] -pub extern "C" fn NodeFeatures_known() -> NodeFeatures { - let mut ret = lightning::ln::features::NodeFeatures::known(); - NodeFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Create a blank Features with no features set -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelFeatures_empty() -> ChannelFeatures { - let mut ret = lightning::ln::features::ChannelFeatures::empty(); - ChannelFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Creates features known by the implementation as defined by [`T::KNOWN_FEATURE_FLAGS`]. -/// -/// [`T::KNOWN_FEATURE_FLAGS`]: sealed/trait.Context.html#associatedconstant.KNOWN_FEATURE_FLAGS -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelFeatures_known() -> ChannelFeatures { - let mut ret = lightning::ln::features::ChannelFeatures::known(); - ChannelFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -#[no_mangle] -pub extern "C" fn InitFeatures_write(obj: &InitFeatures) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn InitFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInitFeatures) }) -} -#[no_mangle] -pub extern "C" fn NodeFeatures_write(obj: &NodeFeatures) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn NodeFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeFeatures) }) -} -#[no_mangle] -pub extern "C" fn ChannelFeatures_write(obj: &ChannelFeatures) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ChannelFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelFeatures) }) -} -#[no_mangle] -pub extern "C" fn InitFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InitFeaturesDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::features::InitFeatures { 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 -} -#[no_mangle] -pub extern "C" fn NodeFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeFeaturesDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::features::NodeFeatures { 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 -} -#[no_mangle] -pub extern "C" fn ChannelFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelFeaturesDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::features::ChannelFeatures { 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 -} diff --git a/lightning-c-bindings/src/ln/mod.rs b/lightning-c-bindings/src/ln/mod.rs deleted file mode 100644 index b81204a47..000000000 --- a/lightning-c-bindings/src/ln/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! High level lightning structs and impls live here. -//! -//! You probably want to create a channelmanager::ChannelManager, and a routing::NetGraphMsgHandler first. -//! Then, you probably want to pass them both on to a peer_handler::PeerManager and use that to -//! create/manage connections and call get_and_clear_pending_events after each action, handling -//! them appropriately. -//! -//! When you want to open/close a channel or send a payment, call into your ChannelManager and when -//! you want to learn things about the network topology (eg get a route for sending a payment), -//! call into your NetGraphMsgHandler. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - -pub mod channelmanager; -pub mod msgs; -pub mod peer_handler; -pub mod chan_utils; -pub mod features; diff --git a/lightning-c-bindings/src/ln/msgs.rs b/lightning-c-bindings/src/ln/msgs.rs deleted file mode 100644 index 416b532c1..000000000 --- a/lightning-c-bindings/src/ln/msgs.rs +++ /dev/null @@ -1,4822 +0,0 @@ -//! Wire messages, traits representing wire message handlers, and a few error types live here. -//! -//! For a normal node you probably don't need to use anything here, however, if you wish to split a -//! node into an internet-facing route/message socket handling daemon and a separate daemon (or -//! server entirely) which handles only channel-related messages you may wish to implement -//! ChannelMessageHandler yourself and use it to re-serialize messages and pass them across -//! daemons/servers. -//! -//! Note that if you go with such an architecture (instead of passing raw socket events to a -//! non-internet-facing system) you trust the frontend internet-facing system to not lie about the -//! source node_id of the message, however this does allow you to significantly reduce bandwidth -//! between the systems as routing messages can represent a significant chunk of bandwidth usage -//! (especially for non-channel-publicly-announcing nodes). As an alternate design which avoids -//! this issue, if you have sufficient bidirectional bandwidth between your systems, you may send -//! raw socket events into your non-internet-facing system and then send routing events back to -//! track the network on the less-secure system. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - - -use lightning::ln::msgs::DecodeError as nativeDecodeErrorImport; -type nativeDecodeError = nativeDecodeErrorImport; - -/// An error in decoding a message or struct. -#[must_use] -#[repr(C)] -pub struct DecodeError { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeDecodeError, - pub is_owned: bool, -} - -impl Drop for DecodeError { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeDecodeError>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn DecodeError_free(this_ptr: DecodeError) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn DecodeError_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDecodeError); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl DecodeError { - pub(crate) fn take_inner(mut self) -> *mut nativeDecodeError { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -impl Clone for DecodeError { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeDecodeError>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn 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; -type nativeInit = nativeInitImport; - -/// An init message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct Init { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeInit, - pub is_owned: bool, -} - -impl Drop for Init { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeInit>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn Init_free(this_ptr: Init) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn Init_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInit); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl Init { - pub(crate) fn take_inner(mut self) -> *mut nativeInit { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The relevant features which the sender supports -#[no_mangle] -pub extern "C" fn Init_get_features(this_ptr: &Init) -> crate::ln::features::InitFeatures { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features; - crate::ln::features::InitFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// The relevant features which the sender supports -#[no_mangle] -pub extern "C" fn Init_set_features(this_ptr: &mut Init, mut val: crate::ln::features::InitFeatures) { - unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) }; -} -#[must_use] -#[no_mangle] -pub extern "C" fn Init_new(mut features_arg: crate::ln::features::InitFeatures) -> Init { - Init { inner: Box::into_raw(Box::new(nativeInit { - features: *unsafe { Box::from_raw(features_arg.take_inner()) }, - })), is_owned: true } -} -impl Clone for Init { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeInit>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn Init_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInit)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn Init_clone(orig: &Init) -> Init { - orig.clone() -} - -use lightning::ln::msgs::ErrorMessage as nativeErrorMessageImport; -type nativeErrorMessage = nativeErrorMessageImport; - -/// An error message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct ErrorMessage { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeErrorMessage, - pub is_owned: bool, -} - -impl Drop for ErrorMessage { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeErrorMessage>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ErrorMessage_free(this_ptr: ErrorMessage) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ErrorMessage_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeErrorMessage); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ErrorMessage { - pub(crate) fn take_inner(mut self) -> *mut nativeErrorMessage { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID involved in the error -#[no_mangle] -pub extern "C" fn ErrorMessage_get_channel_id(this_ptr: &ErrorMessage) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID involved in the error -#[no_mangle] -pub extern "C" fn ErrorMessage_set_channel_id(this_ptr: &mut ErrorMessage, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// A possibly human-readable error description. -/// The string should be sanitized before it is used (e.g. emitted to logs -/// or printed to stdout). Otherwise, a well crafted error message may trigger a security -/// vulnerability in the terminal emulator or the logging subsystem. -#[no_mangle] -pub extern "C" fn ErrorMessage_get_data(this_ptr: &ErrorMessage) -> crate::c_types::Str { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.data; - (*inner_val).as_str().into() -} -/// A possibly human-readable error description. -/// The string should be sanitized before it is used (e.g. emitted to logs -/// or printed to stdout). Otherwise, a well crafted error message may trigger a security -/// vulnerability in the terminal emulator or the logging subsystem. -#[no_mangle] -pub extern "C" fn ErrorMessage_set_data(this_ptr: &mut ErrorMessage, mut val: crate::c_types::derived::CVec_u8Z) { - unsafe { &mut *this_ptr.inner }.data = String::from_utf8(val.into_rust()).unwrap(); -} -#[must_use] -#[no_mangle] -pub extern "C" fn ErrorMessage_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut data_arg: crate::c_types::derived::CVec_u8Z) -> ErrorMessage { - ErrorMessage { inner: Box::into_raw(Box::new(nativeErrorMessage { - channel_id: channel_id_arg.data, - data: String::from_utf8(data_arg.into_rust()).unwrap(), - })), is_owned: true } -} -impl Clone for ErrorMessage { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeErrorMessage>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ErrorMessage_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeErrorMessage)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ErrorMessage_clone(orig: &ErrorMessage) -> ErrorMessage { - orig.clone() -} - -use lightning::ln::msgs::Ping as nativePingImport; -type nativePing = nativePingImport; - -/// A ping message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct Ping { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativePing, - pub is_owned: bool, -} - -impl Drop for Ping { - fn drop(&mut self) { - if self.is_owned && !<*mut nativePing>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn Ping_free(this_ptr: Ping) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn Ping_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativePing); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl Ping { - pub(crate) fn take_inner(mut self) -> *mut nativePing { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The desired response length -#[no_mangle] -pub extern "C" fn Ping_get_ponglen(this_ptr: &Ping) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.ponglen; - (*inner_val) -} -/// The desired response length -#[no_mangle] -pub extern "C" fn Ping_set_ponglen(this_ptr: &mut Ping, mut val: u16) { - unsafe { &mut *this_ptr.inner }.ponglen = val; -} -/// The ping packet size. -/// This field is not sent on the wire. byteslen zeros are sent. -#[no_mangle] -pub extern "C" fn Ping_get_byteslen(this_ptr: &Ping) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.byteslen; - (*inner_val) -} -/// The ping packet size. -/// This field is not sent on the wire. byteslen zeros are sent. -#[no_mangle] -pub extern "C" fn Ping_set_byteslen(this_ptr: &mut Ping, mut val: u16) { - unsafe { &mut *this_ptr.inner }.byteslen = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn Ping_new(mut ponglen_arg: u16, mut byteslen_arg: u16) -> Ping { - Ping { inner: Box::into_raw(Box::new(nativePing { - ponglen: ponglen_arg, - byteslen: byteslen_arg, - })), is_owned: true } -} -impl Clone for Ping { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativePing>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn Ping_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePing)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn Ping_clone(orig: &Ping) -> Ping { - orig.clone() -} - -use lightning::ln::msgs::Pong as nativePongImport; -type nativePong = nativePongImport; - -/// A pong message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct Pong { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativePong, - pub is_owned: bool, -} - -impl Drop for Pong { - fn drop(&mut self) { - if self.is_owned && !<*mut nativePong>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn Pong_free(this_ptr: Pong) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn Pong_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativePong); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl Pong { - pub(crate) fn take_inner(mut self) -> *mut nativePong { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The pong packet size. -/// This field is not sent on the wire. byteslen zeros are sent. -#[no_mangle] -pub extern "C" fn Pong_get_byteslen(this_ptr: &Pong) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.byteslen; - (*inner_val) -} -/// The pong packet size. -/// This field is not sent on the wire. byteslen zeros are sent. -#[no_mangle] -pub extern "C" fn Pong_set_byteslen(this_ptr: &mut Pong, mut val: u16) { - unsafe { &mut *this_ptr.inner }.byteslen = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn Pong_new(mut byteslen_arg: u16) -> Pong { - Pong { inner: Box::into_raw(Box::new(nativePong { - byteslen: byteslen_arg, - })), is_owned: true } -} -impl Clone for Pong { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativePong>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn Pong_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePong)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn Pong_clone(orig: &Pong) -> Pong { - orig.clone() -} - -use lightning::ln::msgs::OpenChannel as nativeOpenChannelImport; -type nativeOpenChannel = nativeOpenChannelImport; - -/// An open_channel message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct OpenChannel { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeOpenChannel, - pub is_owned: bool, -} - -impl Drop for OpenChannel { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeOpenChannel>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn OpenChannel_free(this_ptr: OpenChannel) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn OpenChannel_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeOpenChannel); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl OpenChannel { - pub(crate) fn take_inner(mut self) -> *mut nativeOpenChannel { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The genesis hash of the blockchain where the channel is to be opened -#[no_mangle] -pub extern "C" fn OpenChannel_get_chain_hash(this_ptr: &OpenChannel) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chain_hash; - (*inner_val).as_inner() -} -/// The genesis hash of the blockchain where the channel is to be opened -#[no_mangle] -pub extern "C" fn OpenChannel_set_chain_hash(this_ptr: &mut OpenChannel, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); -} -/// A temporary channel ID, until the funding outpoint is announced -#[no_mangle] -pub extern "C" fn OpenChannel_get_temporary_channel_id(this_ptr: &OpenChannel) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.temporary_channel_id; - &(*inner_val) -} -/// A temporary channel ID, until the funding outpoint is announced -#[no_mangle] -pub extern "C" fn OpenChannel_set_temporary_channel_id(this_ptr: &mut OpenChannel, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.temporary_channel_id = val.data; -} -/// The channel value -#[no_mangle] -pub extern "C" fn OpenChannel_get_funding_satoshis(this_ptr: &OpenChannel) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_satoshis; - (*inner_val) -} -/// The channel value -#[no_mangle] -pub extern "C" fn OpenChannel_set_funding_satoshis(this_ptr: &mut OpenChannel, mut val: u64) { - unsafe { &mut *this_ptr.inner }.funding_satoshis = val; -} -/// The amount to push to the counterparty as part of the open, in milli-satoshi -#[no_mangle] -pub extern "C" fn OpenChannel_get_push_msat(this_ptr: &OpenChannel) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.push_msat; - (*inner_val) -} -/// The amount to push to the counterparty as part of the open, in milli-satoshi -#[no_mangle] -pub extern "C" fn OpenChannel_set_push_msat(this_ptr: &mut OpenChannel, mut val: u64) { - unsafe { &mut *this_ptr.inner }.push_msat = val; -} -/// The threshold below which outputs on transactions broadcast by sender will be omitted -#[no_mangle] -pub extern "C" fn OpenChannel_get_dust_limit_satoshis(this_ptr: &OpenChannel) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.dust_limit_satoshis; - (*inner_val) -} -/// The threshold below which outputs on transactions broadcast by sender will be omitted -#[no_mangle] -pub extern "C" fn OpenChannel_set_dust_limit_satoshis(this_ptr: &mut OpenChannel, mut val: u64) { - unsafe { &mut *this_ptr.inner }.dust_limit_satoshis = val; -} -/// The maximum inbound HTLC value in flight towards sender, in milli-satoshi -#[no_mangle] -pub extern "C" fn OpenChannel_get_max_htlc_value_in_flight_msat(this_ptr: &OpenChannel) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_htlc_value_in_flight_msat; - (*inner_val) -} -/// The maximum inbound HTLC value in flight towards sender, in milli-satoshi -#[no_mangle] -pub extern "C" fn OpenChannel_set_max_htlc_value_in_flight_msat(this_ptr: &mut OpenChannel, mut val: u64) { - unsafe { &mut *this_ptr.inner }.max_htlc_value_in_flight_msat = val; -} -/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel -#[no_mangle] -pub extern "C" fn OpenChannel_get_channel_reserve_satoshis(this_ptr: &OpenChannel) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_reserve_satoshis; - (*inner_val) -} -/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel -#[no_mangle] -pub extern "C" fn OpenChannel_set_channel_reserve_satoshis(this_ptr: &mut OpenChannel, mut val: u64) { - unsafe { &mut *this_ptr.inner }.channel_reserve_satoshis = val; -} -/// The minimum HTLC size incoming to sender, in milli-satoshi -#[no_mangle] -pub extern "C" fn OpenChannel_get_htlc_minimum_msat(this_ptr: &OpenChannel) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat; - (*inner_val) -} -/// The minimum HTLC size incoming to sender, in milli-satoshi -#[no_mangle] -pub extern "C" fn OpenChannel_set_htlc_minimum_msat(this_ptr: &mut OpenChannel, mut val: u64) { - unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val; -} -/// The feerate per 1000-weight of sender generated transactions, until updated by update_fee -#[no_mangle] -pub extern "C" fn OpenChannel_get_feerate_per_kw(this_ptr: &OpenChannel) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.feerate_per_kw; - (*inner_val) -} -/// The feerate per 1000-weight of sender generated transactions, until updated by update_fee -#[no_mangle] -pub extern "C" fn OpenChannel_set_feerate_per_kw(this_ptr: &mut OpenChannel, mut val: u32) { - unsafe { &mut *this_ptr.inner }.feerate_per_kw = val; -} -/// The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction -#[no_mangle] -pub extern "C" fn OpenChannel_get_to_self_delay(this_ptr: &OpenChannel) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.to_self_delay; - (*inner_val) -} -/// The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction -#[no_mangle] -pub extern "C" fn OpenChannel_set_to_self_delay(this_ptr: &mut OpenChannel, mut val: u16) { - unsafe { &mut *this_ptr.inner }.to_self_delay = val; -} -/// The maximum number of inbound HTLCs towards sender -#[no_mangle] -pub extern "C" fn OpenChannel_get_max_accepted_htlcs(this_ptr: &OpenChannel) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_accepted_htlcs; - (*inner_val) -} -/// The maximum number of inbound HTLCs towards sender -#[no_mangle] -pub extern "C" fn OpenChannel_set_max_accepted_htlcs(this_ptr: &mut OpenChannel, mut val: u16) { - unsafe { &mut *this_ptr.inner }.max_accepted_htlcs = val; -} -/// The sender's key controlling the funding transaction -#[no_mangle] -pub extern "C" fn OpenChannel_get_funding_pubkey(this_ptr: &OpenChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_pubkey; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The sender's key controlling the funding transaction -#[no_mangle] -pub extern "C" fn OpenChannel_set_funding_pubkey(this_ptr: &mut OpenChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.funding_pubkey = val.into_rust(); -} -/// Used to derive a revocation key for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn OpenChannel_get_revocation_basepoint(this_ptr: &OpenChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_basepoint; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// Used to derive a revocation key for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn OpenChannel_set_revocation_basepoint(this_ptr: &mut OpenChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.revocation_basepoint = val.into_rust(); -} -/// A payment key to sender for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn OpenChannel_get_payment_point(this_ptr: &OpenChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_point; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// A payment key to sender for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn OpenChannel_set_payment_point(this_ptr: &mut OpenChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.payment_point = val.into_rust(); -} -/// Used to derive a payment key to sender for transactions broadcast by sender -#[no_mangle] -pub extern "C" fn OpenChannel_get_delayed_payment_basepoint(this_ptr: &OpenChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// Used to derive a payment key to sender for transactions broadcast by sender -#[no_mangle] -pub extern "C" fn OpenChannel_set_delayed_payment_basepoint(this_ptr: &mut OpenChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint = val.into_rust(); -} -/// Used to derive an HTLC payment key to sender -#[no_mangle] -pub extern "C" fn OpenChannel_get_htlc_basepoint(this_ptr: &OpenChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_basepoint; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// Used to derive an HTLC payment key to sender -#[no_mangle] -pub extern "C" fn OpenChannel_set_htlc_basepoint(this_ptr: &mut OpenChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.htlc_basepoint = val.into_rust(); -} -/// The first to-be-broadcast-by-sender transaction's per commitment point -#[no_mangle] -pub extern "C" fn OpenChannel_get_first_per_commitment_point(this_ptr: &OpenChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.first_per_commitment_point; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The first to-be-broadcast-by-sender transaction's per commitment point -#[no_mangle] -pub extern "C" fn OpenChannel_set_first_per_commitment_point(this_ptr: &mut OpenChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.first_per_commitment_point = val.into_rust(); -} -/// Channel flags -#[no_mangle] -pub extern "C" fn OpenChannel_get_channel_flags(this_ptr: &OpenChannel) -> u8 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_flags; - (*inner_val) -} -/// Channel flags -#[no_mangle] -pub extern "C" fn OpenChannel_set_channel_flags(this_ptr: &mut OpenChannel, mut val: u8) { - unsafe { &mut *this_ptr.inner }.channel_flags = val; -} -impl Clone for OpenChannel { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeOpenChannel>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn OpenChannel_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeOpenChannel)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn OpenChannel_clone(orig: &OpenChannel) -> OpenChannel { - orig.clone() -} - -use lightning::ln::msgs::AcceptChannel as nativeAcceptChannelImport; -type nativeAcceptChannel = nativeAcceptChannelImport; - -/// An accept_channel message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct AcceptChannel { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeAcceptChannel, - pub is_owned: bool, -} - -impl Drop for AcceptChannel { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeAcceptChannel>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn AcceptChannel_free(this_ptr: AcceptChannel) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn AcceptChannel_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeAcceptChannel); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl AcceptChannel { - pub(crate) fn take_inner(mut self) -> *mut nativeAcceptChannel { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// A temporary channel ID, until the funding outpoint is announced -#[no_mangle] -pub extern "C" fn AcceptChannel_get_temporary_channel_id(this_ptr: &AcceptChannel) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.temporary_channel_id; - &(*inner_val) -} -/// A temporary channel ID, until the funding outpoint is announced -#[no_mangle] -pub extern "C" fn AcceptChannel_set_temporary_channel_id(this_ptr: &mut AcceptChannel, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.temporary_channel_id = val.data; -} -/// The threshold below which outputs on transactions broadcast by sender will be omitted -#[no_mangle] -pub extern "C" fn AcceptChannel_get_dust_limit_satoshis(this_ptr: &AcceptChannel) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.dust_limit_satoshis; - (*inner_val) -} -/// The threshold below which outputs on transactions broadcast by sender will be omitted -#[no_mangle] -pub extern "C" fn AcceptChannel_set_dust_limit_satoshis(this_ptr: &mut AcceptChannel, mut val: u64) { - unsafe { &mut *this_ptr.inner }.dust_limit_satoshis = val; -} -/// The maximum inbound HTLC value in flight towards sender, in milli-satoshi -#[no_mangle] -pub extern "C" fn AcceptChannel_get_max_htlc_value_in_flight_msat(this_ptr: &AcceptChannel) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_htlc_value_in_flight_msat; - (*inner_val) -} -/// The maximum inbound HTLC value in flight towards sender, in milli-satoshi -#[no_mangle] -pub extern "C" fn AcceptChannel_set_max_htlc_value_in_flight_msat(this_ptr: &mut AcceptChannel, mut val: u64) { - unsafe { &mut *this_ptr.inner }.max_htlc_value_in_flight_msat = val; -} -/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel -#[no_mangle] -pub extern "C" fn AcceptChannel_get_channel_reserve_satoshis(this_ptr: &AcceptChannel) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_reserve_satoshis; - (*inner_val) -} -/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel -#[no_mangle] -pub extern "C" fn AcceptChannel_set_channel_reserve_satoshis(this_ptr: &mut AcceptChannel, mut val: u64) { - unsafe { &mut *this_ptr.inner }.channel_reserve_satoshis = val; -} -/// The minimum HTLC size incoming to sender, in milli-satoshi -#[no_mangle] -pub extern "C" fn AcceptChannel_get_htlc_minimum_msat(this_ptr: &AcceptChannel) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat; - (*inner_val) -} -/// The minimum HTLC size incoming to sender, in milli-satoshi -#[no_mangle] -pub extern "C" fn AcceptChannel_set_htlc_minimum_msat(this_ptr: &mut AcceptChannel, mut val: u64) { - unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val; -} -/// Minimum depth of the funding transaction before the channel is considered open -#[no_mangle] -pub extern "C" fn AcceptChannel_get_minimum_depth(this_ptr: &AcceptChannel) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.minimum_depth; - (*inner_val) -} -/// Minimum depth of the funding transaction before the channel is considered open -#[no_mangle] -pub extern "C" fn AcceptChannel_set_minimum_depth(this_ptr: &mut AcceptChannel, mut val: u32) { - unsafe { &mut *this_ptr.inner }.minimum_depth = val; -} -/// The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction -#[no_mangle] -pub extern "C" fn AcceptChannel_get_to_self_delay(this_ptr: &AcceptChannel) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.to_self_delay; - (*inner_val) -} -/// The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction -#[no_mangle] -pub extern "C" fn AcceptChannel_set_to_self_delay(this_ptr: &mut AcceptChannel, mut val: u16) { - unsafe { &mut *this_ptr.inner }.to_self_delay = val; -} -/// The maximum number of inbound HTLCs towards sender -#[no_mangle] -pub extern "C" fn AcceptChannel_get_max_accepted_htlcs(this_ptr: &AcceptChannel) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_accepted_htlcs; - (*inner_val) -} -/// The maximum number of inbound HTLCs towards sender -#[no_mangle] -pub extern "C" fn AcceptChannel_set_max_accepted_htlcs(this_ptr: &mut AcceptChannel, mut val: u16) { - unsafe { &mut *this_ptr.inner }.max_accepted_htlcs = val; -} -/// The sender's key controlling the funding transaction -#[no_mangle] -pub extern "C" fn AcceptChannel_get_funding_pubkey(this_ptr: &AcceptChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_pubkey; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The sender's key controlling the funding transaction -#[no_mangle] -pub extern "C" fn AcceptChannel_set_funding_pubkey(this_ptr: &mut AcceptChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.funding_pubkey = val.into_rust(); -} -/// Used to derive a revocation key for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn AcceptChannel_get_revocation_basepoint(this_ptr: &AcceptChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_basepoint; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// Used to derive a revocation key for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn AcceptChannel_set_revocation_basepoint(this_ptr: &mut AcceptChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.revocation_basepoint = val.into_rust(); -} -/// A payment key to sender for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn AcceptChannel_get_payment_point(this_ptr: &AcceptChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_point; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// A payment key to sender for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn AcceptChannel_set_payment_point(this_ptr: &mut AcceptChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.payment_point = val.into_rust(); -} -/// Used to derive a payment key to sender for transactions broadcast by sender -#[no_mangle] -pub extern "C" fn AcceptChannel_get_delayed_payment_basepoint(this_ptr: &AcceptChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// Used to derive a payment key to sender for transactions broadcast by sender -#[no_mangle] -pub extern "C" fn AcceptChannel_set_delayed_payment_basepoint(this_ptr: &mut AcceptChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint = val.into_rust(); -} -/// Used to derive an HTLC payment key to sender for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn AcceptChannel_get_htlc_basepoint(this_ptr: &AcceptChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_basepoint; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// Used to derive an HTLC payment key to sender for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn AcceptChannel_set_htlc_basepoint(this_ptr: &mut AcceptChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.htlc_basepoint = val.into_rust(); -} -/// The first to-be-broadcast-by-sender transaction's per commitment point -#[no_mangle] -pub extern "C" fn AcceptChannel_get_first_per_commitment_point(this_ptr: &AcceptChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.first_per_commitment_point; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The first to-be-broadcast-by-sender transaction's per commitment point -#[no_mangle] -pub extern "C" fn AcceptChannel_set_first_per_commitment_point(this_ptr: &mut AcceptChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.first_per_commitment_point = val.into_rust(); -} -impl Clone for AcceptChannel { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeAcceptChannel>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn AcceptChannel_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeAcceptChannel)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn AcceptChannel_clone(orig: &AcceptChannel) -> AcceptChannel { - orig.clone() -} - -use lightning::ln::msgs::FundingCreated as nativeFundingCreatedImport; -type nativeFundingCreated = nativeFundingCreatedImport; - -/// A funding_created message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct FundingCreated { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeFundingCreated, - pub is_owned: bool, -} - -impl Drop for FundingCreated { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeFundingCreated>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn FundingCreated_free(this_ptr: FundingCreated) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn FundingCreated_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeFundingCreated); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl FundingCreated { - pub(crate) fn take_inner(mut self) -> *mut nativeFundingCreated { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// A temporary channel ID, until the funding is established -#[no_mangle] -pub extern "C" fn FundingCreated_get_temporary_channel_id(this_ptr: &FundingCreated) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.temporary_channel_id; - &(*inner_val) -} -/// A temporary channel ID, until the funding is established -#[no_mangle] -pub extern "C" fn FundingCreated_set_temporary_channel_id(this_ptr: &mut FundingCreated, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.temporary_channel_id = val.data; -} -/// The funding transaction ID -#[no_mangle] -pub extern "C" fn FundingCreated_get_funding_txid(this_ptr: &FundingCreated) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_txid; - (*inner_val).as_inner() -} -/// The funding transaction ID -#[no_mangle] -pub extern "C" fn FundingCreated_set_funding_txid(this_ptr: &mut FundingCreated, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.funding_txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap(); -} -/// The specific output index funding this channel -#[no_mangle] -pub extern "C" fn FundingCreated_get_funding_output_index(this_ptr: &FundingCreated) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_output_index; - (*inner_val) -} -/// The specific output index funding this channel -#[no_mangle] -pub extern "C" fn FundingCreated_set_funding_output_index(this_ptr: &mut FundingCreated, mut val: u16) { - unsafe { &mut *this_ptr.inner }.funding_output_index = val; -} -/// The signature of the channel initiator (funder) on the funding transaction -#[no_mangle] -pub extern "C" fn FundingCreated_get_signature(this_ptr: &FundingCreated) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.signature; - crate::c_types::Signature::from_rust(&(*inner_val)) -} -/// The signature of the channel initiator (funder) on the funding transaction -#[no_mangle] -pub extern "C" fn FundingCreated_set_signature(this_ptr: &mut FundingCreated, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.signature = val.into_rust(); -} -#[must_use] -#[no_mangle] -pub extern "C" fn FundingCreated_new(mut temporary_channel_id_arg: crate::c_types::ThirtyTwoBytes, mut funding_txid_arg: crate::c_types::ThirtyTwoBytes, mut funding_output_index_arg: u16, mut signature_arg: crate::c_types::Signature) -> FundingCreated { - FundingCreated { inner: Box::into_raw(Box::new(nativeFundingCreated { - temporary_channel_id: temporary_channel_id_arg.data, - funding_txid: ::bitcoin::hash_types::Txid::from_slice(&funding_txid_arg.data[..]).unwrap(), - funding_output_index: funding_output_index_arg, - signature: signature_arg.into_rust(), - })), is_owned: true } -} -impl Clone for FundingCreated { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeFundingCreated>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn FundingCreated_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFundingCreated)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn FundingCreated_clone(orig: &FundingCreated) -> FundingCreated { - orig.clone() -} - -use lightning::ln::msgs::FundingSigned as nativeFundingSignedImport; -type nativeFundingSigned = nativeFundingSignedImport; - -/// A funding_signed message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct FundingSigned { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeFundingSigned, - pub is_owned: bool, -} - -impl Drop for FundingSigned { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeFundingSigned>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn FundingSigned_free(this_ptr: FundingSigned) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn FundingSigned_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeFundingSigned); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl FundingSigned { - pub(crate) fn take_inner(mut self) -> *mut nativeFundingSigned { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID -#[no_mangle] -pub extern "C" fn FundingSigned_get_channel_id(this_ptr: &FundingSigned) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID -#[no_mangle] -pub extern "C" fn FundingSigned_set_channel_id(this_ptr: &mut FundingSigned, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// The signature of the channel acceptor (fundee) on the funding transaction -#[no_mangle] -pub extern "C" fn FundingSigned_get_signature(this_ptr: &FundingSigned) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.signature; - crate::c_types::Signature::from_rust(&(*inner_val)) -} -/// The signature of the channel acceptor (fundee) on the funding transaction -#[no_mangle] -pub extern "C" fn FundingSigned_set_signature(this_ptr: &mut FundingSigned, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.signature = val.into_rust(); -} -#[must_use] -#[no_mangle] -pub extern "C" fn FundingSigned_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut signature_arg: crate::c_types::Signature) -> FundingSigned { - FundingSigned { inner: Box::into_raw(Box::new(nativeFundingSigned { - channel_id: channel_id_arg.data, - signature: signature_arg.into_rust(), - })), is_owned: true } -} -impl Clone for FundingSigned { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeFundingSigned>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn FundingSigned_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFundingSigned)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn FundingSigned_clone(orig: &FundingSigned) -> FundingSigned { - orig.clone() -} - -use lightning::ln::msgs::FundingLocked as nativeFundingLockedImport; -type nativeFundingLocked = nativeFundingLockedImport; - -/// A funding_locked message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct FundingLocked { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeFundingLocked, - pub is_owned: bool, -} - -impl Drop for FundingLocked { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeFundingLocked>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn FundingLocked_free(this_ptr: FundingLocked) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn FundingLocked_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeFundingLocked); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl FundingLocked { - pub(crate) fn take_inner(mut self) -> *mut nativeFundingLocked { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID -#[no_mangle] -pub extern "C" fn FundingLocked_get_channel_id(this_ptr: &FundingLocked) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID -#[no_mangle] -pub extern "C" fn FundingLocked_set_channel_id(this_ptr: &mut FundingLocked, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// The per-commitment point of the second commitment transaction -#[no_mangle] -pub extern "C" fn FundingLocked_get_next_per_commitment_point(this_ptr: &FundingLocked) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.next_per_commitment_point; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The per-commitment point of the second commitment transaction -#[no_mangle] -pub extern "C" fn FundingLocked_set_next_per_commitment_point(this_ptr: &mut FundingLocked, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.next_per_commitment_point = val.into_rust(); -} -#[must_use] -#[no_mangle] -pub extern "C" fn FundingLocked_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut next_per_commitment_point_arg: crate::c_types::PublicKey) -> FundingLocked { - FundingLocked { inner: Box::into_raw(Box::new(nativeFundingLocked { - channel_id: channel_id_arg.data, - next_per_commitment_point: next_per_commitment_point_arg.into_rust(), - })), is_owned: true } -} -impl Clone for FundingLocked { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeFundingLocked>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn FundingLocked_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFundingLocked)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn FundingLocked_clone(orig: &FundingLocked) -> FundingLocked { - orig.clone() -} - -use lightning::ln::msgs::Shutdown as nativeShutdownImport; -type nativeShutdown = nativeShutdownImport; - -/// A shutdown message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct Shutdown { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeShutdown, - pub is_owned: bool, -} - -impl Drop for Shutdown { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeShutdown>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn Shutdown_free(this_ptr: Shutdown) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn Shutdown_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeShutdown); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl Shutdown { - pub(crate) fn take_inner(mut self) -> *mut nativeShutdown { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID -#[no_mangle] -pub extern "C" fn Shutdown_get_channel_id(this_ptr: &Shutdown) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID -#[no_mangle] -pub extern "C" fn Shutdown_set_channel_id(this_ptr: &mut Shutdown, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// The destination of this peer's funds on closing. -/// Must be in one of these forms: p2pkh, p2sh, p2wpkh, p2wsh. -#[no_mangle] -pub extern "C" fn Shutdown_get_scriptpubkey(this_ptr: &Shutdown) -> crate::c_types::u8slice { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.scriptpubkey; - crate::c_types::u8slice::from_slice(&(*inner_val)[..]) -} -/// The destination of this peer's funds on closing. -/// Must be in one of these forms: p2pkh, p2sh, p2wpkh, p2wsh. -#[no_mangle] -pub extern "C" fn Shutdown_set_scriptpubkey(this_ptr: &mut Shutdown, mut val: crate::c_types::derived::CVec_u8Z) { - unsafe { &mut *this_ptr.inner }.scriptpubkey = ::bitcoin::blockdata::script::Script::from(val.into_rust()); -} -#[must_use] -#[no_mangle] -pub extern "C" fn Shutdown_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut scriptpubkey_arg: crate::c_types::derived::CVec_u8Z) -> Shutdown { - Shutdown { inner: Box::into_raw(Box::new(nativeShutdown { - channel_id: channel_id_arg.data, - scriptpubkey: ::bitcoin::blockdata::script::Script::from(scriptpubkey_arg.into_rust()), - })), is_owned: true } -} -impl Clone for Shutdown { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeShutdown>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn Shutdown_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeShutdown)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn Shutdown_clone(orig: &Shutdown) -> Shutdown { - orig.clone() -} - -use lightning::ln::msgs::ClosingSigned as nativeClosingSignedImport; -type nativeClosingSigned = nativeClosingSignedImport; - -/// A closing_signed message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct ClosingSigned { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeClosingSigned, - pub is_owned: bool, -} - -impl Drop for ClosingSigned { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeClosingSigned>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ClosingSigned_free(this_ptr: ClosingSigned) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ClosingSigned_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeClosingSigned); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ClosingSigned { - pub(crate) fn take_inner(mut self) -> *mut nativeClosingSigned { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID -#[no_mangle] -pub extern "C" fn ClosingSigned_get_channel_id(this_ptr: &ClosingSigned) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID -#[no_mangle] -pub extern "C" fn ClosingSigned_set_channel_id(this_ptr: &mut ClosingSigned, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// The proposed total fee for the closing transaction -#[no_mangle] -pub extern "C" fn ClosingSigned_get_fee_satoshis(this_ptr: &ClosingSigned) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_satoshis; - (*inner_val) -} -/// The proposed total fee for the closing transaction -#[no_mangle] -pub extern "C" fn ClosingSigned_set_fee_satoshis(this_ptr: &mut ClosingSigned, mut val: u64) { - unsafe { &mut *this_ptr.inner }.fee_satoshis = val; -} -/// A signature on the closing transaction -#[no_mangle] -pub extern "C" fn ClosingSigned_get_signature(this_ptr: &ClosingSigned) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.signature; - crate::c_types::Signature::from_rust(&(*inner_val)) -} -/// A signature on the closing transaction -#[no_mangle] -pub extern "C" fn ClosingSigned_set_signature(this_ptr: &mut ClosingSigned, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.signature = val.into_rust(); -} -#[must_use] -#[no_mangle] -pub extern "C" fn ClosingSigned_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut fee_satoshis_arg: u64, mut signature_arg: crate::c_types::Signature) -> ClosingSigned { - ClosingSigned { inner: Box::into_raw(Box::new(nativeClosingSigned { - channel_id: channel_id_arg.data, - fee_satoshis: fee_satoshis_arg, - signature: signature_arg.into_rust(), - })), is_owned: true } -} -impl Clone for ClosingSigned { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeClosingSigned>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ClosingSigned_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeClosingSigned)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ClosingSigned_clone(orig: &ClosingSigned) -> ClosingSigned { - orig.clone() -} - -use lightning::ln::msgs::UpdateAddHTLC as nativeUpdateAddHTLCImport; -type nativeUpdateAddHTLC = nativeUpdateAddHTLCImport; - -/// An update_add_htlc message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct UpdateAddHTLC { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeUpdateAddHTLC, - pub is_owned: bool, -} - -impl Drop for UpdateAddHTLC { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeUpdateAddHTLC>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_free(this_ptr: UpdateAddHTLC) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn UpdateAddHTLC_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUpdateAddHTLC); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl UpdateAddHTLC { - pub(crate) fn take_inner(mut self) -> *mut nativeUpdateAddHTLC { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_get_channel_id(this_ptr: &UpdateAddHTLC) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_set_channel_id(this_ptr: &mut UpdateAddHTLC, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// The HTLC ID -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_get_htlc_id(this_ptr: &UpdateAddHTLC) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_id; - (*inner_val) -} -/// The HTLC ID -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_set_htlc_id(this_ptr: &mut UpdateAddHTLC, mut val: u64) { - unsafe { &mut *this_ptr.inner }.htlc_id = val; -} -/// The HTLC value in milli-satoshi -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_get_amount_msat(this_ptr: &UpdateAddHTLC) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.amount_msat; - (*inner_val) -} -/// The HTLC value in milli-satoshi -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_set_amount_msat(this_ptr: &mut UpdateAddHTLC, mut val: u64) { - unsafe { &mut *this_ptr.inner }.amount_msat = val; -} -/// The payment hash, the pre-image of which controls HTLC redemption -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_get_payment_hash(this_ptr: &UpdateAddHTLC) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_hash; - &(*inner_val).0 -} -/// The payment hash, the pre-image of which controls HTLC redemption -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_set_payment_hash(this_ptr: &mut UpdateAddHTLC, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.payment_hash = ::lightning::ln::channelmanager::PaymentHash(val.data); -} -/// The expiry height of the HTLC -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_get_cltv_expiry(this_ptr: &UpdateAddHTLC) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry; - (*inner_val) -} -/// The expiry height of the HTLC -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_set_cltv_expiry(this_ptr: &mut UpdateAddHTLC, mut val: u32) { - unsafe { &mut *this_ptr.inner }.cltv_expiry = val; -} -impl Clone for UpdateAddHTLC { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeUpdateAddHTLC>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn UpdateAddHTLC_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateAddHTLC)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_clone(orig: &UpdateAddHTLC) -> UpdateAddHTLC { - orig.clone() -} - -use lightning::ln::msgs::UpdateFulfillHTLC as nativeUpdateFulfillHTLCImport; -type nativeUpdateFulfillHTLC = nativeUpdateFulfillHTLCImport; - -/// An update_fulfill_htlc message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct UpdateFulfillHTLC { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeUpdateFulfillHTLC, - pub is_owned: bool, -} - -impl Drop for UpdateFulfillHTLC { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeUpdateFulfillHTLC>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_free(this_ptr: UpdateFulfillHTLC) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn UpdateFulfillHTLC_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUpdateFulfillHTLC); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl UpdateFulfillHTLC { - pub(crate) fn take_inner(mut self) -> *mut nativeUpdateFulfillHTLC { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID -#[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_get_channel_id(this_ptr: &UpdateFulfillHTLC) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID -#[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_set_channel_id(this_ptr: &mut UpdateFulfillHTLC, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// The HTLC ID -#[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_get_htlc_id(this_ptr: &UpdateFulfillHTLC) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_id; - (*inner_val) -} -/// The HTLC ID -#[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_set_htlc_id(this_ptr: &mut UpdateFulfillHTLC, mut val: u64) { - unsafe { &mut *this_ptr.inner }.htlc_id = val; -} -/// The pre-image of the payment hash, allowing HTLC redemption -#[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_get_payment_preimage(this_ptr: &UpdateFulfillHTLC) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_preimage; - &(*inner_val).0 -} -/// The pre-image of the payment hash, allowing HTLC redemption -#[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_set_payment_preimage(this_ptr: &mut UpdateFulfillHTLC, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.payment_preimage = ::lightning::ln::channelmanager::PaymentPreimage(val.data); -} -#[must_use] -#[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut htlc_id_arg: u64, mut payment_preimage_arg: crate::c_types::ThirtyTwoBytes) -> UpdateFulfillHTLC { - UpdateFulfillHTLC { inner: Box::into_raw(Box::new(nativeUpdateFulfillHTLC { - channel_id: channel_id_arg.data, - htlc_id: htlc_id_arg, - payment_preimage: ::lightning::ln::channelmanager::PaymentPreimage(payment_preimage_arg.data), - })), is_owned: true } -} -impl Clone for UpdateFulfillHTLC { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeUpdateFulfillHTLC>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn UpdateFulfillHTLC_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateFulfillHTLC)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_clone(orig: &UpdateFulfillHTLC) -> UpdateFulfillHTLC { - orig.clone() -} - -use lightning::ln::msgs::UpdateFailHTLC as nativeUpdateFailHTLCImport; -type nativeUpdateFailHTLC = nativeUpdateFailHTLCImport; - -/// An update_fail_htlc message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct UpdateFailHTLC { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeUpdateFailHTLC, - pub is_owned: bool, -} - -impl Drop for UpdateFailHTLC { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeUpdateFailHTLC>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn UpdateFailHTLC_free(this_ptr: UpdateFailHTLC) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn UpdateFailHTLC_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUpdateFailHTLC); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl UpdateFailHTLC { - pub(crate) fn take_inner(mut self) -> *mut nativeUpdateFailHTLC { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID -#[no_mangle] -pub extern "C" fn UpdateFailHTLC_get_channel_id(this_ptr: &UpdateFailHTLC) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID -#[no_mangle] -pub extern "C" fn UpdateFailHTLC_set_channel_id(this_ptr: &mut UpdateFailHTLC, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// The HTLC ID -#[no_mangle] -pub extern "C" fn UpdateFailHTLC_get_htlc_id(this_ptr: &UpdateFailHTLC) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_id; - (*inner_val) -} -/// The HTLC ID -#[no_mangle] -pub extern "C" fn UpdateFailHTLC_set_htlc_id(this_ptr: &mut UpdateFailHTLC, mut val: u64) { - unsafe { &mut *this_ptr.inner }.htlc_id = val; -} -impl Clone for UpdateFailHTLC { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeUpdateFailHTLC>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn UpdateFailHTLC_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateFailHTLC)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn UpdateFailHTLC_clone(orig: &UpdateFailHTLC) -> UpdateFailHTLC { - orig.clone() -} - -use lightning::ln::msgs::UpdateFailMalformedHTLC as nativeUpdateFailMalformedHTLCImport; -type nativeUpdateFailMalformedHTLC = nativeUpdateFailMalformedHTLCImport; - -/// An update_fail_malformed_htlc message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct UpdateFailMalformedHTLC { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeUpdateFailMalformedHTLC, - pub is_owned: bool, -} - -impl Drop for UpdateFailMalformedHTLC { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeUpdateFailMalformedHTLC>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn UpdateFailMalformedHTLC_free(this_ptr: UpdateFailMalformedHTLC) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn UpdateFailMalformedHTLC_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUpdateFailMalformedHTLC); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl UpdateFailMalformedHTLC { - pub(crate) fn take_inner(mut self) -> *mut nativeUpdateFailMalformedHTLC { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID -#[no_mangle] -pub extern "C" fn UpdateFailMalformedHTLC_get_channel_id(this_ptr: &UpdateFailMalformedHTLC) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID -#[no_mangle] -pub extern "C" fn UpdateFailMalformedHTLC_set_channel_id(this_ptr: &mut UpdateFailMalformedHTLC, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// The HTLC ID -#[no_mangle] -pub extern "C" fn UpdateFailMalformedHTLC_get_htlc_id(this_ptr: &UpdateFailMalformedHTLC) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_id; - (*inner_val) -} -/// The HTLC ID -#[no_mangle] -pub extern "C" fn UpdateFailMalformedHTLC_set_htlc_id(this_ptr: &mut UpdateFailMalformedHTLC, mut val: u64) { - unsafe { &mut *this_ptr.inner }.htlc_id = val; -} -/// The failure code -#[no_mangle] -pub extern "C" fn UpdateFailMalformedHTLC_get_failure_code(this_ptr: &UpdateFailMalformedHTLC) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.failure_code; - (*inner_val) -} -/// The failure code -#[no_mangle] -pub extern "C" fn UpdateFailMalformedHTLC_set_failure_code(this_ptr: &mut UpdateFailMalformedHTLC, mut val: u16) { - unsafe { &mut *this_ptr.inner }.failure_code = val; -} -impl Clone for UpdateFailMalformedHTLC { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeUpdateFailMalformedHTLC>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn UpdateFailMalformedHTLC_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateFailMalformedHTLC)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn UpdateFailMalformedHTLC_clone(orig: &UpdateFailMalformedHTLC) -> UpdateFailMalformedHTLC { - orig.clone() -} - -use lightning::ln::msgs::CommitmentSigned as nativeCommitmentSignedImport; -type nativeCommitmentSigned = nativeCommitmentSignedImport; - -/// A commitment_signed message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct CommitmentSigned { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeCommitmentSigned, - pub is_owned: bool, -} - -impl Drop for CommitmentSigned { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeCommitmentSigned>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn CommitmentSigned_free(this_ptr: CommitmentSigned) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn CommitmentSigned_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCommitmentSigned); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl CommitmentSigned { - pub(crate) fn take_inner(mut self) -> *mut nativeCommitmentSigned { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID -#[no_mangle] -pub extern "C" fn CommitmentSigned_get_channel_id(this_ptr: &CommitmentSigned) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID -#[no_mangle] -pub extern "C" fn CommitmentSigned_set_channel_id(this_ptr: &mut CommitmentSigned, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// A signature on the commitment transaction -#[no_mangle] -pub extern "C" fn CommitmentSigned_get_signature(this_ptr: &CommitmentSigned) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.signature; - crate::c_types::Signature::from_rust(&(*inner_val)) -} -/// A signature on the commitment transaction -#[no_mangle] -pub extern "C" fn CommitmentSigned_set_signature(this_ptr: &mut CommitmentSigned, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.signature = val.into_rust(); -} -/// Signatures on the HTLC transactions -#[no_mangle] -pub extern "C" fn CommitmentSigned_set_htlc_signatures(this_ptr: &mut CommitmentSigned, mut val: crate::c_types::derived::CVec_SignatureZ) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_rust() }); }; - unsafe { &mut *this_ptr.inner }.htlc_signatures = local_val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn CommitmentSigned_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut signature_arg: crate::c_types::Signature, mut htlc_signatures_arg: crate::c_types::derived::CVec_SignatureZ) -> CommitmentSigned { - let mut local_htlc_signatures_arg = Vec::new(); for mut item in htlc_signatures_arg.into_rust().drain(..) { local_htlc_signatures_arg.push( { item.into_rust() }); }; - CommitmentSigned { inner: Box::into_raw(Box::new(nativeCommitmentSigned { - channel_id: channel_id_arg.data, - signature: signature_arg.into_rust(), - htlc_signatures: local_htlc_signatures_arg, - })), is_owned: true } -} -impl Clone for CommitmentSigned { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeCommitmentSigned>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn CommitmentSigned_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentSigned)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn CommitmentSigned_clone(orig: &CommitmentSigned) -> CommitmentSigned { - orig.clone() -} - -use lightning::ln::msgs::RevokeAndACK as nativeRevokeAndACKImport; -type nativeRevokeAndACK = nativeRevokeAndACKImport; - -/// A revoke_and_ack message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct RevokeAndACK { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeRevokeAndACK, - pub is_owned: bool, -} - -impl Drop for RevokeAndACK { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeRevokeAndACK>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn RevokeAndACK_free(this_ptr: RevokeAndACK) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn RevokeAndACK_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRevokeAndACK); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl RevokeAndACK { - pub(crate) fn take_inner(mut self) -> *mut nativeRevokeAndACK { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID -#[no_mangle] -pub extern "C" fn RevokeAndACK_get_channel_id(this_ptr: &RevokeAndACK) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID -#[no_mangle] -pub extern "C" fn RevokeAndACK_set_channel_id(this_ptr: &mut RevokeAndACK, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// The secret corresponding to the per-commitment point -#[no_mangle] -pub extern "C" fn RevokeAndACK_get_per_commitment_secret(this_ptr: &RevokeAndACK) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.per_commitment_secret; - &(*inner_val) -} -/// The secret corresponding to the per-commitment point -#[no_mangle] -pub extern "C" fn RevokeAndACK_set_per_commitment_secret(this_ptr: &mut RevokeAndACK, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.per_commitment_secret = val.data; -} -/// The next sender-broadcast commitment transaction's per-commitment point -#[no_mangle] -pub extern "C" fn RevokeAndACK_get_next_per_commitment_point(this_ptr: &RevokeAndACK) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.next_per_commitment_point; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The next sender-broadcast commitment transaction's per-commitment point -#[no_mangle] -pub extern "C" fn RevokeAndACK_set_next_per_commitment_point(this_ptr: &mut RevokeAndACK, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.next_per_commitment_point = val.into_rust(); -} -#[must_use] -#[no_mangle] -pub extern "C" fn RevokeAndACK_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut per_commitment_secret_arg: crate::c_types::ThirtyTwoBytes, mut next_per_commitment_point_arg: crate::c_types::PublicKey) -> RevokeAndACK { - RevokeAndACK { inner: Box::into_raw(Box::new(nativeRevokeAndACK { - channel_id: channel_id_arg.data, - per_commitment_secret: per_commitment_secret_arg.data, - next_per_commitment_point: next_per_commitment_point_arg.into_rust(), - })), is_owned: true } -} -impl Clone for RevokeAndACK { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeRevokeAndACK>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn RevokeAndACK_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRevokeAndACK)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn RevokeAndACK_clone(orig: &RevokeAndACK) -> RevokeAndACK { - orig.clone() -} - -use lightning::ln::msgs::UpdateFee as nativeUpdateFeeImport; -type nativeUpdateFee = nativeUpdateFeeImport; - -/// An update_fee message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct UpdateFee { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeUpdateFee, - pub is_owned: bool, -} - -impl Drop for UpdateFee { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeUpdateFee>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn UpdateFee_free(this_ptr: UpdateFee) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn UpdateFee_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUpdateFee); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl UpdateFee { - pub(crate) fn take_inner(mut self) -> *mut nativeUpdateFee { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID -#[no_mangle] -pub extern "C" fn UpdateFee_get_channel_id(this_ptr: &UpdateFee) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID -#[no_mangle] -pub extern "C" fn UpdateFee_set_channel_id(this_ptr: &mut UpdateFee, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// Fee rate per 1000-weight of the transaction -#[no_mangle] -pub extern "C" fn UpdateFee_get_feerate_per_kw(this_ptr: &UpdateFee) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.feerate_per_kw; - (*inner_val) -} -/// Fee rate per 1000-weight of the transaction -#[no_mangle] -pub extern "C" fn UpdateFee_set_feerate_per_kw(this_ptr: &mut UpdateFee, mut val: u32) { - unsafe { &mut *this_ptr.inner }.feerate_per_kw = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn UpdateFee_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut feerate_per_kw_arg: u32) -> UpdateFee { - UpdateFee { inner: Box::into_raw(Box::new(nativeUpdateFee { - channel_id: channel_id_arg.data, - feerate_per_kw: feerate_per_kw_arg, - })), is_owned: true } -} -impl Clone for UpdateFee { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeUpdateFee>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn UpdateFee_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateFee)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn UpdateFee_clone(orig: &UpdateFee) -> UpdateFee { - orig.clone() -} - -use lightning::ln::msgs::DataLossProtect as nativeDataLossProtectImport; -type nativeDataLossProtect = nativeDataLossProtectImport; - -/// Proof that the sender knows the per-commitment secret of the previous commitment transaction. -/// This is used to convince the recipient that the channel is at a certain commitment -/// number even if they lost that data due to a local failure. Of course, the peer may lie -/// and even later commitments may have been revoked. -#[must_use] -#[repr(C)] -pub struct DataLossProtect { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeDataLossProtect, - pub is_owned: bool, -} - -impl Drop for DataLossProtect { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeDataLossProtect>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn DataLossProtect_free(this_ptr: DataLossProtect) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn DataLossProtect_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDataLossProtect); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl DataLossProtect { - pub(crate) fn take_inner(mut self) -> *mut nativeDataLossProtect { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Proof that the sender knows the per-commitment secret of a specific commitment transaction -/// belonging to the recipient -#[no_mangle] -pub extern "C" fn DataLossProtect_get_your_last_per_commitment_secret(this_ptr: &DataLossProtect) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.your_last_per_commitment_secret; - &(*inner_val) -} -/// Proof that the sender knows the per-commitment secret of a specific commitment transaction -/// belonging to the recipient -#[no_mangle] -pub extern "C" fn DataLossProtect_set_your_last_per_commitment_secret(this_ptr: &mut DataLossProtect, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.your_last_per_commitment_secret = val.data; -} -/// The sender's per-commitment point for their current commitment transaction -#[no_mangle] -pub extern "C" fn DataLossProtect_get_my_current_per_commitment_point(this_ptr: &DataLossProtect) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.my_current_per_commitment_point; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The sender's per-commitment point for their current commitment transaction -#[no_mangle] -pub extern "C" fn DataLossProtect_set_my_current_per_commitment_point(this_ptr: &mut DataLossProtect, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.my_current_per_commitment_point = val.into_rust(); -} -#[must_use] -#[no_mangle] -pub extern "C" fn DataLossProtect_new(mut your_last_per_commitment_secret_arg: crate::c_types::ThirtyTwoBytes, mut my_current_per_commitment_point_arg: crate::c_types::PublicKey) -> DataLossProtect { - DataLossProtect { inner: Box::into_raw(Box::new(nativeDataLossProtect { - your_last_per_commitment_secret: your_last_per_commitment_secret_arg.data, - my_current_per_commitment_point: my_current_per_commitment_point_arg.into_rust(), - })), is_owned: true } -} -impl Clone for DataLossProtect { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeDataLossProtect>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn DataLossProtect_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDataLossProtect)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn DataLossProtect_clone(orig: &DataLossProtect) -> DataLossProtect { - orig.clone() -} - -use lightning::ln::msgs::ChannelReestablish as nativeChannelReestablishImport; -type nativeChannelReestablish = nativeChannelReestablishImport; - -/// A channel_reestablish message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct ChannelReestablish { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelReestablish, - pub is_owned: bool, -} - -impl Drop for ChannelReestablish { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelReestablish>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelReestablish_free(this_ptr: ChannelReestablish) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelReestablish_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelReestablish); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelReestablish { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelReestablish { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID -#[no_mangle] -pub extern "C" fn ChannelReestablish_get_channel_id(this_ptr: &ChannelReestablish) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID -#[no_mangle] -pub extern "C" fn ChannelReestablish_set_channel_id(this_ptr: &mut ChannelReestablish, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// The next commitment number for the sender -#[no_mangle] -pub extern "C" fn ChannelReestablish_get_next_local_commitment_number(this_ptr: &ChannelReestablish) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.next_local_commitment_number; - (*inner_val) -} -/// The next commitment number for the sender -#[no_mangle] -pub extern "C" fn ChannelReestablish_set_next_local_commitment_number(this_ptr: &mut ChannelReestablish, mut val: u64) { - unsafe { &mut *this_ptr.inner }.next_local_commitment_number = val; -} -/// The next commitment number for the recipient -#[no_mangle] -pub extern "C" fn ChannelReestablish_get_next_remote_commitment_number(this_ptr: &ChannelReestablish) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.next_remote_commitment_number; - (*inner_val) -} -/// The next commitment number for the recipient -#[no_mangle] -pub extern "C" fn ChannelReestablish_set_next_remote_commitment_number(this_ptr: &mut ChannelReestablish, mut val: u64) { - unsafe { &mut *this_ptr.inner }.next_remote_commitment_number = val; -} -impl Clone for ChannelReestablish { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeChannelReestablish>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelReestablish_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelReestablish)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ChannelReestablish_clone(orig: &ChannelReestablish) -> ChannelReestablish { - orig.clone() -} - -use lightning::ln::msgs::AnnouncementSignatures as nativeAnnouncementSignaturesImport; -type nativeAnnouncementSignatures = nativeAnnouncementSignaturesImport; - -/// An announcement_signatures message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct AnnouncementSignatures { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeAnnouncementSignatures, - pub is_owned: bool, -} - -impl Drop for AnnouncementSignatures { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeAnnouncementSignatures>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn AnnouncementSignatures_free(this_ptr: AnnouncementSignatures) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn AnnouncementSignatures_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeAnnouncementSignatures); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl AnnouncementSignatures { - pub(crate) fn take_inner(mut self) -> *mut nativeAnnouncementSignatures { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The channel ID -#[no_mangle] -pub extern "C" fn AnnouncementSignatures_get_channel_id(this_ptr: &AnnouncementSignatures) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_id; - &(*inner_val) -} -/// The channel ID -#[no_mangle] -pub extern "C" fn AnnouncementSignatures_set_channel_id(this_ptr: &mut AnnouncementSignatures, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.channel_id = val.data; -} -/// The short channel ID -#[no_mangle] -pub extern "C" fn AnnouncementSignatures_get_short_channel_id(this_ptr: &AnnouncementSignatures) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.short_channel_id; - (*inner_val) -} -/// The short channel ID -#[no_mangle] -pub extern "C" fn AnnouncementSignatures_set_short_channel_id(this_ptr: &mut AnnouncementSignatures, mut val: u64) { - unsafe { &mut *this_ptr.inner }.short_channel_id = val; -} -/// A signature by the node key -#[no_mangle] -pub extern "C" fn AnnouncementSignatures_get_node_signature(this_ptr: &AnnouncementSignatures) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_signature; - crate::c_types::Signature::from_rust(&(*inner_val)) -} -/// A signature by the node key -#[no_mangle] -pub extern "C" fn AnnouncementSignatures_set_node_signature(this_ptr: &mut AnnouncementSignatures, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.node_signature = val.into_rust(); -} -/// A signature by the funding key -#[no_mangle] -pub extern "C" fn AnnouncementSignatures_get_bitcoin_signature(this_ptr: &AnnouncementSignatures) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.bitcoin_signature; - crate::c_types::Signature::from_rust(&(*inner_val)) -} -/// A signature by the funding key -#[no_mangle] -pub extern "C" fn AnnouncementSignatures_set_bitcoin_signature(this_ptr: &mut AnnouncementSignatures, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.bitcoin_signature = val.into_rust(); -} -#[must_use] -#[no_mangle] -pub extern "C" fn AnnouncementSignatures_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut short_channel_id_arg: u64, mut node_signature_arg: crate::c_types::Signature, mut bitcoin_signature_arg: crate::c_types::Signature) -> AnnouncementSignatures { - AnnouncementSignatures { inner: Box::into_raw(Box::new(nativeAnnouncementSignatures { - channel_id: channel_id_arg.data, - short_channel_id: short_channel_id_arg, - node_signature: node_signature_arg.into_rust(), - bitcoin_signature: bitcoin_signature_arg.into_rust(), - })), is_owned: true } -} -impl Clone for AnnouncementSignatures { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeAnnouncementSignatures>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn AnnouncementSignatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeAnnouncementSignatures)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn AnnouncementSignatures_clone(orig: &AnnouncementSignatures) -> AnnouncementSignatures { - orig.clone() -} -/// An address which can be used to connect to a remote peer -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum NetAddress { - /// An IPv4 address/port on which the peer is listening. - IPv4 { - addr: crate::c_types::FourBytes, - port: u16, - }, - /// An IPv6 address/port on which the peer is listening. - IPv6 { - addr: crate::c_types::SixteenBytes, - port: u16, - }, - /// An old-style Tor onion address/port on which the peer is listening. - OnionV2 { - addr: crate::c_types::TenBytes, - port: u16, - }, - /// A new-style Tor onion address/port on which the peer is listening. - /// To create the human-readable \"hostname\", concatenate ed25519_pubkey, checksum, and version, - /// wrap as base32 and append \".onion\". - OnionV3 { - ed25519_pubkey: crate::c_types::ThirtyTwoBytes, - checksum: u16, - version: u8, - port: u16, - }, -} -use lightning::ln::msgs::NetAddress as nativeNetAddress; -impl NetAddress { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeNetAddress { - match self { - NetAddress::IPv4 {ref addr, ref port, } => { - let mut addr_nonref = (*addr).clone(); - let mut port_nonref = (*port).clone(); - nativeNetAddress::IPv4 { - addr: addr_nonref.data, - port: port_nonref, - } - }, - NetAddress::IPv6 {ref addr, ref port, } => { - let mut addr_nonref = (*addr).clone(); - let mut port_nonref = (*port).clone(); - nativeNetAddress::IPv6 { - addr: addr_nonref.data, - port: port_nonref, - } - }, - NetAddress::OnionV2 {ref addr, ref port, } => { - let mut addr_nonref = (*addr).clone(); - let mut port_nonref = (*port).clone(); - nativeNetAddress::OnionV2 { - addr: addr_nonref.data, - port: port_nonref, - } - }, - NetAddress::OnionV3 {ref ed25519_pubkey, ref checksum, ref version, ref port, } => { - let mut ed25519_pubkey_nonref = (*ed25519_pubkey).clone(); - let mut checksum_nonref = (*checksum).clone(); - let mut version_nonref = (*version).clone(); - let mut port_nonref = (*port).clone(); - nativeNetAddress::OnionV3 { - ed25519_pubkey: ed25519_pubkey_nonref.data, - checksum: checksum_nonref, - version: version_nonref, - port: port_nonref, - } - }, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativeNetAddress { - match self { - NetAddress::IPv4 {mut addr, mut port, } => { - nativeNetAddress::IPv4 { - addr: addr.data, - port: port, - } - }, - NetAddress::IPv6 {mut addr, mut port, } => { - nativeNetAddress::IPv6 { - addr: addr.data, - port: port, - } - }, - NetAddress::OnionV2 {mut addr, mut port, } => { - nativeNetAddress::OnionV2 { - addr: addr.data, - port: port, - } - }, - NetAddress::OnionV3 {mut ed25519_pubkey, mut checksum, mut version, mut port, } => { - nativeNetAddress::OnionV3 { - ed25519_pubkey: ed25519_pubkey.data, - checksum: checksum, - version: version, - port: port, - } - }, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativeNetAddress) -> Self { - match native { - nativeNetAddress::IPv4 {ref addr, ref port, } => { - let mut addr_nonref = (*addr).clone(); - let mut port_nonref = (*port).clone(); - NetAddress::IPv4 { - addr: crate::c_types::FourBytes { data: addr_nonref }, - port: port_nonref, - } - }, - nativeNetAddress::IPv6 {ref addr, ref port, } => { - let mut addr_nonref = (*addr).clone(); - let mut port_nonref = (*port).clone(); - NetAddress::IPv6 { - addr: crate::c_types::SixteenBytes { data: addr_nonref }, - port: port_nonref, - } - }, - nativeNetAddress::OnionV2 {ref addr, ref port, } => { - let mut addr_nonref = (*addr).clone(); - let mut port_nonref = (*port).clone(); - NetAddress::OnionV2 { - addr: crate::c_types::TenBytes { data: addr_nonref }, - port: port_nonref, - } - }, - nativeNetAddress::OnionV3 {ref ed25519_pubkey, ref checksum, ref version, ref port, } => { - let mut ed25519_pubkey_nonref = (*ed25519_pubkey).clone(); - let mut checksum_nonref = (*checksum).clone(); - let mut version_nonref = (*version).clone(); - let mut port_nonref = (*port).clone(); - NetAddress::OnionV3 { - ed25519_pubkey: crate::c_types::ThirtyTwoBytes { data: ed25519_pubkey_nonref }, - checksum: checksum_nonref, - version: version_nonref, - port: port_nonref, - } - }, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativeNetAddress) -> Self { - match native { - nativeNetAddress::IPv4 {mut addr, mut port, } => { - NetAddress::IPv4 { - addr: crate::c_types::FourBytes { data: addr }, - port: port, - } - }, - nativeNetAddress::IPv6 {mut addr, mut port, } => { - NetAddress::IPv6 { - addr: crate::c_types::SixteenBytes { data: addr }, - port: port, - } - }, - nativeNetAddress::OnionV2 {mut addr, mut port, } => { - NetAddress::OnionV2 { - addr: crate::c_types::TenBytes { data: addr }, - port: port, - } - }, - nativeNetAddress::OnionV3 {mut ed25519_pubkey, mut checksum, mut version, mut port, } => { - NetAddress::OnionV3 { - ed25519_pubkey: crate::c_types::ThirtyTwoBytes { data: ed25519_pubkey }, - checksum: checksum, - version: version, - port: port, - } - }, - } - } -} -#[no_mangle] -pub extern "C" fn NetAddress_free(this_ptr: NetAddress) { } -#[no_mangle] -pub extern "C" fn NetAddress_clone(orig: &NetAddress) -> NetAddress { - orig.clone() -} -#[no_mangle] -pub extern "C" fn NetAddress_write(obj: &NetAddress) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) -} -#[no_mangle] -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 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 -} - -use lightning::ln::msgs::UnsignedNodeAnnouncement as nativeUnsignedNodeAnnouncementImport; -type nativeUnsignedNodeAnnouncement = nativeUnsignedNodeAnnouncementImport; - -/// The unsigned part of a node_announcement -#[must_use] -#[repr(C)] -pub struct UnsignedNodeAnnouncement { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeUnsignedNodeAnnouncement, - pub is_owned: bool, -} - -impl Drop for UnsignedNodeAnnouncement { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeUnsignedNodeAnnouncement>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_free(this_ptr: UnsignedNodeAnnouncement) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn UnsignedNodeAnnouncement_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUnsignedNodeAnnouncement); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl UnsignedNodeAnnouncement { - pub(crate) fn take_inner(mut self) -> *mut nativeUnsignedNodeAnnouncement { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The advertised features -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_get_features(this_ptr: &UnsignedNodeAnnouncement) -> crate::ln::features::NodeFeatures { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features; - crate::ln::features::NodeFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// The advertised features -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_set_features(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::ln::features::NodeFeatures) { - unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// A strictly monotonic announcement counter, with gaps allowed -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_get_timestamp(this_ptr: &UnsignedNodeAnnouncement) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.timestamp; - (*inner_val) -} -/// A strictly monotonic announcement counter, with gaps allowed -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_set_timestamp(this_ptr: &mut UnsignedNodeAnnouncement, mut val: u32) { - unsafe { &mut *this_ptr.inner }.timestamp = val; -} -/// The node_id this announcement originated from (don't rebroadcast the node_announcement back -/// to this node). -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_get_node_id(this_ptr: &UnsignedNodeAnnouncement) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_id; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The node_id this announcement originated from (don't rebroadcast the node_announcement back -/// to this node). -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_set_node_id(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.node_id = val.into_rust(); -} -/// An RGB color for UI purposes -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_get_rgb(this_ptr: &UnsignedNodeAnnouncement) -> *const [u8; 3] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.rgb; - &(*inner_val) -} -/// An RGB color for UI purposes -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_set_rgb(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::c_types::ThreeBytes) { - unsafe { &mut *this_ptr.inner }.rgb = val.data; -} -/// An alias, for UI purposes. This should be sanitized before use. There is no guarantee -/// of uniqueness. -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_get_alias(this_ptr: &UnsignedNodeAnnouncement) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.alias; - &(*inner_val) -} -/// An alias, for UI purposes. This should be sanitized before use. There is no guarantee -/// of uniqueness. -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_set_alias(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.alias = val.data; -} -/// List of addresses on which this node is reachable -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_set_addresses(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::c_types::derived::CVec_NetAddressZ) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); }; - unsafe { &mut *this_ptr.inner }.addresses = local_val; -} -impl Clone for UnsignedNodeAnnouncement { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeUnsignedNodeAnnouncement>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn UnsignedNodeAnnouncement_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUnsignedNodeAnnouncement)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_clone(orig: &UnsignedNodeAnnouncement) -> UnsignedNodeAnnouncement { - orig.clone() -} - -use lightning::ln::msgs::NodeAnnouncement as nativeNodeAnnouncementImport; -type nativeNodeAnnouncement = nativeNodeAnnouncementImport; - -/// A node_announcement message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct NodeAnnouncement { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeNodeAnnouncement, - pub is_owned: bool, -} - -impl Drop for NodeAnnouncement { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeNodeAnnouncement>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn NodeAnnouncement_free(this_ptr: NodeAnnouncement) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn NodeAnnouncement_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncement); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl NodeAnnouncement { - pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncement { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The signature by the node key -#[no_mangle] -pub extern "C" fn NodeAnnouncement_get_signature(this_ptr: &NodeAnnouncement) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.signature; - crate::c_types::Signature::from_rust(&(*inner_val)) -} -/// The signature by the node key -#[no_mangle] -pub extern "C" fn NodeAnnouncement_set_signature(this_ptr: &mut NodeAnnouncement, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.signature = val.into_rust(); -} -/// The actual content of the announcement -#[no_mangle] -pub extern "C" fn NodeAnnouncement_get_contents(this_ptr: &NodeAnnouncement) -> crate::ln::msgs::UnsignedNodeAnnouncement { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.contents; - crate::ln::msgs::UnsignedNodeAnnouncement { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// The actual content of the announcement -#[no_mangle] -pub extern "C" fn NodeAnnouncement_set_contents(this_ptr: &mut NodeAnnouncement, mut val: crate::ln::msgs::UnsignedNodeAnnouncement) { - unsafe { &mut *this_ptr.inner }.contents = *unsafe { Box::from_raw(val.take_inner()) }; -} -#[must_use] -#[no_mangle] -pub extern "C" fn NodeAnnouncement_new(mut signature_arg: crate::c_types::Signature, mut contents_arg: crate::ln::msgs::UnsignedNodeAnnouncement) -> NodeAnnouncement { - NodeAnnouncement { inner: Box::into_raw(Box::new(nativeNodeAnnouncement { - signature: signature_arg.into_rust(), - contents: *unsafe { Box::from_raw(contents_arg.take_inner()) }, - })), is_owned: true } -} -impl Clone for NodeAnnouncement { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeNodeAnnouncement>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn NodeAnnouncement_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncement)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn NodeAnnouncement_clone(orig: &NodeAnnouncement) -> NodeAnnouncement { - orig.clone() -} - -use lightning::ln::msgs::UnsignedChannelAnnouncement as nativeUnsignedChannelAnnouncementImport; -type nativeUnsignedChannelAnnouncement = nativeUnsignedChannelAnnouncementImport; - -/// The unsigned part of a channel_announcement -#[must_use] -#[repr(C)] -pub struct UnsignedChannelAnnouncement { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeUnsignedChannelAnnouncement, - pub is_owned: bool, -} - -impl Drop for UnsignedChannelAnnouncement { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeUnsignedChannelAnnouncement>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_free(this_ptr: UnsignedChannelAnnouncement) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn UnsignedChannelAnnouncement_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUnsignedChannelAnnouncement); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl UnsignedChannelAnnouncement { - pub(crate) fn take_inner(mut self) -> *mut nativeUnsignedChannelAnnouncement { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The advertised channel features -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_get_features(this_ptr: &UnsignedChannelAnnouncement) -> crate::ln::features::ChannelFeatures { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features; - crate::ln::features::ChannelFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// The advertised channel features -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_set_features(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::ln::features::ChannelFeatures) { - unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// The genesis hash of the blockchain where the channel is to be opened -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_get_chain_hash(this_ptr: &UnsignedChannelAnnouncement) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chain_hash; - (*inner_val).as_inner() -} -/// The genesis hash of the blockchain where the channel is to be opened -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_set_chain_hash(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); -} -/// The short channel ID -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_get_short_channel_id(this_ptr: &UnsignedChannelAnnouncement) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.short_channel_id; - (*inner_val) -} -/// The short channel ID -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_set_short_channel_id(this_ptr: &mut UnsignedChannelAnnouncement, mut val: u64) { - unsafe { &mut *this_ptr.inner }.short_channel_id = val; -} -/// One of the two node_ids which are endpoints of this channel -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_get_node_id_1(this_ptr: &UnsignedChannelAnnouncement) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_id_1; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// One of the two node_ids which are endpoints of this channel -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_set_node_id_1(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.node_id_1 = val.into_rust(); -} -/// The other of the two node_ids which are endpoints of this channel -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_get_node_id_2(this_ptr: &UnsignedChannelAnnouncement) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_id_2; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The other of the two node_ids which are endpoints of this channel -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_set_node_id_2(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.node_id_2 = val.into_rust(); -} -/// The funding key for the first node -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_get_bitcoin_key_1(this_ptr: &UnsignedChannelAnnouncement) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.bitcoin_key_1; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The funding key for the first node -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_set_bitcoin_key_1(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.bitcoin_key_1 = val.into_rust(); -} -/// The funding key for the second node -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_get_bitcoin_key_2(this_ptr: &UnsignedChannelAnnouncement) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.bitcoin_key_2; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The funding key for the second node -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_set_bitcoin_key_2(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.bitcoin_key_2 = val.into_rust(); -} -impl Clone for UnsignedChannelAnnouncement { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeUnsignedChannelAnnouncement>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn UnsignedChannelAnnouncement_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUnsignedChannelAnnouncement)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_clone(orig: &UnsignedChannelAnnouncement) -> UnsignedChannelAnnouncement { - orig.clone() -} - -use lightning::ln::msgs::ChannelAnnouncement as nativeChannelAnnouncementImport; -type nativeChannelAnnouncement = nativeChannelAnnouncementImport; - -/// A channel_announcement message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct ChannelAnnouncement { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelAnnouncement, - pub is_owned: bool, -} - -impl Drop for ChannelAnnouncement { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelAnnouncement>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_free(this_ptr: ChannelAnnouncement) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelAnnouncement_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelAnnouncement); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelAnnouncement { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelAnnouncement { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Authentication of the announcement by the first public node -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_get_node_signature_1(this_ptr: &ChannelAnnouncement) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_signature_1; - crate::c_types::Signature::from_rust(&(*inner_val)) -} -/// Authentication of the announcement by the first public node -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_set_node_signature_1(this_ptr: &mut ChannelAnnouncement, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.node_signature_1 = val.into_rust(); -} -/// Authentication of the announcement by the second public node -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_get_node_signature_2(this_ptr: &ChannelAnnouncement) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_signature_2; - crate::c_types::Signature::from_rust(&(*inner_val)) -} -/// Authentication of the announcement by the second public node -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_set_node_signature_2(this_ptr: &mut ChannelAnnouncement, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.node_signature_2 = val.into_rust(); -} -/// Proof of funding UTXO ownership by the first public node -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_get_bitcoin_signature_1(this_ptr: &ChannelAnnouncement) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.bitcoin_signature_1; - crate::c_types::Signature::from_rust(&(*inner_val)) -} -/// Proof of funding UTXO ownership by the first public node -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_set_bitcoin_signature_1(this_ptr: &mut ChannelAnnouncement, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.bitcoin_signature_1 = val.into_rust(); -} -/// Proof of funding UTXO ownership by the second public node -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_get_bitcoin_signature_2(this_ptr: &ChannelAnnouncement) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.bitcoin_signature_2; - crate::c_types::Signature::from_rust(&(*inner_val)) -} -/// Proof of funding UTXO ownership by the second public node -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_set_bitcoin_signature_2(this_ptr: &mut ChannelAnnouncement, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.bitcoin_signature_2 = val.into_rust(); -} -/// The actual announcement -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_get_contents(this_ptr: &ChannelAnnouncement) -> crate::ln::msgs::UnsignedChannelAnnouncement { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.contents; - crate::ln::msgs::UnsignedChannelAnnouncement { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// The actual announcement -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_set_contents(this_ptr: &mut ChannelAnnouncement, mut val: crate::ln::msgs::UnsignedChannelAnnouncement) { - unsafe { &mut *this_ptr.inner }.contents = *unsafe { Box::from_raw(val.take_inner()) }; -} -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_new(mut node_signature_1_arg: crate::c_types::Signature, mut node_signature_2_arg: crate::c_types::Signature, mut bitcoin_signature_1_arg: crate::c_types::Signature, mut bitcoin_signature_2_arg: crate::c_types::Signature, mut contents_arg: crate::ln::msgs::UnsignedChannelAnnouncement) -> ChannelAnnouncement { - ChannelAnnouncement { inner: Box::into_raw(Box::new(nativeChannelAnnouncement { - node_signature_1: node_signature_1_arg.into_rust(), - node_signature_2: node_signature_2_arg.into_rust(), - bitcoin_signature_1: bitcoin_signature_1_arg.into_rust(), - bitcoin_signature_2: bitcoin_signature_2_arg.into_rust(), - contents: *unsafe { Box::from_raw(contents_arg.take_inner()) }, - })), is_owned: true } -} -impl Clone for ChannelAnnouncement { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeChannelAnnouncement>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelAnnouncement_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelAnnouncement)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_clone(orig: &ChannelAnnouncement) -> ChannelAnnouncement { - orig.clone() -} - -use lightning::ln::msgs::UnsignedChannelUpdate as nativeUnsignedChannelUpdateImport; -type nativeUnsignedChannelUpdate = nativeUnsignedChannelUpdateImport; - -/// The unsigned part of a channel_update -#[must_use] -#[repr(C)] -pub struct UnsignedChannelUpdate { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeUnsignedChannelUpdate, - pub is_owned: bool, -} - -impl Drop for UnsignedChannelUpdate { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeUnsignedChannelUpdate>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_free(this_ptr: UnsignedChannelUpdate) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn UnsignedChannelUpdate_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUnsignedChannelUpdate); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl UnsignedChannelUpdate { - pub(crate) fn take_inner(mut self) -> *mut nativeUnsignedChannelUpdate { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The genesis hash of the blockchain where the channel is to be opened -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_get_chain_hash(this_ptr: &UnsignedChannelUpdate) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chain_hash; - (*inner_val).as_inner() -} -/// The genesis hash of the blockchain where the channel is to be opened -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_set_chain_hash(this_ptr: &mut UnsignedChannelUpdate, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); -} -/// The short channel ID -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_get_short_channel_id(this_ptr: &UnsignedChannelUpdate) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.short_channel_id; - (*inner_val) -} -/// The short channel ID -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_set_short_channel_id(this_ptr: &mut UnsignedChannelUpdate, mut val: u64) { - unsafe { &mut *this_ptr.inner }.short_channel_id = val; -} -/// A strictly monotonic announcement counter, with gaps allowed, specific to this channel -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_get_timestamp(this_ptr: &UnsignedChannelUpdate) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.timestamp; - (*inner_val) -} -/// A strictly monotonic announcement counter, with gaps allowed, specific to this channel -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_set_timestamp(this_ptr: &mut UnsignedChannelUpdate, mut val: u32) { - unsafe { &mut *this_ptr.inner }.timestamp = val; -} -/// Channel flags -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_get_flags(this_ptr: &UnsignedChannelUpdate) -> u8 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.flags; - (*inner_val) -} -/// Channel flags -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_set_flags(this_ptr: &mut UnsignedChannelUpdate, mut val: u8) { - unsafe { &mut *this_ptr.inner }.flags = val; -} -/// The number of blocks to subtract from incoming HTLC cltv_expiry values -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_get_cltv_expiry_delta(this_ptr: &UnsignedChannelUpdate) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta; - (*inner_val) -} -/// The number of blocks to subtract from incoming HTLC cltv_expiry values -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_set_cltv_expiry_delta(this_ptr: &mut UnsignedChannelUpdate, mut val: u16) { - unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val; -} -/// The minimum HTLC size incoming to sender, in milli-satoshi -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_get_htlc_minimum_msat(this_ptr: &UnsignedChannelUpdate) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat; - (*inner_val) -} -/// The minimum HTLC size incoming to sender, in milli-satoshi -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_set_htlc_minimum_msat(this_ptr: &mut UnsignedChannelUpdate, mut val: u64) { - unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val; -} -/// The base HTLC fee charged by sender, in milli-satoshi -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_get_fee_base_msat(this_ptr: &UnsignedChannelUpdate) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_base_msat; - (*inner_val) -} -/// The base HTLC fee charged by sender, in milli-satoshi -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_set_fee_base_msat(this_ptr: &mut UnsignedChannelUpdate, mut val: u32) { - unsafe { &mut *this_ptr.inner }.fee_base_msat = val; -} -/// The amount to fee multiplier, in micro-satoshi -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_get_fee_proportional_millionths(this_ptr: &UnsignedChannelUpdate) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_proportional_millionths; - (*inner_val) -} -/// The amount to fee multiplier, in micro-satoshi -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_set_fee_proportional_millionths(this_ptr: &mut UnsignedChannelUpdate, mut val: u32) { - unsafe { &mut *this_ptr.inner }.fee_proportional_millionths = val; -} -impl Clone for UnsignedChannelUpdate { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeUnsignedChannelUpdate>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn UnsignedChannelUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUnsignedChannelUpdate)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_clone(orig: &UnsignedChannelUpdate) -> UnsignedChannelUpdate { - orig.clone() -} - -use lightning::ln::msgs::ChannelUpdate as nativeChannelUpdateImport; -type nativeChannelUpdate = nativeChannelUpdateImport; - -/// A channel_update message to be sent or received from a peer -#[must_use] -#[repr(C)] -pub struct ChannelUpdate { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelUpdate, - pub is_owned: bool, -} - -impl Drop for ChannelUpdate { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelUpdate>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelUpdate_free(this_ptr: ChannelUpdate) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelUpdate_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelUpdate); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelUpdate { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelUpdate { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// A signature of the channel update -#[no_mangle] -pub extern "C" fn ChannelUpdate_get_signature(this_ptr: &ChannelUpdate) -> crate::c_types::Signature { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.signature; - crate::c_types::Signature::from_rust(&(*inner_val)) -} -/// A signature of the channel update -#[no_mangle] -pub extern "C" fn ChannelUpdate_set_signature(this_ptr: &mut ChannelUpdate, mut val: crate::c_types::Signature) { - unsafe { &mut *this_ptr.inner }.signature = val.into_rust(); -} -/// The actual channel update -#[no_mangle] -pub extern "C" fn ChannelUpdate_get_contents(this_ptr: &ChannelUpdate) -> crate::ln::msgs::UnsignedChannelUpdate { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.contents; - crate::ln::msgs::UnsignedChannelUpdate { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// The actual channel update -#[no_mangle] -pub extern "C" fn ChannelUpdate_set_contents(this_ptr: &mut ChannelUpdate, mut val: crate::ln::msgs::UnsignedChannelUpdate) { - unsafe { &mut *this_ptr.inner }.contents = *unsafe { Box::from_raw(val.take_inner()) }; -} -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelUpdate_new(mut signature_arg: crate::c_types::Signature, mut contents_arg: crate::ln::msgs::UnsignedChannelUpdate) -> ChannelUpdate { - ChannelUpdate { inner: Box::into_raw(Box::new(nativeChannelUpdate { - signature: signature_arg.into_rust(), - contents: *unsafe { Box::from_raw(contents_arg.take_inner()) }, - })), is_owned: true } -} -impl Clone for ChannelUpdate { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeChannelUpdate>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUpdate)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ChannelUpdate_clone(orig: &ChannelUpdate) -> ChannelUpdate { - orig.clone() -} - -use lightning::ln::msgs::QueryChannelRange as nativeQueryChannelRangeImport; -type nativeQueryChannelRange = nativeQueryChannelRangeImport; - -/// A query_channel_range message is used to query a peer for channel -/// UTXOs in a range of blocks. The recipient of a query makes a best -/// effort to reply to the query using one or more reply_channel_range -/// messages. -#[must_use] -#[repr(C)] -pub struct QueryChannelRange { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeQueryChannelRange, - pub is_owned: bool, -} - -impl Drop for QueryChannelRange { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeQueryChannelRange>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn QueryChannelRange_free(this_ptr: QueryChannelRange) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn QueryChannelRange_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeQueryChannelRange); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl QueryChannelRange { - pub(crate) fn take_inner(mut self) -> *mut nativeQueryChannelRange { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The genesis hash of the blockchain being queried -#[no_mangle] -pub extern "C" fn QueryChannelRange_get_chain_hash(this_ptr: &QueryChannelRange) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chain_hash; - (*inner_val).as_inner() -} -/// The genesis hash of the blockchain being queried -#[no_mangle] -pub extern "C" fn QueryChannelRange_set_chain_hash(this_ptr: &mut QueryChannelRange, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); -} -/// The height of the first block for the channel UTXOs being queried -#[no_mangle] -pub extern "C" fn QueryChannelRange_get_first_blocknum(this_ptr: &QueryChannelRange) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.first_blocknum; - (*inner_val) -} -/// The height of the first block for the channel UTXOs being queried -#[no_mangle] -pub extern "C" fn QueryChannelRange_set_first_blocknum(this_ptr: &mut QueryChannelRange, mut val: u32) { - unsafe { &mut *this_ptr.inner }.first_blocknum = val; -} -/// The number of blocks to include in the query results -#[no_mangle] -pub extern "C" fn QueryChannelRange_get_number_of_blocks(this_ptr: &QueryChannelRange) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.number_of_blocks; - (*inner_val) -} -/// The number of blocks to include in the query results -#[no_mangle] -pub extern "C" fn QueryChannelRange_set_number_of_blocks(this_ptr: &mut QueryChannelRange, mut val: u32) { - unsafe { &mut *this_ptr.inner }.number_of_blocks = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn QueryChannelRange_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut first_blocknum_arg: u32, mut number_of_blocks_arg: u32) -> QueryChannelRange { - QueryChannelRange { inner: Box::into_raw(Box::new(nativeQueryChannelRange { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), - first_blocknum: first_blocknum_arg, - number_of_blocks: number_of_blocks_arg, - })), is_owned: true } -} -impl Clone for QueryChannelRange { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeQueryChannelRange>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn QueryChannelRange_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeQueryChannelRange)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn QueryChannelRange_clone(orig: &QueryChannelRange) -> QueryChannelRange { - orig.clone() -} - -use lightning::ln::msgs::ReplyChannelRange as nativeReplyChannelRangeImport; -type nativeReplyChannelRange = nativeReplyChannelRangeImport; - -/// A reply_channel_range message is a reply to a query_channel_range -/// message. Multiple reply_channel_range messages can be sent in reply -/// to a single query_channel_range message. The query recipient makes a -/// best effort to respond based on their local network view which may -/// not be a perfect view of the network. The short_channel_ids in the -/// reply are encoded. We only support encoding_type=0 uncompressed -/// serialization and do not support encoding_type=1 zlib serialization. -#[must_use] -#[repr(C)] -pub struct ReplyChannelRange { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeReplyChannelRange, - pub is_owned: bool, -} - -impl Drop for ReplyChannelRange { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeReplyChannelRange>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ReplyChannelRange_free(this_ptr: ReplyChannelRange) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ReplyChannelRange_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeReplyChannelRange); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ReplyChannelRange { - pub(crate) fn take_inner(mut self) -> *mut nativeReplyChannelRange { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The genesis hash of the blockchain being queried -#[no_mangle] -pub extern "C" fn ReplyChannelRange_get_chain_hash(this_ptr: &ReplyChannelRange) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chain_hash; - (*inner_val).as_inner() -} -/// The genesis hash of the blockchain being queried -#[no_mangle] -pub extern "C" fn ReplyChannelRange_set_chain_hash(this_ptr: &mut ReplyChannelRange, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); -} -/// The height of the first block in the range of the reply -#[no_mangle] -pub extern "C" fn ReplyChannelRange_get_first_blocknum(this_ptr: &ReplyChannelRange) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.first_blocknum; - (*inner_val) -} -/// The height of the first block in the range of the reply -#[no_mangle] -pub extern "C" fn ReplyChannelRange_set_first_blocknum(this_ptr: &mut ReplyChannelRange, mut val: u32) { - unsafe { &mut *this_ptr.inner }.first_blocknum = val; -} -/// The number of blocks included in the range of the reply -#[no_mangle] -pub extern "C" fn ReplyChannelRange_get_number_of_blocks(this_ptr: &ReplyChannelRange) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.number_of_blocks; - (*inner_val) -} -/// The number of blocks included in the range of the reply -#[no_mangle] -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; -} -/// True when this is the final reply for a query -#[no_mangle] -pub extern "C" fn ReplyChannelRange_get_sync_complete(this_ptr: &ReplyChannelRange) -> bool { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.sync_complete; - (*inner_val) -} -/// True when this is the final reply for a query -#[no_mangle] -pub extern "C" fn ReplyChannelRange_set_sync_complete(this_ptr: &mut ReplyChannelRange, mut val: bool) { - unsafe { &mut *this_ptr.inner }.sync_complete = val; -} -/// The short_channel_ids in the channel range -#[no_mangle] -pub extern "C" fn ReplyChannelRange_set_short_channel_ids(this_ptr: &mut ReplyChannelRange, mut val: crate::c_types::derived::CVec_u64Z) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); }; - unsafe { &mut *this_ptr.inner }.short_channel_ids = local_val; -} -#[must_use] -#[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 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 }); }; - ReplyChannelRange { inner: Box::into_raw(Box::new(nativeReplyChannelRange { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), - first_blocknum: first_blocknum_arg, - number_of_blocks: number_of_blocks_arg, - sync_complete: sync_complete_arg, - short_channel_ids: local_short_channel_ids_arg, - })), is_owned: true } -} -impl Clone for ReplyChannelRange { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeReplyChannelRange>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ReplyChannelRange_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeReplyChannelRange)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ReplyChannelRange_clone(orig: &ReplyChannelRange) -> ReplyChannelRange { - orig.clone() -} - -use lightning::ln::msgs::QueryShortChannelIds as nativeQueryShortChannelIdsImport; -type nativeQueryShortChannelIds = nativeQueryShortChannelIdsImport; - -/// A query_short_channel_ids message is used to query a peer for -/// routing gossip messages related to one or more short_channel_ids. -/// The query recipient will reply with the latest, if available, -/// channel_announcement, channel_update and node_announcement messages -/// it maintains for the requested short_channel_ids followed by a -/// reply_short_channel_ids_end message. The short_channel_ids sent in -/// this query are encoded. We only support encoding_type=0 uncompressed -/// serialization and do not support encoding_type=1 zlib serialization. -#[must_use] -#[repr(C)] -pub struct QueryShortChannelIds { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeQueryShortChannelIds, - pub is_owned: bool, -} - -impl Drop for QueryShortChannelIds { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeQueryShortChannelIds>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn QueryShortChannelIds_free(this_ptr: QueryShortChannelIds) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn QueryShortChannelIds_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeQueryShortChannelIds); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl QueryShortChannelIds { - pub(crate) fn take_inner(mut self) -> *mut nativeQueryShortChannelIds { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The genesis hash of the blockchain being queried -#[no_mangle] -pub extern "C" fn QueryShortChannelIds_get_chain_hash(this_ptr: &QueryShortChannelIds) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chain_hash; - (*inner_val).as_inner() -} -/// The genesis hash of the blockchain being queried -#[no_mangle] -pub extern "C" fn QueryShortChannelIds_set_chain_hash(this_ptr: &mut QueryShortChannelIds, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); -} -/// The short_channel_ids that are being queried -#[no_mangle] -pub extern "C" fn QueryShortChannelIds_set_short_channel_ids(this_ptr: &mut QueryShortChannelIds, mut val: crate::c_types::derived::CVec_u64Z) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); }; - unsafe { &mut *this_ptr.inner }.short_channel_ids = local_val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn QueryShortChannelIds_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut short_channel_ids_arg: crate::c_types::derived::CVec_u64Z) -> QueryShortChannelIds { - 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 }); }; - QueryShortChannelIds { inner: Box::into_raw(Box::new(nativeQueryShortChannelIds { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), - short_channel_ids: local_short_channel_ids_arg, - })), is_owned: true } -} -impl Clone for QueryShortChannelIds { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeQueryShortChannelIds>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn QueryShortChannelIds_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeQueryShortChannelIds)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn QueryShortChannelIds_clone(orig: &QueryShortChannelIds) -> QueryShortChannelIds { - orig.clone() -} - -use lightning::ln::msgs::ReplyShortChannelIdsEnd as nativeReplyShortChannelIdsEndImport; -type nativeReplyShortChannelIdsEnd = nativeReplyShortChannelIdsEndImport; - -/// A reply_short_channel_ids_end message is sent as a reply to a -/// query_short_channel_ids message. The query recipient makes a best -/// effort to respond based on their local network view which may not be -/// a perfect view of the network. -#[must_use] -#[repr(C)] -pub struct ReplyShortChannelIdsEnd { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeReplyShortChannelIdsEnd, - pub is_owned: bool, -} - -impl Drop for ReplyShortChannelIdsEnd { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeReplyShortChannelIdsEnd>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ReplyShortChannelIdsEnd_free(this_ptr: ReplyShortChannelIdsEnd) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ReplyShortChannelIdsEnd_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeReplyShortChannelIdsEnd); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ReplyShortChannelIdsEnd { - pub(crate) fn take_inner(mut self) -> *mut nativeReplyShortChannelIdsEnd { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The genesis hash of the blockchain that was queried -#[no_mangle] -pub extern "C" fn ReplyShortChannelIdsEnd_get_chain_hash(this_ptr: &ReplyShortChannelIdsEnd) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chain_hash; - (*inner_val).as_inner() -} -/// The genesis hash of the blockchain that was queried -#[no_mangle] -pub extern "C" fn ReplyShortChannelIdsEnd_set_chain_hash(this_ptr: &mut ReplyShortChannelIdsEnd, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); -} -/// Indicates if the query recipient maintains up-to-date channel -/// information for the chain_hash -#[no_mangle] -pub extern "C" fn ReplyShortChannelIdsEnd_get_full_information(this_ptr: &ReplyShortChannelIdsEnd) -> bool { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.full_information; - (*inner_val) -} -/// Indicates if the query recipient maintains up-to-date channel -/// information for the chain_hash -#[no_mangle] -pub extern "C" fn ReplyShortChannelIdsEnd_set_full_information(this_ptr: &mut ReplyShortChannelIdsEnd, mut val: bool) { - unsafe { &mut *this_ptr.inner }.full_information = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn ReplyShortChannelIdsEnd_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut full_information_arg: bool) -> ReplyShortChannelIdsEnd { - ReplyShortChannelIdsEnd { inner: Box::into_raw(Box::new(nativeReplyShortChannelIdsEnd { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), - full_information: full_information_arg, - })), is_owned: true } -} -impl Clone for ReplyShortChannelIdsEnd { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeReplyShortChannelIdsEnd>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ReplyShortChannelIdsEnd_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeReplyShortChannelIdsEnd)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ReplyShortChannelIdsEnd_clone(orig: &ReplyShortChannelIdsEnd) -> ReplyShortChannelIdsEnd { - orig.clone() -} - -use lightning::ln::msgs::GossipTimestampFilter as nativeGossipTimestampFilterImport; -type nativeGossipTimestampFilter = nativeGossipTimestampFilterImport; - -/// A gossip_timestamp_filter message is used by a node to request -/// gossip relay for messages in the requested time range when the -/// gossip_queries feature has been negotiated. -#[must_use] -#[repr(C)] -pub struct GossipTimestampFilter { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeGossipTimestampFilter, - pub is_owned: bool, -} - -impl Drop for GossipTimestampFilter { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeGossipTimestampFilter>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn GossipTimestampFilter_free(this_ptr: GossipTimestampFilter) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn GossipTimestampFilter_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeGossipTimestampFilter); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl GossipTimestampFilter { - pub(crate) fn take_inner(mut self) -> *mut nativeGossipTimestampFilter { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The genesis hash of the blockchain for channel and node information -#[no_mangle] -pub extern "C" fn GossipTimestampFilter_get_chain_hash(this_ptr: &GossipTimestampFilter) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chain_hash; - (*inner_val).as_inner() -} -/// The genesis hash of the blockchain for channel and node information -#[no_mangle] -pub extern "C" fn GossipTimestampFilter_set_chain_hash(this_ptr: &mut GossipTimestampFilter, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); -} -/// The starting unix timestamp -#[no_mangle] -pub extern "C" fn GossipTimestampFilter_get_first_timestamp(this_ptr: &GossipTimestampFilter) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.first_timestamp; - (*inner_val) -} -/// The starting unix timestamp -#[no_mangle] -pub extern "C" fn GossipTimestampFilter_set_first_timestamp(this_ptr: &mut GossipTimestampFilter, mut val: u32) { - unsafe { &mut *this_ptr.inner }.first_timestamp = val; -} -/// The range of information in seconds -#[no_mangle] -pub extern "C" fn GossipTimestampFilter_get_timestamp_range(this_ptr: &GossipTimestampFilter) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.timestamp_range; - (*inner_val) -} -/// The range of information in seconds -#[no_mangle] -pub extern "C" fn GossipTimestampFilter_set_timestamp_range(this_ptr: &mut GossipTimestampFilter, mut val: u32) { - unsafe { &mut *this_ptr.inner }.timestamp_range = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn GossipTimestampFilter_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut first_timestamp_arg: u32, mut timestamp_range_arg: u32) -> GossipTimestampFilter { - GossipTimestampFilter { inner: Box::into_raw(Box::new(nativeGossipTimestampFilter { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), - first_timestamp: first_timestamp_arg, - timestamp_range: timestamp_range_arg, - })), is_owned: true } -} -impl Clone for GossipTimestampFilter { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeGossipTimestampFilter>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn GossipTimestampFilter_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeGossipTimestampFilter)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn GossipTimestampFilter_clone(orig: &GossipTimestampFilter) -> GossipTimestampFilter { - orig.clone() -} -/// Used to put an error message in a LightningError -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum ErrorAction { - /// The peer took some action which made us think they were useless. Disconnect them. - DisconnectPeer { - msg: crate::ln::msgs::ErrorMessage, - }, - /// The peer did something harmless that we weren't able to process, just log and ignore - IgnoreError, - /// The peer did something incorrect. Tell them. - SendErrorMessage { - msg: crate::ln::msgs::ErrorMessage, - }, -} -use lightning::ln::msgs::ErrorAction as nativeErrorAction; -impl ErrorAction { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeErrorAction { - match self { - ErrorAction::DisconnectPeer {ref msg, } => { - let mut msg_nonref = (*msg).clone(); - let mut local_msg_nonref = if msg_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(msg_nonref.take_inner()) } }) }; - nativeErrorAction::DisconnectPeer { - msg: local_msg_nonref, - } - }, - ErrorAction::IgnoreError => nativeErrorAction::IgnoreError, - ErrorAction::SendErrorMessage {ref msg, } => { - let mut msg_nonref = (*msg).clone(); - nativeErrorAction::SendErrorMessage { - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativeErrorAction { - match self { - ErrorAction::DisconnectPeer {mut msg, } => { - let mut local_msg = if msg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(msg.take_inner()) } }) }; - nativeErrorAction::DisconnectPeer { - msg: local_msg, - } - }, - ErrorAction::IgnoreError => nativeErrorAction::IgnoreError, - ErrorAction::SendErrorMessage {mut msg, } => { - nativeErrorAction::SendErrorMessage { - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativeErrorAction) -> Self { - match native { - nativeErrorAction::DisconnectPeer {ref msg, } => { - let mut msg_nonref = (*msg).clone(); - let mut local_msg_nonref = crate::ln::msgs::ErrorMessage { inner: if msg_nonref.is_none() { std::ptr::null_mut() } else { { Box::into_raw(Box::new((msg_nonref.unwrap()))) } }, is_owned: true }; - ErrorAction::DisconnectPeer { - msg: local_msg_nonref, - } - }, - nativeErrorAction::IgnoreError => ErrorAction::IgnoreError, - nativeErrorAction::SendErrorMessage {ref msg, } => { - let mut msg_nonref = (*msg).clone(); - ErrorAction::SendErrorMessage { - msg: crate::ln::msgs::ErrorMessage { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativeErrorAction) -> Self { - match native { - nativeErrorAction::DisconnectPeer {mut msg, } => { - let mut local_msg = crate::ln::msgs::ErrorMessage { inner: if msg.is_none() { std::ptr::null_mut() } else { { Box::into_raw(Box::new((msg.unwrap()))) } }, is_owned: true }; - ErrorAction::DisconnectPeer { - msg: local_msg, - } - }, - nativeErrorAction::IgnoreError => ErrorAction::IgnoreError, - nativeErrorAction::SendErrorMessage {mut msg, } => { - ErrorAction::SendErrorMessage { - msg: crate::ln::msgs::ErrorMessage { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - } - } -} -#[no_mangle] -pub extern "C" fn ErrorAction_free(this_ptr: ErrorAction) { } -#[no_mangle] -pub extern "C" fn ErrorAction_clone(orig: &ErrorAction) -> ErrorAction { - orig.clone() -} - -use lightning::ln::msgs::LightningError as nativeLightningErrorImport; -type nativeLightningError = nativeLightningErrorImport; - -/// An Err type for failure to process messages. -#[must_use] -#[repr(C)] -pub struct LightningError { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeLightningError, - pub is_owned: bool, -} - -impl Drop for LightningError { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeLightningError>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn LightningError_free(this_ptr: LightningError) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn LightningError_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLightningError); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl LightningError { - pub(crate) fn take_inner(mut self) -> *mut nativeLightningError { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// A human-readable message describing the error -#[no_mangle] -pub extern "C" fn LightningError_get_err(this_ptr: &LightningError) -> crate::c_types::Str { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.err; - (*inner_val).as_str().into() -} -/// A human-readable message describing the error -#[no_mangle] -pub extern "C" fn LightningError_set_err(this_ptr: &mut LightningError, mut val: crate::c_types::derived::CVec_u8Z) { - unsafe { &mut *this_ptr.inner }.err = String::from_utf8(val.into_rust()).unwrap(); -} -/// The action which should be taken against the offending peer. -#[no_mangle] -pub extern "C" fn LightningError_get_action(this_ptr: &LightningError) -> crate::ln::msgs::ErrorAction { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.action; - crate::ln::msgs::ErrorAction::from_native(&(*inner_val)) -} -/// The action which should be taken against the offending peer. -#[no_mangle] -pub extern "C" fn LightningError_set_action(this_ptr: &mut LightningError, mut val: crate::ln::msgs::ErrorAction) { - unsafe { &mut *this_ptr.inner }.action = val.into_native(); -} -#[must_use] -#[no_mangle] -pub extern "C" fn LightningError_new(mut err_arg: crate::c_types::derived::CVec_u8Z, mut action_arg: crate::ln::msgs::ErrorAction) -> LightningError { - LightningError { inner: Box::into_raw(Box::new(nativeLightningError { - err: String::from_utf8(err_arg.into_rust()).unwrap(), - action: action_arg.into_native(), - })), is_owned: true } -} -impl Clone for LightningError { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeLightningError>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn 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() -} - -use lightning::ln::msgs::CommitmentUpdate as nativeCommitmentUpdateImport; -type nativeCommitmentUpdate = nativeCommitmentUpdateImport; - -/// Struct used to return values from revoke_and_ack messages, containing a bunch of commitment -/// transaction updates if they were pending. -#[must_use] -#[repr(C)] -pub struct CommitmentUpdate { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeCommitmentUpdate, - pub is_owned: bool, -} - -impl Drop for CommitmentUpdate { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeCommitmentUpdate>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn CommitmentUpdate_free(this_ptr: CommitmentUpdate) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn CommitmentUpdate_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCommitmentUpdate); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl CommitmentUpdate { - pub(crate) fn take_inner(mut self) -> *mut nativeCommitmentUpdate { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// update_add_htlc messages which should be sent -#[no_mangle] -pub extern "C" fn CommitmentUpdate_set_update_add_htlcs(this_ptr: &mut CommitmentUpdate, mut val: crate::c_types::derived::CVec_UpdateAddHTLCZ) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; - unsafe { &mut *this_ptr.inner }.update_add_htlcs = local_val; -} -/// update_fulfill_htlc messages which should be sent -#[no_mangle] -pub extern "C" fn CommitmentUpdate_set_update_fulfill_htlcs(this_ptr: &mut CommitmentUpdate, mut val: crate::c_types::derived::CVec_UpdateFulfillHTLCZ) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; - unsafe { &mut *this_ptr.inner }.update_fulfill_htlcs = local_val; -} -/// update_fail_htlc messages which should be sent -#[no_mangle] -pub extern "C" fn CommitmentUpdate_set_update_fail_htlcs(this_ptr: &mut CommitmentUpdate, mut val: crate::c_types::derived::CVec_UpdateFailHTLCZ) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; - unsafe { &mut *this_ptr.inner }.update_fail_htlcs = local_val; -} -/// update_fail_malformed_htlc messages which should be sent -#[no_mangle] -pub extern "C" fn CommitmentUpdate_set_update_fail_malformed_htlcs(this_ptr: &mut CommitmentUpdate, mut val: crate::c_types::derived::CVec_UpdateFailMalformedHTLCZ) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; - unsafe { &mut *this_ptr.inner }.update_fail_malformed_htlcs = local_val; -} -/// An update_fee message which should be sent -#[no_mangle] -pub extern "C" fn CommitmentUpdate_get_update_fee(this_ptr: &CommitmentUpdate) -> crate::ln::msgs::UpdateFee { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.update_fee; - let mut local_inner_val = crate::ln::msgs::UpdateFee { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; - local_inner_val -} -/// An update_fee message which should be sent -#[no_mangle] -pub extern "C" fn CommitmentUpdate_set_update_fee(this_ptr: &mut CommitmentUpdate, mut val: crate::ln::msgs::UpdateFee) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *this_ptr.inner }.update_fee = local_val; -} -/// Finally, the commitment_signed message which should be sent -#[no_mangle] -pub extern "C" fn CommitmentUpdate_get_commitment_signed(this_ptr: &CommitmentUpdate) -> crate::ln::msgs::CommitmentSigned { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.commitment_signed; - crate::ln::msgs::CommitmentSigned { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// Finally, the commitment_signed message which should be sent -#[no_mangle] -pub extern "C" fn CommitmentUpdate_set_commitment_signed(this_ptr: &mut CommitmentUpdate, mut val: crate::ln::msgs::CommitmentSigned) { - unsafe { &mut *this_ptr.inner }.commitment_signed = *unsafe { Box::from_raw(val.take_inner()) }; -} -#[must_use] -#[no_mangle] -pub extern "C" fn CommitmentUpdate_new(mut update_add_htlcs_arg: crate::c_types::derived::CVec_UpdateAddHTLCZ, mut update_fulfill_htlcs_arg: crate::c_types::derived::CVec_UpdateFulfillHTLCZ, mut update_fail_htlcs_arg: crate::c_types::derived::CVec_UpdateFailHTLCZ, mut update_fail_malformed_htlcs_arg: crate::c_types::derived::CVec_UpdateFailMalformedHTLCZ, mut update_fee_arg: crate::ln::msgs::UpdateFee, mut commitment_signed_arg: crate::ln::msgs::CommitmentSigned) -> CommitmentUpdate { - let mut local_update_add_htlcs_arg = Vec::new(); for mut item in update_add_htlcs_arg.into_rust().drain(..) { local_update_add_htlcs_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; - let mut local_update_fulfill_htlcs_arg = Vec::new(); for mut item in update_fulfill_htlcs_arg.into_rust().drain(..) { local_update_fulfill_htlcs_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; - let mut local_update_fail_htlcs_arg = Vec::new(); for mut item in update_fail_htlcs_arg.into_rust().drain(..) { local_update_fail_htlcs_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; - let mut local_update_fail_malformed_htlcs_arg = Vec::new(); for mut item in update_fail_malformed_htlcs_arg.into_rust().drain(..) { local_update_fail_malformed_htlcs_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; - let mut local_update_fee_arg = if update_fee_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(update_fee_arg.take_inner()) } }) }; - CommitmentUpdate { inner: Box::into_raw(Box::new(nativeCommitmentUpdate { - update_add_htlcs: local_update_add_htlcs_arg, - update_fulfill_htlcs: local_update_fulfill_htlcs_arg, - update_fail_htlcs: local_update_fail_htlcs_arg, - update_fail_malformed_htlcs: local_update_fail_malformed_htlcs_arg, - update_fee: local_update_fee_arg, - commitment_signed: *unsafe { Box::from_raw(commitment_signed_arg.take_inner()) }, - })), is_owned: true } -} -impl Clone for CommitmentUpdate { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeCommitmentUpdate>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn CommitmentUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentUpdate)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn CommitmentUpdate_clone(orig: &CommitmentUpdate) -> CommitmentUpdate { - orig.clone() -} -/// The information we received from a peer along the route of a payment we originated. This is -/// returned by ChannelMessageHandler::handle_update_fail_htlc to be passed into -/// RoutingMessageHandler::handle_htlc_fail_channel_update to update our network map. -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum HTLCFailChannelUpdate { - /// We received an error which included a full ChannelUpdate message. - ChannelUpdateMessage { - msg: crate::ln::msgs::ChannelUpdate, - }, - /// We received an error which indicated only that a channel has been closed - ChannelClosed { - short_channel_id: u64, - is_permanent: bool, - }, - /// We received an error which indicated only that a node has failed - NodeFailure { - node_id: crate::c_types::PublicKey, - is_permanent: bool, - }, -} -use lightning::ln::msgs::HTLCFailChannelUpdate as nativeHTLCFailChannelUpdate; -impl HTLCFailChannelUpdate { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeHTLCFailChannelUpdate { - match self { - HTLCFailChannelUpdate::ChannelUpdateMessage {ref msg, } => { - let mut msg_nonref = (*msg).clone(); - nativeHTLCFailChannelUpdate::ChannelUpdateMessage { - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - HTLCFailChannelUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => { - let mut short_channel_id_nonref = (*short_channel_id).clone(); - let mut is_permanent_nonref = (*is_permanent).clone(); - nativeHTLCFailChannelUpdate::ChannelClosed { - short_channel_id: short_channel_id_nonref, - is_permanent: is_permanent_nonref, - } - }, - HTLCFailChannelUpdate::NodeFailure {ref node_id, ref is_permanent, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut is_permanent_nonref = (*is_permanent).clone(); - nativeHTLCFailChannelUpdate::NodeFailure { - node_id: node_id_nonref.into_rust(), - is_permanent: is_permanent_nonref, - } - }, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativeHTLCFailChannelUpdate { - match self { - HTLCFailChannelUpdate::ChannelUpdateMessage {mut msg, } => { - nativeHTLCFailChannelUpdate::ChannelUpdateMessage { - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - HTLCFailChannelUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => { - nativeHTLCFailChannelUpdate::ChannelClosed { - short_channel_id: short_channel_id, - is_permanent: is_permanent, - } - }, - HTLCFailChannelUpdate::NodeFailure {mut node_id, mut is_permanent, } => { - nativeHTLCFailChannelUpdate::NodeFailure { - node_id: node_id.into_rust(), - is_permanent: is_permanent, - } - }, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativeHTLCFailChannelUpdate) -> Self { - match native { - nativeHTLCFailChannelUpdate::ChannelUpdateMessage {ref msg, } => { - let mut msg_nonref = (*msg).clone(); - HTLCFailChannelUpdate::ChannelUpdateMessage { - msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeHTLCFailChannelUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => { - let mut short_channel_id_nonref = (*short_channel_id).clone(); - let mut is_permanent_nonref = (*is_permanent).clone(); - HTLCFailChannelUpdate::ChannelClosed { - short_channel_id: short_channel_id_nonref, - is_permanent: is_permanent_nonref, - } - }, - nativeHTLCFailChannelUpdate::NodeFailure {ref node_id, ref is_permanent, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut is_permanent_nonref = (*is_permanent).clone(); - HTLCFailChannelUpdate::NodeFailure { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - is_permanent: is_permanent_nonref, - } - }, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativeHTLCFailChannelUpdate) -> Self { - match native { - nativeHTLCFailChannelUpdate::ChannelUpdateMessage {mut msg, } => { - HTLCFailChannelUpdate::ChannelUpdateMessage { - msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeHTLCFailChannelUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => { - HTLCFailChannelUpdate::ChannelClosed { - short_channel_id: short_channel_id, - is_permanent: is_permanent, - } - }, - nativeHTLCFailChannelUpdate::NodeFailure {mut node_id, mut is_permanent, } => { - HTLCFailChannelUpdate::NodeFailure { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - is_permanent: is_permanent, - } - }, - } - } -} -#[no_mangle] -pub extern "C" fn HTLCFailChannelUpdate_free(this_ptr: HTLCFailChannelUpdate) { } -#[no_mangle] -pub extern "C" fn HTLCFailChannelUpdate_clone(orig: &HTLCFailChannelUpdate) -> HTLCFailChannelUpdate { - orig.clone() -} -/// A trait to describe an object which can receive channel messages. -/// -/// Messages MAY be called in parallel when they originate from different their_node_ids, however -/// they MUST NOT be called in parallel when the two calls have the same their_node_id. -#[repr(C)] -pub struct ChannelMessageHandler { - pub this_arg: *mut c_void, - /// Handle an incoming open_channel message from the given peer. - pub handle_open_channel: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, their_features: crate::ln::features::InitFeatures, msg: &crate::ln::msgs::OpenChannel), - /// Handle an incoming accept_channel message from the given peer. - pub handle_accept_channel: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, their_features: crate::ln::features::InitFeatures, msg: &crate::ln::msgs::AcceptChannel), - /// Handle an incoming funding_created message from the given peer. - pub handle_funding_created: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingCreated), - /// Handle an incoming funding_signed message from the given peer. - pub handle_funding_signed: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingSigned), - /// Handle an incoming funding_locked message from the given peer. - pub handle_funding_locked: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingLocked), - /// Handle an incoming shutdown message from the given peer. - pub handle_shutdown: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, their_features: &crate::ln::features::InitFeatures, msg: &crate::ln::msgs::Shutdown), - /// Handle an incoming closing_signed message from the given peer. - pub handle_closing_signed: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ClosingSigned), - /// Handle an incoming update_add_htlc message from the given peer. - pub handle_update_add_htlc: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateAddHTLC), - /// Handle an incoming update_fulfill_htlc message from the given peer. - pub handle_update_fulfill_htlc: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFulfillHTLC), - /// Handle an incoming update_fail_htlc message from the given peer. - pub handle_update_fail_htlc: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFailHTLC), - /// Handle an incoming update_fail_malformed_htlc message from the given peer. - pub handle_update_fail_malformed_htlc: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFailMalformedHTLC), - /// Handle an incoming commitment_signed message from the given peer. - pub handle_commitment_signed: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::CommitmentSigned), - /// Handle an incoming revoke_and_ack message from the given peer. - pub handle_revoke_and_ack: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::RevokeAndACK), - /// Handle an incoming update_fee message from the given peer. - pub handle_update_fee: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFee), - /// Handle an incoming announcement_signatures message from the given peer. - pub handle_announcement_signatures: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::AnnouncementSignatures), - /// Indicates a connection to the peer failed/an existing connection was lost. If no connection - /// is believed to be possible in the future (eg they're sending us messages we don't - /// understand or indicate they require unknown feature bits), no_connection_possible is set - /// and any outstanding channels should be failed. - pub peer_disconnected: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, no_connection_possible: bool), - /// Handle a peer reconnecting, possibly generating channel_reestablish message(s). - pub peer_connected: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::Init), - /// Handle an incoming channel_reestablish message from the given peer. - pub handle_channel_reestablish: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ChannelReestablish), - /// Handle an incoming error message from the given peer. - pub handle_error: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ErrorMessage), - pub MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider, - pub free: Option, -} -impl lightning::util::events::MessageSendEventsProvider for ChannelMessageHandler { - fn get_and_clear_pending_msg_events(&self) -> Vec { - ::get_and_clear_pending_msg_events(&self.MessageSendEventsProvider) - } -} -unsafe impl Send for ChannelMessageHandler {} -unsafe impl Sync for ChannelMessageHandler {} - -use lightning::ln::msgs::ChannelMessageHandler as rustChannelMessageHandler; -impl rustChannelMessageHandler for ChannelMessageHandler { - fn handle_open_channel(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, their_features: lightning::ln::features::InitFeatures, msg: &lightning::ln::msgs::OpenChannel) { - (self.handle_open_channel)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::ln::features::InitFeatures { inner: Box::into_raw(Box::new(their_features)), is_owned: true }, &crate::ln::msgs::OpenChannel { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_accept_channel(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, their_features: lightning::ln::features::InitFeatures, msg: &lightning::ln::msgs::AcceptChannel) { - (self.handle_accept_channel)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::ln::features::InitFeatures { inner: Box::into_raw(Box::new(their_features)), is_owned: true }, &crate::ln::msgs::AcceptChannel { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_funding_created(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::FundingCreated) { - (self.handle_funding_created)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::FundingCreated { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_funding_signed(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::FundingSigned) { - (self.handle_funding_signed)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::FundingSigned { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_funding_locked(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::FundingLocked) { - (self.handle_funding_locked)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::FundingLocked { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_shutdown(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, their_features: &lightning::ln::features::InitFeatures, msg: &lightning::ln::msgs::Shutdown) { - (self.handle_shutdown)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::features::InitFeatures { inner: unsafe { (their_features as *const _) as *mut _ }, is_owned: false }, &crate::ln::msgs::Shutdown { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_closing_signed(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::ClosingSigned) { - (self.handle_closing_signed)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::ClosingSigned { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_update_add_htlc(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::UpdateAddHTLC) { - (self.handle_update_add_htlc)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::UpdateAddHTLC { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_update_fulfill_htlc(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::UpdateFulfillHTLC) { - (self.handle_update_fulfill_htlc)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::UpdateFulfillHTLC { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_update_fail_htlc(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::UpdateFailHTLC) { - (self.handle_update_fail_htlc)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::UpdateFailHTLC { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_update_fail_malformed_htlc(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::UpdateFailMalformedHTLC) { - (self.handle_update_fail_malformed_htlc)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::UpdateFailMalformedHTLC { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_commitment_signed(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::CommitmentSigned) { - (self.handle_commitment_signed)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::CommitmentSigned { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_revoke_and_ack(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::RevokeAndACK) { - (self.handle_revoke_and_ack)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::RevokeAndACK { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_update_fee(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::UpdateFee) { - (self.handle_update_fee)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::UpdateFee { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_announcement_signatures(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::AnnouncementSignatures) { - (self.handle_announcement_signatures)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::AnnouncementSignatures { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn peer_disconnected(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, no_connection_possible: bool) { - (self.peer_disconnected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), no_connection_possible) - } - fn peer_connected(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::Init) { - (self.peer_connected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::Init { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_channel_reestablish(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::ChannelReestablish) { - (self.handle_channel_reestablish)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::ChannelReestablish { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } - fn handle_error(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: &lightning::ln::msgs::ErrorMessage) { - (self.handle_error)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::ErrorMessage { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }) - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for ChannelMessageHandler { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn ChannelMessageHandler_free(this_ptr: ChannelMessageHandler) { } -impl Drop for ChannelMessageHandler { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} -/// A trait to describe an object which can receive routing messages. -/// -/// # Implementor DoS Warnings -/// -/// For `gossip_queries` messages there are potential DoS vectors when handling -/// inbound queries. Implementors using an on-disk network graph should be aware of -/// repeated disk I/O for queries accessing different parts of the network graph. -#[repr(C)] -pub struct RoutingMessageHandler { - pub this_arg: *mut c_void, - /// Handle an incoming node_announcement message, returning true if it should be forwarded on, - /// false or returning an Err otherwise. - #[must_use] - pub handle_node_announcement: extern "C" fn (this_arg: *const c_void, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ, - /// Handle a channel_announcement message, returning true if it should be forwarded on, false - /// or returning an Err otherwise. - #[must_use] - pub handle_channel_announcement: extern "C" fn (this_arg: *const c_void, msg: &crate::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ, - /// Handle an incoming channel_update message, returning true if it should be forwarded on, - /// false or returning an Err otherwise. - #[must_use] - pub handle_channel_update: extern "C" fn (this_arg: *const c_void, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ, - /// Handle some updates to the route graph that we learned due to an outbound failed payment. - pub handle_htlc_fail_channel_update: extern "C" fn (this_arg: *const c_void, update: &crate::ln::msgs::HTLCFailChannelUpdate), - /// Gets a subset of the channel announcements and updates required to dump our routing table - /// to a remote node, starting at the short_channel_id indicated by starting_point and - /// including the batch_amount entries immediately higher in numerical value than starting_point. - #[must_use] - pub get_next_channel_announcements: extern "C" fn (this_arg: *const c_void, starting_point: u64, batch_amount: u8) -> crate::c_types::derived::CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ, - /// Gets a subset of the node announcements required to dump our routing table to a remote node, - /// starting at the node *after* the provided publickey and including batch_amount entries - /// immediately higher (as defined by ::cmp) than starting_point. - /// If None is provided for starting_point, we start at the first node. - #[must_use] - pub get_next_node_announcements: extern "C" fn (this_arg: *const c_void, starting_point: crate::c_types::PublicKey, batch_amount: u8) -> crate::c_types::derived::CVec_NodeAnnouncementZ, - /// Called when a connection is established with a peer. This can be used to - /// perform routing table synchronization using a strategy defined by the - /// implementor. - pub sync_routing_table: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, init: &crate::ln::msgs::Init), - /// Handles the reply of a query we initiated to learn about channels - /// for a given range of blocks. We can expect to receive one or more - /// replies to a single query. - #[must_use] - pub handle_reply_channel_range: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: crate::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ, - /// Handles the reply of a query we initiated asking for routing gossip - /// messages for a list of channels. We should receive this message when - /// a node has completed its best effort to send us the pertaining routing - /// gossip messages. - #[must_use] - pub handle_reply_short_channel_ids_end: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: crate::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ, - /// Handles when a peer asks us to send a list of short_channel_ids - /// for the requested range of blocks. - #[must_use] - pub handle_query_channel_range: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: crate::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ, - /// Handles when a peer asks us to send routing gossip messages for a - /// list of short_channel_ids. - #[must_use] - pub handle_query_short_channel_ids: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: crate::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ, - pub MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider, - pub free: Option, -} -unsafe impl Send for RoutingMessageHandler {} -unsafe impl Sync for RoutingMessageHandler {} -impl lightning::util::events::MessageSendEventsProvider for RoutingMessageHandler { - fn get_and_clear_pending_msg_events(&self) -> Vec { - ::get_and_clear_pending_msg_events(&self.MessageSendEventsProvider) - } -} - -use lightning::ln::msgs::RoutingMessageHandler as rustRoutingMessageHandler; -impl rustRoutingMessageHandler for RoutingMessageHandler { - fn handle_node_announcement(&self, msg: &lightning::ln::msgs::NodeAnnouncement) -> Result { - let mut ret = (self.handle_node_announcement)(self.this_arg, &crate::ln::msgs::NodeAnnouncement { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }); - let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; - local_ret - } - fn handle_channel_announcement(&self, msg: &lightning::ln::msgs::ChannelAnnouncement) -> Result { - let mut ret = (self.handle_channel_announcement)(self.this_arg, &crate::ln::msgs::ChannelAnnouncement { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }); - let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; - local_ret - } - fn handle_channel_update(&self, msg: &lightning::ln::msgs::ChannelUpdate) -> Result { - let mut ret = (self.handle_channel_update)(self.this_arg, &crate::ln::msgs::ChannelUpdate { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false }); - let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; - local_ret - } - fn handle_htlc_fail_channel_update(&self, update: &lightning::ln::msgs::HTLCFailChannelUpdate) { - (self.handle_htlc_fail_channel_update)(self.this_arg, &crate::ln::msgs::HTLCFailChannelUpdate::from_native(&update)) - } - fn get_next_channel_announcements(&self, starting_point: u64, batch_amount: u8) -> Vec<(lightning::ln::msgs::ChannelAnnouncement, Option, Option)> { - let mut ret = (self.get_next_channel_announcements)(self.this_arg, starting_point, batch_amount); - let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item.to_rust(); let mut local_orig_ret_0_1 = if orig_ret_0_1.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(orig_ret_0_1.take_inner()) } }) }; let mut local_orig_ret_0_2 = if orig_ret_0_2.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(orig_ret_0_2.take_inner()) } }) }; let mut local_ret_0 = (*unsafe { Box::from_raw(orig_ret_0_0.take_inner()) }, local_orig_ret_0_1, local_orig_ret_0_2); local_ret_0 }); }; - local_ret - } - fn get_next_node_announcements(&self, starting_point: Option<&bitcoin::secp256k1::key::PublicKey>, batch_amount: u8) -> Vec { - let mut local_starting_point = if starting_point.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(starting_point.unwrap())) } }; - let mut ret = (self.get_next_node_announcements)(self.this_arg, local_starting_point, batch_amount); - let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; - local_ret - } - fn sync_routing_table(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, init: &lightning::ln::msgs::Init) { - (self.sync_routing_table)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::ln::msgs::Init { inner: unsafe { (init as *const _) as *mut _ }, is_owned: false }) - } - fn handle_reply_channel_range(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: lightning::ln::msgs::ReplyChannelRange) -> Result<(), lightning::ln::msgs::LightningError> { - let mut ret = (self.handle_reply_channel_range)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::ln::msgs::ReplyChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true }); - let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; - local_ret - } - fn handle_reply_short_channel_ids_end(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: lightning::ln::msgs::ReplyShortChannelIdsEnd) -> Result<(), lightning::ln::msgs::LightningError> { - let mut ret = (self.handle_reply_short_channel_ids_end)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::ln::msgs::ReplyShortChannelIdsEnd { inner: Box::into_raw(Box::new(msg)), is_owned: true }); - let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; - local_ret - } - fn handle_query_channel_range(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: lightning::ln::msgs::QueryChannelRange) -> Result<(), lightning::ln::msgs::LightningError> { - let mut ret = (self.handle_query_channel_range)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true }); - let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; - local_ret - } - fn handle_query_short_channel_ids(&self, their_node_id: &bitcoin::secp256k1::key::PublicKey, msg: lightning::ln::msgs::QueryShortChannelIds) -> Result<(), lightning::ln::msgs::LightningError> { - let mut ret = (self.handle_query_short_channel_ids)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg)), is_owned: true }); - let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; - local_ret - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for RoutingMessageHandler { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn RoutingMessageHandler_free(this_ptr: RoutingMessageHandler) { } -impl Drop for RoutingMessageHandler { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} -#[no_mangle] -pub extern "C" fn AcceptChannel_write(obj: &AcceptChannel) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn AcceptChannel_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeAcceptChannel) }) -} -#[no_mangle] -pub extern "C" fn AcceptChannel_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_AcceptChannelDecodeErrorZ { - 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::AcceptChannel { 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 -} -#[no_mangle] -pub extern "C" fn AnnouncementSignatures_write(obj: &AnnouncementSignatures) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn AnnouncementSignatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeAnnouncementSignatures) }) -} -#[no_mangle] -pub extern "C" fn AnnouncementSignatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_AnnouncementSignaturesDecodeErrorZ { - 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::AnnouncementSignatures { 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 -} -#[no_mangle] -pub extern "C" fn ChannelReestablish_write(obj: &ChannelReestablish) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ChannelReestablish_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelReestablish) }) -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn ClosingSigned_write(obj: &ClosingSigned) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ClosingSigned_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeClosingSigned) }) -} -#[no_mangle] -pub extern "C" fn ClosingSigned_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ClosingSignedDecodeErrorZ { - 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::ClosingSigned { 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 -} -#[no_mangle] -pub extern "C" fn CommitmentSigned_write(obj: &CommitmentSigned) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn CommitmentSigned_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentSigned) }) -} -#[no_mangle] -pub extern "C" fn CommitmentSigned_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CommitmentSignedDecodeErrorZ { - 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::CommitmentSigned { 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 -} -#[no_mangle] -pub extern "C" fn FundingCreated_write(obj: &FundingCreated) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn FundingCreated_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFundingCreated) }) -} -#[no_mangle] -pub extern "C" fn FundingCreated_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_FundingCreatedDecodeErrorZ { - 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::FundingCreated { 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 -} -#[no_mangle] -pub extern "C" fn FundingSigned_write(obj: &FundingSigned) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn FundingSigned_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFundingSigned) }) -} -#[no_mangle] -pub extern "C" fn FundingSigned_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_FundingSignedDecodeErrorZ { - 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::FundingSigned { 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 -} -#[no_mangle] -pub extern "C" fn FundingLocked_write(obj: &FundingLocked) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn FundingLocked_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFundingLocked) }) -} -#[no_mangle] -pub extern "C" fn FundingLocked_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_FundingLockedDecodeErrorZ { - 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::FundingLocked { 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 -} -#[no_mangle] -pub extern "C" fn Init_write(obj: &Init) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn Init_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInit) }) -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn OpenChannel_write(obj: &OpenChannel) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn OpenChannel_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOpenChannel) }) -} -#[no_mangle] -pub extern "C" fn OpenChannel_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_OpenChannelDecodeErrorZ { - 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::OpenChannel { 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 -} -#[no_mangle] -pub extern "C" fn RevokeAndACK_write(obj: &RevokeAndACK) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn RevokeAndACK_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRevokeAndACK) }) -} -#[no_mangle] -pub extern "C" fn RevokeAndACK_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RevokeAndACKDecodeErrorZ { - 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::RevokeAndACK { 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 -} -#[no_mangle] -pub extern "C" fn Shutdown_write(obj: &Shutdown) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn Shutdown_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeShutdown) }) -} -#[no_mangle] -pub extern "C" fn Shutdown_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ShutdownDecodeErrorZ { - 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::Shutdown { 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 -} -#[no_mangle] -pub extern "C" fn UpdateFailHTLC_write(obj: &UpdateFailHTLC) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn UpdateFailHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFailHTLC) }) -} -#[no_mangle] -pub extern "C" fn UpdateFailHTLC_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UpdateFailHTLCDecodeErrorZ { - 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::UpdateFailHTLC { 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 -} -#[no_mangle] -pub extern "C" fn UpdateFailMalformedHTLC_write(obj: &UpdateFailMalformedHTLC) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn UpdateFailMalformedHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFailMalformedHTLC) }) -} -#[no_mangle] -pub extern "C" fn UpdateFailMalformedHTLC_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UpdateFailMalformedHTLCDecodeErrorZ { - 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::UpdateFailMalformedHTLC { 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 -} -#[no_mangle] -pub extern "C" fn UpdateFee_write(obj: &UpdateFee) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn UpdateFee_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFee) }) -} -#[no_mangle] -pub extern "C" fn UpdateFee_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UpdateFeeDecodeErrorZ { - 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::UpdateFee { 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 -} -#[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_write(obj: &UpdateFulfillHTLC) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn UpdateFulfillHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFulfillHTLC) }) -} -#[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UpdateFulfillHTLCDecodeErrorZ { - 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::UpdateFulfillHTLC { 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 -} -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_write(obj: &UpdateAddHTLC) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn UpdateAddHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateAddHTLC) }) -} -#[no_mangle] -pub extern "C" fn UpdateAddHTLC_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UpdateAddHTLCDecodeErrorZ { - 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::UpdateAddHTLC { 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 -} -#[no_mangle] -pub extern "C" fn Ping_write(obj: &Ping) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn Ping_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePing) }) -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn Pong_write(obj: &Pong) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn Pong_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePong) }) -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_write(obj: &UnsignedChannelAnnouncement) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn UnsignedChannelAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedChannelAnnouncement) }) -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_write(obj: &ChannelAnnouncement) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ChannelAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelAnnouncement) }) -} -#[no_mangle] -pub extern "C" fn ChannelAnnouncement_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelAnnouncementDecodeErrorZ { - 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::ChannelAnnouncement { 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 -} -#[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_write(obj: &UnsignedChannelUpdate) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn UnsignedChannelUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedChannelUpdate) }) -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn ChannelUpdate_write(obj: &ChannelUpdate) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ChannelUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdate) }) -} -#[no_mangle] -pub extern "C" fn ChannelUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelUpdateDecodeErrorZ { - 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::ChannelUpdate { 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 -} -#[no_mangle] -pub extern "C" fn ErrorMessage_write(obj: &ErrorMessage) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ErrorMessage_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeErrorMessage) }) -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_write(obj: &UnsignedNodeAnnouncement) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn UnsignedNodeAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedNodeAnnouncement) }) -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn NodeAnnouncement_write(obj: &NodeAnnouncement) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn NodeAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncement) }) -} -#[no_mangle] -pub extern "C" fn NodeAnnouncement_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementDecodeErrorZ { - 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::NodeAnnouncement { 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 -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn QueryShortChannelIds_write(obj: &QueryShortChannelIds) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn QueryShortChannelIds_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeQueryShortChannelIds) }) -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn ReplyShortChannelIdsEnd_write(obj: &ReplyShortChannelIdsEnd) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ReplyShortChannelIdsEnd_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeReplyShortChannelIdsEnd) }) -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn QueryChannelRange_write(obj: &QueryChannelRange) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn QueryChannelRange_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeQueryChannelRange) }) -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn ReplyChannelRange_write(obj: &ReplyChannelRange) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ReplyChannelRange_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeReplyChannelRange) }) -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn GossipTimestampFilter_write(obj: &GossipTimestampFilter) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn GossipTimestampFilter_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeGossipTimestampFilter) }) -} diff --git a/lightning-c-bindings/src/ln/peer_handler.rs b/lightning-c-bindings/src/ln/peer_handler.rs deleted file mode 100644 index 96966a859..000000000 --- a/lightning-c-bindings/src/ln/peer_handler.rs +++ /dev/null @@ -1,790 +0,0 @@ -//! Top level peer message handling and socket handling logic lives here. -//! -//! Instead of actually servicing sockets ourselves we require that you implement the -//! SocketDescriptor interface and use that to receive actions which you should perform on the -//! socket, and call into PeerManager with bytes read from the socket. The PeerManager will then -//! call into the provided message handlers (probably a ChannelManager and NetGraphmsgHandler) with messages -//! they should handle, and encoding/sending response messages. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - - -use lightning::ln::peer_handler::IgnoringMessageHandler as nativeIgnoringMessageHandlerImport; -type nativeIgnoringMessageHandler = nativeIgnoringMessageHandlerImport; - -/// A dummy struct which implements `RoutingMessageHandler` without storing any routing information -/// or doing any processing. You can provide one of these as the route_handler in a MessageHandler. -#[must_use] -#[repr(C)] -pub struct IgnoringMessageHandler { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeIgnoringMessageHandler, - pub is_owned: bool, -} - -impl Drop for IgnoringMessageHandler { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeIgnoringMessageHandler>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn IgnoringMessageHandler_free(this_ptr: IgnoringMessageHandler) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn IgnoringMessageHandler_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeIgnoringMessageHandler); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl IgnoringMessageHandler { - pub(crate) fn take_inner(mut self) -> *mut nativeIgnoringMessageHandler { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -#[must_use] -#[no_mangle] -pub extern "C" fn IgnoringMessageHandler_new() -> IgnoringMessageHandler { - IgnoringMessageHandler { inner: Box::into_raw(Box::new(nativeIgnoringMessageHandler { - })), is_owned: true } -} -impl From for crate::util::events::MessageSendEventsProvider { - fn from(obj: nativeIgnoringMessageHandler) -> Self { - let mut rust_obj = IgnoringMessageHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = IgnoringMessageHandler_as_MessageSendEventsProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(IgnoringMessageHandler_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn IgnoringMessageHandler_as_MessageSendEventsProvider(this_arg: &IgnoringMessageHandler) -> crate::util::events::MessageSendEventsProvider { - crate::util::events::MessageSendEventsProvider { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events, - } -} - -#[must_use] -extern "C" fn IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { - let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); }; - local_ret.into() -} - -impl From for crate::ln::msgs::RoutingMessageHandler { - fn from(obj: nativeIgnoringMessageHandler) -> Self { - let mut rust_obj = IgnoringMessageHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = IgnoringMessageHandler_as_RoutingMessageHandler(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(IgnoringMessageHandler_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn IgnoringMessageHandler_as_RoutingMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::ln::msgs::RoutingMessageHandler { - crate::ln::msgs::RoutingMessageHandler { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - handle_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_node_announcement, - handle_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_announcement, - handle_channel_update: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update, - handle_htlc_fail_channel_update: IgnoringMessageHandler_RoutingMessageHandler_handle_htlc_fail_channel_update, - get_next_channel_announcements: IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcements, - get_next_node_announcements: IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcements, - sync_routing_table: IgnoringMessageHandler_RoutingMessageHandler_sync_routing_table, - handle_reply_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_channel_range, - handle_reply_short_channel_ids_end: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end, - handle_query_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_query_channel_range, - handle_query_short_channel_ids: IgnoringMessageHandler_RoutingMessageHandler_handle_query_short_channel_ids, - MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - get_and_clear_pending_msg_events: IgnoringMessageHandler_RoutingMessageHandler_get_and_clear_pending_msg_events, - }, - } -} - -#[must_use] -extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, _msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ { - let mut ret = >::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, unsafe { &*_msg.inner }); - 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 -} -#[must_use] -extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, _msg: &crate::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ { - let mut ret = >::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, unsafe { &*_msg.inner }); - 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 -} -#[must_use] -extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, _msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ { - let mut ret = >::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, unsafe { &*_msg.inner }); - 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 -} -extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, _update: &crate::ln::msgs::HTLCFailChannelUpdate) { - >::handle_htlc_fail_channel_update(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &_update.to_native()) -} -#[must_use] -extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcements(this_arg: *const c_void, mut _starting_point: u64, mut _batch_amount: u8) -> crate::c_types::derived::CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ { - let mut ret = >::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _starting_point, _batch_amount); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_1 = crate::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { std::ptr::null_mut() } else { { Box::into_raw(Box::new((orig_ret_0_1.unwrap()))) } }, is_owned: true }; let mut local_orig_ret_0_2 = crate::ln::msgs::ChannelUpdate { inner: if orig_ret_0_2.is_none() { std::ptr::null_mut() } else { { Box::into_raw(Box::new((orig_ret_0_2.unwrap()))) } }, is_owned: true }; let mut local_ret_0 = (crate::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(orig_ret_0_0)), is_owned: true }, local_orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }); }; - local_ret.into() -} -#[must_use] -extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcements(this_arg: *const c_void, mut _starting_point: crate::c_types::PublicKey, mut _batch_amount: u8) -> crate::c_types::derived::CVec_NodeAnnouncementZ { - let mut local__starting_point_base = if _starting_point.is_null() { None } else { Some( { _starting_point.into_rust() }) }; let mut local__starting_point = local__starting_point_base.as_ref(); - let mut ret = >::get_next_node_announcements(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, local__starting_point, _batch_amount); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(item)), is_owned: true } }); }; - local_ret.into() -} -extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_sync_routing_table(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, _init: &crate::ln::msgs::Init) { - >::sync_routing_table(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &_their_node_id.into_rust(), unsafe { &*_init.inner }) -} -#[must_use] -extern "C" fn IgnoringMessageHandler_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 = >::handle_reply_channel_range(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &_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*/ }).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 -} -#[must_use] -extern "C" fn IgnoringMessageHandler_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 = >::handle_reply_short_channel_ids_end(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &_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*/ }).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 -} -#[must_use] -extern "C" fn IgnoringMessageHandler_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 = >::handle_query_channel_range(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &_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*/ }).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 -} -#[must_use] -extern "C" fn IgnoringMessageHandler_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 = >::handle_query_short_channel_ids(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &_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*/ }).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 -} -#[must_use] -extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { - let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); }; - local_ret.into() -} - - -use lightning::ln::peer_handler::ErroringMessageHandler as nativeErroringMessageHandlerImport; -type nativeErroringMessageHandler = nativeErroringMessageHandlerImport; - -/// A dummy struct which implements `ChannelMessageHandler` without having any channels. -/// You can provide one of these as the route_handler in a MessageHandler. -#[must_use] -#[repr(C)] -pub struct ErroringMessageHandler { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeErroringMessageHandler, - pub is_owned: bool, -} - -impl Drop for ErroringMessageHandler { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeErroringMessageHandler>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ErroringMessageHandler_free(this_ptr: ErroringMessageHandler) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ErroringMessageHandler_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeErroringMessageHandler); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ErroringMessageHandler { - pub(crate) fn take_inner(mut self) -> *mut nativeErroringMessageHandler { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Constructs a new ErroringMessageHandler -#[must_use] -#[no_mangle] -pub extern "C" fn ErroringMessageHandler_new() -> ErroringMessageHandler { - let mut ret = lightning::ln::peer_handler::ErroringMessageHandler::new(); - ErroringMessageHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -impl From for crate::util::events::MessageSendEventsProvider { - fn from(obj: nativeErroringMessageHandler) -> Self { - let mut rust_obj = ErroringMessageHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = ErroringMessageHandler_as_MessageSendEventsProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(ErroringMessageHandler_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn ErroringMessageHandler_as_MessageSendEventsProvider(this_arg: &ErroringMessageHandler) -> crate::util::events::MessageSendEventsProvider { - crate::util::events::MessageSendEventsProvider { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events, - } -} - -#[must_use] -extern "C" fn ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { - let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); }; - local_ret.into() -} - -impl From for crate::ln::msgs::ChannelMessageHandler { - fn from(obj: nativeErroringMessageHandler) -> Self { - let mut rust_obj = ErroringMessageHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = ErroringMessageHandler_as_ChannelMessageHandler(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(ErroringMessageHandler_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn ErroringMessageHandler_as_ChannelMessageHandler(this_arg: &ErroringMessageHandler) -> crate::ln::msgs::ChannelMessageHandler { - crate::ln::msgs::ChannelMessageHandler { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - handle_open_channel: ErroringMessageHandler_ChannelMessageHandler_handle_open_channel, - handle_accept_channel: ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel, - handle_funding_created: ErroringMessageHandler_ChannelMessageHandler_handle_funding_created, - handle_funding_signed: ErroringMessageHandler_ChannelMessageHandler_handle_funding_signed, - handle_funding_locked: ErroringMessageHandler_ChannelMessageHandler_handle_funding_locked, - handle_shutdown: ErroringMessageHandler_ChannelMessageHandler_handle_shutdown, - handle_closing_signed: ErroringMessageHandler_ChannelMessageHandler_handle_closing_signed, - handle_update_add_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_add_htlc, - handle_update_fulfill_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fulfill_htlc, - handle_update_fail_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_htlc, - handle_update_fail_malformed_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_malformed_htlc, - handle_commitment_signed: ErroringMessageHandler_ChannelMessageHandler_handle_commitment_signed, - handle_revoke_and_ack: ErroringMessageHandler_ChannelMessageHandler_handle_revoke_and_ack, - handle_update_fee: ErroringMessageHandler_ChannelMessageHandler_handle_update_fee, - handle_announcement_signatures: ErroringMessageHandler_ChannelMessageHandler_handle_announcement_signatures, - peer_disconnected: ErroringMessageHandler_ChannelMessageHandler_peer_disconnected, - peer_connected: ErroringMessageHandler_ChannelMessageHandler_peer_connected, - handle_channel_reestablish: ErroringMessageHandler_ChannelMessageHandler_handle_channel_reestablish, - handle_error: ErroringMessageHandler_ChannelMessageHandler_handle_error, - MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - get_and_clear_pending_msg_events: ErroringMessageHandler_ChannelMessageHandler_get_and_clear_pending_msg_events, - }, - } -} - -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_open_channel(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut _their_features: crate::ln::features::InitFeatures, msg: &crate::ln::msgs::OpenChannel) { - >::handle_open_channel(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(_their_features.take_inner()) }, unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut _their_features: crate::ln::features::InitFeatures, msg: &crate::ln::msgs::AcceptChannel) { - >::handle_accept_channel(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(_their_features.take_inner()) }, unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_funding_created(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingCreated) { - >::handle_funding_created(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_funding_signed(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingSigned) { - >::handle_funding_signed(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_funding_locked(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingLocked) { - >::handle_funding_locked(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_shutdown(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, _their_features: &crate::ln::features::InitFeatures, msg: &crate::ln::msgs::Shutdown) { - >::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*_their_features.inner }, unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_closing_signed(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ClosingSigned) { - >::handle_closing_signed(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_add_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateAddHTLC) { - >::handle_update_add_htlc(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_fulfill_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFulfillHTLC) { - >::handle_update_fulfill_htlc(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFailHTLC) { - >::handle_update_fail_htlc(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_malformed_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFailMalformedHTLC) { - >::handle_update_fail_malformed_htlc(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_commitment_signed(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::CommitmentSigned) { - >::handle_commitment_signed(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_revoke_and_ack(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::RevokeAndACK) { - >::handle_revoke_and_ack(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_fee(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFee) { - >::handle_update_fee(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_announcement_signatures(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::AnnouncementSignatures) { - >::handle_announcement_signatures(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_channel_reestablish(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ChannelReestablish) { - >::handle_channel_reestablish(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_peer_disconnected(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _no_connection_possible: bool) { - >::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), _no_connection_possible) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_peer_connected(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, _msg: &crate::ln::msgs::Init) { - >::peer_connected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), unsafe { &*_msg.inner }) -} -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_error(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, _msg: &crate::ln::msgs::ErrorMessage) { - >::handle_error(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), unsafe { &*_msg.inner }) -} -#[must_use] -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { - let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); }; - local_ret.into() -} - - -use lightning::ln::peer_handler::MessageHandler as nativeMessageHandlerImport; -type nativeMessageHandler = nativeMessageHandlerImport; - -/// Provides references to trait impls which handle different types of messages. -#[must_use] -#[repr(C)] -pub struct MessageHandler { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeMessageHandler, - pub is_owned: bool, -} - -impl Drop for MessageHandler { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeMessageHandler>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn MessageHandler_free(this_ptr: MessageHandler) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn MessageHandler_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMessageHandler); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl MessageHandler { - pub(crate) fn take_inner(mut self) -> *mut nativeMessageHandler { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// A message handler which handles messages specific to channels. Usually this is just a -/// ChannelManager object or a ErroringMessageHandler. -#[no_mangle] -pub extern "C" fn MessageHandler_get_chan_handler(this_ptr: &MessageHandler) -> *const crate::ln::msgs::ChannelMessageHandler { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chan_handler; - &(*inner_val) -} -/// A message handler which handles messages specific to channels. Usually this is just a -/// ChannelManager object or a ErroringMessageHandler. -#[no_mangle] -pub extern "C" fn MessageHandler_set_chan_handler(this_ptr: &mut MessageHandler, mut val: crate::ln::msgs::ChannelMessageHandler) { - unsafe { &mut *this_ptr.inner }.chan_handler = val; -} -/// A message handler which handles messages updating our knowledge of the network channel -/// graph. Usually this is just a NetGraphMsgHandlerMonitor object or an IgnoringMessageHandler. -#[no_mangle] -pub extern "C" fn MessageHandler_get_route_handler(this_ptr: &MessageHandler) -> *const crate::ln::msgs::RoutingMessageHandler { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.route_handler; - &(*inner_val) -} -/// A message handler which handles messages updating our knowledge of the network channel -/// graph. Usually this is just a NetGraphMsgHandlerMonitor object or an IgnoringMessageHandler. -#[no_mangle] -pub extern "C" fn MessageHandler_set_route_handler(this_ptr: &mut MessageHandler, mut val: crate::ln::msgs::RoutingMessageHandler) { - unsafe { &mut *this_ptr.inner }.route_handler = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn MessageHandler_new(mut chan_handler_arg: crate::ln::msgs::ChannelMessageHandler, mut route_handler_arg: crate::ln::msgs::RoutingMessageHandler) -> MessageHandler { - MessageHandler { inner: Box::into_raw(Box::new(nativeMessageHandler { - chan_handler: chan_handler_arg, - route_handler: route_handler_arg, - })), is_owned: true } -} -/// Provides an object which can be used to send data to and which uniquely identifies a connection -/// to a remote host. You will need to be able to generate multiple of these which meet Eq and -/// implement Hash to meet the PeerManager API. -/// -/// For efficiency, Clone should be relatively cheap for this type. -/// -/// You probably want to just extend an int and put a file descriptor in a struct and implement -/// send_data. Note that if you are using a higher-level net library that may call close() itself, -/// be careful to ensure you don't have races whereby you might register a new connection with an -/// fd which is the same as a previous one which has yet to be removed via -/// PeerManager::socket_disconnected(). -#[repr(C)] -pub struct SocketDescriptor { - pub this_arg: *mut c_void, - /// Attempts to send some data from the given slice to the peer. - /// - /// Returns the amount of data which was sent, possibly 0 if the socket has since disconnected. - /// Note that in the disconnected case, socket_disconnected must still fire and further write - /// attempts may occur until that time. - /// - /// If the returned size is smaller than data.len(), a write_available event must - /// trigger the next time more data can be written. Additionally, until the a send_data event - /// completes fully, no further read_events should trigger on the same peer! - /// - /// If a read_event on this descriptor had previously returned true (indicating that read - /// events should be paused to prevent DoS in the send buffer), resume_read may be set - /// indicating that read events on this descriptor should resume. A resume_read of false does - /// *not* imply that further read events should be paused. - #[must_use] - pub send_data: extern "C" fn (this_arg: *mut c_void, data: crate::c_types::u8slice, resume_read: bool) -> usize, - /// Disconnect the socket pointed to by this SocketDescriptor. Once this function returns, no - /// more calls to write_buffer_space_avail, read_event or socket_disconnected may be made with - /// this descriptor. No socket_disconnected call should be generated as a result of this call, - /// though races may occur whereby disconnect_socket is called after a call to - /// socket_disconnected but prior to socket_disconnected returning. - pub disconnect_socket: extern "C" fn (this_arg: *mut c_void), - pub eq: extern "C" fn (this_arg: *const c_void, other_arg: &SocketDescriptor) -> bool, - pub hash: extern "C" fn (this_arg: *const c_void) -> u64, - pub clone: Option *mut c_void>, - pub free: Option, -} -impl std::cmp::Eq for SocketDescriptor {} -impl std::cmp::PartialEq for SocketDescriptor { - fn eq(&self, o: &Self) -> bool { (self.eq)(self.this_arg, o) } -} -impl std::hash::Hash for SocketDescriptor { - fn hash(&self, hasher: &mut H) { hasher.write_u64((self.hash)(self.this_arg)) } -} -#[no_mangle] -pub extern "C" fn SocketDescriptor_clone(orig: &SocketDescriptor) -> SocketDescriptor { - SocketDescriptor { - this_arg: if let Some(f) = orig.clone { (f)(orig.this_arg) } else { orig.this_arg }, - send_data: orig.send_data.clone(), - disconnect_socket: orig.disconnect_socket.clone(), - eq: orig.eq.clone(), - hash: orig.hash.clone(), - clone: orig.clone.clone(), - free: orig.free.clone(), - } -} -impl Clone for SocketDescriptor { - fn clone(&self) -> Self { - SocketDescriptor_clone(self) - } -} - -use lightning::ln::peer_handler::SocketDescriptor as rustSocketDescriptor; -impl rustSocketDescriptor for SocketDescriptor { - fn send_data(&mut self, data: &[u8], resume_read: bool) -> usize { - let mut local_data = crate::c_types::u8slice::from_slice(data); - let mut ret = (self.send_data)(self.this_arg, local_data, resume_read); - ret - } - fn disconnect_socket(&mut self) { - (self.disconnect_socket)(self.this_arg) - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for SocketDescriptor { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn SocketDescriptor_free(this_ptr: SocketDescriptor) { } -impl Drop for SocketDescriptor { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} - -use lightning::ln::peer_handler::PeerHandleError as nativePeerHandleErrorImport; -type nativePeerHandleError = nativePeerHandleErrorImport; - -/// 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 -/// descriptor. -#[must_use] -#[repr(C)] -pub struct PeerHandleError { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativePeerHandleError, - pub is_owned: bool, -} - -impl Drop for PeerHandleError { - fn drop(&mut self) { - if self.is_owned && !<*mut nativePeerHandleError>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn PeerHandleError_free(this_ptr: PeerHandleError) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn PeerHandleError_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativePeerHandleError); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl PeerHandleError { - pub(crate) fn take_inner(mut self) -> *mut nativePeerHandleError { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// 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. -#[no_mangle] -pub extern "C" fn PeerHandleError_get_no_connection_possible(this_ptr: &PeerHandleError) -> bool { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.no_connection_possible; - (*inner_val) -} -/// 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. -#[no_mangle] -pub extern "C" fn PeerHandleError_set_no_connection_possible(this_ptr: &mut PeerHandleError, mut val: bool) { - unsafe { &mut *this_ptr.inner }.no_connection_possible = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn PeerHandleError_new(mut no_connection_possible_arg: bool) -> PeerHandleError { - PeerHandleError { inner: Box::into_raw(Box::new(nativePeerHandleError { - no_connection_possible: no_connection_possible_arg, - })), is_owned: true } -} -impl Clone for PeerHandleError { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativePeerHandleError>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn 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() -} - -use lightning::ln::peer_handler::PeerManager as nativePeerManagerImport; -type nativePeerManager = nativePeerManagerImport; - -/// A PeerManager manages a set of peers, described by their SocketDescriptor and marshalls socket -/// events into messages which it passes on to its MessageHandlers. -/// -/// Rather than using a plain PeerManager, it is preferable to use either a SimpleArcPeerManager -/// a SimpleRefPeerManager, for conciseness. See their documentation for more details, but -/// essentially you should default to using a SimpleRefPeerManager, and use a -/// SimpleArcPeerManager when you require a PeerManager with a static lifetime, such as when -/// you're using lightning-net-tokio. -#[must_use] -#[repr(C)] -pub struct PeerManager { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativePeerManager, - pub is_owned: bool, -} - -impl Drop for PeerManager { - fn drop(&mut self) { - if self.is_owned && !<*mut nativePeerManager>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn PeerManager_free(this_ptr: PeerManager) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn PeerManager_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativePeerManager); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl PeerManager { - pub(crate) fn take_inner(mut self) -> *mut nativePeerManager { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Constructs a new PeerManager with the given message handlers and node_id secret key -/// ephemeral_random_data is used to derive per-connection ephemeral keys and must be -/// cryptographically secure random bytes. -#[must_use] -#[no_mangle] -pub extern "C" fn PeerManager_new(mut message_handler: crate::ln::peer_handler::MessageHandler, mut our_node_secret: crate::c_types::SecretKey, ephemeral_random_data: *const [u8; 32], mut logger: crate::util::logger::Logger) -> PeerManager { - let mut ret = lightning::ln::peer_handler::PeerManager::new(*unsafe { Box::from_raw(message_handler.take_inner()) }, our_node_secret.into_rust(), unsafe { &*ephemeral_random_data}, logger); - PeerManager { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Get the list of node ids for peers which have completed the initial handshake. -/// -/// For outbound connections, this will be the same as the their_node_id parameter passed in to -/// new_outbound_connection, however entries will only appear once the initial handshake has -/// completed and we are sure the remote peer has the private key for the given node_id. -#[must_use] -#[no_mangle] -pub extern "C" fn PeerManager_get_peer_node_ids(this_arg: &PeerManager) -> crate::c_types::derived::CVec_PublicKeyZ { - let mut ret = unsafe { &*this_arg.inner }.get_peer_node_ids(); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::PublicKey::from_rust(&item) }); }; - local_ret.into() -} - -/// Indicates a new outbound connection has been established to a node with the given node_id. -/// Note that if an Err is returned here you MUST NOT call socket_disconnected for the new -/// descriptor but must disconnect the connection immediately. -/// -/// Returns a small number of bytes to send to the remote node (currently always 50). -/// -/// Panics if descriptor is duplicative with some other descriptor which has not yet had a -/// socket_disconnected(). -#[must_use] -#[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 { - 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 mut 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 -} - -/// Indicates a new inbound connection has been established. -/// -/// May refuse the connection by returning an Err, but will never write bytes to the remote end -/// (outbound connector always speaks first). Note that if an Err is returned here you MUST NOT -/// call socket_disconnected for the new descriptor but must disconnect the connection -/// immediately. -/// -/// Panics if descriptor is duplicative with some other descriptor which has not yet had -/// socket_disconnected called. -#[must_use] -#[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 { - 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*/ }).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 -} - -/// Indicates that there is room to write data to the given socket descriptor. -/// -/// May return an Err to indicate that the connection should be closed. -/// -/// Will most likely call send_data on the descriptor passed in (or the descriptor handed into -/// new_*\\_connection) before returning. Thus, be very careful with reentrancy issues! The -/// invariants around calling write_buffer_space_avail in case a write did not fully complete -/// must still hold - be ready to call write_buffer_space_avail again if a write call generated -/// here isn't sufficient! Panics if the descriptor was not previously registered in a -/// new_\\*_connection event. -#[must_use] -#[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 { - 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*/ }).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 -} - -/// Indicates that data was read from the given socket descriptor. -/// -/// May return an Err to indicate that the connection should be closed. -/// -/// Will *not* call back into send_data on any descriptors to avoid reentrancy complexity. -/// Thus, however, you almost certainly want to call process_events() after any read_event to -/// generate send_data calls to handle responses. -/// -/// If Ok(true) is returned, further read_events should not be triggered until a send_data call -/// on this file descriptor has resume_read set (preventing DoS issues in the send buffer). -/// -/// Panics if the descriptor was not previously registered in a new_*_connection event. -#[must_use] -#[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 { - 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 }).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 -} - -/// Checks for any events generated by our handlers and processes them. Includes sending most -/// response messages as well as messages generated by calls to handler functions directly (eg -/// functions like ChannelManager::process_pending_htlc_forward or send_payment). -#[no_mangle] -pub extern "C" fn PeerManager_process_events(this_arg: &PeerManager) { - unsafe { &*this_arg.inner }.process_events() -} - -/// Indicates that the given socket descriptor's connection is now closed. -/// -/// This must only be called if the socket has been disconnected by the peer or your own -/// decision to disconnect it and must NOT be called in any case where other parts of this -/// library (eg PeerHandleError, explicit disconnect_socket calls) instruct you to disconnect -/// the peer. -/// -/// Panics if the descriptor was not previously registered in a successful new_*_connection event. -#[no_mangle] -pub extern "C" fn PeerManager_socket_disconnected(this_arg: &PeerManager, descriptor: &crate::ln::peer_handler::SocketDescriptor) { - unsafe { &*this_arg.inner }.socket_disconnected(descriptor) -} - -/// Disconnect a peer given its node id. -/// -/// Set no_connection_possible to true to prevent any further connection with this peer, -/// force-closing any channels we have with it. -/// -/// If a peer is connected, this will call `disconnect_socket` on the descriptor for the peer, -/// so be careful about reentrancy issues. -#[no_mangle] -pub extern "C" fn PeerManager_disconnect_by_node_id(this_arg: &PeerManager, mut node_id: crate::c_types::PublicKey, mut no_connection_possible: bool) { - unsafe { &*this_arg.inner }.disconnect_by_node_id(node_id.into_rust(), no_connection_possible) -} - -/// This function should be called roughly once every 30 seconds. -/// It will send pings to each peer and disconnect those which did not respond to the last round of pings. -/// Will most likely call send_data on all of the registered descriptors, thus, be very careful with reentrancy issues! -#[no_mangle] -pub extern "C" fn PeerManager_timer_tick_occured(this_arg: &PeerManager) { - unsafe { &*this_arg.inner }.timer_tick_occured() -} - diff --git a/lightning-c-bindings/src/routing/mod.rs b/lightning-c-bindings/src/routing/mod.rs deleted file mode 100644 index 4311ff353..000000000 --- a/lightning-c-bindings/src/routing/mod.rs +++ /dev/null @@ -1,8 +0,0 @@ -//! Structs and impls for receiving messages about the network and storing the topology live here. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - -pub mod router; -pub mod network_graph; diff --git a/lightning-c-bindings/src/routing/network_graph.rs b/lightning-c-bindings/src/routing/network_graph.rs deleted file mode 100644 index 72910e8a3..000000000 --- a/lightning-c-bindings/src/routing/network_graph.rs +++ /dev/null @@ -1,1116 +0,0 @@ -//! The top-level network map tracking logic lives here. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - - -use lightning::routing::network_graph::NetworkGraph as nativeNetworkGraphImport; -type nativeNetworkGraph = nativeNetworkGraphImport; - -/// Represents the network as nodes and channels between them -#[must_use] -#[repr(C)] -pub struct NetworkGraph { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeNetworkGraph, - pub is_owned: bool, -} - -impl Drop for NetworkGraph { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn NetworkGraph_free(this_ptr: NetworkGraph) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetworkGraph); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl NetworkGraph { - pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -impl Clone for NetworkGraph { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeNetworkGraph>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn NetworkGraph_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNetworkGraph)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn NetworkGraph_clone(orig: &NetworkGraph) -> NetworkGraph { - orig.clone() -} - -use lightning::routing::network_graph::LockedNetworkGraph as nativeLockedNetworkGraphImport; -type nativeLockedNetworkGraph = nativeLockedNetworkGraphImport<'static>; - -/// A simple newtype for RwLockReadGuard<'a, NetworkGraph>. -/// This exists only to make accessing a RwLock possible from -/// the C bindings, as it can be done directly in Rust code. -#[must_use] -#[repr(C)] -pub struct LockedNetworkGraph { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeLockedNetworkGraph, - pub is_owned: bool, -} - -impl Drop for LockedNetworkGraph { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeLockedNetworkGraph>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn LockedNetworkGraph_free(this_ptr: LockedNetworkGraph) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn LockedNetworkGraph_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLockedNetworkGraph); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl LockedNetworkGraph { - pub(crate) fn take_inner(mut self) -> *mut nativeLockedNetworkGraph { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} - -use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport; -type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport; - -/// Receives and validates network updates from peers, -/// stores authentic and relevant data as a network graph. -/// This network graph is then used for routing payments. -/// Provides interface to help with initial routing sync by -/// serving historical announcements. -#[must_use] -#[repr(C)] -pub struct NetGraphMsgHandler { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeNetGraphMsgHandler, - pub is_owned: bool, -} - -impl Drop for NetGraphMsgHandler { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeNetGraphMsgHandler>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn NetGraphMsgHandler_free(this_ptr: NetGraphMsgHandler) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn NetGraphMsgHandler_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetGraphMsgHandler); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl NetGraphMsgHandler { - pub(crate) fn take_inner(mut self) -> *mut nativeNetGraphMsgHandler { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Creates a new tracker of the actual state of the network of channels and nodes, -/// assuming a fresh network graph. -/// Chain monitor is used to make sure announced channels exist on-chain, -/// channel data is correct, and that the announcement is signed with -/// channel owners' keys. -#[must_use] -#[no_mangle] -pub extern "C" fn NetGraphMsgHandler_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes, chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger) -> NetGraphMsgHandler { - let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) }; - let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap(), local_chain_access, logger); - NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Creates a new tracker of the actual state of the network of channels and nodes, -/// assuming an existing Network Graph. -#[must_use] -#[no_mangle] -pub extern "C" fn NetGraphMsgHandler_from_net_graph(chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger, mut network_graph: crate::routing::network_graph::NetworkGraph) -> NetGraphMsgHandler { - let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) }; - let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::from_net_graph(local_chain_access, logger, *unsafe { Box::from_raw(network_graph.take_inner()) }); - NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Adds a provider used to check new announcements. Does not affect -/// existing announcements unless they are updated. -/// Add, update or remove the provider would replace the current one. -#[no_mangle] -pub extern "C" fn NetGraphMsgHandler_add_chain_access(this_arg: &mut NetGraphMsgHandler, chain_access: *mut crate::chain::Access) { - let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) }; - unsafe { &mut (*(this_arg.inner as *mut nativeNetGraphMsgHandler)) }.add_chain_access(local_chain_access) -} - -/// Take a read lock on the network_graph and return it in the C-bindings -/// newtype helper. This is likely only useful when called via the C -/// bindings as you can call `self.network_graph.read().unwrap()` in Rust -/// yourself. -#[must_use] -#[no_mangle] -pub extern "C" fn NetGraphMsgHandler_read_locked_graph(this_arg: &NetGraphMsgHandler) -> crate::routing::network_graph::LockedNetworkGraph { - let mut ret = unsafe { &*this_arg.inner }.read_locked_graph(); - crate::routing::network_graph::LockedNetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// Get a reference to the NetworkGraph which this read-lock contains. -#[must_use] -#[no_mangle] -pub extern "C" fn LockedNetworkGraph_graph(this_arg: &LockedNetworkGraph) -> crate::routing::network_graph::NetworkGraph { - let mut ret = unsafe { &*this_arg.inner }.graph(); - crate::routing::network_graph::NetworkGraph { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } -} - -impl From for crate::ln::msgs::RoutingMessageHandler { - fn from(obj: nativeNetGraphMsgHandler) -> Self { - let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = NetGraphMsgHandler_as_RoutingMessageHandler(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(NetGraphMsgHandler_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: &NetGraphMsgHandler) -> crate::ln::msgs::RoutingMessageHandler { - crate::ln::msgs::RoutingMessageHandler { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement, - handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement, - handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update, - handle_htlc_fail_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update, - get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements, - get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements, - sync_routing_table: NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table, - handle_reply_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range, - handle_reply_short_channel_ids_end: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end, - handle_query_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range, - handle_query_short_channel_ids: NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids, - MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - get_and_clear_pending_msg_events: NetGraphMsgHandler_RoutingMessageHandler_get_and_clear_pending_msg_events, - }, - } -} - -#[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 { - let mut ret = >::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner }); - 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 -} -#[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 { - let mut ret = >::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner }); - 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 -} -extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, update: &crate::ln::msgs::HTLCFailChannelUpdate) { - >::handle_htlc_fail_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &update.to_native()) -} -#[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 { - let mut ret = >::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner }); - 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 -} -#[must_use] -extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements(this_arg: *const c_void, mut starting_point: u64, mut batch_amount: u8) -> crate::c_types::derived::CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ { - let mut ret = >::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, starting_point, batch_amount); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_1 = crate::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { std::ptr::null_mut() } else { { Box::into_raw(Box::new((orig_ret_0_1.unwrap()))) } }, is_owned: true }; let mut local_orig_ret_0_2 = crate::ln::msgs::ChannelUpdate { inner: if orig_ret_0_2.is_none() { std::ptr::null_mut() } else { { Box::into_raw(Box::new((orig_ret_0_2.unwrap()))) } }, is_owned: true }; let mut local_ret_0 = (crate::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(orig_ret_0_0)), is_owned: true }, local_orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }); }; - local_ret.into() -} -#[must_use] -extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements(this_arg: *const c_void, mut starting_point: crate::c_types::PublicKey, mut batch_amount: u8) -> crate::c_types::derived::CVec_NodeAnnouncementZ { - let mut local_starting_point_base = if starting_point.is_null() { None } else { Some( { starting_point.into_rust() }) }; let mut local_starting_point = local_starting_point_base.as_ref(); - let mut ret = >::get_next_node_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, local_starting_point, batch_amount); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(item)), is_owned: true } }); }; - local_ret.into() -} -extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init_msg: &crate::ln::msgs::Init) { - >::sync_routing_table(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), unsafe { &*init_msg.inner }) -} -#[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 { - let mut ret = >::handle_reply_channel_range(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &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*/ }).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 -} -#[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 { - let mut ret = >::handle_reply_short_channel_ids_end(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &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*/ }).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 -} -#[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 { - let mut ret = >::handle_query_channel_range(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &_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*/ }).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 -} -#[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 { - let mut ret = >::handle_query_short_channel_ids(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &_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*/ }).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 -} -#[must_use] -extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { - let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); }; - local_ret.into() -} - -impl From for crate::util::events::MessageSendEventsProvider { - fn from(obj: nativeNetGraphMsgHandler) -> Self { - let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true }; - let mut ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&rust_obj); - // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn - rust_obj.inner = std::ptr::null_mut(); - ret.free = Some(NetGraphMsgHandler_free_void); - ret - } -} -#[no_mangle] -pub extern "C" fn NetGraphMsgHandler_as_MessageSendEventsProvider(this_arg: &NetGraphMsgHandler) -> crate::util::events::MessageSendEventsProvider { - crate::util::events::MessageSendEventsProvider { - this_arg: unsafe { (*this_arg).inner as *mut c_void }, - free: None, - get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events, - } -} - -#[must_use] -extern "C" fn NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { - let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); }; - local_ret.into() -} - - -use lightning::routing::network_graph::DirectionalChannelInfo as nativeDirectionalChannelInfoImport; -type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport; - -/// Details about one direction of a channel. Received -/// within a channel update. -#[must_use] -#[repr(C)] -pub struct DirectionalChannelInfo { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeDirectionalChannelInfo, - pub is_owned: bool, -} - -impl Drop for DirectionalChannelInfo { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeDirectionalChannelInfo>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_free(this_ptr: DirectionalChannelInfo) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectionalChannelInfo); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl DirectionalChannelInfo { - pub(crate) fn take_inner(mut self) -> *mut nativeDirectionalChannelInfo { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// When the last update to the channel direction was issued. -/// Value is opaque, as set in the announcement. -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_get_last_update(this_ptr: &DirectionalChannelInfo) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update; - (*inner_val) -} -/// When the last update to the channel direction was issued. -/// Value is opaque, as set in the announcement. -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_set_last_update(this_ptr: &mut DirectionalChannelInfo, mut val: u32) { - unsafe { &mut *this_ptr.inner }.last_update = val; -} -/// Whether the channel can be currently used for payments (in this one direction). -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_get_enabled(this_ptr: &DirectionalChannelInfo) -> bool { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.enabled; - (*inner_val) -} -/// Whether the channel can be currently used for payments (in this one direction). -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_set_enabled(this_ptr: &mut DirectionalChannelInfo, mut val: bool) { - unsafe { &mut *this_ptr.inner }.enabled = val; -} -/// The difference in CLTV values that you must have when routing through this channel. -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_get_cltv_expiry_delta(this_ptr: &DirectionalChannelInfo) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta; - (*inner_val) -} -/// The difference in CLTV values that you must have when routing through this channel. -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_set_cltv_expiry_delta(this_ptr: &mut DirectionalChannelInfo, mut val: u16) { - unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val; -} -/// The minimum value, which must be relayed to the next hop via the channel -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &DirectionalChannelInfo) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat; - (*inner_val) -} -/// The minimum value, which must be relayed to the next hop via the channel -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) { - unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val; -} -/// Fees charged when the channel is used for routing -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_get_fees(this_ptr: &DirectionalChannelInfo) -> crate::routing::network_graph::RoutingFees { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fees; - crate::routing::network_graph::RoutingFees { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// Fees charged when the channel is used for routing -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_set_fees(this_ptr: &mut DirectionalChannelInfo, mut val: crate::routing::network_graph::RoutingFees) { - unsafe { &mut *this_ptr.inner }.fees = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// Most recent update for the channel received from the network -/// Mostly redundant with the data we store in fields explicitly. -/// Everything else is useful only for sending out for initial routing sync. -/// Not stored if contains excess data to prevent DoS. -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_get_last_update_message(this_ptr: &DirectionalChannelInfo) -> crate::ln::msgs::ChannelUpdate { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update_message; - let mut local_inner_val = crate::ln::msgs::ChannelUpdate { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; - local_inner_val -} -/// Most recent update for the channel received from the network -/// Mostly redundant with the data we store in fields explicitly. -/// Everything else is useful only for sending out for initial routing sync. -/// Not stored if contains excess data to prevent DoS. -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut DirectionalChannelInfo, mut val: crate::ln::msgs::ChannelUpdate) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *this_ptr.inner }.last_update_message = local_val; -} -impl Clone for DirectionalChannelInfo { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeDirectionalChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn 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() -} -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_write(obj: &DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn DirectionalChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDirectionalChannelInfo) }) -} -#[no_mangle] -pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DirectionalChannelInfoDecodeErrorZ { - 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::DirectionalChannelInfo { 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 -} - -use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport; -type nativeChannelInfo = nativeChannelInfoImport; - -/// Details about a channel (both directions). -/// Received within a channel announcement. -#[must_use] -#[repr(C)] -pub struct ChannelInfo { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelInfo, - pub is_owned: bool, -} - -impl Drop for ChannelInfo { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelInfo_free(this_ptr: ChannelInfo) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelInfo { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Protocol features of a channel communicated during its announcement -#[no_mangle] -pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::ln::features::ChannelFeatures { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features; - crate::ln::features::ChannelFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// Protocol features of a channel communicated during its announcement -#[no_mangle] -pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::ln::features::ChannelFeatures) { - unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// Source node of the first direction of a channel -#[no_mangle] -pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_one; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// Source node of the first direction of a channel -#[no_mangle] -pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.node_one = val.into_rust(); -} -/// Details about the first direction of a channel -#[no_mangle] -pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.one_to_two; - let mut local_inner_val = crate::routing::network_graph::DirectionalChannelInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; - local_inner_val -} -/// Details about the first direction of a channel -#[no_mangle] -pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *this_ptr.inner }.one_to_two = local_val; -} -/// Source node of the second direction of a channel -#[no_mangle] -pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_two; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// Source node of the second direction of a channel -#[no_mangle] -pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.node_two = val.into_rust(); -} -/// Details about the second direction of a channel -#[no_mangle] -pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.two_to_one; - let mut local_inner_val = crate::routing::network_graph::DirectionalChannelInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; - local_inner_val -} -/// Details about the second direction of a channel -#[no_mangle] -pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *this_ptr.inner }.two_to_one = local_val; -} -/// An initial announcement of the channel -/// Mostly redundant with the data we store in fields explicitly. -/// Everything else is useful only for sending out for initial routing sync. -/// Not stored if contains excess data to prevent DoS. -#[no_mangle] -pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::ln::msgs::ChannelAnnouncement { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message; - let mut local_inner_val = crate::ln::msgs::ChannelAnnouncement { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; - local_inner_val -} -/// An initial announcement of the channel -/// Mostly redundant with the data we store in fields explicitly. -/// Everything else is useful only for sending out for initial routing sync. -/// Not stored if contains excess data to prevent DoS. -#[no_mangle] -pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::ln::msgs::ChannelAnnouncement) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *this_ptr.inner }.announcement_message = local_val; -} -impl Clone for ChannelInfo { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo { - orig.clone() -} -#[no_mangle] -pub extern "C" fn ChannelInfo_write(obj: &ChannelInfo) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) }) -} -#[no_mangle] -pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ { - 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::ChannelInfo { 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 -} - -use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport; -type nativeRoutingFees = nativeRoutingFeesImport; - -/// Fees for routing via a given channel or a node -#[must_use] -#[repr(C)] -pub struct RoutingFees { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeRoutingFees, - pub is_owned: bool, -} - -impl Drop for RoutingFees { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn RoutingFees_free(this_ptr: RoutingFees) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl RoutingFees { - pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Flat routing fee in satoshis -#[no_mangle] -pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.base_msat; - (*inner_val) -} -/// Flat routing fee in satoshis -#[no_mangle] -pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) { - unsafe { &mut *this_ptr.inner }.base_msat = val; -} -/// Liquidity-based routing fee in millionths of a routed amount. -/// In other words, 10000 is 1%. -#[no_mangle] -pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.proportional_millionths; - (*inner_val) -} -/// Liquidity-based routing fee in millionths of a routed amount. -/// In other words, 10000 is 1%. -#[no_mangle] -pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) { - unsafe { &mut *this_ptr.inner }.proportional_millionths = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees { - RoutingFees { inner: Box::into_raw(Box::new(nativeRoutingFees { - base_msat: base_msat_arg, - proportional_millionths: proportional_millionths_arg, - })), is_owned: true } -} -impl Clone for RoutingFees { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeRoutingFees>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees { - orig.clone() -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn RoutingFees_write(obj: &RoutingFees) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) }) -} - -use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport; -type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport; - -/// Information received in the latest node_announcement from this node. -#[must_use] -#[repr(C)] -pub struct NodeAnnouncementInfo { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeNodeAnnouncementInfo, - pub is_owned: bool, -} - -impl Drop for NodeAnnouncementInfo { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_free(this_ptr: NodeAnnouncementInfo) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl NodeAnnouncementInfo { - pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Protocol features the node announced support for -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::ln::features::NodeFeatures { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features; - crate::ln::features::NodeFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// Protocol features the node announced support for -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::features::NodeFeatures) { - unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// When the last known update to the node state was issued. -/// Value is opaque, as set in the announcement. -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update; - (*inner_val) -} -/// When the last known update to the node state was issued. -/// Value is opaque, as set in the announcement. -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) { - unsafe { &mut *this_ptr.inner }.last_update = val; -} -/// Color assigned to the node -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.rgb; - &(*inner_val) -} -/// Color assigned to the node -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) { - unsafe { &mut *this_ptr.inner }.rgb = val.data; -} -/// Moniker assigned to the node. -/// May be invalid or malicious (eg control chars), -/// should not be exposed to the user. -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.alias; - &(*inner_val) -} -/// Moniker assigned to the node. -/// May be invalid or malicious (eg control chars), -/// should not be exposed to the user. -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *this_ptr.inner }.alias = val.data; -} -/// Internet-level addresses via which one can connect to the node -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); }; - unsafe { &mut *this_ptr.inner }.addresses = local_val; -} -/// An initial announcement of the node -/// Mostly redundant with the data we store in fields explicitly. -/// Everything else is useful only for sending out for initial routing sync. -/// Not stored if contains excess data to prevent DoS. -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::ln::msgs::NodeAnnouncement { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message; - let mut local_inner_val = crate::ln::msgs::NodeAnnouncement { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; - local_inner_val -} -/// An initial announcement of the node -/// Mostly redundant with the data we store in fields explicitly. -/// Everything else is useful only for sending out for initial routing sync. -/// Not stored if contains excess data to prevent DoS. -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::msgs::NodeAnnouncement) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *this_ptr.inner }.announcement_message = local_val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_new(mut features_arg: crate::ln::features::NodeFeatures, mut last_update_arg: u32, mut rgb_arg: crate::c_types::ThreeBytes, mut alias_arg: crate::c_types::ThirtyTwoBytes, mut addresses_arg: crate::c_types::derived::CVec_NetAddressZ, mut announcement_message_arg: crate::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo { - let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); }; - let mut local_announcement_message_arg = if announcement_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_message_arg.take_inner()) } }) }; - NodeAnnouncementInfo { inner: Box::into_raw(Box::new(nativeNodeAnnouncementInfo { - features: *unsafe { Box::from_raw(features_arg.take_inner()) }, - last_update: last_update_arg, - rgb: rgb_arg.data, - alias: alias_arg.data, - addresses: local_addresses_arg, - announcement_message: local_announcement_message_arg, - })), is_owned: true } -} -impl Clone for NodeAnnouncementInfo { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn 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() -} -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_write(obj: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) }) -} -#[no_mangle] -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 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 -} - -use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport; -type nativeNodeInfo = nativeNodeInfoImport; - -/// Details about a node in the network, known from the network announcement. -#[must_use] -#[repr(C)] -pub struct NodeInfo { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeNodeInfo, - pub is_owned: bool, -} - -impl Drop for NodeInfo { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn NodeInfo_free(this_ptr: NodeInfo) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl NodeInfo { - pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// All valid channels a node has announced -#[no_mangle] -pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); }; - unsafe { &mut *this_ptr.inner }.channels = local_val; -} -/// Lowest fees enabling routing via any of the enabled, known channels to a node. -/// The two fields (flat and proportional fee) are independent, -/// meaning they don't have to refer to the same channel. -#[no_mangle] -pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::routing::network_graph::RoutingFees { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees; - let mut local_inner_val = crate::routing::network_graph::RoutingFees { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; - local_inner_val -} -/// Lowest fees enabling routing via any of the enabled, known channels to a node. -/// The two fields (flat and proportional fee) are independent, -/// meaning they don't have to refer to the same channel. -#[no_mangle] -pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::RoutingFees) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees = local_val; -} -/// More information about a node from node_announcement. -/// Optional because we store a Node entry after learning about it from -/// a channel announcement, but before receiving a node announcement. -#[no_mangle] -pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::routing::network_graph::NodeAnnouncementInfo { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_info; - let mut local_inner_val = crate::routing::network_graph::NodeAnnouncementInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; - local_inner_val -} -/// More information about a node from node_announcement. -/// Optional because we store a Node entry after learning about it from -/// a channel announcement, but before receiving a node announcement. -#[no_mangle] -pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::NodeAnnouncementInfo) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *this_ptr.inner }.announcement_info = local_val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn NodeInfo_new(mut channels_arg: crate::c_types::derived::CVec_u64Z, mut lowest_inbound_channel_fees_arg: crate::routing::network_graph::RoutingFees, mut announcement_info_arg: crate::routing::network_graph::NodeAnnouncementInfo) -> NodeInfo { - let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); }; - let mut local_lowest_inbound_channel_fees_arg = if lowest_inbound_channel_fees_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(lowest_inbound_channel_fees_arg.take_inner()) } }) }; - let mut local_announcement_info_arg = if announcement_info_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_info_arg.take_inner()) } }) }; - NodeInfo { inner: Box::into_raw(Box::new(nativeNodeInfo { - channels: local_channels_arg, - lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg, - announcement_info: local_announcement_info_arg, - })), is_owned: true } -} -impl Clone for NodeInfo { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeNodeInfo>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn 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() -} -#[no_mangle] -pub extern "C" fn NodeInfo_write(obj: &NodeInfo) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) }) -} -#[no_mangle] -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 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 -} -#[no_mangle] -pub extern "C" fn NetworkGraph_write(obj: &NetworkGraph) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) }) -} -#[no_mangle] -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 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 -} -/// Creates a new, empty, network graph. -#[must_use] -#[no_mangle] -pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::routing::network_graph::NetworkGraph { - let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap()); - crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true } -} - -/// For an already known node (from channel announcements), update its stored properties from a -/// given node announcement. -/// -/// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's -/// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept -/// routing messages from a source using a protocol other than the lightning P2P protocol. -#[must_use] -#[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 { - let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_announcement(unsafe { &*msg.inner }, secp256k1::SECP256K1); - 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 -} - -/// For an already known node (from channel announcements), update its stored properties from a -/// given node announcement without verifying the associated signatures. Because we aren't -/// given the associated signatures here we cannot relay the node announcement to any of our -/// peers. -#[must_use] -#[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 { - 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*/ }).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 -} - -/// Store or update channel info from a channel announcement. -/// -/// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's -/// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept -/// routing messages from a source using a protocol other than the lightning P2P protocol. -/// -/// If a `chain::Access` object is provided via `chain_access`, it will be called to verify -/// the corresponding UTXO exists on chain and is correctly-formatted. -#[must_use] -#[no_mangle] -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 ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_announcement(unsafe { &*msg.inner }, &local_chain_access, secp256k1::SECP256K1); - 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 -} - -/// Store or update channel info from a channel announcement without verifying the associated -/// signatures. Because we aren't given the associated signatures here we cannot relay the -/// channel announcement to any of our peers. -/// -/// If a `chain::Access` object is provided via `chain_access`, it will be called to verify -/// the corresponding UTXO exists on chain and is correctly-formatted. -#[must_use] -#[no_mangle] -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 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*/ }).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 -} - -/// Close a channel if a corresponding HTLC fail was sent. -/// If permanent, removes a channel from the local storage. -/// May cause the removal of nodes too, if this was their last channel. -/// If not permanent, makes channels unavailable for routing. -#[no_mangle] -pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) { - unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.close_channel_from_update(short_channel_id, is_permanent) -} - -/// For an already known (from announcement) channel, update info about one of the directions -/// of the channel. -/// -/// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's -/// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept -/// routing messages from a source using a protocol other than the lightning P2P protocol. -#[must_use] -#[no_mangle] -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 }, secp256k1::SECP256K1); - 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 -} - -/// For an already known (from announcement) channel, update info about one of the directions -/// of the channel without verifying the associated signatures. Because we aren't given the -/// associated signatures here we cannot relay the channel update to any of our peers. -#[must_use] -#[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 { - 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*/ }).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 -} - diff --git a/lightning-c-bindings/src/routing/router.rs b/lightning-c-bindings/src/routing/router.rs deleted file mode 100644 index 32b4aebb9..000000000 --- a/lightning-c-bindings/src/routing/router.rs +++ /dev/null @@ -1,368 +0,0 @@ -//! The top-level routing/network map tracking logic lives here. -//! -//! You probably want to create a NetGraphMsgHandler and use that as your RoutingMessageHandler and then -//! interrogate it to get routes for your own payments. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - - -use lightning::routing::router::RouteHop as nativeRouteHopImport; -type nativeRouteHop = nativeRouteHopImport; - -/// A hop in a route -#[must_use] -#[repr(C)] -pub struct RouteHop { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeRouteHop, - pub is_owned: bool, -} - -impl Drop for RouteHop { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeRouteHop>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn RouteHop_free(this_ptr: RouteHop) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn RouteHop_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHop); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl RouteHop { - pub(crate) fn take_inner(mut self) -> *mut nativeRouteHop { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The node_id of the node at this hop. -#[no_mangle] -pub extern "C" fn RouteHop_get_pubkey(this_ptr: &RouteHop) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.pubkey; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The node_id of the node at this hop. -#[no_mangle] -pub extern "C" fn RouteHop_set_pubkey(this_ptr: &mut RouteHop, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.pubkey = val.into_rust(); -} -/// The node_announcement features of the node at this hop. For the last hop, these may be -/// amended to match the features present in the invoice this node generated. -#[no_mangle] -pub extern "C" fn RouteHop_get_node_features(this_ptr: &RouteHop) -> crate::ln::features::NodeFeatures { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_features; - crate::ln::features::NodeFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// The node_announcement features of the node at this hop. For the last hop, these may be -/// amended to match the features present in the invoice this node generated. -#[no_mangle] -pub extern "C" fn RouteHop_set_node_features(this_ptr: &mut RouteHop, mut val: crate::ln::features::NodeFeatures) { - unsafe { &mut *this_ptr.inner }.node_features = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// The channel that should be used from the previous hop to reach this node. -#[no_mangle] -pub extern "C" fn RouteHop_get_short_channel_id(this_ptr: &RouteHop) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.short_channel_id; - (*inner_val) -} -/// The channel that should be used from the previous hop to reach this node. -#[no_mangle] -pub extern "C" fn RouteHop_set_short_channel_id(this_ptr: &mut RouteHop, mut val: u64) { - unsafe { &mut *this_ptr.inner }.short_channel_id = val; -} -/// The channel_announcement features of the channel that should be used from the previous hop -/// to reach this node. -#[no_mangle] -pub extern "C" fn RouteHop_get_channel_features(this_ptr: &RouteHop) -> crate::ln::features::ChannelFeatures { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_features; - crate::ln::features::ChannelFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// The channel_announcement features of the channel that should be used from the previous hop -/// to reach this node. -#[no_mangle] -pub extern "C" fn RouteHop_set_channel_features(this_ptr: &mut RouteHop, mut val: crate::ln::features::ChannelFeatures) { - unsafe { &mut *this_ptr.inner }.channel_features = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// The fee taken on this hop (for paying for the use of the *next* channel in the path). -/// For the last hop, this should be the full value of the payment (might be more than -/// requested if we had to match htlc_minimum_msat). -#[no_mangle] -pub extern "C" fn RouteHop_get_fee_msat(this_ptr: &RouteHop) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_msat; - (*inner_val) -} -/// The fee taken on this hop (for paying for the use of the *next* channel in the path). -/// For the last hop, this should be the full value of the payment (might be more than -/// requested if we had to match htlc_minimum_msat). -#[no_mangle] -pub extern "C" fn RouteHop_set_fee_msat(this_ptr: &mut RouteHop, mut val: u64) { - unsafe { &mut *this_ptr.inner }.fee_msat = val; -} -/// The CLTV delta added for this hop. For the last hop, this should be the full CLTV value -/// expected at the destination, in excess of the current block height. -#[no_mangle] -pub extern "C" fn RouteHop_get_cltv_expiry_delta(this_ptr: &RouteHop) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta; - (*inner_val) -} -/// The CLTV delta added for this hop. For the last hop, this should be the full CLTV value -/// expected at the destination, in excess of the current block height. -#[no_mangle] -pub extern "C" fn RouteHop_set_cltv_expiry_delta(this_ptr: &mut RouteHop, mut val: u32) { - unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn RouteHop_new(mut pubkey_arg: crate::c_types::PublicKey, mut node_features_arg: crate::ln::features::NodeFeatures, mut short_channel_id_arg: u64, mut channel_features_arg: crate::ln::features::ChannelFeatures, mut fee_msat_arg: u64, mut cltv_expiry_delta_arg: u32) -> RouteHop { - RouteHop { inner: Box::into_raw(Box::new(nativeRouteHop { - pubkey: pubkey_arg.into_rust(), - node_features: *unsafe { Box::from_raw(node_features_arg.take_inner()) }, - short_channel_id: short_channel_id_arg, - channel_features: *unsafe { Box::from_raw(channel_features_arg.take_inner()) }, - fee_msat: fee_msat_arg, - cltv_expiry_delta: cltv_expiry_delta_arg, - })), is_owned: true } -} -impl Clone for RouteHop { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeRouteHop>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn RouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHop)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop { - orig.clone() -} - -use lightning::routing::router::Route as nativeRouteImport; -type nativeRoute = nativeRouteImport; - -/// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP, -/// it can take multiple paths. Each path is composed of one or more hops through the network. -#[must_use] -#[repr(C)] -pub struct Route { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeRoute, - pub is_owned: bool, -} - -impl Drop for Route { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeRoute>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn Route_free(this_ptr: Route) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn Route_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoute); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl Route { - pub(crate) fn take_inner(mut self) -> *mut nativeRoute { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// 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. -/// Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the -/// destination. Thus, this must always be at least length one. While the maximum length of any -/// given path is variable, keeping the length of any path to less than 20 should currently -/// ensure it is viable. -#[no_mangle] -pub extern "C" fn Route_set_paths(this_ptr: &mut Route, mut val: crate::c_types::derived::CVec_CVec_RouteHopZZ) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { let mut local_val_0 = Vec::new(); for mut item in item.into_rust().drain(..) { local_val_0.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; local_val_0 }); }; - unsafe { &mut *this_ptr.inner }.paths = local_val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn Route_new(mut paths_arg: crate::c_types::derived::CVec_CVec_RouteHopZZ) -> Route { - let mut local_paths_arg = Vec::new(); for mut item in paths_arg.into_rust().drain(..) { local_paths_arg.push( { let mut local_paths_arg_0 = Vec::new(); for mut item in item.into_rust().drain(..) { local_paths_arg_0.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; local_paths_arg_0 }); }; - Route { inner: Box::into_raw(Box::new(nativeRoute { - paths: local_paths_arg, - })), is_owned: true } -} -impl Clone for Route { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeRoute>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoute)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn Route_clone(orig: &Route) -> Route { - orig.clone() -} -#[no_mangle] -pub extern "C" fn Route_write(obj: &Route) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) }) -} -#[no_mangle] -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 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 -} - -use lightning::routing::router::RouteHint as nativeRouteHintImport; -type nativeRouteHint = nativeRouteHintImport; - -/// A channel descriptor which provides a last-hop route to get_route -#[must_use] -#[repr(C)] -pub struct RouteHint { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeRouteHint, - pub is_owned: bool, -} - -impl Drop for RouteHint { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn RouteHint_free(this_ptr: RouteHint) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHint); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl RouteHint { - pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// The node_id of the non-target end of the route -#[no_mangle] -pub extern "C" fn RouteHint_get_src_node_id(this_ptr: &RouteHint) -> crate::c_types::PublicKey { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.src_node_id; - crate::c_types::PublicKey::from_rust(&(*inner_val)) -} -/// The node_id of the non-target end of the route -#[no_mangle] -pub extern "C" fn RouteHint_set_src_node_id(this_ptr: &mut RouteHint, mut val: crate::c_types::PublicKey) { - unsafe { &mut *this_ptr.inner }.src_node_id = val.into_rust(); -} -/// The short_channel_id of this channel -#[no_mangle] -pub extern "C" fn RouteHint_get_short_channel_id(this_ptr: &RouteHint) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.short_channel_id; - (*inner_val) -} -/// The short_channel_id of this channel -#[no_mangle] -pub extern "C" fn RouteHint_set_short_channel_id(this_ptr: &mut RouteHint, mut val: u64) { - unsafe { &mut *this_ptr.inner }.short_channel_id = val; -} -/// The fees which must be paid to use this channel -#[no_mangle] -pub extern "C" fn RouteHint_get_fees(this_ptr: &RouteHint) -> crate::routing::network_graph::RoutingFees { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fees; - crate::routing::network_graph::RoutingFees { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// The fees which must be paid to use this channel -#[no_mangle] -pub extern "C" fn RouteHint_set_fees(this_ptr: &mut RouteHint, mut val: crate::routing::network_graph::RoutingFees) { - unsafe { &mut *this_ptr.inner }.fees = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// The difference in CLTV values between this node and the next node. -#[no_mangle] -pub extern "C" fn RouteHint_get_cltv_expiry_delta(this_ptr: &RouteHint) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta; - (*inner_val) -} -/// The difference in CLTV values between this node and the next node. -#[no_mangle] -pub extern "C" fn RouteHint_set_cltv_expiry_delta(this_ptr: &mut RouteHint, mut val: u16) { - unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val; -} -impl Clone for RouteHint { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeRouteHint>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint { - orig.clone() -} -/// Gets a route from us (payer) to the given target node (payee). -/// -/// Extra routing hops between known nodes and the target will be used if they are included in -/// last_hops. -/// -/// If some channels aren't announced, it may be useful to fill in a first_hops with the -/// results from a local ChannelManager::list_usable_channels() call. If it is filled in, our -/// view of our local channels (from net_graph_msg_handler) will be ignored, and only those -/// in first_hops will be used. -/// -/// Panics if first_hops contains channels without short_channel_ids -/// (ChannelManager::list_usable_channels will never include such channels). -/// -/// The fees on channels from us to next-hops are ignored (as they are assumed to all be -/// equal), however the enabled/disabled bit on such channels as well as the -/// htlc_minimum_msat/htlc_maximum_msat *are* checked as they may change based on the receiving node. -#[no_mangle] -pub extern "C" fn get_route(mut our_node_id: crate::c_types::PublicKey, network: &crate::routing::network_graph::NetworkGraph, mut payee: crate::c_types::PublicKey, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut last_hops: crate::c_types::derived::CVec_RouteHintZ, mut final_value_msat: u64, mut final_cltv: u32, mut logger: crate::util::logger::Logger) -> crate::c_types::derived::CResult_RouteLightningErrorZ { - 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 ret = lightning::routing::router::get_route(&our_node_id.into_rust(), unsafe { &*network.inner }, &payee.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 } }).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 -} - diff --git a/lightning-c-bindings/src/util/config.rs b/lightning-c-bindings/src/util/config.rs deleted file mode 100644 index 9f8769d80..000000000 --- a/lightning-c-bindings/src/util/config.rs +++ /dev/null @@ -1,709 +0,0 @@ -//! Various user-configurable channel limits and settings which ChannelManager -//! applies for you. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - - -use lightning::util::config::ChannelHandshakeConfig as nativeChannelHandshakeConfigImport; -type nativeChannelHandshakeConfig = nativeChannelHandshakeConfigImport; - -/// Configuration we set when applicable. -/// -/// Default::default() provides sane defaults. -#[must_use] -#[repr(C)] -pub struct ChannelHandshakeConfig { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelHandshakeConfig, - pub is_owned: bool, -} - -impl Drop for ChannelHandshakeConfig { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelHandshakeConfig>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelHandshakeConfig_free(this_ptr: ChannelHandshakeConfig) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelHandshakeConfig_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeConfig); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelHandshakeConfig { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeConfig { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Confirmations we will wait for before considering the channel locked in. -/// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the -/// equivalent limit applied to outbound channels). -/// -/// Default value: 6. -#[no_mangle] -pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHandshakeConfig) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.minimum_depth; - (*inner_val) -} -/// Confirmations we will wait for before considering the channel locked in. -/// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the -/// equivalent limit applied to outbound channels). -/// -/// Default value: 6. -#[no_mangle] -pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) { - unsafe { &mut *this_ptr.inner }.minimum_depth = val; -} -/// Set to the amount of time we require our counterparty to wait to claim their money. -/// -/// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST -/// be online to check for peer having broadcast a revoked transaction to steal our funds -/// at least once every our_to_self_delay blocks. -/// -/// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in -/// case of an honest unilateral channel close, which implicitly decrease the economic value of -/// our channel. -/// -/// Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel -/// opening so you can tweak config to ask for more security, not less. -#[no_mangle] -pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_to_self_delay; - (*inner_val) -} -/// Set to the amount of time we require our counterparty to wait to claim their money. -/// -/// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST -/// be online to check for peer having broadcast a revoked transaction to steal our funds -/// at least once every our_to_self_delay blocks. -/// -/// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in -/// case of an honest unilateral channel close, which implicitly decrease the economic value of -/// our channel. -/// -/// Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel -/// opening so you can tweak config to ask for more security, not less. -#[no_mangle] -pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) { - unsafe { &mut *this_ptr.inner }.our_to_self_delay = val; -} -/// Set to the smallest value HTLC we will accept to process. -/// -/// This value is sent to our counterparty on channel-open and we close the channel any time -/// our counterparty misbehaves by sending us an HTLC with a value smaller than this. -/// -/// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required -/// by the protocol. -#[no_mangle] -pub extern "C" fn ChannelHandshakeConfig_get_our_htlc_minimum_msat(this_ptr: &ChannelHandshakeConfig) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat; - (*inner_val) -} -/// Set to the smallest value HTLC we will accept to process. -/// -/// This value is sent to our counterparty on channel-open and we close the channel any time -/// our counterparty misbehaves by sending us an HTLC with a value smaller than this. -/// -/// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required -/// by the protocol. -#[no_mangle] -pub extern "C" fn ChannelHandshakeConfig_set_our_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeConfig, mut val: u64) { - unsafe { &mut *this_ptr.inner }.our_htlc_minimum_msat = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelHandshakeConfig_new(mut minimum_depth_arg: u32, mut our_to_self_delay_arg: u16, mut our_htlc_minimum_msat_arg: u64) -> ChannelHandshakeConfig { - ChannelHandshakeConfig { inner: Box::into_raw(Box::new(nativeChannelHandshakeConfig { - minimum_depth: minimum_depth_arg, - our_to_self_delay: our_to_self_delay_arg, - our_htlc_minimum_msat: our_htlc_minimum_msat_arg, - })), is_owned: true } -} -impl Clone for ChannelHandshakeConfig { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeChannelHandshakeConfig>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelHandshakeConfig_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeConfig)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ChannelHandshakeConfig_clone(orig: &ChannelHandshakeConfig) -> ChannelHandshakeConfig { - orig.clone() -} -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelHandshakeConfig_default() -> ChannelHandshakeConfig { - ChannelHandshakeConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true } -} - -use lightning::util::config::ChannelHandshakeLimits as nativeChannelHandshakeLimitsImport; -type nativeChannelHandshakeLimits = nativeChannelHandshakeLimitsImport; - -/// Optional channel limits which are applied during channel creation. -/// -/// These limits are only applied to our counterparty's limits, not our own. -/// -/// Use 0/::max_value() as appropriate to skip checking. -/// -/// Provides sane defaults for most configurations. -/// -/// Most additional limits are disabled except those with which specify a default in individual -/// field documentation. Note that this may result in barely-usable channels, but since they -/// are applied mostly only to incoming channels that's not much of a problem. -#[must_use] -#[repr(C)] -pub struct ChannelHandshakeLimits { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelHandshakeLimits, - pub is_owned: bool, -} - -impl Drop for ChannelHandshakeLimits { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelHandshakeLimits>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_free(this_ptr: ChannelHandshakeLimits) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelHandshakeLimits_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelHandshakeLimits); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelHandshakeLimits { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelHandshakeLimits { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so -/// only applies to inbound channels. -/// -/// Default value: 0. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_get_min_funding_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_funding_satoshis; - (*inner_val) -} -/// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so -/// only applies to inbound channels. -/// -/// Default value: 0. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_set_min_funding_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) { - unsafe { &mut *this_ptr.inner }.min_funding_satoshis = val; -} -/// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows -/// you to limit the maximum minimum-size they can require. -/// -/// Default value: u64::max_value. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_get_max_htlc_minimum_msat(this_ptr: &ChannelHandshakeLimits) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat; - (*inner_val) -} -/// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows -/// you to limit the maximum minimum-size they can require. -/// -/// Default value: u64::max_value. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_set_max_htlc_minimum_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) { - unsafe { &mut *this_ptr.inner }.max_htlc_minimum_msat = val; -} -/// The remote node sets a limit on the maximum value of pending HTLCs to them at any given -/// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value. -/// -/// Default value: 0. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(this_ptr: &ChannelHandshakeLimits) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat; - (*inner_val) -} -/// The remote node sets a limit on the maximum value of pending HTLCs to them at any given -/// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value. -/// -/// Default value: 0. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) { - unsafe { &mut *this_ptr.inner }.min_max_htlc_value_in_flight_msat = val; -} -/// The remote node will require we keep a certain amount in direct payment to ourselves at all -/// time, ensuring that we are able to be punished if we broadcast an old state. This allows to -/// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs). -/// -/// Default value: u64::max_value. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_get_max_channel_reserve_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis; - (*inner_val) -} -/// The remote node will require we keep a certain amount in direct payment to ourselves at all -/// time, ensuring that we are able to be punished if we broadcast an old state. This allows to -/// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs). -/// -/// Default value: u64::max_value. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_set_max_channel_reserve_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) { - unsafe { &mut *this_ptr.inner }.max_channel_reserve_satoshis = val; -} -/// The remote node sets a limit on the maximum number of pending HTLCs to them at any given -/// time. This allows you to set a minimum such value. -/// -/// Default value: 0. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_get_min_max_accepted_htlcs(this_ptr: &ChannelHandshakeLimits) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs; - (*inner_val) -} -/// The remote node sets a limit on the maximum number of pending HTLCs to them at any given -/// time. This allows you to set a minimum such value. -/// -/// Default value: 0. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_set_min_max_accepted_htlcs(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) { - unsafe { &mut *this_ptr.inner }.min_max_accepted_htlcs = val; -} -/// Outputs below a certain value will not be added to on-chain transactions. The dust value is -/// required to always be higher than this value so this only applies to HTLC outputs (and -/// potentially to-self outputs before any payments have been made). -/// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain. -/// This setting allows you to set a minimum dust limit for their commitment transactions, -/// reflecting the reality that tiny outputs are not considered standard transactions and will -/// not propagate through the Bitcoin network. -/// -/// Default value: 546, the current dust limit on the Bitcoin network. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_get_min_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis; - (*inner_val) -} -/// Outputs below a certain value will not be added to on-chain transactions. The dust value is -/// required to always be higher than this value so this only applies to HTLC outputs (and -/// potentially to-self outputs before any payments have been made). -/// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain. -/// This setting allows you to set a minimum dust limit for their commitment transactions, -/// reflecting the reality that tiny outputs are not considered standard transactions and will -/// not propagate through the Bitcoin network. -/// -/// Default value: 546, the current dust limit on the Bitcoin network. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_set_min_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) { - unsafe { &mut *this_ptr.inner }.min_dust_limit_satoshis = val; -} -/// Maximum allowed threshold above which outputs will not be generated in their commitment -/// transactions. -/// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain. -/// -/// Default value: u64::max_value. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_get_max_dust_limit_satoshis(this_ptr: &ChannelHandshakeLimits) -> u64 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis; - (*inner_val) -} -/// Maximum allowed threshold above which outputs will not be generated in their commitment -/// transactions. -/// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain. -/// -/// Default value: u64::max_value. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_set_max_dust_limit_satoshis(this_ptr: &mut ChannelHandshakeLimits, mut val: u64) { - unsafe { &mut *this_ptr.inner }.max_dust_limit_satoshis = val; -} -/// Before a channel is usable the funding transaction will need to be confirmed by at least a -/// certain number of blocks, specified by the node which is not the funder (as the funder can -/// assume they aren't going to double-spend themselves). -/// This config allows you to set a limit on the maximum amount of time to wait. -/// -/// Default value: 144, or roughly one day and only applies to outbound channels. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_get_max_minimum_depth(this_ptr: &ChannelHandshakeLimits) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.max_minimum_depth; - (*inner_val) -} -/// Before a channel is usable the funding transaction will need to be confirmed by at least a -/// certain number of blocks, specified by the node which is not the funder (as the funder can -/// assume they aren't going to double-spend themselves). -/// This config allows you to set a limit on the maximum amount of time to wait. -/// -/// Default value: 144, or roughly one day and only applies to outbound channels. -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_set_max_minimum_depth(this_ptr: &mut ChannelHandshakeLimits, mut val: u32) { - unsafe { &mut *this_ptr.inner }.max_minimum_depth = val; -} -/// Set to force the incoming channel to match our announced channel preference in -/// ChannelConfig. -/// -/// Default value: true, to make the default that no announced channels are possible (which is -/// appropriate for any nodes which are not online very reliably). -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_get_force_announced_channel_preference(this_ptr: &ChannelHandshakeLimits) -> bool { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.force_announced_channel_preference; - (*inner_val) -} -/// Set to force the incoming channel to match our announced channel preference in -/// ChannelConfig. -/// -/// Default value: true, to make the default that no announced channels are possible (which is -/// appropriate for any nodes which are not online very reliably). -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_set_force_announced_channel_preference(this_ptr: &mut ChannelHandshakeLimits, mut val: bool) { - unsafe { &mut *this_ptr.inner }.force_announced_channel_preference = val; -} -/// Set to the amount of time we're willing to wait to claim money back to us. -/// -/// Not checking this value would be a security issue, as our peer would be able to set it to -/// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time. -/// -/// Default value: MAX_LOCAL_BREAKDOWN_TIMEOUT (1008), which we also enforce as a maximum value -/// so you can tweak config to reduce the loss of having useless locked funds (if your peer accepts) -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_get_their_to_self_delay(this_ptr: &ChannelHandshakeLimits) -> u16 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.their_to_self_delay; - (*inner_val) -} -/// Set to the amount of time we're willing to wait to claim money back to us. -/// -/// Not checking this value would be a security issue, as our peer would be able to set it to -/// max relative lock-time (a year) and we would \"lose\" money as it would be locked for a long time. -/// -/// Default value: MAX_LOCAL_BREAKDOWN_TIMEOUT (1008), which we also enforce as a maximum value -/// so you can tweak config to reduce the loss of having useless locked funds (if your peer accepts) -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_set_their_to_self_delay(this_ptr: &mut ChannelHandshakeLimits, mut val: u16) { - unsafe { &mut *this_ptr.inner }.their_to_self_delay = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_new(mut min_funding_satoshis_arg: u64, mut max_htlc_minimum_msat_arg: u64, mut min_max_htlc_value_in_flight_msat_arg: u64, mut max_channel_reserve_satoshis_arg: u64, mut min_max_accepted_htlcs_arg: u16, mut min_dust_limit_satoshis_arg: u64, mut max_dust_limit_satoshis_arg: u64, mut max_minimum_depth_arg: u32, mut force_announced_channel_preference_arg: bool, mut their_to_self_delay_arg: u16) -> ChannelHandshakeLimits { - ChannelHandshakeLimits { inner: Box::into_raw(Box::new(nativeChannelHandshakeLimits { - min_funding_satoshis: min_funding_satoshis_arg, - max_htlc_minimum_msat: max_htlc_minimum_msat_arg, - min_max_htlc_value_in_flight_msat: min_max_htlc_value_in_flight_msat_arg, - max_channel_reserve_satoshis: max_channel_reserve_satoshis_arg, - min_max_accepted_htlcs: min_max_accepted_htlcs_arg, - min_dust_limit_satoshis: min_dust_limit_satoshis_arg, - max_dust_limit_satoshis: max_dust_limit_satoshis_arg, - max_minimum_depth: max_minimum_depth_arg, - force_announced_channel_preference: force_announced_channel_preference_arg, - their_to_self_delay: their_to_self_delay_arg, - })), is_owned: true } -} -impl Clone for ChannelHandshakeLimits { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeChannelHandshakeLimits>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelHandshakeLimits_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelHandshakeLimits)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_clone(orig: &ChannelHandshakeLimits) -> ChannelHandshakeLimits { - orig.clone() -} -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelHandshakeLimits_default() -> ChannelHandshakeLimits { - ChannelHandshakeLimits { inner: Box::into_raw(Box::new(Default::default())), is_owned: true } -} - -use lightning::util::config::ChannelConfig as nativeChannelConfigImport; -type nativeChannelConfig = nativeChannelConfigImport; - -/// Options which apply on a per-channel basis and may change at runtime or based on negotiation -/// with our counterparty. -#[must_use] -#[repr(C)] -pub struct ChannelConfig { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeChannelConfig, - pub is_owned: bool, -} - -impl Drop for ChannelConfig { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelConfig>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn ChannelConfig_free(this_ptr: ChannelConfig) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn ChannelConfig_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelConfig); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl ChannelConfig { - pub(crate) fn take_inner(mut self) -> *mut nativeChannelConfig { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// 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 -/// update messages sent to notify all nodes of our updated relay fee. -/// -/// Default value: 0. -#[no_mangle] -pub extern "C" fn ChannelConfig_get_fee_proportional_millionths(this_ptr: &ChannelConfig) -> u32 { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_proportional_millionths; - (*inner_val) -} -/// 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 -/// update messages sent to notify all nodes of our updated relay fee. -/// -/// Default value: 0. -#[no_mangle] -pub extern "C" fn ChannelConfig_set_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) { - unsafe { &mut *this_ptr.inner }.fee_proportional_millionths = val; -} -/// Set to announce the channel publicly and notify all nodes that they can route via this -/// channel. -/// -/// This should only be set to true for nodes which expect to be online reliably. -/// -/// As the node which funds a channel picks this value this will only apply for new outbound -/// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set. -/// -/// This cannot be changed after the initial channel handshake. -/// -/// Default value: false. -#[no_mangle] -pub extern "C" fn ChannelConfig_get_announced_channel(this_ptr: &ChannelConfig) -> bool { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announced_channel; - (*inner_val) -} -/// Set to announce the channel publicly and notify all nodes that they can route via this -/// channel. -/// -/// This should only be set to true for nodes which expect to be online reliably. -/// -/// As the node which funds a channel picks this value this will only apply for new outbound -/// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set. -/// -/// This cannot be changed after the initial channel handshake. -/// -/// Default value: false. -#[no_mangle] -pub extern "C" fn ChannelConfig_set_announced_channel(this_ptr: &mut ChannelConfig, mut val: bool) { - unsafe { &mut *this_ptr.inner }.announced_channel = val; -} -/// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty -/// supports it, they will then enforce the mutual-close output to us matches what we provided -/// at intialization, preventing us from closing to an alternate pubkey. -/// -/// This is set to true by default to provide a slight increase in security, though ultimately -/// any attacker who is able to take control of a channel can just as easily send the funds via -/// lightning payments, so we never require that our counterparties support this option. -/// -/// This cannot be changed after a channel has been initialized. -/// -/// Default value: true. -#[no_mangle] -pub extern "C" fn ChannelConfig_get_commit_upfront_shutdown_pubkey(this_ptr: &ChannelConfig) -> bool { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey; - (*inner_val) -} -/// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty -/// supports it, they will then enforce the mutual-close output to us matches what we provided -/// at intialization, preventing us from closing to an alternate pubkey. -/// -/// This is set to true by default to provide a slight increase in security, though ultimately -/// any attacker who is able to take control of a channel can just as easily send the funds via -/// lightning payments, so we never require that our counterparties support this option. -/// -/// This cannot be changed after a channel has been initialized. -/// -/// Default value: true. -#[no_mangle] -pub extern "C" fn ChannelConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mut ChannelConfig, mut val: bool) { - unsafe { &mut *this_ptr.inner }.commit_upfront_shutdown_pubkey = val; -} -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelConfig_new(mut fee_proportional_millionths_arg: u32, mut announced_channel_arg: bool, mut commit_upfront_shutdown_pubkey_arg: bool) -> ChannelConfig { - ChannelConfig { inner: Box::into_raw(Box::new(nativeChannelConfig { - fee_proportional_millionths: fee_proportional_millionths_arg, - announced_channel: announced_channel_arg, - commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg, - })), is_owned: true } -} -impl Clone for ChannelConfig { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeChannelConfig>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelConfig_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelConfig)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn ChannelConfig_clone(orig: &ChannelConfig) -> ChannelConfig { - orig.clone() -} -#[must_use] -#[no_mangle] -pub extern "C" fn ChannelConfig_default() -> ChannelConfig { - ChannelConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true } -} -#[no_mangle] -pub extern "C" fn ChannelConfig_write(obj: &ChannelConfig) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner }) -} -#[no_mangle] -pub(crate) extern "C" fn ChannelConfig_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelConfig) }) -} -#[no_mangle] -pub extern "C" fn ChannelConfig_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelConfigDecodeErrorZ { - let res = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::util::config::ChannelConfig { 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 -} - -use lightning::util::config::UserConfig as nativeUserConfigImport; -type nativeUserConfig = nativeUserConfigImport; - -/// Top-level config which holds ChannelHandshakeLimits and ChannelConfig. -/// -/// Default::default() provides sane defaults for most configurations -/// (but currently with 0 relay fees!) -#[must_use] -#[repr(C)] -pub struct UserConfig { - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeUserConfig, - pub is_owned: bool, -} - -impl Drop for UserConfig { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeUserConfig>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(self.inner) }; - } - } -} -#[no_mangle] -pub extern "C" fn UserConfig_free(this_ptr: UserConfig) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -extern "C" fn UserConfig_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUserConfig); } -} -#[allow(unused)] -/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy -impl UserConfig { - pub(crate) fn take_inner(mut self) -> *mut nativeUserConfig { - assert!(self.is_owned); - let ret = self.inner; - self.inner = std::ptr::null_mut(); - ret - } -} -/// Channel config that we propose to our counterparty. -#[no_mangle] -pub extern "C" fn UserConfig_get_own_channel_config(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeConfig { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.own_channel_config; - crate::util::config::ChannelHandshakeConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// Channel config that we propose to our counterparty. -#[no_mangle] -pub extern "C" fn UserConfig_set_own_channel_config(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeConfig) { - unsafe { &mut *this_ptr.inner }.own_channel_config = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// Limits applied to our counterparty's proposed channel config settings. -#[no_mangle] -pub extern "C" fn UserConfig_get_peer_channel_config_limits(this_ptr: &UserConfig) -> crate::util::config::ChannelHandshakeLimits { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.peer_channel_config_limits; - crate::util::config::ChannelHandshakeLimits { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// Limits applied to our counterparty's proposed channel config settings. -#[no_mangle] -pub extern "C" fn UserConfig_set_peer_channel_config_limits(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelHandshakeLimits) { - unsafe { &mut *this_ptr.inner }.peer_channel_config_limits = *unsafe { Box::from_raw(val.take_inner()) }; -} -/// Channel config which affects behavior during channel lifetime. -#[no_mangle] -pub extern "C" fn UserConfig_get_channel_options(this_ptr: &UserConfig) -> crate::util::config::ChannelConfig { - let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_options; - crate::util::config::ChannelConfig { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false } -} -/// Channel config which affects behavior during channel lifetime. -#[no_mangle] -pub extern "C" fn UserConfig_set_channel_options(this_ptr: &mut UserConfig, mut val: crate::util::config::ChannelConfig) { - unsafe { &mut *this_ptr.inner }.channel_options = *unsafe { Box::from_raw(val.take_inner()) }; -} -#[must_use] -#[no_mangle] -pub extern "C" fn UserConfig_new(mut own_channel_config_arg: crate::util::config::ChannelHandshakeConfig, mut peer_channel_config_limits_arg: crate::util::config::ChannelHandshakeLimits, mut channel_options_arg: crate::util::config::ChannelConfig) -> UserConfig { - UserConfig { inner: Box::into_raw(Box::new(nativeUserConfig { - own_channel_config: *unsafe { Box::from_raw(own_channel_config_arg.take_inner()) }, - peer_channel_config_limits: *unsafe { Box::from_raw(peer_channel_config_limits_arg.take_inner()) }, - channel_options: *unsafe { Box::from_raw(channel_options_arg.take_inner()) }, - })), is_owned: true } -} -impl Clone for UserConfig { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeUserConfig>::is_null(self.inner) { std::ptr::null_mut() } else { - Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, - is_owned: true, - } - } -} -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn UserConfig_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUserConfig)).clone() })) as *mut c_void -} -#[no_mangle] -pub extern "C" fn UserConfig_clone(orig: &UserConfig) -> UserConfig { - orig.clone() -} -#[must_use] -#[no_mangle] -pub extern "C" fn UserConfig_default() -> UserConfig { - UserConfig { inner: Box::into_raw(Box::new(Default::default())), is_owned: true } -} diff --git a/lightning-c-bindings/src/util/errors.rs b/lightning-c-bindings/src/util/errors.rs deleted file mode 100644 index 9b0e757de..000000000 --- a/lightning-c-bindings/src/util/errors.rs +++ /dev/null @@ -1,166 +0,0 @@ -//! Error types live here. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - -/// Indicates an error on the client's part (usually some variant of attempting to use too-low or -/// too-high values) -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum APIError { - /// 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. - APIMisuseError { - err: crate::c_types::derived::CVec_u8Z, - }, - /// Due to a high feerate, we were unable to complete the request. - /// For example, this may be returned if the feerate implies we cannot open a channel at the - /// requested value, but opening a larger channel would succeed. - FeeRateTooHigh { - err: crate::c_types::derived::CVec_u8Z, - feerate: u32, - }, - /// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route, - /// too-many-hops, etc). - RouteError { - err: crate::c_types::Str, - }, - /// We were unable to complete the request as the Channel required to do so is unable to - /// complete the request (or was not found). This can take many forms, including disconnected - /// peer, channel at capacity, channel shutting down, etc. - ChannelUnavailable { - err: crate::c_types::derived::CVec_u8Z, - }, - /// An attempt to call watch/update_channel returned an Err (ie you did this!), causing the - /// attempted action to fail. - MonitorUpdateFailed, -} -use lightning::util::errors::APIError as nativeAPIError; -impl APIError { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeAPIError { - match self { - APIError::APIMisuseError {ref err, } => { - let mut err_nonref = (*err).clone(); - nativeAPIError::APIMisuseError { - err: String::from_utf8(err_nonref.into_rust()).unwrap(), - } - }, - APIError::FeeRateTooHigh {ref err, ref feerate, } => { - let mut err_nonref = (*err).clone(); - let mut feerate_nonref = (*feerate).clone(); - nativeAPIError::FeeRateTooHigh { - err: String::from_utf8(err_nonref.into_rust()).unwrap(), - feerate: feerate_nonref, - } - }, - APIError::RouteError {ref err, } => { - let mut err_nonref = (*err).clone(); - nativeAPIError::RouteError { - err: err_nonref.into(), - } - }, - APIError::ChannelUnavailable {ref err, } => { - let mut err_nonref = (*err).clone(); - nativeAPIError::ChannelUnavailable { - err: String::from_utf8(err_nonref.into_rust()).unwrap(), - } - }, - APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativeAPIError { - match self { - APIError::APIMisuseError {mut err, } => { - nativeAPIError::APIMisuseError { - err: String::from_utf8(err.into_rust()).unwrap(), - } - }, - APIError::FeeRateTooHigh {mut err, mut feerate, } => { - nativeAPIError::FeeRateTooHigh { - err: String::from_utf8(err.into_rust()).unwrap(), - feerate: feerate, - } - }, - APIError::RouteError {mut err, } => { - nativeAPIError::RouteError { - err: err.into(), - } - }, - APIError::ChannelUnavailable {mut err, } => { - nativeAPIError::ChannelUnavailable { - err: String::from_utf8(err.into_rust()).unwrap(), - } - }, - APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativeAPIError) -> Self { - match native { - nativeAPIError::APIMisuseError {ref err, } => { - let mut err_nonref = (*err).clone(); - APIError::APIMisuseError { - err: err_nonref.into_bytes().into(), - } - }, - nativeAPIError::FeeRateTooHigh {ref err, ref feerate, } => { - let mut err_nonref = (*err).clone(); - let mut feerate_nonref = (*feerate).clone(); - APIError::FeeRateTooHigh { - err: err_nonref.into_bytes().into(), - feerate: feerate_nonref, - } - }, - nativeAPIError::RouteError {ref err, } => { - let mut err_nonref = (*err).clone(); - APIError::RouteError { - err: err_nonref.into(), - } - }, - nativeAPIError::ChannelUnavailable {ref err, } => { - let mut err_nonref = (*err).clone(); - APIError::ChannelUnavailable { - err: err_nonref.into_bytes().into(), - } - }, - nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativeAPIError) -> Self { - match native { - nativeAPIError::APIMisuseError {mut err, } => { - APIError::APIMisuseError { - err: err.into_bytes().into(), - } - }, - nativeAPIError::FeeRateTooHigh {mut err, mut feerate, } => { - APIError::FeeRateTooHigh { - err: err.into_bytes().into(), - feerate: feerate, - } - }, - nativeAPIError::RouteError {mut err, } => { - APIError::RouteError { - err: err.into(), - } - }, - nativeAPIError::ChannelUnavailable {mut err, } => { - APIError::ChannelUnavailable { - err: err.into_bytes().into(), - } - }, - nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed, - } - } -} -#[no_mangle] -pub extern "C" fn APIError_free(this_ptr: APIError) { } -#[no_mangle] -pub extern "C" fn APIError_clone(orig: &APIError) -> APIError { - orig.clone() -} diff --git a/lightning-c-bindings/src/util/events.rs b/lightning-c-bindings/src/util/events.rs deleted file mode 100644 index 52893679e..000000000 --- a/lightning-c-bindings/src/util/events.rs +++ /dev/null @@ -1,1016 +0,0 @@ -//! Events are returned from various bits in the library which indicate some action must be taken -//! by the client. -//! -//! Because we don't have a built-in runtime, it's up to the client to call events at a time in the -//! future, as well as generate and broadcast funding transactions handle payment preimages and a -//! few other things. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - -/// An Event which you should probably take some action in response to. -/// -/// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use -/// them directly as they don't round-trip exactly (for example FundingGenerationReady is never -/// written as it makes no sense to respond to it after reconnecting to peers). -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum Event { - /// Used to indicate that the client should generate a funding transaction with the given - /// parameters and then call ChannelManager::funding_transaction_generated. - /// Generated in ChannelManager message handling. - /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your - /// counterparty can steal your funds! - FundingGenerationReady { - temporary_channel_id: crate::c_types::ThirtyTwoBytes, - channel_value_satoshis: u64, - output_script: crate::c_types::derived::CVec_u8Z, - user_channel_id: u64, - }, - /// Used to indicate that the client may now broadcast the funding transaction it created for a - /// channel. Broadcasting such a transaction prior to this event may lead to our counterparty - /// trivially stealing all funds in the funding transaction! - FundingBroadcastSafe { - funding_txo: crate::chain::transaction::OutPoint, - user_channel_id: u64, - }, - /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to - /// ChannelManager::claim_funds to get it.... - /// Note that if the preimage is not known or the amount paid is incorrect, you should call - /// ChannelManager::fail_htlc_backwards to free up resources for this HTLC and avoid - /// network congestion. - /// The amount paid should be considered 'incorrect' when it is less than or more than twice - /// the amount expected. - /// If you fail to call either ChannelManager::claim_funds or - /// ChannelManager::fail_htlc_backwards within the HTLC's timeout, the HTLC will be - /// automatically failed. - PaymentReceived { - payment_hash: crate::c_types::ThirtyTwoBytes, - payment_secret: crate::c_types::ThirtyTwoBytes, - amt: u64, - }, - /// Indicates an outbound payment we made succeeded (ie it made it all the way to its target - /// and we got back the payment preimage for it). - /// Note that duplicative PaymentSent Events may be generated - it is your responsibility to - /// deduplicate them by payment_preimage (which MUST be unique)! - PaymentSent { - payment_preimage: crate::c_types::ThirtyTwoBytes, - }, - /// Indicates an outbound payment we made failed. Probably some intermediary node dropped - /// something. You may wish to retry with a different route. - /// Note that duplicative PaymentFailed Events may be generated - it is your responsibility to - /// deduplicate them by payment_hash (which MUST be unique)! - PaymentFailed { - payment_hash: crate::c_types::ThirtyTwoBytes, - rejected_by_dest: bool, - }, - /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a - /// time in the future. - PendingHTLCsForwardable { - time_forwardable: u64, - }, - /// Used to indicate that an output was generated on-chain which you should know how to spend. - /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your - /// counterparty spending them due to some kind of timeout. Thus, you need to store them - /// somewhere and spend them when you create on-chain transactions. - SpendableOutputs { - outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, - }, -} -use lightning::util::events::Event as nativeEvent; -impl Event { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeEvent { - match self { - Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => { - let mut temporary_channel_id_nonref = (*temporary_channel_id).clone(); - let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone(); - let mut output_script_nonref = (*output_script).clone(); - let mut user_channel_id_nonref = (*user_channel_id).clone(); - nativeEvent::FundingGenerationReady { - temporary_channel_id: temporary_channel_id_nonref.data, - channel_value_satoshis: channel_value_satoshis_nonref, - output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()), - user_channel_id: user_channel_id_nonref, - } - }, - Event::FundingBroadcastSafe {ref funding_txo, ref user_channel_id, } => { - let mut funding_txo_nonref = (*funding_txo).clone(); - let mut user_channel_id_nonref = (*user_channel_id).clone(); - nativeEvent::FundingBroadcastSafe { - funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) }, - user_channel_id: user_channel_id_nonref, - } - }, - Event::PaymentReceived {ref payment_hash, ref payment_secret, ref amt, } => { - let mut payment_hash_nonref = (*payment_hash).clone(); - let mut payment_secret_nonref = (*payment_secret).clone(); - let mut local_payment_secret_nonref = if payment_secret_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret_nonref.data) }) }; - let mut amt_nonref = (*amt).clone(); - nativeEvent::PaymentReceived { - payment_hash: ::lightning::ln::channelmanager::PaymentHash(payment_hash_nonref.data), - payment_secret: local_payment_secret_nonref, - amt: amt_nonref, - } - }, - Event::PaymentSent {ref payment_preimage, } => { - let mut payment_preimage_nonref = (*payment_preimage).clone(); - nativeEvent::PaymentSent { - payment_preimage: ::lightning::ln::channelmanager::PaymentPreimage(payment_preimage_nonref.data), - } - }, - Event::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => { - let mut payment_hash_nonref = (*payment_hash).clone(); - let mut rejected_by_dest_nonref = (*rejected_by_dest).clone(); - nativeEvent::PaymentFailed { - payment_hash: ::lightning::ln::channelmanager::PaymentHash(payment_hash_nonref.data), - rejected_by_dest: rejected_by_dest_nonref, - } - }, - Event::PendingHTLCsForwardable {ref time_forwardable, } => { - let mut time_forwardable_nonref = (*time_forwardable).clone(); - nativeEvent::PendingHTLCsForwardable { - time_forwardable: std::time::Duration::from_secs(time_forwardable_nonref), - } - }, - Event::SpendableOutputs {ref outputs, } => { - let mut outputs_nonref = (*outputs).clone(); - let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); }; - nativeEvent::SpendableOutputs { - outputs: local_outputs_nonref, - } - }, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativeEvent { - match self { - Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => { - nativeEvent::FundingGenerationReady { - temporary_channel_id: temporary_channel_id.data, - channel_value_satoshis: channel_value_satoshis, - output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()), - user_channel_id: user_channel_id, - } - }, - Event::FundingBroadcastSafe {mut funding_txo, mut user_channel_id, } => { - nativeEvent::FundingBroadcastSafe { - funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) }, - user_channel_id: user_channel_id, - } - }, - Event::PaymentReceived {mut payment_hash, mut payment_secret, mut amt, } => { - let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) }; - nativeEvent::PaymentReceived { - payment_hash: ::lightning::ln::channelmanager::PaymentHash(payment_hash.data), - payment_secret: local_payment_secret, - amt: amt, - } - }, - Event::PaymentSent {mut payment_preimage, } => { - nativeEvent::PaymentSent { - payment_preimage: ::lightning::ln::channelmanager::PaymentPreimage(payment_preimage.data), - } - }, - Event::PaymentFailed {mut payment_hash, mut rejected_by_dest, } => { - nativeEvent::PaymentFailed { - payment_hash: ::lightning::ln::channelmanager::PaymentHash(payment_hash.data), - rejected_by_dest: rejected_by_dest, - } - }, - Event::PendingHTLCsForwardable {mut time_forwardable, } => { - nativeEvent::PendingHTLCsForwardable { - time_forwardable: std::time::Duration::from_secs(time_forwardable), - } - }, - Event::SpendableOutputs {mut outputs, } => { - let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); }; - nativeEvent::SpendableOutputs { - outputs: local_outputs, - } - }, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativeEvent) -> Self { - match native { - nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => { - let mut temporary_channel_id_nonref = (*temporary_channel_id).clone(); - let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone(); - let mut output_script_nonref = (*output_script).clone(); - let mut user_channel_id_nonref = (*user_channel_id).clone(); - Event::FundingGenerationReady { - temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref }, - channel_value_satoshis: channel_value_satoshis_nonref, - output_script: output_script_nonref.into_bytes().into(), - user_channel_id: user_channel_id_nonref, - } - }, - nativeEvent::FundingBroadcastSafe {ref funding_txo, ref user_channel_id, } => { - let mut funding_txo_nonref = (*funding_txo).clone(); - let mut user_channel_id_nonref = (*user_channel_id).clone(); - Event::FundingBroadcastSafe { - funding_txo: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo_nonref)), is_owned: true }, - user_channel_id: user_channel_id_nonref, - } - }, - nativeEvent::PaymentReceived {ref payment_hash, ref payment_secret, ref amt, } => { - let mut payment_hash_nonref = (*payment_hash).clone(); - let mut payment_secret_nonref = (*payment_secret).clone(); - let mut local_payment_secret_nonref = if payment_secret_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_secret_nonref.unwrap()).0 } } }; - let mut amt_nonref = (*amt).clone(); - Event::PaymentReceived { - payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 }, - payment_secret: local_payment_secret_nonref, - amt: amt_nonref, - } - }, - nativeEvent::PaymentSent {ref payment_preimage, } => { - let mut payment_preimage_nonref = (*payment_preimage).clone(); - Event::PaymentSent { - payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 }, - } - }, - nativeEvent::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => { - let mut payment_hash_nonref = (*payment_hash).clone(); - let mut rejected_by_dest_nonref = (*rejected_by_dest).clone(); - Event::PaymentFailed { - payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 }, - rejected_by_dest: rejected_by_dest_nonref, - } - }, - nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => { - let mut time_forwardable_nonref = (*time_forwardable).clone(); - Event::PendingHTLCsForwardable { - time_forwardable: time_forwardable_nonref.as_secs(), - } - }, - nativeEvent::SpendableOutputs {ref outputs, } => { - let mut outputs_nonref = (*outputs).clone(); - let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.drain(..) { local_outputs_nonref.push( { crate::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); }; - Event::SpendableOutputs { - outputs: local_outputs_nonref.into(), - } - }, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativeEvent) -> Self { - match native { - nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => { - Event::FundingGenerationReady { - temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id }, - channel_value_satoshis: channel_value_satoshis, - output_script: output_script.into_bytes().into(), - user_channel_id: user_channel_id, - } - }, - nativeEvent::FundingBroadcastSafe {mut funding_txo, mut user_channel_id, } => { - Event::FundingBroadcastSafe { - funding_txo: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo)), is_owned: true }, - user_channel_id: user_channel_id, - } - }, - nativeEvent::PaymentReceived {mut payment_hash, mut payment_secret, mut amt, } => { - let mut local_payment_secret = if payment_secret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_secret.unwrap()).0 } } }; - Event::PaymentReceived { - payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 }, - payment_secret: local_payment_secret, - amt: amt, - } - }, - nativeEvent::PaymentSent {mut payment_preimage, } => { - Event::PaymentSent { - payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 }, - } - }, - nativeEvent::PaymentFailed {mut payment_hash, mut rejected_by_dest, } => { - Event::PaymentFailed { - payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 }, - rejected_by_dest: rejected_by_dest, - } - }, - nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => { - Event::PendingHTLCsForwardable { - time_forwardable: time_forwardable.as_secs(), - } - }, - nativeEvent::SpendableOutputs {mut outputs, } => { - let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); }; - Event::SpendableOutputs { - outputs: local_outputs.into(), - } - }, - } - } -} -#[no_mangle] -pub extern "C" fn Event_free(this_ptr: Event) { } -#[no_mangle] -pub extern "C" fn Event_clone(orig: &Event) -> Event { - orig.clone() -} -#[no_mangle] -pub extern "C" fn Event_write(obj: &Event) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) -} -/// An event generated by ChannelManager which indicates a message should be sent to a peer (or -/// broadcast to most peers). -/// These events are handled by PeerManager::process_events if you are using a PeerManager. -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum MessageSendEvent { - /// Used to indicate that we've accepted a channel open and should send the accept_channel - /// message provided to the given peer. - SendAcceptChannel { - node_id: crate::c_types::PublicKey, - msg: crate::ln::msgs::AcceptChannel, - }, - /// Used to indicate that we've initiated a channel open and should send the open_channel - /// message provided to the given peer. - SendOpenChannel { - node_id: crate::c_types::PublicKey, - msg: crate::ln::msgs::OpenChannel, - }, - /// Used to indicate that a funding_created message should be sent to the peer with the given node_id. - SendFundingCreated { - node_id: crate::c_types::PublicKey, - msg: crate::ln::msgs::FundingCreated, - }, - /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id. - SendFundingSigned { - node_id: crate::c_types::PublicKey, - msg: crate::ln::msgs::FundingSigned, - }, - /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id. - SendFundingLocked { - node_id: crate::c_types::PublicKey, - msg: crate::ln::msgs::FundingLocked, - }, - /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id. - SendAnnouncementSignatures { - node_id: crate::c_types::PublicKey, - msg: crate::ln::msgs::AnnouncementSignatures, - }, - /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed - /// message should be sent to the peer with the given node_id. - UpdateHTLCs { - node_id: crate::c_types::PublicKey, - updates: crate::ln::msgs::CommitmentUpdate, - }, - /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id. - SendRevokeAndACK { - node_id: crate::c_types::PublicKey, - msg: crate::ln::msgs::RevokeAndACK, - }, - /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id. - SendClosingSigned { - node_id: crate::c_types::PublicKey, - msg: crate::ln::msgs::ClosingSigned, - }, - /// Used to indicate that a shutdown message should be sent to the peer with the given node_id. - SendShutdown { - node_id: crate::c_types::PublicKey, - msg: crate::ln::msgs::Shutdown, - }, - /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id. - SendChannelReestablish { - node_id: crate::c_types::PublicKey, - msg: crate::ln::msgs::ChannelReestablish, - }, - /// Used to indicate that a channel_announcement and channel_update should be broadcast to all - /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2). - /// - /// Note that after doing so, you very likely (unless you did so very recently) want to call - /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event. - /// This ensures that any nodes which see our channel_announcement also have a relevant - /// node_announcement, including relevant feature flags which may be important for routing - /// through or to us. - BroadcastChannelAnnouncement { - msg: crate::ln::msgs::ChannelAnnouncement, - update_msg: crate::ln::msgs::ChannelUpdate, - }, - /// Used to indicate that a node_announcement should be broadcast to all peers. - BroadcastNodeAnnouncement { - msg: crate::ln::msgs::NodeAnnouncement, - }, - /// Used to indicate that a channel_update should be broadcast to all peers. - BroadcastChannelUpdate { - msg: crate::ln::msgs::ChannelUpdate, - }, - /// Broadcast an error downstream to be handled - HandleError { - node_id: crate::c_types::PublicKey, - action: crate::ln::msgs::ErrorAction, - }, - /// When a payment fails we may receive updates back from the hop where it failed. In such - /// cases this event is generated so that we can inform the network graph of this information. - PaymentFailureNetworkUpdate { - update: crate::ln::msgs::HTLCFailChannelUpdate, - }, - /// Query a peer for channels with funding transaction UTXOs in a block range. - SendChannelRangeQuery { - node_id: crate::c_types::PublicKey, - msg: crate::ln::msgs::QueryChannelRange, - }, - /// Request routing gossip messages from a peer for a list of channels identified by - /// their short_channel_ids. - SendShortIdsQuery { - node_id: crate::c_types::PublicKey, - msg: crate::ln::msgs::QueryShortChannelIds, - }, -} -use lightning::util::events::MessageSendEvent as nativeMessageSendEvent; -impl MessageSendEvent { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeMessageSendEvent { - match self { - MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::SendAcceptChannel { - node_id: node_id_nonref.into_rust(), - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::SendOpenChannel { - node_id: node_id_nonref.into_rust(), - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::SendFundingCreated { - node_id: node_id_nonref.into_rust(), - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::SendFundingSigned { - node_id: node_id_nonref.into_rust(), - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::SendFundingLocked { - node_id: node_id_nonref.into_rust(), - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::SendAnnouncementSignatures { - node_id: node_id_nonref.into_rust(), - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut updates_nonref = (*updates).clone(); - nativeMessageSendEvent::UpdateHTLCs { - node_id: node_id_nonref.into_rust(), - updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) }, - } - }, - MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::SendRevokeAndACK { - node_id: node_id_nonref.into_rust(), - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::SendClosingSigned { - node_id: node_id_nonref.into_rust(), - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::SendShutdown {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::SendShutdown { - node_id: node_id_nonref.into_rust(), - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::SendChannelReestablish { - node_id: node_id_nonref.into_rust(), - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => { - let mut msg_nonref = (*msg).clone(); - let mut update_msg_nonref = (*update_msg).clone(); - nativeMessageSendEvent::BroadcastChannelAnnouncement { - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => { - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::BroadcastNodeAnnouncement { - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::BroadcastChannelUpdate {ref msg, } => { - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::BroadcastChannelUpdate { - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::HandleError {ref node_id, ref action, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut action_nonref = (*action).clone(); - nativeMessageSendEvent::HandleError { - node_id: node_id_nonref.into_rust(), - action: action_nonref.into_native(), - } - }, - MessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => { - let mut update_nonref = (*update).clone(); - nativeMessageSendEvent::PaymentFailureNetworkUpdate { - update: update_nonref.into_native(), - } - }, - MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::SendChannelRangeQuery { - node_id: node_id_nonref.into_rust(), - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - nativeMessageSendEvent::SendShortIdsQuery { - node_id: node_id_nonref.into_rust(), - msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, - } - }, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativeMessageSendEvent { - match self { - MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => { - nativeMessageSendEvent::SendAcceptChannel { - node_id: node_id.into_rust(), - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => { - nativeMessageSendEvent::SendOpenChannel { - node_id: node_id.into_rust(), - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => { - nativeMessageSendEvent::SendFundingCreated { - node_id: node_id.into_rust(), - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => { - nativeMessageSendEvent::SendFundingSigned { - node_id: node_id.into_rust(), - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => { - nativeMessageSendEvent::SendFundingLocked { - node_id: node_id.into_rust(), - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => { - nativeMessageSendEvent::SendAnnouncementSignatures { - node_id: node_id.into_rust(), - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => { - nativeMessageSendEvent::UpdateHTLCs { - node_id: node_id.into_rust(), - updates: *unsafe { Box::from_raw(updates.take_inner()) }, - } - }, - MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => { - nativeMessageSendEvent::SendRevokeAndACK { - node_id: node_id.into_rust(), - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => { - nativeMessageSendEvent::SendClosingSigned { - node_id: node_id.into_rust(), - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - MessageSendEvent::SendShutdown {mut node_id, mut msg, } => { - nativeMessageSendEvent::SendShutdown { - node_id: node_id.into_rust(), - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => { - nativeMessageSendEvent::SendChannelReestablish { - node_id: node_id.into_rust(), - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => { - nativeMessageSendEvent::BroadcastChannelAnnouncement { - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) }, - } - }, - MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => { - nativeMessageSendEvent::BroadcastNodeAnnouncement { - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - MessageSendEvent::BroadcastChannelUpdate {mut msg, } => { - nativeMessageSendEvent::BroadcastChannelUpdate { - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - MessageSendEvent::HandleError {mut node_id, mut action, } => { - nativeMessageSendEvent::HandleError { - node_id: node_id.into_rust(), - action: action.into_native(), - } - }, - MessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => { - nativeMessageSendEvent::PaymentFailureNetworkUpdate { - update: update.into_native(), - } - }, - MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => { - nativeMessageSendEvent::SendChannelRangeQuery { - node_id: node_id.into_rust(), - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => { - nativeMessageSendEvent::SendShortIdsQuery { - node_id: node_id.into_rust(), - msg: *unsafe { Box::from_raw(msg.take_inner()) }, - } - }, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self { - match native { - nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::SendAcceptChannel { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - msg: crate::ln::msgs::AcceptChannel { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::SendOpenChannel { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - msg: crate::ln::msgs::OpenChannel { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::SendFundingCreated { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - msg: crate::ln::msgs::FundingCreated { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::SendFundingSigned { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - msg: crate::ln::msgs::FundingSigned { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::SendFundingLocked { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - msg: crate::ln::msgs::FundingLocked { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::SendAnnouncementSignatures { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - msg: crate::ln::msgs::AnnouncementSignatures { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut updates_nonref = (*updates).clone(); - MessageSendEvent::UpdateHTLCs { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - updates: crate::ln::msgs::CommitmentUpdate { inner: Box::into_raw(Box::new(updates_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::SendRevokeAndACK { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - msg: crate::ln::msgs::RevokeAndACK { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::SendClosingSigned { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - msg: crate::ln::msgs::ClosingSigned { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::SendShutdown { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - msg: crate::ln::msgs::Shutdown { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::SendChannelReestablish { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - msg: crate::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => { - let mut msg_nonref = (*msg).clone(); - let mut update_msg_nonref = (*update_msg).clone(); - MessageSendEvent::BroadcastChannelAnnouncement { - msg: crate::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - update_msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(update_msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => { - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::BroadcastNodeAnnouncement { - msg: crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => { - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::BroadcastChannelUpdate { - msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::HandleError {ref node_id, ref action, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut action_nonref = (*action).clone(); - MessageSendEvent::HandleError { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - action: crate::ln::msgs::ErrorAction::native_into(action_nonref), - } - }, - nativeMessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => { - let mut update_nonref = (*update).clone(); - MessageSendEvent::PaymentFailureNetworkUpdate { - update: crate::ln::msgs::HTLCFailChannelUpdate::native_into(update_nonref), - } - }, - nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::SendChannelRangeQuery { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - msg: crate::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => { - let mut node_id_nonref = (*node_id).clone(); - let mut msg_nonref = (*msg).clone(); - MessageSendEvent::SendShortIdsQuery { - node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref), - msg: crate::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true }, - } - }, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self { - match native { - nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => { - MessageSendEvent::SendAcceptChannel { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - msg: crate::ln::msgs::AcceptChannel { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => { - MessageSendEvent::SendOpenChannel { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - msg: crate::ln::msgs::OpenChannel { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => { - MessageSendEvent::SendFundingCreated { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - msg: crate::ln::msgs::FundingCreated { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => { - MessageSendEvent::SendFundingSigned { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - msg: crate::ln::msgs::FundingSigned { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => { - MessageSendEvent::SendFundingLocked { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - msg: crate::ln::msgs::FundingLocked { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => { - MessageSendEvent::SendAnnouncementSignatures { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - msg: crate::ln::msgs::AnnouncementSignatures { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => { - MessageSendEvent::UpdateHTLCs { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - updates: crate::ln::msgs::CommitmentUpdate { inner: Box::into_raw(Box::new(updates)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => { - MessageSendEvent::SendRevokeAndACK { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - msg: crate::ln::msgs::RevokeAndACK { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => { - MessageSendEvent::SendClosingSigned { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - msg: crate::ln::msgs::ClosingSigned { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => { - MessageSendEvent::SendShutdown { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - msg: crate::ln::msgs::Shutdown { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => { - MessageSendEvent::SendChannelReestablish { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - msg: crate::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => { - MessageSendEvent::BroadcastChannelAnnouncement { - msg: crate::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - update_msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(update_msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => { - MessageSendEvent::BroadcastNodeAnnouncement { - msg: crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => { - MessageSendEvent::BroadcastChannelUpdate { - msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::HandleError {mut node_id, mut action, } => { - MessageSendEvent::HandleError { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - action: crate::ln::msgs::ErrorAction::native_into(action), - } - }, - nativeMessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => { - MessageSendEvent::PaymentFailureNetworkUpdate { - update: crate::ln::msgs::HTLCFailChannelUpdate::native_into(update), - } - }, - nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => { - MessageSendEvent::SendChannelRangeQuery { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - msg: crate::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => { - MessageSendEvent::SendShortIdsQuery { - node_id: crate::c_types::PublicKey::from_rust(&node_id), - msg: crate::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg)), is_owned: true }, - } - }, - } - } -} -#[no_mangle] -pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { } -#[no_mangle] -pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent { - orig.clone() -} -/// A trait indicating an object may generate message send events -#[repr(C)] -pub struct MessageSendEventsProvider { - pub this_arg: *mut c_void, - /// Gets the list of pending events which were generated by previous actions, clearing the list - /// in the process. - #[must_use] - pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ, - pub free: Option, -} - -use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider; -impl rustMessageSendEventsProvider for MessageSendEventsProvider { - fn get_and_clear_pending_msg_events(&self) -> Vec { - let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg); - let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); }; - local_ret - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for MessageSendEventsProvider { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { } -impl Drop for MessageSendEventsProvider { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} -/// A trait indicating an object may generate events -#[repr(C)] -pub struct EventsProvider { - pub this_arg: *mut c_void, - /// Gets the list of pending events which were generated by previous actions, clearing the list - /// in the process. - #[must_use] - pub get_and_clear_pending_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_EventZ, - pub free: Option, -} - -use lightning::util::events::EventsProvider as rustEventsProvider; -impl rustEventsProvider for EventsProvider { - fn get_and_clear_pending_events(&self) -> Vec { - let mut ret = (self.get_and_clear_pending_events)(self.this_arg); - let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); }; - local_ret - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for EventsProvider { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { } -impl Drop for EventsProvider { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} diff --git a/lightning-c-bindings/src/util/logger.rs b/lightning-c-bindings/src/util/logger.rs deleted file mode 100644 index 8a1fbb15d..000000000 --- a/lightning-c-bindings/src/util/logger.rs +++ /dev/null @@ -1,125 +0,0 @@ -//! Log traits live here, which are called throughout the library to provide useful information for -//! debugging purposes. -//! -//! There is currently 2 ways to filter log messages. First one, by using compilation features, e.g \"max_level_off\". -//! The second one, client-side by implementing check against Record Level field. -//! Each module may have its own Logger or share one. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - -/// An enum representing the available verbosity levels of the logger. -#[must_use] -#[derive(Clone)] -#[repr(C)] -pub enum Level { - ///Designates logger being silent - Off, - /// Designates very serious errors - Error, - /// Designates hazardous situations - Warn, - /// Designates useful information - Info, - /// Designates lower priority information - Debug, - /// Designates very low priority, often extremely verbose, information - Trace, -} -use lightning::util::logger::Level as nativeLevel; -impl Level { - #[allow(unused)] - pub(crate) fn to_native(&self) -> nativeLevel { - match self { - Level::Off => nativeLevel::Off, - Level::Error => nativeLevel::Error, - Level::Warn => nativeLevel::Warn, - Level::Info => nativeLevel::Info, - Level::Debug => nativeLevel::Debug, - Level::Trace => nativeLevel::Trace, - } - } - #[allow(unused)] - pub(crate) fn into_native(self) -> nativeLevel { - match self { - Level::Off => nativeLevel::Off, - Level::Error => nativeLevel::Error, - Level::Warn => nativeLevel::Warn, - Level::Info => nativeLevel::Info, - Level::Debug => nativeLevel::Debug, - Level::Trace => nativeLevel::Trace, - } - } - #[allow(unused)] - pub(crate) fn from_native(native: &nativeLevel) -> Self { - match native { - nativeLevel::Off => Level::Off, - nativeLevel::Error => Level::Error, - nativeLevel::Warn => Level::Warn, - nativeLevel::Info => Level::Info, - nativeLevel::Debug => Level::Debug, - nativeLevel::Trace => Level::Trace, - } - } - #[allow(unused)] - pub(crate) fn native_into(native: nativeLevel) -> Self { - match native { - nativeLevel::Off => Level::Off, - nativeLevel::Error => Level::Error, - nativeLevel::Warn => Level::Warn, - nativeLevel::Info => Level::Info, - nativeLevel::Debug => Level::Debug, - nativeLevel::Trace => Level::Trace, - } - } -} -#[no_mangle] -pub extern "C" fn Level_clone(orig: &Level) -> Level { - orig.clone() -} -/// Returns the most verbose logging level. -#[must_use] -#[no_mangle] -pub extern "C" fn Level_max() -> crate::util::logger::Level { - let mut ret = lightning::util::logger::Level::max(); - crate::util::logger::Level::native_into(ret) -} - -/// A trait encapsulating the operations required of a logger -#[repr(C)] -pub struct Logger { - pub this_arg: *mut c_void, - /// Logs the `Record` - pub log: extern "C" fn (this_arg: *const c_void, record: *const std::os::raw::c_char), - pub free: Option, -} -unsafe impl Sync for Logger {} -unsafe impl Send for Logger {} - -use lightning::util::logger::Logger as rustLogger; -impl rustLogger for Logger { - fn log(&self, record: &lightning::util::logger::Record) { - let mut local_record = std::ffi::CString::new(format!("{}", record.args)).unwrap(); - (self.log)(self.this_arg, local_record.as_ptr()) - } -} - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl std::ops::Deref for Logger { - type Target = Self; - fn deref(&self) -> &Self { - self - } -} -/// Calls the free function if one is set -#[no_mangle] -pub extern "C" fn Logger_free(this_ptr: Logger) { } -impl Drop for Logger { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); - } - } -} diff --git a/lightning-c-bindings/src/util/macro_logger.rs b/lightning-c-bindings/src/util/macro_logger.rs deleted file mode 100644 index 79c1ea1bb..000000000 --- a/lightning-c-bindings/src/util/macro_logger.rs +++ /dev/null @@ -1,6 +0,0 @@ -/// Logging macro utilities. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - diff --git a/lightning-c-bindings/src/util/mod.rs b/lightning-c-bindings/src/util/mod.rs deleted file mode 100644 index 8e5bf04b8..000000000 --- a/lightning-c-bindings/src/util/mod.rs +++ /dev/null @@ -1,12 +0,0 @@ -//! Some utility modules live here. See individual sub-modules for more info. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - -pub mod events; -pub mod errors; -pub mod ser; -pub mod macro_logger; -pub mod logger; -pub mod config; diff --git a/lightning-c-bindings/src/util/ser.rs b/lightning-c-bindings/src/util/ser.rs deleted file mode 100644 index db9549c65..000000000 --- a/lightning-c-bindings/src/util/ser.rs +++ /dev/null @@ -1,10 +0,0 @@ -//! A very simple serialization framework which is used to serialize/deserialize messages as well -//! as ChannelsManagers and ChannelMonitors. - -use std::ffi::c_void; -use bitcoin::hashes::Hash; -use crate::c_types::*; - - -#[no_mangle] -pub static MAX_BUF_SIZE: usize = lightning::util::ser::MAX_BUF_SIZE;