def get_last_block():
    return create_json_response(b.last_block(chain).__dict__)
def say_next_properties():
    log.log('----> next "previous_hash" will be {}'.format(b.hash_block(b.last_block(chain))))
    log.log('----> next "proof" will be: {}'.format(mine_next(b.last_block(chain).proof)))
from flask import Flask, request, render_template
from server_common import *
import json
import log as log
import jumblecoin as b
import miner
from miner import mine_next

# initialise the flask app
app = Flask(__name__)

# create an empty chain
chain = b.new_chain()

previous_proof = b.last_block(chain).proof
b.add_new_block_to_chain(chain, json.dumps({'name': 'bob', 'value': 1}), mine_next(previous_proof))
previous_proof = b.last_block(chain).proof
b.add_new_block_to_chain(chain, json.dumps({'name': 'alice', 'value': 1}), mine_next(previous_proof))
previous_proof = b.last_block(chain).proof
b.add_new_block_to_chain(chain, json.dumps({'name': 'charles', 'value': 1}), mine_next(previous_proof))
log.log(json.dumps(chain.to_dict()))


@app.route('/chain', methods=['GET'])
def get_entire_chain():
    return create_json_response(chain.to_dict())


@app.route('/last_block', methods=['GET'])
def get_last_block():
    return create_json_response(b.last_block(chain).__dict__)