wallet: simplify get_history
some years ago wallet.get_tx_delta returned Optional[int] but it returns int now
This commit is contained in:
@@ -52,9 +52,9 @@ TX_HEIGHT_UNCONFIRMED = 0
|
|||||||
class HistoryItem(NamedTuple):
|
class HistoryItem(NamedTuple):
|
||||||
txid: str
|
txid: str
|
||||||
tx_mined_status: TxMinedInfo
|
tx_mined_status: TxMinedInfo
|
||||||
delta: Optional[int]
|
delta: int
|
||||||
fee: Optional[int]
|
fee: Optional[int]
|
||||||
balance: Optional[int]
|
balance: int
|
||||||
|
|
||||||
|
|
||||||
class TxWalletDelta(NamedTuple):
|
class TxWalletDelta(NamedTuple):
|
||||||
@@ -476,15 +476,11 @@ class AddressSynchronizer(Logger):
|
|||||||
domain = set(domain)
|
domain = set(domain)
|
||||||
# 1. Get the history of each address in the domain, maintain the
|
# 1. Get the history of each address in the domain, maintain the
|
||||||
# delta of a tx as the sum of its deltas on domain addresses
|
# delta of a tx as the sum of its deltas on domain addresses
|
||||||
tx_deltas = defaultdict(int) # type: Dict[str, Optional[int]]
|
tx_deltas = defaultdict(int) # type: Dict[str, int]
|
||||||
for addr in domain:
|
for addr in domain:
|
||||||
h = self.get_address_history(addr)
|
h = self.get_address_history(addr)
|
||||||
for tx_hash, height in h:
|
for tx_hash, height in h:
|
||||||
delta = self.get_tx_delta(tx_hash, addr)
|
tx_deltas[tx_hash] += self.get_tx_delta(tx_hash, addr)
|
||||||
if delta is None or tx_deltas[tx_hash] is None:
|
|
||||||
tx_deltas[tx_hash] = None
|
|
||||||
else:
|
|
||||||
tx_deltas[tx_hash] += delta
|
|
||||||
# 2. create sorted history
|
# 2. create sorted history
|
||||||
history = []
|
history = []
|
||||||
for tx_hash in tx_deltas:
|
for tx_hash in tx_deltas:
|
||||||
@@ -503,13 +499,10 @@ class AddressSynchronizer(Logger):
|
|||||||
delta=delta,
|
delta=delta,
|
||||||
fee=fee,
|
fee=fee,
|
||||||
balance=balance))
|
balance=balance))
|
||||||
if balance is None or delta is None:
|
balance -= delta
|
||||||
balance = None
|
|
||||||
else:
|
|
||||||
balance -= delta
|
|
||||||
h2.reverse()
|
h2.reverse()
|
||||||
# fixme: this may happen if history is incomplete
|
# fixme: this may happen if history is incomplete
|
||||||
if balance not in [None, 0]:
|
if balance != 0:
|
||||||
self.logger.warning("history not synchronized")
|
self.logger.warning("history not synchronized")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -657,7 +650,7 @@ class AddressSynchronizer(Logger):
|
|||||||
return 0, 0
|
return 0, 0
|
||||||
|
|
||||||
@with_transaction_lock
|
@with_transaction_lock
|
||||||
def get_tx_delta(self, tx_hash, address):
|
def get_tx_delta(self, tx_hash: str, address: str) -> int:
|
||||||
"""effect of tx on address"""
|
"""effect of tx on address"""
|
||||||
delta = 0
|
delta = 0
|
||||||
# subtract the value of coins sent from address
|
# subtract the value of coins sent from address
|
||||||
|
|||||||
Reference in New Issue
Block a user