Unverified Commit c80c8368 authored by Roman Zeyde's avatar Roman Zeyde
Browse files

Simplify error handling for Query::get_best_header()

parent bf92ceeb
......@@ -267,9 +267,10 @@ impl Query {
result
}
pub fn get_best_header(&self) -> Option<HeaderEntry> {
pub fn get_best_header(&self) -> Result<HeaderEntry> {
let header_list = self.app.index().headers_list();
Some(header_list.headers().last()?.clone())
let last_header = header_list.headers().last();
Ok(last_header.chain_err(|| "no headers indexed")?.clone())
}
pub fn get_merkle_proof(
......
......@@ -58,9 +58,7 @@ impl Connection {
}
fn blockchain_headers_subscribe(&mut self) -> Result<Value> {
let entry = self.query
.get_best_header()
.chain_err(|| "no headers found")?;
let entry = self.query.get_best_header()?;
self.last_header_entry = Some(entry.clone());
Ok(jsonify_header(entry.header(), entry.height()))
}
......@@ -210,9 +208,7 @@ impl Connection {
fn update_subscriptions(&mut self) -> Result<Vec<Value>> {
let mut result = vec![];
if let Some(ref mut last_entry) = self.last_header_entry {
let entry = self.query
.get_best_header()
.chain_err(|| "no headers found")?;
let entry = self.query.get_best_header()?;
if *last_entry != entry {
*last_entry = entry;
let header = jsonify_header(last_entry.header(), last_entry.height());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment