Error cleanly when claiming a new channel with exact or higher amount than balance

fixes #1107
This commit is contained in:
hackrush 2018-03-07 17:05:04 +05:30
parent 96e30984c1
commit 6d4af4ba90
3 changed files with 13 additions and 2 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']:
log.error(channel_claim)
msg = 'Claim to name {} failed: {}'.format(channel_name, channel_claim['reason'])
raise Exception(msg)
yield self.save_claim(self._get_temp_claim_info(channel_claim, channel_name, amount))
defer.returnValue(channel_claim)

View file

@ -1851,8 +1851,12 @@ class Daemon(AuthJSONRPCServer):
raise Exception("Invalid channel name")
if amount <= 0:
raise Exception("Invalid amount")
if amount > self.session.wallet.get_balance():
raise InsufficientFundsError()
amt = yield self.session.wallet.get_max_usable_balance_for_claim(channel_name)
if amount > amt:
raise InsufficientFundsError(
"Please lower the bid value, the maximum amount you can specify for this claim is {}"
.format(amt - MAX_UPDATE_FEE_ESTIMATE))
result = yield self.session.wallet.claim_new_channel(channel_name, amount)
self.analytics_manager.send_new_channel()