}
}
+/// List of manually-generated types which are clonable
+fn initial_clonable_types() -> HashSet<String> {
+ let mut res = HashSet::new();
+ res.insert("crate::c_types::u5".to_owned());
+ res
+}
+
/// 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
opaques: HashMap::new(), mirrored_enums: HashMap::new(), traits: HashMap::new(),
type_aliases: HashMap::new(), reverse_alias_map: HashMap::new(),
templates_defined: RefCell::new(HashMap::default()),
- clonable_types: RefCell::new(HashSet::new()), trait_impls: HashMap::new(),
+ clonable_types: RefCell::new(initial_clonable_types()), trait_impls: HashMap::new(),
template_file: RefCell::new(template_file), lib_ast: &libast,
}
}
// for arrays are different (https://github.com/eqrion/cbindgen/issues/528)
"[u8; 32]" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
+ "[u8; 20]" if !is_ref => Some("crate::c_types::TwentyBytes"),
"[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"),
"std::time::Duration" => Some("u64"),
"std::io::Error" => Some("crate::c_types::IOError"),
+ "bech32::u5" => Some("crate::c_types::u5"),
+
"bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
=> Some("crate::c_types::PublicKey"),
"bitcoin::secp256k1::Signature" => Some("crate::c_types::Signature"),
"[u8; 32]" if is_ref => Some("unsafe { &*"),
"[u8; 32]" if !is_ref => Some(""),
+ "[u8; 20]" if !is_ref => Some(""),
"[u8; 16]" if !is_ref => Some(""),
"[u8; 10]" if !is_ref => Some(""),
"[u8; 4]" if !is_ref => Some(""),
"std::time::Duration" => Some("std::time::Duration::from_secs("),
+ "bech32::u5" => Some(""),
+
"bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
if is_ref => Some("&"),
"bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
"[u8; 32]" if is_ref => Some("}"),
"[u8; 32]" if !is_ref => Some(".data"),
+ "[u8; 20]" 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"),
"std::time::Duration" => Some(")"),
+ "bech32::u5" => Some(".into()"),
+
"bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
=> Some(".into_rust()"),
"bitcoin::secp256k1::Signature" => Some(".into_rust()"),
"[u8; 32]" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
"[u8; 32]" if is_ref => Some(""),
+ "[u8; 20]" if !is_ref => Some("crate::c_types::TwentyBytes { data: "),
"[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: "),
"std::time::Duration" => Some(""),
"std::io::Error" if !is_ref => Some("crate::c_types::IOError::from_rust("),
+ "bech32::u5" => Some(""),
+
"bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
=> Some("crate::c_types::PublicKey::from_rust(&"),
"bitcoin::secp256k1::Signature" => Some("crate::c_types::Signature::from_rust(&"),
"[u8; 32]" if !is_ref => Some(" }"),
"[u8; 32]" if is_ref => Some(""),
+ "[u8; 20]" if !is_ref => Some(" }"),
"[u8; 16]" if !is_ref => Some(" }"),
"[u8; 10]" if !is_ref => Some(" }"),
"[u8; 4]" if !is_ref => Some(" }"),
"std::time::Duration" => Some(".as_secs()"),
"std::io::Error" if !is_ref => Some(")"),
+ "bech32::u5" => Some(".into()"),
+
"bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
=> Some(")"),
"bitcoin::secp256k1::Signature" => Some(")"),
use bitcoin::secp256k1::key::SecretKey as SecpSecretKey;
use bitcoin::secp256k1::Signature as SecpSignature;
use bitcoin::secp256k1::Error as SecpError;
+use bitcoin::bech32;
use std::convert::TryInto; // Bindings need at least rustc 1.34
+/// Integer in the range `0..32`
+#[derive(PartialEq, Eq, Copy, Clone)]
+#[allow(non_camel_case_types)]
+#[repr(C)]
+pub struct u5(u8);
+
+impl From<bech32::u5> for u5 {
+ fn from(o: bech32::u5) -> Self { Self(o.to_u8()) }
+}
+impl Into<bech32::u5> for u5 {
+ fn into(self) -> bech32::u5 { bech32::u5::try_from_u8(self.0).expect("u5 objects must be in the range 0..32") }
+}
+
#[derive(Clone)]
#[repr(C)]
/// Represents a valid secp256k1 public key serialized in "compressed form" as a 33 byte array.
#[repr(C)]
/// A 16-byte byte array.
pub struct SixteenBytes { /** The sixteen bytes */ pub data: [u8; 16], }
+#[derive(Clone)]
+#[repr(C)]
+/// A 20-byte byte array.
+pub struct TwentyBytes { /** The twenty bytes */ pub data: [u8; 20], }
pub(crate) struct VecWriter(pub Vec<u8>);
impl lightning::util::ser::Writer for VecWriter {