use bitcoin::secp256k1::ecdsa;
use bitcoin::secp256k1::schnorr;
use bitcoin::blockdata::constants::ChainHash;
-use bitcoin::blockdata::script::{self, Script};
+use bitcoin::blockdata::script::{self, ScriptBuf};
use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxOut};
use bitcoin::{consensus, Witness};
use bitcoin::consensus::Encodable;
fn from(v: &'a Vec<T>) -> Self { Self(v) }
}
-impl Writeable for WithoutLength<&Script> {
+impl Writeable for WithoutLength<&ScriptBuf> {
#[inline]
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
writer.write_all(self.0.as_bytes())
}
}
-impl Readable for WithoutLength<Script> {
+impl Readable for WithoutLength<ScriptBuf> {
#[inline]
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
let v: WithoutLength<Vec<u8>> = Readable::read(r)?;
}
}
-impl Writeable for Script {
+impl Writeable for ScriptBuf {
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
(self.len() as u16).write(w)?;
w.write_all(self.as_bytes())
}
}
-impl Readable for Script {
+impl Readable for ScriptBuf {
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
let len = <u16 as Readable>::read(r)? as usize;
let mut buf = vec![0; len];
r.read_exact(&mut buf)?;
- Ok(Script::from(buf))
+ Ok(ScriptBuf::from(buf))
}
}
impl Readable for ChainHash {
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
let buf: [u8; 32] = Readable::read(r)?;
- Ok(ChainHash::from(&buf[..]))
+ Ok(ChainHash::from(buf))
}
}
/// This serialization is used by [`BOLT 7`] hostnames.
///
/// [`BOLT 7`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md
-#[derive(Clone, Debug, PartialEq, Eq)]
+#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct Hostname(String);
impl Hostname {
/// Returns the length of the hostname.
/// if the `Transaction`'s consensus-serialized length is <= u16::MAX.
///
/// Use [`TransactionU16LenLimited::into_transaction`] to convert into the contained `Transaction`.
-#[derive(Clone, Debug, PartialEq, Eq)]
+#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct TransactionU16LenLimited(Transaction);
impl TransactionU16LenLimited {
#[cfg(test)]
mod tests {
use core::convert::TryFrom;
+ use bitcoin::hashes::hex::FromHex;
use bitcoin::secp256k1::ecdsa;
use crate::util::ser::{Readable, Hostname, Writeable};
"ffffffffffffffffff"
];
for i in 0..=7 {
- let mut stream = crate::io::Cursor::new(::hex::decode(bytes[i]).unwrap());
+ let mut stream = crate::io::Cursor::new(<Vec<u8>>::from_hex(bytes[i]).unwrap());
assert_eq!(super::BigSize::read(&mut stream).unwrap().0, values[i]);
let mut stream = super::VecWriter(Vec::new());
super::BigSize(values[i]).write(&mut stream).unwrap();
- assert_eq!(stream.0, ::hex::decode(bytes[i]).unwrap());
+ assert_eq!(stream.0, <Vec<u8>>::from_hex(bytes[i]).unwrap());
}
let err_bytes = vec![
"fd00fc",
""
];
for i in 0..=9 {
- let mut stream = crate::io::Cursor::new(::hex::decode(err_bytes[i]).unwrap());
+ let mut stream = crate::io::Cursor::new(<Vec<u8>>::from_hex(err_bytes[i]).unwrap());
if i < 3 {
assert_eq!(super::BigSize::read(&mut stream).err(), Some(crate::ln::msgs::DecodeError::InvalidValue));
} else {