From a39471317198df60b6669d90d3ac674d221f8690 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Sun, 8 Sep 2019 23:23:14 -0300 Subject: [PATCH] wip --- lbry/lbry/extras/daemon/json_response_encoder.py | 1 + lbry/lbry/stream/managed_stream.py | 9 ++++++--- lbry/lbry/stream/stream_manager.py | 5 +++++ lbry/lbry/wallet/manager.py | 4 +++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lbry/lbry/extras/daemon/json_response_encoder.py b/lbry/lbry/extras/daemon/json_response_encoder.py index 3283b1fb7..69dd19545 100644 --- a/lbry/lbry/extras/daemon/json_response_encoder.py +++ b/lbry/lbry/extras/daemon/json_response_encoder.py @@ -227,6 +227,7 @@ class JSONResponseEncoder(JSONEncoder): 'file_name': managed_stream.file_name if output_exists else None, 'download_directory': managed_stream.download_directory if output_exists else None, 'download_path': managed_stream.full_path if output_exists else None, + 'claim_output': managed_stream.claim_output, 'points_paid': 0.0, 'stopped': not managed_stream.running, 'stream_hash': managed_stream.stream_hash, diff --git a/lbry/lbry/stream/managed_stream.py b/lbry/lbry/stream/managed_stream.py index a3ad25794..b20485ab8 100644 --- a/lbry/lbry/stream/managed_stream.py +++ b/lbry/lbry/stream/managed_stream.py @@ -18,7 +18,7 @@ if typing.TYPE_CHECKING: from lbry.blob.blob_info import BlobInfo from lbry.dht.node import Node from lbry.extras.daemon.analytics import AnalyticsManager - from lbry.wallet.transaction import Transaction + from lbry.wallet.transaction import Transaction, Output log = logging.getLogger(__name__) @@ -68,7 +68,8 @@ class ManagedStream: 'saving', 'finished_writing', 'started_writing', - 'finished_write_attempt' + 'finished_write_attempt', + 'claim_output' ] def __init__(self, loop: asyncio.AbstractEventLoop, config: 'Config', blob_manager: 'BlobManager', @@ -77,7 +78,8 @@ class ManagedStream: download_id: typing.Optional[str] = None, rowid: typing.Optional[int] = None, descriptor: typing.Optional[StreamDescriptor] = None, content_fee: typing.Optional['Transaction'] = None, - analytics_manager: typing.Optional['AnalyticsManager'] = None): + analytics_manager: typing.Optional['AnalyticsManager'] = None, + output: typing.Optional['Output'] = None): self.loop = loop self.config = config self.blob_manager = blob_manager @@ -91,6 +93,7 @@ class ManagedStream: self.content_fee = content_fee self.downloader = StreamDownloader(self.loop, self.config, self.blob_manager, sd_hash, descriptor) self.analytics_manager = analytics_manager + self.claim_output = output self.fully_reflected = asyncio.Event(loop=self.loop) self.file_output_task: typing.Optional[asyncio.Task] = None diff --git a/lbry/lbry/stream/stream_manager.py b/lbry/lbry/stream/stream_manager.py index f15d8ee82..7a73d651a 100644 --- a/lbry/lbry/stream/stream_manager.py +++ b/lbry/lbry/stream/stream_manager.py @@ -1,5 +1,6 @@ import os import asyncio +import time import typing import binascii import logging @@ -126,12 +127,15 @@ class StreamManager: claim, content_fee=content_fee, rowid=rowid, descriptor=descriptor, analytics_manager=self.analytics_manager ) + tx = await self.wallet.get_transaction(claim.txid, save_missing=True) + stream.claim_output = tx.outputs[claim.nout] self.streams[sd_hash] = stream self.storage.content_claim_callbacks[stream.stream_hash] = lambda: self._update_content_claim(stream) async def load_and_resume_streams_from_database(self): to_recover = [] to_start = [] + start = time.time() await self.storage.update_manually_removed_files_since_last_run() @@ -161,6 +165,7 @@ class StreamManager: if add_stream_tasks: await asyncio.gather(*add_stream_tasks, loop=self.loop) log.info("Started stream manager with %i files", len(self.streams)) + log.info("took %s seconds", time.time() - start) if not self.node: log.warning("no DHT node given, resuming downloads trusting that we can contact reflector") if to_resume_saving: diff --git a/lbry/lbry/wallet/manager.py b/lbry/lbry/wallet/manager.py index 6740edad6..d8d0c1cc6 100644 --- a/lbry/lbry/wallet/manager.py +++ b/lbry/lbry/wallet/manager.py @@ -194,7 +194,7 @@ class LbryWalletManager(BaseWalletManager): await account.ledger.broadcast(tx) return tx - async def get_transaction(self, txid): + async def get_transaction(self, txid, save_missing=False): tx = await self.db.get_transaction(txid=txid) if not tx: try: @@ -206,6 +206,8 @@ class LbryWalletManager(BaseWalletManager): return {'success': False, 'code': e.code, 'message': e.message} tx = self.ledger.transaction_class(unhexlify(raw)) await self.ledger.maybe_verify_transaction(tx, height) + if save_missing: + await self.db.insert_transaction(tx) return tx def save(self):