Merge branch 'lbcpatience' into development

This commit is contained in:
Jimmy Kiselak 2016-03-19 22:33:56 -04:00
commit 06a1bdbcba
5 changed files with 53 additions and 6 deletions

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
@ -70,6 +74,7 @@ class LBRYWallet(object):
self._manage_count = 0
self._balance_refresh_time = 3
self._batch_count = 20
self._first_run = self._FIRST_RUN_UNKNOWN
def start(self):
@ -419,6 +424,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)
@ -534,7 +552,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):
@ -614,7 +632,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)
@ -996,7 +1014,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
@ -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

@ -253,7 +253,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

@ -460,7 +460,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
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