writeln!(w, "pub extern \"C\" fn {}_free(_res: {}) {{ }}", mangled_container, mangled_container).unwrap();
}
+/// Writes out a C-callable concrete Option<A> struct and utility methods
+pub fn write_option_block<W: std::io::Write>(w: &mut W, mangled_container: &str, inner_type: &str, clonable: bool) {
+ writeln!(w, "#[repr(C)]").unwrap();
+ if clonable {
+ writeln!(w, "#[derive(Clone)]").unwrap();
+ }
+ writeln!(w, "pub enum {} {{", mangled_container).unwrap();
+ writeln!(w, "\tSome({}),", inner_type).unwrap();
+ writeln!(w, "\tNone").unwrap();
+ writeln!(w, "}}").unwrap();
+
+ writeln!(w, "impl {} {{", mangled_container).unwrap();
+ writeln!(w, "\t#[allow(unused)] pub(crate) fn is_some(&self) -> bool {{").unwrap();
+ writeln!(w, "\t\tif let Self::Some(_) = self {{ true }} else {{ false }}").unwrap();
+ writeln!(w, "\t}}").unwrap();
+ writeln!(w, "\t#[allow(unused)] pub(crate) fn take(mut self) -> {} {{", inner_type).unwrap();
+ writeln!(w, "\t\tif let Self::Some(v) = self {{ v }} else {{ unreachable!() }}").unwrap();
+ writeln!(w, "\t}}").unwrap();
+ writeln!(w, "}}").unwrap();
+
+ writeln!(w, "#[no_mangle]").unwrap();
+ writeln!(w, "pub extern \"C\" fn {}_some(o: {}) -> {} {{", mangled_container, inner_type, mangled_container).unwrap();
+ writeln!(w, "\t{}::Some(o)", mangled_container).unwrap();
+ writeln!(w, "}}").unwrap();
+
+ writeln!(w, "#[no_mangle]").unwrap();
+ writeln!(w, "pub extern \"C\" fn {}_none() -> {} {{", mangled_container, mangled_container).unwrap();
+ writeln!(w, "\t{}::None", mangled_container).unwrap();
+ writeln!(w, "}}").unwrap();
+
+ writeln!(w, "#[no_mangle]").unwrap();
+ writeln!(w, "pub extern \"C\" fn {}_free(_res: {}) {{ }}", mangled_container, mangled_container).unwrap();
+ if clonable {
+ writeln!(w, "#[no_mangle]").unwrap();
+ writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{ orig.clone() }}", mangled_container, mangled_container, mangled_container).unwrap();
+ }
+}
+
/// Prints the docs from a given attribute list unless its tagged no export
pub fn writeln_docs<W: std::io::Write>(w: &mut W, attrs: &[syn::Attribute], prefix: &str) {
for attr in attrs.iter() {
ReferenceAsPointer,
}
+#[derive(PartialEq)]
+/// Describes the appropriate place to print a general type-conversion string when converting a
+/// container.
+enum ContainerPrefixLocation {
+ /// Prints a general type-conversion string prefix and suffix outside of the
+ /// container-conversion strings.
+ OutsideConv,
+ /// Prints a general type-conversion string prefix and suffix inside of the
+ /// container-conversion strings.
+ PerConv,
+ /// Does not print the usual type-conversion string prefix and suffix.
+ NoPrefix,
+}
+
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 }
"crate::c_types"
}
- /// Returns true if this is a "transparent" container, ie an Option or a container which does
+ /// Returns true if the path containing the given args is a "transparent" container, ie an
+ /// Option or a container which does not require a generated continer class.
+ fn is_transparent_container<'i, I: Iterator<Item=&'i syn::Type>>(&self, full_path: &str, _is_ref: bool, mut args: I) -> bool {
+ if full_path == "Option" {
+ let inner = args.next().unwrap();
+ assert!(args.next().is_none());
+ match inner {
+ syn::Type::Reference(_) => true,
+ syn::Type::Path(p) => {
+ if let Some(resolved) = self.maybe_resolve_path(&p.path, None) {
+ if self.is_primitive(&resolved) { false } else { true }
+ } else { true }
+ },
+ syn::Type::Tuple(_) => false,
+ _ => unimplemented!(),
+ }
+ } else { false }
+ }
+ /// Returns true if the path 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"
+ fn is_path_transparent_container(&self, full_path: &syn::Path, generics: Option<&GenericTypes>, is_ref: bool) -> bool {
+ let inner_iter = match &full_path.segments.last().unwrap().arguments {
+ syn::PathArguments::None => return false,
+ syn::PathArguments::AngleBracketed(args) => args.args.iter().map(|arg| {
+ if let syn::GenericArgument::Type(ref ty) = arg {
+ ty
+ } else { unimplemented!() }
+ }),
+ syn::PathArguments::Parenthesized(_) => unimplemented!(),
+ };
+ self.is_transparent_container(&self.resolve_path(full_path, generics), is_ref, inner_iter)
}
/// 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")
+ (full_path == "Result" && !is_ref) || (full_path == "Vec" && !is_ref) || full_path.ends_with("Tuple") || full_path == "Option"
}
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)> {
+ -> Option<(&'b str, Vec<(String, String)>, &'b str, ContainerPrefixLocation)> {
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() }"))
+ ").into() }", ContainerPrefixLocation::PerConv))
},
"Vec" if !is_ref => {
- Some(("Vec::new(); for mut item in ", vec![(format!(".drain(..) {{ local_{}.push(", var_name), "item".to_string())], "); }"))
+ Some(("Vec::new(); for mut item in ", vec![(format!(".drain(..) {{ local_{}.push(", var_name), "item".to_string())], "); }", ContainerPrefixLocation::PerConv))
},
"Slice" => {
- Some(("Vec::new(); for item in ", vec![(format!(".iter() {{ local_{}.push(", var_name), "**item".to_string())], "); }"))
+ Some(("Vec::new(); for item in ", vec![(format!(".iter() {{ local_{}.push(", var_name), "**item".to_string())], "); }", ContainerPrefixLocation::PerConv))
},
"Option" => {
if let Some(syn::Type::Path(p)) = single_contained {
- if self.c_type_has_inner_from_path(&self.resolve_path(&p.path, generics)) {
+ let inner_path = self.resolve_path(&p.path, generics);
+ if self.is_primitive(&inner_path) {
+ return Some(("if ", vec![
+ (format!(".is_none() {{ {}::COption_{}Z::None }} else {{ ", Self::generated_container_path(), inner_path),
+ format!("{}::COption_{}Z::Some({}.unwrap())", Self::generated_container_path(), inner_path, var_access))
+ ], " }", ContainerPrefixLocation::NoPrefix));
+ } else if self.c_type_has_inner_from_path(&inner_path) {
if is_ref {
return Some(("if ", vec![
(".is_none() { std::ptr::null() } else { ".to_owned(), format!("({}.as_ref().unwrap())", var_access))
- ], " }"));
+ ], " }", ContainerPrefixLocation::OutsideConv));
} else {
return Some(("if ", vec![
(".is_none() { std::ptr::null_mut() } else { ".to_owned(), format!("({}.unwrap())", var_access))
- ], " }"));
+ ], " }", ContainerPrefixLocation::OutsideConv));
}
}
}
let s = String::from_utf8(v).unwrap();
return Some(("if ", vec![
(format!(".is_none() {{ {} }} else {{ ", s), format!("({}.unwrap())", var_access))
- ], " }"));
+ ], " }", ContainerPrefixLocation::PerConv));
} else { unreachable!(); }
},
_ => None,
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)> {
+ -> Option<(&'b str, Vec<(String, String)>, &'b str, ContainerPrefixLocation)> {
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())], "); }"))
+ ")}", ContainerPrefixLocation::PerConv))
},
"Slice" if is_ref => {
- Some(("Vec::new(); for mut item in ", vec![(format!(".as_slice().iter() {{ local_{}.push(", var_name), "item".to_string())], "); }"))
+ Some(("Vec::new(); for mut item in ", vec![(format!(".as_slice().iter() {{ local_{}.push(", var_name), "item".to_string())], "); }", ContainerPrefixLocation::PerConv))
+ },
+ "Vec"|"Slice" => {
+ Some(("Vec::new(); for mut item in ", vec![(format!(".into_rust().drain(..) {{ local_{}.push(", var_name), "item".to_string())], "); }", ContainerPrefixLocation::PerConv))
},
"Option" => {
if let Some(syn::Type::Path(p)) = single_contained {
- if self.c_type_has_inner_from_path(&self.resolve_path(&p.path, generics)) {
+ let inner_path = self.resolve_path(&p.path, generics);
+ if self.is_primitive(&inner_path) {
+ return Some(("if ", vec![(".is_some() { Some(".to_string(), format!("{}.take()", var_access))], ") } else { None }", ContainerPrefixLocation::NoPrefix))
+ } else if self.c_type_has_inner_from_path(&inner_path) {
if is_ref {
- return Some(("if ", vec![(".inner.is_null() { None } else { Some((*".to_string(), format!("{}", var_access))], ").clone()) }"))
+ return Some(("if ", vec![(".inner.is_null() { None } else { Some((*".to_string(), format!("{}", var_access))], ").clone()) }", ContainerPrefixLocation::PerConv))
} else {
- return Some(("if ", vec![(".inner.is_null() { None } else { Some(".to_string(), format!("{}", var_access))], ") }"));
+ return Some(("if ", vec![(".inner.is_null() { None } else { Some(".to_string(), format!("{}", var_access))], ") }", ContainerPrefixLocation::PerConv));
}
}
}
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))
- ], ") }")),
+ match t {
+ syn::Type::Reference(_)|syn::Type::Path(_)|syn::Type::Slice(_) => {
+ 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))
+ ], ") }", ContainerPrefixLocation::NoPrefix)),
+ EmptyValExpectedTy::OwnedPointer => {
+ if let syn::Type::Slice(_) = t {
+ panic!();
+ }
+ return Some(("if ", vec![
+ (format!("{} {{ None }} else {{ Some(", s), format!("unsafe {{ *Box::from_raw({}) }}", var_access))
+ ], ") }", ContainerPrefixLocation::NoPrefix));
+ }
+ EmptyValExpectedTy::NonPointer =>
+ return Some(("if ", vec![
+ (format!("{} {{ None }} else {{ Some(", s), format!("{}", var_access))
+ ], ") }", ContainerPrefixLocation::PerConv)),
+ }
+ },
+ syn::Type::Tuple(_) => {
+ return Some(("if ", vec![(".is_some() { Some(".to_string(), format!("{}.take()", var_access))], ") } else { None }", ContainerPrefixLocation::PerConv))
+ },
+ _ => unimplemented!(),
}
} else { unreachable!(); }
},
}
}
+ fn is_real_type_array(&self, resolved_type: &str) -> Option<syn::Type> {
+ if let Some(real_ty) = self.c_type_from_path(&resolved_type, true, false) {
+ if real_ty.ends_with("]") && real_ty.starts_with("*const [u8; ") {
+ let mut split = real_ty.split("; ");
+ split.next().unwrap();
+ let tail_str = split.next().unwrap();
+ assert!(split.next().is_none());
+ let len = &tail_str[..tail_str.len() - 1];
+ Some(syn::Type::Array(syn::TypeArray {
+ bracket_token: syn::token::Bracket { span: Span::call_site() },
+ elem: Box::new(syn::Type::Path(syn::TypePath {
+ qself: None,
+ path: syn::Path::from(syn::PathSegment::from(syn::Ident::new("u8", Span::call_site()))),
+ })),
+ semi_token: syn::Token!(;)(Span::call_site()),
+ len: syn::Expr::Lit(syn::ExprLit { attrs: Vec::new(), lit: syn::Lit::Int(syn::LitInt::new(len, Span::call_site())) }),
+ }))
+ } else { None }
+ } else { None }
+ }
+
/// 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<W: std::io::Write>(&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 let Some(arr_ty) = self.is_real_type_array(&resolved) {
+ write!(w, ".data").unwrap();
+ return self.write_empty_rust_val_check_suffix(generics, w, &arr_ty);
+ }
if self.crate_types.opaques.get(&resolved).is_some() {
write!(w, ".inner.is_null()").unwrap();
EmptyValExpectedTy::NonPointer
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)>,
+ LC: Fn(&str, bool, Option<&syn::Type>, &syn::Ident, &str) -> Option<(&'b str, Vec<(String, String)>, &'b str, ContainerPrefixLocation)>,
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>,
// 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_has_inner = if $args_len == 1 {
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
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) {
+ if $args_len == 1 {
only_contained_has_inner = ty_has_inner;
let arg = $args_iter().next().unwrap();
if let syn::Type::Reference(t) = arg {
} 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 {
+ // If the inner element contains an inner pointer, we will just use that,
+ // avoiding the need to map elements to references. Otherwise we'll need to
+ // do an extra mapping step.
+ needs_ref_map = !only_contained_has_inner;
+ } else {
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) {
+ if let Some((prefix, conversions, suffix, prefix_location)) = 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 {
+ if prefix_location == ContainerPrefixLocation::OutsideConv {
var_prefix(w, $args_iter().next().unwrap(), generics, is_ref, ptr_for_ref, true);
}
write!(w, "{}{}", prefix, var).unwrap();
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 {
+ if prefix_location == ContainerPrefixLocation::PerConv {
+ var_prefix(w, conv_ty, generics, is_ref && ty_has_inner, ptr_for_ref, false);
+ } else 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 {
+ if prefix_location == ContainerPrefixLocation::PerConv {
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 {
+ } else 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 {
+ if prefix_location == ContainerPrefixLocation::OutsideConv {
var_suffix(w, $args_iter().next().unwrap(), generics, is_ref, ptr_for_ref, true);
}
write!(w, ";").unwrap();
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 self.is_known_container(&resolved_path, is_ref) || self.is_path_transparent_container(&p.path, generics, 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 {
} else if let syn::Type::Reference(ty) = &*s.elem {
let tyref = [&*ty.elem];
is_ref = true;
- convert_container!("Slice", 1, || tyref.iter());
+ convert_container!("Slice", 1, || tyref.iter().map(|t| *t));
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.
// ******************************************************
fn write_template_generics<'b, W: std::io::Write>(&mut self, w: &mut W, args: &mut dyn Iterator<Item=&'b syn::Type>, generics: Option<&GenericTypes>, is_ref: bool) -> bool {
- 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 {
+ assert!(!is_ref); // We don't currently support outer reference types for non-primitive inners
+
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
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 let syn::Type::Path(p_arg) = t {
+ if let Some(resolved) = self.maybe_resolve_path(&p_arg.path, generics) {
+ if !self.is_primitive(&resolved) {
+ assert!(!is_ref); // We don't currently support outer reference types for non-primitive inners
+ }
+ } else {
+ assert!(!is_ref); // We don't currently support outer reference types for non-primitive inners
+ }
+ if !self.write_c_type_intern(w, t, generics, false, false, false) { return false; }
} else {
+ assert!(!is_ref); // We don't currently support outer reference types for non-primitive inners
if !self.write_c_type_intern(w, t, generics, false, false, false) { return false; }
}
}
if is_clonable {
self.crate_types.clonable_types.insert(Self::generated_container_path().to_owned() + "::" + &mangled_container);
}
+ } else if container_type == "Option" {
+ let mut a_ty: Vec<u8> = Vec::new();
+ if !self.write_template_generics(&mut a_ty, &mut args.iter().map(|t| *t), generics, is_ref) { return false; }
+ let ty = String::from_utf8(a_ty).unwrap();
+ let is_clonable = self.is_clonable(&ty);
+ write_option_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 {
unreachable!();
}
fn write_c_mangled_container_path_intern<W: std::io::Write>
(&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<u8> = Vec::new();
- if !self.is_transparent_container(ident, is_ref) {
+ if !self.is_transparent_container(ident, is_ref, args.iter().map(|a| *a)) {
write!(w, "C{}_", ident).unwrap();
write!(mangled_type, "C{}_", ident).unwrap();
} else { assert_eq!(args.len(), 1); }
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 self.is_transparent_container(ident, is_ref, args.iter().map(|a| *a)) {
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<T> 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; }
+ if let Some(arr_ty) = self.is_real_type_array(&subtype) {
+ if !self.write_c_type_intern(w, &arr_ty, generics, false, true, false) { return false; }
+ } else {
+ // Option<T> 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) {
+ } else if self.is_known_container(&subtype, is_ref) || self.is_path_transparent_container(&$p_arg.path, generics, 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;
} else { return false; }
} else { return false; }
}
- if self.is_transparent_container(ident, is_ref) { return true; }
+ if self.is_transparent_container(ident, is_ref, args.iter().map(|a| *a)) { return true; }
// Push the "end of type" Z
write!(w, "Z").unwrap();
write!(mangled_type, "Z").unwrap();
self.check_create_container(String::from_utf8(mangled_type).unwrap(), ident, args, generics, is_ref)
}
fn write_c_mangled_container_path<W: std::io::Write>(&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) {
+ if !self.is_transparent_container(ident, is_ref, args.iter().map(|a| *a)) {
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)
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) {
+ if self.is_known_container(&full_path, is_ref) || self.is_path_transparent_container(&p.path, generics, 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() {
bitcoin = "0.26"
secp256k1 = { version = "0.20.1", features = ["global-context-less-secure"] }
# Note that the following line is matched by genbindings to update the path
-lightning = { git = "https://git.bitcoin.ninja/rust-lightning", rev = "8a8c75a8fc96e5c8ed59e6d80a517bc59215b4d6" }
+lightning = { git = "https://git.bitcoin.ninja/rust-lightning", rev = "6fcac8bc65ed6d372e0b8c367e9934c754f99ff3" }
[patch.crates-io]
# Rust-Secp256k1 PR 279. Should be dropped once merged.
bool result_ok;
} LDKCResult_TxCreationKeysErrorZ;
+typedef enum LDKCOption_u32Z_Tag {
+ LDKCOption_u32Z_Some,
+ LDKCOption_u32Z_None,
+ /**
+ * Must be last for serialization purposes
+ */
+ LDKCOption_u32Z_Sentinel,
+} LDKCOption_u32Z_Tag;
+
+typedef struct LDKCOption_u32Z {
+ LDKCOption_u32Z_Tag tag;
+ union {
+ struct {
+ uint32_t some;
+ };
+ };
+} LDKCOption_u32Z;
+
/**
bool result_ok;
} LDKCResult_ChannelConfigDecodeErrorZ;
+typedef enum LDKCOption_u64Z_Tag {
+ LDKCOption_u64Z_Some,
+ LDKCOption_u64Z_None,
+ /**
+ * Must be last for serialization purposes
+ */
+ LDKCOption_u64Z_Sentinel,
+} LDKCOption_u64Z_Tag;
+
+typedef struct LDKCOption_u64Z {
+ LDKCOption_u64Z_Tag tag;
+ union {
+ struct {
+ uint64_t some;
+ };
+ };
+} LDKCOption_u64Z;
+
/**
bool result_ok;
} LDKCResult_TxOutAccessErrorZ;
+typedef enum LDKCOption_C2Tuple_usizeTransactionZZ_Tag {
+ LDKCOption_C2Tuple_usizeTransactionZZ_Some,
+ LDKCOption_C2Tuple_usizeTransactionZZ_None,
+ /**
+ * Must be last for serialization purposes
+ */
+ LDKCOption_C2Tuple_usizeTransactionZZ_Sentinel,
+} LDKCOption_C2Tuple_usizeTransactionZZ_Tag;
+
+typedef struct LDKCOption_C2Tuple_usizeTransactionZZ {
+ LDKCOption_C2Tuple_usizeTransactionZZ_Tag tag;
+ union {
+ struct {
+ struct LDKC2Tuple_usizeTransactionZ some;
+ };
+ };
+} LDKCOption_C2Tuple_usizeTransactionZZ;
+
/**
* 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!
void (*free)(void *this_arg);
} LDKListen;
+
+
+/**
+ * A transaction output watched by a [`ChannelMonitor`] for spends on-chain.
+ *
+ * Used to convey to a [`Filter`] such an output with a given spending condition. Any transaction
+ * spending the output must be given to [`ChannelMonitor::block_connected`] either directly or via
+ * the return value of [`Filter::register_output`].
+ *
+ * If `block_hash` is `Some`, this indicates the output was created in the corresponding block and
+ * may have been spent there. See [`Filter::register_output`] for details.
+ *
+ * [`ChannelMonitor`]: channelmonitor::ChannelMonitor
+ * [`ChannelMonitor::block_connected`]: channelmonitor::ChannelMonitor::block_connected
+ */
+typedef struct MUST_USE_STRUCT LDKWatchedOutput {
+ /**
+ * A pointer to the opaque Rust object.
+ * 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.
+ */
+ LDKnativeWatchedOutput *inner;
+ /**
+ * Indicates that this is the only struct which contains the same pointer.
+ * Rust functions which take ownership of an object provided via an argument require
+ * this to be true and invalidate the object pointed to by inner.
+ */
+ bool is_owned;
+} LDKWatchedOutput;
+
/**
* The `Filter` trait defines behavior for indicating chain activity of interest pertaining to
* channels.
*/
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.
+ * Registers interest in spends of a transaction output.
+ *
+ * Optionally, when `output.block_hash` is set, should return any transaction spending the
+ * output that is found in the corresponding block along with its index.
+ *
+ * This return value is useful for Electrum clients in order to supply in-block descendant
+ * transactions which otherwise were not included. This is not necessary for other clients if
+ * such descendant transactions were already included (e.g., when a BIP 157 client provides the
+ * full block).
*/
- void (*register_output)(const void *this_arg, const struct LDKOutPoint *NONNULL_PTR outpoint, struct LDKu8slice script_pubkey);
+ struct LDKCOption_C2Tuple_usizeTransactionZZ (*register_output)(const void *this_arg, struct LDKWatchedOutput output);
/**
* Frees any resources associated with this object given its this_arg pointer.
* Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
void CResult_TxCreationKeysErrorZ_free(struct LDKCResult_TxCreationKeysErrorZ _res);
+struct LDKCOption_u32Z COption_u32Z_some(uint32_t o);
+
+struct LDKCOption_u32Z COption_u32Z_none(void);
+
+void COption_u32Z_free(struct LDKCOption_u32Z _res);
+
+struct LDKCOption_u32Z COption_u32Z_clone(const struct LDKCOption_u32Z *NONNULL_PTR orig);
+
struct LDKCResult_HTLCOutputInCommitmentDecodeErrorZ CResult_HTLCOutputInCommitmentDecodeErrorZ_ok(struct LDKHTLCOutputInCommitment o);
struct LDKCResult_HTLCOutputInCommitmentDecodeErrorZ CResult_HTLCOutputInCommitmentDecodeErrorZ_err(struct LDKDecodeError e);
struct LDKCResult_ChannelConfigDecodeErrorZ CResult_ChannelConfigDecodeErrorZ_clone(const struct LDKCResult_ChannelConfigDecodeErrorZ *NONNULL_PTR orig);
+struct LDKCOption_u64Z COption_u64Z_some(uint64_t o);
+
+struct LDKCOption_u64Z COption_u64Z_none(void);
+
+void COption_u64Z_free(struct LDKCOption_u64Z _res);
+
+struct LDKCOption_u64Z COption_u64Z_clone(const struct LDKCOption_u64Z *NONNULL_PTR orig);
+
struct LDKCResult_DirectionalChannelInfoDecodeErrorZ CResult_DirectionalChannelInfoDecodeErrorZ_ok(struct LDKDirectionalChannelInfo o);
struct LDKCResult_DirectionalChannelInfoDecodeErrorZ CResult_DirectionalChannelInfoDecodeErrorZ_err(struct LDKDecodeError e);
struct LDKCResult_TxOutAccessErrorZ CResult_TxOutAccessErrorZ_clone(const struct LDKCResult_TxOutAccessErrorZ *NONNULL_PTR orig);
+struct LDKCOption_C2Tuple_usizeTransactionZZ COption_C2Tuple_usizeTransactionZZ_some(struct LDKC2Tuple_usizeTransactionZ o);
+
+struct LDKCOption_C2Tuple_usizeTransactionZZ COption_C2Tuple_usizeTransactionZZ_none(void);
+
+void COption_C2Tuple_usizeTransactionZZ_free(struct LDKCOption_C2Tuple_usizeTransactionZZ _res);
+
struct LDKCResult_NoneAPIErrorZ CResult_NoneAPIErrorZ_ok(void);
struct LDKCResult_NoneAPIErrorZ CResult_NoneAPIErrorZ_err(struct LDKAPIError e);
*/
void Filter_free(struct LDKFilter this_ptr);
+/**
+ * Frees any resources used by the WatchedOutput, if is_owned is set and inner is non-NULL.
+ */
+void WatchedOutput_free(struct LDKWatchedOutput this_obj);
+
+/**
+ * First block where the transaction output may have been spent.
+ */
+struct LDKThirtyTwoBytes WatchedOutput_get_block_hash(const struct LDKWatchedOutput *NONNULL_PTR this_ptr);
+
+/**
+ * First block where the transaction output may have been spent.
+ */
+void WatchedOutput_set_block_hash(struct LDKWatchedOutput *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val);
+
+/**
+ * Outpoint identifying the transaction output.
+ */
+struct LDKOutPoint WatchedOutput_get_outpoint(const struct LDKWatchedOutput *NONNULL_PTR this_ptr);
+
+/**
+ * Outpoint identifying the transaction output.
+ */
+void WatchedOutput_set_outpoint(struct LDKWatchedOutput *NONNULL_PTR this_ptr, struct LDKOutPoint val);
+
+/**
+ * Spending condition of the transaction output.
+ */
+struct LDKu8slice WatchedOutput_get_script_pubkey(const struct LDKWatchedOutput *NONNULL_PTR this_ptr);
+
+/**
+ * Spending condition of the transaction output.
+ */
+void WatchedOutput_set_script_pubkey(struct LDKWatchedOutput *NONNULL_PTR this_ptr, struct LDKCVec_u8Z val);
+
+/**
+ * Constructs a new WatchedOutput given each field
+ */
+MUST_USE_RES struct LDKWatchedOutput WatchedOutput_new(struct LDKThirtyTwoBytes block_hash_arg, struct LDKOutPoint outpoint_arg, struct LDKCVec_u8Z script_pubkey_arg);
+
/**
* Calls the free function if one is set
*/
*/
void ChannelDetails_set_channel_id(struct LDKChannelDetails *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val);
+/**
+ * The position of the funding transaction in the chain. None if the funding transaction has
+ * not yet been confirmed and the channel fully opened.
+ */
+struct LDKCOption_u64Z ChannelDetails_get_short_channel_id(const struct LDKChannelDetails *NONNULL_PTR this_ptr);
+
+/**
+ * The position of the funding transaction in the chain. None if the funding transaction has
+ * not yet been confirmed and the channel fully opened.
+ */
+void ChannelDetails_set_short_channel_id(struct LDKChannelDetails *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val);
+
/**
* The node_id of our counterparty
*/
*/
void HTLCOutputInCommitment_set_payment_hash(struct LDKHTLCOutputInCommitment *NONNULL_PTR this_ptr, struct LDKThirtyTwoBytes val);
+/**
+ * The position within the commitment transactions' outputs. This may be None if the value is
+ * below the dust limit (in which case no output appears in the commitment transaction and the
+ * value is spent to additional transaction fees).
+ */
+struct LDKCOption_u32Z HTLCOutputInCommitment_get_transaction_output_index(const struct LDKHTLCOutputInCommitment *NONNULL_PTR this_ptr);
+
+/**
+ * The position within the commitment transactions' outputs. This may be None if the value is
+ * below the dust limit (in which case no output appears in the commitment transaction and the
+ * value is spent to additional transaction fees).
+ */
+void HTLCOutputInCommitment_set_transaction_output_index(struct LDKHTLCOutputInCommitment *NONNULL_PTR this_ptr, struct LDKCOption_u32Z val);
+
+/**
+ * Constructs a new HTLCOutputInCommitment given each field
+ */
+MUST_USE_RES struct LDKHTLCOutputInCommitment HTLCOutputInCommitment_new(bool offered_arg, uint64_t amount_msat_arg, uint32_t cltv_expiry_arg, struct LDKThirtyTwoBytes payment_hash_arg, struct LDKCOption_u32Z transaction_output_index_arg);
+
/**
* Creates a copy of the HTLCOutputInCommitment
*/
*/
void RouteHint_set_cltv_expiry_delta(struct LDKRouteHint *NONNULL_PTR this_ptr, uint16_t val);
+/**
+ * The minimum value, in msat, which must be relayed to the next hop.
+ */
+struct LDKCOption_u64Z RouteHint_get_htlc_minimum_msat(const struct LDKRouteHint *NONNULL_PTR this_ptr);
+
+/**
+ * The minimum value, in msat, which must be relayed to the next hop.
+ */
+void RouteHint_set_htlc_minimum_msat(struct LDKRouteHint *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val);
+
+/**
+ * The maximum value in msat available for routing with a single HTLC.
+ */
+struct LDKCOption_u64Z RouteHint_get_htlc_maximum_msat(const struct LDKRouteHint *NONNULL_PTR this_ptr);
+
+/**
+ * The maximum value in msat available for routing with a single HTLC.
+ */
+void RouteHint_set_htlc_maximum_msat(struct LDKRouteHint *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val);
+
+/**
+ * Constructs a new RouteHint given each field
+ */
+MUST_USE_RES struct LDKRouteHint RouteHint_new(struct LDKPublicKey src_node_id_arg, uint64_t short_channel_id_arg, struct LDKRoutingFees fees_arg, uint16_t cltv_expiry_delta_arg, struct LDKCOption_u64Z htlc_minimum_msat_arg, struct LDKCOption_u64Z htlc_maximum_msat_arg);
+
/**
* Creates a copy of the RouteHint
*/
*/
void DirectionalChannelInfo_set_htlc_minimum_msat(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, uint64_t val);
+/**
+ * The maximum value which may be relayed to the next hop via the channel.
+ */
+struct LDKCOption_u64Z DirectionalChannelInfo_get_htlc_maximum_msat(const struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr);
+
+/**
+ * The maximum value which may be relayed to the next hop via the channel.
+ */
+void DirectionalChannelInfo_set_htlc_maximum_msat(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val);
+
/**
* Fees charged when the channel is used for routing
*/
*/
void DirectionalChannelInfo_set_last_update_message(struct LDKDirectionalChannelInfo *NONNULL_PTR this_ptr, struct LDKChannelUpdate val);
+/**
+ * Constructs a new DirectionalChannelInfo given each field
+ */
+MUST_USE_RES struct LDKDirectionalChannelInfo DirectionalChannelInfo_new(uint32_t last_update_arg, bool enabled_arg, uint16_t cltv_expiry_delta_arg, uint64_t htlc_minimum_msat_arg, struct LDKCOption_u64Z htlc_maximum_msat_arg, struct LDKRoutingFees fees_arg, struct LDKChannelUpdate last_update_message_arg);
+
/**
* Creates a copy of the DirectionalChannelInfo
*/
*/
void ChannelInfo_set_two_to_one(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKDirectionalChannelInfo val);
+/**
+ * The channel capacity as seen on-chain, if chain lookup is available.
+ */
+struct LDKCOption_u64Z ChannelInfo_get_capacity_sats(const struct LDKChannelInfo *NONNULL_PTR this_ptr);
+
+/**
+ * The channel capacity as seen on-chain, if chain lookup is available.
+ */
+void ChannelInfo_set_capacity_sats(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val);
+
/**
* An initial announcement of the channel
* Mostly redundant with the data we store in fields explicitly.
*/
void ChannelInfo_set_announcement_message(struct LDKChannelInfo *NONNULL_PTR this_ptr, struct LDKChannelAnnouncement val);
+/**
+ * Constructs a new ChannelInfo given each field
+ */
+MUST_USE_RES struct LDKChannelInfo ChannelInfo_new(struct LDKChannelFeatures features_arg, struct LDKPublicKey node_one_arg, struct LDKDirectionalChannelInfo one_to_two_arg, struct LDKPublicKey node_two_arg, struct LDKDirectionalChannelInfo two_to_one_arg, struct LDKCOption_u64Z capacity_sats_arg, struct LDKChannelAnnouncement announcement_message_arg);
+
/**
* Creates a copy of the ChannelInfo
*/
const LDKFilter* operator &() const { return &self; }
const LDKFilter* operator ->() const { return &self; }
};
+class WatchedOutput {
+private:
+ LDKWatchedOutput self;
+public:
+ WatchedOutput(const WatchedOutput&) = delete;
+ WatchedOutput(WatchedOutput&& o) : self(o.self) { memset(&o, 0, sizeof(WatchedOutput)); }
+ WatchedOutput(LDKWatchedOutput&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKWatchedOutput)); }
+ operator LDKWatchedOutput() && { LDKWatchedOutput res = self; memset(&self, 0, sizeof(LDKWatchedOutput)); return res; }
+ ~WatchedOutput() { WatchedOutput_free(self); }
+ WatchedOutput& operator=(WatchedOutput&& o) { WatchedOutput_free(self); self = o.self; memset(&o, 0, sizeof(WatchedOutput)); return *this; }
+ LDKWatchedOutput* operator &() { return &self; }
+ LDKWatchedOutput* operator ->() { return &self; }
+ const LDKWatchedOutput* operator &() const { return &self; }
+ const LDKWatchedOutput* operator ->() const { return &self; }
+};
class BroadcasterInterface {
private:
LDKBroadcasterInterface self;
const LDKCResult_ChannelMonitorUpdateDecodeErrorZ* operator &() const { return &self; }
const LDKCResult_ChannelMonitorUpdateDecodeErrorZ* operator ->() const { return &self; }
};
-class CResult_ReplyChannelRangeDecodeErrorZ {
+class COption_u64Z {
private:
- LDKCResult_ReplyChannelRangeDecodeErrorZ self;
+ LDKCOption_u64Z 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; }
+ COption_u64Z(const COption_u64Z&) = delete;
+ COption_u64Z(COption_u64Z&& o) : self(o.self) { memset(&o, 0, sizeof(COption_u64Z)); }
+ COption_u64Z(LDKCOption_u64Z&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCOption_u64Z)); }
+ operator LDKCOption_u64Z() && { LDKCOption_u64Z res = self; memset(&self, 0, sizeof(LDKCOption_u64Z)); return res; }
+ ~COption_u64Z() { COption_u64Z_free(self); }
+ COption_u64Z& operator=(COption_u64Z&& o) { COption_u64Z_free(self); self = o.self; memset(&o, 0, sizeof(COption_u64Z)); return *this; }
+ LDKCOption_u64Z* operator &() { return &self; }
+ LDKCOption_u64Z* operator ->() { return &self; }
+ const LDKCOption_u64Z* operator &() const { return &self; }
+ const LDKCOption_u64Z* operator ->() const { return &self; }
};
class CResult_TxOutAccessErrorZ {
private:
const LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* operator &() const { return &self; }
const LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* 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;
const LDKCVec_UpdateAddHTLCZ* operator &() const { return &self; }
const LDKCVec_UpdateAddHTLCZ* operator ->() const { return &self; }
};
+class COption_u32Z {
+private:
+ LDKCOption_u32Z self;
+public:
+ COption_u32Z(const COption_u32Z&) = delete;
+ COption_u32Z(COption_u32Z&& o) : self(o.self) { memset(&o, 0, sizeof(COption_u32Z)); }
+ COption_u32Z(LDKCOption_u32Z&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCOption_u32Z)); }
+ operator LDKCOption_u32Z() && { LDKCOption_u32Z res = self; memset(&self, 0, sizeof(LDKCOption_u32Z)); return res; }
+ ~COption_u32Z() { COption_u32Z_free(self); }
+ COption_u32Z& operator=(COption_u32Z&& o) { COption_u32Z_free(self); self = o.self; memset(&o, 0, sizeof(COption_u32Z)); return *this; }
+ LDKCOption_u32Z* operator &() { return &self; }
+ LDKCOption_u32Z* operator ->() { return &self; }
+ const LDKCOption_u32Z* operator &() const { return &self; }
+ const LDKCOption_u32Z* operator ->() const { return &self; }
+};
class CResult_InitFeaturesDecodeErrorZ {
private:
LDKCResult_InitFeaturesDecodeErrorZ self;
const LDKCResult_CommitmentTransactionDecodeErrorZ* operator &() const { return &self; }
const LDKCResult_CommitmentTransactionDecodeErrorZ* operator ->() const { return &self; }
};
+class COption_C2Tuple_usizeTransactionZZ {
+private:
+ LDKCOption_C2Tuple_usizeTransactionZZ self;
+public:
+ COption_C2Tuple_usizeTransactionZZ(const COption_C2Tuple_usizeTransactionZZ&) = delete;
+ COption_C2Tuple_usizeTransactionZZ(COption_C2Tuple_usizeTransactionZZ&& o) : self(o.self) { memset(&o, 0, sizeof(COption_C2Tuple_usizeTransactionZZ)); }
+ COption_C2Tuple_usizeTransactionZZ(LDKCOption_C2Tuple_usizeTransactionZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCOption_C2Tuple_usizeTransactionZZ)); }
+ operator LDKCOption_C2Tuple_usizeTransactionZZ() && { LDKCOption_C2Tuple_usizeTransactionZZ res = self; memset(&self, 0, sizeof(LDKCOption_C2Tuple_usizeTransactionZZ)); return res; }
+ ~COption_C2Tuple_usizeTransactionZZ() { COption_C2Tuple_usizeTransactionZZ_free(self); }
+ COption_C2Tuple_usizeTransactionZZ& operator=(COption_C2Tuple_usizeTransactionZZ&& o) { COption_C2Tuple_usizeTransactionZZ_free(self); self = o.self; memset(&o, 0, sizeof(COption_C2Tuple_usizeTransactionZZ)); return *this; }
+ LDKCOption_C2Tuple_usizeTransactionZZ* operator &() { return &self; }
+ LDKCOption_C2Tuple_usizeTransactionZZ* operator ->() { return &self; }
+ const LDKCOption_C2Tuple_usizeTransactionZZ* operator &() const { return &self; }
+ const LDKCOption_C2Tuple_usizeTransactionZZ* operator ->() const { return &self; }
+};
class CResult_TransactionNoneZ {
private:
LDKCResult_TransactionNoneZ self;
typedef struct nativeHTLCUpdateOpaque LDKnativeHTLCUpdate;
struct nativeChannelMonitorOpaque;
typedef struct nativeChannelMonitorOpaque LDKnativeChannelMonitor;
+struct nativeWatchedOutputOpaque;
+typedef struct nativeWatchedOutputOpaque LDKnativeWatchedOutput;
struct nativeChannelManagerOpaque;
typedef struct nativeChannelManagerOpaque LDKnativeChannelManager;
struct nativeChainParametersOpaque;
}
}
#[repr(C)]
+#[derive(Clone)]
+pub enum COption_u32Z {
+ Some(u32),
+ None
+}
+impl COption_u32Z {
+ #[allow(unused)] pub(crate) fn is_some(&self) -> bool {
+ if let Self::Some(_) = self { true } else { false }
+ }
+ #[allow(unused)] pub(crate) fn take(mut self) -> u32 {
+ if let Self::Some(v) = self { v } else { unreachable!() }
+ }
+}
+#[no_mangle]
+pub extern "C" fn COption_u32Z_some(o: u32) -> COption_u32Z {
+ COption_u32Z::Some(o)
+}
+#[no_mangle]
+pub extern "C" fn COption_u32Z_none() -> COption_u32Z {
+ COption_u32Z::None
+}
+#[no_mangle]
+pub extern "C" fn COption_u32Z_free(_res: COption_u32Z) { }
+#[no_mangle]
+pub extern "C" fn COption_u32Z_clone(orig: &COption_u32Z) -> COption_u32Z { orig.clone() }
+#[repr(C)]
pub union CResult_HTLCOutputInCommitmentDecodeErrorZPtr {
pub result: *mut crate::ln::chan_utils::HTLCOutputInCommitment,
pub err: *mut crate::ln::msgs::DecodeError,
#[no_mangle]
pub extern "C" fn CResult_ChannelConfigDecodeErrorZ_clone(orig: &CResult_ChannelConfigDecodeErrorZ) -> CResult_ChannelConfigDecodeErrorZ { orig.clone() }
#[repr(C)]
+#[derive(Clone)]
+pub enum COption_u64Z {
+ Some(u64),
+ None
+}
+impl COption_u64Z {
+ #[allow(unused)] pub(crate) fn is_some(&self) -> bool {
+ if let Self::Some(_) = self { true } else { false }
+ }
+ #[allow(unused)] pub(crate) fn take(mut self) -> u64 {
+ if let Self::Some(v) = self { v } else { unreachable!() }
+ }
+}
+#[no_mangle]
+pub extern "C" fn COption_u64Z_some(o: u64) -> COption_u64Z {
+ COption_u64Z::Some(o)
+}
+#[no_mangle]
+pub extern "C" fn COption_u64Z_none() -> COption_u64Z {
+ COption_u64Z::None
+}
+#[no_mangle]
+pub extern "C" fn COption_u64Z_free(_res: COption_u64Z) { }
+#[no_mangle]
+pub extern "C" fn COption_u64Z_clone(orig: &COption_u64Z) -> COption_u64Z { orig.clone() }
+#[repr(C)]
pub union CResult_DirectionalChannelInfoDecodeErrorZPtr {
pub result: *mut crate::routing::network_graph::DirectionalChannelInfo,
pub err: *mut crate::ln::msgs::DecodeError,
#[no_mangle]
pub extern "C" fn CResult_TxOutAccessErrorZ_clone(orig: &CResult_TxOutAccessErrorZ) -> CResult_TxOutAccessErrorZ { orig.clone() }
#[repr(C)]
+pub enum COption_C2Tuple_usizeTransactionZZ {
+ Some(crate::c_types::derived::C2Tuple_usizeTransactionZ),
+ None
+}
+impl COption_C2Tuple_usizeTransactionZZ {
+ #[allow(unused)] pub(crate) fn is_some(&self) -> bool {
+ if let Self::Some(_) = self { true } else { false }
+ }
+ #[allow(unused)] pub(crate) fn take(mut self) -> crate::c_types::derived::C2Tuple_usizeTransactionZ {
+ if let Self::Some(v) = self { v } else { unreachable!() }
+ }
+}
+#[no_mangle]
+pub extern "C" fn COption_C2Tuple_usizeTransactionZZ_some(o: crate::c_types::derived::C2Tuple_usizeTransactionZ) -> COption_C2Tuple_usizeTransactionZZ {
+ COption_C2Tuple_usizeTransactionZZ::Some(o)
+}
+#[no_mangle]
+pub extern "C" fn COption_C2Tuple_usizeTransactionZZ_none() -> COption_C2Tuple_usizeTransactionZZ {
+ COption_C2Tuple_usizeTransactionZZ::None
+}
+#[no_mangle]
+pub extern "C" fn COption_C2Tuple_usizeTransactionZZ_free(_res: COption_C2Tuple_usizeTransactionZZ) { }
+#[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,
/// 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),
+ /// Registers interest in spends of a transaction output.
+ ///
+ /// Optionally, when `output.block_hash` is set, should return any transaction spending the
+ /// output that is found in the corresponding block along with its index.
+ ///
+ /// This return value is useful for Electrum clients in order to supply in-block descendant
+ /// transactions which otherwise were not included. This is not necessary for other clients if
+ /// such descendant transactions were already included (e.g., when a BIP 157 client provides the
+ /// full block).
+ #[must_use]
+ pub register_output: extern "C" fn (this_arg: *const c_void, output: crate::chain::WatchedOutput) -> crate::c_types::derived::COption_C2Tuple_usizeTransactionZZ,
/// Frees any resources associated with this object given its this_arg pointer.
/// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
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[..]))
+ fn register_output(&self, output: lightning::chain::WatchedOutput) -> Option<(usize, bitcoin::blockdata::transaction::Transaction)> {
+ let mut ret = (self.register_output)(self.this_arg, crate::chain::WatchedOutput { inner: Box::into_raw(Box::new(output)), is_owned: true });
+ let mut local_ret = if ret.is_some() { Some( { let (mut orig_ret_0_0, mut orig_ret_0_1) = ret.take().to_rust(); let mut local_ret_0 = (orig_ret_0_0, orig_ret_0_1.into_bitcoin()); local_ret_0 }) } else { None };
+ local_ret
}
}
}
}
}
+
+use lightning::chain::WatchedOutput as nativeWatchedOutputImport;
+type nativeWatchedOutput = nativeWatchedOutputImport;
+
+/// A transaction output watched by a [`ChannelMonitor`] for spends on-chain.
+///
+/// Used to convey to a [`Filter`] such an output with a given spending condition. Any transaction
+/// spending the output must be given to [`ChannelMonitor::block_connected`] either directly or via
+/// the return value of [`Filter::register_output`].
+///
+/// If `block_hash` is `Some`, this indicates the output was created in the corresponding block and
+/// may have been spent there. See [`Filter::register_output`] for details.
+///
+/// [`ChannelMonitor`]: channelmonitor::ChannelMonitor
+/// [`ChannelMonitor::block_connected`]: channelmonitor::ChannelMonitor::block_connected
+#[must_use]
+#[repr(C)]
+pub struct WatchedOutput {
+ /// A pointer to the opaque Rust object.
+
+ /// 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 nativeWatchedOutput,
+ /// Indicates that this is the only struct which contains the same pointer.
+
+ /// Rust functions which take ownership of an object provided via an argument require
+ /// this to be true and invalidate the object pointed to by inner.
+ pub is_owned: bool,
+}
+
+impl Drop for WatchedOutput {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativeWatchedOutput>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(self.inner) };
+ }
+ }
+}
+/// Frees any resources used by the WatchedOutput, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_free(this_obj: WatchedOutput) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+extern "C" fn WatchedOutput_free_void(this_ptr: *mut c_void) {
+ unsafe { let _ = Box::from_raw(this_ptr as *mut nativeWatchedOutput); }
+}
+#[allow(unused)]
+/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
+impl WatchedOutput {
+ pub(crate) fn take_inner(mut self) -> *mut nativeWatchedOutput {
+ assert!(self.is_owned);
+ let ret = self.inner;
+ self.inner = std::ptr::null_mut();
+ ret
+ }
+}
+/// First block where the transaction output may have been spent.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_get_block_hash(this_ptr: &WatchedOutput) -> crate::c_types::ThirtyTwoBytes {
+ let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.block_hash;
+ let mut local_inner_val = if inner_val.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (inner_val.unwrap()).into_inner() } } };
+ local_inner_val
+}
+/// First block where the transaction output may have been spent.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_set_block_hash(this_ptr: &mut WatchedOutput, mut val: crate::c_types::ThirtyTwoBytes) {
+ let mut local_val = if val.data == [0; 32] { None } else { Some( { ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap() }) };
+ unsafe { &mut *this_ptr.inner }.block_hash = local_val;
+}
+/// Outpoint identifying the transaction output.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_get_outpoint(this_ptr: &WatchedOutput) -> 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 }
+}
+/// Outpoint identifying the transaction output.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_set_outpoint(this_ptr: &mut WatchedOutput, mut val: crate::chain::transaction::OutPoint) {
+ unsafe { &mut *this_ptr.inner }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
+}
+/// Spending condition of the transaction output.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_get_script_pubkey(this_ptr: &WatchedOutput) -> crate::c_types::u8slice {
+ let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.script_pubkey;
+ crate::c_types::u8slice::from_slice(&(*inner_val)[..])
+}
+/// Spending condition of the transaction output.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_set_script_pubkey(this_ptr: &mut WatchedOutput, mut val: crate::c_types::derived::CVec_u8Z) {
+ unsafe { &mut *this_ptr.inner }.script_pubkey = ::bitcoin::blockdata::script::Script::from(val.into_rust());
+}
+/// Constructs a new WatchedOutput given each field
+#[must_use]
+#[no_mangle]
+pub extern "C" fn WatchedOutput_new(mut block_hash_arg: crate::c_types::ThirtyTwoBytes, mut outpoint_arg: crate::chain::transaction::OutPoint, mut script_pubkey_arg: crate::c_types::derived::CVec_u8Z) -> WatchedOutput {
+ let mut local_block_hash_arg = if block_hash_arg.data == [0; 32] { None } else { Some( { ::bitcoin::hash_types::BlockHash::from_slice(&block_hash_arg.data[..]).unwrap() }) };
+ WatchedOutput { inner: Box::into_raw(Box::new(nativeWatchedOutput {
+ block_hash: local_block_hash_arg,
+ outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
+ script_pubkey: ::bitcoin::blockdata::script::Script::from(script_pubkey_arg.into_rust()),
+ })), is_owned: true }
+}
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);
}
+/// The position within the commitment transactions' outputs. This may be None if the value is
+/// below the dust limit (in which case no output appears in the commitment transaction and the
+/// value is spent to additional transaction fees).
+#[no_mangle]
+pub extern "C" fn HTLCOutputInCommitment_get_transaction_output_index(this_ptr: &HTLCOutputInCommitment) -> crate::c_types::derived::COption_u32Z {
+ let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.transaction_output_index;
+ let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u32Z::None } else { { crate::c_types::derived::COption_u32Z::Some(inner_val.unwrap()) } };
+ local_inner_val
+}
+/// The position within the commitment transactions' outputs. This may be None if the value is
+/// below the dust limit (in which case no output appears in the commitment transaction and the
+/// value is spent to additional transaction fees).
+#[no_mangle]
+pub extern "C" fn HTLCOutputInCommitment_set_transaction_output_index(this_ptr: &mut HTLCOutputInCommitment, mut val: crate::c_types::derived::COption_u32Z) {
+ let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
+ unsafe { &mut *this_ptr.inner }.transaction_output_index = local_val;
+}
+/// Constructs a new HTLCOutputInCommitment given each field
+#[must_use]
+#[no_mangle]
+pub extern "C" fn HTLCOutputInCommitment_new(mut offered_arg: bool, mut amount_msat_arg: u64, mut cltv_expiry_arg: u32, mut payment_hash_arg: crate::c_types::ThirtyTwoBytes, mut transaction_output_index_arg: crate::c_types::derived::COption_u32Z) -> HTLCOutputInCommitment {
+ let mut local_transaction_output_index_arg = if transaction_output_index_arg.is_some() { Some( { transaction_output_index_arg.take() }) } else { None };
+ HTLCOutputInCommitment { inner: Box::into_raw(Box::new(nativeHTLCOutputInCommitment {
+ offered: offered_arg,
+ amount_msat: amount_msat_arg,
+ cltv_expiry: cltv_expiry_arg,
+ payment_hash: ::lightning::ln::channelmanager::PaymentHash(payment_hash_arg.data),
+ transaction_output_index: local_transaction_output_index_arg,
+ })), is_owned: true }
+}
impl Clone for HTLCOutputInCommitment {
fn clone(&self) -> Self {
Self {
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 position of the funding transaction in the chain. None if the funding transaction has
+/// not yet been confirmed and the channel fully opened.
+#[no_mangle]
+pub extern "C" fn ChannelDetails_get_short_channel_id(this_ptr: &ChannelDetails) -> crate::c_types::derived::COption_u64Z {
+ let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.short_channel_id;
+ let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(inner_val.unwrap()) } };
+ local_inner_val
+}
+/// The position of the funding transaction in the chain. None if the funding transaction has
+/// not yet been confirmed and the channel fully opened.
+#[no_mangle]
+pub extern "C" fn ChannelDetails_set_short_channel_id(this_ptr: &mut ChannelDetails, mut val: crate::c_types::derived::COption_u64Z) {
+ let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
+ unsafe { &mut *this_ptr.inner }.short_channel_id = local_val;
+}
/// The node_id of our counterparty
#[no_mangle]
pub extern "C" fn ChannelDetails_get_remote_network_id(this_ptr: &ChannelDetails) -> crate::c_types::PublicKey {
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;
}
+/// The maximum value which may be relayed to the next hop via the channel.
+#[no_mangle]
+pub extern "C" fn DirectionalChannelInfo_get_htlc_maximum_msat(this_ptr: &DirectionalChannelInfo) -> crate::c_types::derived::COption_u64Z {
+ let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_maximum_msat;
+ let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(inner_val.unwrap()) } };
+ local_inner_val
+}
+/// The maximum value which may be relayed to the next hop via the channel.
+#[no_mangle]
+pub extern "C" fn DirectionalChannelInfo_set_htlc_maximum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
+ let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
+ unsafe { &mut *this_ptr.inner }.htlc_maximum_msat = local_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 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;
}
+/// Constructs a new DirectionalChannelInfo given each field
+#[must_use]
+#[no_mangle]
+pub extern "C" fn DirectionalChannelInfo_new(mut last_update_arg: u32, mut enabled_arg: bool, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z, mut fees_arg: crate::routing::network_graph::RoutingFees, mut last_update_message_arg: crate::ln::msgs::ChannelUpdate) -> DirectionalChannelInfo {
+ let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
+ let mut local_last_update_message_arg = if last_update_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(last_update_message_arg.take_inner()) } }) };
+ DirectionalChannelInfo { inner: Box::into_raw(Box::new(nativeDirectionalChannelInfo {
+ last_update: last_update_arg,
+ enabled: enabled_arg,
+ cltv_expiry_delta: cltv_expiry_delta_arg,
+ htlc_minimum_msat: htlc_minimum_msat_arg,
+ htlc_maximum_msat: local_htlc_maximum_msat_arg,
+ fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
+ last_update_message: local_last_update_message_arg,
+ })), is_owned: true }
+}
impl Clone for DirectionalChannelInfo {
fn clone(&self) -> Self {
Self {
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;
}
+/// The channel capacity as seen on-chain, if chain lookup is available.
+#[no_mangle]
+pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
+ let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.capacity_sats;
+ let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(inner_val.unwrap()) } };
+ local_inner_val
+}
+/// The channel capacity as seen on-chain, if chain lookup is available.
+#[no_mangle]
+pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
+ let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
+ unsafe { &mut *this_ptr.inner }.capacity_sats = 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.
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;
}
+/// Constructs a new ChannelInfo given each field
+#[must_use]
+#[no_mangle]
+pub extern "C" fn ChannelInfo_new(mut features_arg: crate::ln::features::ChannelFeatures, mut node_one_arg: crate::c_types::PublicKey, mut one_to_two_arg: crate::routing::network_graph::DirectionalChannelInfo, mut node_two_arg: crate::c_types::PublicKey, mut two_to_one_arg: crate::routing::network_graph::DirectionalChannelInfo, mut capacity_sats_arg: crate::c_types::derived::COption_u64Z, mut announcement_message_arg: crate::ln::msgs::ChannelAnnouncement) -> ChannelInfo {
+ let mut local_one_to_two_arg = if one_to_two_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(one_to_two_arg.take_inner()) } }) };
+ let mut local_two_to_one_arg = if two_to_one_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(two_to_one_arg.take_inner()) } }) };
+ let mut local_capacity_sats_arg = if capacity_sats_arg.is_some() { Some( { capacity_sats_arg.take() }) } else { None };
+ 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()) } }) };
+ ChannelInfo { inner: Box::into_raw(Box::new(nativeChannelInfo {
+ features: *unsafe { Box::from_raw(features_arg.take_inner()) },
+ node_one: node_one_arg.into_rust(),
+ one_to_two: local_one_to_two_arg,
+ node_two: node_two_arg.into_rust(),
+ two_to_one: local_two_to_one_arg,
+ capacity_sats: local_capacity_sats_arg,
+ announcement_message: local_announcement_message_arg,
+ })), is_owned: true }
+}
impl Clone for ChannelInfo {
fn clone(&self) -> Self {
Self {
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;
}
+/// The minimum value, in msat, which must be relayed to the next hop.
+#[no_mangle]
+pub extern "C" fn RouteHint_get_htlc_minimum_msat(this_ptr: &RouteHint) -> crate::c_types::derived::COption_u64Z {
+ let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat;
+ let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(inner_val.unwrap()) } };
+ local_inner_val
+}
+/// The minimum value, in msat, which must be relayed to the next hop.
+#[no_mangle]
+pub extern "C" fn RouteHint_set_htlc_minimum_msat(this_ptr: &mut RouteHint, mut val: crate::c_types::derived::COption_u64Z) {
+ let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
+ unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = local_val;
+}
+/// The maximum value in msat available for routing with a single HTLC.
+#[no_mangle]
+pub extern "C" fn RouteHint_get_htlc_maximum_msat(this_ptr: &RouteHint) -> crate::c_types::derived::COption_u64Z {
+ let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_maximum_msat;
+ let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(inner_val.unwrap()) } };
+ local_inner_val
+}
+/// The maximum value in msat available for routing with a single HTLC.
+#[no_mangle]
+pub extern "C" fn RouteHint_set_htlc_maximum_msat(this_ptr: &mut RouteHint, mut val: crate::c_types::derived::COption_u64Z) {
+ let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
+ unsafe { &mut *this_ptr.inner }.htlc_maximum_msat = local_val;
+}
+/// Constructs a new RouteHint given each field
+#[must_use]
+#[no_mangle]
+pub extern "C" fn RouteHint_new(mut src_node_id_arg: crate::c_types::PublicKey, mut short_channel_id_arg: u64, mut fees_arg: crate::routing::network_graph::RoutingFees, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: crate::c_types::derived::COption_u64Z, mut htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z) -> RouteHint {
+ let mut local_htlc_minimum_msat_arg = if htlc_minimum_msat_arg.is_some() { Some( { htlc_minimum_msat_arg.take() }) } else { None };
+ let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
+ RouteHint { inner: Box::into_raw(Box::new(nativeRouteHint {
+ src_node_id: src_node_id_arg.into_rust(),
+ short_channel_id: short_channel_id_arg,
+ fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
+ cltv_expiry_delta: cltv_expiry_delta_arg,
+ htlc_minimum_msat: local_htlc_minimum_msat_arg,
+ htlc_maximum_msat: local_htlc_maximum_msat_arg,
+ })), is_owned: true }
+}
impl Clone for RouteHint {
fn clone(&self) -> Self {
Self {