From 12eff5a2f988033fa2ce18b2c27e93a1c70431e8 Mon Sep 17 00:00:00 2001 From: Jack May Date: Tue, 28 Jan 2020 16:11:22 -0800 Subject: [PATCH] Cleanup SDK use syntax (#8004) --- sdk/src/account.rs | 8 +++++--- sdk/src/account_utils.rs | 3 +-- sdk/src/bank_hash.rs | 3 +-- sdk/src/fee_calculator.rs | 3 +-- sdk/src/hash.rs | 5 +---- sdk/src/instruction.rs | 4 +--- sdk/src/loader_instruction.rs | 8 +++++--- sdk/src/message.rs | 16 ++++++++++------ sdk/src/native_loader.rs | 3 +-- sdk/src/nonce_state.rs | 3 +-- sdk/src/packet.rs | 6 ++++-- sdk/src/pubkey.rs | 6 +----- sdk/src/short_vec.rs | 12 ++++++------ sdk/src/system_instruction.rs | 16 +++++++++------- sdk/src/sysvar/recent_blockhashes.rs | 4 +--- sdk/src/transaction.rs | 21 ++++++++++----------- sdk/src/transport.rs | 4 +--- 17 files changed, 59 insertions(+), 66 deletions(-) diff --git a/sdk/src/account.rs b/sdk/src/account.rs index d831f7059c..f10db11550 100644 --- a/sdk/src/account.rs +++ b/sdk/src/account.rs @@ -1,6 +1,8 @@ -use crate::hash::Hash; -use crate::instruction::InstructionError; -use crate::{clock::Epoch, pubkey::Pubkey}; +use crate::{ + hash::Hash, + instruction::InstructionError, + {clock::Epoch, pubkey::Pubkey}, +}; use std::{ cell::{Ref, RefCell, RefMut}, cmp, fmt, diff --git a/sdk/src/account_utils.rs b/sdk/src/account_utils.rs index f996bda6d5..7b97dde5b5 100644 --- a/sdk/src/account_utils.rs +++ b/sdk/src/account_utils.rs @@ -46,8 +46,7 @@ where #[cfg(test)] mod tests { use super::*; - use crate::account::Account; - use crate::pubkey::Pubkey; + use crate::{account::Account, pubkey::Pubkey}; #[test] fn test_account_state() { diff --git a/sdk/src/bank_hash.rs b/sdk/src/bank_hash.rs index 6a769113e8..67b6a36011 100644 --- a/sdk/src/bank_hash.rs +++ b/sdk/src/bank_hash.rs @@ -3,8 +3,7 @@ use bincode::deserialize_from; use rand::{Rng, SeedableRng}; use rand_chacha::ChaChaRng; use serde::{Deserialize, Serialize, Serializer}; -use std::fmt; -use std::io::Cursor; +use std::{fmt, io::Cursor}; // Type for representing a bank accounts state. // Taken by xor of a sha256 of accounts state for lower 32-bytes, and diff --git a/sdk/src/fee_calculator.rs b/sdk/src/fee_calculator.rs index ae286ba895..9c13d2fdad 100644 --- a/sdk/src/fee_calculator.rs +++ b/sdk/src/fee_calculator.rs @@ -133,8 +133,7 @@ impl FeeCalculator { #[cfg(test)] mod tests { use super::*; - use crate::pubkey::Pubkey; - use crate::system_instruction; + use crate::{pubkey::Pubkey, system_instruction}; #[test] fn test_fee_calculator_burn() { diff --git a/sdk/src/hash.rs b/sdk/src/hash.rs index e1a86e5253..9dcd5db471 100644 --- a/sdk/src/hash.rs +++ b/sdk/src/hash.rs @@ -2,10 +2,7 @@ use bs58; use sha2::{Digest, Sha256}; -use std::convert::TryFrom; -use std::fmt; -use std::mem; -use std::str::FromStr; +use std::{convert::TryFrom, fmt, mem, str::FromStr}; pub const HASH_BYTES: usize = 32; #[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] diff --git a/sdk/src/instruction.rs b/sdk/src/instruction.rs index e67505a9c7..f995e842eb 100644 --- a/sdk/src/instruction.rs +++ b/sdk/src/instruction.rs @@ -1,8 +1,6 @@ //! Defines a composable Instruction type and a memory-efficient CompiledInstruction. -use crate::pubkey::Pubkey; -use crate::short_vec; -use crate::system_instruction::SystemError; +use crate::{pubkey::Pubkey, short_vec, system_instruction::SystemError}; use bincode::serialize; use serde::Serialize; diff --git a/sdk/src/loader_instruction.rs b/sdk/src/loader_instruction.rs index 556ae3c4bf..72bcbaf38f 100644 --- a/sdk/src/loader_instruction.rs +++ b/sdk/src/loader_instruction.rs @@ -1,6 +1,8 @@ -use crate::instruction::{AccountMeta, Instruction}; -use crate::pubkey::Pubkey; -use crate::sysvar::rent; +use crate::{ + instruction::{AccountMeta, Instruction}, + pubkey::Pubkey, + sysvar::rent, +}; #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub enum LoaderInstruction { diff --git a/sdk/src/message.rs b/sdk/src/message.rs index 68af07c647..294159d5ae 100644 --- a/sdk/src/message.rs +++ b/sdk/src/message.rs @@ -1,9 +1,11 @@ //! A library for generating a message from a sequence of instructions -use crate::hash::Hash; -use crate::instruction::{AccountMeta, CompiledInstruction, Instruction}; -use crate::pubkey::Pubkey; -use crate::short_vec; +use crate::{ + hash::Hash, + instruction::{AccountMeta, CompiledInstruction, Instruction}, + pubkey::Pubkey, + short_vec, +}; use itertools::Itertools; fn position(keys: &[Pubkey], key: &Pubkey) -> u8 { @@ -245,8 +247,10 @@ impl Message { #[cfg(test)] mod tests { use super::*; - use crate::instruction::AccountMeta; - use crate::signature::{Keypair, KeypairUtil}; + use crate::{ + instruction::AccountMeta, + signature::{Keypair, KeypairUtil}, + }; #[test] fn test_message_unique_program_ids() { diff --git a/sdk/src/native_loader.rs b/sdk/src/native_loader.rs index a401e2f60f..e7bdff6d4b 100644 --- a/sdk/src/native_loader.rs +++ b/sdk/src/native_loader.rs @@ -1,5 +1,4 @@ -use crate::account::Account; -use crate::hash::Hash; +use crate::{account::Account, hash::Hash}; crate::declare_id!("NativeLoader1111111111111111111111111111111"); diff --git a/sdk/src/nonce_state.rs b/sdk/src/nonce_state.rs index a00fd89d51..5c9a100b3b 100644 --- a/sdk/src/nonce_state.rs +++ b/sdk/src/nonce_state.rs @@ -6,8 +6,7 @@ use crate::{ pubkey::Pubkey, system_instruction::NonceError, system_program, - sysvar::recent_blockhashes::RecentBlockhashes, - sysvar::rent::Rent, + sysvar::{recent_blockhashes::RecentBlockhashes, rent::Rent}, }; use serde_derive::{Deserialize, Serialize}; use std::{cell::RefCell, collections::HashSet}; diff --git a/sdk/src/packet.rs b/sdk/src/packet.rs index a754315465..47d0fac369 100644 --- a/sdk/src/packet.rs +++ b/sdk/src/packet.rs @@ -1,8 +1,10 @@ use crate::clock::Slot; use bincode::Result; use serde::Serialize; -use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; -use std::{fmt, io}; +use std::{ + net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}, + {fmt, io}, +}; /// Maximum over-the-wire size of a Transaction /// 1280 is IPv6 minimum MTU diff --git a/sdk/src/pubkey.rs b/sdk/src/pubkey.rs index faf3b0b484..860bcb56ae 100644 --- a/sdk/src/pubkey.rs +++ b/sdk/src/pubkey.rs @@ -1,8 +1,4 @@ -use std::convert::TryFrom; -use std::error; -use std::fmt; -use std::mem; -use std::str::FromStr; +use std::{convert::TryFrom, error, fmt, mem, str::FromStr}; pub use bs58; diff --git a/sdk/src/short_vec.rs b/sdk/src/short_vec.rs index 38b1e92aed..32f22b1d5a 100644 --- a/sdk/src/short_vec.rs +++ b/sdk/src/short_vec.rs @@ -1,9 +1,9 @@ -use serde::de::{self, Deserializer, SeqAccess, Visitor}; -use serde::ser::{self, SerializeTuple, Serializer}; -use serde::{Deserialize, Serialize}; -use std::fmt; -use std::marker::PhantomData; -use std::mem::size_of; +use serde::{ + de::{self, Deserializer, SeqAccess, Visitor}, + ser::{self, SerializeTuple, Serializer}, + {Deserialize, Serialize}, +}; +use std::{fmt, marker::PhantomData, mem::size_of}; /// Same as u16, but serialized with 1 to 3 bytes. If the value is above /// 0x7f, the top bit is set and the remaining value is stored in the next diff --git a/sdk/src/system_instruction.rs b/sdk/src/system_instruction.rs index 71508dcb4b..e69f4a0005 100644 --- a/sdk/src/system_instruction.rs +++ b/sdk/src/system_instruction.rs @@ -1,10 +1,12 @@ -use crate::hash::hashv; -use crate::instruction::{AccountMeta, Instruction, WithSigner}; -use crate::instruction_processor_utils::DecodeError; -use crate::nonce_state::NonceState; -use crate::pubkey::Pubkey; -use crate::system_program; -use crate::sysvar::{recent_blockhashes, rent}; +use crate::{ + hash::hashv, + instruction::{AccountMeta, Instruction, WithSigner}, + instruction_processor_utils::DecodeError, + nonce_state::NonceState, + pubkey::Pubkey, + system_program, + sysvar::{recent_blockhashes, rent}, +}; use num_derive::{FromPrimitive, ToPrimitive}; use thiserror::Error; diff --git a/sdk/src/sysvar/recent_blockhashes.rs b/sdk/src/sysvar/recent_blockhashes.rs index 874a74d877..e12af3afc6 100644 --- a/sdk/src/sysvar/recent_blockhashes.rs +++ b/sdk/src/sysvar/recent_blockhashes.rs @@ -4,9 +4,7 @@ use crate::{ sysvar::Sysvar, }; use bincode::serialize; -use std::collections::BinaryHeap; -use std::iter::FromIterator; -use std::ops::Deref; +use std::{collections::BinaryHeap, iter::FromIterator, ops::Deref}; const MAX_ENTRIES: usize = 32; diff --git a/sdk/src/transaction.rs b/sdk/src/transaction.rs index 068f9c826a..6cae3704a4 100644 --- a/sdk/src/transaction.rs +++ b/sdk/src/transaction.rs @@ -1,12 +1,14 @@ //! Defines a Transaction type to package an atomic sequence of instructions. -use crate::hash::Hash; -use crate::instruction::{CompiledInstruction, Instruction, InstructionError}; -use crate::message::Message; -use crate::pubkey::Pubkey; -use crate::short_vec; -use crate::signature::{KeypairUtil, Signature}; -use crate::system_instruction; +use crate::{ + hash::Hash, + instruction::{CompiledInstruction, Instruction, InstructionError}, + message::Message, + pubkey::Pubkey, + short_vec, + signature::{KeypairUtil, Signature}, + system_instruction, +}; use bincode::serialize; use std::result; use thiserror::Error; @@ -337,10 +339,7 @@ impl Transaction { #[cfg(test)] mod tests { use super::*; - use crate::hash::hash; - use crate::instruction::AccountMeta; - use crate::signature::Keypair; - use crate::system_instruction; + use crate::{hash::hash, instruction::AccountMeta, signature::Keypair, system_instruction}; use bincode::{deserialize, serialize, serialized_size}; use std::mem::size_of; diff --git a/sdk/src/transport.rs b/sdk/src/transport.rs index ea0308ca75..6306893548 100644 --- a/sdk/src/transport.rs +++ b/sdk/src/transport.rs @@ -1,7 +1,5 @@ use crate::transaction::TransactionError; -use std::error; -use std::fmt; -use std::io; +use std::{error, fmt, io}; #[derive(Debug)] pub enum TransportError {