aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/test_framework/blocktools.py
diff options
context:
space:
mode:
authormrbandrews <bandrewsny@gmail.com>2016-06-02 14:42:09 -0400
committermrbandrews <bandrewsny@gmail.com>2016-06-02 14:42:09 -0400
commit291f8aa5daf80eed56d6cefa3d410652b412150a (patch)
treec35a5208f431842091032eb429c415ae8efe36c7 /qa/rpc-tests/test_framework/blocktools.py
parent8c9e681ff8bae61c803cdcc1d05d69cbea5da7bf (diff)
downloadbitcoin-291f8aa5daf80eed56d6cefa3d410652b412150a.tar.xz
Continuing port of java comptool
Diffstat (limited to 'qa/rpc-tests/test_framework/blocktools.py')
-rw-r--r--qa/rpc-tests/test_framework/blocktools.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/qa/rpc-tests/test_framework/blocktools.py b/qa/rpc-tests/test_framework/blocktools.py
index 44232153ac..26cc396315 100644
--- a/qa/rpc-tests/test_framework/blocktools.py
+++ b/qa/rpc-tests/test_framework/blocktools.py
@@ -56,12 +56,27 @@ def create_coinbase(height, pubkey = None):
coinbase.calc_sha256()
return coinbase
-# Create a transaction with an anyone-can-spend output, that spends the
-# nth output of prevtx.
-def create_transaction(prevtx, n, sig, value):
+# Create a transaction.
+# If the scriptPubKey is not specified, make it anyone-can-spend.
+def create_transaction(prevtx, n, sig, value, scriptPubKey=CScript()):
tx = CTransaction()
assert(n < len(prevtx.vout))
tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), sig, 0xffffffff))
- tx.vout.append(CTxOut(value, b""))
+ tx.vout.append(CTxOut(value, scriptPubKey))
tx.calc_sha256()
return tx
+
+def get_legacy_sigopcount_block(block, fAccurate=True):
+ count = 0
+ for tx in block.vtx:
+ count += get_legacy_sigopcount_tx(tx, fAccurate)
+ return count
+
+def get_legacy_sigopcount_tx(tx, fAccurate=True):
+ count = 0
+ for i in tx.vout:
+ count += i.scriptPubKey.GetSigOpCount(fAccurate)
+ for j in tx.vin:
+ # scriptSig might be of type bytes, so convert to CScript for the moment
+ count += CScript(j.scriptSig).GetSigOpCount(fAccurate)
+ return count