Merge rust-bitcoin/rust-bitcoin#2577: Fix cargo cult programming

290e4418e6 units: Fix cargo cult programming (Tobin C. Harding)

Pull request description:

  When creating the ParseIntError in `hex_u32` I (tobin) just cargo cult programmed the generic stuff without thinking.

  - The `is_signed` field is used to denote whether we were attempting to parse a signed or unsigned integer, it should be `false`.
  - The `bits` field should be directly set to 32.

ACKs for top commit:
  apoelstra:
    ACK 290e4418e6
  sanket1729:
    ACK 290e4418e6

Tree-SHA512: 7dfd9f0cd98eff1c2b27a92dac5c4e2fe0fa4ae724528ef741fe43d8d923e2d31cbdcd4e540ecfba1b953860dc2b728a958e756e2d2012d9a9e715c0ca3c5068
This commit is contained in:
Andrew Poelstra 2024-03-19 15:31:37 +00:00
commit 6389d3f7fc
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 2 additions and 2 deletions

View File

View File

@ -108,8 +108,8 @@ pub(crate) fn strip_hex_prefix(s: &str) -> &str {
pub fn hex_u32<S: AsRef<str> + Into<String>>(s: S) -> Result<u32, ParseIntError> {
u32::from_str_radix(strip_hex_prefix(s.as_ref()), 16).map_err(|error| ParseIntError {
input: s.into(),
bits: u8::try_from(core::mem::size_of::<u32>() * 8).expect("max is 32 bits for u32"),
is_signed: u32::try_from(-1i8).is_ok(),
bits: 32,
is_signed: false,
source: error,
})
}