Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/util.py
Show First 20 Lines • Show All 569 Lines • ▼ Show 20 Lines | def random_transaction(nodes, amount, min_fee, fee_increment, fee_variants): | ||||
outputs[to_node.getnewaddress()] = float(amount) | outputs[to_node.getnewaddress()] = float(amount) | ||||
rawtx = from_node.createrawtransaction(inputs, outputs) | rawtx = from_node.createrawtransaction(inputs, outputs) | ||||
signresult = from_node.signrawtransaction(rawtx) | signresult = from_node.signrawtransaction(rawtx) | ||||
txid = from_node.sendrawtransaction(signresult["hex"], True) | txid = from_node.sendrawtransaction(signresult["hex"], True) | ||||
return (txid, signresult["hex"], fee) | return (txid, signresult["hex"], fee) | ||||
# Helper to create at least "count" utxos | |||||
# Pass in a fee that is sufficient for relay and mining new transactions. | |||||
def create_confirmed_utxos(fee, node, count, age=101): | |||||
to_generate = int(0.5 * count) + age | |||||
while to_generate > 0: | |||||
node.generate(min(25, to_generate)) | |||||
to_generate -= 25 | |||||
utxos = node.listunspent() | |||||
iterations = count - len(utxos) | |||||
addr1 = node.getnewaddress() | |||||
addr2 = node.getnewaddress() | |||||
if iterations <= 0: | |||||
return utxos | |||||
for i in range(iterations): | |||||
t = utxos.pop() | |||||
inputs = [] | |||||
inputs.append({"txid": t["txid"], "vout": t["vout"]}) | |||||
outputs = {} | |||||
send_value = t['amount'] - fee | |||||
outputs[addr1] = satoshi_round(send_value / 2) | |||||
outputs[addr2] = satoshi_round(send_value / 2) | |||||
raw_tx = node.createrawtransaction(inputs, outputs) | |||||
signed_tx = node.signrawtransaction(raw_tx)["hex"] | |||||
node.sendrawtransaction(signed_tx) | |||||
while (node.getmempoolinfo()['size'] > 0): | |||||
node.generate(1) | |||||
utxos = node.listunspent() | |||||
assert(len(utxos) >= count) | |||||
return utxos | |||||
# Create large OP_RETURN txouts that can be appended to a transaction | # Create large OP_RETURN txouts that can be appended to a transaction | ||||
# to make it large (helper for constructing large transactions). | # to make it large (helper for constructing large transactions). | ||||
def gen_return_txouts(): | def gen_return_txouts(): | ||||
# Some pre-processing to create a bunch of OP_RETURN txouts to insert into transactions we create | # Some pre-processing to create a bunch of OP_RETURN txouts to insert into transactions we create | ||||
# So we have big transactions (and therefore can't fit very many into each block) | # So we have big transactions (and therefore can't fit very many into each block) | ||||
# create one script_pubkey | # create one script_pubkey | ||||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |