예제 #1
0
def get_test_daemon(data_rate=None, generous=True, with_fee=False):
    if data_rate is None:
        data_rate = conf.ADJUSTABLE_SETTINGS['data_rate'][1]

    rates = {
        'BTCLBC': {
            'spot': 3.0,
            'ts': util.DEFAULT_ISO_TIME + 1
        },
        'USDBTC': {
            'spot': 2.0,
            'ts': util.DEFAULT_ISO_TIME + 2
        }
    }
    daemon = LBRYDaemon(None)
    daemon.session = mock.Mock(spec=Session.Session)
    daemon.session.wallet = mock.Mock(spec=Wallet.LBRYumWallet)
    market_feeds = [BTCLBCFeed(), USDBTCFeed()]
    daemon.exchange_rate_manager = DummyExchangeRateManager(
        market_feeds, rates)
    base_prm = PaymentRateManager.BasePaymentRateManager(rate=data_rate)
    prm = PaymentRateManager.NegotiatedPaymentRateManager(
        base_prm, DummyBlobAvailabilityTracker(), generous=generous)
    daemon.session.payment_rate_manager = prm

    metadata = {
        "author": "fake author",
        "language": "en",
        "content_type": "fake/format",
        "description": "fake description",
        "license": "fake license",
        "license_url": "fake license url",
        "nsfw": False,
        "sources": {
            "lbry_sd_hash":
            'd2b8b6e907dde95245fe6d144d16c2fdd60c4e0c6463ec98'
            'b85642d06d8e9414e8fcfdcb7cb13532ec5454fb8fe7f280'
        },
        "thumbnail": "fake thumbnail",
        "title": "fake title",
        "ver": "0.0.3"
    }
    if with_fee:
        metadata.update({
            "fee": {
                "USD": {
                    "address": "bQ6BGboPV2SpTMEP7wLNiAcnsZiH8ye6eA",
                    "amount": 0.75
                }
            }
        })
    daemon._resolve_name = lambda _: defer.succeed(metadata)
    migrated = smart_decode(json.dumps(metadata))
    daemon.session.wallet.resolve = lambda *_: defer.succeed(
        {"test": {
            'claim': {
                'value': migrated.claim_dict
            }
        }})
    return daemon
예제 #2
0
def start():
    # lbry daemon
    https_context()
    conf.initialize_settings()

    lbrynet_log = conf.settings.get_log_filename()
    log_support.configure_logging(lbrynet_log, True, [])

    # TODO: specify components, initialise auth
    conf.settings.update({
        'components_to_skip':
        [PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT],
        'concurrent_announcers':
        0,
        'use_upnp':
        False
    })

    log.info('Final Settings: %s', conf.settings.get_current_settings_dict())
    log.info("Starting lbrynet-daemon")

    if test_internet_connection():
        daemon = Daemon()
        daemon.start_listening()
        reactor.run()
    else:
        log.info("Not connected to the Internet. Unable to start.")
예제 #3
0
    async def setUp(self):
        await super().setUp()

        if self.VERBOSE:
            log.setLevel(logging.DEBUG)
            logging.getLogger('lbrynet.core').setLevel(logging.DEBUG)

        lbry_conf.settings = None
        lbry_conf.initialize_settings(load_conf_file=False)
        lbry_conf.settings['data_dir'] = self.stack.wallet.data_path
        lbry_conf.settings['lbryum_wallet_dir'] = self.stack.wallet.data_path
        lbry_conf.settings['download_directory'] = self.stack.wallet.data_path
        lbry_conf.settings['use_upnp'] = False
        lbry_conf.settings['reflect_uploads'] = False
        lbry_conf.settings['blockchain_name'] = 'lbrycrd_regtest'
        lbry_conf.settings['lbryum_servers'] = [('localhost', 50001)]
        lbry_conf.settings['known_dht_nodes'] = []
        lbry_conf.settings.node_id = None

        await d2f(self.account.ensure_address_gap())
        address = (await d2f(
            self.account.receiving.get_addresses(1, only_usable=True)))[0]
        sendtxid = await self.blockchain.send_to_address(address, 10)
        await self.confirm_tx(sendtxid)
        await self.generate(5)

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet = self.manager
            self.wallet_component._running = True
            return self.wallet_component

        skip = [
            #UPNP_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT,
            REFLECTOR_COMPONENT
        ]
        analytics_manager = FakeAnalytics()
        self.daemon = Daemon(
            analytics_manager,
            ComponentManager(analytics_manager=analytics_manager,
                             skip_components=skip,
                             wallet=wallet_maker,
                             dht=FakeDHT,
                             hash_announcer=FakeHashAnnouncerComponent,
                             exchange_rate_manager=FakeExchangeRateComponent,
                             upnp=FakeUPnP))
        #for component in skip:
        #    self.daemon.component_attributes.pop(component, None)
        await d2f(self.daemon.setup())
        self.daemon.wallet = self.wallet_component.wallet
        self.manager.old_db = self.daemon.storage
def start(argv=None, conf_path=None):
    if conf_path is not None:
        conf.conf_file = conf_path

    conf.initialize_settings()

    parser = argparse.ArgumentParser()
    parser.add_argument("--http-auth",
                        dest="useauth",
                        action="store_true",
                        default=conf.settings['use_auth_http'])
    parser.add_argument('--quiet',
                        dest='quiet',
                        action="store_true",
                        help='Disable all console output.')
    parser.add_argument(
        '--verbose',
        nargs="*",
        help=
        ('Enable debug output. Optionally specify loggers for which debug output '
         'should selectively be applied.'))
    parser.add_argument('--version',
                        action="store_true",
                        help='Show daemon version and quit')

    args = parser.parse_args(argv)
    if args.useauth:
        conf.settings.update({'use_auth_http': args.useauth},
                             data_types=(conf.TYPE_CLI, ))

    if args.version:
        version = system_info.get_platform(get_ip=False)
        version['installation_id'] = conf.settings.installation_id
        print(utils.json_dumps_pretty(version))
        return

    lbrynet_log = conf.settings.get_log_filename()
    log_support.configure_logging(lbrynet_log, not args.quiet, args.verbose)
    log_support.configure_loggly_handler()
    log.debug('Final Settings: %s', conf.settings.get_current_settings_dict())

    log.info("Starting lbrynet-daemon from command line")

    if test_internet_connection():
        daemon = Daemon()
        daemon.start_listening()
        reactor.run()
    else:
        log.info("Not connected to internet, unable to start")
예제 #5
0
class DaemonServer(object):
    def __init__(self, analytics_manager=None):
        self._daemon = None
        self.root = None
        self.server_port = None
        self.analytics_manager = analytics_manager

    def _setup_server(self, use_auth):
        self.root = IndexResource()
        self._daemon = Daemon(self.analytics_manager)
        self.root.putChild("", self._daemon)
        # TODO: DEPRECATED, remove this and just serve the API at the root
        self.root.putChild(conf.settings['API_ADDRESS'], self._daemon)

        lbrynet_server = get_site_base(use_auth, self.root)
        lbrynet_server.requestFactory = DaemonRequest

        try:
            self.server_port = reactor.listenTCP(
                conf.settings['api_port'], lbrynet_server, interface=conf.settings['api_host'])
        except error.CannotListenError:
            log.info('Daemon already running, exiting app')
            raise

        return defer.succeed(True)

    @defer.inlineCallbacks
    def start(self, use_auth):
        yield self._setup_server(use_auth)
        yield self._daemon.setup()

    def stop(self):
        if reactor.running:
            log.info("Stopping the reactor")
            reactor.fireSystemEvent("shutdown")
예제 #6
0
 def setUp(self):
     skip = [
         DATABASE_COMPONENT, BLOB_COMPONENT, HEADERS_COMPONENT,
         WALLET_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT,
         STREAM_IDENTIFIER_COMPONENT, FILE_MANAGER_COMPONENT,
         PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT,
         UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT,
         RATE_LIMITER_COMPONENT, PAYMENT_RATE_COMPONENT
     ]
     conf.initialize_settings(load_conf_file=False)
     conf.settings['use_auth_http'] = self.USE_AUTH
     conf.settings["components_to_skip"] = skip
     conf.settings.initialize_post_conf_load()
     Daemon.component_attributes = {}
     self.daemon = Daemon(analytics_manager=FakeAnalytics())
     yield self.daemon.start_listening()
예제 #7
0
class DaemonServer(object):
    def __init__(self, analytics_manager=None):
        self._daemon = None
        self.root = None
        self.server_port = None
        self.analytics_manager = analytics_manager

    def _setup_server(self, use_auth):
        self.root = IndexResource()
        self._daemon = Daemon(self.analytics_manager)
        self.root.putChild("", self._daemon)
        # TODO: DEPRECATED, remove this and just serve the API at the root
        self.root.putChild(conf.settings['API_ADDRESS'], self._daemon)

        lbrynet_server = get_site_base(use_auth, self.root)

        try:
            self.server_port = reactor.listenTCP(
                conf.settings['api_port'], lbrynet_server, interface=conf.settings['api_host'])
        except error.CannotListenError:
            log.info('Daemon already running, exiting app')
            raise

        return defer.succeed(True)

    @defer.inlineCallbacks
    def start(self, use_auth):
        yield self._setup_server(use_auth)
        yield self._daemon.setup()

    def stop(self):
        if reactor.running:
            log.info("Stopping the reactor")
            reactor.fireSystemEvent("shutdown")
def start_server_and_listen(use_auth, analytics_manager, quiet):
    log_support.configure_console()
    logging.getLogger("lbrynet").setLevel(logging.CRITICAL)
    logging.getLogger("lbryum").setLevel(logging.CRITICAL)
    logging.getLogger("requests").setLevel(logging.CRITICAL)

    analytics_manager.send_server_startup()
    yield Daemon().start_listening()
예제 #9
0
    def _setup_server(self, use_auth):
        self.root = IndexResource()
        self._daemon = Daemon(self.analytics_manager)
        self.root.putChild("", self._daemon)
        # TODO: DEPRECATED, remove this and just serve the API at the root
        self.root.putChild(conf.settings['API_ADDRESS'], self._daemon)

        lbrynet_server = get_site_base(use_auth, self.root)
        lbrynet_server.requestFactory = DaemonRequest

        try:
            self.server_port = reactor.listenTCP(
                conf.settings['api_port'], lbrynet_server, interface=conf.settings['api_host'])
        except error.CannotListenError:
            log.info('Daemon already running, exiting app')
            raise

        return defer.succeed(True)
예제 #10
0
def get_test_daemon(data_rate=None, generous=True, with_fee=False):
    if data_rate is None:
        data_rate = conf.ADJUSTABLE_SETTINGS['data_rate'][1]

    rates = {
        'BTCLBC': {'spot': 3.0, 'ts': util.DEFAULT_ISO_TIME + 1},
        'USDBTC': {'spot': 2.0, 'ts': util.DEFAULT_ISO_TIME + 2}
    }
    daemon = LBRYDaemon(None)
    daemon.session = mock.Mock(spec=Session.Session)
    daemon.session.wallet = mock.Mock(spec=Wallet.LBRYumWallet)
    market_feeds = [BTCLBCFeed(), USDBTCFeed()]
    daemon.exchange_rate_manager = DummyExchangeRateManager(market_feeds, rates)
    base_prm = PaymentRateManager.BasePaymentRateManager(rate=data_rate)
    prm = PaymentRateManager.NegotiatedPaymentRateManager(base_prm, DummyBlobAvailabilityTracker(),
                                                          generous=generous)
    daemon.session.payment_rate_manager = prm

    metadata = {
        "author": "fake author",
        "language": "en",
        "content_type": "fake/format",
        "description": "fake description",
        "license": "fake license",
        "license_url": "fake license url",
        "nsfw": False,
        "sources": {
            "lbry_sd_hash": 'd2b8b6e907dde95245fe6d144d16c2fdd60c4e0c6463ec98'
                            'b85642d06d8e9414e8fcfdcb7cb13532ec5454fb8fe7f280'
        },
        "thumbnail": "fake thumbnail",
        "title": "fake title",
        "ver": "0.0.3"
    }
    if with_fee:
        metadata.update(
            {"fee": {"USD": {"address": "bQ6BGboPV2SpTMEP7wLNiAcnsZiH8ye6eA", "amount": 0.75}}})
    daemon._resolve_name = lambda _: defer.succeed(metadata)
    migrated = smart_decode(json.dumps(metadata))
    daemon.session.wallet.resolve = lambda *_: defer.succeed(
        {"test": {'claim': {'value': migrated.claim_dict}}})
    return daemon
