Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/util.py
Show First 20 Lines • Show All 507 Lines • ▼ Show 20 Lines | if change > amount * 2: | ||||
outputs[change_address] = Decimal( | outputs[change_address] = Decimal( | ||||
change / 2).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN) | change / 2).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN) | ||||
change = amount_in - amount - outputs[change_address] | change = amount_in - amount - outputs[change_address] | ||||
if change > 0: | if change > 0: | ||||
outputs[from_node.getnewaddress()] = change | outputs[from_node.getnewaddress()] = change | ||||
return outputs | return outputs | ||||
def send_zeropri_transaction(from_node, to_node, amount, fee): | |||||
""" | |||||
Create&broadcast a zero-priority transaction. | |||||
Returns (txid, hex-encoded-txdata) | |||||
Ensures transaction is zero-priority by first creating a send-to-self, | |||||
then using its output | |||||
""" | |||||
# Create a send-to-self with confirmed inputs: | |||||
self_address = from_node.getnewaddress() | |||||
(total_in, inputs) = gather_inputs(from_node, amount + fee * 2) | |||||
outputs = make_change(from_node, total_in, amount + fee, fee) | |||||
outputs[self_address] = float(amount + fee) | |||||
self_rawtx = from_node.createrawtransaction(inputs, outputs) | |||||
self_signresult = from_node.signrawtransactionwithwallet(self_rawtx) | |||||
self_txid = from_node.sendrawtransaction(self_signresult["hex"], True) | |||||
vout = find_output(from_node, self_txid, amount + fee) | |||||
# Now immediately spend the output to create a 1-input, 1-output | |||||
# zero-priority transaction: | |||||
inputs = [{"txid": self_txid, "vout": vout}] | |||||
outputs = {to_node.getnewaddress(): float(amount)} | |||||
rawtx = from_node.createrawtransaction(inputs, outputs) | |||||
signresult = from_node.signrawtransactionwithwallet(rawtx) | |||||
txid = from_node.sendrawtransaction(signresult["hex"], True) | |||||
return (txid, signresult["hex"]) | |||||
def random_zeropri_transaction(nodes, amount, min_fee, fee_increment, fee_variants): | |||||
""" | |||||
Create a random zero-priority transaction. | |||||
Returns (txid, hex-encoded-transaction-data, fee) | |||||
""" | |||||
from_node = random.choice(nodes) | |||||
to_node = random.choice(nodes) | |||||
fee = min_fee + fee_increment * random.randint(0, fee_variants) | |||||
(txid, txhex) = send_zeropri_transaction(from_node, to_node, amount, fee) | |||||
return (txid, txhex, fee) | |||||
def random_transaction(nodes, amount, min_fee, fee_increment, fee_variants): | def random_transaction(nodes, amount, min_fee, fee_increment, fee_variants): | ||||
""" | """ | ||||
Create a random transaction. | Create a random transaction. | ||||
Returns (txid, hex-encoded-transaction-data, fee) | Returns (txid, hex-encoded-transaction-data, fee) | ||||
""" | """ | ||||
from_node = random.choice(nodes) | from_node = random.choice(nodes) | ||||
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) | ||||
▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines |