use constants for wallet types

This commit is contained in:
Alex Grintsvayg 2016-11-10 14:26:21 -05:00
parent 8e1ad0aa8b
commit 6b72b4de11
4 changed files with 16 additions and 12 deletions

View file

@ -1,7 +1,7 @@
import logging import logging
from lbrynet.core import utils from lbrynet.core import utils
from lbrynet.conf import LBRYUM_WALLET
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -69,7 +69,7 @@ def make_context(platform, wallet, is_dev=False):
'wallet': { 'wallet': {
'name': wallet, 'name': wallet,
# TODO: add in version info for lbrycrdd # 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 # TODO: expand os info to give linux/osx specific info

View file

@ -7,6 +7,9 @@ import yaml
from appdirs import user_data_dir from appdirs import user_data_dir
LBRYCRD_WALLET = 'lbrycrd'
LBRYUM_WALLET = 'lbryum'
PTC_WALLET = 'ptc'
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -173,7 +176,7 @@ class AdjustableSettings(Setting):
] ]
self.pointtrader_server = 'http://127.0.0.1:2424' self.pointtrader_server = 'http://127.0.0.1:2424'
self.reflector_servers = [("reflector.lbry.io", 5566)] self.reflector_servers = [("reflector.lbry.io", 5566)]
self.wallet = "lbryum" self.wallet = LBRYUM_WALLET
self.ui_branch = "master" self.ui_branch = "master"
self.default_ui_branch = 'master' self.default_ui_branch = 'master'
self.data_dir = default_data_dir 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.ICON_PATH = "icons" if platform is WINDOWS else "app.icns"
self.APP_NAME = "LBRY" self.APP_NAME = "LBRY"
self.PROTOCOL_PREFIX = "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.SOURCE_TYPES = ['lbry_sd_hash', 'url', 'btih']
self.CURRENCIES = { self.CURRENCIES = {
'BTC': {'type': 'crypto'}, 'BTC': {'type': 'crypto'},

View file

@ -28,6 +28,7 @@ from lbryum.version import LBRYUM_VERSION as lbryum_version
from lbrynet import __version__ as lbrynet_version from lbrynet import __version__ as lbrynet_version
from lbrynet import conf from lbrynet import conf
from lbrynet.conf import settings as lbrynet_settings 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 analytics
from lbrynet import reflector from lbrynet import reflector
from lbrynet.metadata.Metadata import Metadata, verify_name_characters from lbrynet.metadata.Metadata import Metadata, verify_name_characters
@ -320,14 +321,14 @@ class Daemon(AuthJSONRPCServer):
content = request.content.read() content = request.content.read()
parsed = jsonrpclib.loads(content) parsed = jsonrpclib.loads(content)
function_path = parsed.get("method") 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") log.warning("Mining commands are not available in lbryum")
raise Exception("Command not available in lbryum") raise Exception("Command not available in lbryum")
return True return True
def set_wallet_attributes(self): def set_wallet_attributes(self):
self.wallet_dir = None self.wallet_dir = None
if self.wallet_type != "lbrycrd": if self.wallet_type != LBRYCRD_WALLET:
return return
if os.name == "nt": if os.name == "nt":
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
@ -804,25 +805,25 @@ class Daemon(AuthJSONRPCServer):
return d return d
def get_wallet(): def get_wallet():
if self.wallet_type == "lbrycrd": if self.wallet_type == LBRYCRD_WALLET:
log.info("Using lbrycrd wallet") log.info("Using lbrycrd wallet")
wallet = LBRYcrdWallet(self.db_dir, wallet = LBRYcrdWallet(self.db_dir,
wallet_dir=self.wallet_dir, wallet_dir=self.wallet_dir,
wallet_conf=self.lbrycrd_conf, wallet_conf=self.lbrycrd_conf,
lbrycrdd_path=self.lbrycrdd_path) lbrycrdd_path=self.lbrycrdd_path)
d = defer.succeed(wallet) d = defer.succeed(wallet)
elif self.wallet_type == "lbryum": elif self.wallet_type == LBRYUM_WALLET:
log.info("Using lbryum wallet") log.info("Using lbryum wallet")
config = {'auto-connect': True} config = {'auto-connect': True}
if lbrynet_settings.lbryum_wallet_dir: if lbrynet_settings.lbryum_wallet_dir:
config['lbryum_path'] = lbrynet_settings.lbryum_wallet_dir config['lbryum_path'] = lbrynet_settings.lbryum_wallet_dir
d = defer.succeed(LBRYumWallet(self.db_dir, config)) d = defer.succeed(LBRYumWallet(self.db_dir, config))
elif self.wallet_type == "ptc": elif self.wallet_type == PTC_WALLET:
log.info("Using PTC wallet") log.info("Using PTC wallet")
d = defer.succeed(PTCWallet(self.db_dir)) d = defer.succeed(PTCWallet(self.db_dir))
else: else:
raise ValueError('Wallet Type {} is not valid'.format(self.wallet_type)) 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 return d
d1 = get_default_data_rate() d1 = get_default_data_rate()
@ -1113,7 +1114,7 @@ class Daemon(AuthJSONRPCServer):
r['message'] = self.connection_problem[1] r['message'] = self.connection_problem[1]
r['is_lagging'] = True r['is_lagging'] = True
elif self.startup_status[0] == LOADING_wallet_CODE: 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: if self.session.wallet.blocks_behind_alert != 0:
r['message'] = r['message'] % (str(self.session.wallet.blocks_behind_alert) + " blocks behind") r['message'] = r['message'] % (str(self.session.wallet.blocks_behind_alert) + " blocks behind")
r['progress'] = self.session.wallet.catchup_progress r['progress'] = self.session.wallet.catchup_progress

View file

@ -46,7 +46,7 @@ def start():
parser.add_argument("--wallet", parser.add_argument("--wallet",
help="lbrycrd or lbryum, default lbryum", help="lbrycrd or lbryum, default lbryum",
type=str, type=str,
default='lbryum') default=conf.LBRYUM_WALLET)
parser.add_argument("--ui", help="path to custom UI folder", default=None) parser.add_argument("--ui", help="path to custom UI folder", default=None)
parser.add_argument( parser.add_argument(
"--branch", "--branch",