mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-11 03:53:22 +02:00
test: refactor: deduplicate segwitv0 ECDSA signing for tx inputs
Follow-up for #28025.
This commit is contained in:
@@ -699,6 +699,15 @@ def sign_input_legacy(tx, input_index, input_scriptpubkey, privkey, sighash_type
|
||||
tx.vin[input_index].scriptSig = bytes(CScript([der_sig + bytes([sighash_type])])) + tx.vin[input_index].scriptSig
|
||||
tx.rehash()
|
||||
|
||||
def sign_input_segwitv0(tx, input_index, input_scriptpubkey, input_amount, privkey, sighash_type=SIGHASH_ALL):
|
||||
"""Add segwitv0 ECDSA signature for a given transaction input. Note that the signature
|
||||
is inserted at the bottom of the witness stack, i.e. additional witness data
|
||||
needed (e.g. pubkey for P2WPKH) can already be set before."""
|
||||
sighash = SegwitV0SignatureHash(input_scriptpubkey, tx, input_index, sighash_type, input_amount)
|
||||
der_sig = privkey.sign_ecdsa(sighash)
|
||||
tx.wit.vtxinwit[input_index].scriptWitness.stack.insert(0, der_sig + bytes([sighash_type]))
|
||||
tx.rehash()
|
||||
|
||||
# TODO: Allow cached hashPrevouts/hashSequence/hashOutputs to be provided.
|
||||
# Performance optimization probably not necessary for python tests, however.
|
||||
# Note that this corresponds to sigversion == 1 in EvalScript, which is used
|
||||
|
Reference in New Issue
Block a user