mirror of
https://github.com/aljazceru/nutshell.git
synced 2026-01-30 05:54:19 +01:00
[FIX] Specs conformant error codes (#693)
* error codes must follow spec * make format
This commit is contained in:
@@ -18,6 +18,19 @@ class NotAllowedError(CashuError):
|
|||||||
def __init__(self, detail: Optional[str] = None, code: Optional[int] = None):
|
def __init__(self, detail: Optional[str] = None, code: Optional[int] = None):
|
||||||
super().__init__(detail or self.detail, code=code or self.code)
|
super().__init__(detail or self.detail, code=code or self.code)
|
||||||
|
|
||||||
|
class OutputsAlreadySignedError(CashuError):
|
||||||
|
detail = "outputs have already been signed before."
|
||||||
|
code = 10002
|
||||||
|
|
||||||
|
def __init__(self, detail: Optional[str] = None, code: Optional[int] = None):
|
||||||
|
super().__init__(detail or self.detail, code=code or self.code)
|
||||||
|
|
||||||
|
class InvalidProofsError(CashuError):
|
||||||
|
detail = "proofs could not be verified"
|
||||||
|
code = 10003
|
||||||
|
|
||||||
|
def __init__(self, detail: Optional[str] = None, code: Optional[int] = None):
|
||||||
|
super().__init__(detail or self.detail, code=code or self.code)
|
||||||
|
|
||||||
class TransactionError(CashuError):
|
class TransactionError(CashuError):
|
||||||
detail = "transaction error"
|
detail = "transaction error"
|
||||||
@@ -63,6 +76,11 @@ class TransactionUnitError(TransactionError):
|
|||||||
def __init__(self, detail):
|
def __init__(self, detail):
|
||||||
super().__init__(detail, code=self.code)
|
super().__init__(detail, code=self.code)
|
||||||
|
|
||||||
|
class TransactionAmountExceedsLimitError(TransactionError):
|
||||||
|
code = 11006
|
||||||
|
|
||||||
|
def __init__(self, detail):
|
||||||
|
super().__init__(detail, code=self.code)
|
||||||
|
|
||||||
class KeysetError(CashuError):
|
class KeysetError(CashuError):
|
||||||
detail = "keyset error"
|
detail = "keyset error"
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ from ..core.errors import (
|
|||||||
NotAllowedError,
|
NotAllowedError,
|
||||||
QuoteNotPaidError,
|
QuoteNotPaidError,
|
||||||
QuoteSignatureInvalidError,
|
QuoteSignatureInvalidError,
|
||||||
|
TransactionAmountExceedsLimitError,
|
||||||
TransactionError,
|
TransactionError,
|
||||||
)
|
)
|
||||||
from ..core.helpers import sum_proofs
|
from ..core.helpers import sum_proofs
|
||||||
@@ -403,7 +404,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions, LedgerTasks, LedgerFe
|
|||||||
if not quote_request.amount > 0:
|
if not quote_request.amount > 0:
|
||||||
raise TransactionError("amount must be positive")
|
raise TransactionError("amount must be positive")
|
||||||
if settings.mint_max_peg_in and quote_request.amount > settings.mint_max_peg_in:
|
if settings.mint_max_peg_in and quote_request.amount > settings.mint_max_peg_in:
|
||||||
raise NotAllowedError(
|
raise TransactionAmountExceedsLimitError(
|
||||||
f"Maximum mint amount is {settings.mint_max_peg_in} sat."
|
f"Maximum mint amount is {settings.mint_max_peg_in} sat."
|
||||||
)
|
)
|
||||||
if settings.mint_peg_out_only:
|
if settings.mint_peg_out_only:
|
||||||
|
|||||||
@@ -15,8 +15,10 @@ from ..core.crypto import b_dhke
|
|||||||
from ..core.crypto.secp import PublicKey
|
from ..core.crypto.secp import PublicKey
|
||||||
from ..core.db import Connection, Database
|
from ..core.db import Connection, Database
|
||||||
from ..core.errors import (
|
from ..core.errors import (
|
||||||
|
InvalidProofsError,
|
||||||
NoSecretInProofsError,
|
NoSecretInProofsError,
|
||||||
NotAllowedError,
|
NotAllowedError,
|
||||||
|
OutputsAlreadySignedError,
|
||||||
SecretTooLongError,
|
SecretTooLongError,
|
||||||
TransactionError,
|
TransactionError,
|
||||||
TransactionUnitError,
|
TransactionUnitError,
|
||||||
@@ -79,7 +81,7 @@ class LedgerVerification(
|
|||||||
raise TransactionError("duplicate proofs.")
|
raise TransactionError("duplicate proofs.")
|
||||||
# Verify ecash signatures
|
# Verify ecash signatures
|
||||||
if not all([self._verify_proof_bdhke(p) for p in proofs]):
|
if not all([self._verify_proof_bdhke(p) for p in proofs]):
|
||||||
raise TransactionError("could not verify proofs.")
|
raise InvalidProofsError()
|
||||||
# Verify input spending conditions
|
# Verify input spending conditions
|
||||||
if not all([self._verify_input_spending_conditions(p) for p in proofs]):
|
if not all([self._verify_input_spending_conditions(p) for p in proofs]):
|
||||||
raise TransactionError("validation of input spending conditions failed.")
|
raise TransactionError("validation of input spending conditions failed.")
|
||||||
@@ -141,7 +143,7 @@ class LedgerVerification(
|
|||||||
# verify that outputs have not been signed previously
|
# verify that outputs have not been signed previously
|
||||||
signed_before = await self._check_outputs_issued_before(outputs, conn)
|
signed_before = await self._check_outputs_issued_before(outputs, conn)
|
||||||
if any(signed_before):
|
if any(signed_before):
|
||||||
raise TransactionError("outputs have already been signed before.")
|
raise OutputsAlreadySignedError()
|
||||||
logger.trace(f"Verified {len(outputs)} outputs.")
|
logger.trace(f"Verified {len(outputs)} outputs.")
|
||||||
|
|
||||||
async def _check_outputs_issued_before(
|
async def _check_outputs_issued_before(
|
||||||
|
|||||||
Reference in New Issue
Block a user