mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 08:41:07 +00:00
Simplify some Option / Result / ? operator patterns (#8653)
* Simplify some Option / Result / ? operator patterns When those match a combinator exactly. Tool-aided by [comby-rust](https://github.com/huitseeker/comby-rust). * adjust after review * adjust post-review
This commit is contained in:
committed by
GitHub
parent
541692c4a8
commit
052be8bbef
@@ -72,10 +72,7 @@ fn check_header<C, B: BlockT, P: Pair>(
|
||||
C: sc_client_api::backend::AuxStore,
|
||||
P::Public: Encode + Decode + PartialEq + Clone,
|
||||
{
|
||||
let seal = match header.digest_mut().pop() {
|
||||
Some(x) => x,
|
||||
None => return Err(Error::HeaderUnsealed(hash)),
|
||||
};
|
||||
let seal = header.digest_mut().pop().ok_or_else(|| Error::HeaderUnsealed(hash))?;
|
||||
|
||||
let sig = seal.as_aura_seal().ok_or_else(|| {
|
||||
aura_err(Error::HeaderBadSeal(hash))
|
||||
@@ -89,10 +86,8 @@ fn check_header<C, B: BlockT, P: Pair>(
|
||||
} else {
|
||||
// check the signature is valid under the expected authority and
|
||||
// chain state.
|
||||
let expected_author = match slot_author::<P>(slot, &authorities) {
|
||||
None => return Err(Error::SlotAuthorNotFound),
|
||||
Some(author) => author,
|
||||
};
|
||||
let expected_author = slot_author::<P>(slot, &authorities)
|
||||
.ok_or_else(|| Error::SlotAuthorNotFound)?;
|
||||
|
||||
let pre_hash = header.hash();
|
||||
|
||||
|
||||
@@ -71,10 +71,8 @@ pub(super) fn check_header<B: BlockT + Sized>(
|
||||
let pre_digest = pre_digest.map(Ok).unwrap_or_else(|| find_pre_digest::<B>(&header))?;
|
||||
|
||||
trace!(target: "babe", "Checking header");
|
||||
let seal = match header.digest_mut().pop() {
|
||||
Some(x) => x,
|
||||
None => return Err(babe_err(Error::HeaderUnsealed(header.hash()))),
|
||||
};
|
||||
let seal = header.digest_mut().pop()
|
||||
.ok_or_else(|| babe_err(Error::HeaderUnsealed(header.hash())))?;
|
||||
|
||||
let sig = seal.as_babe_seal().ok_or_else(|| {
|
||||
babe_err(Error::HeaderBadSeal(header.hash()))
|
||||
|
||||
@@ -104,10 +104,7 @@ pub async fn seal_block<B, BI, SC, C, E, P>(
|
||||
// or fetch the best_block.
|
||||
let parent = match parent_hash {
|
||||
Some(hash) => {
|
||||
match client.header(BlockId::Hash(hash))? {
|
||||
Some(header) => header,
|
||||
None => return Err(Error::BlockNotFound(format!("{}", hash))),
|
||||
}
|
||||
client.header(BlockId::Hash(hash))?.ok_or_else(|| Error::BlockNotFound(format!("{}", hash)))?
|
||||
}
|
||||
None => select_chain.best_chain()?
|
||||
};
|
||||
|
||||
@@ -256,10 +256,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
|
||||
return None;
|
||||
}
|
||||
|
||||
let claim = match self.claim_slot(&chain_head, slot, &epoch_data) {
|
||||
None => return None,
|
||||
Some(claim) => claim,
|
||||
};
|
||||
let claim = self.claim_slot(&chain_head, slot, &epoch_data)?;
|
||||
|
||||
if self.should_backoff(slot, &chain_head) {
|
||||
return None;
|
||||
|
||||
@@ -135,10 +135,7 @@ impl<SC: SlotCompatible> Slots<SC> {
|
||||
Err(err) => return Err(sp_consensus::Error::InherentData(err)),
|
||||
};
|
||||
let result = self.timestamp_extractor.extract_timestamp_and_slot(&inherent_data);
|
||||
let (timestamp, slot, offset) = match result {
|
||||
Ok(v) => v,
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
let (timestamp, slot, offset) = result?;
|
||||
// reschedule delay for next slot.
|
||||
let ends_in = offset +
|
||||
time_until_next(timestamp.as_duration(), self.slot_duration);
|
||||
|
||||
Reference in New Issue
Block a user