From 8c50f08fec5e5f86f839b1a0dc1d68df63591644 Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Fri, 5 Aug 2016 05:25:46 -0500 Subject: [PATCH] refactor _start_download --- lbrynet/lbrynet_daemon/LBRYDownloader.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lbrynet/lbrynet_daemon/LBRYDownloader.py b/lbrynet/lbrynet_daemon/LBRYDownloader.py index 62d9cd33d..323882eaf 100644 --- a/lbrynet/lbrynet_daemon/LBRYDownloader.py +++ b/lbrynet/lbrynet_daemon/LBRYDownloader.py @@ -150,21 +150,19 @@ class GetStream(object): return self.finished def _start_download(self, downloader): - def _pay_key_fee(): - if self.fee is not None: - fee_lbc = self.exchange_rate_manager.to_lbc(self.fee).amount - reserved_points = self.wallet.reserve_points(self.fee.address, fee_lbc) - if reserved_points is None: - return defer.fail(InsufficientFundsError()) - return self.wallet.send_points_to_address(reserved_points, fee_lbc) - - return defer.succeed(None) - - d = _pay_key_fee() - + log.info('Starting download for %s', self.name) self.downloader = downloader self.download_path = os.path.join(downloader.download_directory, downloader.file_name) + d = self._pay_key_fee() d.addCallback(lambda _: log.info("Downloading %s --> %s", self.stream_hash, self.downloader.file_name)) d.addCallback(lambda _: self.downloader.start()) + def _pay_key_fee(self): + if self.fee is not None: + fee_lbc = self.exchange_rate_manager.to_lbc(self.fee).amount + reserved_points = self.wallet.reserve_points(self.fee.address, fee_lbc) + if reserved_points is None: + return defer.fail(InsufficientFundsError()) + return self.wallet.send_points_to_address(reserved_points, fee_lbc) + return defer.succeed(None)