Added an abstract base class so plugins don't need to add stubs for functions they don't care about.

This commit is contained in:
Matt Smith 2016-02-29 19:19:08 -08:00
parent ee4720d1a5
commit 380482b967
2 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,43 @@
# TODO: no real reason to use abc yet, but later we can enforce inheritance from
# this class when loading plugins if that's desirable.
# from abc import ABCMeta
class AbstractConsensusRules:
# TODO: rather than having plugin-authors inherit and override,
# it'd be cleaner to make a `transactionrule` decorator and etc
@classmethod
def validate_transaction(cls, bigchain, transaction):
"""Validate a transaction.
Args:
bigchain (Bigchain): an instantiated bigchaindb.Bigchain object.
transaction (dict): transaction to validate.
Returns:
The transaction if the transaction is valid else it raises an
exception describing the reason why the transaction is invalid.
Raises:
Descriptive exceptions indicating the reason the transaction failed.
See the `exceptions` module for bigchain-native error classes.
"""
return transaction
@classmethod
def validate_block(cls, bigchain, block):
"""Validate a block.
Args:
bigchain (Bigchain): an instantiated bigchaindb.Bigchain object.
block (dict): block to validate.
Returns:
The block if the block is valid else it raises and exception
describing the reason why the block is invalid.
Raises:
Descriptive exceptions indicating the reason the block failed.
See the `exceptions` module for bigchain-native error classes.
"""
return block

View File

@ -1,7 +1,8 @@
import bigchaindb.exceptions as exceptions import bigchaindb.exceptions as exceptions
from bigchaindb.crypto import hash_data from bigchaindb.crypto import hash_data
from bigchaindb.consensus import AbstractConsensusRules
class ConsensusRules(object): class ConsensusRules(AbstractConsensusRules):
"""Base consensus rules for Bigchain. """Base consensus rules for Bigchain.
This class can be copied to write your own consensus rules! This class can be copied to write your own consensus rules!