diff --git a/src/blockdata/opcodes.rs b/src/blockdata/opcodes.rs index 9c664a35..a79081a3 100644 --- a/src/blockdata/opcodes.rs +++ b/src/blockdata/opcodes.rs @@ -24,8 +24,7 @@ use std::fmt; -use consensus::encode::{self, Decoder, Encoder}; -use consensus::encode::{Decodable, Encodable}; +use consensus::{encode, Decodable, Encodable, ReadExt, WriteExt}; // Note: I am deliberately not implementing PartialOrd or Ord on the // opcode enum. If you want to check ranges of opcodes, etc., @@ -715,14 +714,14 @@ impl From for All { display_from_debug!(All); -impl Decodable for All { +impl Decodable for All { #[inline] fn consensus_decode(d: &mut D) -> Result { Ok(All::from(d.read_u8()?)) } } -impl Encodable for All { +impl Encodable for All { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), encode::Error> { s.emit_u8(self.code) diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index f683e4b9..845fb8f8 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -30,8 +30,7 @@ use std::{error, fmt}; #[cfg(feature = "serde")] use serde; use blockdata::opcodes; -use consensus::encode::{Decodable, Encodable}; -use consensus::encode::{self, Decoder, Encoder}; +use consensus::{encode, Decodable, Encodable, ReadExt, WriteExt}; use bitcoin_hashes::{hash160, sha256, Hash}; #[cfg(feature="bitcoinconsensus")] use bitcoinconsensus; #[cfg(feature="bitcoinconsensus")] use std::convert; @@ -726,14 +725,14 @@ impl serde::Serialize for Script { } // Network serialization -impl Encodable for Script { +impl Encodable for Script { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), encode::Error> { self.0.consensus_encode(s) } } -impl Decodable for Script { +impl Decodable for Script { #[inline] fn consensus_decode(d: &mut D) -> Result { Ok(Script(Decodable::consensus_decode(d)?)) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index d0d18309..ff59f8a1 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -34,8 +34,8 @@ use bitcoin_hashes::hex::FromHex; use util::hash::BitcoinHash; #[cfg(feature="bitcoinconsensus")] use blockdata::script; use blockdata::script::Script; -use consensus::encode::{self, serialize, Encoder, Decoder}; -use consensus::encode::{Encodable, Decodable, VarInt}; +use consensus::{encode, serialize, Decodable, Encodable, ReadExt, WriteExt}; +use VarInt; /// A reference to a transaction output #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] @@ -439,13 +439,13 @@ impl BitcoinHash for Transaction { impl_consensus_encoding!(TxOut, value, script_pubkey); -impl Encodable for OutPoint { +impl Encodable for OutPoint { fn consensus_encode(&self, s: &mut S) -> Result <(), encode::Error> { self.txid.consensus_encode(s)?; self.vout.consensus_encode(s) } } -impl Decodable for OutPoint { +impl Decodable for OutPoint { fn consensus_decode(d: &mut D) -> Result { Ok(OutPoint { txid: Decodable::consensus_decode(d)?, @@ -454,14 +454,14 @@ impl Decodable for OutPoint { } } -impl Encodable for TxIn { +impl Encodable for TxIn { fn consensus_encode(&self, s: &mut S) -> Result <(), encode::Error> { self.previous_output.consensus_encode(s)?; self.script_sig.consensus_encode(s)?; self.sequence.consensus_encode(s) } } -impl Decodable for TxIn { +impl Decodable for TxIn { fn consensus_decode(d: &mut D) -> Result { Ok(TxIn { previous_output: Decodable::consensus_decode(d)?, @@ -472,7 +472,7 @@ impl Decodable for TxIn { } } -impl Encodable for Transaction { +impl Encodable for Transaction { fn consensus_encode(&self, s: &mut S) -> Result <(), encode::Error> { self.version.consensus_encode(s)?; let mut have_witness = self.input.is_empty(); @@ -498,7 +498,7 @@ impl Encodable for Transaction { } } -impl Decodable for Transaction { +impl Decodable for Transaction { fn consensus_decode(d: &mut D) -> Result { let version: u32 = Decodable::consensus_decode(d)?; let input: Vec = Decodable::consensus_decode(d)?; diff --git a/src/consensus/encode.rs b/src/consensus/encode.rs index 7620137a..b2c10c88 100644 --- a/src/consensus/encode.rs +++ b/src/consensus/encode.rs @@ -242,8 +242,8 @@ pub fn deserialize_partial<'a, T>(data: &'a [u8]) -> Result<(T, usize), Error> } -/// A simple Encoder trait -pub trait Encoder { +/// Extensions of `Write` to encode data as per Bitcoin consensus +pub trait WriteExt { /// Output a 64-bit uint fn emit_u64(&mut self, v: u64) -> Result<(), Error>; /// Output a 32-bit uint @@ -269,8 +269,8 @@ pub trait Encoder { fn emit_slice(&mut self, v: &[u8]) -> Result<(), Error>; } -/// A simple Decoder trait -pub trait Decoder { +/// Extensions of `Read` to decode data as per Bitcoin consensus +pub trait ReadExt { /// Read a 64-bit uint fn read_u64(&mut self) -> Result; /// Read a 32-bit uint @@ -314,7 +314,7 @@ macro_rules! decoder_fn { } } -impl Encoder for W { +impl WriteExt for W { encoder_fn!(emit_u64, u64, write_u64); encoder_fn!(emit_u32, u32, write_u32); encoder_fn!(emit_u16, u16, write_u16); @@ -340,7 +340,7 @@ impl Encoder for W { } } -impl Decoder for R { +impl ReadExt for R { decoder_fn!(read_u64, u64, read_u64); decoder_fn!(read_u32, u32, read_u32); decoder_fn!(read_u16, u16, read_u16); @@ -358,7 +358,7 @@ impl Decoder for R { } #[inline] fn read_bool(&mut self) -> Result { - Decoder::read_i8(self).map(|bit| bit != 0) + ReadExt::read_i8(self).map(|bit| bit != 0) } #[inline] fn read_slice(&mut self, slice: &mut [u8]) -> Result<(), Error> { @@ -370,14 +370,14 @@ impl Decoder for R { pub const MAX_VEC_SIZE: usize = 32 * 1024 * 1024; /// Data which can be encoded in a consensus-consistent way -pub trait Encodable { +pub trait Encodable { /// Encode an object with a well-defined format, should only ever error if - /// the underlying Encoder errors. + /// the underlying WriteExt errors. fn consensus_encode(&self, e: &mut S) -> Result<(), self::Error>; } /// Data which can be encoded in a consensus-consistent way -pub trait Decodable: Sized { +pub trait Decodable: Sized { /// Decode an object with a well-defined format fn consensus_decode(d: &mut D) -> Result; } @@ -393,12 +393,12 @@ pub struct CheckedData(pub Vec); // Primitive types macro_rules! impl_int_encodable{ ($ty:ident, $meth_dec:ident, $meth_enc:ident) => ( - impl Decodable for $ty { + impl Decodable for $ty { #[inline] fn consensus_decode(d: &mut D) -> Result<$ty, self::Error> { d.$meth_dec().map($ty::from_le) } } - impl Encodable for $ty { + impl Encodable for $ty { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), self::Error> { s.$meth_enc(self.to_le()) } } @@ -429,7 +429,7 @@ impl VarInt { } } -impl Encodable for VarInt { +impl Encodable for VarInt { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), self::Error> { match self.0 { @@ -441,7 +441,7 @@ impl Encodable for VarInt { } } -impl Decodable for VarInt { +impl Decodable for VarInt { #[inline] fn consensus_decode(d: &mut D) -> Result { let n = d.read_u8()?; @@ -477,18 +477,18 @@ impl Decodable for VarInt { // Booleans -impl Encodable for bool { +impl Encodable for bool { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), self::Error> { s.emit_u8(if *self {1} else {0}) } } -impl Decodable for bool { +impl Decodable for bool { #[inline] fn consensus_decode(d: &mut D) -> Result { d.read_u8().map(|n| n != 0) } } // Strings -impl Encodable for String { +impl Encodable for String { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), self::Error> { let b = self.as_bytes(); @@ -497,7 +497,7 @@ impl Encodable for String { } } -impl Decodable for String { +impl Decodable for String { #[inline] fn consensus_decode(d: &mut D) -> Result { String::from_utf8(Decodable::consensus_decode(d)?) @@ -509,14 +509,14 @@ impl Decodable for String { // Arrays macro_rules! impl_array { ( $size:expr ) => ( - impl Encodable for [u8; $size] { + impl Encodable for [u8; $size] { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), self::Error> { s.emit_slice(&self[..]) } } - impl Decodable for [u8; $size] { + impl Decodable for [u8; $size] { #[inline] fn consensus_decode(d: &mut D) -> Result<[u8; $size], self::Error> { let mut ret = [0; $size]; @@ -535,7 +535,7 @@ impl_array!(16); impl_array!(32); impl_array!(33); -impl Decodable for [u16; 8] { +impl Decodable for [u16; 8] { #[inline] fn consensus_decode(d: &mut D) -> Result<[u16; 8], self::Error> { let mut res = [0; 8]; @@ -546,7 +546,7 @@ impl Decodable for [u16; 8] { } } -impl Encodable for [u16; 8] { +impl Encodable for [u16; 8] { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), self::Error> { for c in self.iter() { c.consensus_encode(s)?; } @@ -557,7 +557,7 @@ impl Encodable for [u16; 8] { // Vectors macro_rules! impl_vec { ($type: ty) => { - impl Encodable for Vec<$type> { + impl Encodable for Vec<$type> { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), self::Error> { VarInt(self.len() as u64).consensus_encode(s)?; @@ -566,7 +566,7 @@ macro_rules! impl_vec { } } - impl Decodable for Vec<$type> { + impl Decodable for Vec<$type> { #[inline] fn consensus_decode(d: &mut D) -> Result, self::Error> { let len = VarInt::consensus_decode(d)?.0; @@ -592,7 +592,7 @@ impl_vec!(Vec); impl_vec!((u32, Address)); impl_vec!(u64); -impl Encodable for Vec { +impl Encodable for Vec { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), self::Error> { VarInt(self.len() as u64).consensus_encode(s)?; @@ -600,7 +600,7 @@ impl Encodable for Vec { } } -impl Decodable for Vec { +impl Decodable for Vec { #[inline] fn consensus_decode(d: &mut D) -> Result, self::Error> { let len = VarInt::consensus_decode(d)?.0; @@ -615,7 +615,7 @@ impl Decodable for Vec { } } -impl Encodable for Box<[u8]> { +impl Encodable for Box<[u8]> { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), self::Error> { VarInt(self.len() as u64).consensus_encode(s)?; @@ -623,7 +623,7 @@ impl Encodable for Box<[u8]> { } } -impl Decodable for Box<[u8]> { +impl Decodable for Box<[u8]> { #[inline] fn consensus_decode(d: &mut D) -> Result, self::Error> { let len = VarInt::consensus_decode(d)?.0; @@ -646,7 +646,7 @@ fn sha2_checksum(data: &[u8]) -> [u8; 4] { } // Checked data -impl Encodable for CheckedData { +impl Encodable for CheckedData { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), self::Error> { (self.0.len() as u32).consensus_encode(s)?; @@ -655,7 +655,7 @@ impl Encodable for CheckedData { } } -impl Decodable for CheckedData { +impl Decodable for CheckedData { #[inline] fn consensus_decode(d: &mut D) -> Result { let len: u32 = Decodable::consensus_decode(d)?; @@ -684,7 +684,7 @@ impl Decodable for CheckedData { // Tuples macro_rules! tuple_encode { ($($x:ident),*) => ( - impl ),*> Encodable for ($($x),*) { + impl ),*> Encodable for ($($x),*) { #[inline] #[allow(non_snake_case)] fn consensus_encode(&self, s: &mut S) -> Result<(), self::Error> { @@ -694,7 +694,7 @@ macro_rules! tuple_encode { } } - impl),*> Decodable for ($($x),*) { + impl),*> Decodable for ($($x),*) { #[inline] #[allow(non_snake_case)] fn consensus_decode(d: &mut D) -> Result<($($x),*), self::Error> { @@ -709,13 +709,13 @@ tuple_encode!(T0, T1, T2, T3); tuple_encode!(T0, T1, T2, T3, T4, T5); tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); -impl Encodable for sha256d::Hash { +impl Encodable for sha256d::Hash { fn consensus_encode(&self, s: &mut S) -> Result<(), self::Error> { self.into_inner().consensus_encode(s) } } -impl Decodable for sha256d::Hash { +impl Decodable for sha256d::Hash { fn consensus_decode(d: &mut D) -> Result { let inner: [u8; 32] = Decodable::consensus_decode(d)?; Ok(sha256d::Hash::from_slice(&inner).unwrap()) diff --git a/src/consensus/mod.rs b/src/consensus/mod.rs index 634b23ca..1e302333 100644 --- a/src/consensus/mod.rs +++ b/src/consensus/mod.rs @@ -21,6 +21,6 @@ pub mod encode; pub mod params; -pub use self::encode::{Encodable, Decodable, Encoder, Decoder, - serialize, deserialize, deserialize_partial}; +pub use self::encode::{Encodable, Decodable, WriteExt, ReadExt}; +pub use self::encode::{serialize, deserialize, deserialize_partial}; pub use self::params::Params; diff --git a/src/internal_macros.rs b/src/internal_macros.rs index f891c46b..86cec029 100644 --- a/src/internal_macros.rs +++ b/src/internal_macros.rs @@ -18,7 +18,7 @@ macro_rules! impl_consensus_encoding { ($thing:ident, $($field:ident),+) => ( - impl ::consensus::encode::Encodable for $thing { + impl ::consensus::Encodable for $thing { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), ::consensus::encode::Error> { $( self.$field.consensus_encode(s)?; )+ @@ -26,12 +26,11 @@ macro_rules! impl_consensus_encoding { } } - impl ::consensus::encode::Decodable for $thing { + impl ::consensus::Decodable for $thing { #[inline] fn consensus_decode(d: &mut D) -> Result<$thing, ::consensus::encode::Error> { - use consensus::encode::Decodable; Ok($thing { - $( $field: Decodable::consensus_decode(d)?, )+ + $( $field: ::consensus::Decodable::consensus_decode(d)?, )+ }) } } diff --git a/src/network/address.rs b/src/network/address.rs index c6871486..36531b2a 100644 --- a/src/network/address.rs +++ b/src/network/address.rs @@ -22,7 +22,7 @@ use std::io; use std::fmt; use std::net::{SocketAddr, Ipv6Addr, SocketAddrV4, SocketAddrV6}; -use consensus::encode::{self, Encoder, Decoder}; +use consensus::{encode, ReadExt, WriteExt}; use consensus::encode::{Decodable, Encodable}; /// A message which can be sent on the Bitcoin network @@ -72,7 +72,7 @@ fn addr_to_be(addr: [u16; 8]) -> [u16; 8] { addr[4].to_be(), addr[5].to_be(), addr[6].to_be(), addr[7].to_be()] } -impl Encodable for Address { +impl Encodable for Address { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), encode::Error> { self.services.consensus_encode(s)?; @@ -81,7 +81,7 @@ impl Encodable for Address { } } -impl Decodable for Address { +impl Decodable for Address { #[inline] fn consensus_decode(d: &mut D) -> Result { Ok(Address { diff --git a/src/network/constants.rs b/src/network/constants.rs index 0315fb13..7f44ff02 100644 --- a/src/network/constants.rs +++ b/src/network/constants.rs @@ -37,8 +37,7 @@ //! assert_eq!(&bytes[..], &[0xF9, 0xBE, 0xB4, 0xD9]); //! ``` -use consensus::encode::{Decodable, Encodable}; -use consensus::encode::{self, Encoder, Decoder}; +use consensus::{encode, Decodable, Encodable, ReadExt, WriteExt}; /// Version of the protocol as appearing in network message headers pub const PROTOCOL_VERSION: u32 = 70001; @@ -102,7 +101,7 @@ impl Network { } } -impl Encodable for Network { +impl Encodable for Network { /// Encodes the magic bytes of `Network`. #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), encode::Error> { @@ -110,7 +109,7 @@ impl Encodable for Network { } } -impl Decodable for Network { +impl Decodable for Network { /// Decodes the magic bytes of `Network`. #[inline] fn consensus_decode(d: &mut D) -> Result { diff --git a/src/network/message.rs b/src/network/message.rs index 2e01c708..40d1e051 100644 --- a/src/network/message.rs +++ b/src/network/message.rs @@ -30,14 +30,14 @@ use network::message_blockdata; use network::message_filter; use consensus::encode::{Decodable, Encodable}; use consensus::encode::{CheckedData, VarInt}; -use consensus::encode::{self, serialize, Encoder, Decoder}; +use consensus::{encode, serialize, ReadExt, WriteExt}; use consensus::encode::MAX_VEC_SIZE; /// Serializer for command string #[derive(PartialEq, Eq, Clone, Debug)] pub struct CommandString(pub String); -impl Encodable for CommandString { +impl Encodable for CommandString { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), encode::Error> { let &CommandString(ref inner_str) = self; @@ -53,7 +53,7 @@ impl Encodable for CommandString { } } -impl Decodable for CommandString { +impl Decodable for CommandString { #[inline] fn consensus_decode(d: &mut D) -> Result { let rawbytes: [u8; 12] = Decodable::consensus_decode(d)?; @@ -160,7 +160,7 @@ impl RawNetworkMessage { } struct HeaderSerializationWrapper<'a>(&'a Vec); -impl <'a, S: Encoder> Encodable for HeaderSerializationWrapper<'a> { +impl <'a, S: WriteExt> Encodable for HeaderSerializationWrapper<'a> { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), encode::Error> { VarInt(self.0.len() as u64).consensus_encode(s)?; @@ -172,7 +172,7 @@ impl <'a, S: Encoder> Encodable for HeaderSerializationWrapper<'a> { } } -impl Encodable for RawNetworkMessage { +impl Encodable for RawNetworkMessage { fn consensus_encode(&self, s: &mut S) -> Result<(), encode::Error> { self.magic.consensus_encode(s)?; CommandString(self.command()).consensus_encode(s)?; @@ -205,7 +205,7 @@ impl Encodable for RawNetworkMessage { } struct HeaderDeserializationWrapper(Vec); -impl Decodable for HeaderDeserializationWrapper { +impl Decodable for HeaderDeserializationWrapper { #[inline] fn consensus_decode(d: &mut D) -> Result { let len = VarInt::consensus_decode(d)?.0; @@ -226,7 +226,7 @@ impl Decodable for HeaderDeserializationWrapper { } } -impl Decodable for RawNetworkMessage { +impl Decodable for RawNetworkMessage { fn consensus_decode(d: &mut D) -> Result { let magic = Decodable::consensus_decode(d)?; let CommandString(cmd): CommandString= Decodable::consensus_decode(d)?; diff --git a/src/network/message_blockdata.rs b/src/network/message_blockdata.rs index 67834d86..b9f76b3b 100644 --- a/src/network/message_blockdata.rs +++ b/src/network/message_blockdata.rs @@ -20,7 +20,7 @@ use network::constants; use consensus::encode::{Decodable, Encodable}; -use consensus::encode::{self, Decoder, Encoder}; +use consensus::{encode, ReadExt, WriteExt}; use bitcoin_hashes::sha256d; #[derive(PartialEq, Eq, Clone, Debug)] @@ -101,7 +101,7 @@ impl GetHeadersMessage { impl_consensus_encoding!(GetHeadersMessage, version, locator_hashes, stop_hash); -impl Encodable for Inventory { +impl Encodable for Inventory { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), encode::Error> { match self.inv_type { @@ -115,7 +115,7 @@ impl Encodable for Inventory { } } -impl Decodable for Inventory { +impl Decodable for Inventory { #[inline] fn consensus_decode(d: &mut D) -> Result { let int_type: u32 = Decodable::consensus_decode(d)?; diff --git a/src/util/merkleblock.rs b/src/util/merkleblock.rs index 6b2eb6b2..6ae1512e 100644 --- a/src/util/merkleblock.rs +++ b/src/util/merkleblock.rs @@ -62,7 +62,7 @@ use bitcoin_hashes::{sha256d, Hash}; use blockdata::constants::{MAX_BLOCK_WEIGHT, MIN_TRANSACTION_WEIGHT}; use consensus::encode::{Encodable, Error}; -use consensus::{Decodable, Decoder, Encoder}; +use consensus::{Decodable, ReadExt, WriteExt}; use util::hash::BitcoinHash; use util::merkleblock::MerkleBlockError::*; use {Block, BlockHeader}; @@ -353,7 +353,7 @@ impl PartialMerkleTree { } } -impl Encodable for PartialMerkleTree { +impl Encodable for PartialMerkleTree { fn consensus_encode(&self, s: &mut S) -> Result<(), Error> { self.num_transactions.consensus_encode(s)?; self.hashes.consensus_encode(s)?; @@ -365,7 +365,7 @@ impl Encodable for PartialMerkleTree { } } -impl Decodable for PartialMerkleTree { +impl Decodable for PartialMerkleTree { fn consensus_decode(d: &mut D) -> Result { let num_transactions: u32 = Decodable::consensus_decode(d)?; let hashes: Vec = Decodable::consensus_decode(d)?; @@ -471,14 +471,14 @@ impl MerkleBlock { } } -impl Encodable for MerkleBlock { +impl Encodable for MerkleBlock { fn consensus_encode(&self, s: &mut S) -> Result<(), Error> { self.header.consensus_encode(s)?; self.txn.consensus_encode(s) } } -impl Decodable for MerkleBlock { +impl Decodable for MerkleBlock { fn consensus_decode(d: &mut D) -> Result { Ok(MerkleBlock { header: Decodable::consensus_decode(d)?, diff --git a/src/util/psbt/macros.rs b/src/util/psbt/macros.rs index 21a4be8a..50363f4b 100644 --- a/src/util/psbt/macros.rs +++ b/src/util/psbt/macros.rs @@ -14,7 +14,7 @@ #[allow(unused_macros)] macro_rules! hex_psbt { - ($s:expr) => { ::consensus::encode::deserialize(&::hex::decode($s).unwrap()) }; + ($s:expr) => { ::consensus::deserialize(&::hex::decode($s).unwrap()) }; } macro_rules! merge { @@ -36,7 +36,7 @@ macro_rules! impl_psbt_deserialize { ($thing:ty) => { impl ::util::psbt::serialize::Deserialize for $thing { fn deserialize(bytes: &[u8]) -> Result { - ::consensus::encode::deserialize(&bytes[..]) + ::consensus::deserialize(&bytes[..]) } } }; @@ -46,7 +46,7 @@ macro_rules! impl_psbt_serialize { ($thing:ty) => { impl ::util::psbt::serialize::Serialize for $thing { fn serialize(&self) -> Vec { - ::consensus::encode::serialize(self) + ::consensus::serialize(self) } } }; @@ -54,13 +54,13 @@ macro_rules! impl_psbt_serialize { macro_rules! impl_psbtmap_consensus_encoding { ($thing:ty) => { - impl ::consensus::encode::Encodable for $thing { + impl ::consensus::Encodable for $thing { fn consensus_encode(&self, s: &mut S) -> Result<(), ::consensus::encode::Error> { for pair in ::util::psbt::Map::get_pairs(self)? { - ::consensus::encode::Encodable::consensus_encode(&pair, s)? + ::consensus::Encodable::consensus_encode(&pair, s)? } - ::consensus::encode::Encodable::consensus_encode(&0x00_u8, s) + ::consensus::Encodable::consensus_encode(&0x00_u8, s) } } }; @@ -68,12 +68,12 @@ macro_rules! impl_psbtmap_consensus_encoding { macro_rules! impl_psbtmap_consensus_decoding { ($thing:ty) => { - impl ::consensus::encode::Decodable for $thing { + impl ::consensus::Decodable for $thing { fn consensus_decode(d: &mut D) -> Result { let mut rv: Self = ::std::default::Default::default(); loop { - match ::consensus::encode::Decodable::consensus_decode(d) { + match ::consensus::Decodable::consensus_decode(d) { Ok(pair) => ::util::psbt::Map::insert_pair(&mut rv, pair)?, Err(::consensus::encode::Error::Psbt(::util::psbt::Error::NoMorePairs)) => return Ok(rv), Err(e) => return Err(e), diff --git a/src/util/psbt/map/global.rs b/src/util/psbt/map/global.rs index faa59dcc..9e14bd68 100644 --- a/src/util/psbt/map/global.rs +++ b/src/util/psbt/map/global.rs @@ -16,7 +16,7 @@ use std::collections::HashMap; use std::io::Cursor; use blockdata::transaction::Transaction; -use consensus::encode::{self, Encodable, Decodable, Decoder}; +use consensus::{encode, Encodable, Decodable, ReadExt}; use util::psbt::map::Map; use util::psbt::raw; use util::psbt; @@ -120,7 +120,7 @@ impl Map for Global { impl_psbtmap_consensus_encoding!(Global); -impl Decodable for Global { +impl Decodable for Global { fn consensus_decode(d: &mut D) -> Result { let mut tx: Option = None; diff --git a/src/util/psbt/mod.rs b/src/util/psbt/mod.rs index 2f149105..e3299d09 100644 --- a/src/util/psbt/mod.rs +++ b/src/util/psbt/mod.rs @@ -20,7 +20,7 @@ use blockdata::script::Script; use blockdata::transaction::Transaction; -use consensus::encode::{self, Encodable, Decodable, Encoder, Decoder}; +use consensus::{encode, Encodable, Decodable, WriteExt, ReadExt}; mod error; pub use self::error::Error; @@ -88,7 +88,7 @@ impl PartiallySignedTransaction { } } -impl Encodable for PartiallySignedTransaction { +impl Encodable for PartiallySignedTransaction { fn consensus_encode(&self, s: &mut S) -> Result<(), encode::Error> { b"psbt".consensus_encode(s)?; @@ -108,7 +108,7 @@ impl Encodable for PartiallySignedTransaction { } } -impl Decodable for PartiallySignedTransaction { +impl Decodable for PartiallySignedTransaction { fn consensus_decode(d: &mut D) -> Result { let magic: [u8; 4] = Decodable::consensus_decode(d)?; diff --git a/src/util/psbt/raw.rs b/src/util/psbt/raw.rs index 3f7fbba5..1753cf1b 100644 --- a/src/util/psbt/raw.rs +++ b/src/util/psbt/raw.rs @@ -20,7 +20,7 @@ use std::fmt; use consensus::encode::{Decodable, Encodable, VarInt, MAX_VEC_SIZE}; -use consensus::encode::{self, Decoder, Encoder}; +use consensus::{encode, ReadExt, WriteExt}; use util::psbt::Error; /// A PSBT key in its raw byte form. @@ -52,7 +52,7 @@ impl fmt::Display for Key { } } -impl Decodable for Key { +impl Decodable for Key { fn consensus_decode(d: &mut D) -> Result { let VarInt(byte_size): VarInt = Decodable::consensus_decode(d)?; @@ -80,7 +80,7 @@ impl Decodable for Key { } } -impl Encodable for Key { +impl Encodable for Key { fn consensus_encode(&self, s: &mut S) -> Result<(), encode::Error> { VarInt((self.key.len() + 1) as u64).consensus_encode(s)?; @@ -94,14 +94,14 @@ impl Encodable for Key { } } -impl Encodable for Pair { +impl Encodable for Pair { fn consensus_encode(&self, s: &mut S) -> Result<(), encode::Error> { self.key.consensus_encode(s)?; self.value.consensus_encode(s) } } -impl Decodable for Pair { +impl Decodable for Pair { fn consensus_decode(d: &mut D) -> Result { Ok(Pair { key: Decodable::consensus_decode(d)?, diff --git a/src/util/uint.rs b/src/util/uint.rs index 05d4a95a..42abdbfa 100644 --- a/src/util/uint.rs +++ b/src/util/uint.rs @@ -336,7 +336,7 @@ macro_rules! construct_uint { } } - impl ::consensus::encode::Encodable for $name { + impl ::consensus::Encodable for $name { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), encode::Error> { let &$name(ref data) = self; @@ -345,9 +345,9 @@ macro_rules! construct_uint { } } - impl ::consensus::encode::Decodable for $name { + impl ::consensus::Decodable for $name { fn consensus_decode(d: &mut D) -> Result<$name, encode::Error> { - use consensus::encode::Decodable; + use consensus::Decodable; let mut ret: [u64; $n_words] = [0; $n_words]; for i in 0..$n_words { ret[i] = Decodable::consensus_decode(d)?; @@ -388,7 +388,7 @@ impl Uint256 { #[cfg(test)] mod tests { - use consensus::encode::{deserialize, serialize}; + use consensus::{deserialize, serialize}; use util::uint::Uint256; use util::BitArray;