programmingbitcoin
programmingbitcoin copied to clipboard
Bug when signing segwit transaction with non-segwit inputs
When signing a segwit transaction with non-segwit inputs, this line fails because tx_in.witness is not defined.
A simple fix is to initialize self.witness = b'' in the TxIn constructor. Then TxIn.witness is always defined, result += int_to_little_endian(len(tx_in.witness), 1) correctly writes b'\x00' representing empty witness for non-segwit inputs, and for item in tx_in.witness: is skipped because it has nothing to iterate over.
empty list also works