Merge pull request #482 from rust-bitcoin/2020-09-modern

Small modernization after MSRV bump
This commit is contained in:
Steven Roose 2020-10-09 13:51:22 +02:00 committed by GitHub
commit 5355b36f63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 99 additions and 185 deletions

View File

@ -10,9 +10,6 @@ description = "General purpose library for using and interoperating with Bitcoin
keywords = [ "crypto", "bitcoin" ] keywords = [ "crypto", "bitcoin" ]
readme = "README.md" readme = "README.md"
[lib]
name = "bitcoin"
path = "src/lib.rs"
[features] [features]
fuzztarget = ["secp256k1/fuzztarget", "bitcoin_hashes/fuzztarget"] fuzztarget = ["secp256k1/fuzztarget", "bitcoin_hashes/fuzztarget"]
@ -32,7 +29,6 @@ bitcoinconsensus = { version = "0.19.0-1", optional = true }
serde = { version = "1", optional = true } serde = { version = "1", optional = true }
[dev-dependencies] [dev-dependencies]
hex = "=0.3.2"
serde_derive = "<1.0.99" serde_derive = "<1.0.99"
serde_json = "<1.0.45" serde_json = "<1.0.45"
serde_test = "1" serde_test = "1"

View File

@ -31,9 +31,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -36,9 +36,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -53,9 +53,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -31,9 +31,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -40,9 +40,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -70,9 +70,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -52,9 +52,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -67,9 +67,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -88,9 +88,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -120,12 +120,7 @@ impl fmt::Display for Error {
} }
} }
#[allow(deprecated)] impl error::Error for Error {}
impl error::Error for Error {
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
}
#[cfg(feature="bitcoinconsensus")] #[cfg(feature="bitcoinconsensus")]
#[doc(hidden)] #[doc(hidden)]
@ -422,7 +417,7 @@ impl Script {
} }
/// Write the assembly decoding of the script to the formatter. /// Write the assembly decoding of the script to the formatter.
pub fn fmt_asm(&self, f: &mut fmt::Write) -> fmt::Result { pub fn fmt_asm(&self, f: &mut dyn fmt::Write) -> fmt::Result {
let mut index = 0; let mut index = 0;
while index < self.0.len() { while index < self.0.len() {
let opcode = opcodes::All::from(self.0[index]); let opcode = opcodes::All::from(self.0[index]);

View File

@ -24,7 +24,7 @@
//! //!
use std::default::Default; use std::default::Default;
use std::{fmt, io}; use std::{error, fmt, io};
use hashes::{self, Hash, sha256d}; use hashes::{self, Hash, sha256d};
use hashes::hex::FromHex; use hashes::hex::FromHex;
@ -128,13 +128,8 @@ impl fmt::Display for ParseOutPointError {
} }
} }
#[allow(deprecated)] impl error::Error for ParseOutPointError {
impl ::std::error::Error for ParseOutPointError { fn cause(&self) -> Option<&dyn error::Error> {
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
fn cause(&self) -> Option<&::std::error::Error> {
match *self { match *self {
ParseOutPointError::Txid(ref e) => Some(e), ParseOutPointError::Txid(ref e) => Some(e),
ParseOutPointError::Vout(ref e) => Some(e), ParseOutPointError::Vout(ref e) => Some(e),
@ -147,7 +142,7 @@ impl ::std::error::Error for ParseOutPointError {
/// It does not permit leading zeroes or non-digit characters. /// It does not permit leading zeroes or non-digit characters.
fn parse_vout(s: &str) -> Result<u32, ParseOutPointError> { fn parse_vout(s: &str) -> Result<u32, ParseOutPointError> {
if s.len() > 1 { if s.len() > 1 {
let first = s.chars().nth(0).unwrap(); let first = s.chars().next().unwrap();
if first == '0' || first == '+' { if first == '0' || first == '+' {
return Err(ParseOutPointError::VoutNotCanonical); return Err(ParseOutPointError::VoutNotCanonical);
} }

View File

@ -109,9 +109,8 @@ impl fmt::Display for Error {
} }
} }
#[allow(deprecated)]
impl error::Error for Error { impl error::Error for Error {
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
Error::Io(ref e) => Some(e), Error::Io(ref e) => Some(e),
Error::Psbt(ref e) => Some(e), Error::Psbt(ref e) => Some(e),
@ -126,10 +125,6 @@ impl error::Error for Error {
| Error::UnknownInventoryType(..) => None, | Error::UnknownInventoryType(..) => None,
} }
} }
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
} }
#[doc(hidden)] #[doc(hidden)]
@ -376,14 +371,14 @@ impl_int_encodable!(i64, read_i64, emit_i64);
impl VarInt { impl VarInt {
/// Gets the length of this VarInt when encoded. /// Gets the length of this VarInt when encoded.
/// Returns 1 for 0...0xFC, 3 for 0xFD...(2^16-1), 5 for 0x10000...(2^32-1), /// Returns 1 for 0..=0xFC, 3 for 0xFD..=(2^16-1), 5 for 0x10000..=(2^32-1),
/// and 9 otherwise. /// and 9 otherwise.
#[inline] #[inline]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
match self.0 { match self.0 {
0...0xFC => { 1 } 0..=0xFC => { 1 }
0xFD...0xFFFF => { 3 } 0xFD..=0xFFFF => { 3 }
0x10000...0xFFFFFFFF => { 5 } 0x10000..=0xFFFFFFFF => { 5 }
_ => { 9 } _ => { 9 }
} }
} }
@ -393,16 +388,16 @@ impl Encodable for VarInt {
#[inline] #[inline]
fn consensus_encode<S: io::Write>(&self, mut s: S) -> Result<usize, Error> { fn consensus_encode<S: io::Write>(&self, mut s: S) -> Result<usize, Error> {
match self.0 { match self.0 {
0...0xFC => { 0..=0xFC => {
(self.0 as u8).consensus_encode(s)?; (self.0 as u8).consensus_encode(s)?;
Ok(1) Ok(1)
}, },
0xFD...0xFFFF => { 0xFD..=0xFFFF => {
s.emit_u8(0xFD)?; s.emit_u8(0xFD)?;
(self.0 as u16).consensus_encode(s)?; (self.0 as u16).consensus_encode(s)?;
Ok(3) Ok(3)
}, },
0x10000...0xFFFFFFFF => { 0x10000..=0xFFFFFFFF => {
s.emit_u8(0xFE)?; s.emit_u8(0xFE)?;
(self.0 as u32).consensus_encode(s)?; (self.0 as u32).consensus_encode(s)?;
Ok(5) Ok(5)

View File

@ -16,10 +16,7 @@
//! to avoid mixing data of the same hash format (like SHA256d) but of different meaning //! to avoid mixing data of the same hash format (like SHA256d) but of different meaning
//! (transaction id, block hash etc). //! (transaction id, block hash etc).
use consensus::encode::{Encodable, Decodable, Error}; use hashes::{Hash, sha256, sha256d, hash160};
use hashes::{Hash, sha256, sha256d, ripemd160, hash160};
use hashes::hex::{FromHex, ToHex};
use util::key::PublicKey;
macro_rules! impl_hashencode { macro_rules! impl_hashencode {
($hashtype:ident) => { ($hashtype:ident) => {

View File

@ -23,17 +23,9 @@
//! software. //! software.
//! //!
#![crate_name = "bitcoin"]
#![crate_type = "dylib"]
#![crate_type = "rlib"]
// Experimental features we need // Experimental features we need
#![cfg_attr(all(test, feature = "unstable"), feature(test))] #![cfg_attr(all(test, feature = "unstable"), feature(test))]
// Clippy whitelist
#![cfg_attr(feature = "clippy", allow(needless_range_loop))] // suggests making a big mess of array newtypes
#![cfg_attr(feature = "clippy", allow(extend_from_slice))] // `extend_from_slice` only available since 1.6
// Coding conventions // Coding conventions
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
#![deny(non_upper_case_globals)] #![deny(non_upper_case_globals)]
@ -44,23 +36,17 @@
#![deny(unused_imports)] #![deny(unused_imports)]
#![deny(missing_docs)] #![deny(missing_docs)]
// In general, rust is absolutely horrid at supporting users doing things like,
// for example, compiling Rust code for real environments. Disable useless lints
// that don't do anything but annoy us and cant actually ever be resolved.
#![allow(bare_trait_objects)]
#![allow(ellipsis_inclusive_range_patterns)]
// Re-exported dependencies. // Re-exported dependencies.
#[macro_use] pub extern crate bitcoin_hashes as hashes; #[macro_use] pub extern crate bitcoin_hashes as hashes;
pub extern crate secp256k1; pub extern crate secp256k1;
pub extern crate bech32; pub extern crate bech32;
#[cfg(feature="bitcoinconsensus")] extern crate bitcoinconsensus;
#[cfg(feature = "serde")] extern crate serde; #[cfg(feature = "serde")] extern crate serde;
#[cfg(all(test, feature = "serde"))] #[macro_use] extern crate serde_derive; // for 1.22.0 compat #[cfg(all(test, feature = "serde"))] #[macro_use] extern crate serde_derive; // for 1.22.0 compat
#[cfg(all(test, feature = "serde"))] extern crate serde_json; #[cfg(all(test, feature = "serde"))] extern crate serde_json;
#[cfg(all(test, feature = "serde"))] extern crate serde_test; #[cfg(all(test, feature = "serde"))] extern crate serde_test;
#[cfg(all(test, feature = "unstable"))] extern crate test; #[cfg(all(test, feature = "unstable"))] extern crate test;
#[cfg(feature="bitcoinconsensus")] extern crate bitcoinconsensus;
#[cfg(target_pointer_width = "16")] #[cfg(target_pointer_width = "16")]
compile_error!("rust-bitcoin cannot be used on 16-bit architectures"); compile_error!("rust-bitcoin cannot be used on 16-bit architectures");
@ -75,8 +61,6 @@ pub mod network;
pub mod blockdata; pub mod blockdata;
pub mod util; pub mod util;
pub mod consensus; pub mod consensus;
// Do not remove: required in order to get hash types implementation macros to work correctly
#[allow(unused_imports)]
pub mod hash_types; pub mod hash_types;
pub use hash_types::*; pub use hash_types::*;

View File

@ -60,13 +60,9 @@ impl From<io::Error> for Error {
} }
} }
#[allow(deprecated)]
impl error::Error for Error { impl error::Error for Error {
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
Error::Io(ref e) => Some(e), Error::Io(ref e) => Some(e),
Error::SocketMutexPoisoned | Error::SocketNotConnectedToPeer => None, Error::SocketMutexPoisoned | Error::SocketNotConnectedToPeer => None,

View File

@ -38,6 +38,7 @@
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
use std::str::FromStr; use std::str::FromStr;
use std::error;
use bech32; use bech32;
use hashes::Hash; use hashes::Hash;
@ -86,19 +87,14 @@ impl fmt::Display for Error {
} }
} }
#[allow(deprecated)] impl error::Error for Error {
impl ::std::error::Error for Error { fn cause(&self) -> Option<&dyn error::Error> {
fn cause(&self) -> Option<&::std::error::Error> {
match *self { match *self {
Error::Base58(ref e) => Some(e), Error::Base58(ref e) => Some(e),
Error::Bech32(ref e) => Some(e), Error::Bech32(ref e) => Some(e),
_ => None, _ => None,
} }
} }
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
} }
#[doc(hidden)] #[doc(hidden)]

View File

@ -115,13 +115,7 @@ impl fmt::Display for ParseAmountError {
} }
} }
#[allow(deprecated)] impl error::Error for ParseAmountError {}
impl error::Error for ParseAmountError {
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
}
fn is_too_precise(s: &str, precision: usize) -> bool { fn is_too_precise(s: &str, precision: usize) -> bool {
s.contains('.') || precision >= s.len() || s.chars().rev().take(precision).any(|d| d != '0') s.contains('.') || precision >= s.len() || s.chars().rev().take(precision).any(|d| d != '0')
@ -172,7 +166,7 @@ fn parse_signed_to_satoshi(
let mut value: u64 = 0; // as satoshis let mut value: u64 = 0; // as satoshis
for c in s.chars() { for c in s.chars() {
match c { match c {
'0'...'9' => { '0'..='9' => {
// Do `value = 10 * value + digit`, catching overflows. // Do `value = 10 * value + digit`, catching overflows.
match 10_u64.checked_mul(value) { match 10_u64.checked_mul(value) {
None => return Err(ParseAmountError::TooBig), None => return Err(ParseAmountError::TooBig),
@ -215,7 +209,7 @@ fn parse_signed_to_satoshi(
fn fmt_satoshi_in( fn fmt_satoshi_in(
satoshi: u64, satoshi: u64,
negative: bool, negative: bool,
f: &mut fmt::Write, f: &mut dyn fmt::Write,
denom: Denomination, denom: Denomination,
) -> fmt::Result { ) -> fmt::Result {
if negative { if negative {
@ -365,7 +359,7 @@ impl Amount {
/// Format the value of this [Amount] in the given denomination. /// Format the value of this [Amount] in the given denomination.
/// ///
/// Does not include the denomination. /// Does not include the denomination.
pub fn fmt_value_in(self, f: &mut fmt::Write, denom: Denomination) -> fmt::Result { pub fn fmt_value_in(self, f: &mut dyn fmt::Write, denom: Denomination) -> fmt::Result {
fmt_satoshi_in(self.as_sat(), false, f, denom) fmt_satoshi_in(self.as_sat(), false, f, denom)
} }
@ -643,7 +637,7 @@ impl SignedAmount {
/// Format the value of this [SignedAmount] in the given denomination. /// Format the value of this [SignedAmount] in the given denomination.
/// ///
/// Does not include the denomination. /// Does not include the denomination.
pub fn fmt_value_in(self, f: &mut fmt::Write, denom: Denomination) -> fmt::Result { pub fn fmt_value_in(self, f: &mut dyn fmt::Write, denom: Denomination) -> fmt::Result {
let sats = self.as_sat().checked_abs().map(|a: i64| a as u64).unwrap_or_else(|| { let sats = self.as_sat().checked_abs().map(|a: i64| a as u64).unwrap_or_else(|| {
// We could also hard code this into `9223372036854775808` // We could also hard code this into `9223372036854775808`
u64::max_value() - self.as_sat() as u64 +1 u64::max_value() - self.as_sat() as u64 +1

View File

@ -52,12 +52,7 @@ impl fmt::Display for Error {
} }
} }
#[allow(deprecated)] impl error::Error for Error {}
impl error::Error for Error {
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
}
/// Vector-like object that holds the first 100 elements on the stack. If more space is needed it /// Vector-like object that holds the first 100 elements on the stack. If more space is needed it
/// will be allocated on the heap. /// will be allocated on the heap.

View File

@ -75,12 +75,7 @@ pub enum Error {
Io(io::Error), Io(io::Error),
} }
#[allow(deprecated)] impl error::Error for Error {}
impl error::Error for Error {
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
}
impl Display for Error { impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
@ -133,13 +128,13 @@ impl BlockFilter {
} }
/// match any query pattern /// match any query pattern
pub fn match_any(&self, block_hash: &BlockHash, query: &mut Iterator<Item=&[u8]>) -> Result<bool, Error> { pub fn match_any(&self, block_hash: &BlockHash, query: &mut dyn Iterator<Item=&[u8]>) -> Result<bool, Error> {
let filter_reader = BlockFilterReader::new(block_hash); let filter_reader = BlockFilterReader::new(block_hash);
filter_reader.match_any(&mut Cursor::new(self.content.as_slice()), query) filter_reader.match_any(&mut Cursor::new(self.content.as_slice()), query)
} }
/// match all query pattern /// match all query pattern
pub fn match_all(&self, block_hash: &BlockHash, query: &mut Iterator<Item=&[u8]>) -> Result<bool, Error> { pub fn match_all(&self, block_hash: &BlockHash, query: &mut dyn Iterator<Item=&[u8]>) -> Result<bool, Error> {
let filter_reader = BlockFilterReader::new(block_hash); let filter_reader = BlockFilterReader::new(block_hash);
filter_reader.match_all(&mut Cursor::new(self.content.as_slice()), query) filter_reader.match_all(&mut Cursor::new(self.content.as_slice()), query)
} }
@ -153,7 +148,7 @@ pub struct BlockFilterWriter<'a> {
impl<'a> BlockFilterWriter<'a> { impl<'a> BlockFilterWriter<'a> {
/// Create a block filter writer /// Create a block filter writer
pub fn new(writer: &'a mut io::Write, block: &'a Block) -> BlockFilterWriter<'a> { pub fn new(writer: &'a mut dyn io::Write, block: &'a Block) -> BlockFilterWriter<'a> {
let block_hash_as_int = block.block_hash().into_inner(); let block_hash_as_int = block.block_hash().into_inner();
let k0 = endian::slice_to_u64_le(&block_hash_as_int[0..8]); let k0 = endian::slice_to_u64_le(&block_hash_as_int[0..8]);
let k1 = endian::slice_to_u64_le(&block_hash_as_int[8..16]); let k1 = endian::slice_to_u64_le(&block_hash_as_int[8..16]);
@ -214,12 +209,12 @@ impl BlockFilterReader {
} }
/// match any query pattern /// match any query pattern
pub fn match_any(&self, reader: &mut io::Read, query: &mut Iterator<Item=&[u8]>) -> Result<bool, Error> { pub fn match_any(&self, reader: &mut dyn io::Read, query: &mut dyn Iterator<Item=&[u8]>) -> Result<bool, Error> {
self.reader.match_any(reader, query) self.reader.match_any(reader, query)
} }
/// match all query pattern /// match all query pattern
pub fn match_all(&self, reader: &mut io::Read, query: &mut Iterator<Item=&[u8]>) -> Result<bool, Error> { pub fn match_all(&self, reader: &mut dyn io::Read, query: &mut dyn Iterator<Item=&[u8]>) -> Result<bool, Error> {
self.reader.match_all(reader, query) self.reader.match_all(reader, query)
} }
} }
@ -238,7 +233,7 @@ impl GCSFilterReader {
} }
/// match any query pattern /// match any query pattern
pub fn match_any(&self, reader: &mut io::Read, query: &mut Iterator<Item=&[u8]>) -> Result<bool, Error> { pub fn match_any(&self, reader: &mut dyn io::Read, query: &mut dyn Iterator<Item=&[u8]>) -> Result<bool, Error> {
let mut decoder = reader; let mut decoder = reader;
let n_elements: VarInt = Decodable::consensus_decode(&mut decoder).unwrap_or(VarInt(0)); let n_elements: VarInt = Decodable::consensus_decode(&mut decoder).unwrap_or(VarInt(0));
let reader = &mut decoder; let reader = &mut decoder;
@ -278,7 +273,7 @@ impl GCSFilterReader {
} }
/// match all query pattern /// match all query pattern
pub fn match_all(&self, reader: &mut io::Read, query: &mut Iterator<Item=&[u8]>) -> Result<bool, Error> { pub fn match_all(&self, reader: &mut dyn io::Read, query: &mut dyn Iterator<Item=&[u8]>) -> Result<bool, Error> {
let mut decoder = reader; let mut decoder = reader;
let n_elements: VarInt = Decodable::consensus_decode(&mut decoder).unwrap_or(VarInt(0)); let n_elements: VarInt = Decodable::consensus_decode(&mut decoder).unwrap_or(VarInt(0));
let reader = &mut decoder; let reader = &mut decoder;
@ -340,14 +335,14 @@ fn map_to_range(hash: u64, nm: u64) -> u64 {
/// Colomb-Rice encoded filter writer /// Colomb-Rice encoded filter writer
pub struct GCSFilterWriter<'a> { pub struct GCSFilterWriter<'a> {
filter: GCSFilter, filter: GCSFilter,
writer: &'a mut io::Write, writer: &'a mut dyn io::Write,
elements: HashSet<Vec<u8>>, elements: HashSet<Vec<u8>>,
m: u64 m: u64
} }
impl<'a> GCSFilterWriter<'a> { impl<'a> GCSFilterWriter<'a> {
/// Create a new GCS writer wrapping a generic writer, with specific seed to siphash /// Create a new GCS writer wrapping a generic writer, with specific seed to siphash
pub fn new(writer: &'a mut io::Write, k0: u64, k1: u64, m: u64, p: u8) -> GCSFilterWriter<'a> { pub fn new(writer: &'a mut dyn io::Write, k0: u64, k1: u64, m: u64, p: u8) -> GCSFilterWriter<'a> {
GCSFilterWriter { GCSFilterWriter {
filter: GCSFilter::new(k0, k1, p), filter: GCSFilter::new(k0, k1, p),
writer, writer,
@ -436,12 +431,12 @@ impl GCSFilter {
pub struct BitStreamReader<'a> { pub struct BitStreamReader<'a> {
buffer: [u8; 1], buffer: [u8; 1],
offset: u8, offset: u8,
reader: &'a mut io::Read, reader: &'a mut dyn io::Read,
} }
impl<'a> BitStreamReader<'a> { impl<'a> BitStreamReader<'a> {
/// Create a new BitStreamReader that reads bitwise from a given reader /// Create a new BitStreamReader that reads bitwise from a given reader
pub fn new(reader: &'a mut io::Read) -> BitStreamReader { pub fn new(reader: &'a mut dyn io::Read) -> BitStreamReader {
BitStreamReader { BitStreamReader {
buffer: [0u8], buffer: [0u8],
reader: reader, reader: reader,
@ -474,12 +469,12 @@ impl<'a> BitStreamReader<'a> {
pub struct BitStreamWriter<'a> { pub struct BitStreamWriter<'a> {
buffer: [u8; 1], buffer: [u8; 1],
offset: u8, offset: u8,
writer: &'a mut io::Write, writer: &'a mut dyn io::Write,
} }
impl<'a> BitStreamWriter<'a> { impl<'a> BitStreamWriter<'a> {
/// Create a new BitStreamWriter that writes bitwise to a given writer /// Create a new BitStreamWriter that writes bitwise to a given writer
pub fn new(writer: &'a mut io::Write) -> BitStreamWriter { pub fn new(writer: &'a mut dyn io::Write) -> BitStreamWriter {
BitStreamWriter { BitStreamWriter {
buffer: [0u8], buffer: [0u8],
writer: writer, writer: writer,
@ -528,7 +523,6 @@ mod test {
use super::*; use super::*;
extern crate hex;
extern crate serde_json; extern crate serde_json;
use self::serde_json::{Value}; use self::serde_json::{Value};
@ -557,18 +551,18 @@ mod test {
let testdata = serde_json::from_str::<Value>(data).unwrap().as_array().unwrap().clone(); let testdata = serde_json::from_str::<Value>(data).unwrap().as_array().unwrap().clone();
for t in testdata.iter().skip(1) { for t in testdata.iter().skip(1) {
let block_hash = BlockHash::from_hex(&t.get(1).unwrap().as_str().unwrap()).unwrap(); let block_hash = BlockHash::from_hex(&t.get(1).unwrap().as_str().unwrap()).unwrap();
let block: Block = deserialize(hex::decode(&t.get(2).unwrap().as_str().unwrap().as_bytes()).unwrap().as_slice()).unwrap(); let block: Block = deserialize(&Vec::from_hex(&t.get(2).unwrap().as_str().unwrap()).unwrap()).unwrap();
assert_eq!(block.block_hash(), block_hash); assert_eq!(block.block_hash(), block_hash);
let scripts = t.get(3).unwrap().as_array().unwrap(); let scripts = t.get(3).unwrap().as_array().unwrap();
let previous_filter_id = FilterHash::from_hex(&t.get(4).unwrap().as_str().unwrap()).unwrap(); let previous_filter_id = FilterHash::from_hex(&t.get(4).unwrap().as_str().unwrap()).unwrap();
let filter_content = hex::decode(&t.get(5).unwrap().as_str().unwrap().as_bytes()).unwrap(); let filter_content = Vec::from_hex(&t.get(5).unwrap().as_str().unwrap()).unwrap();
let filter_id = FilterHash::from_hex(&t.get(6).unwrap().as_str().unwrap()).unwrap(); let filter_id = FilterHash::from_hex(&t.get(6).unwrap().as_str().unwrap()).unwrap();
let mut txmap = HashMap::new(); let mut txmap = HashMap::new();
let mut si = scripts.iter(); let mut si = scripts.iter();
for tx in block.txdata.iter().skip(1) { for tx in block.txdata.iter().skip(1) {
for input in tx.input.iter() { for input in tx.input.iter() {
txmap.insert(input.previous_output.clone(), Script::from(hex::decode(si.next().unwrap().as_str().unwrap()).unwrap())); txmap.insert(input.previous_output.clone(), Script::from(Vec::from_hex(si.next().unwrap().as_str().unwrap()).unwrap()));
} }
} }
@ -603,22 +597,22 @@ mod test {
fn test_filter () { fn test_filter () {
let mut patterns = HashSet::new(); let mut patterns = HashSet::new();
patterns.insert(hex::decode("000000").unwrap()); patterns.insert(Vec::from_hex("000000").unwrap());
patterns.insert(hex::decode("111111").unwrap()); patterns.insert(Vec::from_hex("111111").unwrap());
patterns.insert(hex::decode("222222").unwrap()); patterns.insert(Vec::from_hex("222222").unwrap());
patterns.insert(hex::decode("333333").unwrap()); patterns.insert(Vec::from_hex("333333").unwrap());
patterns.insert(hex::decode("444444").unwrap()); patterns.insert(Vec::from_hex("444444").unwrap());
patterns.insert(hex::decode("555555").unwrap()); patterns.insert(Vec::from_hex("555555").unwrap());
patterns.insert(hex::decode("666666").unwrap()); patterns.insert(Vec::from_hex("666666").unwrap());
patterns.insert(hex::decode("777777").unwrap()); patterns.insert(Vec::from_hex("777777").unwrap());
patterns.insert(hex::decode("888888").unwrap()); patterns.insert(Vec::from_hex("888888").unwrap());
patterns.insert(hex::decode("999999").unwrap()); patterns.insert(Vec::from_hex("999999").unwrap());
patterns.insert(hex::decode("aaaaaa").unwrap()); patterns.insert(Vec::from_hex("aaaaaa").unwrap());
patterns.insert(hex::decode("bbbbbb").unwrap()); patterns.insert(Vec::from_hex("bbbbbb").unwrap());
patterns.insert(hex::decode("cccccc").unwrap()); patterns.insert(Vec::from_hex("cccccc").unwrap());
patterns.insert(hex::decode("dddddd").unwrap()); patterns.insert(Vec::from_hex("dddddd").unwrap());
patterns.insert(hex::decode("eeeeee").unwrap()); patterns.insert(Vec::from_hex("eeeeee").unwrap());
patterns.insert(hex::decode("ffffff").unwrap()); patterns.insert(Vec::from_hex("ffffff").unwrap());
let mut out = Cursor::new(Vec::new()); let mut out = Cursor::new(Vec::new());
{ {
@ -633,8 +627,8 @@ mod test {
{ {
let mut query = Vec::new(); let mut query = Vec::new();
query.push(hex::decode("abcdef").unwrap()); query.push(Vec::from_hex("abcdef").unwrap());
query.push(hex::decode("eeeeee").unwrap()); query.push(Vec::from_hex("eeeeee").unwrap());
let reader = GCSFilterReader::new(0, 0, M, P); let reader = GCSFilterReader::new(0, 0, M, P);
let mut input = Cursor::new(bytes.clone()); let mut input = Cursor::new(bytes.clone());
@ -642,8 +636,8 @@ mod test {
} }
{ {
let mut query = Vec::new(); let mut query = Vec::new();
query.push(hex::decode("abcdef").unwrap()); query.push(Vec::from_hex("abcdef").unwrap());
query.push(hex::decode("123456").unwrap()); query.push(Vec::from_hex("123456").unwrap());
let reader = GCSFilterReader::new(0, 0, M, P); let reader = GCSFilterReader::new(0, 0, M, P);
let mut input = Cursor::new(bytes.clone()); let mut input = Cursor::new(bytes.clone());
@ -664,7 +658,7 @@ mod test {
for p in &patterns { for p in &patterns {
query.push(p.clone()); query.push(p.clone());
} }
query.push(hex::decode("abcdef").unwrap()); query.push(Vec::from_hex("abcdef").unwrap());
let mut input = Cursor::new(bytes.clone()); let mut input = Cursor::new(bytes.clone());
assert!(!reader.match_all(&mut input, &mut query.iter().map(|v| v.as_slice())).unwrap()); assert!(!reader.match_all(&mut input, &mut query.iter().map(|v| v.as_slice())).unwrap());
} }

View File

@ -404,17 +404,13 @@ impl fmt::Display for Error {
} }
impl error::Error for Error { impl error::Error for Error {
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
if let Error::Ecdsa(ref e) = *self { if let Error::Ecdsa(ref e) = *self {
Some(e) Some(e)
} else { } else {
None None
} }
} }
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
} }
impl From<secp256k1::Error> for Error { impl From<secp256k1::Error> for Error {

View File

@ -71,19 +71,14 @@ impl fmt::Display for Error {
} }
} }
#[allow(deprecated)]
impl error::Error for Error { impl error::Error for Error {
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
Error::Secp(ref e) => Some(e), Error::Secp(ref e) => Some(e),
Error::Script(ref e) => Some(e), Error::Script(ref e) => Some(e),
_ => None _ => None
} }
} }
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
} }
/// An element of a script template /// An element of a script template

View File

@ -60,7 +60,7 @@ pub fn bitcoin_merkle_root<T, I>(mut iter: I) -> T
return Default::default(); return Default::default();
} }
if iter.len() == 1 { if iter.len() == 1 {
return T::from_inner(iter.nth(0).unwrap().into_inner()); return T::from_inner(iter.next().unwrap().into_inner());
} }
// Recursion // Recursion
let half_len = iter.len() / 2 + iter.len() % 2; let half_len = iter.len() / 2 + iter.len() % 2;

View File

@ -46,16 +46,12 @@ impl fmt::Display for Error {
} }
impl error::Error for Error { impl error::Error for Error {
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
Error::Base58(ref e) => Some(e), Error::Base58(ref e) => Some(e),
Error::Secp256k1(ref e) => Some(e), Error::Secp256k1(ref e) => Some(e),
} }
} }
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
} }
#[doc(hidden)] #[doc(hidden)]
@ -193,7 +189,7 @@ impl PrivateKey {
} }
/// Format the private key to WIF format. /// Format the private key to WIF format.
pub fn fmt_wif(&self, fmt: &mut fmt::Write) -> fmt::Result { pub fn fmt_wif(&self, fmt: &mut dyn fmt::Write) -> fmt::Result {
let mut ret = [0; 34]; let mut ret = [0; 34];
ret[0] = match self.network { ret[0] = match self.network {
Network::Bitcoin => 128, Network::Bitcoin => 128,

View File

@ -445,7 +445,7 @@ impl MerkleBlock {
match_txids: &HashSet<Txid>, match_txids: &HashSet<Txid>,
) -> Self { ) -> Self {
let matches: Vec<bool> = block_txids let matches: Vec<bool> = block_txids
.into_iter() .iter()
.map(|txid| match_txids.contains(txid)) .map(|txid| match_txids.contains(txid))
.collect(); .collect();

View File

@ -83,19 +83,14 @@ impl fmt::Display for Error {
} }
} }
#[allow(deprecated)]
impl error::Error for Error { impl error::Error for Error {
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
Error::Encode(ref e) => Some(e), Error::Encode(ref e) => Some(e),
Error::Network(ref e) => Some(e), Error::Network(ref e) => Some(e),
Error::BlockBadProofOfWork | Error::BlockBadTarget => None Error::BlockBadProofOfWork | Error::BlockBadTarget => None
} }
} }
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
} }
#[doc(hidden)] #[doc(hidden)]

View File

@ -69,9 +69,4 @@ impl fmt::Display for Error {
} }
} }
#[allow(deprecated)] impl error::Error for Error {}
impl error::Error for Error {
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
}