mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-11 03:53:22 +02:00
test: Add "include mempool" flag to MiniWallet rescan_utxos
This commit is contained in:
@@ -119,7 +119,7 @@ class MiniWallet:
|
|||||||
def get_balance(self):
|
def get_balance(self):
|
||||||
return sum(u['value'] for u in self._utxos)
|
return sum(u['value'] for u in self._utxos)
|
||||||
|
|
||||||
def rescan_utxos(self):
|
def rescan_utxos(self, *, include_mempool=True):
|
||||||
"""Drop all utxos and rescan the utxo set"""
|
"""Drop all utxos and rescan the utxo set"""
|
||||||
self._utxos = []
|
self._utxos = []
|
||||||
res = self._test_node.scantxoutset(action="start", scanobjects=[self.get_descriptor()])
|
res = self._test_node.scantxoutset(action="start", scanobjects=[self.get_descriptor()])
|
||||||
@@ -132,6 +132,12 @@ class MiniWallet:
|
|||||||
height=utxo["height"],
|
height=utxo["height"],
|
||||||
coinbase=utxo["coinbase"],
|
coinbase=utxo["coinbase"],
|
||||||
confirmations=res["height"] - utxo["height"] + 1))
|
confirmations=res["height"] - utxo["height"] + 1))
|
||||||
|
if include_mempool:
|
||||||
|
mempool = self._test_node.getrawmempool(verbose=True)
|
||||||
|
# Sort tx by ancestor count. See BlockAssembler::SortForBlock in src/node/miner.cpp
|
||||||
|
sorted_mempool = sorted(mempool.items(), key=lambda item: (item[1]["ancestorcount"], int(item[0], 16)))
|
||||||
|
for txid, _ in sorted_mempool:
|
||||||
|
self.scan_tx(self._test_node.getrawtransaction(txid=txid, verbose=True))
|
||||||
|
|
||||||
def scan_tx(self, tx):
|
def scan_tx(self, tx):
|
||||||
"""Scan the tx and adjust the internal list of owned utxos"""
|
"""Scan the tx and adjust the internal list of owned utxos"""
|
||||||
|
Reference in New Issue
Block a user