Skip to content

Commit 8ec6a60

Browse files
author
ThomasV
committed
compatibility with 0.6 protocol
1 parent 259c5c1 commit 8ec6a60

File tree

5 files changed

+66
-42
lines changed

5 files changed

+66
-42
lines changed

lib/gui_qt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,8 @@ def update_receive_tab(self):
845845
label = self.wallet.labels.get(address,'')
846846
n = 0
847847
h = self.wallet.history.get(address,[])
848+
if h == ['*']: h = []
849+
848850
for tx_hash, tx_height in h:
849851
tx = self.wallet.transactions.get(tx_hash)
850852
if tx: n += 1

lib/interface.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def queue_json_response(self, c):
8484

8585
if error:
8686
print_error("received error:", c)
87+
if msg_id is not None:
88+
with self.lock:
89+
method, params, channel = self.unanswered_requests.pop(msg_id)
90+
response_queue = self.responses[channel]
91+
response_queue.put({'method':method, 'params':params, 'error':error, 'id':msg_id})
92+
8793
return
8894

8995
if msg_id is not None:

lib/verifier.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, interface, config):
3232
self.daemon = True
3333
self.config = config
3434
self.interface = interface
35-
self.transactions = [] # monitored transactions
35+
self.transactions = {} # monitored transactions
3636
self.interface.register_channel('verifier')
3737

3838
self.verified_tx = config.get('verified_tx',{}) # height of verified tx
@@ -49,16 +49,16 @@ def __init__(self, interface, config):
4949
def get_confirmations(self, tx):
5050
""" return the number of confirmations of a monitored transaction. """
5151
with self.lock:
52-
if tx in self.transactions:
52+
if tx in self.transactions.keys():
5353
return (self.local_height - self.verified_tx[tx] + 1) if tx in self.verified_tx else 0
5454
else:
5555
return 0
5656

57-
def add(self, tx_hash):
57+
def add(self, tx_hash, tx_height):
5858
""" add a transaction to the list of monitored transactions. """
5959
with self.lock:
60-
if tx_hash not in self.transactions:
61-
self.transactions.append(tx_hash)
60+
if tx_hash not in self.transactions.keys():
61+
self.transactions[tx_hash] = tx_height
6262

6363
def run(self):
6464
requested_merkle = []
@@ -87,11 +87,11 @@ def run(self):
8787

8888
# request missing tx
8989
if all_chunks:
90-
for tx_hash in self.transactions:
90+
for tx_hash, tx_height in self.transactions.items():
9191
if tx_hash not in self.verified_tx:
9292
if self.merkle_roots.get(tx_hash) is None and tx_hash not in requested_merkle:
9393
print_error('requesting merkle', tx_hash)
94-
self.interface.send([ ('blockchain.transaction.get_merkle',[tx_hash]) ], 'verifier')
94+
self.interface.send([ ('blockchain.transaction.get_merkle',[tx_hash, tx_height]) ], 'verifier')
9595
requested_merkle.append(tx_hash)
9696

9797
# process pending headers

lib/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
ELECTRUM_VERSION = "1.3" # version of the client package
2-
PROTOCOL_VERSION = '0.5' # protocol version requested
2+
PROTOCOL_VERSION = '0.6' # protocol version requested
33
SEED_VERSION = 4 # bump this everytime the seed generation is modified
44
TRANSLATION_ID = 32150 # version of the wiki page

lib/wallet.py

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ def get_tx_value(self, tx_hash, addresses = None):
381381
addr = item.get('address')
382382
if addr in addresses:
383383
key = item['prevout_hash'] + ':%d'%item['prevout_n']
384-
value = self.prevout_values[ key ]
384+
value = self.prevout_values.get( key )
385+
if value is None: continue
385386
v -= value
386387
for item in d.get('outputs'):
387388
addr = item.get('address')
@@ -409,6 +410,7 @@ def update_tx_outputs(self, tx_hash):
409410
def get_addr_balance(self, addr):
410411
assert self.is_mine(addr)
411412
h = self.history.get(addr,[])
413+
if h == ['*']: return 0,0
412414
c = u = 0
413415
for tx_hash, tx_height in h:
414416
v = self.get_tx_value(tx_hash, [addr])
@@ -531,6 +533,7 @@ def get_history(self, address):
531533

532534
def get_status(self, h):
533535
if not h: return None
536+
if h == ['*']: return '*'
534537
status = ''
535538
for tx_hash, height in h:
536539
status += tx_hash + ':%d:' % height
@@ -553,16 +556,18 @@ def receive_tx_callback(self, tx_hash, tx):
553556

554557
def receive_history_callback(self, addr, hist):
555558

556-
if not self.check_new_history(addr, hist):
557-
raise BaseException("error: received history for %s is not consistent with known transactions"%addr)
559+
if hist != ['*']:
560+
if not self.check_new_history(addr, hist):
561+
raise BaseException("error: received history for %s is not consistent with known transactions"%addr)
558562

