else: transaction = Transaction(wallet, transaction_data["recipient"], transaction_data["amount"]) pubsub.broadcast_transaction(transaction) return jsonify(transaction.to_json()) @app.route("/wallet/info") def route_wallet_info(): return jsonify({"address": wallet.address, "balance": wallet.balance}) ROOT_PORT = 5000 PORT = ROOT_PORT if os.environ.get("PEER") == "True": PORT = random.randint(5001, 6000) result = requests.get(f"http://localhost:{ROOT_PORT}/blockchain") result_blockchain = Blockchain.from_json(result.json()) try: blockchain.replace_chain(result_blockchain.chain) print("\n -- Successfully synchronised the local chain") except Exception as e: print(f"\n -- Error synchronising: {e}") app.run(port=PORT)
return block.to_json() @app.route("/wallet/transact", methods=['POST']) def route_wallet_transact(): transaction_data = request.get_json() transaction = Transaction(sender_wallet, transaction_data['recipient'], transaction_data['amount']) print(f"{transaction.to_json()}") return jsonify(transaction.to_json()) ROOT_PORT = 5000 PORT = ROOT_PORT if os.environ.get("PEER") == "True": PORT = random.randint(5001, 6000) response = requests.get(f"http://localhost:{ROOT_PORT}/blockchain") root_blockchain = Blockchain.from_json(response.json()) try: blockchain.replace_chain(root_blockchain) print(f"Blockchain synchronized successfully\n") except Exception as e: print(f"Failed to synchronize blockchain !!!\n Error: {e}") app.run(port=PORT)