rename get_header to block_header by convention

This commit is contained in:
Robert Habermeier 2017-02-08 20:22:41 +01:00
parent 0246d5c734
commit 028dbe5fe2
4 changed files with 16 additions and 16 deletions

View File

@ -211,7 +211,7 @@ impl HeaderChain {
/// Get a block header. In the case of query by number, only canonical blocks
/// will be returned.
pub fn get_header(&self, id: BlockId) -> Option<encoded::Header> {
pub fn block_header(&self, id: BlockId) -> Option<encoded::Header> {
match id {
BlockId::Earliest | BlockId::Number(0) => Some(self.genesis_header.clone()),
BlockId::Hash(hash) => self.headers.read().get(&hash).cloned(),
@ -238,7 +238,7 @@ impl HeaderChain {
/// Get the best block's header.
pub fn best_header(&self) -> encoded::Header {
self.get_header(BlockId::Latest).expect("Header for best block always stored; qed")
self.block_header(BlockId::Latest).expect("Header for best block always stored; qed")
}
/// Get the nth CHT root, if it's been computed.
@ -324,8 +324,8 @@ mod tests {
rolling_timestamp += 10;
}
assert!(chain.get_header(BlockId::Number(10)).is_none());
assert!(chain.get_header(BlockId::Number(9000)).is_some());
assert!(chain.block_header(BlockId::Number(10)).is_none());
assert!(chain.block_header(BlockId::Number(9000)).is_some());
assert!(chain.cht_root(2).is_some());
assert!(chain.cht_root(3).is_none());
}
@ -394,7 +394,7 @@ mod tests {
assert_eq!(num, 12);
while num > 0 {
let header = chain.get_header(BlockId::Number(num)).unwrap();
let header = chain.block_header(BlockId::Number(num)).unwrap();
assert_eq!(header.hash(), canon_hash);
canon_hash = header.parent_hash();
@ -409,8 +409,8 @@ mod tests {
let chain = HeaderChain::new(&::rlp::encode(&genesis_header));
assert!(chain.get_header(BlockId::Earliest).is_some());
assert!(chain.get_header(BlockId::Latest).is_some());
assert!(chain.get_header(BlockId::Pending).is_some());
assert!(chain.block_header(BlockId::Earliest).is_some());
assert!(chain.block_header(BlockId::Latest).is_some());
assert!(chain.block_header(BlockId::Pending).is_some());
}
}

View File

@ -155,8 +155,8 @@ impl Client {
}
/// Get a block header by Id.
pub fn get_header(&self, id: BlockId) -> Option<encoded::Header> {
self.chain.get_header(id)
pub fn block_header(&self, id: BlockId) -> Option<encoded::Header> {
self.chain.block_header(id)
}
/// Flush the header queue.
@ -252,7 +252,7 @@ impl Provider for Client {
}
fn block_header(&self, id: BlockId) -> Option<encoded::Header> {
self.chain.get_header(id)
Client::block_header(self, id)
}
fn block_body(&self, _id: BlockId) -> Option<encoded::Body> {

View File

@ -88,7 +88,7 @@ impl EthClient {
/// Get a block header from the on demand service or client, or error.
fn header(&self, id: BlockId) -> BoxFuture<Option<encoded::Header>, Error> {
if let Some(h) = self.client.get_header(id) {
if let Some(h) = self.client.block_header(id) {
return future::ok(Some(h)).boxed()
}

View File

@ -28,7 +28,7 @@ fn basic_sync() {
net.sync();
assert!(net.peer(0).light_chain().get_header(BlockId::Number(6000)).is_some());
assert!(net.peer(0).light_chain().block_header(BlockId::Number(6000)).is_some());
}
#[test]
@ -49,15 +49,15 @@ fn fork_post_cht() {
let _ = light_chain.import_header(header);
light_chain.flush_queue();
light_chain.import_verified();
assert!(light_chain.get_header(id).is_some());
assert!(light_chain.block_header(id).is_some());
}
net.sync();
for id in (0..CHAIN_LENGTH).map(|x| x + 1).map(BlockId::Number) {
assert_eq!(
net.peer(0).light_chain().get_header(id),
net.peer(2).chain().block_header(id).map(|h| h.into_inner())
net.peer(0).light_chain().block_header(id).unwrap(),
net.peer(2).chain().block_header(id).unwrap()
);
}
}