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