Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Chiguireitor
addrindexrs
Commits
c80c8368
Unverified
Commit
c80c8368
authored
May 26, 2018
by
Roman Zeyde
Browse files
Simplify error handling for Query::get_best_header()
parent
bf92ceeb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
8 deletions
+5
-8
src/query.rs
src/query.rs
+3
-2
src/rpc.rs
src/rpc.rs
+2
-6
No files found.
src/query.rs
View file @
c80c8368
...
...
@@ -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
(
...
...
src/rpc.rs
View file @
c80c8368
...
...
@@ -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
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment