text: import hashlib
  import json
  from time import time
  from urllib.parse import urlparse
  from uuid import uuid4
  
  import requests
  from flask import Flask, jsonify, request
  
  
  class Blockchain:
      def __init__(self):
          
          # Create a new genesis block
  
  
      def new_block(self, proof, previous_hash):
          """
          Create a new Block in the Blockchain
          A block contains block_number, timestamp, transactions, proof, hash of previous
  
          :param proof: The proof given by the Proof of Work algorithm
          :param previous_hash: Hash of previous Block
          :return: New Block
          """
  
          block = {
  
          }
  
          # Reset the current list of transactions
  
  
          return block
  
      def new_transaction(self, sender, recipient, amount):
          """
          Creates a new transaction to go into the next mined Block
  
          :param sender: Address of the Sender
          :param recipient: Address of the Recipient
          :param amount: Amount
          :return: The index of the Block that will hold this transaction
          """
          new_transaction = {
  
          }
  
  
          return new_transaction
  
      @property
      def last_block(self):
          
          return self.chain[-1]
  
      @staticmethod
      def hash(block):
          """
          Creates a SHA-256 hash of a Block
  
          :param block: Block
          """
  
          # We must make sure that the Dictionary is Ordered, or we'll have inconsistent hashes
  
  
      def proof_of_work(self, last_block):
          """
          Simple Proof of Work Algorithm:
  
           - Find a number p' such that hash(pp') contains leading 4 zeroes
           - Where p is the previous proof, and p' is the new proof
           
          :param last_block: <dict> last Block
          :return: <int>
          """
  
          return "POW"
  
      @staticmethod
      def valid_proof(last_proof, proof, last_hash):
          """
          Validates the Proof
  
          :param last_proof: <int> Previous Proof
          :param proof: <int> Current Proof
          :param last_hash: <str> The hash of the Previous Block
          :return: <bool> True if correct, False if not.
  
          """
  
          return "Valid proof"
  
  
  # Instantiate the Node
  app = Flask(__name__)
  
  # Generate a globally unique address for this node
  node_identifier = str(uuid4()).replace('-', '')
  
  # Instantiate the Blockchain
  blockchain = Blockchain()
  
  
  @app.route('/mine', methods=['GET'])
  def mine():
      # We run the proof of work algorithm to get the next proof...
      last_block = blockchain.last_block
      proof = blockchain.proof_of_work(last_block)
  
      # We must receive a reward for finding the proof.
      # The sender is "0" to signify that this node has mined a new coin.
      blockchain.new_transaction(
          sender="0",
          recipient=node_identifier,
          amount=1,
      )
  
      # Forge the new Block by adding it to the chain
      previous_hash = blockchain.hash(last_block)
      block = blockchain.new_block(proof, previous_hash)
  
      response = {
          'message': "New Block Forged",
          'index': block['index'],
          'transactions': block['transactions'],
          'proof': block['proof'],
          'previous_hash': block['previous_hash'],
      }
      return jsonify(response), 200
  
  
  @app.route('/transactions/new', methods=['POST'])
  def new_transaction():
      values = request.get_json()
  
      # Check that the required fields are in the POST'ed data
      required = ['sender', 'recipient', 'amount']
      if not all(k in values for k in required):
          return 'Missing values', 400
  
      # Create a new Transaction
      index = blockchain.new_transaction(values['sender'], values['recipient'], values['amount'])
  
      response = {'message': f'Transaction will be added to Block {index}'}
      return jsonify(response), 201
  
  
  @app.route('/chain', methods=['GET'])
  def full_chain():
      response = {
          'chain': blockchain.chain,
          'length': len(blockchain.chain),
      }
      return jsonify(response), 200
  
  
  if __name__ == '__main__':
      from argparse import ArgumentParser
  
      parser = ArgumentParser()
      parser.add_argument('-p', '--port', default=5000, type=int, help='port to listen on')
      args = parser.parse_args()
      port = args.port
  
      app.run(host='0.0.0.0', port=port)
  