blockchain.headers subscription service
[electrum-server.git] / backends / abe / __init__.py
1 from Abe.util import hash_to_address, decode_check_address
2 from Abe.DataStore import DataStore as Datastore_class
3 from Abe import DataStore, readconf, BCDataStream,  deserialize, util, base58
4
5 import binascii
6
7 import thread, traceback, sys, urllib, operator
8 from json import dumps, loads
9 from Queue import Queue
10 import time, threading
11
12
13 import hashlib
14 encode = lambda x: x[::-1].encode('hex')
15 decode = lambda x: x.decode('hex')[::-1]
16 Hash = lambda x: hashlib.sha256(hashlib.sha256(x).digest()).digest()
17
18 def rev_hex(s):
19     return s.decode('hex')[::-1].encode('hex')
20
21 def int_to_hex(i, length=1):
22     s = hex(i)[2:].rstrip('L')
23     s = "0"*(2*length - len(s)) + s
24     return rev_hex(s)
25
26 def header_to_string(res):
27     s = int_to_hex(res.get('version'),4) \
28         + rev_hex(res.get('prev_block_hash')) \
29         + rev_hex(res.get('merkle_root')) \
30         + int_to_hex(int(res.get('timestamp')),4) \
31         + int_to_hex(int(res.get('bits')),4) \
32         + int_to_hex(int(res.get('nonce')),4)
33     return s
34
35
36 class AbeStore(Datastore_class):
37
38     def __init__(self, config):
39         conf = DataStore.CONFIG_DEFAULTS
40         args, argv = readconf.parse_argv( [], conf)
41         args.dbtype = config.get('database','type')
42         if args.dbtype == 'sqlite3':
43             args.connect_args = { 'database' : config.get('database','database') }
44         elif args.dbtype == 'MySQLdb':
45             args.connect_args = { 'db' : config.get('database','database'), 'user' : config.get('database','username'), 'passwd' : config.get('database','password') }
46         elif args.dbtype == 'psycopg2':
47             args.connect_args = { 'database' : config.get('database','database') }
48
49         coin = config.get('server', 'coin')
50         self.addrtype = 0
51         if coin == 'litecoin':
52             print 'Litecoin settings:'
53             datadir = config.get('server','datadir')
54             print '  datadir = ' + datadir
55             args.datadir = [{"dirname":datadir,"chain":"Litecoin","code3":"LTC","address_version":"\u0030"}]
56             print '  addrtype = 48'
57             self.addrtype = 48
58
59         Datastore_class.__init__(self,args)
60
61         # Use 1 (Bitcoin) if chain_id is not sent
62         self.chain_id = self.datadirs[0]["chain_id"] or 1
63         print 'Coin chain_id = %d' % self.chain_id
64
65         self.sql_limit = int( config.get('database','limit') )
66
67         self.tx_cache = {}
68         self.bitcoind_url = 'http://%s:%s@%s:%s/' % ( config.get('bitcoind','user'), config.get('bitcoind','password'), config.get('bitcoind','host'), config.get('bitcoind','port'))
69
70         self.address_queue = Queue()
71
72         self.dblock = thread.allocate_lock()
73         self.last_tx_id = 0
74         self.known_mempool_hashes = []
75
76     
77     def import_tx(self, tx, is_coinbase):
78         tx_id = super(AbeStore, self).import_tx(tx, is_coinbase)
79         self.last_tx_id = tx_id
80         return tx_id
81         
82
83
84
85     def import_block(self, b, chain_ids=frozenset()):
86         #print "import block"
87         block_id = super(AbeStore, self).import_block(b, chain_ids)
88         for pos in xrange(len(b['transactions'])):
89             tx = b['transactions'][pos]
90             if 'hash' not in tx:
91                 tx['hash'] = util.double_sha256(tx['tx'])
92             tx_id = self.tx_find_id_and_value(tx)
93             if tx_id:
94                 self.update_tx_cache(tx_id)
95             else:
96                 print "error: import_block: no tx_id"
97         return block_id
98
99
100     def update_tx_cache(self, txid):
101         inrows = self.get_tx_inputs(txid, False)
102         for row in inrows:
103             _hash = self.binout(row[6])
104             if not _hash:
105                 #print "WARNING: missing tx_in for tx", txid
106                 continue
107
108             address = hash_to_address(chr(self.addrtype), _hash)
109             if self.tx_cache.has_key(address):
110                 print "cache: invalidating", address
111                 self.tx_cache.pop(address)
112             self.address_queue.put(address)
113
114         outrows = self.get_tx_outputs(txid, False)
115         for row in outrows:
116             _hash = self.binout(row[6])
117             if not _hash:
118                 #print "WARNING: missing tx_out for tx", txid
119                 continue
120
121             address = hash_to_address(chr(self.addrtype), _hash)
122             if self.tx_cache.has_key(address):
123                 print "cache: invalidating", address
124                 self.tx_cache.pop(address)
125             self.address_queue.put(address)
126
127     def safe_sql(self,sql, params=(), lock=True):
128
129         error = False
130         try:
131             if lock: self.dblock.acquire()
132             ret = self.selectall(sql,params)
133         except:
134             error = True
135             traceback.print_exc(file=sys.stdout)
136         finally:
137             if lock: self.dblock.release()
138
139         if error: 
140             raise BaseException('sql error')
141
142         return ret
143             
144
145     def get_tx_outputs(self, tx_id, lock=True):
146         return self.safe_sql("""SELECT
147                 txout.txout_pos,
148                 txout.txout_scriptPubKey,
149                 txout.txout_value,
150                 nexttx.tx_hash,
151                 nexttx.tx_id,
152                 txin.txin_pos,
153                 pubkey.pubkey_hash
154               FROM txout
155               LEFT JOIN txin ON (txin.txout_id = txout.txout_id)
156               LEFT JOIN pubkey ON (pubkey.pubkey_id = txout.pubkey_id)
157               LEFT JOIN tx nexttx ON (txin.tx_id = nexttx.tx_id)
158              WHERE txout.tx_id = %d 
159              ORDER BY txout.txout_pos
160         """%(tx_id), (), lock)
161
162     def get_tx_inputs(self, tx_id, lock=True):
163         return self.safe_sql(""" SELECT
164                 txin.txin_pos,
165                 txin.txin_scriptSig,
166                 txout.txout_value,
167                 COALESCE(prevtx.tx_hash, u.txout_tx_hash),
168                 prevtx.tx_id,
169                 COALESCE(txout.txout_pos, u.txout_pos),
170                 pubkey.pubkey_hash
171               FROM txin
172               LEFT JOIN txout ON (txout.txout_id = txin.txout_id)
173               LEFT JOIN pubkey ON (pubkey.pubkey_id = txout.pubkey_id)
174               LEFT JOIN tx prevtx ON (txout.tx_id = prevtx.tx_id)
175               LEFT JOIN unlinked_txin u ON (u.txin_id = txin.txin_id)
176              WHERE txin.tx_id = %d
177              ORDER BY txin.txin_pos
178              """%(tx_id,), (), lock)
179
180
181     def get_address_out_rows(self, dbhash):
182         out = self.safe_sql(""" SELECT
183                 b.block_nTime,
184                 cc.chain_id,
185                 b.block_height,
186                 1,
187                 b.block_hash,
188                 tx.tx_hash,
189                 tx.tx_id,
190                 txin.txin_pos,
191                 -prevout.txout_value
192               FROM chain_candidate cc
193               JOIN block b ON (b.block_id = cc.block_id)
194               JOIN block_tx ON (block_tx.block_id = b.block_id)
195               JOIN tx ON (tx.tx_id = block_tx.tx_id)
196               JOIN txin ON (txin.tx_id = tx.tx_id)
197               JOIN txout prevout ON (txin.txout_id = prevout.txout_id)
198               JOIN pubkey ON (pubkey.pubkey_id = prevout.pubkey_id)
199              WHERE pubkey.pubkey_hash = ?
200                AND cc.chain_id = ?
201                AND cc.in_longest = 1
202              LIMIT ? """, (dbhash, self.chain_id, self.sql_limit))
203
204         if len(out)==self.sql_limit: 
205             raise BaseException('limit reached')
206         return out
207
208     def get_address_out_rows_memorypool(self, dbhash):
209         out = self.safe_sql(""" SELECT
210                 1,
211                 tx.tx_hash,
212                 tx.tx_id,
213                 txin.txin_pos,
214                 -prevout.txout_value
215               FROM tx 
216               JOIN txin ON (txin.tx_id = tx.tx_id)
217               JOIN txout prevout ON (txin.txout_id = prevout.txout_id)
218               JOIN pubkey ON (pubkey.pubkey_id = prevout.pubkey_id)
219              WHERE pubkey.pubkey_hash = ?
220              LIMIT ? """, (dbhash,self.sql_limit))
221
222         if len(out)==self.sql_limit: 
223             raise BaseException('limit reached')
224         return out
225
226     def get_address_in_rows(self, dbhash):
227         out = self.safe_sql(""" SELECT
228                 b.block_nTime,
229                 cc.chain_id,
230                 b.block_height,
231                 0,
232                 b.block_hash,
233                 tx.tx_hash,
234                 tx.tx_id,
235                 txout.txout_pos,
236                 txout.txout_value
237               FROM chain_candidate cc
238               JOIN block b ON (b.block_id = cc.block_id)
239               JOIN block_tx ON (block_tx.block_id = b.block_id)
240               JOIN tx ON (tx.tx_id = block_tx.tx_id)
241               JOIN txout ON (txout.tx_id = tx.tx_id)
242               JOIN pubkey ON (pubkey.pubkey_id = txout.pubkey_id)
243              WHERE pubkey.pubkey_hash = ?
244                AND cc.chain_id = ?
245                AND cc.in_longest = 1
246                LIMIT ? """, (dbhash, self.chain_id, self.sql_limit))
247
248         if len(out)==self.sql_limit: 
249             raise BaseException('limit reached')
250         return out
251
252     def get_address_in_rows_memorypool(self, dbhash):
253         out = self.safe_sql( """ SELECT
254                 0,
255                 tx.tx_hash,
256                 tx.tx_id,
257                 txout.txout_pos,
258                 txout.txout_value
259               FROM tx
260               JOIN txout ON (txout.tx_id = tx.tx_id)
261               JOIN pubkey ON (pubkey.pubkey_id = txout.pubkey_id)
262              WHERE pubkey.pubkey_hash = ?
263              LIMIT ? """, (dbhash,self.sql_limit))
264
265         if len(out)==self.sql_limit: 
266             raise BaseException('limit reached')
267         return out
268
269     def get_history(self, addr):
270
271         cached_version = self.tx_cache.get( addr )
272         if cached_version is not None:
273             return cached_version
274
275         version, binaddr = decode_check_address(addr)
276         if binaddr is None:
277             return None
278
279         dbhash = self.binin(binaddr)
280         rows = []
281         rows += self.get_address_out_rows( dbhash )
282         rows += self.get_address_in_rows( dbhash )
283
284         txpoints = []
285         known_tx = []
286
287         for row in rows:
288             try:
289                 nTime, chain_id, height, is_in, blk_hash, tx_hash, tx_id, pos, value = row
290             except:
291                 print "cannot unpack row", row
292                 break
293             tx_hash = self.hashout_hex(tx_hash)
294             txpoint = {
295                     "timestamp":    int(nTime),
296                     "height":   int(height),
297                     "is_input":    int(is_in),
298                     "block_hash": self.hashout_hex(blk_hash),
299                     "tx_hash":  tx_hash,
300                     "tx_id":    int(tx_id),
301                     "index":      int(pos),
302                     "value":    int(value),
303                     }
304
305             txpoints.append(txpoint)
306             known_tx.append(self.hashout_hex(tx_hash))
307
308
309         # todo: sort them really...
310         txpoints = sorted(txpoints, key=operator.itemgetter("timestamp"))
311
312         # read memory pool
313         rows = []
314         rows += self.get_address_in_rows_memorypool( dbhash )
315         rows += self.get_address_out_rows_memorypool( dbhash )
316         address_has_mempool = False
317
318         for row in rows:
319             is_in, tx_hash, tx_id, pos, value = row
320             tx_hash = self.hashout_hex(tx_hash)
321             if tx_hash in known_tx:
322                 continue
323
324             # discard transactions that are too old
325             if self.last_tx_id - tx_id > 50000:
326                 print "discarding tx id", tx_id
327                 continue
328
329             # this means that pending transactions were added to the db, even if they are not returned by getmemorypool
330             address_has_mempool = True
331
332             #print "mempool", tx_hash
333             txpoint = {
334                     "timestamp":    0,
335                     "height":   0,
336                     "is_input":    int(is_in),
337                     "block_hash": 'mempool', 
338                     "tx_hash":  tx_hash,
339                     "tx_id":    int(tx_id),
340                     "index":      int(pos),
341                     "value":    int(value),
342                     }
343             txpoints.append(txpoint)
344
345
346         for txpoint in txpoints:
347             tx_id = txpoint['tx_id']
348             
349             txinputs = []
350             inrows = self.get_tx_inputs(tx_id)
351             for row in inrows:
352                 _hash = self.binout(row[6])
353                 if not _hash:
354                     #print "WARNING: missing tx_in for tx", tx_id, addr
355                     continue
356                 address = hash_to_address(chr(self.addrtype), _hash)
357                 txinputs.append(address)
358             txpoint['inputs'] = txinputs
359             txoutputs = []
360             outrows = self.get_tx_outputs(tx_id)
361             for row in outrows:
362                 _hash = self.binout(row[6])
363                 if not _hash:
364                     #print "WARNING: missing tx_out for tx", tx_id, addr
365                     continue
366                 address = hash_to_address(chr(self.addrtype), _hash)
367                 txoutputs.append(address)
368             txpoint['outputs'] = txoutputs
369
370             # for all unspent inputs, I want their scriptpubkey. (actually I could deduce it from the address)
371             if not txpoint['is_input']:
372                 # detect if already redeemed...
373                 for row in outrows:
374                     if row[6] == dbhash: break
375                 else:
376                     raise
377                 #row = self.get_tx_output(tx_id,dbhash)
378                 # pos, script, value, o_hash, o_id, o_pos, binaddr = row
379                 # if not redeemed, we add the script
380                 if row:
381                     if not row[4]: txpoint['raw_output_script'] = row[1]
382
383             txpoint.pop('tx_id')
384
385         # cache result
386         # do not cache mempool results because statuses are ambiguous
387         if not address_has_mempool:
388             self.tx_cache[addr] = txpoints
389         
390         return txpoints
391
392
393     def get_status(self,addr):
394         # get address status, i.e. the last block for that address.
395         tx_points = self.get_history(addr)
396         if not tx_points:
397             status = None
398         else:
399             lastpoint = tx_points[-1]
400             status = lastpoint['block_hash']
401             # this is a temporary hack; move it up once old clients have disappeared
402             if status == 'mempool': # and session['version'] != "old":
403                 status = status + ':%d'% len(tx_points)
404         return status
405
406
407     def get_block_header(self, block_height):
408         out = self.safe_sql("""
409             SELECT
410                 block_hash,
411                 block_version,
412                 block_hashMerkleRoot,
413                 block_nTime,
414                 block_nBits,
415                 block_nNonce,
416                 block_height,
417                 prev_block_hash,
418                 block_id
419               FROM chain_summary
420              WHERE block_height = %d AND in_longest = 1"""%block_height)
421
422         if not out: raise BaseException("block not found")
423         row = out[0]
424         (block_hash, block_version, hashMerkleRoot, nTime, nBits, nNonce, height,prev_block_hash, block_id) \
425             = ( self.hashout_hex(row[0]), int(row[1]), self.hashout_hex(row[2]), int(row[3]), int(row[4]), int(row[5]), int(row[6]), self.hashout_hex(row[7]), int(row[8]) )
426
427         out = {"block_height":block_height, "version":block_version, "prev_block_hash":prev_block_hash, 
428                 "merkle_root":hashMerkleRoot, "timestamp":nTime, "bits":nBits, "nonce":nNonce}
429         return out
430         
431
432     def get_chunk(self, index):
433         sql = """
434             SELECT
435                 block_hash,
436                 block_version,
437                 block_hashMerkleRoot,
438                 block_nTime,
439                 block_nBits,
440                 block_nNonce,
441                 block_height,
442                 prev_block_hash,
443                 block_height
444               FROM chain_summary
445              WHERE block_height >= %d AND block_height< %d AND in_longest = 1"""%(index*2016, (index+1)*2016)
446
447         out = self.safe_sql(sql)
448         msg = ''
449         for row in out:
450             (block_hash, block_version, hashMerkleRoot, nTime, nBits, nNonce, height, prev_block_hash, block_height) \
451                 = ( self.hashout_hex(row[0]), int(row[1]), self.hashout_hex(row[2]), int(row[3]), int(row[4]), int(row[5]), int(row[6]), self.hashout_hex(row[7]), int(row[8]) )
452             h = {"block_height":block_height, "version":block_version, "prev_block_hash":prev_block_hash, 
453                    "merkle_root":hashMerkleRoot, "timestamp":nTime, "bits":nBits, "nonce":nNonce}
454
455             if h.get('block_height')==0: h['prev_block_hash'] = "0"*64
456             msg += header_to_string(h)
457
458             #print "hash", encode(Hash(msg.decode('hex')))
459             #if h.get('block_height')==1:break
460
461         print "get_chunk", index, len(msg)
462         return msg
463
464
465
466     def get_tx_merkle(self, tx_hash):
467
468         out = self.safe_sql("""
469              SELECT block_tx.block_id FROM tx 
470              JOIN block_tx on tx.tx_id = block_tx.tx_id 
471              JOIN chain_summary on chain_summary.block_id = block_tx.block_id
472              WHERE tx_hash='%s' AND in_longest = 1"""%tx_hash)
473         block_id = out[0]
474
475         # get block height
476         out = self.safe_sql("SELECT block_height FROM chain_summary WHERE block_id = %d AND in_longest = 1"%block_id)
477
478         if not out: raise BaseException("block not found")
479         block_height = int(out[0][0])
480
481         merkle = []
482         # list all tx in block
483         for row in self.safe_sql("""
484             SELECT DISTINCT tx_id, tx_pos, tx_hash
485               FROM txin_detail
486              WHERE block_id = ?
487              ORDER BY tx_pos""", (block_id,)):
488             tx_id, tx_pos, tx_h = row
489             merkle.append(tx_h)
490
491         # find subset.
492         # TODO: do not compute this on client request, better store the hash tree of each block in a database...
493
494         merkle = map(decode, merkle)
495         target_hash = decode(tx_hash)
496
497         s = []
498         while len(merkle) != 1:
499             if len(merkle)%2: merkle.append( merkle[-1] )
500             n = []
501             while merkle:
502                 new_hash = Hash( merkle[0] + merkle[1] )
503                 if merkle[0] == target_hash:
504                     s.append( "L" + encode(merkle[1]))
505                     target_hash = new_hash
506                 elif merkle[1] == target_hash:
507                     s.append( "R" + encode(merkle[0]))
508                     target_hash = new_hash
509                 n.append( new_hash )
510                 merkle = merkle[2:]
511             merkle = n
512
513         # send result
514         return {"block_height":block_height,"merkle":s}
515
516
517
518
519     def memorypool_update(store):
520
521         ds = BCDataStream.BCDataStream()
522         postdata = dumps({"method": 'getrawmempool', 'params': [], 'id':'jsonrpc'})
523         respdata = urllib.urlopen(store.bitcoind_url, postdata).read()
524         r = loads(respdata)
525         if r['error'] != None:
526             print r['error']
527             return
528
529         mempool_hashes = r.get('result')
530         for tx_hash in mempool_hashes:
531
532             if tx_hash in store.known_mempool_hashes: continue
533             store.known_mempool_hashes.append(tx_hash)
534
535             postdata = dumps({"method": 'getrawtransaction', 'params': [tx_hash], 'id':'jsonrpc'})
536             respdata = urllib.urlopen(store.bitcoind_url, postdata).read()
537             r = loads(respdata)
538             if r['error'] != None:
539                 continue
540             hextx = r.get('result')
541             ds.clear()
542             ds.write(hextx.decode('hex'))
543             tx = deserialize.parse_Transaction(ds)
544             tx['hash'] = util.double_sha256(tx['tx'])
545                 
546             if store.tx_find_id_and_value(tx):
547                 pass
548             else:
549                 tx_id = store.import_tx(tx, False)
550                 store.update_tx_cache(tx_id)
551                 #print tx_hash
552
553         store.commit()
554         store.known_mempool_hashes = mempool_hashes
555
556
557     def send_tx(self,tx):
558         postdata = dumps({"method": 'sendrawtransaction', 'params': [tx], 'id':'jsonrpc'})
559         respdata = urllib.urlopen(self.bitcoind_url, postdata).read()
560         r = loads(respdata)
561         if r['error'] != None:
562             msg = r['error'].get('message')
563             out = "error: transaction rejected by memorypool: " + msg + "\n" + tx
564         else:
565             out = r['result']
566         return out
567
568
569     def main_iteration(store):
570         with store.dblock:
571             store.catch_up()
572             store.memorypool_update()
573             height = store.get_block_number( store.chain_id )
574
575         block_header = store.get_block_header( height )
576         return block_header
577
578
579
580
581     def catch_up(store):
582         # if there is an exception, do rollback and then re-raise the exception
583         for dircfg in store.datadirs:
584             try:
585                 store.catch_up_dir(dircfg)
586             except Exception, e:
587                 store.log.exception("Failed to catch up %s", dircfg)
588                 store.rollback()
589                 raise e
590
591
592
593
594 from processor import Processor
595
596 class BlockchainProcessor(Processor):
597
598     def __init__(self, config):
599         Processor.__init__(self)
600         self.store = AbeStore(config)
601         self.watched_addresses = []
602
603         # catch_up first
604         self.block_header = self.store.main_iteration()
605         self.block_number = self.block_header.get('block_height')
606         print "blockchain: %d blocks"%self.block_number
607
608         threading.Timer(10, self.run_store_iteration).start()
609
610     def process(self, request):
611         #print "abe process", request
612
613         message_id = request['id']
614         method = request['method']
615         params = request.get('params',[])
616         result = None
617         error = None
618
619         if method == 'blockchain.numblocks.subscribe':
620             result = self.block_number
621
622         elif method == 'blockchain.headers.subscribe':
623             result = self.block_header
624
625         elif method == 'blockchain.address.subscribe':
626             try:
627                 address = params[0]
628                 result = self.store.get_status(address)
629                 self.watch_address(address)
630             except BaseException, e:
631                 error = str(e) + ': ' + address
632                 print "error:", error
633
634         elif method == 'blockchain.address.get_history':
635             try:
636                 address = params[0]
637                 result = self.store.get_history( address ) 
638             except BaseException, e:
639                 error = str(e) + ': ' + address
640                 print "error:", error
641
642         elif method == 'blockchain.block.get_header':
643             try:
644                 height = params[0]
645                 result = self.store.get_block_header( height ) 
646             except BaseException, e:
647                 error = str(e) + ': %d'% height
648                 print "error:", error
649
650         elif method == 'blockchain.block.get_chunk':
651             try:
652                 index = params[0]
653                 result = self.store.get_chunk( index ) 
654             except BaseException, e:
655                 error = str(e) + ': %d'% index
656                 print "error:", error
657
658         elif method == 'blockchain.transaction.broadcast':
659             txo = self.store.send_tx(params[0])
660             print "sent tx:", txo
661             result = txo 
662
663         elif method == 'blockchain.transaction.get_merkle':
664             try:
665                 tx_hash = params[0]
666                 result = self.store.get_tx_merkle(tx_hash ) 
667             except BaseException, e:
668                 error = str(e) + ': ' + tx_hash
669                 print "error:", error
670
671         else:
672             error = "unknown method:%s"%method
673
674
675         if error:
676             response = { 'id':message_id, 'error':error }
677             self.push_response(response)
678         elif result != '':
679             response = { 'id':message_id, 'result':result }
680             self.push_response(response)
681
682
683     def watch_address(self, addr):
684         if addr not in self.watched_addresses:
685             self.watched_addresses.append(addr)
686
687
688     def run_store_iteration(self):
689         
690         try:
691             block_header = self.store.main_iteration()
692         except:
693             traceback.print_exc(file=sys.stdout)
694             print "terminating"
695             self.shared.stop()
696
697         if self.shared.stopped(): 
698             print "exit timer"
699             return
700
701         if self.block_number != block_header.get('block_height'):
702             self.block_number = block_header.get('block_height')
703             print "block number:", self.block_number
704             self.push_response({ 'id': None, 'method':'blockchain.numblocks.subscribe', 'params':[self.block_number] })
705
706         if self.block_header != block_header:
707             self.block_header = block_header
708             self.push_response({ 'id': None, 'method':'blockchain.headers.subscribe', 'params':[self.block_header] })
709
710         while True:
711             try:
712                 addr = self.store.address_queue.get(False)
713             except:
714                 break
715             if addr in self.watched_addresses:
716                 status = self.store.get_status( addr )
717                 self.push_response({ 'id': None, 'method':'blockchain.address.subscribe', 'params':[addr, status] })
718
719         threading.Timer(10, self.run_store_iteration).start()
720
721