This commit is contained in:
arkpar 2016-01-08 16:00:32 +01:00
parent 5ef719ae23
commit 290d738e3f
6 changed files with 24 additions and 24 deletions

View File

@ -128,15 +128,15 @@ impl Client {
impl BlockChainClient for Client { impl BlockChainClient for Client {
fn block_header(&self, hash: &H256) -> Option<Bytes> { 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> { fn block_body(&self, hash: &H256) -> Option<Bytes> {
self.chain.block(hash).map(|bytes| { self.chain.block(hash).map(|bytes| {
let rlp = Rlp::new(&bytes); let rlp = Rlp::new(&bytes);
let mut body = RlpStream::new(); let mut body = RlpStream::new();
body.append_raw(rlp.at(1).raw(), 1); body.append_raw(rlp.at(1).as_raw(), 1);
body.append_raw(rlp.at(2).raw(), 1); body.append_raw(rlp.at(2).as_raw(), 1);
body.out() body.out()
}) })
} }

View File

@ -65,7 +65,7 @@ impl Header {
hash @ &mut 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.as_raw().sha3();
*hash = Some(h.clone()); *hash = Some(h.clone());
h.clone() h.clone()
} }
@ -92,11 +92,11 @@ 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: RefCell::new(Some(r.raw().sha3())) hash: RefCell::new(Some(r.as_raw().sha3()))
}; };
for i in 13..r.item_count() { 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) Ok(blockheader)

View File

@ -128,7 +128,7 @@ impl Spec {
s.out() s.out()
}; };
let r = Rlp::new(&seal); 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) hash: RefCell::new(None)
}; };

View File

@ -282,7 +282,7 @@ impl ChainSync {
} }
} }
let hdr = Header { let hdr = Header {
data: r.at(i).raw().to_vec(), data: r.at(i).as_raw().to_vec(),
hash: hash.clone(), hash: hash.clone(),
parent: info.parent_hash(), parent: info.parent_hash(),
}; };
@ -326,8 +326,8 @@ impl ChainSync {
for i in 0..item_count { for i in 0..item_count {
let body: Rlp = r.at(i); let body: Rlp = r.at(i);
let tx = body.at(0); 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 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).raw().sha3(); let uncles = body.at(1).as_raw().sha3();
let header_id = HeaderId { let header_id = HeaderId {
transactions_root: tx_root, transactions_root: tx_root,
uncles: uncles uncles: uncles
@ -335,7 +335,7 @@ impl ChainSync {
match self.header_ids.get(&header_id).map(|n| *n) { match self.header_ids.get(&header_id).map(|n| *n) {
Some(n) => { Some(n) => {
self.header_ids.remove(&header_id); 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); trace!(target: "sync", "Got body {}", n);
} }
None => { None => {
@ -351,10 +351,10 @@ impl ChainSync {
fn on_peer_new_block(&mut self, io: &mut SyncIo, peer_id: &PeerId, r: &Rlp) { fn on_peer_new_block(&mut self, io: &mut SyncIo, peer_id: &PeerId, r: &Rlp) {
let block_rlp = r.at(0); let block_rlp = r.at(0);
let header_rlp = block_rlp.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); 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 => { ImportResult::AlreadyInChain => {
trace!(target: "sync", "New block already in chain {:?}", h); trace!(target: "sync", "New block already in chain {:?}", h);
}, },
@ -590,8 +590,8 @@ impl ChainSync {
let mut block_rlp = RlpStream::new_list(3); let mut block_rlp = RlpStream::new_list(3);
block_rlp.append_raw(&headers.1[i].data, 1); block_rlp.append_raw(&headers.1[i].data, 1);
let body = Rlp::new(&bodies.1[i]); let body = Rlp::new(&bodies.1[i]);
block_rlp.append_raw(body.at(0).raw(), 1); block_rlp.append_raw(body.at(0).as_raw(), 1);
block_rlp.append_raw(body.at(1).raw(), 1); block_rlp.append_raw(body.at(1).as_raw(), 1);
let h = &headers.1[i].hash; let h = &headers.1[i].hash;
match io.chain().import_block(&block_rlp.out()) { match io.chain().import_block(&block_rlp.out()) {
ImportResult::AlreadyInChain => { ImportResult::AlreadyInChain => {

View File

@ -42,28 +42,28 @@ impl TestBlockChainClient {
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 {
uncles.append(&H256::from(&U256::from(n))); 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); let mut rlp = RlpStream::new_list(3);
rlp.append(&header); rlp.append(&header);
rlp.append_raw(&rlp::NULL_RLP, 1); rlp.append_raw(&rlp::NULL_RLP, 1);
rlp.append_raw(uncles.raw(), 1); rlp.append_raw(uncles.as_raw(), 1);
self.import_block(rlp.raw()); self.import_block(rlp.as_raw());
} }
} }
} }
impl BlockChainClient for TestBlockChainClient { impl BlockChainClient for TestBlockChainClient {
fn block_header(&self, h: &H256) -> Option<Bytes> { 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> { fn block_body(&self, h: &H256) -> Option<Bytes> {
self.blocks.get(h).map(|r| { self.blocks.get(h).map(|r| {
let mut stream = RlpStream::new_list(2); let mut stream = RlpStream::new_list(2);
stream.append_raw(Rlp::new(&r).at(1).raw(), 1); stream.append_raw(Rlp::new(&r).at(1).as_raw(), 1);
stream.append_raw(Rlp::new(&r).at(2).raw(), 1); stream.append_raw(Rlp::new(&r).at(2).as_raw(), 1);
stream.out() stream.out()
}) })
} }

View File

@ -49,7 +49,7 @@ impl<'a> BlockView<'a> {
/// Return transaction hashes. /// Return transaction hashes.
pub fn transaction_hashes(&self) -> Vec<H256> { 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. /// Return list of uncles of given block.
@ -59,7 +59,7 @@ impl<'a> BlockView<'a> {
/// Return list of uncle hashes of given block. /// Return list of uncle hashes of given block.
pub fn uncle_hashes(&self) -> Vec<H256> { 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> { impl<'a> Hashable for HeaderView<'a> {
fn sha3(&self) -> H256 { fn sha3(&self) -> H256 {
self.rlp.raw().sha3() self.rlp.as_raw().sha3()
} }
} }