X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Fc_types%2Fmod.rs;h=2248ec2befbfec64e08fd43484cbac004c3e02e5;hb=1f9a169c7e376baad24015ecf775e1adcf9d5967;hp=c4113a9647cf20f64b09d11881a626992d884d55;hpb=350074fb39d33812f2e37c0c903b6910b584850f;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/c_types/mod.rs b/lightning-c-bindings/src/c_types/mod.rs index c4113a9..2248ec2 100644 --- a/lightning-c-bindings/src/c_types/mod.rs +++ b/lightning-c-bindings/src/c_types/mod.rs @@ -9,9 +9,23 @@ 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 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 for u5 { + fn from(o: bech32::u5) -> Self { Self(o.to_u8()) } +} +impl Into 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. @@ -296,6 +310,10 @@ pub struct TenBytes { /** The ten bytes */ pub data: [u8; 10], } #[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); impl lightning::util::ser::Writer for VecWriter {