|
12 | 12 | import json
|
13 | 13 | import logging
|
14 | 14 | import os
|
15 |
| -import random |
16 | 15 | import re
|
17 | 16 | import time
|
18 | 17 | import unittest
|
@@ -469,62 +468,6 @@ def find_output(node, txid, amount, *, blockhash=None):
|
469 | 468 | raise RuntimeError("find_output txid %s : %s not found" % (txid, str(amount)))
|
470 | 469 |
|
471 | 470 |
|
472 |
| -def gather_inputs(from_node, amount_needed, confirmations_required=1): |
473 |
| - """ |
474 |
| - Return a random set of unspent txouts that are enough to pay amount_needed |
475 |
| - """ |
476 |
| - assert confirmations_required >= 0 |
477 |
| - utxo = from_node.listunspent(confirmations_required) |
478 |
| - random.shuffle(utxo) |
479 |
| - inputs = [] |
480 |
| - total_in = Decimal("0.00000000") |
481 |
| - while total_in < amount_needed and len(utxo) > 0: |
482 |
| - t = utxo.pop() |
483 |
| - total_in += t["amount"] |
484 |
| - inputs.append({"txid": t["txid"], "vout": t["vout"], "address": t["address"]}) |
485 |
| - if total_in < amount_needed: |
486 |
| - raise RuntimeError("Insufficient funds: need %d, have %d" % (amount_needed, total_in)) |
487 |
| - return (total_in, inputs) |
488 |
| - |
489 |
| - |
490 |
| -def make_change(from_node, amount_in, amount_out, fee): |
491 |
| - """ |
492 |
| - Create change output(s), return them |
493 |
| - """ |
494 |
| - outputs = {} |
495 |
| - amount = amount_out + fee |
496 |
| - change = amount_in - amount |
497 |
| - if change > amount * 2: |
498 |
| - # Create an extra change output to break up big inputs |
499 |
| - change_address = from_node.getnewaddress() |
500 |
| - # Split change in two, being careful of rounding: |
501 |
| - outputs[change_address] = Decimal(change / 2).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN) |
502 |
| - change = amount_in - amount - outputs[change_address] |
503 |
| - if change > 0: |
504 |
| - outputs[from_node.getnewaddress()] = change |
505 |
| - return outputs |
506 |
| - |
507 |
| - |
508 |
| -def random_transaction(nodes, amount, min_fee, fee_increment, fee_variants): |
509 |
| - """ |
510 |
| - Create a random transaction. |
511 |
| - Returns (txid, hex-encoded-transaction-data, fee) |
512 |
| - """ |
513 |
| - from_node = random.choice(nodes) |
514 |
| - to_node = random.choice(nodes) |
515 |
| - fee = min_fee + fee_increment * random.randint(0, fee_variants) |
516 |
| - |
517 |
| - (total_in, inputs) = gather_inputs(from_node, amount + fee) |
518 |
| - outputs = make_change(from_node, total_in, amount, fee) |
519 |
| - outputs[to_node.getnewaddress()] = float(amount) |
520 |
| - |
521 |
| - rawtx = from_node.createrawtransaction(inputs, outputs) |
522 |
| - signresult = from_node.signrawtransactionwithwallet(rawtx) |
523 |
| - txid = from_node.sendrawtransaction(signresult["hex"], 0) |
524 |
| - |
525 |
| - return (txid, signresult["hex"], fee) |
526 |
| - |
527 |
| - |
528 | 471 | # Helper to create at least "count" utxos
|
529 | 472 | # Pass in a fee that is sufficient for relay and mining new transactions.
|
530 | 473 | def create_confirmed_utxos(fee, node, count):
|
|
0 commit comments