diff --git a/atomic.py b/atomic.py index 85ff777c3a159b6ac59d26b005fc0d270c6107d1..4a13356505fd31601f3b87e0565f0ceb7834e070 100644 --- a/atomic.py +++ b/atomic.py @@ -11,7 +11,6 @@ class Atomic(object): self.__committed_once__ = True self.__var_backup__ = dict(vars(self)) self.__var_backup__.pop("__var_backup__") - #print(self.__var_backup__) def revert(self): for attr, val in self.__var_backup__.items(): diff --git a/blockchain.py b/blockchain.py index ea0eec62fb087218c2183bd45443542ef87a2cea..113b0eff66cb96264104f4b930566db3f27551c1 100644 --- a/blockchain.py +++ b/blockchain.py @@ -7,7 +7,6 @@ import requests from block import Block import validation - class Blockchain: # difficulty level of the Proof of Work # shows the pattern with which each hash has to start with @@ -109,8 +108,7 @@ class Blockchain: success, errors = validation.apply_block(block, commit=True) if not success: - return False - + raise validation.BlockException(errors) self.chain.append(block) # reset the list since the transactions are confirmed now self.transactions_to_be_confirmed = [] #TODO Only remove @@ -153,6 +151,8 @@ class Blockchain: success, errors = validation.apply_block(new_block) if not success: + print(errors) + print("Removing Erroneous transactions from transaction list") erroneous_transactions = [err.trindex for err in errors] new_transaction_list = [] for trindex, transaction in enumerate(new_block.transactions): @@ -164,6 +164,7 @@ class Blockchain: raise Exception("Removing erroneous transactions still resulted in errors. -------\n"+str(errors)) proof = self.proof_of_work(new_block) + self.append_block(new_block, proof) # Consensus mechanism to make sure that the nodes in diff --git a/validation.py b/validation.py index a05df3892a70021e460944a0bdb13be98f96c5ca..8a3748c9a45526c8eaaa533e71cd2715781f7570 100644 --- a/validation.py +++ b/validation.py @@ -4,6 +4,11 @@ from wallet import NotEnoughCreditsException NEW_NODE_INITIAL_CREDITS = 5 +class BlockException(Exception): + def __init__(self, transactionExceptions=[]): + self.transactionExceptions = transactionExceptions + super.__init__("Block failed to validate. Following Exceptions occured: {}".format(str(transactionExceptions))) + def apply_block(block, commit=False): """ Try to update node_state based on all the transactions in the diff --git a/wallet.py b/wallet.py index 792a725ac52ae57953c3074747428fcad3c051d0..67d06e22c741306c5cc58d0b3d9b7c6d491faeec 100644 --- a/wallet.py +++ b/wallet.py @@ -3,10 +3,10 @@ class NotEnoughCreditsException(Exception): wallet_ID, current_amount, discredit_amount): - message = "Tried to discredit `{}` credits from wallet `{}` with only `{}` credits.".format(discredit_amount, + self.message = "Tried to discredit `{}` credits from wallet `{}` with only `{}` credits.".format(discredit_amount, wallet_ID, current_amount) - super().__init__(message) + super().__init__(self.message) class Wallet(object): """