From 6d4af4ba90c7ffec4c0514b3dc90a59daa714fe2 Mon Sep 17 00:00:00 2001 From: hackrush Date: Wed, 7 Mar 2018 17:05:04 +0530 Subject: [PATCH 1/3] Error cleanly when claiming a new channel with exact or higher amount than balance fixes #1107 --- CHANGELOG.md | 3 +++ lbrynet/core/Wallet.py | 4 ++++ lbrynet/daemon/Daemon.py | 8 ++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8db7731d8..d8e1b2f8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index d2fc3c94e..9a9b183f1 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -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) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 516264633..99e0c8efd 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -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() From f5aadf391877a9d6acf0019c46c84333abf6d59c Mon Sep 17 00:00:00 2001 From: hackrush Date: Wed, 7 Mar 2018 21:51:11 +0530 Subject: [PATCH 2/3] Sanitized logged error for channel and name claims --- lbrynet/core/Wallet.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 9a9b183f1..0eb25f318 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -503,8 +503,8 @@ class Wallet(object): 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']) + msg = 'Claiming of {} 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) @@ -563,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'])) From 16f2a5429b3cdb2403a0c6c0a2f45c9f0ad19985 Mon Sep 17 00:00:00 2001 From: hackrush Date: Fri, 9 Mar 2018 20:36:00 +0530 Subject: [PATCH 3/3] Name and output message fix. --- lbrynet/core/Wallet.py | 2 +- lbrynet/daemon/Daemon.py | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 0eb25f318..f739a5849 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -503,7 +503,7 @@ class Wallet(object): 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 {} failed: {}'.format(channel_name, channel_claim['reason']) + 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)) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 99e0c8efd..12935af24 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -1852,11 +1852,16 @@ class Daemon(AuthJSONRPCServer): if amount <= 0: raise Exception("Invalid amount") - amt = yield self.session.wallet.get_max_usable_balance_for_claim(channel_name) - if amount > amt: + 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(amt - MAX_UPDATE_FEE_ESTIMATE)) + .format(max_bid_amount)) result = yield self.session.wallet.claim_new_channel(channel_name, amount) self.analytics_manager.send_new_channel() @@ -2032,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: