mirror of
https://github.com/mimblewimble/grin.git
synced 2025-05-06 01:01:14 +03:00
Remove usage of try! macro, use ? instead (#3097)
We converted the major part of the code a while ago, but some occurences were left. It's a compiler warning on nightly already.
This commit is contained in:
parent
b4e42bef8d
commit
8a7da89d47
5 changed files with 20 additions and 18 deletions
|
@ -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)? );*
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,9 +42,9 @@ impl PMMRable for TestElem {
|
|||
|
||||
impl Writeable for TestElem {
|
||||
fn write<W: Writer>(&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])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -72,7 +72,10 @@ pub fn to_entropy(mnemonic: &str) -> Result<Vec<u8>, Error> {
|
|||
}
|
||||
|
||||
// u11 vector of indexes for each word
|
||||
let mut indexes: Vec<u16> = r#try!(words.iter().map(|x| search(x)).collect());
|
||||
let mut indexes: Vec<u16> = words
|
||||
.iter()
|
||||
.map(|x| search(x))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
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<T>,
|
||||
{
|
||||
// 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();
|
||||
|
|
|
@ -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, ")")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue