From 87c7ce588e46f564e1488585797520dbf11ae2c3 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Tue, 31 Dec 2019 16:33:08 -0500 Subject: [PATCH] disabled cryptonator.com in tests, removed references to torba --- lbry/lbry/extras/cli.py | 3 +- lbry/lbry/extras/daemon/Components.py | 2 +- lbry/lbry/extras/daemon/Daemon.py | 3 +- .../extras/daemon/exchange_rate_manager.py | 8 +- lbry/lbry/stream/stream_manager.py | 2 +- lbry/lbry/testcase.py | 3 +- lbry/lbry/wallet/client/cli.py | 89 ------------------- lbry/lbry/wallet/client/mnemonic.py | 2 +- lbry/lbry/wallet/orchstr8/cli.py | 2 +- lbry/lbry/wallet/orchstr8/node.py | 20 +---- lbry/lbry/wallet/orchstr8/service.py | 8 +- lbry/lbry/wallet/server/cli.py | 10 +-- .../integration/test_exchange_rate_manager.py | 5 +- 13 files changed, 27 insertions(+), 130 deletions(-) delete mode 100644 lbry/lbry/wallet/client/cli.py diff --git a/lbry/lbry/extras/cli.py b/lbry/lbry/extras/cli.py index 4156031bf..46586af02 100644 --- a/lbry/lbry/extras/cli.py +++ b/lbry/lbry/extras/cli.py @@ -225,7 +225,7 @@ def ensure_directory_exists(path: str): pathlib.Path(path).mkdir(parents=True, exist_ok=True) -LOG_MODULES = ('lbry', 'torba', 'aioupnp') +LOG_MODULES = 'lbry', 'aioupnp' def setup_logging(logger: logging.Logger, args: argparse.Namespace, conf: Config): @@ -241,7 +241,6 @@ def setup_logging(logger: logging.Logger, args: argparse.Namespace, conf: Config logger.getChild(module_name).addHandler(handler) logger.getChild('lbry').setLevel(logging.INFO) - logger.getChild('torba').setLevel(logging.INFO) logger.getChild('aioupnp').setLevel(logging.WARNING) logger.getChild('aiohttp').setLevel(logging.CRITICAL) diff --git a/lbry/lbry/extras/daemon/Components.py b/lbry/lbry/extras/daemon/Components.py index fc7854532..73dd2cd79 100644 --- a/lbry/lbry/extras/daemon/Components.py +++ b/lbry/lbry/extras/daemon/Components.py @@ -145,7 +145,7 @@ class WalletComponent(Component): return result async def start(self): - log.info("Starting torba wallet") + log.info("Starting wallet") self.wallet_manager = await LbryWalletManager.from_lbrynet_config(self.conf) await self.wallet_manager.start() diff --git a/lbry/lbry/extras/daemon/Daemon.py b/lbry/lbry/extras/daemon/Daemon.py index 6707c5746..7d911405d 100644 --- a/lbry/lbry/extras/daemon/Daemon.py +++ b/lbry/lbry/extras/daemon/Daemon.py @@ -856,8 +856,7 @@ class Daemon(metaclass=JSONRPCServerType): 'platform': (str) platform string, 'os_release': (str) os release string, 'os_system': (str) os name, - 'lbrynet_version': (str) lbrynet version, - 'torba_version': (str) torba version, + 'version': (str) lbrynet version, 'build': (str) "dev" | "qa" | "rc" | "release", } """ diff --git a/lbry/lbry/extras/daemon/exchange_rate_manager.py b/lbry/lbry/extras/daemon/exchange_rate_manager.py index fad6f6e05..9e0c45df2 100644 --- a/lbry/lbry/extras/daemon/exchange_rate_manager.py +++ b/lbry/lbry/extras/daemon/exchange_rate_manager.py @@ -4,6 +4,7 @@ import asyncio import logging from decimal import Decimal from typing import Optional, Iterable, Type +from aiohttp.client_exceptions import ContentTypeError from lbry.error import InvalidExchangeRateResponseError, CurrencyConversionError from lbry.utils import aiohttp_request from lbry.wallet.dewies import lbc_to_dewies @@ -58,7 +59,12 @@ class MarketFeed: async def get_response(self): async with aiohttp_request('get', self.url, params=self.params, timeout=self.request_timeout) as response: - self._last_response = await response.json() + try: + self._last_response = await response.json() + except ContentTypeError as e: + self._last_response = {} + log.warning("Could not parse exchange rate response from %s: %s", self.name, e.message) + log.debug(await response.text()) return self._last_response async def get_rate(self): diff --git a/lbry/lbry/stream/stream_manager.py b/lbry/lbry/stream/stream_manager.py index 8ac934664..d019502e9 100644 --- a/lbry/lbry/stream/stream_manager.py +++ b/lbry/lbry/stream/stream_manager.py @@ -24,7 +24,7 @@ if typing.TYPE_CHECKING: from lbry.wallet import LbryWalletManager from lbry.wallet.transaction import Transaction from lbry.extras.daemon.exchange_rate_manager import ExchangeRateManager - from torba.client.wallet import Wallet + from lbry.wallet.client.wallet import Wallet log = logging.getLogger(__name__) diff --git a/lbry/lbry/testcase.py b/lbry/lbry/testcase.py index d5fc574b7..d66c945cc 100644 --- a/lbry/lbry/testcase.py +++ b/lbry/lbry/testcase.py @@ -218,7 +218,6 @@ class IntegrationTestCase(AsyncioTestCase): LEDGER = lbry.wallet MANAGER = LbryWalletManager ENABLE_SEGWIT = False - VERBOSITY = logging.WARN def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -232,7 +231,7 @@ class IntegrationTestCase(AsyncioTestCase): async def asyncSetUp(self): self.conductor = Conductor( - ledger_module=self.LEDGER, manager_module=self.MANAGER, verbosity=self.VERBOSITY, + ledger_module=self.LEDGER, manager_module=self.MANAGER, enable_segwit=self.ENABLE_SEGWIT, seed=self.SEED ) await self.conductor.start_blockchain() diff --git a/lbry/lbry/wallet/client/cli.py b/lbry/lbry/wallet/client/cli.py deleted file mode 100644 index 718d42baa..000000000 --- a/lbry/lbry/wallet/client/cli.py +++ /dev/null @@ -1,89 +0,0 @@ -import logging -import argparse -import asyncio -import aiohttp - -from torba.orchstr8.node import Conductor, get_ledger_from_environment, get_blockchain_node_from_ledger -from torba.orchstr8.service import ConductorService - - -def get_argument_parser(): - parser = argparse.ArgumentParser( - prog="torba" - ) - subparsers = parser.add_subparsers(dest='command', help='sub-command help') - - subparsers.add_parser("gui", help="Start Qt GUI.") - - subparsers.add_parser("download", help="Download blockchain node binary.") - - start = subparsers.add_parser("start", help="Start orchstr8 service.") - start.add_argument("--blockchain", help="Start blockchain node.", action="store_true") - start.add_argument("--spv", help="Start SPV server.", action="store_true") - start.add_argument("--wallet", help="Start wallet daemon.", action="store_true") - - generate = subparsers.add_parser("generate", help="Call generate method on running orchstr8 instance.") - generate.add_argument("blocks", type=int, help="Number of blocks to generate") - - subparsers.add_parser("transfer", help="Call transfer method on running orchstr8 instance.") - return parser - - -async def run_remote_command(command, **kwargs): - async with aiohttp.ClientSession() as session: - async with session.post('http://localhost:7954/'+command, data=kwargs) as resp: - print(resp.status) - print(await resp.text()) - - -def main(): - parser = get_argument_parser() - args = parser.parse_args() - command = getattr(args, 'command', 'help') - - if command == 'gui': - from torba.workbench import main as start_app # pylint: disable=import-outside-toplevel - return start_app() - - loop = asyncio.get_event_loop() - ledger = get_ledger_from_environment() - - if command == 'download': - logging.getLogger('blockchain').setLevel(logging.INFO) - get_blockchain_node_from_ledger(ledger).ensure() - - elif command == 'generate': - loop.run_until_complete(run_remote_command( - 'generate', blocks=args.blocks - )) - - elif command == 'start': - - conductor = Conductor() - if getattr(args, 'blockchain', False): - loop.run_until_complete(conductor.start_blockchain()) - if getattr(args, 'spv', False): - loop.run_until_complete(conductor.start_spv()) - if getattr(args, 'wallet', False): - loop.run_until_complete(conductor.start_wallet()) - - service = ConductorService(conductor, loop) - loop.run_until_complete(service.start()) - - try: - print('========== Orchstr8 API Service Started ========') - loop.run_forever() - except KeyboardInterrupt: - pass - finally: - loop.run_until_complete(service.stop()) - loop.run_until_complete(conductor.stop()) - - loop.close() - - else: - parser.print_help() - - -if __name__ == "__main__": - main() diff --git a/lbry/lbry/wallet/client/mnemonic.py b/lbry/lbry/wallet/client/mnemonic.py index 1fcc9afa5..0fcfe5b57 100644 --- a/lbry/lbry/wallet/client/mnemonic.py +++ b/lbry/lbry/wallet/client/mnemonic.py @@ -80,7 +80,7 @@ def normalize_text(seed): def load_words(language_name): if language_name == 'english': return english.words - language_module = importlib.import_module('torba.words.'+language_name) + language_module = importlib.import_module('lbry.wallet.client.words.'+language_name) return list(map( lambda s: unicodedata.normalize('NFKD', s), language_module.words diff --git a/lbry/lbry/wallet/orchstr8/cli.py b/lbry/lbry/wallet/orchstr8/cli.py index 3b0c035f0..cc49b8bd5 100644 --- a/lbry/lbry/wallet/orchstr8/cli.py +++ b/lbry/lbry/wallet/orchstr8/cli.py @@ -11,7 +11,7 @@ from lbry.wallet.orchstr8.service import ConductorService def get_argument_parser(): parser = argparse.ArgumentParser( - prog="torba" + prog="orchstr8" ) subparsers = parser.add_subparsers(dest='command', help='sub-command help') diff --git a/lbry/lbry/wallet/orchstr8/node.py b/lbry/lbry/wallet/orchstr8/node.py index 82bf9700a..cafe538d3 100644 --- a/lbry/lbry/wallet/orchstr8/node.py +++ b/lbry/lbry/wallet/orchstr8/node.py @@ -48,25 +48,9 @@ def get_blockchain_node_from_ledger(ledger_module): ) -def set_logging(ledger_module, level, handler=None): - modules = [ - 'torba', - 'torba.client', - 'torba.server', - 'blockchain', - ledger_module.__name__ - ] - for module_name in modules: - module = logging.getLogger(module_name) - module.setLevel(level) - if handler is not None: - module.addHandler(handler) - - class Conductor: - def __init__(self, ledger_module=None, manager_module=None, verbosity=logging.WARNING, - enable_segwit=False, seed=None): + def __init__(self, ledger_module=None, manager_module=None, enable_segwit=False, seed=None): self.ledger_module = ledger_module or get_ledger_from_environment() self.manager_module = manager_module or get_manager_from_environment() self.spv_module = get_spvserver_from_ledger(self.ledger_module) @@ -78,8 +62,6 @@ class Conductor: self.manager_module, self.ledger_module.RegTestLedger, default_seed=seed ) - set_logging(self.ledger_module, verbosity) - self.blockchain_started = False self.spv_started = False self.wallet_started = False diff --git a/lbry/lbry/wallet/orchstr8/service.py b/lbry/lbry/wallet/orchstr8/service.py index 39aa571c8..25a62081d 100644 --- a/lbry/lbry/wallet/orchstr8/service.py +++ b/lbry/lbry/wallet/orchstr8/service.py @@ -4,7 +4,7 @@ from aiohttp.web import Application, WebSocketResponse, json_response from aiohttp.http_websocket import WSMsgType, WSCloseCode from lbry.wallet.client.util import satoshis_to_coins -from .node import Conductor, set_logging +from .node import Conductor PORT = 7954 @@ -58,9 +58,9 @@ class ConductorService: await self.app.cleanup() async def start_stack(self, _): - set_logging( - self.stack.ledger_module, logging.DEBUG, WebSocketLogHandler(self.send_message) - ) + #set_logging( + # self.stack.ledger_module, logging.DEBUG, WebSocketLogHandler(self.send_message) + #) self.stack.blockchain_started or await self.stack.start_blockchain() self.send_message({'type': 'service', 'name': 'blockchain', 'port': self.stack.blockchain_node.port}) self.stack.spv_started or await self.stack.start_spv() diff --git a/lbry/lbry/wallet/server/cli.py b/lbry/lbry/wallet/server/cli.py index f627d3cff..5cb15fc5e 100644 --- a/lbry/lbry/wallet/server/cli.py +++ b/lbry/lbry/wallet/server/cli.py @@ -2,8 +2,8 @@ import logging import traceback import argparse import importlib -from torba.server.env import Env -from torba.server.server import Server +from lbry.wallet.server.env import Env +from lbry.wallet.server.server import Server def get_argument_parser(): @@ -26,15 +26,15 @@ def main(): args = parser.parse_args() coin_class = get_coin_class(args.spvserver) logging.basicConfig(level=logging.INFO) - logging.info('torba.server starting') + logging.info('lbry.server starting') try: server = Server(Env(coin_class)) server.run() except Exception: traceback.print_exc() - logging.critical('torba.server terminated abnormally') + logging.critical('lbry.server terminated abnormally') else: - logging.info('torba.server terminated normally') + logging.info('lbry.server terminated normally') if __name__ == "__main__": diff --git a/lbry/tests/integration/test_exchange_rate_manager.py b/lbry/tests/integration/test_exchange_rate_manager.py index 30a753d17..4f67e4f93 100644 --- a/lbry/tests/integration/test_exchange_rate_manager.py +++ b/lbry/tests/integration/test_exchange_rate_manager.py @@ -1,12 +1,13 @@ from decimal import Decimal from lbry.testcase import AsyncioTestCase -from lbry.extras.daemon.exchange_rate_manager import ExchangeRate, ExchangeRateManager +from lbry.extras.daemon.exchange_rate_manager import ExchangeRate, ExchangeRateManager, FEEDS class TestExchangeRateManager(AsyncioTestCase): async def test_exchange_rate_manager(self): - manager = ExchangeRateManager() + # TODO: re-enable cryptonator.com + manager = ExchangeRateManager(FEEDS[:-2]) manager.start() self.addCleanup(manager.stop) for feed in manager.market_feeds: