From fcacf2d91cff4a48d8bd06c1a73990dd485aa597 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sat, 10 Aug 2024 07:44:18 +0700 Subject: [PATCH] Create blockchain.py --- .../pi-stablecoin/routes/blockchain.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 blockchain_integration/pi_network/pi-stablecoin/routes/blockchain.py diff --git a/blockchain_integration/pi_network/pi-stablecoin/routes/blockchain.py b/blockchain_integration/pi_network/pi-stablecoin/routes/blockchain.py new file mode 100644 index 000000000..f74d7e897 --- /dev/null +++ b/blockchain_integration/pi_network/pi-stablecoin/routes/blockchain.py @@ -0,0 +1,16 @@ +from flask import Blueprint, jsonify +from models import Blockchain + +blockchain_blueprint = Blueprint('blockchain', __name__) + +@blockchain_blueprint.route('/blockchain', methods=['GET']) +def get_blockchain(): + blockchain = Blockchain() + return jsonify(blockchain.chain) + +@blockchain_blueprint.route('/blockchain/add_block', methods=['POST']) +def add_block(): + blockchain = Blockchain() + new_block = Block(len(blockchain.chain), blockchain.get_latest_block().hash, int(time.time()), "New Block") + blockchain.add_block(new_block) + return jsonify(blockchain.chain)