Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(stacks-common): Remove unused imports and enable warning #5633

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stacks-common/src/address/b58.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

//! Base58 encoder and decoder

use std::{error, fmt, str};
use std::{fmt, str};

use crate::address::Error;
use crate::util::hash::DoubleSha256;
Expand Down
3 changes: 1 addition & 2 deletions stacks-common/src/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{error, fmt};
use sha2::{Digest, Sha256};

use crate::deps_common::bitcoin::blockdata::opcodes::All as btc_opcodes;
use crate::deps_common::bitcoin::blockdata::script::{Builder, Instruction, Script};
use crate::deps_common::bitcoin::blockdata::script::Builder;
use crate::types::PublicKey;
use crate::util::hash::Hash160;

Expand Down Expand Up @@ -220,7 +220,6 @@ pub fn public_keys_to_address_hash<K: PublicKey>(
mod test {
use super::*;
use crate::util::hash::*;
use crate::util::log;
use crate::util::secp256k1::Secp256k1PublicKey as PubKey;

struct PubkeyFixture {
Expand Down
1 change: 0 additions & 1 deletion stacks-common/src/bitvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ mod test {

use super::BitVec;
use crate::codec::StacksMessageCodec;
use crate::util::hash::to_hex;

fn check_set_get(mut input: BitVec<{ u16::MAX }>) {
let original_input = input.clone();
Expand Down
1 change: 0 additions & 1 deletion stacks-common/src/deps_common/bitcoin/blockdata/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crate::deps_common::bitcoin::blockdata::transaction::Transaction;
use crate::deps_common::bitcoin::network::constants::Network;
use crate::deps_common::bitcoin::network::encodable::VarInt;
use crate::deps_common::bitcoin::network::serialize::BitcoinHash;
use crate::deps_common::bitcoin::util;
use crate::deps_common::bitcoin::util::hash::Sha256dHash;
use crate::deps_common::bitcoin::util::Error;
use crate::deps_common::bitcoin::util::Error::{SpvBadProofOfWork, SpvBadTarget};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use std::mem::size_of;
use std::{error, fmt};

use serde;
use sha2::{Digest, Sha256};

use crate::deps_common::bitcoin::blockdata::opcodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use crate::deps_common::bitcoin::network::serialize::{
self, serialize, BitcoinHash, SimpleDecoder, SimpleEncoder,
};
use crate::deps_common::bitcoin::util::hash::Sha256dHash;
use crate::util::hash::to_hex;

/// A reference to a transaction output
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
Expand Down Expand Up @@ -675,7 +674,7 @@ impl SigHashType {

#[cfg(test)]
mod tests {
use super::{SigHashType, Transaction, TxIn};
use super::{Transaction, TxIn};
use crate::deps_common;
use crate::deps_common::bitcoin::blockdata::script::Script;
use crate::deps_common::bitcoin::network::serialize::{deserialize, BitcoinHash};
Expand All @@ -690,7 +689,6 @@ mod tests {

#[test]
fn test_is_coinbase() {
use crate::deps_common::bitcoin::blockdata::constants;
use crate::deps_common::bitcoin::network::constants::Network;

let genesis = deps_common::bitcoin::blockdata::constants::genesis_block(Network::Bitcoin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
//!

use crate::deps_common::bitcoin::network::address::Address;
use crate::deps_common::bitcoin::network::constants;
use crate::util;

// Some simple messages

Expand Down
2 changes: 1 addition & 1 deletion stacks-common/src/deps_common/bitcoin/util/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use std::char::from_digit;
use std::cmp::min;
use std::io::{Cursor, Write};
use std::{error, fmt, mem};
use std::{fmt, mem};

use ripemd::Ripemd160;
#[cfg(feature = "serde")]
Expand Down
4 changes: 1 addition & 3 deletions stacks-common/src/deps_common/httparse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//! Originally written by Sean McArthur.
//!
//! Modified by Jude Nelson to remove all unsafe code.
use std::{error, fmt, mem, result, str};
use std::{fmt, mem, result, str};

macro_rules! next {
($bytes:ident) => {{
Expand Down Expand Up @@ -1282,8 +1282,6 @@ mod tests {

#[test]
fn test_std_error() {
use std::error::Error as StdError;

use super::Error;
let err = Error::HeaderName;
assert_eq!(err.to_string(), err.description_str());
Expand Down
4 changes: 1 addition & 3 deletions stacks-common/src/libcommon.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![allow(unused_macros)]
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![cfg_attr(test, allow(unused_variables, unused_assignments))]
#![allow(clippy::assertions_on_constants)]

#[allow(unused_imports)]
#[macro_use(o, slog_log, slog_trace, slog_debug, slog_info, slog_warn, slog_error)]
extern crate slog;

Expand All @@ -33,8 +33,6 @@ pub mod deps_common;

pub mod bitvec;

use crate::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, SortitionId, StacksBlockId};

pub mod consts {
use crate::types::chainstate::{BlockHeaderHash, ConsensusHash};
pub use crate::types::MINING_COMMITMENT_WINDOW;
Expand Down
13 changes: 5 additions & 8 deletions stacks-common/src/types/chainstate.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
use std::fmt::{self, Display};
use std::fmt;
use std::io::{Read, Write};
use std::str::FromStr;

use curve25519_dalek::digest::Digest;
use rand::{Rng, SeedableRng};
use serde::de::{Deserialize, Error as de_Error};
use serde::ser::Error as ser_Error;
use serde::Serialize;
use sha2::{Digest as Sha2Digest, Sha256, Sha512_256};
use sha2::{Digest as Sha2Digest, Sha512_256};

use crate::codec::{read_next, write_next, Error as CodecError, StacksMessageCodec};
use crate::consts::{FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH};
use crate::deps_common::bitcoin::util::hash::Sha256dHash;
use crate::util::hash::{to_hex, DoubleSha256, Hash160, Sha512Trunc256Sum, HASH160_ENCODED_SIZE};
use crate::util::hash::{Hash160, Sha512Trunc256Sum, HASH160_ENCODED_SIZE};
use crate::util::secp256k1::{MessageSignature, Secp256k1PrivateKey, Secp256k1PublicKey};
use crate::util::uint::Uint256;
use crate::util::vrf::{VRFProof, VRF_PROOF_ENCODED_SIZE};

pub type StacksPublicKey = Secp256k1PublicKey;
Expand Down Expand Up @@ -452,6 +447,8 @@ impl BurnchainHeaderHash {
index_root: &TrieHash,
noise: u64,
) -> BurnchainHeaderHash {
use crate::util::hash::DoubleSha256;

let mut bytes = vec![];
bytes.extend_from_slice(&block_height.to_be_bytes());
bytes.extend_from_slice(index_root.as_bytes());
Expand Down
2 changes: 0 additions & 2 deletions stacks-common/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use std::cell::LazyCell;
use std::cmp::Ordering;
use std::fmt;
use std::ops::{Deref, DerefMut, Index, IndexMut};
Expand All @@ -30,7 +29,6 @@ use crate::address::{
C32_ADDRESS_VERSION_TESTNET_MULTISIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG,
};
use crate::consts::MICROSTACKS_PER_STACKS;
use crate::deps_common::bitcoin::blockdata::transaction::TxOut;
use crate::types::chainstate::{StacksAddress, StacksPublicKey};
use crate::util::hash::Hash160;
use crate::util::secp256k1::{MessageSignature, Secp256k1PublicKey};
Expand Down
3 changes: 2 additions & 1 deletion stacks-common/src/util/chunked_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,10 @@ impl<W: Write> Write for HttpChunkedTransferWriter<'_, '_, W> {
}
}

#[cfg(test)]
mod test {
use std::io;
use std::io::{Read, Write};
use std::io::Read;

use rand::RngCore;

Expand Down
2 changes: 1 addition & 1 deletion stacks-common/src/util/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use std::backtrace::Backtrace;
use std::sync::{LazyLock, Mutex};
use std::thread;
use std::time::{Duration, Instant};
use std::time::Instant;

use hashbrown::HashMap;
use rand::{thread_rng, Rng};
Expand Down
7 changes: 2 additions & 5 deletions stacks-common/src/util/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use std::{fmt, mem};

use ripemd::Ripemd160;
use serde::de::{Deserialize, Error as de_Error};
use serde::ser::Error as ser_Error;
use serde::Serialize;
use sha2::{Digest, Sha256, Sha512, Sha512_256};
use sha3::Keccak256;
Expand All @@ -29,7 +28,7 @@ use crate::types::StacksPublicKeyBuffer;
use crate::util::pair::*;
use crate::util::secp256k1::Secp256k1PublicKey;
use crate::util::uint::Uint256;
use crate::util::{log, HexError};
use crate::util::HexError;

// hash function for Merkle trees
pub trait MerkleHashFunc {
Expand Down Expand Up @@ -659,9 +658,7 @@ pub fn bytes_to_hex(s: &[u8]) -> String {

#[cfg(test)]
mod test {
use super::{
bin_bytes, hex_bytes, to_bin, DoubleSha256, MerkleHashFunc, MerklePath, MerkleTree,
};
use super::{bin_bytes, hex_bytes, to_bin, DoubleSha256, MerkleHashFunc, MerkleTree};

struct MerkleTreeFixture {
data: Vec<Vec<u8>>,
Expand Down
7 changes: 5 additions & 2 deletions stacks-common/src/util/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use std::io::Write;
use std::sync::Mutex;
jbencin marked this conversation as resolved.
Show resolved Hide resolved
use std::time::{Duration, SystemTime};
use std::{env, io, thread};

use chrono::prelude::*;
use lazy_static::lazy_static;
use slog::{BorrowedKV, Drain, FnValue, Level, Logger, OwnedKVList, Record, KV};
jbencin marked this conversation as resolved.
Show resolved Hide resolved
use slog::{Drain, Level, Logger, OwnedKVList, Record, KV};
use slog_term::{CountingWriter, Decorator, RecordDecorator, Serializer};

lazy_static! {
Expand Down Expand Up @@ -191,6 +190,10 @@ impl<D: Decorator> TermFormat<D> {

#[cfg(feature = "slog_json")]
fn make_json_logger() -> Logger {
use std::sync::Mutex;

use slog::FnValue;

let def_keys = o!("file" => FnValue(move |info| {
info.file()
}),
Expand Down
5 changes: 2 additions & 3 deletions stacks-common/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ pub mod secp256k1;
pub mod uint;
pub mod vrf;

use std::collections::HashMap;
use std::fs::File;
use std::io::{BufReader, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::path::Path;
use std::time::{SystemTime, UNIX_EPOCH};
use std::{error, fmt, thread, time};

/// Given a relative path inside the Cargo workspace, return the absolute path
#[cfg(any(test, feature = "testing"))]
pub fn cargo_workspace<P>(relative_path: P) -> PathBuf
pub fn cargo_workspace<P>(relative_path: P) -> std::path::PathBuf
obycode marked this conversation as resolved.
Show resolved Hide resolved
where
P: AsRef<Path>,
{
Expand Down
4 changes: 0 additions & 4 deletions stacks-common/src/util/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ use std::io;
use std::io::{Read, Write};
use std::sync::mpsc::{sync_channel, Receiver, SyncSender, TryRecvError, TrySendError};

use crate::util::log;

/// Inter-thread pipe for streaming messages, built on channels.
/// Used mainly in conjunction with networking.
///
Expand Down Expand Up @@ -316,15 +314,13 @@ impl Write for PipeWrite {

#[cfg(test)]
mod test {
use std::io::prelude::*;
use std::io::{Read, Write};
use std::{io, thread};

use rand;
use rand::RngCore;

use super::*;
use crate::util::*;

#[test]
fn test_connection_pipe_oneshot() {
Expand Down
6 changes: 1 addition & 5 deletions stacks-common/src/util/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
*/

use std::io;
use std::io::prelude::*;
use std::io::{Read, Write};

use crate::util::hash::to_hex;
use crate::util::log;
use std::io::Read;

/// Wrap a Read so that we store a copy of what was read.
/// Used for re-trying reads when we don't know what to expect from the stream.
Expand Down
6 changes: 2 additions & 4 deletions stacks-common/src/util/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use rand::{thread_rng, RngCore};
use rand::RngCore;
use secp256k1;
use secp256k1::ecdsa::{
RecoverableSignature as LibSecp256k1RecoverableSignature, RecoveryId as LibSecp256k1RecoveryID,
Expand All @@ -24,11 +24,9 @@ use secp256k1::{
PublicKey as LibSecp256k1PublicKey, Secp256k1, SecretKey as LibSecp256k1PrivateKey,
};
use serde::de::{Deserialize, Error as de_Error};
use serde::ser::Error as ser_Error;
use serde::Serialize;

use super::hash::Sha256Sum;
use crate::impl_byte_array_message_codec;
use crate::types::{PrivateKey, PublicKey};
use crate::util::hash::{hex_bytes, to_hex};

Expand Down Expand Up @@ -442,8 +440,8 @@ mod tests {
use secp256k1::{PublicKey as LibSecp256k1PublicKey, Secp256k1};

use super::*;
use crate::util::get_epoch_time_ms;
use crate::util::hash::hex_bytes;
use crate::util::{get_epoch_time_ms, log};

struct KeyFixture<I, R> {
input: I,
Expand Down
7 changes: 0 additions & 7 deletions stacks-common/src/util/vrf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ use std::fmt::Debug;
use std::hash::{Hash, Hasher};
/// This codebase is based on routines defined in the IETF draft for verifiable random functions
/// over elliptic curves (https://tools.ietf.org/id/draft-irtf-cfrg-vrf-02.html).
use std::ops::Deref;
use std::ops::DerefMut;
use std::{error, fmt};

use curve25519_dalek::constants::ED25519_BASEPOINT_POINT;
use curve25519_dalek::edwards::{CompressedEdwardsY, EdwardsPoint};
use curve25519_dalek::scalar::Scalar as ed25519_Scalar;
use ed25519_dalek::{
SecretKey as EdDalekSecretKeyBytes, SigningKey as EdPrivateKey, VerifyingKey as EdPublicKey,
};
use rand;
use sha2::{Digest, Sha512};

Expand Down Expand Up @@ -535,10 +530,8 @@ impl VRF {

#[cfg(test)]
mod tests {
use curve25519_dalek::scalar::Scalar as ed25519_Scalar;
use rand;
use rand::RngCore;
use sha2::Sha512;

use super::*;
use crate::util::hash::hex_bytes;
Expand Down
Loading