From dc2ccc4fe89f9712ca01ce957155a0bba6807b4b Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 17 Sep 2021 01:06:18 -0300 Subject: [PATCH] error for already purchased claims --- lbry/error/README.md | 1 + lbry/error/__init__.py | 10 ++++++++++ lbry/extras/daemon/daemon.py | 8 ++------ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lbry/error/README.md b/lbry/error/README.md index 8df583b36..5de36d3e5 100644 --- a/lbry/error/README.md +++ b/lbry/error/README.md @@ -59,6 +59,7 @@ Code | Name | Message 421 | InvalidPassword | Password is invalid. 422 | IncompatibleWalletServer | '{server}:{port}' has an incompatibly old version. 423 | TooManyClaimSearchParameters | {key} cant have more than {limit} items. +424 | AlreadyPurchased | You already have a purchase for claim_id '{claim_id}'. Use --allow-duplicate-purchase flag to override. 431 | ServerPaymentInvalidAddress | Invalid address from wallet server: '{address}' - skipping payment round. 432 | ServerPaymentWalletLocked | Cannot spend funds with locked wallet, skipping payment round. 433 | ServerPaymentFeeAboveMaxAllowed | Daily server fee of {daily_fee} exceeds maximum configured of {max_fee} LBC. diff --git a/lbry/error/__init__.py b/lbry/error/__init__.py index 72019868d..944b22c65 100644 --- a/lbry/error/__init__.py +++ b/lbry/error/__init__.py @@ -258,6 +258,16 @@ class TooManyClaimSearchParametersError(WalletError): super().__init__(f"{key} cant have more than {limit} items.") +class AlreadyPurchasedError(WalletError): + """ + allow-duplicate-purchase flag to override. + """ + + def __init__(self, claim_id): + self.claim_id = claim_id + super().__init__(f"You already have a purchase for claim_id '{claim_id}'. Use") + + class ServerPaymentInvalidAddressError(WalletError): def __init__(self, address): diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index 62cf93b76..f6a349f09 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -38,7 +38,7 @@ from lbry.dht.peer import make_kademlia_peer from lbry.error import ( DownloadSDTimeoutError, ComponentsNotStartedError, ComponentStartConditionNotMetError, CommandDoesNotExistError, BaseError, WalletNotFoundError, WalletAlreadyLoadedError, WalletAlreadyExistsError, - ConflictingInputValueError + ConflictingInputValueError, AlreadyPurchasedError ) from lbry.extras import system_info from lbry.extras.daemon import analytics @@ -2295,11 +2295,7 @@ class Daemon(metaclass=JSONRPCServerType): # TODO: use error from lbry.error raise Exception("Missing argument claim_id or url.") if not allow_duplicate_purchase and txo.purchase_receipt: - # TODO: use error from lbry.error - raise Exception( - f"You already have a purchase for claim_id '{claim_id}'. " - f"Use --allow-duplicate-purchase flag to override." - ) + raise AlreadyPurchasedError(claim_id) claim = txo.claim if not claim.is_stream or not claim.stream.has_fee: # TODO: use error from lbry.error