Last active
June 24, 2019 11:36
-
-
Save dvf/a61aceea175b9a2d7a0f58850ca3d610 to your computer and use it in GitHub Desktop.
Step 7: Transaction Endpoint
This file contains hidden or 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, jsonify, request | |
| ... | |
| @app.route('/transactions/new', methods=['POST']) | |
| def new_transaction(): | |
| values = request.get_json() | |
| # Check that the required fields are in the POST'ed data | |
| required = ['sender', 'recipient', 'amount'] | |
| if not all(k in values for k in required): | |
| return 'Missing values', 400 | |
| # Create a new Transaction | |
| index = blockchain.new_transaction(values['sender'], values['recipient'], values['amount']) | |
| response = {'message': f'Transaction will be added to Block {index}'} | |
| return jsonify(response), 201 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's because this is introduced in python version 3.6