check consistency of results received by get_history
This commit is contained in:
parent
e39a5c9609
commit
a48a971ae6
|
@ -31,6 +31,7 @@ DEFAULT_SERVERS = [
|
||||||
#'uncle-enzo.info:50001:t',
|
#'uncle-enzo.info:50001:t',
|
||||||
#'electrum.bitcoin.cz:50001:t',
|
#'electrum.bitcoin.cz:50001:t',
|
||||||
#'electrum.bitfoo.org:50001:t',
|
#'electrum.bitfoo.org:50001:t',
|
||||||
|
'webbtc.net:50001:t',
|
||||||
'electrum.bysh.me:50001:t',
|
'electrum.bysh.me:50001:t',
|
||||||
'electrum.pdmc.net:50001:t',
|
'electrum.pdmc.net:50001:t',
|
||||||
'ecdsa.org:50001:t'
|
'ecdsa.org:50001:t'
|
||||||
|
|
|
@ -525,9 +525,11 @@ class Wallet:
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
def get_status(self, address):
|
def get_history(self, address):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
h = self.history.get(address)
|
return self.history.get(address)
|
||||||
|
|
||||||
|
def get_status(self, h):
|
||||||
if not h: return None
|
if not h: return None
|
||||||
status = ''
|
status = ''
|
||||||
for tx_hash, height in h:
|
for tx_hash, height in h:
|
||||||
|
@ -981,17 +983,34 @@ class WalletSynchronizer(threading.Thread):
|
||||||
|
|
||||||
if method == 'blockchain.address.subscribe':
|
if method == 'blockchain.address.subscribe':
|
||||||
addr = params[0]
|
addr = params[0]
|
||||||
if self.wallet.get_status(addr) != result:
|
if self.wallet.get_status(self.wallet.get_history(addr)) != result:
|
||||||
self.interface.send([('blockchain.address.get_history', [addr])], 'synchronizer')
|
self.interface.send([('blockchain.address.get_history', [addr])], 'synchronizer')
|
||||||
requested_histories[addr] = result
|
requested_histories[addr] = result
|
||||||
|
|
||||||
elif method == 'blockchain.address.get_history':
|
elif method == 'blockchain.address.get_history':
|
||||||
addr = params[0]
|
addr = params[0]
|
||||||
hist = []
|
hist = []
|
||||||
# in the new protocol, we will receive a list of (tx_hash, height)
|
|
||||||
for item in result: hist.append( (item['tx_hash'], item['height']) )
|
# check that txids are unique
|
||||||
# store it
|
txids = []
|
||||||
|
for item in result:
|
||||||
|
tx_hash = item['tx_hash']
|
||||||
|
if tx_hash not in txids:
|
||||||
|
txids.append(tx_hash)
|
||||||
|
hist.append( (tx_hash, item['height']) )
|
||||||
|
|
||||||
|
if len(hist) != len(result):
|
||||||
|
print "error: non-unique txid"
|
||||||
|
continue
|
||||||
|
|
||||||
|
# check that the status corresponds to what was announced
|
||||||
|
if self.wallet.get_status(hist) != requested_histories.pop(addr):
|
||||||
|
print "error: status mismatch:", addr
|
||||||
|
continue
|
||||||
|
|
||||||
|
# store received history
|
||||||
self.wallet.receive_history_callback(addr, hist)
|
self.wallet.receive_history_callback(addr, hist)
|
||||||
|
|
||||||
# request transactions that we don't have
|
# request transactions that we don't have
|
||||||
for tx_hash, tx_height in hist:
|
for tx_hash, tx_height in hist:
|
||||||
if self.wallet.transactions.get(tx_hash) is None:
|
if self.wallet.transactions.get(tx_hash) is None:
|
||||||
|
|
Loading…
Reference in New Issue