示例#1
0
 def convert_blocklist_to_chain_from_json(chain_json):
     """
     In this section, I serialize a list of serialized blocks into 
     a Blokchain instance, where the result will contain a chain list of Block instances.
     """
     blockchain = Blockchain()
     blockchain.chain = list(
         map(lambda block_json: Block.convert_block_from_json(block_json), chain_json)
     )
     return  blockchain
示例#2
0
    def message(self, pubnub, message_object):
        print(
            f'\n-- Channel: {message_object.channel} | Message : {message_object.message}'
        )

        if message_object.channel == COMMUNICATION_CHANNELS['BLOCK']:
            block = Block.convert_block_from_json(message_object.message)
            potential_chain = self.blockchain.chain[:]
            potential_chain.append(block)

            try:
                self.blockchain.replace_the_chain(potential_chain)
                self.transaction_pool.clear_the_blockchain_transactions(
                    self.blockchain)
                print('\n -- The local chain was replaced succesfully')
            except Exception as e:
                print(f'\n -- Unfortunately, the chain was not replaced: {e}')
        elif message_object.channel == COMMUNICATION_CHANNELS['TRANSACTION']:
            transaction = SystemTransactions.convert_transaction_data_from_json(
                message_object.message)
            self.transaction_pool.setting_the_trasaction(transaction)
            print(
                '\n -- The New Transaction has Been Set in the Transaction Pool'
            )