Skip to content

Commit

Permalink
Check for max usable balance before updating
Browse files Browse the repository at this point in the history
  • Loading branch information
hackrush01 committed Feb 14, 2018
1 parent 41543a9 commit a50d6a1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
10 changes: 0 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ at anytime.
* `blob_list` failing with --uri parameter (https://github.com/lbryio/lbry/issues/895)
* `get` failing with a non-useful error message when given a uri for a channel claim
* exception checking in several wallet unit tests
* Fixed unnecessarily verbose exchange rate error (https://github.com/lbryio/lbry/issues/984)
* Merged two separate dht test folders into one
* Fixed value error due to a race condition when saving to the claim cache (https://github.com/lbryio/lbry/issues/1013)
* Fixed being unable to re-download updated content (#951)
* Fixed sending error messages for failed api requests
* Fixed the file manager startup being slow when handling thousands of files
* Fixed handling decryption error for blobs encrypted with an invalid key
* Fixed handling stream with no data blob (https://github.com/lbryio/lbry/issues/905)
* Fixed fetching the external ip
* Fixed API call to blob_list with --uri parameter (https://github.com/lbryio/lbry/issues/895)
* Fixed publish command to allow updating claims with bid amount higher than wallet balance(by spending the claimtrietx coin) (https://github.com/lbryio/lbry/issues/748)

### Deprecated
Expand Down
9 changes: 9 additions & 0 deletions lbrynet/core/Wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,10 @@ def claim_name(self, name, bid, metadata, certificate_id=None, claim_address=Non
decoded = ClaimDict.load_dict(metadata)
serialized = decoded.serialized

amt = yield self.get_max_usable_balance_for_claim(name)
if bid > amt:
raise InsufficientFundsError()

claim = yield self._send_name_claim(name, serialized.encode('hex'),
bid, certificate_id, claim_address, change_address)

Expand Down Expand Up @@ -972,6 +976,11 @@ def _update_balance(self):
lambda result: Decimal(result['confirmed']) + Decimal(result.get('unconfirmed', 0.0)))
return d

@defer.inlineCallbacks
def get_max_usable_balance_for_claim(self, claim_name):
amt = yield self._run_cmd_as_defer_to_thread('get_max_spendable_amt_for_claim', claim_name)
defer.returnValue(amt)

# Always create and return a brand new address
def get_new_address(self, for_change=False, account=None):
return defer.succeed(self.wallet.create_new_address(account=account,
Expand Down
6 changes: 6 additions & 0 deletions lbrynet/daemon/Daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,12 @@ def jsonrpc_publish(self, name, bid, metadata=None, file_path=None, fee=None, ti
if bid <= 0.0:
raise Exception("Invalid bid")

amt = yield self.session.wallet.get_max_usable_balance_for_claim(name)
if bid > amt:
raise InsufficientFundsError(
"Please lower the bid value, the max amount you can specify for this claim is {}"
.format(amt))

metadata = metadata or {}
if fee is not None:
metadata['fee'] = fee
Expand Down
2 changes: 2 additions & 0 deletions lbrynet/tests/unit/core/test_Wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def get_name_claims(self):
def _save_name_metadata(self, name, claim_outpoint, sd_hash):
return defer.succeed(True)

def get_max_usable_balance_for_claim(self, name):
return defer.succeed(3)

class WalletTest(unittest.TestCase):
@defer.inlineCallbacks
Expand Down

0 comments on commit a50d6a1

Please sign in to comment.