Rename ntxid to compute_ntxid
Computing the ntxid is computationally expensive, so rename the method accordingly.
This commit is contained in:
parent
9bbf79b08c
commit
7af3a58e91
|
@ -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,
|
||||
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue