def deserialize_jsonified_chain(jsonified_chain): """ Deserialize a list of serialized blocks into a Blockchain instance. The result will contain a chain list of Block instances. """ blockchain = Blockchain() blockchain.chain = list( map( lambda jsonified_block: Block.deserialize_jsonified_block( jsonified_block), jsonified_chain)) return blockchain
def message(self, pubnub, message_object): print( f'\n-- Channel: {message_object.channel} | Message: {message_object.message}' ) if message_object.channel == CHANNELS['BLOCK']: block = Block.deserialize_jsonified_block(message_object.message) potential_chain = self.blockchain.chain[:] #Making copy of existing chain potential_chain.append(block) try: self.blockchain.replace_chain(potential_chain) self.transaction_pool.clear_blockchain_transactions( self.blockchain) print('\n -- Successfully replaced the local chain.') except Exception as e: print(f'\n -- Did not replace chain: {e}') elif message_object.channel == CHANNELS['TRANSACTION']: transaction = Transaction.from_json(message_object.message) self.transaction_pool.set_transaction(transaction) print('\n -- Set the new transaction in the transaction pool.')