Beispiel #1
0
 def from_json(chain_json):
     '''
     Deserialize a list of serialised blocks into Blockchain object or a chain of Block instances
     '''
     blockchain = Blockchain()
     blockchain.chain = list(
         map(lambda block_json: Block.from_json(block_json), chain_json))
     return blockchain
Beispiel #2
0
    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.from_json(message_object.message)
            potential_chain = self.blockchain.chain[:]
            potential_chain.append(block)
            try:
                self.blockchain.replace_chain(potential_chain)
                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.')