def __init__(self):

        self.genesis_transaction = Transaction(
            [TxIn('', 0, '')], [TxOut(get_public_from_wallet(), 50)])
        self._blockchain = [self.get_genesis_block()]
        self.difficulty_bits = 15
        self.unspent_tx_outs = process_transactions([self.genesis_transaction],
                                                    [], 0)
    def add_block(self, new_block):

        if self.is_valid_new_block(new_block, self.get_latest_block()):
            ret_val = process_transactions(new_block.data, self.get_unspent_tx_outs(), new_block.index)
            if ret_val is None:
                print('block is not valid in terms of transactions')
                return False
            else:
                self._blockchain.append(new_block)
                self.set_unspent_tx_outs(ret_val)
                update_transaction_pool(self.get_unspent_tx_outs())
                return True
Beispiel #3
0
    def add_block(self, new_block):

        if self.is_valid_new_block(new_block, self.get_latest_block()):

            transactions = new_block.data if isinstance(new_block.data, list) else [new_block.data]
            ret_val = process_transactions([transaction_object(transaction) for transaction in transactions], self.get_unspent_tx_outs(), new_block.index)

            if ret_val is None:
                print('block is not valid in terms of transactions')
                return False
            else:
                self._blockchain.append(new_block)
                self.set_unspent_tx_outs(ret_val)
                update_transaction_pool(self.get_unspent_tx_outs())
                return True
Beispiel #4
0
    def is_valid_chain(self, blockchain_to_validate):

        # if self.calculate_hash_for_block(Block(**blockchain_to_validate[0])) != self.get_genesis_block().hash:
        #     return False

        previous_block = None
        unspent_tx_outs = []
        for current_block in blockchain_to_validate:
            if previous_block and not self.is_valid_new_block(Block(**current_block), previous_block):
                return False
            current_block = (Block(**current_block))
            transactions = current_block.data if isinstance(current_block.data, list) else [current_block.data]
            unspent_tx_outs = process_transactions([transaction_object(transaction) for transaction in transactions], unspent_tx_outs, current_block.index)
            previous_block = current_block

            if not unspent_tx_outs:
                return False

        return unspent_tx_outs
    def __init__(self):

        self._blockchain = [self.get_genesis_block()]
        self.difficulty_bits = 15
        self.unspent_tx_outs = process_transactions([self.genesis_transaction], [], 0)