diff --git a/examples/n2c-miniprotocols/src/main.rs b/examples/n2c-miniprotocols/src/main.rs index 4c6c00b..ed1f139 100644 --- a/examples/n2c-miniprotocols/src/main.rs +++ b/examples/n2c-miniprotocols/src/main.rs @@ -5,7 +5,7 @@ use pallas::{ miniprotocols::{ chainsync, localstate::queries_v16::{self, Addr, Addrs}, - Point, PRE_PRODUCTION_MAGIC, PREVIEW_MAGIC + Point, PRE_PRODUCTION_MAGIC, }, }, }; @@ -81,8 +81,8 @@ async fn do_chainsync(client: &mut NodeClient) { // change the following to match the Cardano node socket in your local // environment +#[cfg(unix)] const SOCKET_PATH: &str = "/tmp/node.socket"; -const PIPE_NAME: &str = "\\\\.\\pipe\\cardano-pallas"; #[cfg(unix)] #[tokio::main] @@ -107,10 +107,14 @@ async fn main() { do_chainsync(&mut client).await; } +// change the following to match the Cardano node named-pipe in your local +// environment +#[cfg(target_family = "windows")] +const PIPE_NAME: &str = "\\\\.\\pipe\\cardano-pallas"; + #[cfg(target_family = "windows")] #[tokio::main] async fn main() { - tracing::subscriber::set_global_default( tracing_subscriber::FmtSubscriber::builder() .with_max_level(tracing::Level::TRACE) @@ -118,9 +122,9 @@ async fn main() { ) .unwrap(); - // we connect to the namedpipe of the local node. Make sure you have the right + // we connect to the named-pipe of the local node. Make sure you have the right // path for your environment - let mut client = NodeClient::connect(PIPE_NAME, PREVIEW_MAGIC) + let mut client = NodeClient::connect(PIPE_NAME, PRE_PRODUCTION_MAGIC) .await .unwrap(); diff --git a/pallas-hardano/src/storage/immutable/mod.rs b/pallas-hardano/src/storage/immutable/mod.rs index 31d0185..3fd9ce1 100644 --- a/pallas-hardano/src/storage/immutable/mod.rs +++ b/pallas-hardano/src/storage/immutable/mod.rs @@ -4,7 +4,6 @@ use std::{ path::{Path, PathBuf}, }; -use pallas_network::miniprotocols::Point; use pallas_traverse::MultiEraBlock; use tap::Tap; use thiserror::Error; @@ -14,6 +13,10 @@ pub mod chunk; pub mod primary; pub mod secondary; +// TODO: we should make Point accessible in some crate more generic that +// `network`. +pub type Point = pallas_network::miniprotocols::Point; + #[derive(Debug, Error, PartialEq, Eq)] pub enum Error { #[error("Cannot find block by the provided point: {0:?}")] @@ -164,10 +167,10 @@ pub fn read_blocks(dir: &Path) -> Result, st /// /// # Example /// -/// ```rust +/// ```no_run /// use std::path::Path; /// use std::error::Error; -/// use crate::{Point, read_blocks_from_point}; +/// use pallas_hardano::storage::immutable::{Point, read_blocks_from_point}; /// /// fn main() -> Result<(), Box> { /// let dir = Path::new("/path/to/blocks"); @@ -211,7 +214,7 @@ pub fn read_blocks_from_point( // check the first block match iter.peek() { Some(Ok(block_data)) => { - let block = MultiEraBlock::decode(&block_data)?; + let block = MultiEraBlock::decode(block_data)?; // check that the first block is genesis if block.slot() == 0 && block.number() == 0 { Ok(Box::new(iter)) @@ -229,7 +232,7 @@ pub fn read_blocks_from_point( // and compares block's slot with provided slot number let cmp = { |chunk_name: &String, point: &u64| { - let mut blocks = chunk::read_blocks(dir, &chunk_name)?; + let mut blocks = chunk::read_blocks(dir, chunk_name)?; // Try to read the first block from the chunk if let Some(block_data) = blocks.next() { @@ -275,10 +278,10 @@ pub fn read_blocks_from_point( /// /// # Example /// -/// ```rust +/// ```no_run /// use std::path::Path; /// use std::error::Error; -/// use crate::{Point, get_tip}; +/// use pallas_hardano::storage::immutable::{Point, get_tip}; /// /// fn main() -> Result<(), Box> { /// let dir = Path::new("/path/to/blocks"); diff --git a/pallas-network/src/facades.rs b/pallas-network/src/facades.rs index 04247ff..cec5992 100644 --- a/pallas-network/src/facades.rs +++ b/pallas-network/src/facades.rs @@ -262,12 +262,10 @@ impl NodeClient { ) -> Result { let pipe_name = pipe_name.as_ref().to_os_string(); - let bearer = tokio::task::spawn_blocking(move || { - Bearer::connect_named_pipe(pipe_name) - }) - .await - .expect("can't join tokio thread") - .map_err(Error::ConnectFailure)?; + let bearer = tokio::task::spawn_blocking(move || Bearer::connect_named_pipe(pipe_name)) + .await + .expect("can't join tokio thread") + .map_err(Error::ConnectFailure)?; let mut client = Self::new(bearer); diff --git a/pallas-network/src/miniprotocols/blockfetch/mod.rs b/pallas-network/src/miniprotocols/blockfetch/mod.rs index 26cb050..aa26a90 100644 --- a/pallas-network/src/miniprotocols/blockfetch/mod.rs +++ b/pallas-network/src/miniprotocols/blockfetch/mod.rs @@ -6,6 +6,5 @@ mod protocol; mod server; pub use client::*; -pub use codec::*; pub use protocol::*; pub use server::*; diff --git a/pallas-network/src/miniprotocols/chainsync/mod.rs b/pallas-network/src/miniprotocols/chainsync/mod.rs index 6b732fe..4f93c2f 100644 --- a/pallas-network/src/miniprotocols/chainsync/mod.rs +++ b/pallas-network/src/miniprotocols/chainsync/mod.rs @@ -6,6 +6,5 @@ mod server; pub use buffer::*; pub use client::*; -pub use codec::*; pub use protocol::*; pub use server::*; diff --git a/pallas-network/src/miniprotocols/keepalive/mod.rs b/pallas-network/src/miniprotocols/keepalive/mod.rs index a9eaa04..9bbd8cc 100644 --- a/pallas-network/src/miniprotocols/keepalive/mod.rs +++ b/pallas-network/src/miniprotocols/keepalive/mod.rs @@ -3,5 +3,4 @@ mod codec; mod protocol; pub use client::*; -pub use codec::*; pub use protocol::*; diff --git a/pallas-network/src/miniprotocols/localstate/mod.rs b/pallas-network/src/miniprotocols/localstate/mod.rs index 2485b17..2fdad28 100644 --- a/pallas-network/src/miniprotocols/localstate/mod.rs +++ b/pallas-network/src/miniprotocols/localstate/mod.rs @@ -6,6 +6,5 @@ mod server; pub mod queries_v16; pub use client::*; -pub use codec::*; pub use protocol::*; pub use server::*; diff --git a/pallas-network/src/miniprotocols/localtxsubmission/mod.rs b/pallas-network/src/miniprotocols/localtxsubmission/mod.rs index a9d1658..73e980a 100644 --- a/pallas-network/src/miniprotocols/localtxsubmission/mod.rs +++ b/pallas-network/src/miniprotocols/localtxsubmission/mod.rs @@ -1,5 +1,4 @@ pub use client::*; -pub use codec::*; pub use protocol::*; mod client; diff --git a/pallas-network/src/miniprotocols/txmonitor/mod.rs b/pallas-network/src/miniprotocols/txmonitor/mod.rs index a9eaa04..9bbd8cc 100644 --- a/pallas-network/src/miniprotocols/txmonitor/mod.rs +++ b/pallas-network/src/miniprotocols/txmonitor/mod.rs @@ -3,5 +3,4 @@ mod codec; mod protocol; pub use client::*; -pub use codec::*; pub use protocol::*; diff --git a/pallas-network/src/miniprotocols/txsubmission/mod.rs b/pallas-network/src/miniprotocols/txsubmission/mod.rs index 93821a7..bc68dde 100644 --- a/pallas-network/src/miniprotocols/txsubmission/mod.rs +++ b/pallas-network/src/miniprotocols/txsubmission/mod.rs @@ -4,6 +4,5 @@ mod protocol; mod server; pub use client::*; -pub use codec::*; pub use protocol::*; pub use server::*; diff --git a/pallas-network/src/multiplexer.rs b/pallas-network/src/multiplexer.rs index 1fa34ff..506c1ff 100644 --- a/pallas-network/src/multiplexer.rs +++ b/pallas-network/src/multiplexer.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use byteorder::{ByteOrder, NetworkEndian}; use pallas_codec::{minicbor, Fragment}; use thiserror::Error; -use tokio::io::{AsyncReadExt, AsyncWriteExt, ReadHalf, WriteHalf}; +use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::task::JoinHandle; use tokio::time::Instant; use tokio::{select, sync::mpsc::error::SendError}; @@ -21,6 +21,9 @@ use tokio::net as unix; #[cfg(windows)] use tokio::net::windows::named_pipe::NamedPipeClient; +#[cfg(windows)] +use tokio::io::{ReadHalf, WriteHalf}; + const HEADER_LEN: usize = 8; pub type Timestamp = u32; @@ -126,9 +129,8 @@ impl Bearer { } #[cfg(windows)] - pub fn connect_named_pipe(pipe_name: impl AsRef) -> - IOResult { let client = - tokio::net::windows::named_pipe::ClientOptions::new().open(&pipe_name)?; + pub fn connect_named_pipe(pipe_name: impl AsRef) -> IOResult { + let client = tokio::net::windows::named_pipe::ClientOptions::new().open(&pipe_name)?; Ok(Self::NamedPipe(client)) } @@ -174,7 +176,7 @@ impl BearerReadHalf { #[cfg(unix)] BearerReadHalf::Unix(x) => x.read_exact(buf).await, - + #[cfg(windows)] BearerReadHalf::NamedPipe(x) => x.read_exact(buf).await, } diff --git a/pallas-wallet/src/lib.rs b/pallas-wallet/src/lib.rs index e472678..49fe2c9 100644 --- a/pallas-wallet/src/lib.rs +++ b/pallas-wallet/src/lib.rs @@ -1,4 +1,3 @@ -use ed25519_bip32; use pallas_crypto::key::ed25519::{PublicKey, SecretKey, SecretKeyExtended, Signature}; use thiserror::Error; @@ -40,6 +39,7 @@ pub enum PrivateKey { } impl PrivateKey { + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { match self { Self::Normal(_) => SecretKey::SIZE,