Style
This commit is contained in:
parent
5ef719ae23
commit
290d738e3f
@ -128,15 +128,15 @@ impl Client {
|
||||
|
||||
impl BlockChainClient for Client {
|
||||
fn block_header(&self, hash: &H256) -> Option<Bytes> {
|
||||
self.chain.block(hash).map(|bytes| BlockView::new(&bytes).rlp().at(0).raw().to_vec())
|
||||
self.chain.block(hash).map(|bytes| BlockView::new(&bytes).rlp().at(0).as_raw().to_vec())
|
||||
}
|
||||
|
||||
fn block_body(&self, hash: &H256) -> Option<Bytes> {
|
||||
self.chain.block(hash).map(|bytes| {
|
||||
let rlp = Rlp::new(&bytes);
|
||||
let mut body = RlpStream::new();
|
||||
body.append_raw(rlp.at(1).raw(), 1);
|
||||
body.append_raw(rlp.at(2).raw(), 1);
|
||||
body.append_raw(rlp.at(1).as_raw(), 1);
|
||||
body.append_raw(rlp.at(2).as_raw(), 1);
|
||||
body.out()
|
||||
})
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ impl Header {
|
||||
hash @ &mut None => {
|
||||
let mut stream = RlpStream::new();
|
||||
stream.append(self);
|
||||
let h = stream.raw().sha3();
|
||||
let h = stream.as_raw().sha3();
|
||||
*hash = Some(h.clone());
|
||||
h.clone()
|
||||
}
|
||||
@ -92,11 +92,11 @@ impl Decodable for Header {
|
||||
timestamp: try!(r.val_at(11)),
|
||||
extra_data: try!(r.val_at(12)),
|
||||
seal: vec![],
|
||||
hash: RefCell::new(Some(r.raw().sha3()))
|
||||
hash: RefCell::new(Some(r.as_raw().sha3()))
|
||||
};
|
||||
|
||||
for i in 13..r.item_count() {
|
||||
blockheader.seal.push(try!(r.at(i)).raw().to_vec())
|
||||
blockheader.seal.push(try!(r.at(i)).as_raw().to_vec())
|
||||
}
|
||||
|
||||
Ok(blockheader)
|
||||
|
@ -128,7 +128,7 @@ impl Spec {
|
||||
s.out()
|
||||
};
|
||||
let r = Rlp::new(&seal);
|
||||
(0..self.seal_fields).map(|i| r.at(i).raw().to_vec()).collect()
|
||||
(0..self.seal_fields).map(|i| r.at(i).as_raw().to_vec()).collect()
|
||||
},
|
||||
hash: RefCell::new(None)
|
||||
};
|
||||
|
@ -282,7 +282,7 @@ impl ChainSync {
|
||||
}
|
||||
}
|
||||
let hdr = Header {
|
||||
data: r.at(i).raw().to_vec(),
|
||||
data: r.at(i).as_raw().to_vec(),
|
||||
hash: hash.clone(),
|
||||
parent: info.parent_hash(),
|
||||
};
|
||||
@ -326,8 +326,8 @@ impl ChainSync {
|
||||
for i in 0..item_count {
|
||||
let body: Rlp = r.at(i);
|
||||
let tx = body.at(0);
|
||||
let tx_root = ::util::triehash::ordered_trie_root(tx.iter().map(|r| r.raw().to_vec()).collect()); //TODO: get rid of vectors here
|
||||
let uncles = body.at(1).raw().sha3();
|
||||
let tx_root = ::util::triehash::ordered_trie_root(tx.iter().map(|r| r.as_raw().to_vec()).collect()); //TODO: get rid of vectors here
|
||||
let uncles = body.at(1).as_raw().sha3();
|
||||
let header_id = HeaderId {
|
||||
transactions_root: tx_root,
|
||||
uncles: uncles
|
||||
@ -335,7 +335,7 @@ impl ChainSync {
|
||||
match self.header_ids.get(&header_id).map(|n| *n) {
|
||||
Some(n) => {
|
||||
self.header_ids.remove(&header_id);
|
||||
self.bodies.insert_item(n, body.raw().to_vec());
|
||||
self.bodies.insert_item(n, body.as_raw().to_vec());
|
||||
trace!(target: "sync", "Got body {}", n);
|
||||
}
|
||||
None => {
|
||||
@ -351,10 +351,10 @@ impl ChainSync {
|
||||
fn on_peer_new_block(&mut self, io: &mut SyncIo, peer_id: &PeerId, r: &Rlp) {
|
||||
let block_rlp = r.at(0);
|
||||
let header_rlp = block_rlp.at(0);
|
||||
let h = header_rlp.raw().sha3();
|
||||
let h = header_rlp.as_raw().sha3();
|
||||
|
||||
trace!(target: "sync", "{}-> NewBlock ({})", peer_id, h);
|
||||
match io.chain().import_block(block_rlp.raw()) {
|
||||
match io.chain().import_block(block_rlp.as_raw()) {
|
||||
ImportResult::AlreadyInChain => {
|
||||
trace!(target: "sync", "New block already in chain {:?}", h);
|
||||
},
|
||||
@ -590,8 +590,8 @@ impl ChainSync {
|
||||
let mut block_rlp = RlpStream::new_list(3);
|
||||
block_rlp.append_raw(&headers.1[i].data, 1);
|
||||
let body = Rlp::new(&bodies.1[i]);
|
||||
block_rlp.append_raw(body.at(0).raw(), 1);
|
||||
block_rlp.append_raw(body.at(1).raw(), 1);
|
||||
block_rlp.append_raw(body.at(0).as_raw(), 1);
|
||||
block_rlp.append_raw(body.at(1).as_raw(), 1);
|
||||
let h = &headers.1[i].hash;
|
||||
match io.chain().import_block(&block_rlp.out()) {
|
||||
ImportResult::AlreadyInChain => {
|
||||
|
@ -42,28 +42,28 @@ impl TestBlockChainClient {
|
||||
let mut uncles = RlpStream::new_list(if empty {0} else {1});
|
||||
if !empty {
|
||||
uncles.append(&H256::from(&U256::from(n)));
|
||||
header.uncles_hash = uncles.raw().sha3();
|
||||
header.uncles_hash = uncles.as_raw().sha3();
|
||||
}
|
||||
let mut rlp = RlpStream::new_list(3);
|
||||
rlp.append(&header);
|
||||
rlp.append_raw(&rlp::NULL_RLP, 1);
|
||||
rlp.append_raw(uncles.raw(), 1);
|
||||
self.import_block(rlp.raw());
|
||||
rlp.append_raw(uncles.as_raw(), 1);
|
||||
self.import_block(rlp.as_raw());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BlockChainClient for TestBlockChainClient {
|
||||
fn block_header(&self, h: &H256) -> Option<Bytes> {
|
||||
self.blocks.get(h).map(|r| Rlp::new(r).at(0).raw().to_vec())
|
||||
self.blocks.get(h).map(|r| Rlp::new(r).at(0).as_raw().to_vec())
|
||||
|
||||
}
|
||||
|
||||
fn block_body(&self, h: &H256) -> Option<Bytes> {
|
||||
self.blocks.get(h).map(|r| {
|
||||
let mut stream = RlpStream::new_list(2);
|
||||
stream.append_raw(Rlp::new(&r).at(1).raw(), 1);
|
||||
stream.append_raw(Rlp::new(&r).at(2).raw(), 1);
|
||||
stream.append_raw(Rlp::new(&r).at(1).as_raw(), 1);
|
||||
stream.append_raw(Rlp::new(&r).at(2).as_raw(), 1);
|
||||
stream.out()
|
||||
})
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ impl<'a> BlockView<'a> {
|
||||
|
||||
/// Return transaction hashes.
|
||||
pub fn transaction_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(1).iter().map(|rlp| rlp.raw().sha3()).collect()
|
||||
self.rlp.at(1).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
}
|
||||
|
||||
/// Return list of uncles of given block.
|
||||
@ -59,7 +59,7 @@ impl<'a> BlockView<'a> {
|
||||
|
||||
/// Return list of uncle hashes of given block.
|
||||
pub fn uncle_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(2).iter().map(|rlp| rlp.raw().sha3()).collect()
|
||||
self.rlp.at(2).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,6 +143,6 @@ impl<'a> HeaderView<'a> {
|
||||
|
||||
impl<'a> Hashable for HeaderView<'a> {
|
||||
fn sha3(&self) -> H256 {
|
||||
self.rlp.raw().sha3()
|
||||
self.rlp.as_raw().sha3()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user