/// Auto-generated C-mapped types for templated containers
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 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)]
+#[allow(missing_docs)] // If there's no docs upstream, that's good enough for us
+/// Represents an IO Error. Note that some information is lost in the conversion from Rust.
+pub enum IOError {
+ NotFound,
+ PermissionDenied,
+ ConnectionRefused,
+ ConnectionReset,
+ ConnectionAborted,
+ NotConnected,
+ AddrInUse,
+ AddrNotAvailable,
+ BrokenPipe,
+ AlreadyExists,
+ WouldBlock,
+ InvalidInput,
+ InvalidData,
+ TimedOut,
+ WriteZero,
+ Interrupted,
+ Other,
+ UnexpectedEof,
+}
+impl IOError {
+ pub(crate) fn from_rust(err: std::io::Error) -> Self {
+ match err.kind() {
+ std::io::ErrorKind::NotFound => IOError::NotFound,
+ std::io::ErrorKind::PermissionDenied => IOError::PermissionDenied,
+ std::io::ErrorKind::ConnectionRefused => IOError::ConnectionRefused,
+ std::io::ErrorKind::ConnectionReset => IOError::ConnectionReset,
+ std::io::ErrorKind::ConnectionAborted => IOError::ConnectionAborted,
+ std::io::ErrorKind::NotConnected => IOError::NotConnected,
+ std::io::ErrorKind::AddrInUse => IOError::AddrInUse,
+ std::io::ErrorKind::AddrNotAvailable => IOError::AddrNotAvailable,
+ std::io::ErrorKind::BrokenPipe => IOError::BrokenPipe,
+ std::io::ErrorKind::AlreadyExists => IOError::AlreadyExists,
+ std::io::ErrorKind::WouldBlock => IOError::WouldBlock,
+ std::io::ErrorKind::InvalidInput => IOError::InvalidInput,
+ std::io::ErrorKind::InvalidData => IOError::InvalidData,
+ std::io::ErrorKind::TimedOut => IOError::TimedOut,
+ std::io::ErrorKind::WriteZero => IOError::WriteZero,
+ std::io::ErrorKind::Interrupted => IOError::Interrupted,
+ std::io::ErrorKind::Other => IOError::Other,
+ std::io::ErrorKind::UnexpectedEof => IOError::UnexpectedEof,
+ _ => IOError::Other,
+ }
+ }
+}
+
#[repr(C)]
/// A serialized transaction, in (pointer, length) form.
///
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<u8>) -> Self {
- let datalen = v.len();
- let data = Box::into_raw(v.into_boxed_slice());
+ pub(crate) fn from_bitcoin(btc: &BitcoinTransaction) -> Self {
+ let vec = ::bitcoin::consensus::encode::serialize(btc);
+ let datalen = vec.len();
+ let data = Box::into_raw(vec.into_boxed_slice());
Self {
data: unsafe { (*data).as_mut_ptr() },
datalen,
/// Frees the data buffer, if data_is_owned is set and datalen > 0.
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())
+pub(crate) fn bitcoin_to_C_outpoint(outpoint: ::bitcoin::blockdata::transaction::OutPoint) -> crate::lightning::chain::transaction::OutPoint {
+ crate::lightning::chain::transaction::OutPoint_new(ThirtyTwoBytes { data: outpoint.txid.into_inner() }, outpoint.vout.try_into().unwrap())
}
#[repr(C)]
#[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 {