Merge pull request #766 from lbryio/negative-send-to-address
raise error on negative point reservation
This commit is contained in:
commit
2e230828fd
4 changed files with 18 additions and 2 deletions
|
@ -18,7 +18,7 @@ at anytime.
|
|||
|
||||
### Fixed
|
||||
* Fixed timeout behaviour when calling API command get
|
||||
*
|
||||
* Fixed https://github.com/lbryio/lbry/issues/765
|
||||
|
||||
### Deprecated
|
||||
*
|
||||
|
|
|
@ -18,6 +18,14 @@ class RequestCanceledError(Exception):
|
|||
pass
|
||||
|
||||
|
||||
class NegativeFundsError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class NullFundsError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class InsufficientFundsError(Exception):
|
||||
pass
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue