From e909ae566bb08a17ddee29a60400b2a71c251143 Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Mon, 3 Oct 2016 16:19:58 -0500 Subject: [PATCH 1/3] add TODO --- lbrynet/lbrynet_daemon/Daemon.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index 05a654b3a..657aa5779 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -353,6 +353,7 @@ class Daemon(jsonrpc.JSONRPC): self.wallet_dir = os.path.join(os.path.expanduser("~"), ".lbryum") if os.name != 'nt': + # TODO: are we still using this? lbrycrdd_path_conf = os.path.join(os.path.expanduser("~"), ".lbrycrddpath.conf") if not os.path.isfile(lbrycrdd_path_conf): f = open(lbrycrdd_path_conf, "w") From 0ecfad0ae95f3c1842a1f9c911664909c7d085be Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Tue, 4 Oct 2016 13:58:44 -0500 Subject: [PATCH 2/3] add configuration to LBRYumWallet --- lbrynet/conf.py | 2 ++ lbrynet/core/Wallet.py | 12 +++++-- lbrynet/lbrynet_daemon/Daemon.py | 54 +++++++++++++++++--------------- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 2005d7784..cc040be6f 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -75,3 +75,5 @@ LOGGLY_TOKEN = 'LJEzATH4AzRgAwxjAP00LwZ2YGx3MwVgZTMuBQZ3MQuxLmOv' ANALYTICS_ENDPOINT = 'https://api.segment.io/v1' ANALYTICS_TOKEN = 'Ax5LZzR1o3q3Z3WjATASDwR5rKyHH0qOIRIbLmMXn2H=' + +LBRYUM_WALLET_DIR = os.environ.get('LBRYUM_WALLET_DIR') diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 8a7762050..e0a11d04f 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -1110,9 +1110,9 @@ class LBRYcrdWallet(Wallet): class LBRYumWallet(Wallet): - def __init__(self, db_dir): + def __init__(self, db_dir, config=None): Wallet.__init__(self, db_dir) - self.config = None + self._config = config self.network = None self.wallet = None self.cmd_runner = None @@ -1131,7 +1131,7 @@ class LBRYumWallet(Wallet): network_start_d = defer.Deferred() def setup_network(): - self.config = SimpleConfig({'auto_connect': True}) + self.config = make_config(self._config) self.network = Network(self.config) alert.info("Loading the wallet...") return defer.succeed(self.network.start()) @@ -1499,3 +1499,9 @@ class LBRYcrdAddressQueryHandler(object): return defer.fail(Failure(ValueError("Expected but did not receive an address request"))) else: return defer.succeed({}) + + +def make_config(config=None): + if config is None: + config = {} + return SimpleConfig(config) if type(config) == type({}) else config diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index 657aa5779..669f27ee9 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -51,6 +51,7 @@ from lbrynet.conf import MIN_BLOB_DATA_PAYMENT_RATE, DEFAULT_MAX_SEARCH_RESULTS, LOG_POST_URL, LOG_FILE_NAME, REFLECTOR_SERVERS, SEARCH_SERVERS from lbrynet.conf import DEFAULT_SD_DOWNLOAD_TIMEOUT from lbrynet.conf import DEFAULT_TIMEOUT +from lbrynet import conf from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob, BlobStreamDescriptorReader from lbrynet.core.Session import Session from lbrynet.core.PTCWallet import PTCWallet @@ -332,25 +333,7 @@ class Daemon(jsonrpc.JSONRPC): else: self.name_cache = {} - if os.name == "nt": - from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle - self.lbrycrdd_path = "lbrycrdd.exe" - if self.wallet_type == "lbrycrd": - self.wallet_dir = os.path.join(get_path(FOLDERID.RoamingAppData, UserHandle.current), "lbrycrd") - else: - self.wallet_dir = os.path.join(get_path(FOLDERID.RoamingAppData, UserHandle.current), "lbryum") - elif sys.platform == "darwin": - self.lbrycrdd_path = get_darwin_lbrycrdd_path() - if self.wallet_type == "lbrycrd": - self.wallet_dir = user_data_dir("lbrycrd") - else: - self.wallet_dir = user_data_dir("LBRY") - else: - self.lbrycrdd_path = "lbrycrdd" - if self.wallet_type == "lbrycrd": - self.wallet_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd") - else: - self.wallet_dir = os.path.join(os.path.expanduser("~"), ".lbryum") + self.set_wallet_attributes() if os.name != 'nt': # TODO: are we still using this? @@ -366,9 +349,6 @@ class Daemon(jsonrpc.JSONRPC): self.created_data_dir = True self.blobfile_dir = os.path.join(self.db_dir, "blobfiles") - self.lbrycrd_conf = os.path.join(self.wallet_dir, "lbrycrd.conf") - self.autofetcher_conf = os.path.join(self.wallet_dir, "autofetcher.conf") - self.wallet_conf = os.path.join(self.wallet_dir, "lbrycrd.conf") self.wallet_user = None self.wallet_password = None @@ -398,6 +378,24 @@ class Daemon(jsonrpc.JSONRPC): f.write("rpcpassword=" + password) log.info("Done writing lbrycrd.conf") + def set_wallet_attributes(self): + self.wallet_dir = None + if self.wallet_type != "lbrycrd": + return + if os.name == "nt": + from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle + self.lbrycrdd_path = "lbrycrdd.exe" + user_app_dir = get_path(FOLDERID.RoamingAppData, UserHandle.current) + self.wallet_dir = os.path.join(user_app_dir, "lbrycrd") + elif sys.platform == "darwin": + self.lbrycrdd_path = get_darwin_lbrycrdd_path() + self.wallet_dir = user_data_dir("lbrycrd") + else: + self.lbrycrdd_path = "lbrycrdd" + self.wallet_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd") + self.lbrycrd_conf = os.path.join(self.wallet_dir, "lbrycrd.conf") + self.wallet_conf = os.path.join(self.wallet_dir, "lbrycrd.conf") + def _responseFailed(self, err, call): log.debug(err.getTraceback()) @@ -1050,11 +1048,17 @@ class Daemon(jsonrpc.JSONRPC): def get_wallet(): if self.wallet_type == "lbrycrd": log.info("Using lbrycrd wallet") - d = defer.succeed(LBRYcrdWallet(self.db_dir, wallet_dir=self.wallet_dir, wallet_conf=self.lbrycrd_conf, - lbrycrdd_path=self.lbrycrdd_path)) + 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": log.info("Using lbryum wallet") - d = defer.succeed(LBRYumWallet(self.db_dir)) + config = {'auto-connect': True} + if conf.LBRYUM_WALLET_DIR: + config['lbryum_path'] = conf.LBRYUM_WALLET_DIR + d = defer.succeed(LBRYumWallet(self.db_dir, config)) elif self.wallet_type == "ptc": log.info("Using PTC wallet") d = defer.succeed(PTCWallet(self.db_dir)) From a71e87a398dd8f019bc6ce3514e3853269790848 Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Tue, 4 Oct 2016 13:59:04 -0500 Subject: [PATCH 3/3] throw error when invalid wallet is specified --- lbrynet/lbrynet_daemon/Daemon.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index 669f27ee9..0a9bd9b8f 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -313,6 +313,8 @@ class Daemon(jsonrpc.JSONRPC): else: log.info("Using the default wallet type %s", DEFAULT_WALLET) self.wallet_type = DEFAULT_WALLET + if self.wallet_type not in conf.WALLET_TYPES: + raise ValueError('Wallet Type {} is not valid'.format(wallet_type)) # #### self.delete_blobs_on_remove = self.session_settings['delete_blobs_on_remove'] @@ -1063,10 +1065,7 @@ class Daemon(jsonrpc.JSONRPC): log.info("Using PTC wallet") d = defer.succeed(PTCWallet(self.db_dir)) else: - # TODO: should fail here. Can't switch to lbrycrd because the wallet_dir, conf and path won't be set - log.info("Requested unknown wallet '%s', using default lbryum", self.wallet_type) - d = defer.succeed(LBRYumWallet(self.db_dir)) - + raise ValueError('Wallet Type {} is not valid'.format(self.wallet_type)) d.addCallback(lambda wallet: {"wallet": wallet}) return d