block_header can fail so return Result (#8581)

* block_header can fail so return Result

* Restore previous return type based on feedback

* Fix failing doc tests running on non-code
This commit is contained in:
David 2018-05-11 11:34:07 +02:00 committed by Marek Kotewicz
parent 61ec02248a
commit 25dc1c2155
3 changed files with 8 additions and 9 deletions

View File

@ -395,9 +395,9 @@ impl Parity for ParityClient {
let engine = self.light_dispatch.client.engine().clone(); let engine = self.light_dispatch.client.engine().clone();
let from_encoded = move |encoded: encoded::Header| { let from_encoded = move |encoded: encoded::Header| {
let header = encoded.decode().expect("decoding error"); // REVIEW: not sure what to do here; what is a decent return value for the error case here? let header = encoded.decode().map_err(errors::decode)?;
let extra_info = engine.extra_info(&header); let extra_info = engine.extra_info(&header);
RichHeader { Ok(RichHeader {
inner: Header { inner: Header {
hash: Some(header.hash().into()), hash: Some(header.hash().into()),
size: Some(encoded.rlp().as_raw().len().into()), size: Some(encoded.rlp().as_raw().len().into()),
@ -418,9 +418,8 @@ impl Parity for ParityClient {
extra_data: Bytes::new(header.extra_data().clone()), extra_data: Bytes::new(header.extra_data().clone()),
}, },
extra_info: extra_info, extra_info: extra_info,
} })
}; };
// Note: Here we treat `Pending` as `Latest`. // Note: Here we treat `Pending` as `Latest`.
// Since light clients don't produce pending blocks // Since light clients don't produce pending blocks
// (they don't have state) we can safely fallback to `Latest`. // (they don't have state) we can safely fallback to `Latest`.
@ -430,7 +429,7 @@ impl Parity for ParityClient {
BlockNumber::Latest | BlockNumber::Pending => BlockId::Latest, BlockNumber::Latest | BlockNumber::Pending => BlockId::Latest,
}; };
Box::new(self.fetcher().header(id).map(from_encoded)) Box::new(self.fetcher().header(id).and_then(from_encoded))
} }
fn ipfs_cid(&self, content: Bytes) -> Result<String> { fn ipfs_cid(&self, content: Bytes) -> Result<String> {

View File

@ -57,7 +57,7 @@ enum RemoveFrom {
/// the removals actually take effect. /// the removals actually take effect.
/// ///
/// journal format: /// journal format:
/// ``` /// ```text
/// [era, 0] => [ id, [insert_0, ...], [remove_0, ...] ] /// [era, 0] => [ id, [insert_0, ...], [remove_0, ...] ]
/// [era, 1] => [ id, [insert_0, ...], [remove_0, ...] ] /// [era, 1] => [ id, [insert_0, ...], [remove_0, ...] ]
/// [era, n] => [ ... ] /// [era, n] => [ ... ]
@ -76,7 +76,7 @@ enum RemoveFrom {
/// which includes an original key, if any. /// which includes an original key, if any.
/// ///
/// The semantics of the `counter` are: /// The semantics of the `counter` are:
/// ``` /// ```text
/// insert key k: /// insert key k:
/// counter already contains k: count += 1 /// counter already contains k: count += 1
/// counter doesn't contain k: /// counter doesn't contain k:
@ -92,7 +92,7 @@ enum RemoveFrom {
/// ///
/// Practically, this means that for each commit block turning from recent to ancient we do the /// Practically, this means that for each commit block turning from recent to ancient we do the
/// following: /// following:
/// ``` /// ```text
/// is_canonical: /// is_canonical:
/// inserts: Ignored (left alone in the backing database). /// inserts: Ignored (left alone in the backing database).
/// deletes: Enacted; however, recent history queue is checked for ongoing references. This is /// deletes: Enacted; however, recent history queue is checked for ongoing references. This is

View File

@ -40,7 +40,7 @@ use util::{DatabaseKey, DatabaseValueView, DatabaseValueRef};
/// the removals actually take effect. /// the removals actually take effect.
/// ///
/// journal format: /// journal format:
/// ``` /// ```text
/// [era, 0] => [ id, [insert_0, ...], [remove_0, ...] ] /// [era, 0] => [ id, [insert_0, ...], [remove_0, ...] ]
/// [era, 1] => [ id, [insert_0, ...], [remove_0, ...] ] /// [era, 1] => [ id, [insert_0, ...], [remove_0, ...] ]
/// [era, n] => [ ... ] /// [era, n] => [ ... ]