Removed Copy trait from H256
This commit is contained in:
parent
b925df2cd9
commit
8d37ef7d8e
@ -1,6 +1,6 @@
|
||||
use std::io::Read;
|
||||
use std::str::FromStr;
|
||||
use std::cell::Cell;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use rustc_serialize::base64::FromBase64;
|
||||
use rustc_serialize::json::Json;
|
||||
@ -83,7 +83,7 @@ impl Genesis {
|
||||
let nonce = H64::from_str(&json["nonce"].as_string().unwrap()[2..]).unwrap();
|
||||
vec![mixhash.to_vec(), nonce.to_vec()]
|
||||
},
|
||||
hash: Cell::new(None)
|
||||
hash: RefCell::new(None)
|
||||
};
|
||||
|
||||
let mut state = HashMap::new();
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::cell::Cell;
|
||||
use std::cell::RefCell;
|
||||
use util::hash::*;
|
||||
use util::sha3::*;
|
||||
use util::bytes::*;
|
||||
@ -31,16 +31,16 @@ pub struct Header {
|
||||
pub difficulty: U256,
|
||||
pub seal: Vec<Bytes>,
|
||||
|
||||
pub hash: Cell<Option<H256>>, //TODO: make this private
|
||||
pub hash: RefCell<Option<H256>>, //TODO: make this private
|
||||
}
|
||||
|
||||
impl Header {
|
||||
pub fn new() -> Header {
|
||||
Header {
|
||||
parent_hash: ZERO_H256,
|
||||
parent_hash: ZERO_H256.clone(),
|
||||
timestamp: BAD_U256,
|
||||
number: ZERO_U256,
|
||||
author: ZERO_ADDRESS,
|
||||
author: ZERO_ADDRESS.clone(),
|
||||
|
||||
transactions_root: SHA3_NULL_RLP,
|
||||
uncles_hash: SHA3_EMPTY_LIST_RLP,
|
||||
@ -48,26 +48,26 @@ impl Header {
|
||||
|
||||
state_root: SHA3_NULL_RLP,
|
||||
receipts_root: SHA3_NULL_RLP,
|
||||
log_bloom: ZERO_LOGBLOOM,
|
||||
log_bloom: ZERO_LOGBLOOM.clone(),
|
||||
gas_used: ZERO_U256,
|
||||
gas_limit: ZERO_U256,
|
||||
|
||||
difficulty: ZERO_U256,
|
||||
seal: vec![],
|
||||
hash: Cell::new(None),
|
||||
hash: RefCell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hash(&self) -> H256 {
|
||||
let hash = self.hash.get();
|
||||
match hash {
|
||||
Some(h) => h,
|
||||
None => {
|
||||
let mut hash = self.hash.borrow_mut();
|
||||
match &mut *hash {
|
||||
&mut Some(ref h) => h.clone(),
|
||||
hash @ &mut None => {
|
||||
let mut stream = RlpStream::new();
|
||||
stream.append(self);
|
||||
let h = stream.raw().sha3();
|
||||
self.hash.set(Some(h.clone()));
|
||||
h
|
||||
*hash = Some(h.clone());
|
||||
h.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,7 +92,7 @@ impl Decodable for Header {
|
||||
timestamp: try!(r.val_at(11)),
|
||||
extra_data: try!(r.val_at(12)),
|
||||
seal: vec![],
|
||||
hash: Cell::new(Some(r.raw().sha3()))
|
||||
hash: RefCell::new(Some(r.raw().sha3()))
|
||||
};
|
||||
|
||||
for i in 13..r.item_count() {
|
||||
|
@ -257,7 +257,7 @@ impl ChainSync {
|
||||
BlockStatus::InChain => {
|
||||
self.have_common_block = true;
|
||||
self.last_imported_block = number;
|
||||
self.last_imported_hash = hash;
|
||||
self.last_imported_hash = hash.clone();
|
||||
trace!(target: "sync", "Found common header {} ({})", number, hash);
|
||||
},
|
||||
_ => {
|
||||
@ -283,7 +283,7 @@ impl ChainSync {
|
||||
}
|
||||
let hdr = Header {
|
||||
data: r.at(i).raw().to_vec(),
|
||||
hash: hash,
|
||||
hash: hash.clone(),
|
||||
parent: info.parent_hash(),
|
||||
};
|
||||
self.headers.insert_item(number, hdr);
|
||||
@ -597,17 +597,17 @@ impl ChainSync {
|
||||
ImportResult::AlreadyInChain => {
|
||||
trace!(target: "sync", "Block already in chain {:?}", h);
|
||||
self.last_imported_block = headers.0 + i as BlockNumber;
|
||||
self.last_imported_hash = *h;
|
||||
self.last_imported_hash = h.clone();
|
||||
},
|
||||
ImportResult::AlreadyQueued(_) => {
|
||||
trace!(target: "sync", "Block already queued {:?}", h);
|
||||
self.last_imported_block = headers.0 + i as BlockNumber;
|
||||
self.last_imported_hash = *h;
|
||||
self.last_imported_hash = h.clone();
|
||||
},
|
||||
ImportResult::Queued(QueueStatus::Known) => {
|
||||
trace!(target: "sync", "Block queued {:?}", h);
|
||||
self.last_imported_block = headers.0 + i as BlockNumber;
|
||||
self.last_imported_hash = *h;
|
||||
self.last_imported_hash = h.clone();
|
||||
imported += 1;
|
||||
},
|
||||
ImportResult::Queued(QueueStatus::Unknown) => {
|
||||
|
@ -5,7 +5,8 @@ use util::uint::{U256};
|
||||
use util::sha3::Hashable;
|
||||
use util::rlp::{self, Rlp, RlpStream, View, Stream};
|
||||
use util::network::{PeerId, PacketId, Error as NetworkError};
|
||||
use eth::{BlockChainClient, BlockStatus, BlockNumber, TreeRoute, BlockQueueStatus, BlockChainInfo, ImportResult, BlockHeader, QueueStatus};
|
||||
use eth::{BlockChainClient, BlockStatus, BlockNumber, TreeRoute, BlockQueueStatus, BlockChainInfo, ImportResult, QueueStatus};
|
||||
use header::Header as BlockHeader;
|
||||
use sync::{SyncIo};
|
||||
use sync::chain::{ChainSync};
|
||||
|
||||
@ -28,7 +29,7 @@ impl TestBlockChainClient {
|
||||
difficulty: From::from(0),
|
||||
};
|
||||
client.add_blocks(1, true); // add genesis block
|
||||
client.genesis_hash = client.last_hash;
|
||||
client.genesis_hash = client.last_hash.clone();
|
||||
client
|
||||
}
|
||||
|
||||
@ -36,7 +37,7 @@ impl TestBlockChainClient {
|
||||
for n in self.numbers.len()..(self.numbers.len() + count) {
|
||||
let mut header = BlockHeader::new();
|
||||
header.difficulty = From::from(n);
|
||||
header.parent_hash = self.last_hash;
|
||||
header.parent_hash = self.last_hash.clone();
|
||||
header.number = From::from(n);
|
||||
let mut uncles = RlpStream::new_list(if empty {0} else {1});
|
||||
if !empty {
|
||||
@ -142,7 +143,7 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
if number > 0 {
|
||||
let mut n = number - 1;
|
||||
while n > 0 && self.numbers[&n] != parent_hash {
|
||||
*self.numbers.get_mut(&n).unwrap() = parent_hash;
|
||||
*self.numbers.get_mut(&n).unwrap() = parent_hash.clone();
|
||||
n -= 1;
|
||||
parent_hash = Rlp::new(&self.blocks[&parent_hash]).val_at::<BlockHeader>(0).parent_hash;
|
||||
}
|
||||
@ -167,8 +168,8 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
BlockChainInfo {
|
||||
total_difficulty: self.difficulty,
|
||||
pending_total_difficulty: self.difficulty,
|
||||
genesis_hash: self.genesis_hash,
|
||||
last_block_hash: self.last_hash,
|
||||
genesis_hash: self.genesis_hash.clone(),
|
||||
last_block_hash: self.last_hash.clone(),
|
||||
last_block_number: self.blocks.len() as BlockNumber - 1,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user