Merge rust-bitcoin/rust-bitcoin#2718: bitcoin: Stop slicing hashes

1c836acf30 bitcoin: Stop slicing hashes (Tobin C. Harding)

Pull request description:

  As part of the ongoing effort to improve `hashes`; stop using slicing of hash types and use `as_byte_array()` to get an array reference instead. This gives us more flexability to modify the `hashes` module.

ACKs for top commit:
  apoelstra:
    ACK 1c836acf30
  storopoli:
    ACK 1c836acf30
  clarkmoody:
    ACK 1c836acf30

Tree-SHA512: ca4becfc9bae13127aae09bd1eb5e03efc670fb4e56c2aba1cf0e3cf5f5a762dd8c5cff8ff7c15167902b7440f70202e0884f1e4d3bb651476019c78d2be3408
This commit is contained in:
Andrew Poelstra 2024-04-28 22:34:27 +00:00
commit 16292a8797
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 4 additions and 4 deletions

View File

@ -154,7 +154,7 @@ impl fmt::Display for AddressInner {
NetworkKind::Main => PUBKEY_ADDRESS_PREFIX_MAIN,
NetworkKind::Test => PUBKEY_ADDRESS_PREFIX_TEST,
};
prefixed[1..].copy_from_slice(&hash[..]);
prefixed[1..].copy_from_slice(hash.as_byte_array());
base58::encode_check_to_fmt(fmt, &prefixed[..])
}
P2sh { hash, network } => {
@ -163,7 +163,7 @@ impl fmt::Display for AddressInner {
NetworkKind::Main => SCRIPT_ADDRESS_PREFIX_MAIN,
NetworkKind::Test => SCRIPT_ADDRESS_PREFIX_TEST,
};
prefixed[1..].copy_from_slice(&hash[..]);
prefixed[1..].copy_from_slice(hash.as_byte_array());
base58::encode_check_to_fmt(fmt, &prefixed[..])
}
Segwit { program, hrp } => {

View File

@ -818,9 +818,9 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
let mut single_enc = LegacySighash::engine();
self.tx.borrow().output[input_index].consensus_encode(&mut single_enc)?;
let hash = LegacySighash::from_engine(single_enc);
writer.write_all(&hash[..])?;
writer.write_all(hash.as_byte_array())?;
} else {
writer.write_all(&zero_hash[..])?;
writer.write_all(zero_hash.as_byte_array())?;
}
self.tx.borrow().lock_time.consensus_encode(writer)?;