test: Drop spent utxos in MiniWallet scan_tx

This commit is contained in:
MacroFake 2022-06-23 12:24:51 +02:00
parent fa04ff61b6
commit dddd7c4d39
No known key found for this signature in database
GPG Key ID: CE2B75697E69A548

View File

@ -116,7 +116,16 @@ class MiniWallet:
self._utxos.append(self._create_utxo(txid=utxo["txid"], vout=utxo["vout"], value=utxo["amount"], height=utxo["height"])) self._utxos.append(self._create_utxo(txid=utxo["txid"], vout=utxo["vout"], value=utxo["amount"], height=utxo["height"]))
def scan_tx(self, tx): def scan_tx(self, tx):
"""Scan the tx for self._scriptPubKey outputs and add them to self._utxos""" """Scan the tx and adjust the internal list of owned utxos"""
for spent in tx["vin"]:
# Mark spent. This may happen when the caller has ownership of a
# utxo that remained in this wallet. For example, by passing
# mark_as_spent=False to get_utxo or by using an utxo returned by a
# create_self_transfer* call.
try:
self.get_utxo(txid=spent["txid"], vout=spent["vout"])
except StopIteration:
pass
for out in tx['vout']: for out in tx['vout']:
if out['scriptPubKey']['hex'] == self._scriptPubKey.hex(): if out['scriptPubKey']['hex'] == self._scriptPubKey.hex():
self._utxos.append(self._create_utxo(txid=tx["txid"], vout=out["n"], value=out["value"], height=0)) self._utxos.append(self._create_utxo(txid=tx["txid"], vout=out["n"], value=out["value"], height=0))