Skip to content

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumplation committed Apr 16, 2024
1 parent b6fdda7 commit 8b3fb45
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 26 deletions.
10 changes: 6 additions & 4 deletions pallas-network/src/facades.rs
Expand Up @@ -4,14 +4,14 @@ use thiserror::Error;
use tokio::task::JoinHandle;
use tracing::{debug, error};

use crate::miniprotocols::handshake::Confirmation;
use crate::{
miniprotocols::{
blockfetch, chainsync, handshake, localstate, PROTOCOL_N2C_CHAIN_SYNC,
PROTOCOL_N2C_HANDSHAKE, PROTOCOL_N2C_STATE_QUERY,
},
multiplexer::{self, Bearer},
};
use crate::miniprotocols::handshake::Confirmation;

#[derive(Debug, Error)]
pub enum Error {
Expand Down Expand Up @@ -89,8 +89,7 @@ pub struct NodeClient {
}

impl NodeClient {

#[cfg(not(target_os = "windows"))]
#[cfg(not(target_os = "windows"))]
pub async fn connect(path: impl AsRef<Path>, magic: u64) -> Result<Self, Error> {
debug!("connecting");

Expand Down Expand Up @@ -128,7 +127,10 @@ impl NodeClient {
}

#[cfg(not(target_os = "windows"))]
pub async fn handshake_query(path: impl AsRef<Path>, magic: u64) -> Result<handshake::n2c::VersionTable, Error> {
pub async fn handshake_query(
path: impl AsRef<Path>,
magic: u64,
) -> Result<handshake::n2c::VersionTable, Error> {
debug!("connecting");

let bearer = Bearer::connect_unix(path)
Expand Down
7 changes: 4 additions & 3 deletions pallas-network/src/miniprotocols/chainsync/client.rs
Expand Up @@ -277,10 +277,11 @@ where
}

/// Either requests the next block, or waits for one to become available.
///
///
/// # Errors
///
/// Returns an error if the message cannot be sent, or if the inbound message is invalid
///
/// Returns an error if the message cannot be sent, or if the inbound
/// message is invalid
pub async fn request_or_await_next(&mut self) -> Result<NextResponse<O>, Error> {
if self.has_agency() {
self.request_next().await
Expand Down
2 changes: 1 addition & 1 deletion pallas-network/src/miniprotocols/handshake/client.rs
@@ -1,5 +1,5 @@
use std::fmt::Debug;
use pallas_codec::Fragment;
use std::fmt::Debug;
use std::marker::PhantomData;
use tracing::debug;

Expand Down
18 changes: 8 additions & 10 deletions pallas-network/src/miniprotocols/handshake/n2c.rs
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use pallas_codec::minicbor::{decode, Decode, Decoder, encode, Encode, Encoder};
use pallas_codec::minicbor::data::Type;
use pallas_codec::minicbor::{decode, encode, Decode, Decoder, Encode, Encoder};

use super::protocol::NetworkMagic;

Expand Down Expand Up @@ -72,11 +72,9 @@ impl VersionTable {
}

pub fn v15_with_query(network_magic: u64) -> VersionTable {
let values = vec![
(PROTOCOL_V15, VersionData(network_magic, Some(true))),
]
.into_iter()
.collect::<HashMap<u64, VersionData>>();
let values = vec![(PROTOCOL_V15, VersionData(network_magic, Some(true)))]
.into_iter()
.collect::<HashMap<u64, VersionData>>();

VersionTable { values }
}
Expand All @@ -92,7 +90,9 @@ impl Encode<()> for VersionData {
_ctx: &mut (),
) -> Result<(), encode::Error<W::Error>> {
match self.1 {
None => { e.u64(self.0)?; }
None => {
e.u64(self.0)?;
}
Some(is_query) => {
e.array(2)?;
e.u64(self.0)?;
Expand All @@ -117,9 +117,7 @@ impl<'b> Decode<'b, ()> for VersionData {
let is_query = d.bool()?;
Ok(Self(network_magic, Some(is_query)))
}
_ => Err(decode::Error::message(
"unknown type for VersionData",
)),
_ => Err(decode::Error::message("unknown type for VersionData")),
}
}
}
4 changes: 3 additions & 1 deletion pallas-network/src/miniprotocols/handshake/protocol.rs
Expand Up @@ -56,7 +56,9 @@ where
T: Debug + Clone + Decode<'b, ()>,
{
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
let len = d.map()?.ok_or(decode::Error::message("expected def-length map for versiontable"))?;
let len = d.map()?.ok_or(decode::Error::message(
"expected def-length map for versiontable",
))?;
let mut values = HashMap::new();

for _ in 0..len {
Expand Down
14 changes: 7 additions & 7 deletions pallas-network/src/multiplexer.rs
Expand Up @@ -12,7 +12,7 @@ use tokio::sync::mpsc::error::SendError;
use tokio::time::Instant;
use tracing::{debug, error, trace};

#[cfg(not(target_os = "windows"))]
#[cfg(not(target_os = "windows"))]
use tokio::net::UnixStream;

const HEADER_LEN: usize = 8;
Expand Down Expand Up @@ -62,7 +62,7 @@ pub struct Segment {

#[cfg(target_os = "windows")]
pub enum Bearer {
Tcp(TcpStream)
Tcp(TcpStream),
}

#[cfg(not(target_os = "windows"))]
Expand All @@ -84,7 +84,7 @@ impl Bearer {
Ok((Self::Tcp(stream), addr))
}

#[cfg(not(target_os = "windows"))]
#[cfg(not(target_os = "windows"))]
pub async fn connect_unix(path: impl AsRef<Path>) -> Result<Self, tokio::io::Error> {
let stream = UnixStream::connect(path).await?;
Ok(Self::Unix(stream))
Expand All @@ -93,31 +93,31 @@ impl Bearer {
pub async fn readable(&self) -> tokio::io::Result<()> {
match self {
Bearer::Tcp(x) => x.readable().await,
#[cfg(not(target_os = "windows"))]
#[cfg(not(target_os = "windows"))]
Bearer::Unix(x) => x.readable().await,
}
}

fn try_read(&mut self, buf: &mut [u8]) -> tokio::io::Result<usize> {
match self {
Bearer::Tcp(x) => x.try_read(buf),
#[cfg(not(target_os = "windows"))]
#[cfg(not(target_os = "windows"))]
Bearer::Unix(x) => x.try_read(buf),
}
}

async fn write_all(&mut self, buf: &[u8]) -> tokio::io::Result<()> {
match self {
Bearer::Tcp(x) => x.write_all(buf).await,
#[cfg(not(target_os = "windows"))]
#[cfg(not(target_os = "windows"))]
Bearer::Unix(x) => x.write_all(buf).await,
}
}

async fn flush(&mut self) -> tokio::io::Result<()> {
match self {
Bearer::Tcp(x) => x.flush().await,
#[cfg(not(target_os = "windows"))]
#[cfg(not(target_os = "windows"))]
Bearer::Unix(x) => x.flush().await,
}
}
Expand Down
16 changes: 16 additions & 0 deletions pallas-primitives/src/alonzo/model.rs
Expand Up @@ -3,6 +3,7 @@
//! Handcrafted, idiomatic rust artifacts based on based on the [Alonzo CDDL](https://github.com/input-output-hk/cardano-ledger/blob/master/eras/alonzo/test-suite/cddl-files/alonzo.cddl) file in IOHK repo.

use serde::{Deserialize, Serialize};
use std::fmt::Display;
use std::{fmt, ops::Deref};

use pallas_codec::minicbor::{data::Tag, Decode, Encode};
Expand Down Expand Up @@ -1001,6 +1002,21 @@ impl<C> minicbor::encode::Encode<C> for BigInt {
}
}

impl Display for BigInt {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BigInt::Int(n) => n.fmt(f),
BigInt::BigUInt(bytes) | BigInt::BigNInt(bytes) => {
let mut s: String = String::new();
let mut carry = 0;
for b in bytes.0.reverse() {}

Check failure on line 1012 in pallas-primitives/src/alonzo/model.rs

View workflow job for this annotation

GitHub Actions / Test Suite

`()` is not an iterator

Check failure on line 1012 in pallas-primitives/src/alonzo/model.rs

View workflow job for this annotation

GitHub Actions / Check

`()` is not an iterator

Check failure on line 1012 in pallas-primitives/src/alonzo/model.rs

View workflow job for this annotation

GitHub Actions / Lints

`()` is not an iterator
s.insert_str(0, "");
write!(f, "{}", s)
}
}
}
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
pub enum PlutusData {
Constr(Constr<PlutusData>),
Expand Down

0 comments on commit 8b3fb45

Please sign in to comment.