wallet: implement get_utxos at specific block height
This allows looking up what UTXOs the wallet had at a specific time in the past.
This commit is contained in:
@@ -835,27 +835,47 @@ class AddressSynchronizer(Logger):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
@with_local_height_cached
|
@with_local_height_cached
|
||||||
def get_utxos(self, domain=None, *, excluded_addresses=None,
|
def get_utxos(
|
||||||
mature_only: bool = False, confirmed_only: bool = False,
|
self,
|
||||||
nonlocal_only: bool = False) -> Sequence[PartialTxInput]:
|
domain=None,
|
||||||
|
*,
|
||||||
|
excluded_addresses=None,
|
||||||
|
mature_only: bool = False,
|
||||||
|
confirmed_funding_only: bool = False,
|
||||||
|
confirmed_spending_only: bool = False,
|
||||||
|
nonlocal_only: bool = False,
|
||||||
|
block_height: int = None,
|
||||||
|
) -> Sequence[PartialTxInput]:
|
||||||
|
if block_height is not None:
|
||||||
|
# caller wants the UTXOs we had at a given height; check other parameters
|
||||||
|
assert confirmed_funding_only
|
||||||
|
assert confirmed_spending_only
|
||||||
|
assert nonlocal_only
|
||||||
|
else:
|
||||||
|
block_height = self.get_local_height()
|
||||||
coins = []
|
coins = []
|
||||||
if domain is None:
|
if domain is None:
|
||||||
domain = self.get_addresses()
|
domain = self.get_addresses()
|
||||||
domain = set(domain)
|
domain = set(domain)
|
||||||
if excluded_addresses:
|
if excluded_addresses:
|
||||||
domain = set(domain) - set(excluded_addresses)
|
domain = set(domain) - set(excluded_addresses)
|
||||||
mempool_height = self.get_local_height() + 1 # height of next block
|
mempool_height = block_height + 1 # height of next block
|
||||||
for addr in domain:
|
for addr in domain:
|
||||||
utxos = self.get_addr_utxo(addr)
|
txos = self.get_addr_outputs(addr)
|
||||||
for utxo in utxos.values():
|
for txo in txos.values():
|
||||||
if confirmed_only and utxo.block_height <= 0:
|
if txo.spent_height is not None:
|
||||||
|
if not confirmed_spending_only:
|
||||||
|
continue
|
||||||
|
if confirmed_spending_only and 0 < txo.spent_height <= block_height:
|
||||||
|
continue
|
||||||
|
if confirmed_funding_only and not (0 < txo.block_height <= block_height):
|
||||||
continue
|
continue
|
||||||
if nonlocal_only and utxo.block_height == TX_HEIGHT_LOCAL:
|
if nonlocal_only and txo.block_height in (TX_HEIGHT_LOCAL, TX_HEIGHT_FUTURE):
|
||||||
continue
|
continue
|
||||||
if (mature_only and utxo.is_coinbase_output()
|
if (mature_only and txo.is_coinbase_output()
|
||||||
and utxo.block_height + COINBASE_MATURITY > mempool_height):
|
and txo.block_height + COINBASE_MATURITY > mempool_height):
|
||||||
continue
|
continue
|
||||||
coins.append(utxo)
|
coins.append(txo)
|
||||||
continue
|
continue
|
||||||
return coins
|
return coins
|
||||||
|
|
||||||
|
|||||||
@@ -669,7 +669,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
|||||||
utxos = self.get_utxos(domain,
|
utxos = self.get_utxos(domain,
|
||||||
excluded_addresses=frozen_addresses,
|
excluded_addresses=frozen_addresses,
|
||||||
mature_only=True,
|
mature_only=True,
|
||||||
confirmed_only=confirmed_only,
|
confirmed_funding_only=confirmed_only,
|
||||||
nonlocal_only=nonlocal_only)
|
nonlocal_only=nonlocal_only)
|
||||||
utxos = [utxo for utxo in utxos if not self.is_frozen_coin(utxo)]
|
utxos = [utxo for utxo in utxos if not self.is_frozen_coin(utxo)]
|
||||||
return utxos
|
return utxos
|
||||||
|
|||||||
Reference in New Issue
Block a user