Skip to content

Commit c180240

Browse files
committed
Complete Section: Frontend Blockchain
1 parent b9ef73c commit c180240

File tree

9 files changed

+393
-2
lines changed

9 files changed

+393
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@ export PEER=True && python3 -m backend.app
3737
In the frontend directory:
3838
```
3939
npm run start
40+
```
41+
42+
**Seed the backend with data**
43+
44+
Make sure to activate the virtual environment.
45+
46+
```
47+
export SEED_DATA=True && python3 -m backend.app
4048
```

backend/app/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ def route_default():
2626
def route_blockchain():
2727
return jsonify(blockchain.to_json())
2828

29+
@app.route('/blockchain/range')
30+
def route_blockchain_range():
31+
# http://localhost:5000/blockchain/range?start=2&end=5
32+
start = int(request.args.get('start'))
33+
end = int(request.args.get('end'))
34+
35+
return jsonify(blockchain.to_json()[::-1][start:end])
36+
37+
@app.route('/blockchain/length')
38+
def route_blockchain_length():
39+
return jsonify(len(blockchain.chain))
40+
2941
@app.route('/blockchain/mine')
3042
def route_blockchain_mine():
3143
transaction_data = transaction_pool.transaction_data()
@@ -78,4 +90,11 @@ def route_wallet_info():
7890
except Exception as e:
7991
print(f'\n -- Error synchronizing: {e}')
8092

93+
if os.environ.get('SEED_DATA') == 'True':
94+
for i in range(10):
95+
blockchain.add_block([
96+
Transaction(Wallet(), Wallet().address, random.randint(2, 50)).to_json(),
97+
Transaction(Wallet(), Wallet().address, random.randint(2, 50)).to_json()
98+
])
99+
81100
app.run(port=PORT)

frontend/package-lock.json

Lines changed: 201 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"private": true,
55
"dependencies": {
66
"react": "^16.10.2",
7+
"react-bootstrap": "^1.0.0-beta.14",
78
"react-dom": "^16.10.2",
89
"react-scripts": "3.2.0"
910
},

0 commit comments

Comments
 (0)