mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-03 02:35:20 +00:00
get_history: return empty history if balance check fails
This commit is contained in:
parent
7f3fc232a0
commit
065145e557
1 changed files with 9 additions and 13 deletions
|
@ -737,8 +737,7 @@ class Abstract_Wallet(object):
|
||||||
delta = self.get_tx_delta(tx_hash, addr)
|
delta = self.get_tx_delta(tx_hash, addr)
|
||||||
hh.append([addr, tx_hash, height, delta])
|
hh.append([addr, tx_hash, height, delta])
|
||||||
|
|
||||||
# 2. merge
|
# 2. merge: the delta of a tx on the domain is the sum of its deltas on addresses
|
||||||
# the delta of a tx on the domain is the sum of its deltas on addresses
|
|
||||||
merged = {}
|
merged = {}
|
||||||
for addr, tx_hash, height, delta in hh:
|
for addr, tx_hash, height, delta in hh:
|
||||||
if tx_hash not in merged:
|
if tx_hash not in merged:
|
||||||
|
@ -749,31 +748,28 @@ class Abstract_Wallet(object):
|
||||||
|
|
||||||
# 3. create sorted list
|
# 3. create sorted list
|
||||||
history = []
|
history = []
|
||||||
#balance = 0
|
|
||||||
for tx_hash, v in merged.items():
|
for tx_hash, v in merged.items():
|
||||||
height, value = v
|
height, value = v
|
||||||
#balance += value
|
|
||||||
conf, timestamp = self.verifier.get_confirmations(tx_hash) if self.verifier else (None, None)
|
conf, timestamp = self.verifier.get_confirmations(tx_hash) if self.verifier else (None, None)
|
||||||
history.append( (tx_hash, conf, value, timestamp) )
|
history.append((tx_hash, conf, value, timestamp))
|
||||||
if self.verifier:
|
|
||||||
history.sort(key = lambda x: self.verifier.get_txpos(x[0]))
|
history.sort(key = lambda x: self.verifier.get_txpos(x[0]))
|
||||||
|
|
||||||
|
# 4. add balance
|
||||||
c, u = self.get_balance(domain)
|
c, u = self.get_balance(domain)
|
||||||
balance = c + u
|
balance = c + u
|
||||||
h2 = []
|
h2 = []
|
||||||
for item in history[::-1]:
|
for item in history[::-1]:
|
||||||
tx_hash, conf, value, timestamp = item
|
tx_hash, conf, value, timestamp = item
|
||||||
h2.insert( 0, (tx_hash, conf, value, timestamp, balance))
|
h2.insert(0, (tx_hash, conf, value, timestamp, balance))
|
||||||
if balance is not None and value is not None:
|
if balance is not None and value is not None:
|
||||||
balance -= value
|
balance -= value
|
||||||
else:
|
else:
|
||||||
balance = None
|
balance = None
|
||||||
|
|
||||||
assert balance in [None, 0]
|
# fixme: this may happen if history is incomplete
|
||||||
#if balance not in [None, 0]:
|
if balance not in [None, 0]:
|
||||||
# print_error("history error")
|
print_error("Error: history not synchronized")
|
||||||
# self.clear_history()
|
return []
|
||||||
# self.update()
|
|
||||||
|
|
||||||
return h2
|
return h2
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue