Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/util.py
Show First 20 Lines • Show All 570 Lines • ▼ Show 20 Lines | def random_transaction(nodes, amount, min_fee, fee_increment, fee_variants): | ||||
to_node = random.choice(nodes) | to_node = random.choice(nodes) | ||||
fee = min_fee + fee_increment * random.randint(0, fee_variants) | fee = min_fee + fee_increment * random.randint(0, fee_variants) | ||||
(total_in, inputs) = gather_inputs(from_node, amount + fee) | (total_in, inputs) = gather_inputs(from_node, amount + fee) | ||||
outputs = make_change(from_node, total_in, amount, fee) | outputs = make_change(from_node, total_in, amount, fee) | ||||
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.signrawtransactionwithwallet(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) | ||||
# 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). | ||||
Show All 37 Lines | for _ in range(num): | ||||
inputs = [{"txid": t["txid"], "vout": t["vout"]}] | inputs = [{"txid": t["txid"], "vout": t["vout"]}] | ||||
outputs = {} | outputs = {} | ||||
change = t['amount'] - fee | change = t['amount'] - fee | ||||
outputs[addr] = satoshi_round(change) | outputs[addr] = satoshi_round(change) | ||||
rawtx = node.createrawtransaction(inputs, outputs) | rawtx = node.createrawtransaction(inputs, outputs) | ||||
newtx = rawtx[0:92] | newtx = rawtx[0:92] | ||||
newtx = newtx + txouts | newtx = newtx + txouts | ||||
newtx = newtx + rawtx[94:] | newtx = newtx + rawtx[94:] | ||||
signresult = node.signrawtransaction(newtx, None, None, "NONE|FORKID") | signresult = node.signrawtransactionwithwallet( | ||||
newtx, 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 |