From 290d738e3f23da0172fcf5eaf85c1a60d2cdb798 Mon Sep 17 00:00:00 2001 From: arkpar Date: Fri, 8 Jan 2016 16:00:32 +0100 Subject: [PATCH] Style --- src/client.rs | 6 +++--- src/header.rs | 6 +++--- src/spec.rs | 2 +- src/sync/chain.rs | 16 ++++++++-------- src/sync/tests.rs | 12 ++++++------ src/views.rs | 6 +++--- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/client.rs b/src/client.rs index 76c2bac01..f67eb0905 100644 --- a/src/client.rs +++ b/src/client.rs @@ -128,15 +128,15 @@ impl Client { impl BlockChainClient for Client { fn block_header(&self, hash: &H256) -> Option { - 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 { 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() }) } diff --git a/src/header.rs b/src/header.rs index 896fe2bd5..7f00392ee 100644 --- a/src/header.rs +++ b/src/header.rs @@ -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) diff --git a/src/spec.rs b/src/spec.rs index aca29f2e6..371376e16 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -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) }; diff --git a/src/sync/chain.rs b/src/sync/chain.rs index 420571af8..1b3ae83fc 100644 --- a/src/sync/chain.rs +++ b/src/sync/chain.rs @@ -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 => { diff --git a/src/sync/tests.rs b/src/sync/tests.rs index 7651b9298..79e1443c9 100644 --- a/src/sync/tests.rs +++ b/src/sync/tests.rs @@ -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 { - 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 { 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() }) } diff --git a/src/views.rs b/src/views.rs index 8f04d5e82..9d66bb164 100644 --- a/src/views.rs +++ b/src/views.rs @@ -49,7 +49,7 @@ impl<'a> BlockView<'a> { /// Return transaction hashes. pub fn transaction_hashes(&self) -> Vec { - 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 { - 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() } }