Changed LBRYcrdWallet to retrieve the rpc config
This commit is contained in:
parent
756c43c087
commit
0891b0d294
3 changed files with 38 additions and 50 deletions
|
@ -41,11 +41,10 @@ class LBRYcrdWallet(object):
|
||||||
"""This class implements the LBRYWallet interface for the LBRYcrd payment system"""
|
"""This class implements the LBRYWallet interface for the LBRYcrd payment system"""
|
||||||
implements(ILBRYWallet)
|
implements(ILBRYWallet)
|
||||||
|
|
||||||
def __init__(self, db_dir, rpc_user, rpc_pass, rpc_url, rpc_port, wallet_dir=None, wallet_conf=None,
|
def __init__(self, db_dir, wallet_dir=None, wallet_conf=None, lbrycrdd_path=None):
|
||||||
lbrycrdd_path=None):
|
|
||||||
self.db_dir = db_dir
|
self.db_dir = db_dir
|
||||||
self.db = None
|
self.db = None
|
||||||
self.rpc_conn_string = "http://%s:%s@%s:%s" % (rpc_user, rpc_pass, rpc_url, str(rpc_port))
|
|
||||||
self.next_manage_call = None
|
self.next_manage_call = None
|
||||||
self.wallet_balance = Decimal(0.0)
|
self.wallet_balance = Decimal(0.0)
|
||||||
self.total_reserved_points = Decimal(0.0)
|
self.total_reserved_points = Decimal(0.0)
|
||||||
|
@ -64,6 +63,13 @@ class LBRYcrdWallet(object):
|
||||||
self.manage_running = False
|
self.manage_running = False
|
||||||
self.lbrycrdd_path = lbrycrdd_path
|
self.lbrycrdd_path = lbrycrdd_path
|
||||||
|
|
||||||
|
settings = self.get_rpc_conf()
|
||||||
|
rpc_user = settings["username"]
|
||||||
|
rpc_pass = settings["password"]
|
||||||
|
rpc_port = settings["rpc_port"]
|
||||||
|
rpc_url = "127.0.0.1"
|
||||||
|
self.rpc_conn_string = "http://%s:%s@%s:%s" % (rpc_user, rpc_pass, rpc_url, str(rpc_port))
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
|
||||||
def make_connection():
|
def make_connection():
|
||||||
|
@ -315,6 +321,21 @@ class LBRYcrdWallet(object):
|
||||||
def get_new_address(self):
|
def get_new_address(self):
|
||||||
return threads.deferToThread(self._get_new_address)
|
return threads.deferToThread(self._get_new_address)
|
||||||
|
|
||||||
|
def get_rpc_conf(self):
|
||||||
|
settings = {"username": "rpcuser",
|
||||||
|
"password": "rpcpassword",
|
||||||
|
"rpc_port": 8332}
|
||||||
|
if os.path.exists(self.wallet_conf):
|
||||||
|
conf = open(self.wallet_conf)
|
||||||
|
for l in conf:
|
||||||
|
if l.startswith("rpcuser="):
|
||||||
|
settings["username"] = l[8:].rstrip('\n')
|
||||||
|
if l.startswith("rpcpassword="):
|
||||||
|
settings["password"] = l[12:].rstrip('\n')
|
||||||
|
if l.startswith("rpcport="):
|
||||||
|
settings["rpc_port"] = int(l[8:].rstrip('\n'))
|
||||||
|
return settings
|
||||||
|
|
||||||
def _get_rpc_conn(self):
|
def _get_rpc_conn(self):
|
||||||
return AuthServiceProxy(self.rpc_conn_string)
|
return AuthServiceProxy(self.rpc_conn_string)
|
||||||
|
|
||||||
|
|
|
@ -220,55 +220,21 @@ class LBRYConsole():
|
||||||
d = self.settings.save_lbryid(self.lbryid)
|
d = self.settings.save_lbryid(self.lbryid)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _check_config_newlines(self, config_path):
|
|
||||||
f = open(config_path, 'r')
|
|
||||||
lines = [l for l in f]
|
|
||||||
f.close()
|
|
||||||
if lines[-1][-1] != "\n":
|
|
||||||
f = open(config_path, 'w')
|
|
||||||
for l in lines:
|
|
||||||
if l[-1] == "\n":
|
|
||||||
f.write(l)
|
|
||||||
else:
|
|
||||||
f.write(l + "\n")
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def _get_lbrycrd_settings(self):
|
|
||||||
settings = {"username": "rpcuser",
|
|
||||||
"password": "rpcpassword",
|
|
||||||
"rpc_port": 8332}
|
|
||||||
if os.path.exists(self.lbrycrd_conf):
|
|
||||||
self._check_config_newlines(self.lbrycrd_conf)
|
|
||||||
lbrycrd_conf = open(self.lbrycrd_conf)
|
|
||||||
for l in lbrycrd_conf:
|
|
||||||
if l.startswith("rpcuser="):
|
|
||||||
settings["username"] = l[8:-1]
|
|
||||||
if l.startswith("rpcpassword="):
|
|
||||||
settings["password"] = l[12:-1]
|
|
||||||
if l.startswith("rpcport="):
|
|
||||||
settings["rpc_port"] = int(l[8:-1])
|
|
||||||
return settings
|
|
||||||
|
|
||||||
def _get_session(self):
|
def _get_session(self):
|
||||||
def get_default_data_rate():
|
def get_default_data_rate():
|
||||||
d = self.settings.get_default_data_payment_rate()
|
d = self.settings.get_default_data_payment_rate()
|
||||||
d.addCallback(lambda rate: {"default_data_payment_rate": rate if rate is not None else MIN_BLOB_DATA_PAYMENT_RATE})
|
d.addCallback(lambda rate: {"default_data_payment_rate": rate if rate is not None else MIN_BLOB_DATA_PAYMENT_RATE})
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def create_lbrycrd_wallet(lbrycrd_options):
|
|
||||||
lbrycrdd_path = None
|
|
||||||
if self.start_lbrycrdd is True:
|
|
||||||
lbrycrdd_path = self.lbrycrdd_path
|
|
||||||
if not lbrycrdd_path:
|
|
||||||
lbrycrdd_path = self.default_lbrycrdd_path
|
|
||||||
return LBRYcrdWallet(self.db_dir, lbrycrd_options['username'], lbrycrd_options['password'],
|
|
||||||
"127.0.0.1", lbrycrd_options['rpc_port'], wallet_dir=self.lbrycrd_dir,
|
|
||||||
wallet_conf=self.lbrycrd_conf, lbrycrdd_path=lbrycrdd_path)
|
|
||||||
|
|
||||||
def get_wallet():
|
def get_wallet():
|
||||||
if self.wallet_type == "lbrycrd":
|
if self.wallet_type == "lbrycrd":
|
||||||
d = threads.deferToThread(self._get_lbrycrd_settings)
|
lbrycrdd_path = None
|
||||||
d.addCallback(create_lbrycrd_wallet)
|
if self.start_lbrycrdd is True:
|
||||||
|
lbrycrdd_path = self.lbrycrdd_path
|
||||||
|
if not lbrycrdd_path:
|
||||||
|
lbrycrdd_path = self.default_lbrycrdd_path
|
||||||
|
d = defer.succeed(LBRYcrdWallet(self.db_dir, wallet_dir=self.lbrycrd_dir,
|
||||||
|
wallet_conf=self.lbrycrd_conf, lbrycrdd_path=lbrycrdd_path))
|
||||||
else:
|
else:
|
||||||
d = defer.succeed(PTCWallet(self.db_dir))
|
d = defer.succeed(PTCWallet(self.db_dir))
|
||||||
d.addCallback(lambda wallet: {"wallet": wallet})
|
d.addCallback(lambda wallet: {"wallet": wallet})
|
||||||
|
|
|
@ -282,19 +282,20 @@ class LBRYDownloader(object):
|
||||||
lbrycrd_conf = open(self.wallet_conf)
|
lbrycrd_conf = open(self.wallet_conf)
|
||||||
for l in lbrycrd_conf:
|
for l in lbrycrd_conf:
|
||||||
if l.startswith("rpcuser="):
|
if l.startswith("rpcuser="):
|
||||||
self.wallet_user = l[8:-1]
|
self.wallet_user = l[8:].rstrip('\n')
|
||||||
if l.startswith("rpcpassword="):
|
if l.startswith("rpcpassword="):
|
||||||
self.wallet_password = l[12:-1]
|
self.wallet_password = l[12:].rstrip('\n')
|
||||||
if l.startswith("rpcport="):
|
if l.startswith("rpcport="):
|
||||||
self.wallet_rpc_port = int(l[8:-1])
|
self.wallet_rpc_port = int(l[8:-1].rstrip('\n'))
|
||||||
|
|
||||||
def _get_session(self):
|
def _get_session(self):
|
||||||
lbrycrdd_path = None
|
lbrycrdd_path = None
|
||||||
if self.start_lbrycrdd is True:
|
if self.start_lbrycrdd is True:
|
||||||
lbrycrdd_path = self.lbrycrdd_path
|
lbrycrdd_path = self.lbrycrdd_path
|
||||||
wallet = LBRYcrdWallet(self.db_dir, self.wallet_user, self.wallet_password, "127.0.0.1",
|
|
||||||
self.wallet_rpc_port, wallet_dir=self.wallet_dir,
|
wallet = LBRYcrdWallet(self.db_dir, wallet_dir=self.wallet_dir, wallet_conf=self.wallet_conf,
|
||||||
wallet_conf=self.wallet_conf, lbrycrdd_path=lbrycrdd_path)
|
lbrycrdd_path=lbrycrdd_path)
|
||||||
|
|
||||||
peer_port = None
|
peer_port = None
|
||||||
if self.run_server:
|
if self.run_server:
|
||||||
peer_port = self.peer_port
|
peer_port = self.peer_port
|
||||||
|
|
Loading…
Add table
Reference in a new issue