Add code comment for emtpy input

The line of code `let mut have_witness = self.input.is_empty();` is
puzzling if one does not know _why_ we serialize in BIP141 style when
there are no inputs.

Add a code comment to save devs spending time trying to work out _why_
this is correct.
This commit is contained in:
Tobin Harding 2022-03-09 12:49:41 +11:00
parent 6a0ec1ac47
commit f02b3a8472
1 changed files with 2 additions and 0 deletions

View File

@ -588,6 +588,8 @@ impl Encodable for Transaction {
) -> Result<usize, io::Error> { ) -> Result<usize, io::Error> {
let mut len = 0; let mut len = 0;
len += self.version.consensus_encode(&mut s)?; len += self.version.consensus_encode(&mut s)?;
// To avoid serialization ambiguity, no inputs means we use BIP141 serialization (see
// `Transaction` docs for full explanation).
let mut have_witness = self.input.is_empty(); let mut have_witness = self.input.is_empty();
for input in &self.input { for input in &self.input {
if !input.witness.is_empty() { if !input.witness.is_empty() {