convert try!() to ?

This commit is contained in:
Guanqun Lu 2017-06-18 22:15:44 +08:00
parent ed20fa4da1
commit 41fed96d96
5 changed files with 12 additions and 12 deletions

View File

@ -255,13 +255,13 @@ impl Engine for Arc<Ethash> {
fn on_new_block(&self, block: &mut ExecutedBlock, last_hashes: Arc<LastHashes>) -> Result<(), Error> {
let parent_hash = block.fields().header.parent_hash().clone();
try!(::engines::common::push_last_hash(block, last_hashes, self, &parent_hash));
::engines::common::push_last_hash(block, last_hashes, self, &parent_hash)?;
if block.fields().header.number() == self.ethash_params.dao_hardfork_transition {
let state = block.fields_mut().state;
for child in &self.ethash_params.dao_hardfork_accounts {
let beneficiary = &self.ethash_params.dao_hardfork_beneficiary;
try!(state.balance(child)
.and_then(|b| state.transfer_balance(child, beneficiary, &b, CleanupMode::NoEmpty)));
state.balance(child)
.and_then(|b| state.transfer_balance(child, beneficiary, &b, CleanupMode::NoEmpty))?;
}
}
Ok(())

View File

@ -24,7 +24,7 @@ type DeadlineBox<F> where F: Future = BoxFuture<DeadlineStatus<F::Item>, F::Erro
/// Complete a passed future or fail if it is not completed within timeout.
pub fn deadline<F, T>(duration: Duration, handle: &Handle, future: F) -> Result<Deadline<F>, io::Error>
where F: Future<Item = T, Error = io::Error> + Send + 'static, T: 'static {
let timeout = try!(Timeout::new(duration, handle)).map(|_| DeadlineStatus::Timeout).boxed();
let timeout = Timeout::new(duration, handle)?.map(|_| DeadlineStatus::Timeout).boxed();
let future = future.map(DeadlineStatus::Meet).boxed();
let deadline = Deadline {
future: timeout.select(future),

View File

@ -709,7 +709,7 @@ impl LightSync {
};
let mut light_proto = LightProtocol::new(params.client.clone(), light_params);
let sync_handler = Arc::new(try!(SyncHandler::new(params.client.clone())));
let sync_handler = Arc::new(SyncHandler::new(params.client.clone())?);
light_proto.add_handler(sync_handler.clone());
for handler in params.handlers {
@ -719,7 +719,7 @@ impl LightSync {
(sync_handler, Arc::new(light_proto))
};
let service = try!(NetworkService::new(params.network_config));
let service = NetworkService::new(params.network_config)?;
Ok(LightSync {
proto: light_proto,

View File

@ -551,7 +551,7 @@ impl<L: AsLightClient> LightSync<L> {
peers: RwLock::new(HashMap::new()),
pending_reqs: Mutex::new(HashSet::new()),
client: client,
rng: Mutex::new(try!(OsRng::new())),
rng: Mutex::new(OsRng::new()?),
state: Mutex::new(SyncState::Idle),
})
}

View File

@ -47,7 +47,7 @@ impl From<DecoderError> for BasicError {
impl fmt::Display for BasicError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "Header response verification error: "));
write!(f, "Header response verification error: ")?;
match *self {
BasicError::WrongSkip(ref exp, ref got)
@ -78,13 +78,13 @@ pub fn verify(headers: &[encoded::Header], request: &HeadersRequest) -> Result<V
let reverse = request.reverse;
try!(Max(request.max as usize).verify(&headers, reverse));
Max(request.max as usize).verify(&headers, reverse)?;
match request.start {
HashOrNumber::Number(ref num) => try!(StartsAtNumber(*num).verify(&headers, reverse)),
HashOrNumber::Hash(ref hash) => try!(StartsAtHash(*hash).verify(&headers, reverse)),
HashOrNumber::Number(ref num) => StartsAtNumber(*num).verify(&headers, reverse)?,
HashOrNumber::Hash(ref hash) => StartsAtHash(*hash).verify(&headers, reverse)?,
}
try!(SkipsBetween(request.skip).verify(&headers, reverse));
SkipsBetween(request.skip).verify(&headers, reverse)?;
Ok(headers)
}