From e7c380836ba8270653ef86627e2149e5dfc17581 Mon Sep 17 00:00:00 2001 From: yeastplume Date: Fri, 22 Jun 2018 09:44:38 +0100 Subject: [PATCH] rustfmt --- api/src/lib.rs | 3 +- chain/src/chain.rs | 38 ++++++++++---------- chain/src/lib.rs | 2 +- chain/src/store.rs | 2 +- chain/src/txhashset.rs | 21 +++++++---- chain/src/types.rs | 3 -- core/fuzz/fuzz_targets/block_read.rs | 2 +- core/fuzz/fuzz_targets/compact_block_read.rs | 2 +- core/fuzz/fuzz_targets/transaction_read.rs | 2 +- core/src/core/block.rs | 3 +- core/src/genesis.rs | 2 +- servers/src/mining/mod.rs | 4 +-- src/bin/grin.rs | 2 +- src/bin/tui/mod.rs | 10 +++--- store/src/lib.rs | 2 +- util/src/hex.rs | 1 - util/src/lib.rs | 2 +- util/src/zip.rs | 3 +- util/tests/zip.rs | 2 +- wallet/src/libwallet/internal/tx.rs | 3 +- 20 files changed, 54 insertions(+), 55 deletions(-) diff --git a/api/src/lib.rs b/api/src/lib.rs index db8eec8a9..cc3609adc 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -19,7 +19,6 @@ extern crate grin_pool as pool; extern crate grin_store as store; extern crate grin_util as util; - extern crate failure; #[macro_use] extern crate failure_derive; @@ -45,5 +44,5 @@ mod rest; mod types; pub use handlers::start_rest_apis; -pub use types::*; pub use rest::*; +pub use types::*; diff --git a/chain/src/chain.rs b/chain/src/chain.rs index ce0a94ac4..da0c1727d 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -25,8 +25,7 @@ use lmdb; use core::core::hash::{Hash, Hashed}; use core::core::merkle_proof::MerkleProof; use core::core::target::Difficulty; -use core::core::{Block, BlockHeader, Output, OutputIdentifier, Transaction, - TxKernel}; +use core::core::{Block, BlockHeader, Output, OutputIdentifier, Transaction, TxKernel}; use core::global; use grin_store::Error::NotFoundErr; use pipe; @@ -436,25 +435,25 @@ impl Chain { }) } -/// Sets the txhashset roots on a brand new block by applying the block on -/// the current txhashset state. -pub fn set_txhashset_roots(&self, b: &mut Block, is_fork: bool) -> Result<(), Error> { - let mut txhashset = self.txhashset.write().unwrap(); - let store = self.store.clone(); + /// Sets the txhashset roots on a brand new block by applying the block on + /// the current txhashset state. + pub fn set_txhashset_roots(&self, b: &mut Block, is_fork: bool) -> Result<(), Error> { + let mut txhashset = self.txhashset.write().unwrap(); + let store = self.store.clone(); - let roots = txhashset::extending_readonly(&mut txhashset, |extension| { - if is_fork { - pipe::rewind_and_apply_fork(b, store, extension)?; - } - extension.apply_block(b)?; - Ok(extension.roots()) - })?; + let roots = txhashset::extending_readonly(&mut txhashset, |extension| { + if is_fork { + pipe::rewind_and_apply_fork(b, store, extension)?; + } + extension.apply_block(b)?; + Ok(extension.roots()) + })?; - b.header.output_root = roots.output_root; - b.header.range_proof_root = roots.rproof_root; - b.header.kernel_root = roots.kernel_root; - Ok(()) -} + b.header.output_root = roots.output_root; + b.header.range_proof_root = roots.rproof_root; + b.header.kernel_root = roots.kernel_root; + Ok(()) + } /// Return a pre-built Merkle proof for the given commitment from the store. pub fn get_merkle_proof( @@ -826,7 +825,6 @@ fn setup_head( // to match the provided block header. let header = store.get_block_header(&head.last_block_h)?; - let res = txhashset::extending(txhashset, &mut batch, |extension| { extension.rewind(&header, &head_header, true, true, true)?; extension.validate_roots(&header)?; diff --git a/chain/src/lib.rs b/chain/src/lib.rs index bc94ee0ad..bb2303bed 100644 --- a/chain/src/lib.rs +++ b/chain/src/lib.rs @@ -23,8 +23,8 @@ #[macro_use] extern crate bitflags; extern crate byteorder; -extern crate lmdb_zero as lmdb; extern crate croaring; +extern crate lmdb_zero as lmdb; extern crate lru_cache; extern crate serde; #[macro_use] diff --git a/chain/src/store.rs b/chain/src/store.rs index 0d63613ac..e16d3192d 100644 --- a/chain/src/store.rs +++ b/chain/src/store.rs @@ -16,8 +16,8 @@ use std::sync::{Arc, RwLock}; -use lmdb; use croaring::Bitmap; +use lmdb; use lru_cache::LruCache; use util::secp::pedersen::Commitment; diff --git a/chain/src/txhashset.rs b/chain/src/txhashset.rs index 917adcfb7..31a7a531a 100644 --- a/chain/src/txhashset.rs +++ b/chain/src/txhashset.rs @@ -458,7 +458,15 @@ impl<'a> Extension<'a> { let rewind_add_pos: Bitmap = ((output_pos + 1)..(latest_output_pos + 1)) .map(|x| x as u32) .collect(); - self.rewind_to_pos(output_pos, kernel_pos, &rewind_add_pos, rewind_rm_pos, true, true, true)?; + self.rewind_to_pos( + output_pos, + kernel_pos, + &rewind_add_pos, + rewind_rm_pos, + true, + true, + true, + )?; Ok(()) } @@ -483,7 +491,8 @@ impl<'a> Extension<'a> { // Build bitmap of output pos spent (as inputs) by this tx for rewind. let rewind_rm_pos = tx.inputs .iter() - .filter_map(|x| self.get_output_pos(&x.commitment()).ok()) .map(|x| x as u32) + .filter_map(|x| self.get_output_pos(&x.commitment()).ok()) + .map(|x| x as u32) .collect(); for ref output in &tx.outputs { @@ -792,7 +801,7 @@ impl<'a> Extension<'a> { &rewind_rm_pos, rewind_utxo, rewind_kernel, - rewind_rangeproof + rewind_rangeproof, )?; Ok(()) @@ -916,10 +925,8 @@ impl<'a> Extension<'a> { // The real magicking happens here. // Sum of kernel excesses should equal sum of // unspent outputs minus total supply. - let (output_sum, kernel_sum) = self.verify_kernel_sums( - header.total_overage(), - header.total_kernel_offset(), - )?; + let (output_sum, kernel_sum) = + self.verify_kernel_sums(header.total_overage(), header.total_kernel_offset())?; // This is an expensive verification step. self.verify_kernel_signatures()?; diff --git a/chain/src/types.rs b/chain/src/types.rs index 8140b7bda..cabb5d713 100644 --- a/chain/src/types.rs +++ b/chain/src/types.rs @@ -346,6 +346,3 @@ impl Default for BlockSums { } } } - - - diff --git a/core/fuzz/fuzz_targets/block_read.rs b/core/fuzz/fuzz_targets/block_read.rs index 23186ac22..6f110d14d 100644 --- a/core/fuzz/fuzz_targets/block_read.rs +++ b/core/fuzz/fuzz_targets/block_read.rs @@ -3,8 +3,8 @@ extern crate grin_core; #[macro_use] extern crate libfuzzer_sys; -use grin_core::ser; use grin_core::core::block; +use grin_core::ser; fuzz_target!(|data: &[u8]| { let mut d = data.clone(); diff --git a/core/fuzz/fuzz_targets/compact_block_read.rs b/core/fuzz/fuzz_targets/compact_block_read.rs index 8e503c546..cb36a8888 100644 --- a/core/fuzz/fuzz_targets/compact_block_read.rs +++ b/core/fuzz/fuzz_targets/compact_block_read.rs @@ -3,8 +3,8 @@ extern crate grin_core; #[macro_use] extern crate libfuzzer_sys; -use grin_core::ser; use grin_core::core::block; +use grin_core::ser; fuzz_target!(|data: &[u8]| { let mut d = data.clone(); diff --git a/core/fuzz/fuzz_targets/transaction_read.rs b/core/fuzz/fuzz_targets/transaction_read.rs index acc4927f2..c74497b0e 100644 --- a/core/fuzz/fuzz_targets/transaction_read.rs +++ b/core/fuzz/fuzz_targets/transaction_read.rs @@ -3,8 +3,8 @@ extern crate grin_core; #[macro_use] extern crate libfuzzer_sys; -use grin_core::ser; use grin_core::core::transaction; +use grin_core::ser; fuzz_target!(|data: &[u8]| { let mut d = data.clone(); diff --git a/core/src/core/block.rs b/core/src/core/block.rs index 539453f61..d5d14301b 100644 --- a/core/src/core/block.rs +++ b/core/src/core/block.rs @@ -702,7 +702,8 @@ impl Block { vec![prev_kernel_offset.clone()], )? }; - let (_utxo_sum, kernel_sum) = self.verify_kernel_sums(self.header.overage(), block_kernel_offset)?; + let (_utxo_sum, kernel_sum) = + self.verify_kernel_sums(self.header.overage(), block_kernel_offset)?; // check the block header's total kernel sum let total_sum = committed::sum_commits(vec![kernel_sum, prev_kernel_sum.clone()], vec![])?; diff --git a/core/src/genesis.rs b/core/src/genesis.rs index 9109e2704..f981c59ff 100644 --- a/core/src/genesis.rs +++ b/core/src/genesis.rs @@ -16,8 +16,8 @@ use time; -use core; use consensus; +use core; use core::target::Difficulty; use global; diff --git a/servers/src/mining/mod.rs b/servers/src/mining/mod.rs index 2dcf3caa9..e07e20176 100644 --- a/servers/src/mining/mod.rs +++ b/servers/src/mining/mod.rs @@ -14,6 +14,6 @@ //! Mining + Mining server -pub mod test_miner; -pub mod stratumserver; mod mine_block; +pub mod stratumserver; +pub mod test_miner; diff --git a/src/bin/grin.rs b/src/bin/grin.rs index e55ceca8c..780acf51b 100644 --- a/src/bin/grin.rs +++ b/src/bin/grin.rs @@ -40,8 +40,8 @@ pub mod tui; use std::env::current_dir; use std::process::exit; -use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicBool, Ordering}; use std::thread; use std::time::Duration; diff --git a/src/bin/tui/mod.rs b/src/bin/tui/mod.rs index 04316cd8c..343e7ca72 100644 --- a/src/bin/tui/mod.rs +++ b/src/bin/tui/mod.rs @@ -15,12 +15,12 @@ //! Grin TUI extern crate chrono; -pub mod ui; -pub mod table; -mod peers; mod constants; mod menu; -mod status; mod mining; -mod version; +mod peers; +mod status; +pub mod table; mod types; +pub mod ui; +mod version; diff --git a/store/src/lib.rs b/store/src/lib.rs index fd162dcdd..1dfca2ac5 100644 --- a/store/src/lib.rs +++ b/store/src/lib.rs @@ -34,8 +34,8 @@ extern crate slog; extern crate grin_core as core; extern crate grin_util as util; -mod lmdb; pub mod leaf_set; +mod lmdb; pub mod pmmr; pub mod rm_log; pub mod types; diff --git a/util/src/hex.rs b/util/src/hex.rs index 683addf2b..8d764cf79 100644 --- a/util/src/hex.rs +++ b/util/src/hex.rs @@ -16,7 +16,6 @@ /// to bytes. Given that rustc-serialize is deprecated and serde doesn't /// provide easy hex encoding, hex is a bit in limbo right now in Rust- /// land. It's simple enough that we can just have our own. - use std::fmt::Write; use std::num; diff --git a/util/src/lib.rs b/util/src/lib.rs index 5a5006fe9..c62a8534f 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -54,10 +54,10 @@ pub mod types; pub use types::{LogLevel, LoggingConfig}; // other utils +use byteorder::{BigEndian, ByteOrder}; use std::cell::{Ref, RefCell}; #[allow(unused_imports)] use std::ops::Deref; -use byteorder::{BigEndian, ByteOrder}; mod hex; pub use hex::*; diff --git a/util/src/zip.rs b/util/src/zip.rs index 765553928..228c33c25 100644 --- a/util/src/zip.rs +++ b/util/src/zip.rs @@ -12,12 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::fs::{self, File}; /// Wrappers around the `zip-rs` library to compress and decompress zip /// bzip2 archives. - use std::io; use std::path::Path; -use std::fs::{self, File}; use walkdir::WalkDir; use zip_rs; diff --git a/util/tests/zip.rs b/util/tests/zip.rs index 035292b46..54cbab7d4 100644 --- a/util/tests/zip.rs +++ b/util/tests/zip.rs @@ -15,8 +15,8 @@ extern crate grin_util as util; use std::fs::{self, File}; -use std::path::Path; use std::io::{self, Write}; +use std::path::Path; use util::zip; #[test] diff --git a/wallet/src/libwallet/internal/tx.rs b/wallet/src/libwallet/internal/tx.rs index 0d1e3f9cc..7b00a3501 100644 --- a/wallet/src/libwallet/internal/tx.rs +++ b/wallet/src/libwallet/internal/tx.rs @@ -163,8 +163,7 @@ where debug!(LOGGER, "selected some coins - {}", coins.len()); let fee = tx_fee(coins.len(), 2, selection::coins_proof_count(&coins), None); - let (mut parts, _, _) = - selection::inputs_and_change(&coins, wallet, amount, fee)?; + let (mut parts, _, _) = selection::inputs_and_change(&coins, wallet, amount, fee)?; //TODO: If we end up using this, create change output here