X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-block-sync%2Fsrc%2Futils.rs;h=b841f5f9d413d90dfa45ebe8cf18516490a9092e;hb=c01745eec7414a340404398255dcd54580380348;hp=96a2e578877aba57d24c0870f44e594dbc8df9c4;hpb=4894d52d30399c21b7994952a8de0d1d7848c58d;p=rust-lightning diff --git a/lightning-block-sync/src/utils.rs b/lightning-block-sync/src/utils.rs index 96a2e578..b841f5f9 100644 --- a/lightning-block-sync/src/utils.rs +++ b/lightning-block-sync/src/utils.rs @@ -1,54 +1,54 @@ use bitcoin::hashes::hex::FromHex; -use bitcoin::util::uint::Uint256; +use bitcoin::pow::Work; -pub fn hex_to_uint256(hex: &str) -> Result { +pub fn hex_to_work(hex: &str) -> Result { let bytes = <[u8; 32]>::from_hex(hex)?; - Ok(Uint256::from_be_bytes(bytes)) + Ok(Work::from_be_bytes(bytes)) } #[cfg(test)] mod tests { use super::*; - use bitcoin::util::uint::Uint256; + use bitcoin::pow::Work; #[test] - fn hex_to_uint256_empty_str() { - assert!(hex_to_uint256("").is_err()); + fn hex_to_work_empty_str() { + assert!(hex_to_work("").is_err()); } #[test] - fn hex_to_uint256_too_short_str() { + fn hex_to_work_too_short_str() { let hex = String::from_utf8(vec![b'0'; 32]).unwrap(); - assert_eq!(hex_to_uint256(&hex), Err(bitcoin::hashes::hex::Error::InvalidLength(64, 32))); + assert_eq!(hex_to_work(&hex), Err(bitcoin::hashes::hex::Error::InvalidLength(64, 32))); } #[test] - fn hex_to_uint256_too_long_str() { + fn hex_to_work_too_long_str() { let hex = String::from_utf8(vec![b'0'; 128]).unwrap(); - assert_eq!(hex_to_uint256(&hex), Err(bitcoin::hashes::hex::Error::InvalidLength(64, 128))); + assert_eq!(hex_to_work(&hex), Err(bitcoin::hashes::hex::Error::InvalidLength(64, 128))); } #[test] - fn hex_to_uint256_odd_length_str() { + fn hex_to_work_odd_length_str() { let hex = String::from_utf8(vec![b'0'; 65]).unwrap(); - assert_eq!(hex_to_uint256(&hex), Err(bitcoin::hashes::hex::Error::OddLengthString(65))); + assert_eq!(hex_to_work(&hex), Err(bitcoin::hashes::hex::Error::OddLengthString(65))); } #[test] - fn hex_to_uint256_invalid_char() { + fn hex_to_work_invalid_char() { let hex = String::from_utf8(vec![b'G'; 64]).unwrap(); - assert_eq!(hex_to_uint256(&hex), Err(bitcoin::hashes::hex::Error::InvalidChar(b'G'))); + assert_eq!(hex_to_work(&hex), Err(bitcoin::hashes::hex::Error::InvalidChar(b'G'))); } #[test] - fn hex_to_uint256_lowercase_str() { - let hex: String = std::iter::repeat("0123456789abcdef").take(4).collect(); - assert_eq!(hex_to_uint256(&hex).unwrap(), Uint256([0x0123456789abcdefu64; 4])); + fn hex_to_work_lowercase_str() { + let hex: String = std::iter::repeat("1a").take(32).collect(); + assert_eq!(hex_to_work(&hex).unwrap(), Work::from_be_bytes([0x1a; 32])); } #[test] - fn hex_to_uint256_uppercase_str() { - let hex: String = std::iter::repeat("0123456789ABCDEF").take(4).collect(); - assert_eq!(hex_to_uint256(&hex).unwrap(), Uint256([0x0123456789abcdefu64; 4])); + fn hex_to_work_uppercase_str() { + let hex: String = std::iter::repeat("1A").take(32).collect(); + assert_eq!(hex_to_work(&hex).unwrap(), Work::from_be_bytes([0x1A; 32])); } }