Skip to content

Instantly share code, notes, and snippets.

@dvf

dvf/blockchain.py

Last active Jun 24, 2019
Embed
What would you like to do?
Step 7: Transaction Endpoint
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
@NDS1608

This comment has been minimized.

Copy link

@NDS1608 NDS1608 commented Mar 3, 2018

I keep getting "
response = {'message': f'Transaction will be added to Block {index}'}

SyntaxError: invalid syntax
(With the carrot under the ' at the end of the line)
Can't figure it out, any ideas?

@stackotter

This comment has been minimized.

Copy link

@stackotter stackotter commented Apr 14, 2018

Are you using python 3?

@dsp90

This comment has been minimized.

Copy link

@dsp90 dsp90 commented Jun 24, 2019

it's because this is introduced in python version 3.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment