Merge rust-bitcoin/rust-bitcoin#1331: add some comments to `Transaction::weight`
17f0d29d08
add some comments to `Transaction::weight` (Andrew Poelstra) Pull request description: FIxes #1159 ACKs for top commit: tcharding: ACK17f0d29d08
Tree-SHA512: ddef69377a7208dfa2794c09f418fb98820b9fc55a32a29f26cd4fc3126bbc8e6c4085e679601330e1225a8404c6eb2b19c6bf374e327cced343197c631b4930
This commit is contained in:
commit
c5277a8ed7
|
@ -717,6 +717,16 @@ impl Transaction {
|
||||||
/// For transactions with an empty witness, this is simply the consensus-serialized size times
|
/// For transactions with an empty witness, this is simply the consensus-serialized size times
|
||||||
/// four. For transactions with a witness, this is the non-witness consensus-serialized size
|
/// four. For transactions with a witness, this is the non-witness consensus-serialized size
|
||||||
/// multiplied by three plus the with-witness consensus-serialized size.
|
/// multiplied by three plus the with-witness consensus-serialized size.
|
||||||
|
///
|
||||||
|
/// For transactions with no inputs, this function will return a value 2 less than the actual
|
||||||
|
/// weight of the serialized transaction. The reason is that zero-input transactions, post-segwit,
|
||||||
|
/// cannot be unambiguously serialized; we make a choice that adds two extra bytes. For more
|
||||||
|
/// details see [BIP 141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki)
|
||||||
|
/// which uses a "input count" of `0x00` as a `marker` for a Segwit-encoded transaction.
|
||||||
|
///
|
||||||
|
/// If you need to use 0-input transactions, we strongly recommend you do so using the PSBT
|
||||||
|
/// API. The unsigned transaction encoded within PSBT is always a non-segwit transaction
|
||||||
|
/// and can therefore avoid this ambiguity.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn weight(&self) -> usize {
|
pub fn weight(&self) -> usize {
|
||||||
self.scaled_size(WITNESS_SCALE_FACTOR)
|
self.scaled_size(WITNESS_SCALE_FACTOR)
|
||||||
|
|
Loading…
Reference in New Issue