예제 #11
0
class DaemonServer(object):
    def __init__(self, analytics_manager=None):
        self._api = None
        self.root = None
        self.server_port = None
        self.analytics_manager = analytics_manager

    def _setup_server(self, use_auth):
        ui_path = os.path.join(conf.settings.ensure_data_dir(), "lbry-ui",
                               "active")
        self.root = LBRYindex(ui_path)
        self._api = Daemon(self.root, self.analytics_manager)
        self.root.putChild("view", HostedEncryptedFile(self._api))
        self.root.putChild("upload", EncryptedFileUpload(self._api))
        self.root.putChild(conf.settings['API_ADDRESS'], self._api)

        lbrynet_server = server.Site(get_site_base(use_auth, self.root))
        lbrynet_server.requestFactory = DaemonRequest

        try:
            self.server_port = reactor.listenTCP(
                conf.settings['api_port'],
                lbrynet_server,
                interface=conf.settings['api_host'])
        except error.CannotListenError:
            log.info('Daemon already running, exiting app')
            raise

        return defer.succeed(True)

    @defer.inlineCallbacks
    def start(self, use_auth):
        yield self._setup_server(use_auth)
        yield self._api.setup()

    @defer.inlineCallbacks
    def stop(self):
        if self._api is not None:
            yield self._api._shutdown()
        if self.server_port is not None:
            yield self.server_port.stopListening()
예제 #12
0
    def _setup_server(self, use_auth):
        ui_path = os.path.join(conf.settings.ensure_data_dir(), "lbry-ui",
                               "active")
        self.root = LBRYindex(ui_path)
        self._api = Daemon(self.root, self.analytics_manager)
        self.root.putChild("view", HostedEncryptedFile(self._api))
        self.root.putChild("upload", EncryptedFileUpload(self._api))
        self.root.putChild(conf.settings['API_ADDRESS'], self._api)

        lbrynet_server = server.Site(get_site_base(use_auth, self.root))
        lbrynet_server.requestFactory = DaemonRequest

        try:
            self.server_port = reactor.listenTCP(
                conf.settings['api_port'],
                lbrynet_server,
                interface=conf.settings['api_host'])
        except error.CannotListenError:
            log.info('Daemon already running, exiting app')
            raise

        return defer.succeed(True)
class CLIIntegrationTest(unittest.TestCase):
    USE_AUTH = False

    @defer.inlineCallbacks
    def setUp(self):
        skip = [
            DATABASE_COMPONENT, BLOB_COMPONENT, HEADERS_COMPONENT,
            WALLET_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            STREAM_IDENTIFIER_COMPONENT, FILE_MANAGER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT,
            UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT,
            RATE_LIMITER_COMPONENT, PAYMENT_RATE_COMPONENT
        ]
        conf.initialize_settings(load_conf_file=False)
        conf.settings['api_port'] = 5299
        conf.settings['use_auth_http'] = self.USE_AUTH
        conf.settings['components_to_skip'] = skip
        conf.settings.initialize_post_conf_load()
        Daemon.component_attributes = {}
        self.daemon = Daemon(analytics_manager=FakeAnalytics())
        yield self.daemon.start_listening()

    def tearDown(self):
        return self.daemon._shutdown()
예제 #14
0
    def _setup_server(self, use_auth):
        self.root = IndexResource()
        self._daemon = Daemon(self.analytics_manager)
        self.root.putChild("", self._daemon)
        # TODO: DEPRECATED, remove this and just serve the API at the root
        self.root.putChild(conf.settings['API_ADDRESS'], self._daemon)

        lbrynet_server = get_site_base(use_auth, self.root)

        try:
            self.server_port = reactor.listenTCP(
                conf.settings['api_port'], lbrynet_server, interface=conf.settings['api_host'])
        except error.CannotListenError:
            log.info('Daemon already running, exiting app')
            raise

        return defer.succeed(True)
예제 #15
0
def get_test_daemon(data_rate=None, generous=True, with_fee=False):
    if data_rate is None:
        data_rate = conf.ADJUSTABLE_SETTINGS['data_rate'][1]

    rates = {
        'BTCLBC': {'spot': 3.0, 'ts': util.DEFAULT_ISO_TIME + 1},
        'USDBTC': {'spot': 2.0, 'ts': util.DEFAULT_ISO_TIME + 2}
    }
    component_manager = ComponentManager(
        skip_components=[DATABASE_COMPONENT, DHT_COMPONENT, WALLET_COMPONENT, UPNP_COMPONENT,
                         PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT, HASH_ANNOUNCER_COMPONENT,
                         STREAM_IDENTIFIER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, BLOB_COMPONENT,
                         HEADERS_COMPONENT, RATE_LIMITER_COMPONENT],
        file_manager=FakeFileManager
    )
    daemon = LBRYDaemon(component_manager=component_manager)
    daemon.payment_rate_manager = OnlyFreePaymentsManager()
    daemon.wallet_manager = mock.Mock(spec=LbryWalletManager)
    daemon.wallet_manager.wallet = mock.Mock(spec=Wallet)
    daemon.wallet_manager.wallet.use_encryption = False
    daemon.wallet_manager.network = FakeNetwork()
    daemon.storage = mock.Mock(spec=SQLiteStorage)
    market_feeds = [BTCLBCFeed(), USDBTCFeed()]
    daemon.exchange_rate_manager = DummyExchangeRateManager(market_feeds, rates)
    daemon.file_manager = component_manager.get_component(FILE_MANAGER_COMPONENT)

    metadata = {
        "author": "fake author",
        "language": "en",
        "content_type": "fake/format",
        "description": "fake description",
        "license": "fake license",
        "license_url": "fake license url",
        "nsfw": False,
        "sources": {
            "lbry_sd_hash": 'd2b8b6e907dde95245fe6d144d16c2fdd60c4e0c6463ec98'
                            'b85642d06d8e9414e8fcfdcb7cb13532ec5454fb8fe7f280'
        },
        "thumbnail": "fake thumbnail",
        "title": "fake title",
        "ver": "0.0.3"
    }
    if with_fee:
        metadata.update(
            {"fee": {"USD": {"address": "bQ6BGboPV2SpTMEP7wLNiAcnsZiH8ye6eA", "amount": 0.75}}})
    migrated = smart_decode(json.dumps(metadata))
    daemon._resolve = daemon.wallet_manager.resolve = lambda *_: defer.succeed(
        {"test": {'claim': {'value': migrated.claim_dict}}})
    return daemon
예제 #16
0
 def test_invalid_input(self):
     with self.assertRaises(ValueError):
         LBRYDaemon.get_dewies_or_error("", "1")
     with self.assertRaises(ValueError):
         LBRYDaemon.get_dewies_or_error("", "-1.0")
     with self.assertRaises(ValueError):
         LBRYDaemon.get_dewies_or_error("", "10000000000.0")
     with self.assertRaises(ValueError):
         LBRYDaemon.get_dewies_or_error("", "1.000000000")
     with self.assertRaises(ValueError):
         LBRYDaemon.get_dewies_or_error("", "-0")
     with self.assertRaises(ValueError):
         LBRYDaemon.get_dewies_or_error("", "1")
     with self.assertRaises(ValueError):
         LBRYDaemon.get_dewies_or_error("", ".1")
     with self.assertRaises(ValueError):
         LBRYDaemon.get_dewies_or_error("", "1e-7")
예제 #17
0
 def test_input(self):
     self.assertEqual(LBRYDaemon.get_dewies_or_error("", "1.0"), 100000000)
     self.assertEqual(LBRYDaemon.get_dewies_or_error("", "2.00000000"),
                      200000000)
     self.assertEqual(LBRYDaemon.get_dewies_or_error("", "2000000000.0"),
                      200000000000000000)
