From 6b72b4de11613d9782ac43a34e085e1938d76cd6 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Thu, 10 Nov 2016 14:26:21 -0500 Subject: [PATCH] use constants for wallet types --- lbrynet/analytics/events.py | 4 ++-- lbrynet/conf.py | 7 +++++-- lbrynet/lbrynet_daemon/Daemon.py | 15 ++++++++------- lbrynet/lbrynet_daemon/DaemonControl.py | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lbrynet/analytics/events.py b/lbrynet/analytics/events.py index 3b2e879be..1c2dbfb34 100644 --- a/lbrynet/analytics/events.py +++ b/lbrynet/analytics/events.py @@ -1,7 +1,7 @@ import logging from lbrynet.core import utils - +from lbrynet.conf import LBRYUM_WALLET log = logging.getLogger(__name__) @@ -69,7 +69,7 @@ def make_context(platform, wallet, is_dev=False): 'wallet': { 'name': wallet, # TODO: add in version info for lbrycrdd - 'version': platform['lbryum_version'] if wallet == 'lbryum' else None + 'version': platform['lbryum_version'] if wallet == LBRYUM_WALLET else None }, }, # TODO: expand os info to give linux/osx specific info diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 2a12af014..abc60e5ed 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -7,6 +7,9 @@ import yaml from appdirs import user_data_dir +LBRYCRD_WALLET = 'lbrycrd' +LBRYUM_WALLET = 'lbryum' +PTC_WALLET = 'ptc' log = logging.getLogger(__name__) @@ -173,7 +176,7 @@ class AdjustableSettings(Setting): ] self.pointtrader_server = 'http://127.0.0.1:2424' self.reflector_servers = [("reflector.lbry.io", 5566)] - self.wallet = "lbryum" + self.wallet = LBRYUM_WALLET self.ui_branch = "master" self.default_ui_branch = 'master' self.data_dir = default_data_dir @@ -201,7 +204,7 @@ class ApplicationSettings(Setting): self.ICON_PATH = "icons" if platform is WINDOWS else "app.icns" self.APP_NAME = "LBRY" self.PROTOCOL_PREFIX = "lbry" - self.WALLET_TYPES = ["lbryum", "lbrycrd"] + self.WALLET_TYPES = [LBRYUM_WALLET, LBRYCRD_WALLET] self.SOURCE_TYPES = ['lbry_sd_hash', 'url', 'btih'] self.CURRENCIES = { 'BTC': {'type': 'crypto'}, diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index 068f17e18..5dbf6227e 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -28,6 +28,7 @@ from lbryum.version import LBRYUM_VERSION as lbryum_version from lbrynet import __version__ as lbrynet_version from lbrynet import conf from lbrynet.conf import settings as lbrynet_settings +from lbrynet.conf import LBRYCRD_WALLET, LBRYUM_WALLET, PTC_WALLET from lbrynet import analytics from lbrynet import reflector from lbrynet.metadata.Metadata import Metadata, verify_name_characters @@ -320,14 +321,14 @@ class Daemon(AuthJSONRPCServer): content = request.content.read() parsed = jsonrpclib.loads(content) function_path = parsed.get("method") - if self.wallet_type == "lbryum" and function_path in ['set_miner', 'get_miner_status']: + if self.wallet_type == LBRYUM_WALLET and function_path in ['set_miner', 'get_miner_status']: log.warning("Mining commands are not available in lbryum") raise Exception("Command not available in lbryum") return True def set_wallet_attributes(self): self.wallet_dir = None - if self.wallet_type != "lbrycrd": + if self.wallet_type != LBRYCRD_WALLET: return if os.name == "nt": from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle @@ -804,25 +805,25 @@ class Daemon(AuthJSONRPCServer): return d def get_wallet(): - if self.wallet_type == "lbrycrd": + if self.wallet_type == LBRYCRD_WALLET: log.info("Using lbrycrd wallet") wallet = LBRYcrdWallet(self.db_dir, wallet_dir=self.wallet_dir, wallet_conf=self.lbrycrd_conf, lbrycrdd_path=self.lbrycrdd_path) d = defer.succeed(wallet) - elif self.wallet_type == "lbryum": + elif self.wallet_type == LBRYUM_WALLET: log.info("Using lbryum wallet") config = {'auto-connect': True} if lbrynet_settings.lbryum_wallet_dir: config['lbryum_path'] = lbrynet_settings.lbryum_wallet_dir d = defer.succeed(LBRYumWallet(self.db_dir, config)) - elif self.wallet_type == "ptc": + elif self.wallet_type == PTC_WALLET: log.info("Using PTC wallet") d = defer.succeed(PTCWallet(self.db_dir)) else: raise ValueError('Wallet Type {} is not valid'.format(self.wallet_type)) - d.addCallback(lambda wallet: {"wallet": wallet}) + d.addCallback(lambda w: {"wallet": w}) return d d1 = get_default_data_rate() @@ -1113,7 +1114,7 @@ class Daemon(AuthJSONRPCServer): r['message'] = self.connection_problem[1] r['is_lagging'] = True elif self.startup_status[0] == LOADING_wallet_CODE: - if self.wallet_type == 'lbryum': + if self.wallet_type == LBRYUM_WALLET: if self.session.wallet.blocks_behind_alert != 0: r['message'] = r['message'] % (str(self.session.wallet.blocks_behind_alert) + " blocks behind") r['progress'] = self.session.wallet.catchup_progress diff --git a/lbrynet/lbrynet_daemon/DaemonControl.py b/lbrynet/lbrynet_daemon/DaemonControl.py index abf18bb5f..9fbc8c10b 100644 --- a/lbrynet/lbrynet_daemon/DaemonControl.py +++ b/lbrynet/lbrynet_daemon/DaemonControl.py @@ -46,7 +46,7 @@ def start(): parser.add_argument("--wallet", help="lbrycrd or lbryum, default lbryum", type=str, - default='lbryum') + default=conf.LBRYUM_WALLET) parser.add_argument("--ui", help="path to custom UI folder", default=None) parser.add_argument( "--branch",