use get_dewies_or_error in jsonrpc_publish

This commit is contained in:
Lex Berezhny 2018-08-27 11:37:40 -04:00
parent 70e68c6361
commit eff66bdf80

View file

@ -2187,30 +2187,24 @@ class Daemon(AuthJSONRPCServer):
except (TypeError, URIParseError): except (TypeError, URIParseError):
raise Exception("Invalid name given to publish") raise Exception("Invalid name given to publish")
try: amount = self.get_dewies_or_error('bid', bid)
bid = Decimal(str(bid)) if amount <= 0:
except InvalidOperation:
raise TypeError("Bid does not represent a valid decimal.")
if bid <= 0.0:
raise ValueError("Bid value must be greater than 0.0") raise ValueError("Bid value must be greater than 0.0")
bid = int(bid * COIN)
for address in [claim_address, change_address]: for address in [claim_address, change_address]:
if address is not None: if address is not None:
# raises an error if the address is invalid # raises an error if the address is invalid
decode_address(address) decode_address(address)
available = yield self.default_account.get_balance() available = yield self.default_account.get_balance()
if bid >= available: if amount >= available:
# TODO: add check for existing claim balance # TODO: add check for existing claim balance
#balance = yield self.wallet.get_max_usable_balance_for_claim(name) #balance = yield self.wallet.get_max_usable_balance_for_claim(name)
#max_bid_amount = balance - MAX_UPDATE_FEE_ESTIMATE #max_bid_amount = balance - MAX_UPDATE_FEE_ESTIMATE
#if balance <= MAX_UPDATE_FEE_ESTIMATE: #if balance <= MAX_UPDATE_FEE_ESTIMATE:
raise InsufficientFundsError( raise InsufficientFundsError(
"Insufficient funds, please deposit additional LBC. Minimum additional LBC needed {}" "Insufficient funds, please deposit additional LBC. Minimum additional LBC needed {}"
.format(round((bid - available)/COIN + 0.01, 2)) .format(round((amount - available) / COIN + 0.01, 2))
) )
# .format(MAX_UPDATE_FEE_ESTIMATE - balance)) # .format(MAX_UPDATE_FEE_ESTIMATE - balance))
#elif bid > max_bid_amount: #elif bid > max_bid_amount:
@ -2298,7 +2292,7 @@ class Daemon(AuthJSONRPCServer):
log.info("Publish: %s", { log.info("Publish: %s", {
'name': name, 'name': name,
'file_path': file_path, 'file_path': file_path,
'bid': bid, 'bid': amount,
'claim_address': claim_address, 'claim_address': claim_address,
'change_address': change_address, 'change_address': change_address,
'claim_dict': claim_dict, 'claim_dict': claim_dict,
@ -2316,7 +2310,7 @@ class Daemon(AuthJSONRPCServer):
if certificate is None: if certificate is None:
raise Exception("Cannot publish using channel %s" % channel_name) raise Exception("Cannot publish using channel %s" % channel_name)
result = yield self._publish_stream(name, bid, claim_dict, file_path, certificate, result = yield self._publish_stream(name, amount, claim_dict, file_path, certificate,
claim_address, change_address) claim_address, change_address)
defer.returnValue(result) defer.returnValue(result)
@ -3303,9 +3297,7 @@ class Daemon(AuthJSONRPCServer):
return int(Decimal(amount) * COIN) return int(Decimal(amount) * COIN)
elif amount.isdigit(): elif amount.isdigit():
amount = int(amount) amount = int(amount)
if isinstance(amount, int): if isinstance(amount, (float, int)):
return amount * COIN
if isinstance(amount, float):
return int(amount * COIN) return int(amount * COIN)
raise ValueError("Invalid value for '{}' argument: {}".format(argument, amount)) raise ValueError("Invalid value for '{}' argument: {}".format(argument, amount))