Skip to content

Instantly share code, notes, and snippets.

@dvf
Last active November 10, 2022 20:12
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dvf/0ccdfdfd4dadf0a53a82d7a1b2438c4e to your computer and use it in GitHub Desktop.
Step 6: Setting up Flask
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)
@emman27
Copy link

emman27 commented Oct 19, 2017

import jsonify is missing by the way (see line 38)

@Niedzwiedzw
Copy link

What's jsonify?

@volf52
Copy link

volf52 commented Jan 16, 2018

Could you change line 7 to
from flask import Flask, jsonify?

@Ap6pack
Copy link

Ap6pack commented Nov 10, 2022

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