[electrum] make TxInput properly support non serialized inputs
Summary:
When I first created the TxInput class, I intended to keep the constructor simple and always provide it with a scriptsig. It turns out this is not the optimal move, as it would require creating an intermediate dummy incomplete scriptsig when building an input from components (type, keys, optional signatures...) just to take it appart again with TxInput.parse_scriptsig.
This diff makes TxInput support both modes:
- inputs from a serialized source
- inputs from keys, type, singatures...
Two factory methods from_scriptsig & from_keys are added to keep a specialized API for each use case, and a helper factory from_coin os added to select the proper factory based on a coin dict.
This allows moving some of the TxInput building logic out of the Transaction class for size estimation and TxInput building from coin dicts. More code will be moved in the next diff (Transaction.input_script(txin), Transaction.get_siglist(txin) & Transaction.get_sorted_pubkeys(txin)
The mock scriptsig in TestSweep need to be fixed to be proper push operations to avoid an error when attempting to parse them.
The consolidation test needs better mock coins ("num_sig", "signatures", "x_pubkeys" & "pubkeys" are expected to be always present)
Depends on D14491
Test Plan: python test_runner.py
Reviewers: #bitcoin_abc, bytesofman
Reviewed By: #bitcoin_abc, bytesofman
Subscribers: bytesofman
Differential Revision: https://reviews.bitcoinabc.org/D14493