address vrde's comments, reshuffle some exceptions around
This commit is contained in:
parent
352627b83a
commit
e5dd5c665b
|
@ -15,11 +15,3 @@ class OperationError(BackendError):
|
|||
|
||||
class DuplicateKeyError(OperationError):
|
||||
"""Exception raised when an insert fails because the key is not unique"""
|
||||
|
||||
|
||||
class CriticalDoubleSpend(BigchainDBError):
|
||||
"""Data integrity error that requires attention"""
|
||||
|
||||
|
||||
class CriticalDoubleInclusion(BigchainDBError):
|
||||
"""Data integrity error that requires attention"""
|
||||
|
|
|
@ -92,8 +92,8 @@ class AmountError(ValidationError):
|
|||
"""Raised when there is a problem with a transaction's output amounts"""
|
||||
|
||||
|
||||
class TransactionDoesNotExist(ValidationError):
|
||||
"""Raised if the transaction is not in the database"""
|
||||
class InputDoesNotExist(ValidationError):
|
||||
"""Raised if a transaction input does not exist"""
|
||||
|
||||
|
||||
class TransactionOwnerError(ValidationError):
|
||||
|
|
|
@ -4,6 +4,7 @@ import collections
|
|||
from time import time
|
||||
|
||||
from itertools import compress
|
||||
from bigchaindb import exceptions as core_exceptions
|
||||
from bigchaindb.common import crypto, exceptions
|
||||
from bigchaindb.common.utils import gen_timestamp, serialize
|
||||
from bigchaindb.common.transaction import TransactionLink
|
||||
|
@ -11,7 +12,6 @@ from bigchaindb.common.transaction import TransactionLink
|
|||
import bigchaindb
|
||||
|
||||
from bigchaindb import backend, config_utils, utils
|
||||
from bigchaindb.backend import exceptions as backend_exceptions
|
||||
from bigchaindb.consensus import BaseConsensusRules
|
||||
from bigchaindb.models import Block, Transaction
|
||||
|
||||
|
@ -308,7 +308,7 @@ class Bigchain(object):
|
|||
if list(validity.values()).count(Bigchain.BLOCK_VALID) > 1:
|
||||
block_ids = str([block for block in validity
|
||||
if validity[block] == Bigchain.BLOCK_VALID])
|
||||
raise backend_exceptions.CriticalDoubleInclusion(
|
||||
raise core_exceptions.CriticalDoubleInclusion(
|
||||
'Transaction {tx} is present in '
|
||||
'multiple valid blocks: {block_ids}'
|
||||
.format(tx=txid, block_ids=block_ids))
|
||||
|
@ -361,7 +361,7 @@ class Bigchain(object):
|
|||
if self.get_transaction(transaction['id']):
|
||||
num_valid_transactions += 1
|
||||
if num_valid_transactions > 1:
|
||||
raise backend_exceptions.CriticalDoubleSpend(
|
||||
raise core_exceptions.CriticalDoubleSpend(
|
||||
'`{}` was spent more than once. There is a problem'
|
||||
' with the chain'.format(txid))
|
||||
|
||||
|
|
|
@ -1,2 +1,10 @@
|
|||
class BigchainDBError(Exception):
|
||||
"""Base class for BigchainDB exceptions."""
|
||||
|
||||
|
||||
class CriticalDoubleSpend(BigchainDBError):
|
||||
"""Data integrity error that requires attention"""
|
||||
|
||||
|
||||
class CriticalDoubleInclusion(BigchainDBError):
|
||||
"""Data integrity error that requires attention"""
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from bigchaindb.common.crypto import hash_data, PublicKey, PrivateKey
|
||||
from bigchaindb.common.exceptions import (InvalidHash, InvalidSignature,
|
||||
DoubleSpend, TransactionDoesNotExist,
|
||||
DoubleSpend, InputDoesNotExist,
|
||||
TransactionNotInValidBlock,
|
||||
AssetIdMismatch, AmountError,
|
||||
SybilError, ValidationError)
|
||||
|
@ -60,8 +60,8 @@ class Transaction(Transaction):
|
|||
get_transaction(input_txid, include_status=True)
|
||||
|
||||
if input_tx is None:
|
||||
raise TransactionDoesNotExist("input `{}` doesn't exist"
|
||||
.format(input_txid))
|
||||
raise InputDoesNotExist("input `{}` doesn't exist"
|
||||
.format(input_txid))
|
||||
|
||||
if status != bigchain.TX_VALID:
|
||||
raise TransactionNotInValidBlock(
|
||||
|
|
|
@ -93,7 +93,7 @@ class TestBigchainApi(object):
|
|||
|
||||
@pytest.mark.genesis
|
||||
def test_get_spent_with_double_inclusion_detected(self, b, monkeypatch):
|
||||
from bigchaindb.backend.exceptions import CriticalDoubleInclusion
|
||||
from bigchaindb.exceptions import CriticalDoubleInclusion
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
tx = Transaction.create([b.me], [([b.me], 1)])
|
||||
|
@ -128,7 +128,7 @@ class TestBigchainApi(object):
|
|||
|
||||
@pytest.mark.genesis
|
||||
def test_get_spent_with_double_spend_detected(self, b, monkeypatch):
|
||||
from bigchaindb.backend.exceptions import CriticalDoubleSpend
|
||||
from bigchaindb.exceptions import CriticalDoubleSpend
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
tx = Transaction.create([b.me], [([b.me], 1)])
|
||||
|
@ -163,7 +163,7 @@ class TestBigchainApi(object):
|
|||
|
||||
@pytest.mark.genesis
|
||||
def test_get_block_status_for_tx_with_double_inclusion(self, b, monkeypatch):
|
||||
from bigchaindb.backend.exceptions import CriticalDoubleInclusion
|
||||
from bigchaindb.exceptions import CriticalDoubleInclusion
|
||||
from bigchaindb.models import Transaction
|
||||
|
||||
tx = Transaction.create([b.me], [([b.me], 1)])
|
||||
|
|
Loading…
Reference in New Issue