Skip to content

Commit

Permalink
Rename ntxid to compute_ntxid
Browse files Browse the repository at this point in the history
Computing the ntxid is computationally expensive, so rename the method
accordingly.
  • Loading branch information
yancyribbens committed Jan 23, 2024
1 parent 9bbf79b commit 7af3a58
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions bitcoin/src/blockdata/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,21 @@ impl Transaction {
/// Maximum transaction weight for Bitcoin Core 25.0.
pub const MAX_STANDARD_WEIGHT: Weight = Weight::from_wu(400_000);

/// Computes a "normalized TXID" which does not include any signatures.
///
/// This method is deprecated. Use `compute_ntxid` instead.
#[deprecated(
since = "0.31.0",
note = "ntxid has been renamed to compute_ntxid to note that it's computationally expensive. use compute_ntxid() instead."
)]
pub fn ntxid(&self) -> sha256d::Hash { self.compute_ntxid() }

/// Computes a "normalized TXID" which does not include any signatures.
///
/// This gives a way to identify a transaction that is "the same" as
/// another in the sense of having same inputs and outputs.
pub fn ntxid(&self) -> sha256d::Hash {
#[doc(alias = "ntxid")]
pub fn compute_ntxid(&self) -> sha256d::Hash {
let cloned_tx = Transaction {
version: self.version,
lock_time: self.lock_time,
Expand Down Expand Up @@ -1878,17 +1888,17 @@ mod tests {
let tx_bytes = hex!("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000");
let mut tx: Transaction = deserialize(&tx_bytes).unwrap();

let old_ntxid = tx.ntxid();
let old_ntxid = tx.compute_ntxid();
assert_eq!(
format!("{:x}", old_ntxid),
"c3573dbea28ce24425c59a189391937e00d255150fa973d59d61caf3a06b601d"
);
// changing sigs does not affect it
tx.input[0].script_sig = ScriptBuf::new();
assert_eq!(old_ntxid, tx.ntxid());
assert_eq!(old_ntxid, tx.compute_ntxid());
// changing pks does
tx.output[0].script_pubkey = ScriptBuf::new();
assert!(old_ntxid != tx.ntxid());
assert!(old_ntxid != tx.compute_ntxid());
}

#[test]
Expand Down

0 comments on commit 7af3a58

Please sign in to comment.