lbry-sdk/lbrynet/lbrynet_daemon/daemon_scripts/migrateto025.py

38 lines
1.1 KiB
Python
Raw Normal View History

2016-05-30 21:49:25 +02:00
from twisted.internet import defer
class migrator(object):
"""
Re-resolve lbry names to write missing data to blockchain.db and to cache the nametrie
"""
def __init__(self, api):
self._api = api
def start(self):
def _resolve_claims(claimtrie):
claims = [i for i in claimtrie if 'txid' in i.keys()]
2016-11-30 21:20:45 +01:00
r = defer.DeferredList(
[self._api._resolve_name(claim['name'], force_refresh=True) for claim in claims],
consumeErrors=True)
2016-05-30 21:49:25 +02:00
return r
def _restart_lbry_files():
def _restart_lbry_file(lbry_file):
return lbry_file.restore()
2016-11-30 21:20:45 +01:00
lbry_files = self._api.lbry_file_manager.lbry_files
r = defer.DeferredList(
[_restart_lbry_file(lbry_file) for lbry_file in lbry_files if not lbry_file.txid],
consumeErrors=True)
2016-05-30 21:49:25 +02:00
return r
d = self._api.session.wallet.get_nametrie()
d.addCallback(_resolve_claims)
d.addCallback(lambda _: _restart_lbry_files())
def run(api):
refresher = migrator(api)
refresher.start()