1 use bitcoin::util::uint::Uint256;
3 pub fn hex_to_uint256(hex: &str) -> Option<Uint256> {
4 if hex.len() != 64 { return None; }
5 let mut out = [0u64; 4];
8 for (idx, c) in hex.as_bytes().iter().enumerate() {
11 b'A'..=b'F' => b |= (c - b'A' + 10) as u64,
12 b'a'..=b'f' => b |= (c - b'a' + 10) as u64,
13 b'0'..=b'9' => b |= (c - b'0') as u64,
17 out[3 - (idx / 16)] = b;
21 Some(Uint256::from(&out[..]))
24 #[cfg(feature = "rpc-client")]
25 pub fn hex_to_vec(hex: &str) -> Option<Vec<u8>> {
26 let mut out = Vec::with_capacity(hex.len() / 2);
29 for (idx, c) in hex.as_bytes().iter().enumerate() {
32 b'A'..=b'F' => b |= c - b'A' + 10,
33 b'a'..=b'f' => b |= c - b'a' + 10,
34 b'0'..=b'9' => b |= c - b'0',