Reformat imports to a consistent style for imports

rustfmt.toml configuration:
  imports_granularity = "One"
  group_imports = "One"
This commit is contained in:
Michael Vines
2021-12-03 09:00:31 -08:00
parent 0ef1b25e4b
commit b8837c04ec
397 changed files with 5990 additions and 5175 deletions

View File

@ -1,10 +1,17 @@
use crate::{
clock::{Epoch, INITIAL_RENT_EPOCH},
lamports::LamportsError,
pubkey::Pubkey,
use {
crate::{
clock::{Epoch, INITIAL_RENT_EPOCH},
lamports::LamportsError,
pubkey::Pubkey,
},
solana_program::{account_info::AccountInfo, sysvar::Sysvar},
std::{
cell::{Ref, RefCell},
cmp, fmt,
rc::Rc,
sync::Arc,
},
};
use solana_program::{account_info::AccountInfo, sysvar::Sysvar};
use std::{cell::Ref, cell::RefCell, cmp, fmt, rc::Rc, sync::Arc};
/// An Account with data that is stored on chain
#[repr(C)]

View File

@ -1,7 +1,12 @@
//! useful extras for Account state
use crate::{account::Account, account::AccountSharedData, instruction::InstructionError};
use bincode::ErrorKind;
use std::cell::Ref;
use {
crate::{
account::{Account, AccountSharedData},
instruction::InstructionError,
},
bincode::ErrorKind,
std::cell::Ref,
};
/// Convenience trait to covert bincode errors to instruction errors.
pub trait StateMut<T> {
@ -60,8 +65,10 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::{account::AccountSharedData, pubkey::Pubkey};
use {
super::*,
crate::{account::AccountSharedData, pubkey::Pubkey},
};
#[test]
fn test_account_state() {

View File

@ -1,8 +1,7 @@
#![allow(deprecated)]
#![cfg(feature = "full")]
use std::str::FromStr;
use thiserror::Error;
use {std::str::FromStr, thiserror::Error};
#[derive(Serialize, Deserialize, Default, Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[serde(rename_all = "camelCase")]

View File

@ -158,10 +158,12 @@ impl ComputeBudget {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
hash::Hash, message::Message, pubkey::Pubkey, signature::Keypair, signer::Signer,
transaction::Transaction,
use {
super::*,
crate::{
hash::Hash, message::Message, pubkey::Pubkey, signature::Keypair, signer::Signer,
transaction::Transaction,
},
};
macro_rules! test {

View File

@ -260,8 +260,7 @@ impl Bip44 for Solana {
#[cfg(test)]
mod tests {
use super::*;
use uriparse::URIReferenceBuilder;
use {super::*, uriparse::URIReferenceBuilder};
struct TestCoin;
impl Bip44 for TestCoin {

View File

@ -18,8 +18,7 @@ where
#[cfg(test)]
pub mod tests {
use super::*;
use bincode::deserialize;
use {super::*, bincode::deserialize};
#[test]
fn test_default_on_eof() {

View File

@ -1,9 +1,11 @@
#![cfg(feature = "full")]
use crate::{feature_set::FeatureSet, instruction::Instruction, precompiles::PrecompileError};
use bytemuck::{bytes_of, Pod, Zeroable};
use ed25519_dalek::{ed25519::signature::Signature, Signer, Verifier};
use std::sync::Arc;
use {
crate::{feature_set::FeatureSet, instruction::Instruction, precompiles::PrecompileError},
bytemuck::{bytes_of, Pod, Zeroable},
ed25519_dalek::{ed25519::signature::Signature, Signer, Verifier},
std::sync::Arc,
};
pub const PUBKEY_SERIALIZED_SIZE: usize = 32;
pub const SIGNATURE_SERIALIZED_SIZE: usize = 64;
@ -173,16 +175,18 @@ fn get_data_slice<'a>(
#[cfg(test)]
pub mod test {
use super::*;
use crate::{
ed25519_instruction::new_ed25519_instruction,
feature_set::FeatureSet,
hash::Hash,
signature::{Keypair, Signer},
transaction::Transaction,
use {
super::*,
crate::{
ed25519_instruction::new_ed25519_instruction,
feature_set::FeatureSet,
hash::Hash,
signature::{Keypair, Signer},
transaction::Transaction,
},
rand::{thread_rng, Rng},
std::sync::Arc,
};
use rand::{thread_rng, Rng};
use std::sync::Arc;
fn test_case(
num_signatures: u16,

View File

@ -18,13 +18,15 @@
//!
//! For more information on how features are picked up, see comments for `Feature`.
use lazy_static::lazy_static;
use solana_sdk::{
clock::Slot,
hash::{Hash, Hasher},
pubkey::Pubkey,
use {
lazy_static::lazy_static,
solana_sdk::{
clock::Slot,
hash::{Hash, Hasher},
pubkey::Pubkey,
},
std::collections::{HashMap, HashSet},
};
use std::collections::{HashMap, HashSet};
pub mod deprecate_rewards_sysvar {
solana_sdk::declare_id!("GaBtBJvmS4Arjj5W1NmFcyvPjsHN38UGYDq2MDwbs9Qu");

View File

@ -2,34 +2,35 @@
#![cfg(feature = "full")]
use crate::{
account::Account,
account::AccountSharedData,
clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT},
epoch_schedule::EpochSchedule,
fee_calculator::FeeRateGovernor,
hash::{hash, Hash},
inflation::Inflation,
native_token::lamports_to_sol,
poh_config::PohConfig,
pubkey::Pubkey,
rent::Rent,
shred_version::compute_shred_version,
signature::{Keypair, Signer},
system_program,
timing::years_as_slots,
};
use bincode::{deserialize, serialize};
use chrono::{TimeZone, Utc};
use memmap2::Mmap;
use std::{
collections::BTreeMap,
fmt,
fs::{File, OpenOptions},
io::Write,
path::{Path, PathBuf},
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
use {
crate::{
account::{Account, AccountSharedData},
clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT},
epoch_schedule::EpochSchedule,
fee_calculator::FeeRateGovernor,
hash::{hash, Hash},
inflation::Inflation,
native_token::lamports_to_sol,
poh_config::PohConfig,
pubkey::Pubkey,
rent::Rent,
shred_version::compute_shred_version,
signature::{Keypair, Signer},
system_program,
timing::years_as_slots,
},
bincode::{deserialize, serialize},
chrono::{TimeZone, Utc},
memmap2::Mmap,
std::{
collections::BTreeMap,
fmt,
fs::{File, OpenOptions},
io::Write,
path::{Path, PathBuf},
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
},
};
pub const DEFAULT_GENESIS_FILE: &str = "genesis.bin";
@ -291,9 +292,11 @@ impl fmt::Display for GenesisConfig {
#[cfg(test)]
mod tests {
use super::*;
use crate::signature::{Keypair, Signer};
use std::path::PathBuf;
use {
super::*,
crate::signature::{Keypair, Signer},
std::path::PathBuf,
};
fn make_tmp_path(name: &str) -> PathBuf {
let out_dir = std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string());

View File

@ -3,8 +3,10 @@
#![cfg(feature = "full")]
use byteorder::{ByteOrder, LittleEndian};
use solana_sdk::clock::Slot;
use {
byteorder::{ByteOrder, LittleEndian},
solana_sdk::clock::Slot,
};
#[derive(Default, Clone, Debug, Deserialize, Serialize, AbiExample, PartialEq, Eq)]
pub struct HardForks {

View File

@ -1,12 +1,14 @@
use crate::{
account::{from_account, AccountSharedData, ReadableAccount},
account_utils::{State, StateMut},
};
use solana_program::{clock::Epoch, instruction::InstructionError, pubkey::Pubkey, sysvar::Sysvar};
use std::{
cell::{Ref, RefCell, RefMut},
iter::FromIterator,
rc::Rc,
use {
crate::{
account::{from_account, AccountSharedData, ReadableAccount},
account_utils::{State, StateMut},
},
solana_program::{clock::Epoch, instruction::InstructionError, pubkey::Pubkey, sysvar::Sysvar},
std::{
cell::{Ref, RefCell, RefMut},
iter::FromIterator,
rc::Rc,
},
};
#[repr(C)]
@ -258,12 +260,14 @@ pub fn from_keyed_account<S: Sysvar>(
#[cfg(test)]
mod tests {
use super::*;
use crate::{
account::{create_account_for_test, to_account},
pubkey::Pubkey,
use {
super::*,
crate::{
account::{create_account_for_test, to_account},
pubkey::Pubkey,
},
std::cell::RefCell,
};
use std::cell::RefCell;
#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]

View File

@ -1,7 +1,9 @@
use crate::account::{
Account, AccountSharedData, InheritableAccountFields, DUMMY_INHERITABLE_ACCOUNT_FIELDS,
use crate::{
account::{
Account, AccountSharedData, InheritableAccountFields, DUMMY_INHERITABLE_ACCOUNT_FIELDS,
},
clock::INITIAL_RENT_EPOCH,
};
use crate::clock::INITIAL_RENT_EPOCH;
crate::declare_id!("NativeLoader1111111111111111111111111111111");

View File

@ -1,10 +1,12 @@
use crate::{
account::{AccountSharedData, ReadableAccount},
account_utils::StateMut,
hash::Hash,
nonce::{state::Versions, State},
use {
crate::{
account::{AccountSharedData, ReadableAccount},
account_utils::StateMut,
hash::Hash,
nonce::{state::Versions, State},
},
std::cell::RefCell,
};
use std::cell::RefCell;
pub fn create_account(lamports: u64) -> RefCell<AccountSharedData> {
RefCell::new(
@ -40,8 +42,7 @@ pub fn lamports_per_signature_of(account: &AccountSharedData) -> Option<u64> {
#[cfg(test)]
mod tests {
use super::*;
use crate::pubkey::Pubkey;
use {super::*, crate::pubkey::Pubkey};
#[test]
fn test_verify_bad_account_owner_fails() {

View File

@ -1,9 +1,11 @@
use crate::clock::Slot;
use bincode::Result;
use serde::Serialize;
use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
{fmt, io},
use {
crate::clock::Slot,
bincode::Result,
serde::Serialize,
std::{
fmt, io,
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
},
};
/// Maximum over-the-wire size of a Transaction

View File

@ -1,5 +1,7 @@
use crate::{clock::DEFAULT_TICKS_PER_SECOND, unchecked_div_by_const};
use std::time::Duration;
use {
crate::{clock::DEFAULT_TICKS_PER_SECOND, unchecked_div_by_const},
std::time::Duration,
};
#[derive(Serialize, Deserialize, Clone, Debug, AbiExample)]
pub struct PohConfig {

View File

@ -1,5 +1,4 @@
use crate::instruction::InstructionError;
use bincode::config::Options;
use {crate::instruction::InstructionError, bincode::config::Options};
/// Deserialize with a limit based the maximum amount of data a program can expect to get.
/// This function should be used in place of direct deserialization to help prevent OOM errors

View File

@ -33,8 +33,7 @@ pub fn read_pubkey_file(infile: &str) -> Result<Pubkey, Box<dyn std::error::Erro
#[cfg(test)]
mod tests {
use super::*;
use std::fs::remove_file;
use {super::*, std::fs::remove_file};
#[test]
fn test_read_write_pubkey() -> Result<(), Box<dyn std::error::Error>> {

View File

@ -1,13 +1,17 @@
use crate::account::{
create_account_shared_data_with_fields, to_account, AccountSharedData,
InheritableAccountFields, DUMMY_INHERITABLE_ACCOUNT_FIELDS,
};
use crate::clock::INITIAL_RENT_EPOCH;
#[allow(deprecated)]
use solana_program::sysvar::recent_blockhashes::{
IntoIterSorted, IterItem, RecentBlockhashes, MAX_ENTRIES,
};
use std::{collections::BinaryHeap, iter::FromIterator};
use {
crate::{
account::{
create_account_shared_data_with_fields, to_account, AccountSharedData,
InheritableAccountFields, DUMMY_INHERITABLE_ACCOUNT_FIELDS,
},
clock::INITIAL_RENT_EPOCH,
},
std::{collections::BinaryHeap, iter::FromIterator},
};
#[deprecated(
since = "1.9.0",
@ -79,12 +83,14 @@ where
#[cfg(test)]
mod tests {
#![allow(deprecated)]
use super::*;
use crate::account::from_account;
use rand::{seq::SliceRandom, thread_rng};
use solana_program::{
hash::{Hash, HASH_BYTES},
sysvar::recent_blockhashes::Entry,
use {
super::*,
crate::account::from_account,
rand::{seq::SliceRandom, thread_rng},
solana_program::{
hash::{Hash, HASH_BYTES},
sysvar::recent_blockhashes::Entry,
},
};
#[test]

View File

@ -1,13 +1,17 @@
#![cfg(feature = "full")]
use crate::{
feature_set::{libsecp256k1_0_5_upgrade_enabled, libsecp256k1_fail_on_bad_count, FeatureSet},
instruction::Instruction,
precompiles::PrecompileError,
use {
crate::{
feature_set::{
libsecp256k1_0_5_upgrade_enabled, libsecp256k1_fail_on_bad_count, FeatureSet,
},
instruction::Instruction,
precompiles::PrecompileError,
},
digest::Digest,
serde_derive::{Deserialize, Serialize},
std::sync::Arc,
};
use digest::Digest;
use serde_derive::{Deserialize, Serialize};
use std::sync::Arc;
pub const HASHED_PUBKEY_SERIALIZED_SIZE: usize = 20;
pub const SIGNATURE_SERIALIZED_SIZE: usize = 64;
@ -211,18 +215,20 @@ fn get_data_slice<'a>(
#[cfg(test)]
pub mod test {
use super::*;
use crate::{
feature_set,
hash::Hash,
secp256k1_instruction::{
new_secp256k1_instruction, SecpSignatureOffsets, SIGNATURE_OFFSETS_SERIALIZED_SIZE,
use {
super::*,
crate::{
feature_set,
hash::Hash,
secp256k1_instruction::{
new_secp256k1_instruction, SecpSignatureOffsets, SIGNATURE_OFFSETS_SERIALIZED_SIZE,
},
signature::{Keypair, Signer},
transaction::Transaction,
},
signature::{Keypair, Signer},
transaction::Transaction,
rand::{thread_rng, Rng},
std::sync::Arc,
};
use rand::{thread_rng, Rng};
use std::sync::Arc;
fn test_case(
num_signatures: u8,

View File

@ -1,18 +1,19 @@
//! The `signature` module provides functionality for public, and private keys.
#![cfg(feature = "full")]
use crate::pubkey::Pubkey;
use generic_array::{typenum::U64, GenericArray};
use std::{
borrow::{Borrow, Cow},
convert::TryInto,
fmt, mem,
str::FromStr,
};
use thiserror::Error;
// legacy module paths
pub use crate::signer::{keypair::*, null_signer::*, presigner::*, *};
use {
crate::pubkey::Pubkey,
generic_array::{typenum::U64, GenericArray},
std::{
borrow::{Borrow, Cow},
convert::TryInto,
fmt, mem,
str::FromStr,
},
thiserror::Error,
};
/// Number of bytes in a signature
pub const SIGNATURE_BYTES: usize = 64;

View File

@ -100,8 +100,7 @@ pub fn unique_signers(signers: Vec<&dyn Signer>) -> Vec<&dyn Signer> {
#[cfg(test)]
mod tests {
use super::*;
use crate::signer::keypair::Keypair;
use {super::*, crate::signer::keypair::Keypair};
fn pubkeys(signers: &[&dyn Signer]) -> Vec<Pubkey> {
signers.iter().map(|x| x.pubkey()).collect()

View File

@ -63,8 +63,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::signer::keypair::keypair_from_seed;
use {super::*, crate::signer::keypair::keypair_from_seed};
#[test]
fn test_presigner() {

View File

@ -1,7 +1,11 @@
//! The `timing` module provides std::time utility functions.
use crate::unchecked_div_by_const;
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use {
crate::unchecked_div_by_const,
std::{
sync::atomic::{AtomicU64, Ordering},
time::{Duration, SystemTime, UNIX_EPOCH},
},
};
pub fn duration_as_ns(d: &Duration) -> u64 {
d.as_secs()

View File

@ -19,16 +19,14 @@ use {
serde::Serialize,
solana_program::{system_instruction::SystemInstruction, system_program},
solana_sdk::feature_set,
std::result,
std::sync::Arc,
std::{result, sync::Arc},
thiserror::Error,
};
mod sanitized;
mod versioned;
pub use sanitized::*;
pub use versioned::*;
pub use {sanitized::*, versioned::*};
/// Reasons a transaction might be rejected.
#[derive(
@ -547,15 +545,17 @@ pub fn get_nonce_pubkey_from_instruction<'a>(
mod tests {
#![allow(deprecated)]
use super::*;
use crate::{
hash::hash,
instruction::AccountMeta,
signature::{Keypair, Presigner, Signer},
system_instruction, sysvar,
use {
super::*,
crate::{
hash::hash,
instruction::AccountMeta,
signature::{Keypair, Presigner, Signer},
system_instruction, sysvar,
},
bincode::{deserialize, serialize, serialized_size},
std::mem::size_of,
};
use bincode::{deserialize, serialize, serialized_size};
use std::mem::size_of;
fn get_program_id(tx: &Transaction, instruction_index: usize) -> &Pubkey {
let message = tx.message();

View File

@ -1,8 +1,6 @@
#![cfg(feature = "full")]
use crate::transaction::TransactionError;
use std::io;
use thiserror::Error;
use {crate::transaction::TransactionError, std::io, thiserror::Error};
#[derive(Debug, Error)]
pub enum TransportError {