mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-22 03:24:18 +01:00
Update Error Codes (#702)
* add new error codes * use the new errors in the code * fix unsorted import * fix test wallet
This commit is contained in:
@@ -87,6 +87,38 @@ class TransactionAmountExceedsLimitError(TransactionError):
|
||||
super().__init__(detail, code=self.code)
|
||||
|
||||
|
||||
class TransactionDuplicateInputsError(TransactionError):
|
||||
detail = "Duplicate inputs provided"
|
||||
code = 11007
|
||||
|
||||
def __init__(self, detail: Optional[str] = None):
|
||||
super().__init__(detail, code=self.code)
|
||||
|
||||
|
||||
class TransactionDuplicateOutputsError(TransactionError):
|
||||
detail = "Duplicate outputs provided"
|
||||
code = 11008
|
||||
|
||||
def __init__(self, detail: Optional[str] = None):
|
||||
super().__init__(detail, code=self.code)
|
||||
|
||||
|
||||
class TransactionMultipleUnitsError(TransactionError):
|
||||
detail = "Inputs/Outputs of multiple units"
|
||||
code = 11009
|
||||
|
||||
def __init__(self, detail: Optional[str] = None):
|
||||
super().__init__(detail, code=self.code)
|
||||
|
||||
|
||||
class TransactionUnitMismatchError(TransactionError):
|
||||
detail = "Inputs and outputs not of same unit"
|
||||
code = 11010
|
||||
|
||||
def __init__(self, detail: Optional[str] = None):
|
||||
super().__init__(detail, code=self.code)
|
||||
|
||||
|
||||
class KeysetError(CashuError):
|
||||
detail = "keyset error"
|
||||
code = 12000
|
||||
|
||||
@@ -19,8 +19,12 @@ from ..core.errors import (
|
||||
NotAllowedError,
|
||||
OutputsAlreadySignedError,
|
||||
SecretTooLongError,
|
||||
TransactionDuplicateInputsError,
|
||||
TransactionDuplicateOutputsError,
|
||||
TransactionError,
|
||||
TransactionMultipleUnitsError,
|
||||
TransactionUnitError,
|
||||
TransactionUnitMismatchError,
|
||||
)
|
||||
from ..core.nuts import nut20
|
||||
from ..core.settings import settings
|
||||
@@ -67,7 +71,7 @@ class LedgerVerification(
|
||||
raise TransactionError("secrets do not match criteria.")
|
||||
# verify that only unique proofs were used
|
||||
if not self._verify_no_duplicate_proofs(proofs):
|
||||
raise TransactionError("duplicate proofs.")
|
||||
raise TransactionDuplicateInputsError()
|
||||
# Verify ecash signatures
|
||||
if not all([self._verify_proof_bdhke(p) for p in proofs]):
|
||||
raise InvalidProofsError()
|
||||
@@ -128,7 +132,7 @@ class LedgerVerification(
|
||||
raise TransactionError("invalid amount.")
|
||||
# verify that only unique outputs were used
|
||||
if not self._verify_no_duplicate_outputs(outputs):
|
||||
raise TransactionError("duplicate outputs.")
|
||||
raise TransactionDuplicateOutputsError()
|
||||
# verify that outputs have not been signed previously
|
||||
signed_before = await self._check_outputs_issued_before(outputs, conn)
|
||||
if any(signed_before):
|
||||
@@ -219,11 +223,11 @@ class LedgerVerification(
|
||||
units_proofs = [self.keysets[p.id].unit for p in proofs]
|
||||
units_outputs = [self.keysets[o.id].unit for o in outs if o.id]
|
||||
if not len(set(units_proofs)) == 1:
|
||||
raise TransactionUnitError("inputs have different units.")
|
||||
raise TransactionMultipleUnitsError("inputs have different units.")
|
||||
if not len(set(units_outputs)) == 1:
|
||||
raise TransactionUnitError("outputs have different units.")
|
||||
raise TransactionMultipleUnitsError("outputs have different units.")
|
||||
if not units_proofs[0] == units_outputs[0]:
|
||||
raise TransactionUnitError("input and output keysets have different units.")
|
||||
raise TransactionUnitMismatchError()
|
||||
return units_proofs[0]
|
||||
|
||||
def get_fees_for_proofs(self, proofs: List[Proof]) -> int:
|
||||
|
||||
@@ -383,7 +383,7 @@ async def test_duplicate_proofs_double_spent(wallet1: Wallet):
|
||||
doublespend = await wallet1.mint(64, quote_id=mint_quote.quote)
|
||||
await assert_err(
|
||||
wallet1.split(wallet1.proofs + doublespend, 20),
|
||||
"Mint Error: duplicate proofs.",
|
||||
"Mint Error: Duplicate inputs provided",
|
||||
)
|
||||
assert wallet1.balance == 64
|
||||
assert wallet1.available_balance == 64
|
||||
|
||||
Reference in New Issue
Block a user