Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/blocktools.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2016 The Bitcoin Core developers | # Copyright (c) 2015-2016 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Utilities for manipulating blocks and transactions.""" | """Utilities for manipulating blocks and transactions.""" | ||||
from .mininode import * | from .mininode import * | ||||
from .script import CScript, OP_TRUE, OP_CHECKSIG, OP_RETURN, OP_PUSHDATA2 | from .script import CScript, OP_TRUE, OP_CHECKSIG, OP_RETURN, OP_PUSHDATA2, OP_DUP, OP_HASH160, OP_EQUALVERIFY | ||||
from .mininode import CTransaction, CTxOut, CTxIn | from .mininode import CTransaction, CTxOut, CTxIn | ||||
from .util import satoshi_round | from .util import 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() | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | while (node.getmempoolinfo()['size'] > 0): | ||||
node.generate(1) | node.generate(1) | ||||
utxos = node.listunspent() | utxos = node.listunspent() | ||||
assert(len(utxos) >= count) | assert(len(utxos) >= count) | ||||
return utxos | return utxos | ||||
def send_big_transactions(node, utxos, num, fee_multiplier): | def send_big_transactions(node, utxos, num, fee_multiplier): | ||||
from .cashaddr import decode | |||||
txids = [] | txids = [] | ||||
padding = "1"*(512*127) | padding = "1"*(512*127) | ||||
addrHash = decode(node.getnewaddress())[2] | |||||
for _ in range(num): | for _ in range(num): | ||||
ctx = CTransaction() | ctx = CTransaction() | ||||
utxo = utxos.pop() | utxo = utxos.pop() | ||||
txid = int(utxo['txid'], 16) | txid = int(utxo['txid'], 16) | ||||
ctx.vin.append(CTxIn(COutPoint(txid, int(utxo["vout"])), b"")) | ctx.vin.append(CTxIn(COutPoint(txid, int(utxo["vout"])), b"")) | ||||
ctx.vout.append(CTxOut(0, CScript( | ctx.vout.append(CTxOut(0, CScript( | ||||
[OP_RETURN, OP_PUSHDATA2, len(padding), bytes(padding, 'utf-8')]))) | [OP_RETURN, OP_PUSHDATA2, len(padding), bytes(padding, 'utf-8')]))) | ||||
ctx.vout.append( | ctx.vout.append( | ||||
CTxOut(int(satoshi_round(utxo['amount']*COIN)), CScript([OP_TRUE]))) | CTxOut(int(satoshi_round(utxo['amount']*COIN)), | ||||
CScript([OP_DUP, OP_HASH160, addrHash, OP_EQUALVERIFY, OP_CHECKSIG]))) | |||||
# Create a proper fee for the transaction to be mined | # Create a proper fee for the transaction to be mined | ||||
ctx.vout[1].nValue -= int(fee_multiplier * node.calculate_fee(ctx)) | ctx.vout[1].nValue -= int(fee_multiplier * node.calculate_fee(ctx)) | ||||
signresult = node.signrawtransaction( | signresult = node.signrawtransaction( | ||||
ToHex(ctx), None, None, "NONE|FORKID") | ToHex(ctx), None, None, "NONE|FORKID") | ||||
txid = node.sendrawtransaction(signresult["hex"], True) | txid = node.sendrawtransaction(signresult["hex"], True) | ||||
txids.append(txid) | txids.append(txid) | ||||
return txids | return txids |