Skip to content

Commit

Permalink
Create blockchain.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 10, 2024
1 parent f0bf08a commit fcacf2d
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit fcacf2d

Please sign in to comment.