@@ -381,7 +381,8 @@ def get_tx_value(self, tx_hash, addresses = None):
381
381
addr = item .get ('address' )
382
382
if addr in addresses :
383
383
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
385
386
v -= value
386
387
for item in d .get ('outputs' ):
387
388
addr = item .get ('address' )
@@ -409,6 +410,7 @@ def update_tx_outputs(self, tx_hash):
409
410
def get_addr_balance (self , addr ):
410
411
assert self .is_mine (addr )
411
412
h = self .history .get (addr ,[])
413
+ if h == ['*' ]: return 0 ,0
412
414
c = u = 0
413
415
for tx_hash , tx_height in h :
414
416
v = self .get_tx_value (tx_hash , [addr ])
@@ -531,6 +533,7 @@ def get_history(self, address):
531
533
532
534
def get_status (self , h ):
533
535
if not h : return None
536
+ if h == ['*' ]: return '*'
534
537
status = ''
535
538
for tx_hash , height in h :
536
539
status += tx_hash + ':%d:' % height
@@ -553,16 +556,18 @@ def receive_tx_callback(self, tx_hash, tx):
553
556
554
557
def receive_history_callback (self , addr , hist ):
555
558
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 )
558
562
559
563
with self .lock :
560
564
self .history [addr ] = hist
561
565
self .save ()
566
+
567
+ if hist != ['*' ]:
562
568
for tx_hash , tx_height in hist :
563
569
if tx_height > 0 :
564
- self .verifier .add (tx_hash )
565
-
570
+ self .verifier .add (tx_hash , tx_height )
566
571
567
572
568
573
def get_tx_history (self ):
@@ -886,6 +891,7 @@ def set_verifier(self, verifier):
886
891
887
892
# set the timestamp for transactions that need it
888
893
for hist in self .history .values ():
894
+ if hist == ['*' ]: continue
889
895
for tx_hash , tx_height in hist :
890
896
tx = self .transactions .get (tx_hash )
891
897
if tx and not tx .get ('timestamp' ):
@@ -894,7 +900,7 @@ def set_verifier(self, verifier):
894
900
self .set_tx_timestamp (tx_hash , timestamp )
895
901
896
902
if tx_height > 0 :
897
- self .verifier .add (tx_hash )
903
+ self .verifier .add (tx_hash , tx_height )
898
904
899
905
900
906
@@ -936,6 +942,7 @@ def check_new_tx(self, tx_hash, tx):
936
942
# 1 check that tx is referenced in addr_history.
937
943
addresses = []
938
944
for addr , hist in self .history .items ():
945
+ if hist == ['*' ]:continue
939
946
for txh , height in hist :
940
947
if txh == tx_hash :
941
948
addresses .append (addr )
@@ -998,6 +1005,7 @@ def run(self):
998
1005
999
1006
# request any missing transactions
1000
1007
for history in self .wallet .history .values ():
1008
+ if history == ['*' ]: continue
1001
1009
for tx_hash , tx_height in history :
1002
1010
if self .wallet .transactions .get (tx_hash ) is None and (tx_hash , tx_height ) not in missing_tx :
1003
1011
missing_tx .append ( (tx_hash , tx_height ) )
@@ -1035,7 +1043,11 @@ def run(self):
1035
1043
# 3. handle response
1036
1044
method = r ['method' ]
1037
1045
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
1039
1051
1040
1052
if method == 'blockchain.address.subscribe' :
1041
1053
addr = params [0 ]
@@ -1045,34 +1057,38 @@ def run(self):
1045
1057
1046
1058
elif method == 'blockchain.address.get_history' :
1047
1059
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 )
1064
1080
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 )
1076
1092
1077
1093
elif method == 'blockchain.transaction.get' :
1078
1094
tx_hash = params [0 ]
0 commit comments