|
70 | 70 | SIGHASH_ANYONECANPAY, |
71 | 71 | SIGHASH_NONE, |
72 | 72 | SIGHASH_SINGLE, |
73 | | - SegwitV0SignatureHash, |
74 | 73 | hash160, |
75 | 74 | sign_input_legacy, |
| 75 | + sign_input_segwitv0, |
76 | 76 | ) |
77 | 77 | from test_framework.script_util import ( |
78 | 78 | key_to_p2pk_script, |
@@ -121,10 +121,8 @@ def func_wrapper(self, *args, **kwargs): |
121 | 121 |
|
122 | 122 | def sign_p2pk_witness_input(script, tx_to, in_idx, hashtype, value, key): |
123 | 123 | """Add signature for a P2PK witness script.""" |
124 | | - tx_hash = SegwitV0SignatureHash(script, tx_to, in_idx, hashtype, value) |
125 | | - signature = key.sign_ecdsa(tx_hash) + chr(hashtype).encode('latin-1') |
126 | | - tx_to.wit.vtxinwit[in_idx].scriptWitness.stack = [signature, script] |
127 | | - tx_to.rehash() |
| 124 | + tx_to.wit.vtxinwit[in_idx].scriptWitness.stack = [script] |
| 125 | + sign_input_segwitv0(tx_to, in_idx, script, value, key, hashtype) |
128 | 126 |
|
129 | 127 | def test_transaction_acceptance(node, p2p, tx, with_witness, accepted, reason=None): |
130 | 128 | """Send a transaction to the node and check that it's accepted to the mempool |
@@ -1476,11 +1474,9 @@ def test_uncompressed_pubkey(self): |
1476 | 1474 | tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) |
1477 | 1475 | tx2.vout.append(CTxOut(tx.vout[0].nValue - 1000, script_wsh)) |
1478 | 1476 | script = keyhash_to_p2pkh_script(pubkeyhash) |
1479 | | - sig_hash = SegwitV0SignatureHash(script, tx2, 0, SIGHASH_ALL, tx.vout[0].nValue) |
1480 | | - signature = key.sign_ecdsa(sig_hash) + b'\x01' # 0x1 is SIGHASH_ALL |
1481 | 1477 | tx2.wit.vtxinwit.append(CTxInWitness()) |
1482 | | - tx2.wit.vtxinwit[0].scriptWitness.stack = [signature, pubkey] |
1483 | | - tx2.rehash() |
| 1478 | + tx2.wit.vtxinwit[0].scriptWitness.stack = [pubkey] |
| 1479 | + sign_input_segwitv0(tx2, 0, script, tx.vout[0].nValue, key) |
1484 | 1480 |
|
1485 | 1481 | # Should fail policy test. |
1486 | 1482 | test_transaction_acceptance(self.nodes[0], self.test_node, tx2, True, False, 'non-mandatory-script-verify-flag (Using non-compressed keys in segwit)') |
@@ -1676,11 +1672,13 @@ def test_signature_version_1(self): |
1676 | 1672 | tx2.vout.append(CTxOut(tx.vout[0].nValue, CScript([OP_TRUE]))) |
1677 | 1673 |
|
1678 | 1674 | script = keyhash_to_p2pkh_script(pubkeyhash) |
1679 | | - sig_hash = SegwitV0SignatureHash(script, tx2, 0, SIGHASH_ALL, tx.vout[0].nValue) |
1680 | | - signature = key.sign_ecdsa(sig_hash) + b'\x01' # 0x1 is SIGHASH_ALL |
| 1675 | + tx2.wit.vtxinwit.append(CTxInWitness()) |
| 1676 | + sign_input_segwitv0(tx2, 0, script, tx.vout[0].nValue, key) |
| 1677 | + signature = tx2.wit.vtxinwit[0].scriptWitness.stack.pop() |
1681 | 1678 |
|
1682 | 1679 | # Check that we can't have a scriptSig |
1683 | 1680 | tx2.vin[0].scriptSig = CScript([signature, pubkey]) |
| 1681 | + tx2.rehash() |
1684 | 1682 | block = self.build_next_block() |
1685 | 1683 | self.update_witness_block_with_transactions(block, [tx, tx2]) |
1686 | 1684 | test_witness_block(self.nodes[0], self.test_node, block, accepted=False, |
|
0 commit comments