Browse Source

wallet: use get_txin_value in get_wallet_delta

patch-4
SomberNight 4 years ago
parent
commit
8b2eb83238
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 19
      electrum/address_synchronizer.py

19
electrum/address_synchronizer.py

@ -144,11 +144,16 @@ class AddressSynchronizer(Logger):
return tx.outputs()[prevout_n].address return tx.outputs()[prevout_n].address
return None return None
def get_txin_value(self, txin: TxInput) -> Optional[int]: def get_txin_value(self, txin: TxInput, *, address: str = None) -> Optional[int]:
if txin.value_sats() is not None: if txin.value_sats() is not None:
return txin.value_sats() return txin.value_sats()
prevout_hash = txin.prevout.txid.hex() prevout_hash = txin.prevout.txid.hex()
prevout_n = txin.prevout.out_idx prevout_n = txin.prevout.out_idx
if address:
d = self.db.get_txo_addr(prevout_hash, address)
for n, v, cb in d:
if n == txin.prevout.out_idx:
return v
tx = self.db.get_transaction(prevout_hash) tx = self.db.get_transaction(prevout_hash)
if tx: if tx:
return tx.outputs()[prevout_n].value return tx.outputs()[prevout_n].value
@ -670,7 +675,7 @@ class AddressSynchronizer(Logger):
def get_wallet_delta(self, tx: Transaction): def get_wallet_delta(self, tx: Transaction):
""" effect of tx on wallet """ """ effect of tx on wallet """
is_relevant = False # "related to wallet?" is_relevant = False # "related to wallet?"
is_mine = False is_mine = False # "is any input mine?"
is_pruned = False is_pruned = False
is_partial = False is_partial = False
v_in = v_out = v_out_mine = 0 v_in = v_out = v_out_mine = 0
@ -679,15 +684,7 @@ class AddressSynchronizer(Logger):
if self.is_mine(addr): if self.is_mine(addr):
is_mine = True is_mine = True
is_relevant = True is_relevant = True
d = self.db.get_txo_addr(txin.prevout.txid.hex(), addr) value = self.get_txin_value(txin, address=addr)
for n, v, cb in d:
if n == txin.prevout.out_idx:
value = v
break
else:
value = None
if value is None:
value = txin.value_sats()
if value is None: if value is None:
is_pruned = True is_pruned = True
else: else:

Loading…
Cancel
Save