Last active
November 10, 2022 20:12
Star
You must be signed in to star a gist
Step 6: Setting up Flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import json | |
from textwrap import dedent | |
from time import time | |
from uuid import uuid4 | |
from flask import Flask | |
class Blockchain(object): | |
... | |
# Instantiate our 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(): | |
return "We'll mine a new Block" | |
@app.route('/transactions/new', methods=['POST']) | |
def new_transaction(): | |
return "We'll add a new transaction" | |
@app.route('/chain', methods=['GET']) | |
def full_chain(): | |
response = { | |
'chain': blockchain.chain, | |
'length': len(blockchain.chain), | |
} | |
return jsonify(response), 200 | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=5000) |
What's jsonify?
Could you change line 7 to
from flask import Flask, jsonify
?
node_identifier = str(uuid4()).replace('-', '') should be
node_identifier = str(uuid4()).replace('-', ''') a ' is missing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import jsonify is missing by the way (see line 38)