There are several instances in functional tests and the framework
(MiniWallet, feature_block.py, p2p_segwit.py) where we create a legacy
ECDSA signature for a certain transaction's input by doing the following
steps:
1) calculate the `LegacySignatureHash` with the desired sighash type
2) create the actual digital signature by calling `ECKey.sign_ecdsa`
on the signature message hash calculated above
3) put the DER-encoded result as CScript data push into
tx input's scriptSig
Create a new helper `sign_input` which hides those details and
takes only the necessary parameters (tx, input index, relevant
scriptPubKey, private key). For
further convenience, the signature is prepended to already existing
data-pushes in scriptSig, in order to avoid rehashing the transaction
after calling the new signing function.
This is a backport of core#28025 and core#32591
Backport notes:
- for now we always use SIGHASH_ALL | SIGHASH_FORKID as a sighash flag, so no need to pass it as a parameter
- see D18733 for why the signing code is in blocktools rather than feature_block.py
- we weren't testing what we expected to test in feature_block.py wrt to InvalidOPIFConstruction and DisabledOpcode_*. The blocks including these transactions were accepted because `sign_tx` was overwriting the problematic scriptsig. Now they properly fail block inclusion for the expected reason (pushonly rule)