Skip to content

Commit

Permalink
Add import rules to rustfmt and apply (stratum-mining#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
rrybarczyk authored Mar 31, 2022
1 parent c10504c commit b62f702
Show file tree
Hide file tree
Showing 79 changed files with 471 additions and 427 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/fmt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on:
push:
branches:
- main
pull_request:
branches:
- main

name: Rustfmt

jobs:
fmt:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
include:
- os: macos-latest
target: x86_64-apple-darwin
- os: ubuntu-latest
target: x86_64-unknown-linux-musl

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
profile: minimal
toolchain: 1.53.0
override: true
components: rustfmt, clippy
components: clippy

- name: Build
uses: actions-rs/cargo@v1
Expand Down Expand Up @@ -59,12 +59,6 @@ jobs:
command: build
args: --manifest-path examples/sv1-client-and-server/Cargo.toml

- name: Rust fmt lint
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

- name: Cargo clippy lint
uses: actions-rs/cargo@v1
with:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ reviewed:

For everything else including performance an safety issues just accept the PR then amend the
problematic code and do another PR tagging the author of the amended PR.

#### Formatting
Before merging, run `cargo +nightly fmt` to properly apply the settings in `rustfmt.toml`.
21 changes: 12 additions & 9 deletions examples/interop-cpp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ mod main_ {
mod main_ {
use codec_sv2::{Encoder, Frame, StandardDecoder, StandardSv2Frame};
use common_messages_sv2::{Protocol, SetupConnection, SetupConnectionError};
use const_sv2::CHANNEL_BIT_SETUP_CONNECTION;
use const_sv2::MESSAGE_TYPE_SETUP_CONNECTION;
use const_sv2::MESSAGE_TYPE_SETUP_CONNECTION_ERROR;
use std::convert::TryFrom;
use std::convert::TryInto;
use std::io::{Read, Write};
use std::net::TcpStream;
use const_sv2::{
CHANNEL_BIT_SETUP_CONNECTION, MESSAGE_TYPE_SETUP_CONNECTION,
MESSAGE_TYPE_SETUP_CONNECTION_ERROR,
};
use std::{
convert::{TryFrom, TryInto},
io::{Read, Write},
net::TcpStream,
};

use binary_sv2::{
decodable::DecodableField, decodable::FieldMarker, encodable::EncodableField, from_bytes,
Deserialize, Error,
decodable::{DecodableField, FieldMarker},
encodable::EncodableField,
from_bytes, Deserialize, Error,
};

#[derive(Clone, Debug)]
Expand Down
8 changes: 5 additions & 3 deletions examples/ping-pong-with-noise/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
mod messages;
mod node;
use async_std::net::{TcpListener, TcpStream};
use async_std::prelude::*;
use async_std::task;
use async_std::{
net::{TcpListener, TcpStream},
prelude::*,
task,
};
use codec_sv2::{HandshakeRole, Initiator, Responder};
use std::time;

Expand Down
4 changes: 1 addition & 3 deletions examples/ping-pong-with-noise/src/messages.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use binary_sv2::GetSize;
#[cfg(not(feature = "with_serde"))]
use binary_sv2::{binary_codec_sv2, decodable::DecodableField, decodable::FieldMarker};
use binary_sv2::{Bytes as Sv2Bytes, Seq064K, Str0255, U24, U256};
use binary_sv2::{Deserialize, Serialize};
use binary_sv2::{Bytes as Sv2Bytes, Deserialize, GetSize, Seq064K, Serialize, Str0255, U24, U256};
use rand::{distributions::Alphanumeric, Rng};
use std::convert::TryInto;

Expand Down
9 changes: 5 additions & 4 deletions examples/ping-pong-with-noise/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use rand::Rng;
use async_channel::{Receiver, Sender};
use async_std::net::TcpStream;

use async_std::sync::{Arc, Mutex};
use async_std::task;
use async_std::{
sync::{Arc, Mutex},
task,
};
use core::convert::TryInto;

use codec_sv2::Frame;
use codec_sv2::{HandshakeRole, StandardEitherFrame, StandardSv2Frame};
use codec_sv2::{Frame, HandshakeRole, StandardEitherFrame, StandardSv2Frame};

use std::time;

Expand Down
8 changes: 5 additions & 3 deletions examples/ping-pong-without-noise/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
mod messages;
mod node;
use async_std::net::{TcpListener, TcpStream};
use async_std::prelude::*;
use async_std::task;
use async_std::{
net::{TcpListener, TcpStream},
prelude::*,
task,
};
use std::time;

const ADDR: &str = "127.0.0.1:34254";
Expand Down
4 changes: 1 addition & 3 deletions examples/ping-pong-without-noise/src/messages.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use binary_sv2::GetSize;
#[cfg(not(feature = "with_serde"))]
use binary_sv2::{binary_codec_sv2, decodable::DecodableField, decodable::FieldMarker};
use binary_sv2::{Bytes as Sv2Bytes, Seq064K, Str0255, U24, U256};
use binary_sv2::{Deserialize, Serialize};
use binary_sv2::{Bytes as Sv2Bytes, Deserialize, GetSize, Seq064K, Serialize, Str0255, U24, U256};
use rand::{distributions::Alphanumeric, Rng};
use std::convert::TryInto;

Expand Down
10 changes: 6 additions & 4 deletions examples/ping-pong-without-noise/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use binary_sv2::{from_bytes, U256};
use rand::Rng;

use async_channel::{bounded, Receiver, Sender};
use async_std::net::TcpStream;
use async_std::prelude::*;
use async_std::sync::{Arc, Mutex};
use async_std::task;
use async_std::{
net::TcpStream,
prelude::*,
sync::{Arc, Mutex},
task,
};

use codec_sv2::{Frame, StandardDecoder, StandardSv2Frame};

Expand Down
15 changes: 10 additions & 5 deletions examples/sv1-client-and-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ use async_std::net::{TcpListener, TcpStream};
use std::convert::TryInto;

use async_channel::{bounded, Receiver, Sender};
use async_std::io::BufReader;
use async_std::prelude::*;
use async_std::sync::{Arc, Mutex};
use async_std::task;
use async_std::{
io::BufReader,
prelude::*,
sync::{Arc, Mutex},
task,
};
use std::time;

const ADDR: &str = "127.0.0.1:34254";

use v1::{
client_to_server, error::Error, json_rpc, server_to_client, utils::HexBytes, utils::HexU32Be,
client_to_server,
error::Error,
json_rpc, server_to_client,
utils::{HexBytes, HexU32Be},
ClientStatus, IsClient, IsServer,
};

Expand Down
12 changes: 8 additions & 4 deletions examples/template-provider-test/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use async_channel::{Receiver, Sender};
use async_std::net::TcpStream;
use codec_sv2::{Frame, StandardEitherFrame, StandardSv2Frame, Sv2Frame};
use messages_sv2::parsers::{IsSv2Message, TemplateDistribution};
use messages_sv2::template_distribution_sv2::SubmitSolution;
use messages_sv2::{
parsers::{IsSv2Message, TemplateDistribution},
template_distribution_sv2::SubmitSolution,
};
use network_helpers::PlainConnection;
use std::convert::TryInto;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::{
convert::TryInto,
net::{IpAddr, Ipv4Addr, SocketAddr},
};

pub type Message = TemplateDistribution<'static>;
pub type StdFrame = StandardSv2Frame<Message>;
Expand Down
4 changes: 1 addition & 3 deletions protocols/v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ use std::convert::TryInto;
// use error::Result;
use error::Error;
pub use json_rpc::Message;
pub use methods::client_to_server;
pub use methods::server_to_client;
pub use methods::MethodError;
pub use methods::{client_to_server, server_to_client, MethodError};
use utils::{HexBytes, HexU32Be};

/// json_rpc Response are not handled cause startum v1 do not have any request from a server to a
Expand Down
19 changes: 10 additions & 9 deletions protocols/v1/src/methods/client_to_server.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use serde_json::Value;
use serde_json::Value::Array as JArrary;
use serde_json::Value::Number as JNumber;
use serde_json::Value::String as JString;
use std::convert::TryFrom;
use std::convert::TryInto;

use crate::json_rpc::{Message, Response, StandardRequest};
use crate::utils::{HexBytes, HexU32Be};
use serde_json::{
Value,
Value::{Array as JArrary, Number as JNumber, String as JString},
};
use std::convert::{TryFrom, TryInto};

use crate::{
json_rpc::{Message, Response, StandardRequest},
utils::{HexBytes, HexU32Be},
};

use crate::methods::{MethodError, ParsingMethodError};

Expand Down
3 changes: 1 addition & 2 deletions protocols/v1/src/methods/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use bitcoin_hashes::Error as BTCHashError;
use hex::FromHexError;
use std::convert::TryFrom;
use std::convert::TryInto;
use std::convert::{TryFrom, TryInto};

pub mod client_to_server;
pub mod server_to_client;
Expand Down
22 changes: 11 additions & 11 deletions protocols/v1/src/methods/server_to_client.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use serde_json::Value;
use serde_json::Value::Array as JArrary;
use serde_json::Value::Bool as JBool;
use serde_json::Value::Number as JNumber;
use serde_json::Value::String as JString;
use std::convert::TryFrom;
use std::convert::TryInto;

use crate::json_rpc::{Message, Notification, Response};
use crate::methods::{MethodError, ParsingMethodError};
use crate::utils::{HexBytes, HexU32Be, PrevHash};
use serde_json::{
Value,
Value::{Array as JArrary, Bool as JBool, Number as JNumber, String as JString},
};
use std::convert::{TryFrom, TryInto};

use crate::{
json_rpc::{Message, Notification, Response},
methods::{MethodError, ParsingMethodError},
utils::{HexBytes, HexU32Be, PrevHash},
};

// client.get_version() TODO

Expand Down
3 changes: 1 addition & 2 deletions protocols/v1/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use bitcoin_hashes::hex::{FromHex, ToHex};
use byteorder::{BigEndian, ByteOrder, LittleEndian, WriteBytesExt};
use hex::FromHexError;
use serde_json::Value;
use std::convert::TryFrom;
use std::mem::size_of;
use std::{convert::TryFrom, mem::size_of};

/// Helper type that allows simple serialization and deserialization of byte vectors
/// that are represented as hex strings in JSON
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::codec::{GetSize, SizeHint};
use crate::datatypes::{Bytes, Signature, Sv2DataType, B016M, B0255, B032, B064K, U24, U256};
use crate::Error;
use crate::{
codec::{GetSize, SizeHint},
datatypes::{Bytes, Signature, Sv2DataType, B016M, B0255, B032, B064K, U24, U256},
Error,
};
use alloc::vec::Vec;
#[cfg(not(feature = "no_std"))]
use std::io::{Cursor, Read};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::codec::GetSize;
use crate::datatypes::{Bytes, Signature, Sv2DataType, B016M, B0255, B032, B064K, U24, U256};
use crate::Error;
use crate::{
codec::GetSize,
datatypes::{Bytes, Signature, Sv2DataType, B016M, B0255, B032, B064K, U24, U256},
Error,
};
use alloc::vec::Vec;
#[cfg(not(feature = "no_std"))]
use std::io::{Error as E, Write};
Expand Down
14 changes: 9 additions & 5 deletions protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/impls.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::codec::decodable::{
Decodable, DecodableField, DecodablePrimitive, FieldMarker, GetMarker, PrimitiveMarker,
use crate::{
codec::{
decodable::{
Decodable, DecodableField, DecodablePrimitive, FieldMarker, GetMarker, PrimitiveMarker,
},
encodable::{EncodableField, EncodablePrimitive},
},
datatypes::*,
Error,
};
use crate::codec::encodable::{EncodableField, EncodablePrimitive};
use crate::datatypes::*;
use crate::Error;
use alloc::vec::Vec;
use core::convert::{TryFrom, TryInto};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Copy data types
use crate::codec::Fixed;
use crate::datatypes::Sv2DataType;
use crate::Error;
use crate::{codec::Fixed, datatypes::Sv2DataType, Error};
use core::convert::{TryFrom, TryInto};

#[cfg(not(feature = "no_std"))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::codec::{GetSize, SizeHint};
use crate::Error;
use crate::{
codec::{GetSize, SizeHint},
Error,
};
mod non_copy_data_types;

mod copy_data_types;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use super::IntoOwned;
use crate::codec::{GetSize, SizeHint};
use crate::datatypes::Sv2DataType;
use crate::Error;
use crate::{
codec::{GetSize, SizeHint},
datatypes::Sv2DataType,
Error,
};
use core::convert::TryFrom;

#[cfg(not(feature = "no_std"))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::codec::decodable::{Decodable, DecodableField, FieldMarker, GetMarker, PrimitiveMarker};
use crate::codec::encodable::{EncodableField, EncodablePrimitive};
use crate::codec::Fixed;
use crate::codec::GetSize;
use crate::datatypes::Sv2DataType;
use crate::datatypes::*;
use crate::Error;
use crate::{
codec::{
decodable::{Decodable, DecodableField, FieldMarker, GetMarker, PrimitiveMarker},
encodable::{EncodableField, EncodablePrimitive},
Fixed, GetSize,
},
datatypes::{Sv2DataType, *},
Error,
};
use core::marker::PhantomData;

// TODO add test for that implement also with serde!!!!
Expand Down
Loading

0 comments on commit b62f702

Please sign in to comment.