Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/blocktools.py
Show All 19 Lines | from .messages import ( | ||||
CTransaction, | CTransaction, | ||||
CTxIn, | CTxIn, | ||||
CTxOut, | CTxOut, | ||||
FromHex, | FromHex, | ||||
ToHex, | ToHex, | ||||
ser_string, | ser_string, | ||||
) | ) | ||||
from .txtools import pad_tx | from .txtools import pad_tx | ||||
from .util import satoshi_round | from .util import assert_equal, satoshi_round | ||||
# Create a block (with regtest difficulty) | # Create a block (with regtest difficulty) | ||||
def create_block(hashprev, coinbase, nTime=None): | def create_block(hashprev, coinbase, nTime=None): | ||||
block = CBlock() | block = CBlock() | ||||
if nTime is None: | if nTime is None: | ||||
import time | import time | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | def create_transaction(prevtx, n, sig, value, scriptPubKey=CScript()): | ||||
assert n < len(prevtx.vout) | assert n < len(prevtx.vout) | ||||
tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), sig, 0xffffffff)) | tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), sig, 0xffffffff)) | ||||
tx.vout.append(CTxOut(value, scriptPubKey)) | tx.vout.append(CTxOut(value, scriptPubKey)) | ||||
pad_tx(tx) | pad_tx(tx) | ||||
tx.calc_sha256() | tx.calc_sha256() | ||||
return tx | return tx | ||||
def create_raw_transaction(node, txid, to_address, amount): | |||||
""" Return raw signed transaction spending the first output of the | |||||
input txid. Note that the node must be able to sign for the | |||||
output that is being spent, and the node must not be running | |||||
multiple wallets. | |||||
""" | |||||
inputs = [{"txid": txid, "vout": 0}] | |||||
outputs = {to_address: amount} | |||||
rawtx = node.createrawtransaction(inputs, outputs) | |||||
signresult = node.signrawtransactionwithwallet(rawtx) | |||||
assert_equal(signresult["complete"], True) | |||||
return signresult['hex'] | |||||
def get_legacy_sigopcount_block(block, fAccurate=True): | def get_legacy_sigopcount_block(block, fAccurate=True): | ||||
count = 0 | count = 0 | ||||
for tx in block.vtx: | for tx in block.vtx: | ||||
count += get_legacy_sigopcount_tx(tx, fAccurate) | count += get_legacy_sigopcount_tx(tx, fAccurate) | ||||
return count | return count | ||||
def get_legacy_sigopcount_tx(tx, fAccurate=True): | def get_legacy_sigopcount_tx(tx, fAccurate=True): | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |