Check for max usable balance before updating

This commit is contained in:
hackrush 2018-02-14 23:31:57 +05:30
parent d72ef784ed
commit 2368433b22
3 changed files with 17 additions and 0 deletions

View file

@ -537,6 +537,10 @@ class Wallet(object):
decoded = ClaimDict.load_dict(metadata) decoded = ClaimDict.load_dict(metadata)
serialized = decoded.serialized 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'), claim = yield self._send_name_claim(name, serialized.encode('hex'),
bid, certificate_id, claim_address, change_address) bid, certificate_id, claim_address, change_address)
@ -972,6 +976,11 @@ class LBRYumWallet(Wallet):
lambda result: Decimal(result['confirmed']) + Decimal(result.get('unconfirmed', 0.0))) lambda result: Decimal(result['confirmed']) + Decimal(result.get('unconfirmed', 0.0)))
return d 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 # Always create and return a brand new address
def get_new_address(self, for_change=False, account=None): def get_new_address(self, for_change=False, account=None):
return defer.succeed(self.wallet.create_new_address(account=account, return defer.succeed(self.wallet.create_new_address(account=account,

View file

@ -2005,6 +2005,12 @@ class Daemon(AuthJSONRPCServer):
if bid <= 0.0: if bid <= 0.0:
raise ValueError("Bid value must be greater than 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:
raise InsufficientFundsError(
"Please lower the bid value, the max amount you can specify for this claim is {}"
.format(amt))
metadata = metadata or {} metadata = metadata or {}
if fee is not None: if fee is not None:
metadata['fee'] = fee metadata['fee'] = fee

View file

@ -73,6 +73,8 @@ class MocLbryumWallet(LBRYumWallet):
def _save_name_metadata(self, name, claim_outpoint, sd_hash): def _save_name_metadata(self, name, claim_outpoint, sd_hash):
return defer.succeed(True) return defer.succeed(True)
def get_max_usable_balance_for_claim(self, name):
return defer.succeed(3)
class WalletTest(unittest.TestCase): class WalletTest(unittest.TestCase):
@defer.inlineCallbacks @defer.inlineCallbacks