fix balance display in flatfly's bug. restore the wallet.update() method
This commit is contained in:
2
electrum
2
electrum
@@ -301,8 +301,6 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
print("Recovering wallet...")
|
print("Recovering wallet...")
|
||||||
WalletSynchronizer(wallet, config).start()
|
WalletSynchronizer(wallet, config).start()
|
||||||
wallet.up_to_date_event.clear()
|
|
||||||
wallet.up_to_date = False
|
|
||||||
wallet.update()
|
wallet.update()
|
||||||
if wallet.is_found():
|
if wallet.is_found():
|
||||||
print("Recovery successful")
|
print("Recovery successful")
|
||||||
|
|||||||
@@ -969,11 +969,7 @@ class ElectrumGui:
|
|||||||
droid.dialogCreateSpinnerProgress("Electrum", msg)
|
droid.dialogCreateSpinnerProgress("Electrum", msg)
|
||||||
droid.dialogShow()
|
droid.dialogShow()
|
||||||
|
|
||||||
wallet.up_to_date_event.clear()
|
wallet.update()
|
||||||
wallet.up_to_date = False
|
|
||||||
wallet.interface.poke('synchronizer')
|
|
||||||
while not wallet.up_to_date:
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
droid.dialogDismiss()
|
droid.dialogDismiss()
|
||||||
droid.vibrate()
|
droid.vibrate()
|
||||||
|
|||||||
@@ -105,6 +105,10 @@ class Wallet:
|
|||||||
def is_up_to_date(self):
|
def is_up_to_date(self):
|
||||||
with self.lock: return self.up_to_date
|
with self.lock: return self.up_to_date
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self.up_to_date = False
|
||||||
|
self.interface.poke('synchronizer')
|
||||||
|
while not self.up_to_date: time.sleep(0.1)
|
||||||
|
|
||||||
def import_key(self, keypair, password):
|
def import_key(self, keypair, password):
|
||||||
address, key = keypair.split(':')
|
address, key = keypair.split(':')
|
||||||
@@ -378,7 +382,7 @@ class Wallet:
|
|||||||
with self.lock:
|
with self.lock:
|
||||||
is_send = False
|
is_send = False
|
||||||
is_pruned = False
|
is_pruned = False
|
||||||
v_in = v_out = v = 0
|
v_in = v_out = v_out_mine = 0
|
||||||
d = self.transactions.get(tx_hash)
|
d = self.transactions.get(tx_hash)
|
||||||
if not d:
|
if not d:
|
||||||
return 0, 0, 0
|
return 0, 0, 0
|
||||||
@@ -391,24 +395,31 @@ class Wallet:
|
|||||||
value = self.prevout_values.get( key )
|
value = self.prevout_values.get( key )
|
||||||
if value is None:
|
if value is None:
|
||||||
is_pruned = True
|
is_pruned = True
|
||||||
break
|
else:
|
||||||
|
v_in += value
|
||||||
v -= value
|
else:
|
||||||
v_in += value
|
is_pruned = True
|
||||||
|
|
||||||
if is_pruned: v = 0
|
|
||||||
for item in d.get('outputs'):
|
for item in d.get('outputs'):
|
||||||
addr = item.get('address')
|
addr = item.get('address')
|
||||||
value = item.get('value')
|
value = item.get('value')
|
||||||
v_out += value
|
v_out += value
|
||||||
if not is_pruned:
|
if addr in addresses:
|
||||||
if addr in addresses: v += value
|
v_out_mine += value
|
||||||
else:
|
|
||||||
if addr not in addresses: v -= value
|
|
||||||
|
|
||||||
# I can compute the fee only if I am the spender and inputs were not pruned
|
if not is_pruned:
|
||||||
fee = v_in - v_out if is_send and not is_pruned else None
|
# all inputs are mine:
|
||||||
return is_send, v, fee
|
fee = v_out - v_in
|
||||||
|
v = v_out_mine - v_in
|
||||||
|
else:
|
||||||
|
# some inputs are mine:
|
||||||
|
fee = None
|
||||||
|
v = v_out_mine - v_in
|
||||||
|
|
||||||
|
#fee = v_in - v_out if not is_pruned else None
|
||||||
|
if tx_hash=='ed20d95ea9ce044f3267a36b9dea328e839934ee4545f7da9586e6d752a2ab32' and addresses == ['1PeahnfNNXF4jidEwjWKShe5KbD9j4eAh1']:
|
||||||
|
print v, fee, v_in, v_out, is_pruned
|
||||||
|
return is_send, v, fee
|
||||||
|
|
||||||
|
|
||||||
def get_tx_details(self, tx_hash):
|
def get_tx_details(self, tx_hash):
|
||||||
@@ -466,17 +477,32 @@ class Wallet:
|
|||||||
self.spent_outputs.append(key)
|
self.spent_outputs.append(key)
|
||||||
|
|
||||||
|
|
||||||
def get_addr_balance(self, addr):
|
def get_addr_balance(self, address):
|
||||||
assert self.is_mine(addr)
|
assert self.is_mine(address)
|
||||||
h = self.history.get(addr,[])
|
h = self.history.get(address,[])
|
||||||
if h == ['*']: return 0,0
|
if h == ['*']: return 0,0
|
||||||
c = u = 0
|
c = u = 0
|
||||||
|
received_coins = []
|
||||||
|
|
||||||
for tx_hash, tx_height in h:
|
for tx_hash, tx_height in h:
|
||||||
# if the tx is mine, then I know its outputs and input values
|
d = self.transactions.get(tx_hash)
|
||||||
# if it is not mine, I only need its outputs
|
if not d: continue
|
||||||
is_mine, v, fee = self.get_tx_value(tx_hash, [addr])
|
v = 0
|
||||||
if v is None:raise
|
|
||||||
|
for item in d.get('inputs'):
|
||||||
|
addr = item.get('address')
|
||||||
|
if addr == address:
|
||||||
|
key = item['prevout_hash'] + ':%d'%item['prevout_n']
|
||||||
|
value = self.prevout_values.get( key )
|
||||||
|
if key in received_coins:
|
||||||
|
v -= value
|
||||||
|
|
||||||
|
for item in d.get('outputs'):
|
||||||
|
addr = item.get('address')
|
||||||
|
key = tx_hash + ':%d'%item['index']
|
||||||
|
if addr == address:
|
||||||
|
v += item.get('value')
|
||||||
|
received_coins.append(key)
|
||||||
|
|
||||||
if tx_height:
|
if tx_height:
|
||||||
c += v
|
c += v
|
||||||
|
|||||||
Reference in New Issue
Block a user