fix last warnings

This commit is contained in:
Jane Lusby 2020-05-27 10:27:26 -07:00 committed by Deirdre Connolly
parent b6b35364f3
commit 4dc307f2f3
4 changed files with 45 additions and 44 deletions

View File

@ -292,6 +292,7 @@ pub trait ReadZcashExt: io::Read {
impl<R: io::Read + ?Sized> ReadZcashExt for R {} impl<R: io::Read + ?Sized> ReadZcashExt for R {}
#[cfg(test)] #[cfg(test)]
#[allow(clippy::unnecessary_operation)]
mod tests { mod tests {
use super::*; use super::*;
use proptest::prelude::*; use proptest::prelude::*;
@ -321,7 +322,7 @@ mod tests {
// copy the input bytes, and overwrite them with the encoding of s, // copy the input bytes, and overwrite them with the encoding of s,
// so that if the encoding is different, we'll catch it on the part // so that if the encoding is different, we'll catch it on the part
// that's written. // that's written.
let mut expect_bytes = bytes.clone(); let mut expect_bytes = bytes;
Cursor::new(&mut expect_bytes[..]).write_compactsize(s).unwrap(); Cursor::new(&mut expect_bytes[..]).write_compactsize(s).unwrap();
prop_assert_eq!(bytes, expect_bytes); prop_assert_eq!(bytes, expect_bytes);
} }

View File

@ -65,6 +65,7 @@ pub use crate::{
peer_set::init, peer_set::init,
policies::{RetryErrors, RetryLimit}, policies::{RetryErrors, RetryLimit},
protocol::internal::{Request, Response}, protocol::internal::{Request, Response},
protocol::external::codec::Builder,
}; };
/// Types used in the definition of [`Request`] and [`Response`] messages. /// Types used in the definition of [`Request`] and [`Response`] messages.

View File

@ -1,5 +1,5 @@
/// A Tokio codec that transforms an `AsyncRead` into a `Stream` of `Message`s. /// A Tokio codec that transforms an `AsyncRead` into a `Stream` of `Message`s.
mod codec; pub mod codec;
/// Inventory items. /// Inventory items.
mod inv; mod inv;
/// An enum of all supported Bitcoin message types. /// An enum of all supported Bitcoin message types.

View File

@ -154,18 +154,17 @@ impl Codec {
/// the message body prior to writing the header, so that the header can /// the message body prior to writing the header, so that the header can
/// contain a checksum of the message body. /// contain a checksum of the message body.
fn write_body<W: Write>(&self, msg: &Message, mut writer: W) -> Result<(), Error> { fn write_body<W: Write>(&self, msg: &Message, mut writer: W) -> Result<(), Error> {
use Message::*; match msg {
match *msg { Message::Version {
Version { version,
ref version, services,
ref services, timestamp,
ref timestamp, address_recv,
ref address_recv, address_from,
ref address_from, nonce,
ref nonce, user_agent,
ref user_agent, start_height,
ref start_height, relay,
ref relay,
} => { } => {
writer.write_u32::<LittleEndian>(version.0)?; writer.write_u32::<LittleEndian>(version.0)?;
writer.write_u64::<LittleEndian>(services.bits())?; writer.write_u64::<LittleEndian>(services.bits())?;
@ -184,64 +183,64 @@ impl Codec {
writer.write_u32::<LittleEndian>(start_height.0)?; writer.write_u32::<LittleEndian>(start_height.0)?;
writer.write_u8(*relay as u8)?; writer.write_u8(*relay as u8)?;
} }
Verack => { /* Empty payload -- no-op */ } Message::Verack => { /* Empty payload -- no-op */ }
Ping(nonce) => { Message::Ping(nonce) => {
writer.write_u64::<LittleEndian>(nonce.0)?; writer.write_u64::<LittleEndian>(nonce.0)?;
} }
Pong(nonce) => { Message::Pong(nonce) => {
writer.write_u64::<LittleEndian>(nonce.0)?; writer.write_u64::<LittleEndian>(nonce.0)?;
} }
Reject { Message::Reject {
ref message, message,
ref ccode, ccode,
ref reason, reason,
ref data, data,
} => { } => {
writer.write_string(&message)?; writer.write_string(&message)?;
writer.write_u8(*ccode as u8)?; writer.write_u8(*ccode as u8)?;
writer.write_string(&reason)?; writer.write_string(&reason)?;
writer.write_all(&data.unwrap())?; writer.write_all(&data.unwrap())?;
} }
Addr(ref addrs) => addrs.zcash_serialize(&mut writer)?, Message::Addr(addrs) => addrs.zcash_serialize(&mut writer)?,
GetAddr => { /* Empty payload -- no-op */ } Message::GetAddr => { /* Empty payload -- no-op */ }
Block(ref block) => block.zcash_serialize(&mut writer)?, Message::Block(block) => block.zcash_serialize(&mut writer)?,
GetBlocks { Message::GetBlocks {
ref block_locator_hashes, block_locator_hashes,
ref hash_stop, hash_stop,
} => { } => {
writer.write_u32::<LittleEndian>(self.builder.version.0)?; writer.write_u32::<LittleEndian>(self.builder.version.0)?;
block_locator_hashes.zcash_serialize(&mut writer)?; block_locator_hashes.zcash_serialize(&mut writer)?;
hash_stop.zcash_serialize(&mut writer)?; hash_stop.zcash_serialize(&mut writer)?;
} }
GetHeaders { Message::GetHeaders {
ref block_locator_hashes, block_locator_hashes,
ref hash_stop, hash_stop,
} => { } => {
writer.write_u32::<LittleEndian>(self.builder.version.0)?; writer.write_u32::<LittleEndian>(self.builder.version.0)?;
block_locator_hashes.zcash_serialize(&mut writer)?; block_locator_hashes.zcash_serialize(&mut writer)?;
hash_stop.zcash_serialize(&mut writer)?; hash_stop.zcash_serialize(&mut writer)?;
} }
Headers(ref headers) => headers.zcash_serialize(&mut writer)?, Message::Headers(headers) => headers.zcash_serialize(&mut writer)?,
Inv(ref hashes) => hashes.zcash_serialize(&mut writer)?, Message::Inv(hashes) => hashes.zcash_serialize(&mut writer)?,
GetData(ref hashes) => hashes.zcash_serialize(&mut writer)?, Message::GetData(hashes) => hashes.zcash_serialize(&mut writer)?,
NotFound(ref hashes) => hashes.zcash_serialize(&mut writer)?, Message::NotFound(hashes) => hashes.zcash_serialize(&mut writer)?,
Tx(ref transaction) => transaction.zcash_serialize(&mut writer)?, Message::Tx(transaction) => transaction.zcash_serialize(&mut writer)?,
Mempool => { /* Empty payload -- no-op */ } Message::Mempool => { /* Empty payload -- no-op */ }
FilterLoad { Message::FilterLoad {
ref filter, filter,
ref hash_functions_count, hash_functions_count,
ref tweak, tweak,
ref flags, flags,
} => { } => {
writer.write_all(&filter.0)?; writer.write_all(&filter.0)?;
writer.write_u32::<LittleEndian>(*hash_functions_count)?; writer.write_u32::<LittleEndian>(*hash_functions_count)?;
writer.write_u32::<LittleEndian>(tweak.0)?; writer.write_u32::<LittleEndian>(tweak.0)?;
writer.write_u8(*flags)?; writer.write_u8(*flags)?;
} }
FilterAdd { ref data } => { Message::FilterAdd { data } => {
writer.write_all(data)?; writer.write_all(data)?;
} }
FilterClear => { /* Empty payload -- no-op */ } Message::FilterClear => { /* Empty payload -- no-op */ }
} }
Ok(()) Ok(())
} }