jimmysong / programmingbitcoin

Repository for the book
Other
1.75k stars 656 forks source link

Bug when signing segwit transaction with non-segwit inputs #155

Open justinmoon opened 5 years ago

justinmoon commented 5 years ago

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.

scgbckbone commented 4 years ago

empty list also works