1
0
Fork 0
mirror of https://github.com/romanz/electrs.git synced 2025-02-25 07:17:41 +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> { pub fn get_header(&self, height: usize) -> Option<HeaderEntry> {
let entry = self.headers.read().unwrap().headers().get(height)?.clone(); self.headers
assert_eq!(entry.height(), height); .read()
Some(entry) .unwrap()
.header_by_height(height)
.cloned()
} }
pub fn update(&self, store: &DBStore, daemon: &Daemon) -> Result<Sha256dHash> { 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 { pub fn header_by_height(&self, height: usize) -> Option<&HeaderEntry> {
self.headers.last() == other.headers.last() self.headers.get(height).map(|entry| {
assert_eq!(entry.height(), height);
entry
})
} }
pub fn headers(&self) -> &[HeaderEntry] { pub fn equals(&self, other: &HeaderList) -> bool {
&self.headers self.headers.last() == other.headers.last()
} }
pub fn tip(&self) -> &Sha256dHash { pub fn tip(&self) -> &Sha256dHash {