diff --git a/core/src/macros.rs b/core/src/macros.rs index b944e58677..b2954d7733 100644 --- a/core/src/macros.rs +++ b/core/src/macros.rs @@ -66,30 +66,30 @@ macro_rules! tee { /// Eliminate some of the boilerplate of deserialization (package ser) by /// passing just the list of reader function (with optional single param) /// Example before: -/// let foo = try!(reader.read_u64()); -/// let bar = try!(reader.read_u32()); -/// let fixed_byte_var = try!(reader.read_fixed_bytes(64)); +/// let foo = reader.read_u64()?; +/// let bar = reader.read_u32()?; +/// let fixed_byte_var = reader.read_fixed_bytes(64)?; /// Example after: /// let (foo, bar, fixed_byte_var) = ser_multiread!(reader, read_u64, /// read_u32, read_fixed_bytes(64)); #[macro_export] macro_rules! ser_multiread { ($rdr:ident, $($read_call:ident $(($val:expr)),*),*) => { - ( $(r#try!($rdr.$read_call($($val),*))),* ) + ( $($rdr.$read_call($($val),*)?),* ) } } /// Eliminate some of the boilerplate of serialization (package ser) by /// passing directly pairs of writer function and data to write. /// Example before: -/// try!(reader.write_u64(42)); -/// try!(reader.write_u32(100)); +/// reader.write_u64(42)?; +/// reader.write_u32(100)?; /// Example after: /// ser_multiwrite!(writer, [write_u64, 42], [write_u32, 100]); #[macro_export] macro_rules! ser_multiwrite { ($wrtr:ident, $([ $write_call:ident, $val:expr ]),* ) => { - $( r#try!($wrtr.$write_call($val)) );* + $($wrtr.$write_call($val)? );* } } diff --git a/core/tests/vec_backend.rs b/core/tests/vec_backend.rs index 3780f194d0..9943bef245 100644 --- a/core/tests/vec_backend.rs +++ b/core/tests/vec_backend.rs @@ -42,9 +42,9 @@ impl PMMRable for TestElem { impl Writeable for TestElem { fn write(&self, writer: &mut W) -> Result<(), ser::Error> { - r#try!(writer.write_u32(self.0[0])); - r#try!(writer.write_u32(self.0[1])); - r#try!(writer.write_u32(self.0[2])); + writer.write_u32(self.0[0])?; + writer.write_u32(self.0[1])?; + writer.write_u32(self.0[2])?; writer.write_u32(self.0[3]) } } diff --git a/keychain/src/extkey_bip32.rs b/keychain/src/extkey_bip32.rs index 09dd6e6279..22335772ec 100644 --- a/keychain/src/extkey_bip32.rs +++ b/keychain/src/extkey_bip32.rs @@ -122,7 +122,7 @@ impl BIP32Hasher for BIP32GrinHasher { b"IamVoldemort".to_owned() } fn init_sha512(&mut self, seed: &[u8]) { - self.hmac_sha512 = HmacSha512::new_varkey(seed).expect("HMAC can take key of any size");; + self.hmac_sha512 = HmacSha512::new_varkey(seed).expect("HMAC can take key of any size"); } fn append_sha512(&mut self, value: &[u8]) { self.hmac_sha512.input(value); @@ -385,7 +385,7 @@ impl ExtendedPrivKey { Err(e) => return Err(Error::MnemonicError(e)), }; let mut hasher = BIP32GrinHasher::new(is_floo); - let key = r#try!(ExtendedPrivKey::new_master(secp, &mut hasher, &seed)); + let key = ExtendedPrivKey::new_master(secp, &mut hasher, &seed)?; Ok(key) } @@ -716,7 +716,7 @@ mod tests { b"Bitcoin seed".to_owned() } fn init_sha512(&mut self, seed: &[u8]) { - self.hmac_sha512 = HmacSha512::new_varkey(seed).expect("HMAC can take key of any size");; + self.hmac_sha512 = HmacSha512::new_varkey(seed).expect("HMAC can take key of any size"); } fn append_sha512(&mut self, value: &[u8]) { self.hmac_sha512.input(value); @@ -900,5 +900,4 @@ mod tests { serde_round_trip!(ChildNumber::from_hardened_idx(1)); serde_round_trip!(ChildNumber::from_hardened_idx((1 << 31) - 1)); } - } diff --git a/keychain/src/mnemonic.rs b/keychain/src/mnemonic.rs index cf0879ed7c..752907db1f 100644 --- a/keychain/src/mnemonic.rs +++ b/keychain/src/mnemonic.rs @@ -72,7 +72,10 @@ pub fn to_entropy(mnemonic: &str) -> Result, Error> { } // u11 vector of indexes for each word - let mut indexes: Vec = r#try!(words.iter().map(|x| search(x)).collect()); + let mut indexes: Vec = words + .iter() + .map(|x| search(x)) + .collect::, _>>()?; let checksum_bits = words.len() / 3; let mask = ((1 << checksum_bits) - 1) as u8; let last = indexes.pop().unwrap(); @@ -155,7 +158,7 @@ where Option<&'a str>: From, { // make sure the mnemonic is valid - r#try!(to_entropy(mnemonic)); + to_entropy(mnemonic)?; let salt = ("mnemonic".to_owned() + Option::from(passphrase).unwrap_or("")).into_bytes(); let data = mnemonic.as_bytes(); diff --git a/keychain/src/types.rs b/keychain/src/types.rs index abd01f5a09..a6c774935c 100644 --- a/keychain/src/types.rs +++ b/keychain/src/types.rs @@ -220,8 +220,8 @@ impl AsRef<[u8]> for Identifier { impl ::std::fmt::Debug for Identifier { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - r#try!(write!(f, "{}(", stringify!(Identifier))); - r#try!(write!(f, "{}", self.to_hex())); + write!(f, "{}(", stringify!(Identifier))?; + write!(f, "{}", self.to_hex())?; write!(f, ")") } }