Merge pull request #180 from lbryio/configure-lbryum

Configure lbryum
This commit is contained in:
Job Evers‐Meltzer 2016-10-11 16:46:39 -05:00 committed by GitHub
commit 897c113db1
3 changed files with 44 additions and 32 deletions

View file

@ -75,3 +75,5 @@ LOGGLY_TOKEN = 'LJEzATH4AzRgAwxjAP00LwZ2YGx3MwVgZTMuBQZ3MQuxLmOv'
ANALYTICS_ENDPOINT = 'https://api.segment.io/v1' ANALYTICS_ENDPOINT = 'https://api.segment.io/v1'
ANALYTICS_TOKEN = 'Ax5LZzR1o3q3Z3WjATASDwR5rKyHH0qOIRIbLmMXn2H=' ANALYTICS_TOKEN = 'Ax5LZzR1o3q3Z3WjATASDwR5rKyHH0qOIRIbLmMXn2H='
LBRYUM_WALLET_DIR = os.environ.get('LBRYUM_WALLET_DIR')

View file

@ -1110,9 +1110,9 @@ class LBRYcrdWallet(Wallet):
class LBRYumWallet(Wallet): class LBRYumWallet(Wallet):
def __init__(self, db_dir): def __init__(self, db_dir, config=None):
Wallet.__init__(self, db_dir) Wallet.__init__(self, db_dir)
self.config = None self._config = config
self.network = None self.network = None
self.wallet = None self.wallet = None
self.cmd_runner = None self.cmd_runner = None
@ -1131,7 +1131,7 @@ class LBRYumWallet(Wallet):
network_start_d = defer.Deferred() network_start_d = defer.Deferred()
def setup_network(): def setup_network():
self.config = SimpleConfig({'auto_connect': True}) self.config = make_config(self._config)
self.network = Network(self.config) self.network = Network(self.config)
alert.info("Loading the wallet...") alert.info("Loading the wallet...")
return defer.succeed(self.network.start()) 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"))) return defer.fail(Failure(ValueError("Expected but did not receive an address request")))
else: else:
return defer.succeed({}) return defer.succeed({})
def make_config(config=None):
if config is None:
config = {}
return SimpleConfig(config) if type(config) == type({}) else config

View file

@ -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 LOG_POST_URL, LOG_FILE_NAME, REFLECTOR_SERVERS, SEARCH_SERVERS
from lbrynet.conf import DEFAULT_SD_DOWNLOAD_TIMEOUT from lbrynet.conf import DEFAULT_SD_DOWNLOAD_TIMEOUT
from lbrynet.conf import DEFAULT_TIMEOUT from lbrynet.conf import DEFAULT_TIMEOUT
from lbrynet import conf
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob, BlobStreamDescriptorReader from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob, BlobStreamDescriptorReader
from lbrynet.core.Session import Session from lbrynet.core.Session import Session
from lbrynet.core.PTCWallet import PTCWallet from lbrynet.core.PTCWallet import PTCWallet
@ -312,6 +313,8 @@ class Daemon(jsonrpc.JSONRPC):
else: else:
log.info("Using the default wallet type %s", DEFAULT_WALLET) log.info("Using the default wallet type %s", DEFAULT_WALLET)
self.wallet_type = 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'] self.delete_blobs_on_remove = self.session_settings['delete_blobs_on_remove']
@ -332,27 +335,10 @@ class Daemon(jsonrpc.JSONRPC):
else: else:
self.name_cache = {} self.name_cache = {}
if os.name == "nt": self.set_wallet_attributes()
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")
if os.name != 'nt': if os.name != 'nt':
# TODO: are we still using this?
lbrycrdd_path_conf = os.path.join(os.path.expanduser("~"), ".lbrycrddpath.conf") lbrycrdd_path_conf = os.path.join(os.path.expanduser("~"), ".lbrycrddpath.conf")
if not os.path.isfile(lbrycrdd_path_conf): if not os.path.isfile(lbrycrdd_path_conf):
f = open(lbrycrdd_path_conf, "w") f = open(lbrycrdd_path_conf, "w")
@ -365,9 +351,6 @@ class Daemon(jsonrpc.JSONRPC):
self.created_data_dir = True self.created_data_dir = True
self.blobfile_dir = os.path.join(self.db_dir, "blobfiles") 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_user = None
self.wallet_password = None self.wallet_password = None
@ -397,6 +380,24 @@ class Daemon(jsonrpc.JSONRPC):
f.write("rpcpassword=" + password) f.write("rpcpassword=" + password)
log.info("Done writing lbrycrd.conf") 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): def _responseFailed(self, err, call):
log.debug(err.getTraceback()) log.debug(err.getTraceback())
@ -1049,19 +1050,22 @@ class Daemon(jsonrpc.JSONRPC):
def get_wallet(): def get_wallet():
if self.wallet_type == "lbrycrd": if self.wallet_type == "lbrycrd":
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, wallet = LBRYcrdWallet(self.db_dir,
lbrycrdd_path=self.lbrycrdd_path)) 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":
log.info("Using lbryum wallet") 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": 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))
else: else:
# TODO: should fail here. Can't switch to lbrycrd because the wallet_dir, conf and path won't be set raise ValueError('Wallet Type {} is not valid'.format(self.wallet_type))
log.info("Requested unknown wallet '%s', using default lbryum", self.wallet_type)
d = defer.succeed(LBRYumWallet(self.db_dir))
d.addCallback(lambda wallet: {"wallet": wallet}) d.addCallback(lambda wallet: {"wallet": wallet})
return d return d