Merge pull request #67 from lbryio/real-lbryum

Real lbryum
This commit is contained in:
Jack Robison 2016-07-12 15:35:54 -04:00 committed by GitHub
commit ed0f9d4fb5
6 changed files with 67 additions and 67 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

@ -7,7 +7,7 @@ from lbrynet.core.sqlite_helpers import rerun_if_locked
from lbrynet.conf import BASE_METADATA_FIELDS, SOURCE_TYPES, OPTIONAL_METADATA_FIELDS from lbrynet.conf import BASE_METADATA_FIELDS, SOURCE_TYPES, OPTIONAL_METADATA_FIELDS
from lbryum import SimpleConfig, Network from lbryum import SimpleConfig, Network
from lbryum.bitcoin import COIN, TYPE_ADDRESS from lbryum.lbrycrd import COIN, TYPE_ADDRESS
from lbryum.wallet import WalletStorage, Wallet from lbryum.wallet import WalletStorage, Wallet
from lbryum.commands import known_commands, Commands from lbryum.commands import known_commands, Commands
from lbryum.transaction import Transaction from lbryum.transaction import Transaction

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

@ -35,7 +35,7 @@ def main():
if len(args) > 1: if len(args) > 1:
if isinstance(args[1], dict): if isinstance(args[1], dict):
params = args[1] params = args[1]
elif isinstance(args[1], str) or isinstance(args[1], unicode): elif isinstance(args[1], str, unicode):
params = json.loads(args[1]) params = json.loads(args[1])
else: else:
params = None params = None

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)

View file

@ -127,11 +127,11 @@ class Publisher(object):
log.info(err.getTraceback()) log.info(err.getTraceback())
message = "An error occurred publishing %s to %s. Error: %s." message = "An error occurred publishing %s to %s. Error: %s."
if err.check(InsufficientFundsError): if err.check(InsufficientFundsError):
d = defer.succeed(True)
error_message = "Insufficient funds" error_message = "Insufficient funds"
else: else:
d = defer.succeed(True)
error_message = err.getErrorMessage() error_message = err.getErrorMessage()
log.error(error_message) log.error(error_message)
log.error(message, str(self.file_name), str(self.publish_name), err.getTraceback()) log.error(message, str(self.file_name), str(self.publish_name), err.getTraceback())
return d
return defer.succeed(error_message)