Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: the driver depends on BigchainDB package #411

Merged
merged 1 commit into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bigchaindb_driver/common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
###############################################################################
# DO NOT CHANGE THIS FILE. #
# #
# This is a copy of the `bigchaindb.common` module, any change you want to do #
# here should be done in the original module, located in the BigchainDB #
# repository at <https://github.com/bigchaindb/bigchaindb>. #
# #
# We decided to copy the module here to avoid having the whole BigchainDB #
# package as a dependency. This is a temporary solution until BEP-9 is #
# implemented. #
###############################################################################
44 changes: 44 additions & 0 deletions bigchaindb_driver/common/crypto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
###############################################################################
# DO NOT CHANGE THIS FILE. #
# #
# This is a copy of the `bigchaindb.common` module, any change you want to do #
# here should be done in the original module, located in the BigchainDB #
# repository at <https://github.com/bigchaindb/bigchaindb>. #
# #
# We decided to copy the module here to avoid having the whole BigchainDB #
# package as a dependency. This is a temporary solution until BEP-9 is #
# implemented. #
###############################################################################

# Separate all crypto code so that we can easily test several implementations
from collections import namedtuple

import sha3
from cryptoconditions import crypto


CryptoKeypair = namedtuple('CryptoKeypair', ('private_key', 'public_key'))


def hash_data(data):
"""Hash the provided data using SHA3-256"""
return sha3.sha3_256(data.encode()).hexdigest()


def generate_key_pair():
"""Generates a cryptographic key pair.

Returns:
:class:`~bigchaindb.common.crypto.CryptoKeypair`: A
:obj:`collections.namedtuple` with named fields
:attr:`~bigchaindb.common.crypto.CryptoKeypair.private_key` and
:attr:`~bigchaindb.common.crypto.CryptoKeypair.public_key`.

"""
# TODO FOR CC: Adjust interface so that this function becomes unnecessary
return CryptoKeypair(
*(k.decode() for k in crypto.ed25519_generate_key_pair()))


PrivateKey = crypto.Ed25519SigningKey
PublicKey = crypto.Ed25519VerifyingKey
135 changes: 135 additions & 0 deletions bigchaindb_driver/common/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
###############################################################################
# DO NOT CHANGE THIS FILE. #
# #
# This is a copy of the `bigchaindb.common` module, any change you want to do #
# here should be done in the original module, located in the BigchainDB #
# repository at <https://github.com/bigchaindb/bigchaindb>. #
# #
# We decided to copy the module here to avoid having the whole BigchainDB #
# package as a dependency. This is a temporary solution until BEP-9 is #
# implemented. #
###############################################################################

"""Custom exceptions used in the `bigchaindb` package.
"""


class BigchainDBError(Exception):
"""Base class for BigchainDB exceptions."""


class ConfigurationError(BigchainDBError):
"""Raised when there is a problem with server configuration"""


class DatabaseAlreadyExists(BigchainDBError):
"""Raised when trying to create the database but the db is already there"""


class DatabaseDoesNotExist(BigchainDBError):
"""Raised when trying to delete the database but the db is not there"""


class StartupError(BigchainDBError):
"""Raised when there is an error starting up the system"""


class CyclicBlockchainError(BigchainDBError):
"""Raised when there is a cycle in the blockchain"""


class KeypairNotFoundException(BigchainDBError):
"""Raised if operation cannot proceed because the keypair was not given"""


class KeypairMismatchException(BigchainDBError):
"""Raised if the private key(s) provided for signing don't match any of the
current owner(s)
"""


class OperationError(BigchainDBError):
"""Raised when an operation cannot go through"""


##############################################################################
# Validation errors
#
# All validation errors (which are handleable errors, not faults) should
# subclass ValidationError. However, where possible they should also have their
# own distinct type to differentiate them from other validation errors,
# especially for the purposes of testing.


class ValidationError(BigchainDBError):
"""Raised if there was an error in validation"""


class DoubleSpend(ValidationError):
"""Raised if a double spend is found"""


class InvalidHash(ValidationError):
"""Raised if there was an error checking the hash for a particular
operation
"""


class SchemaValidationError(ValidationError):
"""Raised if there was any error validating an object's schema"""


class InvalidSignature(ValidationError):
"""Raised if there was an error checking the signature for a particular
operation
"""


class ImproperVoteError(ValidationError):
"""Raised if a vote is not constructed correctly, or signed incorrectly"""


class MultipleVotesError(ValidationError):
"""Raised if a voter has voted more than once"""


class TransactionNotInValidBlock(ValidationError):
"""Raised when a transfer transaction is attempting to fulfill the
outputs of a transaction that is in an invalid or undecided block
"""


class AssetIdMismatch(ValidationError):
"""Raised when multiple transaction inputs related to different assets"""


class AmountError(ValidationError):
"""Raised when there is a problem with a transaction's output amounts"""


class InputDoesNotExist(ValidationError):
"""Raised if a transaction input does not exist"""


class TransactionOwnerError(ValidationError):
"""Raised if a user tries to transfer a transaction they don't own"""


class SybilError(ValidationError):
"""If a block or vote comes from an unidentifiable node"""


class DuplicateTransaction(ValidationError):
"""Raised if a duplicated transaction is found"""


class ThresholdTooDeep(ValidationError):
"""Raised if threshold condition is too deep"""


class GenesisBlockAlreadyExistsError(ValidationError):
"""Raised when trying to create the already existing genesis block"""


class MultipleValidatorOperationError(ValidationError):
"""Raised when a validator update pending but new request is submited"""
Loading