559563
with self.lock:
560564
self.history[addr] = hist
561565
self.save()
566+
567+
if hist != ['*']:
562568
for tx_hash, tx_height in hist:
563569
if tx_height>0:
564-
self.verifier.add(tx_hash)
565-
570+
self.verifier.add(tx_hash, tx_height)
566571

567572

568573
def get_tx_history(self):
@@ -886,6 +891,7 @@ def set_verifier(self, verifier):
886891

887892
# set the timestamp for transactions that need it
888893
for hist in self.history.values():
894+
if hist == ['*']: continue
889895
for tx_hash, tx_height in hist:
890896
tx = self.transactions.get(tx_hash)
891897
if tx and not tx.get('timestamp'):
@@ -894,7 +900,7 @@ def set_verifier(self, verifier):
894900
self.set_tx_timestamp(tx_hash, timestamp)
895901

896902
if tx_height>0:
897-
self.verifier.add(tx_hash)
903+
self.verifier.add(tx_hash, tx_height)
898904

899905

900906

@@ -936,6 +942,7 @@ def check_new_tx(self, tx_hash, tx):
936942
# 1 check that tx is referenced in addr_history.
937943
addresses = []
938944
for addr, hist in self.history.items():
945+
if hist == ['*']:continue
939946
for txh, height in hist:
940947
if txh == tx_hash:
941948
addresses.append(addr)
@@ -998,6 +1005,7 @@ def run(self):
9981005

9991006
# request any missing transactions
10001007
for history in self.wallet.history.values():
1008+
if history == ['*']: continue
10011009
for tx_hash, tx_height in history:
10021010
if self.wallet.transactions.get(tx_hash) is None and (tx_hash, tx_height) not in missing_tx:
10031011
missing_tx.append( (tx_hash, tx_height) )
@@ -1035,7 +1043,11 @@ def run(self):
10351043
# 3. handle response
10361044
method = r['method']
10371045
params = r['params']
1038-
result = r['result']
1046+
result = r.get('result')
1047+
error = r.get('error')
1048+
if error:
1049+
print "error", r
1050+
continue
10391051

10401052
if method == 'blockchain.address.subscribe':
10411053
addr = params[0]
@@ -1045,34 +1057,38 @@ def run(self):
10451057

10461058
elif method == 'blockchain.address.get_history':
10471059
addr = params[0]
1048-
hist = []
1049-
1050-
# check that txids are unique
1051-
txids = []
1052-
for item in result:
1053-
tx_hash = item['tx_hash']
1054-
if tx_hash not in txids:
1055-
txids.append(tx_hash)
1056-
hist.append( (tx_hash, item['height']) )
1057-
1058-
if len(hist) != len(result):
1059-
raise BaseException("error: server sent history with non-unique txid")
1060-
1061-
# check that the status corresponds to what was announced
1062-
if self.wallet.get_status(hist) != requested_histories.pop(addr):
1063-
raise BaseException("error: status mismatch: %s"%addr)
1060+
if result == ['*']:
1061+
assert requested_histories.pop(addr) == '*'
1062+
self.wallet.receive_history_callback(addr, result)
1063+
else:
1064+
hist = []
1065+
# check that txids are unique
1066+
txids = []
1067+
for item in result:
1068+
tx_hash = item['tx_hash']
1069+
if tx_hash not in txids:
1070+
txids.append(tx_hash)
1071+
hist.append( (tx_hash, item['height']) )
1072+
1073+
if len(hist) != len(result):
1074+
raise BaseException("error: server sent history with non-unique txid")
1075+
1076+
# check that the status corresponds to what was announced
1077+
rs = requested_histories.pop(addr)
1078+
if self.wallet.get_status(hist) != rs:
1079+
raise BaseException("error: status mismatch: %s"%addr)
10641080

1065-
# store received history
1066-
self.wallet.receive_history_callback(addr, hist)
1067-
1068-
# request transactions that we don't have
1069-
for tx_hash, tx_height in hist:
1070-
if self.wallet.transactions.get(tx_hash) is None:
1071-
if (tx_hash, tx_height) not in requested_tx and (tx_hash, tx_height) not in missing_tx:
1072-
missing_tx.append( (tx_hash, tx_height) )
1073-
else:
1074-
timestamp = self.wallet.verifier.get_timestamp(tx_height)
1075-
self.wallet.set_tx_timestamp(tx_hash, timestamp)
1081+
# store received history
1082+
self.wallet.receive_history_callback(addr, hist)
1083+
1084+
# request transactions that we don't have
1085+
for tx_hash, tx_height in hist:
1086+
if self.wallet.transactions.get(tx_hash) is None:
1087+
if (tx_hash, tx_height) not in requested_tx and (tx_hash, tx_height) not in missing_tx:
1088+
missing_tx.append( (tx_hash, tx_height) )
1089+
else:
1090+
timestamp = self.wallet.verifier.get_timestamp(tx_height)
1091+
self.wallet.set_tx_timestamp(tx_hash, timestamp)
10761092

10771093
elif method == 'blockchain.transaction.get':
10781094
tx_hash = params[0]

0 commit comments

Comments
 (0)