Stop using all_zeros

Recently we deprecated the `all_zeros` functions on `Wtxid` and
`Txid` but for some reason our usage of them is not triggering a lint
warning.

Note please that this changes logic slightly, for example by using an
array of `0xFF` bytes instead of all zeros. Done in an effort to make it
even more obvious that the value is a dummy value and not mix it up with
the all zeros being used for coinbase thing.
This commit is contained in:
Tobin C. Harding 2024-09-11 10:37:05 +10:00
parent d69c241b5c
commit 832b726d03
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
7 changed files with 10 additions and 10 deletions

View File

@ -101,7 +101,7 @@ fn dummy_unspent_transaction_outputs() -> Vec<(OutPoint, TxOut)> {
.script_pubkey();
let out_point_1 = OutPoint {
txid: Txid::all_zeros(), // Obviously invalid.
txid: Txid::from_byte_array([0xFF; 32]), // Arbitrary invalid dummy value.
vout: 0,
};
@ -115,7 +115,7 @@ fn dummy_unspent_transaction_outputs() -> Vec<(OutPoint, TxOut)> {
.script_pubkey();
let out_point_2 = OutPoint {
txid: Txid::all_zeros(), // Obviously invalid.
txid: Txid::from_byte_array([0xFF; 32]), // Arbitrary invalid dummy value.
vout: 1,
};

View File

@ -119,7 +119,7 @@ fn dummy_unspent_transaction_output(wpkh: WPubkeyHash) -> (OutPoint, TxOut) {
let script_pubkey = ScriptBuf::new_p2wpkh(wpkh);
let out_point = OutPoint {
txid: Txid::all_zeros(), // Obviously invalid.
txid: Txid::from_byte_array([0xFF; 32]), // Arbitrary invalid dummy value.
vout: 0,
};

View File

@ -119,7 +119,7 @@ fn dummy_unspent_transaction_output<C: Verification>(
let script_pubkey = ScriptBuf::new_p2tr(secp, internal_key, None);
let out_point = OutPoint {
txid: Txid::all_zeros(), // Obviously invalid.
txid: Txid::from_byte_array([0xFF; 32]), // Arbitrary invalid dummy value.
vout: 0,
};

View File

@ -111,7 +111,7 @@ fn dummy_unspent_transaction_outputs() -> Vec<(OutPoint, TxOut)> {
.script_pubkey();
let out_point_1 = OutPoint {
txid: Txid::all_zeros(), // Obviously invalid.
txid: Txid::from_byte_array([0xFF; 32]), // Arbitrary invalid dummy value.
vout: 0,
};
@ -125,7 +125,7 @@ fn dummy_unspent_transaction_outputs() -> Vec<(OutPoint, TxOut)> {
.script_pubkey();
let out_point_2 = OutPoint {
txid: Txid::all_zeros(), // Obviously invalid.
txid: Txid::from_byte_array([0xFF; 32]), // Arbitrary invalid dummy value.
vout: 1,
};

View File

@ -305,7 +305,7 @@ impl Block {
let hashes = self.txdata.iter().enumerate().map(|(i, t)| {
if i == 0 {
// Replace the first hash with zeroes.
Wtxid::all_zeros()
Wtxid::COINBASE
} else {
t.compute_wtxid()
}

View File

@ -226,7 +226,7 @@ mod test {
assert_eq!(gen.version, transaction::Version::ONE);
assert_eq!(gen.input.len(), 1);
assert_eq!(gen.input[0].previous_output.txid, Txid::all_zeros());
assert_eq!(gen.input[0].previous_output.txid, Txid::COINBASE_PREVOUT);
assert_eq!(gen.input[0].previous_output.vout, 0xFFFFFFFF);
assert_eq!(serialize(&gen.input[0].script_sig),
hex!("4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73"));

View File

@ -8,8 +8,8 @@
//! # use bitcoin::Txid;
//! # use bitcoin::merkle_tree::{MerkleNode as _, TxMerkleNode};
//! # use bitcoin::hashes::Hash;
//! # let tx1 = Txid::all_zeros(); // Dummy hash values.
//! # let tx2 = Txid::all_zeros();
//! # let tx1 = Txid::from_byte_array([0xAA; 32]); // Arbitrary dummy hash values.
//! # let tx2 = Txid::from_byte_array([0xFF; 32]);
//! let tx_hashes = vec![tx1, tx2]; // All the hashes we wish to merkelize.
//! let root = TxMerkleNode::calculate_root(tx_hashes.into_iter());
//! ```