From 65bc93f2fe7655bb492079b2fa6c871e44609cfb Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Fri, 7 Jul 2017 16:37:35 -0400 Subject: [PATCH] raise error on negative point reservation --- CHANGELOG.md | 2 +- lbrynet/core/Error.py | 8 ++++++++ lbrynet/core/Wallet.py | 4 +++- lbrynet/daemon/Daemon.py | 6 ++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d49ca865b..6cd44ad89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ at anytime. ### Fixed * Fixed timeout behaviour when calling API command get - * + * Fixed https://github.com/lbryio/lbry/issues/765 ### Deprecated * diff --git a/lbrynet/core/Error.py b/lbrynet/core/Error.py index 67dde9dd4..c9a4f84d4 100644 --- a/lbrynet/core/Error.py +++ b/lbrynet/core/Error.py @@ -18,6 +18,14 @@ class RequestCanceledError(Exception): pass +class NegativeFundsError(Exception): + pass + + +class NullFundsError(Exception): + pass + + class InsufficientFundsError(Exception): pass diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 4bd5a6607..da82db58e 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -28,7 +28,7 @@ from lbrynet.core.sqlite_helpers import rerun_if_locked from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, IWallet from lbrynet.core.client.ClientRequest import ClientRequest 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__) @@ -541,6 +541,8 @@ class Wallet(object): once the service has been rendered """ rounded_amount = Decimal(str(round(amount, 8))) + if rounded_amount < 0: + raise NegativeFundsError(rounded_amount) if self.get_balance() >= rounded_amount: self.total_reserved_points += rounded_amount return ReservedPoints(identifier, rounded_amount) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 7c3ab8216..b5d713131 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -45,6 +45,7 @@ from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory from lbrynet.core.server.ServerProtocol import ServerProtocolFactory from lbrynet.core.Error import InsufficientFundsError, UnknownNameError, NoSuchSDHash from lbrynet.core.Error import NoSuchStreamHash, UnknownClaimID, UnknownURI +from lbrynet.core.Error import NullFundsError, NegativeFundsError log = logging.getLogger(__name__) @@ -2231,6 +2232,11 @@ class Daemon(AuthJSONRPCServer): (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) if reserved_points is None: raise InsufficientFundsError()