re-enable lbryum

This commit is contained in:
Jack 2016-07-09 13:31:07 -04:00
parent b727bd20c8
commit 1b53e8e98c
3 changed files with 62 additions and 62 deletions

View file

@ -38,7 +38,7 @@ API_CONNECTION_STRING = "http://%s:%i/%s" % (API_INTERFACE, API_PORT, API_ADDRES
UI_ADDRESS = "http://%s:%i" % (API_INTERFACE, API_PORT) UI_ADDRESS = "http://%s:%i" % (API_INTERFACE, API_PORT)
PROTOCOL_PREFIX = "lbry" PROTOCOL_PREFIX = "lbry"
DEFAULT_WALLET = "lbrycrd" DEFAULT_WALLET = "lbryum"
WALLET_TYPES = ["lbryum", "lbrycrd"] WALLET_TYPES = ["lbryum", "lbrycrd"]
DEFAULT_TIMEOUT = 30 DEFAULT_TIMEOUT = 30
DEFAULT_MAX_SEARCH_RESULTS = 25 DEFAULT_MAX_SEARCH_RESULTS = 25

View file

@ -145,7 +145,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
isLeaf = True isLeaf = True
def __init__(self, root, wallet_type="lbrycrd"): def __init__(self, root, wallet_type=None):
jsonrpc.JSONRPC.__init__(self) jsonrpc.JSONRPC.__init__(self)
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown) reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
@ -877,13 +877,13 @@ class LBRYDaemon(jsonrpc.JSONRPC):
return d return d
def get_wallet(): def get_wallet():
if self.wallet_type in ["lbrycrd", "lbryum"]: #force lbrycrd wallet no matter what while lbryum is down if self.wallet_type == "lbrycrd": #force lbrycrd wallet no matter what while lbryum is down
log.info("Using lbrycrd wallet") log.info("Using lbrycrd wallet")
d = defer.succeed(LBRYcrdWallet(self.db_dir, wallet_dir=self.wallet_dir, wallet_conf=self.lbrycrd_conf, d = defer.succeed(LBRYcrdWallet(self.db_dir, wallet_dir=self.wallet_dir, wallet_conf=self.lbrycrd_conf,
lbrycrdd_path=self.lbrycrdd_path)) lbrycrdd_path=self.lbrycrdd_path))
# elif self.wallet_type == "lbryum": elif self.wallet_type == "lbryum":
# log.info("Using lbryum wallet") log.info("Using lbryum wallet")
# d = defer.succeed(LBRYumWallet(self.db_dir)) d = defer.succeed(LBRYumWallet(self.db_dir))
elif self.wallet_type == "ptc": elif self.wallet_type == "ptc":
log.info("Using PTC wallet") log.info("Using PTC wallet")
d = defer.succeed(PTCWallet(self.db_dir)) d = defer.succeed(PTCWallet(self.db_dir))
@ -918,61 +918,61 @@ class LBRYDaemon(jsonrpc.JSONRPC):
return dl return dl
def _check_first_run(self): # def _check_first_run(self):
def _set_first_run_false(): # def _set_first_run_false():
log.info("Not first run") # log.info("Not first run")
self.first_run = False # self.first_run = False
self.session_settings['requested_first_run_credits'] = True # self.session_settings['requested_first_run_credits'] = True
f = open(self.daemon_conf, "w") # f = open(self.daemon_conf, "w")
f.write(json.dumps(self.session_settings)) # f.write(json.dumps(self.session_settings))
f.close() # f.close()
return 0.0 # return 0.0
#
if self.wallet_type == 'lbryum': # if self.wallet_type == 'lbryum':
d = self.session.wallet.is_first_run() # d = self.session.wallet.is_first_run()
d.addCallback(lambda is_first_run: self._do_first_run() if is_first_run or not self.requested_first_run_credits # d.addCallback(lambda is_first_run: self._do_first_run() if is_first_run or not self.requested_first_run_credits
else _set_first_run_false()) # else _set_first_run_false())
else: # else:
d = defer.succeed(None) # d = defer.succeed(None)
d.addCallback(lambda _: _set_first_run_false()) # d.addCallback(lambda _: _set_first_run_false())
return d # return d
#
def _do_first_run(self): # def _do_first_run(self):
def send_request(url, data): # def send_request(url, data):
log.info("Requesting first run credits") # log.info("Requesting first run credits")
r = requests.post(url, json=data) # r = requests.post(url, json=data)
if r.status_code == 200: # if r.status_code == 200:
self.requested_first_run_credits = True # self.requested_first_run_credits = True
self.session_settings['requested_first_run_credits'] = True # self.session_settings['requested_first_run_credits'] = True
f = open(self.daemon_conf, "w") # f = open(self.daemon_conf, "w")
f.write(json.dumps(self.session_settings)) # f.write(json.dumps(self.session_settings))
f.close() # f.close()
return r.json()['credits_sent'] # return r.json()['credits_sent']
return 0.0 # return 0.0
#
def log_error(err): # def log_error(err):
log.warning("unable to request free credits. %s", err.getErrorMessage()) # log.warning("unable to request free credits. %s", err.getErrorMessage())
return 0.0 # return 0.0
#
def request_credits(address): # def request_credits(address):
url = "http://credreq.lbry.io/requestcredits" # url = "http://credreq.lbry.io/requestcredits"
data = {"address": address} # data = {"address": address}
d = threads.deferToThread(send_request, url, data) # d = threads.deferToThread(send_request, url, data)
d.addErrback(log_error) # d.addErrback(log_error)
return d # return d
#
self.first_run = True # self.first_run = True
d = self.session.wallet.get_new_address() # d = self.session.wallet.get_new_address()
d.addCallback(request_credits) # d.addCallback(request_credits)
#
return d # return d
#
def _show_first_run_result(self, credits_received): # def _show_first_run_result(self, credits_received):
if credits_received != 0.0: # if credits_received != 0.0:
points_string = locale.format_string("%.2f LBC", (round(credits_received, 2),), grouping=True) # points_string = locale.format_string("%.2f LBC", (round(credits_received, 2),), grouping=True)
self.startup_message = "Thank you for testing the alpha version of LBRY! You have been given %s for free because we love you. Please hang on for a few minutes for the next block to be mined. When you refresh this page and see your credits you're ready to go!." % points_string # self.startup_message = "Thank you for testing the alpha version of LBRY! You have been given %s for free because we love you. Please hang on for a few minutes for the next block to be mined. When you refresh this page and see your credits you're ready to go!." % points_string
else: # else:
self.startup_message = None # self.startup_message = None
def _setup_stream_identifier(self): def _setup_stream_identifier(self):
file_saver_factory = LBRYFileSaverFactory(self.session.peer_finder, self.session.rate_limiter, file_saver_factory = LBRYFileSaverFactory(self.session.peer_finder, self.session.rate_limiter,

View file

@ -183,7 +183,7 @@ class HostedLBRYFile(resource.Resource):
class LBRYDaemonServer(object): class LBRYDaemonServer(object):
def _setup_server(self, wallet): def _setup_server(self, wallet):
self.root = LBRYindex(os.path.join(os.path.join(data_dir, "lbry-ui"), "active")) self.root = LBRYindex(os.path.join(os.path.join(data_dir, "lbry-ui"), "active"))
self._api = LBRYDaemon(self.root, wallet_type="lbrycrd") self._api = LBRYDaemon(self.root, wallet_type=wallet)
self.root.putChild("view", HostedLBRYFile(self._api)) self.root.putChild("view", HostedLBRYFile(self._api))
self.root.putChild(API_ADDRESS, self._api) self.root.putChild(API_ADDRESS, self._api)
return defer.succeed(True) return defer.succeed(True)