X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-block-sync%2Fsrc%2Futils.rs;h=98a720a2eb2778a48224bf91b963e35b72c2954c;hb=d74c143afe2244c39c66adef0dd13e64bdcf6681;hp=b841f5f9d413d90dfa45ebe8cf18516490a9092e;hpb=51d9ee35e53534bb2d907fc105699114134736a5;p=rust-lightning diff --git a/lightning-block-sync/src/utils.rs b/lightning-block-sync/src/utils.rs index b841f5f9..98a720a2 100644 --- a/lightning-block-sync/src/utils.rs +++ b/lightning-block-sync/src/utils.rs @@ -1,7 +1,7 @@ -use bitcoin::hashes::hex::FromHex; +use bitcoin::hashes::hex::{FromHex, HexToArrayError}; use bitcoin::pow::Work; -pub fn hex_to_work(hex: &str) -> Result { +pub fn hex_to_work(hex: &str) -> Result { let bytes = <[u8; 32]>::from_hex(hex)?; Ok(Work::from_be_bytes(bytes)) } @@ -9,6 +9,7 @@ pub fn hex_to_work(hex: &str) -> Result { #[cfg(test)] mod tests { use super::*; + use bitcoin::hashes::hex::HexToBytesError; use bitcoin::pow::Work; #[test] @@ -19,25 +20,25 @@ mod tests { #[test] fn hex_to_work_too_short_str() { let hex = String::from_utf8(vec![b'0'; 32]).unwrap(); - assert_eq!(hex_to_work(&hex), Err(bitcoin::hashes::hex::Error::InvalidLength(64, 32))); + assert_eq!(hex_to_work(&hex), Err(HexToArrayError::InvalidLength(32, 64))); } #[test] fn hex_to_work_too_long_str() { let hex = String::from_utf8(vec![b'0'; 128]).unwrap(); - assert_eq!(hex_to_work(&hex), Err(bitcoin::hashes::hex::Error::InvalidLength(64, 128))); + assert_eq!(hex_to_work(&hex), Err(HexToArrayError::InvalidLength(128, 64))); } #[test] fn hex_to_work_odd_length_str() { let hex = String::from_utf8(vec![b'0'; 65]).unwrap(); - assert_eq!(hex_to_work(&hex), Err(bitcoin::hashes::hex::Error::OddLengthString(65))); + assert_eq!(hex_to_work(&hex), Err(HexToArrayError::Conversion(HexToBytesError::OddLengthString(65)))); } #[test] fn hex_to_work_invalid_char() { let hex = String::from_utf8(vec![b'G'; 64]).unwrap(); - assert_eq!(hex_to_work(&hex), Err(bitcoin::hashes::hex::Error::InvalidChar(b'G'))); + assert_eq!(hex_to_work(&hex), Err(HexToArrayError::Conversion(HexToBytesError::InvalidChar(b'G')))); } #[test]