Add code comments to transaction serialization

In an attempt to help super new devs add code comments about transaction
serialization formats pre and post segwit.
This commit is contained in:
Tobin C. Harding 2023-09-18 03:58:01 +10:00
parent 29f20c1d0b
commit 73f7fbf520
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 2 additions and 0 deletions

View File

@ -1022,10 +1022,12 @@ impl Encodable for Transaction {
break; break;
} }
} }
// Legacy transaction serialization format only includes inputs and outputs.
if !have_witness { if !have_witness {
len += self.input.consensus_encode(w)?; len += self.input.consensus_encode(w)?;
len += self.output.consensus_encode(w)?; len += self.output.consensus_encode(w)?;
} else { } else {
// BIP-141 (segwit) transaction serialization also includes marker, flag, and witness data.
len += SEGWIT_MARKER.consensus_encode(w)?; len += SEGWIT_MARKER.consensus_encode(w)?;
len += SEGWIT_FLAG.consensus_encode(w)?; len += SEGWIT_FLAG.consensus_encode(w)?;
len += self.input.consensus_encode(w)?; len += self.input.consensus_encode(w)?;