1
0
Fork 0
mirror of https://github.com/romanz/electrs.git synced 2025-02-24 23:08:39 +01:00

Refactor Index::get_header() implementation

This commit is contained in:
Roman Zeyde 2018-05-30 21:42:45 +03:00
parent ddb38e7d4a
commit 5b7b7d0d10
No known key found for this signature in database
GPG key ID: 87CAE5FA46917CBB
2 changed files with 12 additions and 7 deletions

View file

@ -373,9 +373,11 @@ impl Index {
}
pub fn get_header(&self, height: usize) -> Option<HeaderEntry> {
let entry = self.headers.read().unwrap().headers().get(height)?.clone();
assert_eq!(entry.height(), height);
Some(entry)
self.headers
.read()
.unwrap()
.header_by_height(height)
.cloned()
}
pub fn update(&self, store: &DBStore, daemon: &Daemon) -> Result<Sha256dHash> {

View file

@ -185,12 +185,15 @@ impl HeaderList {
}
}
pub fn equals(&self, other: &HeaderList) -> bool {
self.headers.last() == other.headers.last()
pub fn header_by_height(&self, height: usize) -> Option<&HeaderEntry> {
self.headers.get(height).map(|entry| {
assert_eq!(entry.height(), height);
entry
})
}
pub fn headers(&self) -> &[HeaderEntry] {
&self.headers
pub fn equals(&self, other: &HeaderList) -> bool {
self.headers.last() == other.headers.last()
}
pub fn tip(&self) -> &Sha256dHash {