Skip to content

Instantly share code, notes, and snippets.

Last active May 22, 2020 14:10
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Step 12: New Endpoints for Consensus
@app.route('/nodes/register', methods=['POST'])
def register_nodes():
values = request.get_json()
nodes = values.get('nodes')
if nodes is None:
return "Error: Please supply a valid list of nodes", 400
for node in nodes:
response = {
'message': 'New nodes have been added',
'total_nodes': list(blockchain.nodes),
return jsonify(response), 201
@app.route('/nodes/resolve', methods=['GET'])
def consensus():
replaced = blockchain.resolve_conflicts()
if replaced:
response = {
'message': 'Our chain was replaced',
'new_chain': blockchain.chain
response = {
'message': 'Our chain is authoritative',
'chain': blockchain.chain
return jsonify(response), 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment