Merge branch 'development' into jsonrpc

# Conflicts:
#	setup.py
This commit is contained in:
Jack 2016-03-23 22:34:27 -04:00
commit 71c4dba34d
8 changed files with 147 additions and 41 deletions

2
MANIFEST.in Normal file
View file

@ -0,0 +1,2 @@
include lbrynet/lbrynet_console/plugins/blindrepeater.yapsy-plugin
recursive-include lbrynet/lbrynet_gui *.gif *.ico *.xbm *.conf

View file

@ -1,4 +1,8 @@
import logging
logging.getLogger(__name__).addHandler(logging.NullHandler())
logging.getLogger(__name__).addHandler(logging.NullHandler())
version = (0, 2, 0)
__version__ = ".".join([str(x) for x in version])

View file

@ -50,6 +50,10 @@ class LBRYWallet(object):
"""This class implements the LBRYWallet interface for the LBRYcrd payment system"""
implements(ILBRYWallet)
_FIRST_RUN_UNKNOWN = 0
_FIRST_RUN_YES = 1
_FIRST_RUN_NO = 2
def __init__(self, db_dir):
self.db_dir = db_dir
@ -67,6 +71,10 @@ class LBRYWallet(object):
self.stopped = True
self.manage_running = False
self._manage_count = 0
self._balance_refresh_time = 3
self._batch_count = 20
self._first_run = self._FIRST_RUN_UNKNOWN
def start(self):
@ -93,16 +101,19 @@ class LBRYWallet(object):
self.next_manage_call.cancel()
self.next_manage_call = None
d = self.manage()
d = self.manage(do_full=True)
d.addErrback(self.log_stop_error)
d.addCallback(lambda _: self._stop())
d.addErrback(self.log_stop_error)
return d
def manage(self):
log.info("Doing manage")
def manage(self, do_full=False):
self.next_manage_call = None
have_set_manage_running = [False]
self._manage_count += 1
if self._manage_count % self._batch_count == 0:
self._manage_count = 0
do_full = True
def check_if_manage_running():
@ -113,6 +124,8 @@ class LBRYWallet(object):
self.manage_running = True
have_set_manage_running[0] = True
d.callback(True)
elif do_full is False:
d.callback(False)
else:
task.deferLater(reactor, 1, fire_if_not_running)
@ -121,20 +134,28 @@ class LBRYWallet(object):
d = check_if_manage_running()
d.addCallback(lambda _: self._check_expected_balances())
def do_manage():
if do_full:
d = self._check_expected_balances()
d.addCallback(lambda _: self._send_payments())
else:
d = defer.succeed(True)
d.addCallback(lambda _: self._send_payments())
d.addCallback(lambda _: self.get_balance())
d.addCallback(lambda _: self.get_balance())
def set_wallet_balance(balance):
if self.wallet_balance != balance:
log.info("Got a new balance: %s", str(balance))
self.wallet_balance = balance
def set_wallet_balance(balance):
self.wallet_balance = balance
d.addCallback(set_wallet_balance)
return d
d.addCallback(set_wallet_balance)
d.addCallback(lambda should_run: do_manage() if should_run else None)
def set_next_manage_call():
if not self.stopped:
self.next_manage_call = reactor.callLater(60, self.manage)
self.next_manage_call = reactor.callLater(self._balance_refresh_time, self.manage)
d.addCallback(lambda _: set_next_manage_call())
@ -252,8 +273,6 @@ class LBRYWallet(object):
return d
def _send_payments(self):
log.info("Trying to send payments, if there are any to be sent")
payments_to_send = {}
for address, points in self.queued_payments.items():
log.info("Should be sending %s points to %s", str(points), str(address))
@ -408,6 +427,19 @@ class LBRYWallet(object):
def get_available_balance(self):
return float(self.wallet_balance - self.total_reserved_points)
def is_first_run(self):
if self._first_run == self._FIRST_RUN_UNKNOWN:
d = self._check_first_run()
def set_first_run(is_first):
self._first_run = self._FIRST_RUN_YES if is_first else self._FIRST_RUN_NO
d.addCallback(set_first_run)
else:
d = defer.succeed(None)
d.addCallback(lambda _: self._first_run == self._FIRST_RUN_YES)
return d
def _get_status_of_claim(self, txid, name, sd_hash):
d = self.get_claims_from_tx(txid)
@ -523,7 +555,7 @@ class LBRYWallet(object):
def get_name_claims(self):
return defer.fail(NotImplementedError())
def check_first_run(self):
def _check_first_run(self):
return defer.fail(NotImplementedError())
def _get_raw_tx(self, txid):
@ -603,7 +635,7 @@ class LBRYcrdWallet(LBRYWallet):
settings["rpc_port"] = int(l[8:].rstrip('\n'))
return settings
def check_first_run(self):
def _check_first_run(self):
d = self.get_balance()
d.addCallback(lambda bal: threads.deferToThread(self._get_num_addresses_rpc) if bal == 0 else 2)
d.addCallback(lambda num_addresses: True if num_addresses <= 1 else False)
@ -865,6 +897,9 @@ class LBRYumWallet(LBRYWallet):
self.cmd_runner = None
self.first_run = False
self.printed_retrieving_headers = False
self._start_check = None
self._catch_up_check = None
self._caught_up_counter = 0
def _start(self):
@ -884,21 +919,30 @@ class LBRYumWallet(LBRYWallet):
alert.info("Running the wallet for the first time...this may take a moment.")
self.printed_retrieving_headers = True
return False
start_check.stop()
self._start_check.stop()
self._start_check = None
if self.network.is_connected():
network_start_d.callback(True)
else:
network_start_d.errback(ValueError("Failed to connect to network."))
start_check = task.LoopingCall(check_started)
self._start_check = task.LoopingCall(check_started)
d.addCallback(lambda _: start_check.start(.1))
d.addCallback(lambda _: self._start_check.start(.1))
d.addCallback(lambda _: network_start_d)
d.addCallback(lambda _: self._load_wallet())
d.addCallback(lambda _: self._get_cmd_runner())
return d
def _stop(self):
if self._start_check is not None:
self._start_check.stop()
self._start_check = None
if self._catch_up_check is not None:
self._catch_up_check.stop()
self._catch_up_check = None
d = defer.Deferred()
def check_stopped():
@ -938,16 +982,28 @@ class LBRYumWallet(LBRYWallet):
remote_height = self.network.get_server_height()
if remote_height != 0 and remote_height - local_height <= 5:
alert.info('Wallet loaded.')
catch_up_check.stop()
msg = ""
if self._caught_up_counter != 0:
msg += "All caught up. "
msg += "Wallet loaded."
alert.info(msg)
self._catch_up_check.stop()
self._catch_up_check = None
blockchain_caught_d.callback(True)
elif remote_height != 0:
if self._caught_up_counter == 0:
alert.info('Catching up to the blockchain...showing blocks left...')
if self._caught_up_counter % 30 == 0:
alert.info('%d...', (remote_height - local_height))
self._caught_up_counter += 1
catch_up_check = task.LoopingCall(check_caught_up)
self._catch_up_check = task.LoopingCall(check_caught_up)
d = threads.deferToThread(get_wallet)
d.addCallback(self._save_wallet)
d.addCallback(lambda _: self.wallet.start_threads(self.network))
d.addCallback(lambda _: catch_up_check.start(.1))
d.addCallback(lambda _: self._catch_up_check.start(.1))
d.addCallback(lambda _: blockchain_caught_d)
return d
@ -987,7 +1043,7 @@ class LBRYumWallet(LBRYWallet):
func = getattr(self.cmd_runner, cmd.name)
return threads.deferToThread(func)
def check_first_run(self):
def _check_first_run(self):
return defer.succeed(self.first_run)
def _get_raw_tx(self, txid):

View file

@ -783,6 +783,9 @@ class AddStream(CommandHandler):
d.addCallback(get_time_behind_blockchain)
d.addCallback(self._show_time_behind_blockchain_download)
d.addErrback(self._log_recent_blockchain_time_error_download)
d.addCallback(lambda _: self.wallet.is_first_run())
d.addCallback(self._show_first_run_insufficient_funds)
d.addErrback(self._log_first_run_check_error)
else:
log.error("An unexpected error has caused the download to stop: %s" % err.getTraceback())
log_file = get_log_file()
@ -803,6 +806,16 @@ class AddStream(CommandHandler):
def _log_recent_blockchain_time_error_download(self, err):
log.error("An error occurred trying to look up the most recent blocktime: %s", err.getTraceback())
def _show_first_run_insufficient_funds(self, is_first_run):
if is_first_run:
self.console.sendLine("\nThis appears to be the first time you have run LBRY. It can take\n"
"a few minutes for your testing LBC to show up. If you haven't\n"
"received them after a few minutes, please let us know.\n\n"
"Thank you for your patience.\n\n")
def _log_first_run_check_error(self, err):
log.error("An error occurred checking if this was the first run: %s", err.getTraceback())
class AddStreamFromSD(AddStream):
#prompt_description = "Add a stream from a stream descriptor file"
@ -849,6 +862,9 @@ class AddStreamFromHash(AddStream):
d.addCallback(get_time_behind_blockchain)
d.addCallback(self._show_time_behind_blockchain_download)
d.addErrback(self._log_recent_blockchain_time_error_download)
d.addCallback(lambda _: self.wallet.is_first_run())
d.addCallback(self._show_first_run_insufficient_funds)
d.addErrback(self._log_first_run_check_error)
d.addCallback(lambda _: self.console.sendLine("\n"))
d.chainDeferred(self.finished_deferred)
return
@ -955,7 +971,7 @@ class AddStreamFromLBRYcrdName(AddStreamFromHash):
def _get_info_to_show(self):
i = AddStream._get_info_to_show(self)
if self.description is not None:
i.append(("description", self.description))
i.append(("description", str(self.description)))
if self.key_fee is None or self.key_fee_address is None:
i.append(("decryption key fee", "Free"))
else:
@ -1857,6 +1873,16 @@ class Publish(CommandHandler):
def _log_best_blocktime_error(self, err):
log.error("An error occurred checking the best time of the blockchain: %s", err.getTraceback())
def _show_first_run_insufficient_funds(self, is_first_run):
if is_first_run:
self.console.sendLine("\nThis appears to be the first time you have run LBRY. It can take\n"
"a few minutes for your testing LBC to show up. If you haven't\n"
"received them after a few minutes, please let us know.\n\n"
"Thank you for your patience.\n\n")
def _log_first_run_check_error(self, err):
log.error("An error occurred checking if this was the first run: %s", err.getTraceback())
def _show_publish_error(self, err):
message = "An error occurred publishing %s to %s. Error: %s."
if err.check(InsufficientFundsError):
@ -1864,6 +1890,9 @@ class Publish(CommandHandler):
d.addCallback(get_time_behind_blockchain)
d.addCallback(self._show_time_behind_blockchain)
d.addErrback(self._log_best_blocktime_error)
d.addCallback(lambda _: self.wallet.is_first_run())
d.addCallback(self._show_first_run_insufficient_funds)
d.addErrback(self._log_first_run_check_error)
error_message = "Insufficient funds"
else:
d = defer.succeed(True)

View file

@ -258,7 +258,7 @@ class LBRYConsole():
return dl
def check_first_run(self):
d = self.session.wallet.check_first_run()
d = self.session.wallet.is_first_run()
d.addCallback(lambda is_first_run: self._do_first_run() if is_first_run else 0.0)
return d

View file

@ -437,7 +437,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
return dl
def _check_first_run(self):
d = self.session.wallet.check_first_run()
d = self.session.wallet.is_first_run()
d.addCallback(lambda is_first_run: self._do_first_run() if is_first_run else 0.0)
return d

View file

@ -362,7 +362,7 @@ class LBRYDownloader(object):
self.sd_identifier.add_stream_downloader_factory(LBRYFileStreamType, file_opener_factory)
def check_first_run(self):
d = self.session.wallet.check_first_run()
d = self.session.wallet.is_first_run()
d.addCallback(lambda is_first_run: self._do_first_run() if is_first_run else 0.0)
return d

View file

@ -1,10 +1,17 @@
#!/usr/bin/env python
from lbrynet import __version__
import ez_setup
import sys
import os
from setuptools import setup, find_packages
<<<<<<< HEAD
=======
base_dir = os.path.abspath(os.path.dirname(__file__))
>>>>>>> development
ez_setup.use_setuptools()
console_scripts = ['lbrynet-console = lbrynet.lbrynet_console.LBRYConsole:launch_lbry_console',
@ -19,10 +26,20 @@ console_scripts = ['lbrynet-console = lbrynet.lbrynet_console.LBRYConsole:launch
'lbrynet-announce_hash_to_dht = lbrynet.dht_scripts:announce_hash_to_dht',
'lbrynet-daemon = lbrynet.lbrynet_daemon.LBRYDaemonControl:start',
'stop-lbrynet-daemon = lbrynet.lbrynet_daemon.LBRYDaemonControl:stop']
<<<<<<< HEAD
=======
requires = ['pycrypto', 'twisted', 'miniupnpc', 'yapsy', 'seccure',
'python-bitcoinrpc==0.1', 'txJSON-RPC', 'requests>=2.4.2', 'unqlite==0.2.0',
'leveldb', 'lbryum', 'jsonrpc', 'simplejson', 'appdirs']
>>>>>>> development
if sys.platform == 'darwin':
console_scripts.append('lbrynet-daemon-status = lbrynet.lbrynet_daemon.LBRYOSXStatusBar:main')
requires.append('six==1.9.0')
else:
requires.append('six>=1.9.0')
<<<<<<< HEAD
requires = ['pycrypto', 'twisted', 'miniupnpc', 'yapsy', 'seccure',
'python-bitcoinrpc==0.1', 'txJSON-RPC', 'requests>=2.4.2', 'unqlite==0.2.0',
'leveldb', 'lbryum', 'jsonrpc', 'simplejson', 'appdirs']
@ -35,26 +52,24 @@ else:
setup(name='lbrynet',
version='0.0.4',
packages=find_packages(),
=======
gui_data_files = ['close2.gif', 'lbry-dark-242x80.gif', 'lbry-dark-icon.xbm', 'lbry-dark-icon.ico',
'drop_down.gif', 'show_options.gif', 'hide_options.gif', 'lbry.conf']
gui_data_paths = [os.path.join(base_dir, 'lbrynet', 'lbrynet_gui', f) for f in gui_data_files]
setup(name='lbrynet', version='.'.join([str(x) for x in __version__]),
packages=find_packages(base_dir),
>>>>>>> development
install_requires=requires,
entry_points={'console_scripts': console_scripts},
data_files=[
('lbrynet/lbrynet_console/plugins',
[
'lbrynet/lbrynet_console/plugins/blindrepeater.yapsy-plugin',
os.path.join(base_dir, 'lbrynet', 'lbrynet_console', 'plugins',
'blindrepeater.yapsy-plugin')
]
),
('lbrynet/lbrynet_gui',
[
'lbrynet/lbrynet_gui/close2.gif',
'lbrynet/lbrynet_gui/lbry-dark-242x80.gif',
'lbrynet/lbrynet_gui/lbry-dark-icon.xbm',
'lbrynet/lbrynet_gui/lbry-dark-icon.ico',
'lbrynet/lbrynet_gui/drop_down.gif',
'lbrynet/lbrynet_gui/show_options.gif',
'lbrynet/lbrynet_gui/hide_options.gif',
'lbrynet/lbrynet_gui/lbry.conf',
]
)
('lbrynet/lbrynet_gui', gui_data_paths)
],
dependency_links=['https://github.com/lbryio/lbryum/tarball/master/#egg=lbryum'],
)