raise error on negative point reservation

This commit is contained in:
Jack Robison 2017-07-07 16:37:35 -04:00
parent cd98367039
commit 65bc93f2fe
4 changed files with 18 additions and 2 deletions

View file

@ -18,7 +18,7 @@ at anytime.
### Fixed ### Fixed
* Fixed timeout behaviour when calling API command get * Fixed timeout behaviour when calling API command get
* * Fixed https://github.com/lbryio/lbry/issues/765
### Deprecated ### Deprecated
* *

View file

@ -18,6 +18,14 @@ class RequestCanceledError(Exception):
pass pass
class NegativeFundsError(Exception):
pass
class NullFundsError(Exception):
pass
class InsufficientFundsError(Exception): class InsufficientFundsError(Exception):
pass pass

View file

@ -28,7 +28,7 @@ from lbrynet.core.sqlite_helpers import rerun_if_locked
from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, IWallet from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, IWallet
from lbrynet.core.client.ClientRequest import ClientRequest from lbrynet.core.client.ClientRequest import ClientRequest
from lbrynet.core.Error import RequestCanceledError, InsufficientFundsError, UnknownNameError from lbrynet.core.Error import RequestCanceledError, InsufficientFundsError, UnknownNameError
from lbrynet.core.Error import UnknownClaimID, UnknownURI from lbrynet.core.Error import UnknownClaimID, UnknownURI, NegativeFundsError
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -541,6 +541,8 @@ class Wallet(object):
once the service has been rendered once the service has been rendered
""" """
rounded_amount = Decimal(str(round(amount, 8))) rounded_amount = Decimal(str(round(amount, 8)))
if rounded_amount < 0:
raise NegativeFundsError(rounded_amount)
if self.get_balance() >= rounded_amount: if self.get_balance() >= rounded_amount:
self.total_reserved_points += rounded_amount self.total_reserved_points += rounded_amount
return ReservedPoints(identifier, rounded_amount) return ReservedPoints(identifier, rounded_amount)

View file

@ -45,6 +45,7 @@ from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
from lbrynet.core.Error import InsufficientFundsError, UnknownNameError, NoSuchSDHash from lbrynet.core.Error import InsufficientFundsError, UnknownNameError, NoSuchSDHash
from lbrynet.core.Error import NoSuchStreamHash, UnknownClaimID, UnknownURI from lbrynet.core.Error import NoSuchStreamHash, UnknownClaimID, UnknownURI
from lbrynet.core.Error import NullFundsError, NegativeFundsError
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -2231,6 +2232,11 @@ class Daemon(AuthJSONRPCServer):
(bool) true if payment successfully scheduled (bool) true if payment successfully scheduled
""" """
if amount < 0:
raise NegativeFundsError()
elif not amount:
raise NullFundsError()
reserved_points = self.session.wallet.reserve_points(address, amount) reserved_points = self.session.wallet.reserve_points(address, amount)
if reserved_points is None: if reserved_points is None:
raise InsufficientFundsError() raise InsufficientFundsError()