Esempio n. 1
0
def download_it(peer, timeout, blob_hash):
    tmp_dir = yield threads.deferToThread(tempfile.mkdtemp)
    storage = SQLiteStorage(tmp_dir, reactor)
    yield storage.setup()
    tmp_blob_manager = DiskBlobManager(tmp_dir, storage)

    config = {'auto_connect': True}
    config['lbryum_wallet_dir'] = tempfile.mkdtemp()
    config['use_keyring'] = False
    config['blockchain_name'] = conf.settings['blockchain_name']
    config['lbryum_servers'] = []
    wallet = yield f2d(LbryWalletManager.from_lbrynet_config(config, storage))

    downloader = SinglePeerDownloader()
    downloader.setup(wallet)

    try:
        blob_downloaded = yield downloader.download_blob_from_peer(peer, timeout, blob_hash,
                                                                   tmp_blob_manager)
        if blob_downloaded:
            log.info("SUCCESS!")
            blob = yield tmp_blob_manager.get_blob(blob_hash)
            pprint(blob)
            if not blob.verified:
                log.error("except that its not verified....")
            else:
                reader = BlobStreamDescriptorReader(blob)
                info = None
                for x in range(0, 3):
                    try:
                        info = yield reader.get_info()
                    except ValueError:
                        pass
                    if info:
                        break

                    # there's some kind of race condition where it sometimes doesn't write the blob to disk in time
                    time.sleep(0.1)

                if info is not None:
                    pprint(info)
                    for content_blob in info['blobs']:
                        if 'blob_hash' in content_blob:
                            yield download_it(peer, timeout, content_blob['blob_hash'])
        else:
            log.error("Download failed")
    finally:
        yield tmp_blob_manager.stop()
        yield threads.deferToThread(shutil.rmtree, tmp_dir)

    defer.returnValue(True)
Esempio n. 2
0
 def check_fee_and_convert(self, fee):
     max_key_fee_amount = self.convert_max_fee()
     converted_fee_amount = self.exchange_rate_manager.convert_currency(
         fee.currency, "LBC", fee.amount)
     if converted_fee_amount > (yield f2d(
             self.wallet.default_account.get_balance())):
         raise InsufficientFundsError('Unable to pay the key fee of %s' %
                                      converted_fee_amount)
     if converted_fee_amount > max_key_fee_amount and not self.disable_max_key_fee:
         raise KeyFeeAboveMaxAllowed(
             'Key fee {} above max allowed {}'.format(
                 converted_fee_amount, max_key_fee_amount))
     converted_fee = {
         'currency': 'LBC',
         'amount': converted_fee_amount,
         'address': fee.address
     }
     return Fee(converted_fee)
Esempio n. 3
0
 def test_fee_and_generous_data(self):
     size = 10000000
     correct_result = 4.5
     daemon = get_test_daemon(generous=True, with_fee=True)
     result = yield f2d(daemon.get_est_cost("test", size))
     self.assertEqual(result, correct_result)
Esempio n. 4
0
 def test_generous_data_and_no_fee(self):
     size = 10000000
     correct_result = 0.0
     daemon = get_test_daemon(generous=True)
     result = yield f2d(daemon.get_est_cost("test", size))
     self.assertEqual(result, correct_result)