예제 #18
0
def start():
    """The primary entry point for launching the daemon."""

    # postpone loading the config file to after the CLI arguments
    # have been parsed, as they may contain an alternate config file location
    conf.initialize_settings(load_conf_file=False)

    parser = argparse.ArgumentParser(description="Launch lbrynet-daemon")
    parser.add_argument("--conf",
                        help="specify an alternative configuration file",
                        type=str,
                        default=None)
    parser.add_argument("--http-auth",
                        dest="useauth",
                        action="store_true",
                        default=conf.settings['use_auth_http'])
    parser.add_argument('--quiet',
                        dest='quiet',
                        action="store_true",
                        help='Disable all console output.')
    parser.add_argument(
        '--verbose',
        nargs="*",
        help=
        ('Enable debug output. Optionally specify loggers for which debug output '
         'should selectively be applied.'))
    parser.add_argument('--version',
                        action="store_true",
                        help='Show daemon version and quit')

    args = parser.parse_args()
    update_settings_from_args(args)

    conf.settings.load_conf_file_settings()

    if args.version:
        version = system_info.get_platform(get_ip=False)
        version['installation_id'] = conf.settings.installation_id
        print utils.json_dumps_pretty(version)
        return

    lbrynet_log = conf.settings.get_log_filename()
    log_support.configure_logging(lbrynet_log, not args.quiet, args.verbose)
    log_support.configure_loggly_handler()
    log.debug('Final Settings: %s', conf.settings.get_current_settings_dict())

    try:
        log.debug('Checking for an existing lbrynet daemon instance')
        JSONRPCProxy.from_url(
            conf.settings.get_api_connection_string()).status()
        log.info("lbrynet-daemon is already running")
        return
    except Exception:
        log.debug('No lbrynet instance found, continuing to start')

    log.info("Starting lbrynet-daemon from command line")

    if test_internet_connection():
        daemon = Daemon()
        daemon.start_listening()
        reactor.run()
    else:
        log.info("Not connected to internet, unable to start")
예제 #19
0
class CommandTestCase(IntegrationTestCase):

    timeout = 180
    WALLET_MANAGER = LbryWalletManager

    async def setUp(self):
        await super().setUp()

        if self.VERBOSE:
            log.setLevel(logging.DEBUG)
            logging.getLogger('lbrynet.core').setLevel(logging.DEBUG)

        lbry_conf.settings = None
        lbry_conf.initialize_settings(load_conf_file=False)
        lbry_conf.settings['data_dir'] = self.stack.wallet.data_path
        lbry_conf.settings['lbryum_wallet_dir'] = self.stack.wallet.data_path
        lbry_conf.settings['download_directory'] = self.stack.wallet.data_path
        lbry_conf.settings['use_upnp'] = False
        lbry_conf.settings['reflect_uploads'] = False
        lbry_conf.settings['blockchain_name'] = 'lbrycrd_regtest'
        lbry_conf.settings['lbryum_servers'] = [('localhost', 50001)]
        lbry_conf.settings['known_dht_nodes'] = []
        lbry_conf.settings.node_id = None

        await d2f(self.account.ensure_address_gap())
        address = (await d2f(
            self.account.receiving.get_addresses(limit=1,
                                                 only_usable=True)))[0]
        sendtxid = await self.blockchain.send_to_address(address, 10)
        await self.confirm_tx(sendtxid)
        await self.generate(5)

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.manager
            self.wallet_component._running = True
            return self.wallet_component

        skip = [
            #UPNP_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT,
            REFLECTOR_COMPONENT
        ]
        analytics_manager = FakeAnalytics()
        self.daemon = Daemon(
            analytics_manager,
            ComponentManager(analytics_manager=analytics_manager,
                             skip_components=skip,
                             wallet=wallet_maker,
                             dht=FakeDHT,
                             hash_announcer=FakeHashAnnouncerComponent,
                             exchange_rate_manager=FakeExchangeRateComponent,
                             upnp=FakeUPnP))
        await d2f(self.daemon.setup())
        self.daemon.wallet_manager = self.wallet_component.wallet_manager
        self.manager.old_db = self.daemon.storage

    async def tearDown(self):
        await super().tearDown()
        self.wallet_component._running = False
        await d2f(self.daemon._shutdown())

    async def confirm_tx(self, txid):
        """ Wait for tx to be in mempool, then generate a block, wait for tx to be in a block. """
        await self.on_transaction_id(txid)
        await self.generate(1)
        await self.on_transaction_id(txid)

    def d_confirm_tx(self, txid):
        return defer.Deferred.fromFuture(
            asyncio.ensure_future(self.confirm_tx(txid)))

    async def generate(self, blocks):
        """ Ask lbrycrd to generate some blocks and wait until ledger has them. """
        await self.blockchain.generate(blocks)
        await self.ledger.on_header.where(self.blockchain.is_expected_block)

    def d_generate(self, blocks):
        return defer.Deferred.fromFuture(
            asyncio.ensure_future(self.generate(blocks)))

    def out(self, d):
        """ Converts Daemon API call results (dictionary)
            to JSON and then back to a dictionary. """
        d.addCallback(lambda o: json.loads(
            jsonrpc_dumps_pretty(o, ledger=self.ledger))['result'])
        return d