test: remove bare CTransaction .rehash()/.calc_sha256() calls
Since the previous commit, CTransaction object calls to the methods `.rehash()` and `.calc_sha256()` are effectively no-ops if the returned value is not used, so we can just remove them.
This commit is contained in:
1 parent
a2724e3ea3
commit
9b3dce24a3
26 files changed
-158
No files matched your search
@@ -134,7 +134,6 @@ def add_witness_commitment(block, nonce=0):
|
||||
|
||||
# witness commitment is the last OP_RETURN output in coinbase
|
||||
block.vtx[0].vout.append(CTxOut(0, get_witness_script(witness_root, witness_nonce)))
|
||||
block.vtx[0].rehash()
|
||||
block.hashMerkleRoot = block.calc_merkle_root()
|
||||
block.rehash()
|
||||
|
||||
@@ -176,7 +175,6 @@ def create_coinbase(height, pubkey=None, *, script_pubkey=None, extra_output_scr
|
||||
coinbaseoutput2.nValue = 0
|
||||
coinbaseoutput2.scriptPubKey = extra_output_script
|
||||
coinbase.vout.append(coinbaseoutput2)
|
||||
coinbase.calc_sha256()
|
||||
return coinbase
|
||||
|
||||
def create_tx_with_script(prevtx, n, script_sig=b"", *, amount, output_script=None):
|
||||
@@ -191,7 +189,6 @@ def create_tx_with_script(prevtx, n, script_sig=b"", *, amount, output_script=No
|
||||
assert n < len(prevtx.vout)
|
||||
tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), script_sig, SEQUENCE_FINAL))
|
||||
tx.vout.append(CTxOut(amount, output_script))
|
||||
tx.calc_sha256()
|
||||
return tx
|
||||
|
||||
def get_legacy_sigopcount_block(block, accurate=True):
|
||||
|
||||
@@ -682,7 +682,6 @@ class CTransaction:
|
||||
return uint256_from_str(hash256(self.serialize_with_witness()))
|
||||
|
||||
def is_valid(self):
|
||||
self.calc_sha256()
|
||||
for tout in self.vout:
|
||||
if tout.nValue < 0 or tout.nValue > 21000000 * COIN:
|
||||
return False
|
||||
@@ -810,7 +809,6 @@ class CBlock(CBlockHeader):
|
||||
def calc_merkle_root(self):
|
||||
hashes = []
|
||||
for tx in self.vtx:
|
||||
tx.calc_sha256()
|
||||
hashes.append(ser_uint256(tx.sha256))
|
||||
return self.get_merkle_root(hashes)
|
||||
|
||||
|
||||
@@ -694,7 +694,6 @@ def sign_input_legacy(tx, input_index, input_scriptpubkey, privkey, sighash_type
|
||||
assert err is None
|
||||
der_sig = privkey.sign_ecdsa(sighash)
|
||||
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
|
||||
@@ -703,7 +702,6 @@ def sign_input_segwitv0(tx, input_index, input_scriptpubkey, input_amount, privk
|
||||
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.
|
||||
|
||||
Reference in new issue
Block a user