Rustify core/src/core (#1122)

Small refactoring of one folder, if it makes sense I could extend the scope.
* Remove some cloning (real and just verbosity in the code)
* Naming conventions like to/into*
* Some Clippy's suggestions

I found that we don't use field init shorthand syntax, so I didn't touch this part, was it discussed before?
This commit is contained in:
hashmap
2018-06-01 21:41:26 +02:00
committed by Yeastplume
parent 7812a02233
commit 2fa32d15ce
27 changed files with 215 additions and 263 deletions
+2 -3
View File
@@ -181,15 +181,14 @@ fn build_block(
b.header.nonce = rng.gen();
b.header.timestamp = time::at_utc(time::Timespec::new(now_sec, 0));
let b_difficulty =
(b.header.total_difficulty.clone() - head.total_difficulty.clone()).into_num();
let b_difficulty = (b.header.total_difficulty.clone() - head.total_difficulty.clone()).to_num();
debug!(
LOGGER,
"Built new block with {} inputs and {} outputs, network difficulty: {}, cumulative difficulty {}",
b.inputs.len(),
b.outputs.len(),
b_difficulty,
b.header.clone().total_difficulty.clone().into_num(),
b.header.clone().total_difficulty.to_num(),
);
let roots_result = chain.set_txhashset_roots(&mut b, false);
+1 -2
View File
@@ -446,7 +446,6 @@ impl StratumServer {
// Reconstruct the block header with this nonce and pow added
b = self.current_block.clone();
b.header.nonce = submit_params.nonce;
b.header.pow.proof_size = submit_params.pow.len();
b.header.pow.nonces = submit_params.pow;
let res = self.chain.process_block(b.clone(), chain::Options::MINE);
if let Err(e) = res {
@@ -644,7 +643,7 @@ impl StratumServer {
self.current_block = new_block;
self.current_difficulty = (self.current_block.header.total_difficulty.clone()
- head.total_difficulty.clone())
.into_num();
.to_num();
self.current_key_id = block_fees.key_id();
current_hash = latest_hash;
// set a new deadline for rebuilding with fresh transactions
+6 -6
View File
@@ -17,23 +17,23 @@
//! header with its proof-of-work. Any valid mined blocks are submitted to the
//! network.
use std::sync::{Arc, RwLock};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, RwLock};
use time;
use common::adapters::PoolToChainAdapter;
use common::types::StratumServerConfig;
use core::consensus;
use core::core::Proof;
use core::core::{Block, BlockHeader};
use core::core::hash::{Hash, Hashed};
use core::core::{Block, BlockHeader};
use core::pow::cuckoo;
use common::types::StratumServerConfig;
use util::LOGGER;
use chain;
use pool;
use mining::mine_block;
use core::global;
use mining::mine_block;
use pool;
// Max number of transactions this miner will assemble in a block
const MAX_TX: u32 = 5000;
@@ -108,7 +108,7 @@ impl Miner {
global::sizeshift(),
).mine()
{
let proof_diff = proof.clone().to_difficulty();
let proof_diff = proof.to_difficulty();
if proof_diff >= (b.header.total_difficulty.clone() - head.total_difficulty.clone())
{
sol = Some(proof);