bitcoin: Stop slicing hashes

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.
This commit is contained in:
Tobin C. Harding 2024-04-25 12:53:58 +10:00
parent fe8ce059b4
commit 1c836acf30
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
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::Main => PUBKEY_ADDRESS_PREFIX_MAIN,
NetworkKind::Test => PUBKEY_ADDRESS_PREFIX_TEST, 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[..]) base58::encode_check_to_fmt(fmt, &prefixed[..])
} }
P2sh { hash, network } => { P2sh { hash, network } => {
@ -163,7 +163,7 @@ impl fmt::Display for AddressInner {
NetworkKind::Main => SCRIPT_ADDRESS_PREFIX_MAIN, NetworkKind::Main => SCRIPT_ADDRESS_PREFIX_MAIN,
NetworkKind::Test => SCRIPT_ADDRESS_PREFIX_TEST, 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[..]) base58::encode_check_to_fmt(fmt, &prefixed[..])
} }
Segwit { program, hrp } => { Segwit { program, hrp } => {

View File

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