From f02b3a84728bc913da6d5b0c1898d0fc8faa2dc5 Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Wed, 9 Mar 2022 12:49:41 +1100 Subject: [PATCH] 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. --- src/blockdata/transaction.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index fcb3f022..e3c9b1f7 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -588,6 +588,8 @@ impl Encodable for Transaction { ) -> Result { let mut len = 0; 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(); for input in &self.input { if !input.witness.is_empty() {