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.
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 theTxIn
constructor. ThenTxIn.witness
is always defined,result += int_to_little_endian(len(tx_in.witness), 1)
correctly writesb'\x00'
representing empty witness for non-segwit inputs, andfor item in tx_in.witness:
is skipped because it has nothing to iterate over.