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:
parent
ddb38e7d4a
commit
5b7b7d0d10
2 changed files with 12 additions and 7 deletions
|
@ -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> {
|
||||||
|
|
11
src/util.rs
11
src/util.rs
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue