Merge pull request #1137 from lbryio/new-channel-fix

Error cleanly when claiming a new channel with exact or higher amount than balance
This commit is contained in:
Lex Berezhny 2018-03-12 16:17:18 -04:00 committed by GitHub
commit 37bfed8aee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 7 deletions

View file

@ -16,6 +16,8 @@ at anytime.
* fixed the inconsistencies in API and CLI docstrings
* `blob_announce` error when announcing a single blob
* `blob_list` error when looking up blobs by stream or sd hash
* issue#1107 whereing claiming a channel with the exact amount present in wallet would give out proper error
*
### Deprecated
* `report_bug` jsonrpc command
@ -27,6 +29,7 @@ at anytime.
### Added
* scripts to autogenerate documentation
* now updating new channel also takes into consideration the original bid amount, so now channel could be updated for wallet balance + the original bid amount
*
### Removed

View file

@ -502,6 +502,10 @@ class Wallet(object):
raise Exception("New channel claim should have no fields other than name")
log.info("Preparing to make certificate claim for %s", channel_name)
channel_claim = yield self._claim_certificate(parsed_channel_name.name, amount)
if not channel_claim['success']:
msg = 'Claiming of channel {} failed: {}'.format(channel_name, channel_claim['reason'])
log.error(msg)
raise Exception(msg)
yield self.save_claim(self._get_temp_claim_info(channel_claim, channel_name, amount))
defer.returnValue(channel_claim)
@ -559,8 +563,8 @@ class Wallet(object):
bid, certificate_id, claim_address, change_address)
if not claim['success']:
log.error(claim)
msg = 'Claim to name {} failed: {}'.format(name, claim['reason'])
msg = 'Claiming of name {} failed: {}'.format(name, claim['reason'])
log.error(msg)
raise Exception(msg)
claim = self._process_claim_out(claim)
yield self.storage.save_claim(self._get_temp_claim_info(claim, name, bid), smart_decode(claim['value']))

View file

@ -1851,8 +1851,17 @@ class Daemon(AuthJSONRPCServer):
raise Exception("Invalid channel name")
if amount <= 0:
raise Exception("Invalid amount")
if amount > self.session.wallet.get_balance():
raise InsufficientFundsError()
balance = yield self.session.wallet.get_max_usable_balance_for_claim(channel_name)
max_bid_amount = balance - MAX_UPDATE_FEE_ESTIMATE
if balance <= MAX_UPDATE_FEE_ESTIMATE:
raise InsufficientFundsError(
"Insufficient funds, please deposit additional LBC. Minimum additional LBC needed {}"
.format(MAX_UPDATE_FEE_ESTIMATE - balance))
elif amount > max_bid_amount:
raise InsufficientFundsError(
"Please lower the bid value, the maximum amount you can specify for this claim is {}"
.format(max_bid_amount))
result = yield self.session.wallet.claim_new_channel(channel_name, amount)
self.analytics_manager.send_new_channel()
@ -2028,11 +2037,16 @@ class Daemon(AuthJSONRPCServer):
if bid <= 0.0:
raise ValueError("Bid value must be greater than 0.0")
amt = yield self.session.wallet.get_max_usable_balance_for_claim(name)
if bid > amt:
balance = yield self.session.wallet.get_max_usable_balance_for_claim(name)
max_bid_amount = balance - MAX_UPDATE_FEE_ESTIMATE
if balance <= MAX_UPDATE_FEE_ESTIMATE:
raise InsufficientFundsError(
"Insufficient funds, please deposit additional LBC. Minimum additional LBC needed {}"
.format(MAX_UPDATE_FEE_ESTIMATE - balance))
elif bid > max_bid_amount:
raise InsufficientFundsError(
"Please lower the bid value, the maximum amount you can specify for this claim is {}"
.format(amt - MAX_UPDATE_FEE_ESTIMATE))
.format(max_bid_amount))
metadata = metadata or {}
if fee is not None: