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:20:02 -08:00
parent 5a7b487e3d
commit 139d15cd84
380 changed files with 6067 additions and 5293 deletions

View File

@@ -1,12 +1,16 @@
#![feature(test)]
extern crate test;
use bincode::{deserialize, serialize};
use solana_sdk::instruction::{AccountMeta, Instruction};
use solana_sdk::message::Message;
use solana_sdk::pubkey;
use solana_sdk::sysvar::instructions;
use test::Bencher;
use {
bincode::{deserialize, serialize},
solana_sdk::{
instruction::{AccountMeta, Instruction},
message::Message,
pubkey,
sysvar::instructions,
},
test::Bencher,
};
fn make_instructions() -> Vec<Instruction> {
let meta = AccountMeta::new(pubkey::new_rand(), false);

View File

@@ -1,9 +1,7 @@
#![feature(test)]
extern crate test;
use bincode::deserialize;
use solana_sdk::short_vec::ShortVec;
use test::Bencher;
use {bincode::deserialize, solana_sdk::short_vec::ShortVec, test::Bencher};
// Return a ShortVec with 127 bytes
fn create_encoded_short_vec() -> Vec<u8> {

View File

@@ -1,12 +1,14 @@
#![feature(test)]
extern crate test;
use solana_sdk::{
account::{create_account_for_test, from_account},
hash::Hash,
slot_hashes::{Slot, SlotHashes, MAX_ENTRIES},
use {
solana_sdk::{
account::{create_account_for_test, from_account},
hash::Hash,
slot_hashes::{Slot, SlotHashes, MAX_ENTRIES},
},
test::Bencher,
};
use test::Bencher;
#[bench]
fn bench_to_from_account(b: &mut Bencher) {

View File

@@ -1,11 +1,13 @@
#![feature(test)]
extern crate test;
use solana_sdk::{
account::{create_account_for_test, from_account},
slot_history::SlotHistory,
use {
solana_sdk::{
account::{create_account_for_test, from_account},
slot_history::SlotHistory,
},
test::Bencher,
};
use test::Bencher;
#[bench]
fn bench_to_from_account(b: &mut Bencher) {

View File

@@ -13,8 +13,7 @@ use {
fs::{self, File},
io::{prelude::*, BufReader, BufWriter},
path::{Path, PathBuf},
process::exit,
process::{Command, Stdio},
process::{exit, Command, Stdio},
str::FromStr,
},
tar::Archive,

View File

@@ -1,12 +1,13 @@
use clap::{
crate_description, crate_name, crate_version, value_t, values_t, App, AppSettings, Arg,
};
use std::{
env,
ffi::OsStr,
path::{Path, PathBuf},
process::exit,
process::Command,
use {
clap::{
crate_description, crate_name, crate_version, value_t, values_t, App, AppSettings, Arg,
},
std::{
env,
ffi::OsStr,
path::{Path, PathBuf},
process::{exit, Command},
},
};
struct Config {

View File

@@ -4,17 +4,19 @@
extern crate proc_macro;
use proc_macro::TokenStream;
use proc_macro2::{Delimiter, Span, TokenTree};
use quote::{quote, ToTokens};
use std::convert::TryFrom;
use syn::{
bracketed,
parse::{Parse, ParseStream, Result},
parse_macro_input,
punctuated::Punctuated,
token::Bracket,
Expr, Ident, LitByte, LitStr, Path, Token,
use {
proc_macro::TokenStream,
proc_macro2::{Delimiter, Span, TokenTree},
quote::{quote, ToTokens},
std::convert::TryFrom,
syn::{
bracketed,
parse::{Parse, ParseStream, Result},
parse_macro_input,
punctuated::Punctuated,
token::Bracket,
Expr, Ident, LitByte, LitStr, Path, Token,
},
};
fn parse_id(

View File

@@ -1,8 +1,10 @@
use crate::{clock::Epoch, program_error::ProgramError, pubkey::Pubkey};
use std::{
cell::{Ref, RefCell, RefMut},
cmp, fmt,
rc::Rc,
use {
crate::{clock::Epoch, program_error::ProgramError, pubkey::Pubkey},
std::{
cell::{Ref, RefCell, RefMut},
cmp, fmt,
rc::Rc,
},
};
/// Account information

View File

@@ -8,13 +8,15 @@
//! upgradeable programs which still have a functioning authority. For more
//! information refer to `loader_upgradeable_instruction.rs`
use crate::{
instruction::{AccountMeta, Instruction, InstructionError},
loader_upgradeable_instruction::UpgradeableLoaderInstruction,
pubkey::Pubkey,
system_instruction, sysvar,
use {
crate::{
instruction::{AccountMeta, Instruction, InstructionError},
loader_upgradeable_instruction::UpgradeableLoaderInstruction,
pubkey::Pubkey,
system_instruction, sysvar,
},
bincode::serialized_size,
};
use bincode::serialized_size;
crate::declare_id!("BPFLoaderUpgradeab1e11111111111111111111111");

View File

@@ -13,8 +13,7 @@ pub trait DecodeError<E> {
#[cfg(test)]
mod tests {
use super::*;
use num_derive::FromPrimitive;
use {super::*, num_derive::FromPrimitive};
#[test]
fn test_decode_custom_error_to_enum() {

View File

@@ -2,17 +2,18 @@
//! BPFLoader. For more information see './bpf_loader.rs'
extern crate alloc;
use crate::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey};
use alloc::vec::Vec;
use std::{
alloc::Layout,
cell::RefCell,
mem::size_of,
ptr::null_mut,
rc::Rc,
// Hide Result from bindgen gets confused about generics in non-generic type declarations
result::Result as ResultGeneric,
slice::{from_raw_parts, from_raw_parts_mut},
use {
crate::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey},
alloc::vec::Vec,
std::{
alloc::Layout,
cell::RefCell,
mem::size_of,
ptr::null_mut,
rc::Rc,
result::Result as ResultGeneric,
slice::{from_raw_parts, from_raw_parts_mut},
},
};
pub type ProgramResult = ResultGeneric<(), ProgramError>;
@@ -354,8 +355,7 @@ pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a
#[cfg(test)]
mod test {
use super::*;
use std::alloc::GlobalAlloc;
use {super::*, std::alloc::GlobalAlloc};
#[test]
fn test_bump_allocator() {

View File

@@ -4,15 +4,16 @@
//! './bpf_loader_deprecated.rs'
extern crate alloc;
use crate::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey};
use alloc::vec::Vec;
use std::{
cell::RefCell,
mem::size_of,
rc::Rc,
// Hide Result from bindgen gets confused about generics in non-generic type declarations
result::Result as ResultGeneric,
slice::{from_raw_parts, from_raw_parts_mut},
use {
crate::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey},
alloc::vec::Vec,
std::{
cell::RefCell,
mem::size_of,
rc::Rc,
result::Result as ResultGeneric,
slice::{from_raw_parts, from_raw_parts_mut},
},
};
pub type ProgramResult = ResultGeneric<(), ProgramError>;

View File

@@ -58,8 +58,7 @@ pub fn activate_with_lamports(
#[cfg(test)]
mod test {
use super::*;
use solana_program::clock::Slot;
use {super::*, solana_program::clock::Slot};
#[test]
fn feature_sizeof() {

View File

@@ -1,9 +1,8 @@
#![allow(clippy::integer_arithmetic)]
use crate::clock::DEFAULT_MS_PER_SLOT;
use crate::ed25519_program;
use crate::message::Message;
use crate::secp256k1_program;
use log::*;
use {
crate::{clock::DEFAULT_MS_PER_SLOT, ed25519_program, message::Message, secp256k1_program},
log::*,
};
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, AbiExample)]
#[serde(rename_all = "camelCase")]
@@ -180,8 +179,10 @@ impl FeeRateGovernor {
#[cfg(test)]
mod tests {
use super::*;
use crate::{pubkey::Pubkey, system_instruction};
use {
super::*,
crate::{pubkey::Pubkey, system_instruction},
};
#[test]
fn test_fee_rate_governor_burn() {

View File

@@ -1,10 +1,12 @@
//! The `hash` module provides functions for creating SHA-256 hashes.
use crate::sanitize::Sanitize;
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use sha2::{Digest, Sha256};
use std::{convert::TryFrom, fmt, mem, str::FromStr};
use thiserror::Error;
use {
crate::sanitize::Sanitize,
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
sha2::{Digest, Sha256},
std::{convert::TryFrom, fmt, mem, str::FromStr},
thiserror::Error,
};
pub const HASH_BYTES: usize = 32;
/// Maximum string length of a base58 encoded hash

View File

@@ -1,12 +1,13 @@
#![allow(clippy::integer_arithmetic)]
//! Defines a composable Instruction type and a memory-efficient CompiledInstruction.
use crate::sanitize::Sanitize;
use crate::{pubkey::Pubkey, short_vec};
use bincode::serialize;
use borsh::BorshSerialize;
use serde::Serialize;
use thiserror::Error;
use {
crate::{pubkey::Pubkey, sanitize::Sanitize, short_vec},
bincode::serialize,
borsh::BorshSerialize,
serde::Serialize,
thiserror::Error,
};
/// Reasons the runtime might have rejected an instruction.
///

View File

@@ -1,8 +1,10 @@
use crate::sanitize::Sanitize;
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use sha3::{Digest, Keccak256};
use std::{convert::TryFrom, fmt, mem, str::FromStr};
use thiserror::Error;
use {
crate::sanitize::Sanitize,
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
sha3::{Digest, Keccak256},
std::{convert::TryFrom, fmt, mem, str::FromStr},
thiserror::Error,
};
pub const HASH_BYTES: usize = 32;
/// Maximum string length of a base58 encoded hash

View File

@@ -1,5 +1,4 @@
use crate::instruction::InstructionError;
use thiserror::Error;
use {crate::instruction::InstructionError, thiserror::Error};
#[derive(Debug, Error)]
pub enum LamportsError {

View File

@@ -1,20 +1,22 @@
#![allow(clippy::integer_arithmetic)]
//! A library for generating a message from a sequence of instructions
use crate::sanitize::{Sanitize, SanitizeError};
use crate::serialize_utils::{
append_slice, append_u16, append_u8, read_pubkey, read_slice, read_u16, read_u8,
use {
crate::{
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable,
hash::Hash,
instruction::{AccountMeta, CompiledInstruction, Instruction},
pubkey::Pubkey,
sanitize::{Sanitize, SanitizeError},
serialize_utils::{
append_slice, append_u16, append_u8, read_pubkey, read_slice, read_u16, read_u8,
},
short_vec, system_instruction, system_program, sysvar,
},
itertools::Itertools,
lazy_static::lazy_static,
std::{convert::TryFrom, str::FromStr},
};
use crate::{
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable,
hash::Hash,
instruction::{AccountMeta, CompiledInstruction, Instruction},
pubkey::Pubkey,
short_vec, system_instruction, system_program, sysvar,
};
use itertools::Itertools;
use lazy_static::lazy_static;
use std::{convert::TryFrom, str::FromStr};
lazy_static! {
// Copied keys over since direct references create cyclical dependency.
@@ -549,9 +551,11 @@ impl Message {
#[cfg(test)]
mod tests {
use super::*;
use crate::{hash, instruction::AccountMeta};
use std::collections::HashSet;
use {
super::*,
crate::{hash, instruction::AccountMeta},
std::collections::HashSet,
};
#[test]
fn test_message_unique_program_ids() {

View File

@@ -1,6 +1,8 @@
use super::Versions;
use crate::{fee_calculator::FeeCalculator, hash::Hash, pubkey::Pubkey};
use serde_derive::{Deserialize, Serialize};
use {
super::Versions,
crate::{fee_calculator::FeeCalculator, hash::Hash, pubkey::Pubkey},
serde_derive::{Deserialize, Serialize},
};
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone)]
pub struct Data {

View File

@@ -1,6 +1,5 @@
mod current;
pub use current::{Data, State};
use serde_derive::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]

View File

@@ -1,9 +1,11 @@
#![allow(clippy::integer_arithmetic)]
use crate::{decode_error::DecodeError, instruction::InstructionError, msg, pubkey::PubkeyError};
use borsh::maybestd::io::Error as BorshIoError;
use num_traits::{FromPrimitive, ToPrimitive};
use std::convert::TryFrom;
use thiserror::Error;
use {
crate::{decode_error::DecodeError, instruction::InstructionError, msg, pubkey::PubkeyError},
borsh::maybestd::io::Error as BorshIoError,
num_traits::{FromPrimitive, ToPrimitive},
std::convert::TryFrom,
thiserror::Error,
};
/// Reasons the program may fail
#[derive(Clone, Debug, Deserialize, Eq, Error, PartialEq, Serialize)]

View File

@@ -2,12 +2,14 @@
#![cfg(not(target_arch = "bpf"))]
use crate::{
account_info::AccountInfo, entrypoint::ProgramResult, instruction::Instruction,
program_error::UNSUPPORTED_SYSVAR, pubkey::Pubkey,
use {
crate::{
account_info::AccountInfo, entrypoint::ProgramResult, instruction::Instruction,
program_error::UNSUPPORTED_SYSVAR, pubkey::Pubkey,
},
itertools::Itertools,
std::sync::{Arc, RwLock},
};
use itertools::Itertools;
use std::sync::{Arc, RwLock};
lazy_static::lazy_static! {
static ref SYSCALL_STUBS: Arc<RwLock<Box<dyn SyscallStubs>>> = Arc::new(RwLock::new(Box::new(DefaultSyscallStubs {})));

View File

@@ -393,8 +393,7 @@ impl fmt::Display for Pubkey {
#[cfg(test)]
mod tests {
use super::*;
use std::str::from_utf8;
use {super::*, std::str::from_utf8};
#[test]
fn test_new_unique() {

View File

@@ -1,6 +1,8 @@
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use core::convert::TryFrom;
use thiserror::Error;
use {
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
core::convert::TryFrom,
thiserror::Error,
};
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum Secp256k1RecoverError {

View File

@@ -1,6 +1,5 @@
#![allow(clippy::integer_arithmetic)]
use crate::pubkey::Pubkey;
use crate::sanitize::SanitizeError;
use crate::{pubkey::Pubkey, sanitize::SanitizeError};
pub fn append_u16(buf: &mut Vec<u8>, data: u16) {
let start = buf.len();

View File

@@ -1,10 +1,12 @@
#![allow(clippy::integer_arithmetic)]
use serde::{
de::{self, Deserializer, SeqAccess, Visitor},
ser::{self, SerializeTuple, Serializer},
{Deserialize, Serialize},
use {
serde::{
de::{self, Deserializer, SeqAccess, Visitor},
ser::{self, SerializeTuple, Serializer},
Deserialize, Serialize,
},
std::{convert::TryFrom, fmt, marker::PhantomData},
};
use std::{convert::TryFrom, fmt, marker::PhantomData};
/// 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
@@ -265,9 +267,11 @@ pub fn decode_shortu16_len(bytes: &[u8]) -> Result<(usize, usize), ()> {
#[cfg(test)]
mod tests {
use super::*;
use assert_matches::assert_matches;
use bincode::{deserialize, serialize};
use {
super::*,
assert_matches::assert_matches,
bincode::{deserialize, serialize},
};
/// Return the serialized length.
fn encode_len(len: u16) -> Vec<u8> {

View File

@@ -2,8 +2,10 @@
//!
//! this account carries the Bank's most recent bank hashes for some N parents
//!
use crate::hash::Hash;
use std::{iter::FromIterator, ops::Deref};
use {
crate::hash::Hash,
std::{iter::FromIterator, ops::Deref},
};
pub const MAX_ENTRIES: usize = 512; // about 2.5 minutes to get your vote in
@@ -51,8 +53,7 @@ impl Deref for SlotHashes {
#[cfg(test)]
mod tests {
use super::*;
use crate::hash::hash;
use {super::*, crate::hash::hash};
#[test]
fn test() {

View File

@@ -3,8 +3,7 @@
//! slot history
//!
pub use crate::clock::Slot;
use bv::BitVec;
use bv::BitsMut;
use bv::{BitVec, BitsMut};
#[repr(C)]
#[derive(Clone, Serialize, Deserialize, PartialEq)]
@@ -86,8 +85,7 @@ impl SlotHistory {
#[cfg(test)]
mod tests {
use super::*;
use log::*;
use {super::*, log::*};
#[test]
fn slot_history_test1() {

View File

@@ -1,14 +1,14 @@
use {
crate::stake::{
config,
program::id,
state::{Authorized, Lockup, StakeAuthorize, StakeState},
},
crate::{
clock::{Epoch, UnixTimestamp},
decode_error::DecodeError,
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
stake::{
config,
program::id,
state::{Authorized, Lockup, StakeAuthorize, StakeState},
},
system_instruction, sysvar,
},
log::*,
@@ -680,8 +680,7 @@ pub fn set_lockup_checked(
#[cfg(test)]
mod tests {
use super::*;
use crate::instruction::InstructionError;
use {super::*, crate::instruction::InstructionError};
#[test]
fn test_custom_error_decode() {

View File

@@ -3,7 +3,6 @@
//! this account carries history about stake activations and de-activations
//!
pub use crate::clock::Epoch;
use std::ops::Deref;
pub const MAX_ENTRIES: usize = 512; // it should never take as many as 512 epochs to warm up or cool down

View File

@@ -1,13 +1,15 @@
use crate::{
decode_error::DecodeError,
instruction::{AccountMeta, Instruction, InstructionError},
nonce,
pubkey::Pubkey,
system_program,
sysvar::{recent_blockhashes, rent},
use {
crate::{
decode_error::DecodeError,
instruction::{AccountMeta, Instruction, InstructionError},
nonce,
pubkey::Pubkey,
system_program,
sysvar::{recent_blockhashes, rent},
},
num_derive::{FromPrimitive, ToPrimitive},
thiserror::Error,
};
use num_derive::{FromPrimitive, ToPrimitive};
use thiserror::Error;
#[derive(Error, Debug, Serialize, Clone, PartialEq, FromPrimitive, ToPrimitive)]
pub enum SystemError {
@@ -567,9 +569,11 @@ pub fn authorize_nonce_account(
#[cfg(test)]
mod tests {
use super::*;
use crate::instruction::{Instruction, InstructionError};
use num_traits::ToPrimitive;
use {
super::*,
crate::instruction::{Instruction, InstructionError},
num_traits::ToPrimitive,
};
fn get_keys(instruction: &Instruction) -> Vec<Pubkey> {
instruction.accounts.iter().map(|x| x.pubkey).collect()

View File

@@ -1,7 +1,6 @@
//! This account contains the clock slot, epoch, and leader_schedule_epoch
//!
pub use crate::clock::Clock;
use crate::{impl_sysvar_get, program_error::ProgramError, sysvar::Sysvar};
crate::declare_sysvar_id!("SysvarC1ock11111111111111111111111111111111", Clock);

View File

@@ -1,7 +1,6 @@
//! This account contains the current cluster rent
//!
pub use crate::epoch_schedule::EpochSchedule;
use crate::{impl_sysvar_get, program_error::ProgramError, sysvar::Sysvar};
crate::declare_sysvar_id!("SysvarEpochSchedu1e111111111111111111111111", EpochSchedule);

View File

@@ -105,8 +105,10 @@ pub fn get_instruction_relative(
#[cfg(test)]
mod tests {
use super::*;
use crate::{instruction::AccountMeta, message::Message, pubkey::Pubkey};
use {
super::*,
crate::{instruction::AccountMeta, message::Message, pubkey::Pubkey},
};
#[test]
fn test_load_store_instruction() {

View File

@@ -108,9 +108,11 @@ macro_rules! impl_sysvar_get {
#[cfg(test)]
mod tests {
use super::*;
use crate::{clock::Epoch, program_error::ProgramError, pubkey::Pubkey};
use std::{cell::RefCell, rc::Rc};
use {
super::*,
crate::{clock::Epoch, program_error::ProgramError, pubkey::Pubkey},
std::{cell::RefCell, rc::Rc},
};
#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]

View File

@@ -1,11 +1,13 @@
#![allow(clippy::integer_arithmetic)]
use crate::{
declare_sysvar_id,
fee_calculator::FeeCalculator,
hash::{hash, Hash},
sysvar::Sysvar,
use {
crate::{
declare_sysvar_id,
fee_calculator::FeeCalculator,
hash::{hash, Hash},
sysvar::Sysvar,
},
std::{cmp::Ordering, collections::BinaryHeap, iter::FromIterator, ops::Deref},
};
use std::{cmp::Ordering, collections::BinaryHeap, iter::FromIterator, ops::Deref};
pub const MAX_ENTRIES: usize = 150;
@@ -145,8 +147,7 @@ pub fn create_test_recent_blockhashes(start: usize) -> RecentBlockhashes {
#[cfg(test)]
mod tests {
use super::*;
use crate::clock::MAX_PROCESSING_AGE;
use {super::*, crate::clock::MAX_PROCESSING_AGE};
#[test]
#[allow(clippy::assertions_on_constants)]

View File

@@ -1,7 +1,6 @@
//! This account contains the current cluster rent
//!
pub use crate::rent::Rent;
use crate::{impl_sysvar_get, program_error::ProgramError, sysvar::Sysvar};
crate::declare_sysvar_id!("SysvarRent111111111111111111111111111111111", Rent);

View File

@@ -3,7 +3,6 @@
//! this account carries the Bank's most recent bank hashes for some N parents
//!
pub use crate::slot_hashes::SlotHashes;
use crate::{account_info::AccountInfo, program_error::ProgramError, sysvar::Sysvar};
crate::declare_sysvar_id!("SysvarS1otHashes111111111111111111111111111", SlotHashes);
@@ -22,8 +21,10 @@ impl Sysvar for SlotHashes {
#[cfg(test)]
mod tests {
use super::*;
use crate::{clock::Slot, hash::Hash, slot_hashes::MAX_ENTRIES};
use {
super::*,
crate::{clock::Slot, hash::Hash, slot_hashes::MAX_ENTRIES},
};
#[test]
fn test_size_of() {

View File

@@ -3,12 +3,11 @@
//! this account carries a bitvector of slots present over the past
//! epoch
//!
use crate::sysvar::Sysvar;
pub use crate::{
account_info::AccountInfo, program_error::ProgramError, slot_history::SlotHistory,
};
use crate::sysvar::Sysvar;
crate::declare_sysvar_id!("SysvarS1otHistory11111111111111111111111111", SlotHistory);
impl Sysvar for SlotHistory {

View File

@@ -3,7 +3,6 @@
//! this account carries history about stake activations and de-activations
//!
pub use crate::stake_history::StakeHistory;
use crate::sysvar::Sysvar;
crate::declare_sysvar_id!("SysvarStakeHistory1111111111111111111111111", StakeHistory);
@@ -18,8 +17,7 @@ impl Sysvar for StakeHistory {
#[cfg(test)]
mod tests {
use super::*;
use crate::stake_history::*;
use {super::*, crate::stake_history::*};
#[test]
fn test_size_of() {

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

@@ -1,17 +1,19 @@
#![cfg(feature = "full")]
use crate::{
entrypoint::HEAP_LENGTH as MIN_HEAP_FRAME_BYTES,
feature_set::{requestable_heap_size, FeatureSet},
process_instruction::BpfComputeBudget,
transaction::{Transaction, TransactionError},
use {
crate::{
entrypoint::HEAP_LENGTH as MIN_HEAP_FRAME_BYTES,
feature_set::{requestable_heap_size, FeatureSet},
process_instruction::BpfComputeBudget,
transaction::{Transaction, TransactionError},
},
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
solana_sdk::{
borsh::try_from_slice_unchecked,
instruction::{Instruction, InstructionError},
},
std::sync::Arc,
};
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use solana_sdk::{
borsh::try_from_slice_unchecked,
instruction::{Instruction, InstructionError},
};
use std::sync::Arc;
crate::declare_id!("ComputeBudget111111111111111111111111111111");
@@ -91,8 +93,10 @@ pub fn process_request(
#[cfg(test)]
mod tests {
use super::*;
use crate::{hash::Hash, message::Message, pubkey::Pubkey, signature::Keypair, signer::Signer};
use {
super::*,
crate::{hash::Hash, message::Message, pubkey::Pubkey, signature::Keypair, signer::Signer},
};
macro_rules! test {
( $instructions: expr, $expected_error: expr, $expected_budget: expr ) => {

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::{decode_error::DecodeError, instruction::Instruction};
use bytemuck::{bytes_of, Pod, Zeroable};
use ed25519_dalek::{ed25519::signature::Signature, Signer, Verifier};
use thiserror::Error;
use {
crate::{decode_error::DecodeError, instruction::Instruction},
bytemuck::{bytes_of, Pod, Zeroable},
ed25519_dalek::{ed25519::signature::Signature, Signer, Verifier},
thiserror::Error,
};
#[derive(Error, Debug, Clone, PartialEq)]
pub enum Ed25519Error {

View File

@@ -1,10 +1,12 @@
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 instructions_sysvar_enabled {
solana_sdk::declare_id!("EnvhHCLvg55P7PDtbvR1NwuTuAeodqpusV3MR5QEK8gs");

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";
@@ -293,9 +294,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)]
@@ -256,12 +258,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,11 +1,13 @@
use crate::{
account::{AccountSharedData, ReadableAccount},
account_utils::StateMut,
fee_calculator::FeeCalculator,
hash::Hash,
nonce::{state::Versions, State},
use {
crate::{
account::{AccountSharedData, ReadableAccount},
account_utils::StateMut,
fee_calculator::FeeCalculator,
hash::Hash,
nonce::{state::Versions, State},
},
std::cell::RefCell,
};
use std::cell::RefCell;
pub fn create_account(lamports: u64) -> RefCell<AccountSharedData> {
RefCell::new(
@@ -41,8 +43,7 @@ pub fn fee_calculator_of(account: &AccountSharedData) -> Option<FeeCalculator> {
#[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,19 +1,21 @@
use crate::{
account::{ReadableAccount, WritableAccount},
account_utils::State as AccountUtilsState,
feature_set, ic_msg,
keyed_account::KeyedAccount,
nonce_account::create_account,
process_instruction::InvokeContext,
use {
crate::{
account::{ReadableAccount, WritableAccount},
account_utils::State as AccountUtilsState,
feature_set, ic_msg,
keyed_account::KeyedAccount,
nonce_account::create_account,
process_instruction::InvokeContext,
},
solana_program::{
instruction::{checked_add, InstructionError},
nonce::{self, state::Versions, State},
pubkey::Pubkey,
system_instruction::{nonce_to_instruction_error, NonceError},
sysvar::{recent_blockhashes::RecentBlockhashes, rent::Rent},
},
std::collections::HashSet,
};
use solana_program::{
instruction::{checked_add, InstructionError},
nonce::{self, state::Versions, State},
pubkey::Pubkey,
system_instruction::{nonce_to_instruction_error, NonceError},
sysvar::{recent_blockhashes::RecentBlockhashes, rent::Rent},
};
use std::collections::HashSet;
pub trait NonceKeyedAccount {
fn advance_nonce_account(
@@ -294,18 +296,20 @@ where
#[cfg(test)]
mod test {
use super::*;
use crate::{
account::ReadableAccount,
account_utils::State as AccountUtilsState,
keyed_account::KeyedAccount,
nonce::{self, State},
nonce_account::verify_nonce_account,
process_instruction::MockInvokeContext,
system_instruction::SystemError,
sysvar::recent_blockhashes::create_test_recent_blockhashes,
use {
super::*,
crate::{
account::ReadableAccount,
account_utils::State as AccountUtilsState,
keyed_account::KeyedAccount,
nonce::{self, State},
nonce_account::verify_nonce_account,
process_instruction::MockInvokeContext,
system_instruction::SystemError,
sysvar::recent_blockhashes::create_test_recent_blockhashes,
},
solana_program::hash::Hash,
};
use solana_program::hash::Hash;
#[test]
fn default_is_uninitialized() {

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,12 +1,14 @@
use itertools::Itertools;
use solana_sdk::{
account::AccountSharedData,
instruction::{CompiledInstruction, Instruction, InstructionError},
keyed_account::{create_keyed_accounts_unified, KeyedAccount},
pubkey::Pubkey,
sysvar::Sysvar,
use {
itertools::Itertools,
solana_sdk::{
account::AccountSharedData,
instruction::{CompiledInstruction, Instruction, InstructionError},
keyed_account::{create_keyed_accounts_unified, KeyedAccount},
pubkey::Pubkey,
sysvar::Sysvar,
},
std::{cell::RefCell, collections::HashSet, fmt::Debug, rc::Rc, sync::Arc},
};
use std::{cell::RefCell, collections::HashSet, fmt::Debug, rc::Rc, sync::Arc};
/// Prototype of a native loader entry point
///

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,12 +1,16 @@
use crate::account::{
create_account_shared_data_with_fields, to_account, AccountSharedData,
InheritableAccountFields, DUMMY_INHERITABLE_ACCOUNT_FIELDS,
use {
crate::{
account::{
create_account_shared_data_with_fields, to_account, AccountSharedData,
InheritableAccountFields, DUMMY_INHERITABLE_ACCOUNT_FIELDS,
},
clock::INITIAL_RENT_EPOCH,
},
solana_program::sysvar::recent_blockhashes::{
IntoIterSorted, IterItem, RecentBlockhashes, MAX_ENTRIES,
},
std::{collections::BinaryHeap, iter::FromIterator},
};
use crate::clock::INITIAL_RENT_EPOCH;
use solana_program::sysvar::recent_blockhashes::{
IntoIterSorted, IterItem, RecentBlockhashes, MAX_ENTRIES,
};
use std::{collections::BinaryHeap, iter::FromIterator};
pub fn update_account<'a, I>(
account: &mut AccountSharedData,
@@ -57,13 +61,15 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::account::from_account;
use rand::{seq::SliceRandom, thread_rng};
use solana_program::{
fee_calculator::FeeCalculator,
hash::{Hash, HASH_BYTES},
sysvar::recent_blockhashes::Entry,
use {
super::*,
crate::account::from_account,
rand::{seq::SliceRandom, thread_rng},
solana_program::{
fee_calculator::FeeCalculator,
hash::{Hash, HASH_BYTES},
sysvar::recent_blockhashes::Entry,
},
};
#[test]

View File

@@ -1,8 +1,10 @@
#![cfg(feature = "full")]
use crate::instruction::Instruction;
use digest::Digest;
use serde_derive::{Deserialize, Serialize};
use {
crate::instruction::Instruction,
digest::Digest,
serde_derive::{Deserialize, Serialize},
};
#[derive(Debug, PartialEq)]
pub enum Secp256k1Error {

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

@@ -2,26 +2,27 @@
#![cfg(feature = "full")]
use crate::sanitize::{Sanitize, SanitizeError};
use crate::secp256k1_instruction::verify_eth_addresses;
use crate::{
ed25519_instruction::verify_signatures,
feature_set,
hash::Hash,
instruction::{CompiledInstruction, Instruction, InstructionError},
message::Message,
nonce::NONCED_TX_MARKER_IX_INDEX,
program_utils::limited_deserialize,
pubkey::Pubkey,
short_vec,
signature::{Signature, SignerError},
signers::Signers,
system_instruction::SystemInstruction,
system_program,
use {
crate::{
ed25519_instruction::verify_signatures,
feature_set,
hash::Hash,
instruction::{CompiledInstruction, Instruction, InstructionError},
message::Message,
nonce::NONCED_TX_MARKER_IX_INDEX,
program_utils::limited_deserialize,
pubkey::Pubkey,
sanitize::{Sanitize, SanitizeError},
secp256k1_instruction::verify_eth_addresses,
short_vec,
signature::{Signature, SignerError},
signers::Signers,
system_instruction::SystemInstruction,
system_program,
},
std::{result, sync::Arc},
thiserror::Error,
};
use std::result;
use std::sync::Arc;
use thiserror::Error;
/// Reasons a transaction might be rejected.
#[derive(
@@ -519,15 +520,17 @@ pub fn get_nonce_pubkey_from_instruction<'a>(
#[cfg(test)]
mod tests {
use super::*;
use crate::{
hash::hash,
instruction::AccountMeta,
signature::{Keypair, Presigner, Signer},
system_instruction,
use {
super::*,
crate::{
hash::hash,
instruction::AccountMeta,
signature::{Keypair, Presigner, Signer},
system_instruction,
},
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 {