fix key fee payment problem

This commit is contained in:
Jack 2016-07-25 23:41:26 -04:00
parent 102436274f
commit 7e5af11c2d
2 changed files with 18 additions and 26 deletions

View file

@ -73,10 +73,10 @@ class LBRYFee(object):
return float(btc) / self._USDBTC['spot'] return float(btc) / self._USDBTC['spot']
def _btc_to_lbc(self, btc): def _btc_to_lbc(self, btc):
return float(btc) / self._BTCLBC['spot'] / (1.0 - BITTREX_FEE) return float(btc) * self._BTCLBC['spot'] / (1.0 - BITTREX_FEE)
def _lbc_to_btc(self, lbc): def _lbc_to_btc(self, lbc):
return self._BTCLBC['spot'] * float(lbc) return self._BTCLBC['spot'] / float(lbc)
class LBRYFeeFormat(dict): class LBRYFeeFormat(dict):

View file

@ -91,9 +91,15 @@ class GetStream(object):
if 'fee' in self.metadata: if 'fee' in self.metadata:
self.fee = LBRYFee(self.metadata['fee'], {'USDBTC': self.wallet._USDBTC, 'BTCLBC': self.wallet._BTCLBC}) self.fee = LBRYFee(self.metadata['fee'], {'USDBTC': self.wallet._USDBTC, 'BTCLBC': self.wallet._BTCLBC})
if isinstance(self.max_key_fee, float):
if self.fee.to_lbc() > self.max_key_fee: if self.fee.to_lbc() > self.max_key_fee:
log.info("Key fee %f above limit of %f didn't download lbry://%s" % (self.fee.to_lbc(), self.max_key_fee, self.resolved_name)) log.info("Key fee %f above limit of %f didn't download lbry://%s" % (self.fee.to_lbc(), self.max_key_fee, self.resolved_name))
return defer.fail(None) return defer.fail(KeyFeeAboveMaxAllowed())
elif isinstance(self.max_key_fee, dict):
max_key = LBRYFee(self.max_key_fee, {'USDBTC': self.wallet._USDBTC, 'BTCLBC': self.wallet._BTCLBC})
if self.fee.to_lbc() > max_key.to_lbc():
log.info("Key fee %f above limit of %f didn't download lbry://%s" % (self.fee.to_lbc(), max_key.to_lbc(), self.resolved_name))
return defer.fail(KeyFeeAboveMaxAllowed())
def _cause_timeout(): def _cause_timeout():
self.timeout_counter = self.timeout * 2 self.timeout_counter = self.timeout * 2
@ -124,27 +130,13 @@ class GetStream(object):
def _start_download(self, downloader): def _start_download(self, downloader):
def _pay_key_fee(): def _pay_key_fee():
if self.fee is not None: if self.fee is not None:
if isinstance(self.max_key_fee, int):
fee_lbc = self.fee.to_lbc() fee_lbc = self.fee.to_lbc()
if fee_lbc > self.max_key_fee:
return defer.fail(KeyFeeAboveMaxAllowed())
reserved_points = self.wallet.reserve_points(self.fee.address, fee_lbc) reserved_points = self.wallet.reserve_points(self.fee.address, fee_lbc)
if reserved_points is None: if reserved_points is None:
return defer.fail(InsufficientFundsError()) return defer.fail(InsufficientFundsError())
log.info("Key fee: %f --> %s" % (fee_lbc, self.fee.address)) log.info("Key fee: %f --> %s" % (fee_lbc, self.fee.address))
return self.wallet.send_points_to_address(reserved_points, self.fee.address) d = self.wallet.send_points_to_address(reserved_points, self.fee.address)
else: return d
assert "USD" in self.max_key_fee
max_fee = LBRYFee(self.max_key_fee, {'USDBTC': self.wallet._USDBTC, 'BTCLBC': self.wallet._BTCLBC})
fee_lbc = self.fee.to_lbc()
if fee_lbc > max_fee.to_lbc():
return defer.fail(KeyFeeAboveMaxAllowed())
reserved_points = self.wallet.reserve_points(self.fee.address, fee_lbc)
if reserved_points is None:
return defer.fail(InsufficientFundsError())
log.info("Key fee: %f --> %s" % (fee_lbc, self.fee.address))
return self.wallet.send_points_to_address(reserved_points, self.fee.address)
return defer.succeed(None) return defer.succeed(None)