Count the unspent outputs for the given node and return various statistics
(node)
| 18 | node.sendtoaddress(address=discardaddr, amount=balance, subtractfeefromamount=True, avoid_reuse=False) |
| 19 | |
| 20 | def count_unspent(node): |
| 21 | '''Count the unspent outputs for the given node and return various statistics''' |
| 22 | r = { |
| 23 | "total": { |
| 24 | "count": 0, |
| 25 | "sum": 0, |
| 26 | }, |
| 27 | "reused": { |
| 28 | "count": 0, |
| 29 | "sum": 0, |
| 30 | }, |
| 31 | } |
| 32 | supports_reused = True |
| 33 | for utxo in node.listunspent(minconf=0): |
| 34 | r["total"]["count"] += 1 |
| 35 | r["total"]["sum"] += utxo["amount"] |
| 36 | if supports_reused and "reused" in utxo: |
| 37 | if utxo["reused"]: |
| 38 | r["reused"]["count"] += 1 |
| 39 | r["reused"]["sum"] += utxo["amount"] |
| 40 | else: |
| 41 | supports_reused = False |
| 42 | r["reused"]["supported"] = supports_reused |
| 43 | return r |
| 44 | |
| 45 | def assert_unspent(node, total_count=None, total_sum=None, reused_supported=None, reused_count=None, reused_sum=None, margin=0.001): |
| 46 | '''Make assertions about a node's unspent output statistics''' |