Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d610399

Browse filesBrowse files
committed
Completed entire project. Updates might be possible here
1 parent f5b865b commit d610399
Copy full SHA for d610399

File tree

Expand file treeCollapse file tree

12 files changed

+316
-13
lines changed
Filter options
Expand file treeCollapse file tree

12 files changed

+316
-13
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ Make sure to activate the virtual environment for python
5151
export SEED_DATA=True && python3 -m backend.app
5252
```
5353

54-
*This will be updated accordingly*
5554
___
5655
## DEVELOPER'S IDEA
5756
My idea is to create a cryptocurrency system which I can utilise for payments inside the college. The idea is to create a full fledged cryptocurrency system with certain nodes and verification. I hope to make teacher's desktops as miners and students as the wallet holders. Teacher's desktop will verify and add the transaction details to the blockchain and on spending some computational power the teacher may recieve some incentive which will be decided during a later period. The value of the currency system will also be decided later on.
@@ -96,7 +95,20 @@ Extra information is given in the required files.
9695

9796
- So today I have completed the frontend part of blockchain to display the blockchain data in the website. This included use of buttons installation of react-bootstrap and more. We have also learnt that we need to allow CORS to access the backend part of the chain. These things will be included in the requirements.txt file. I have also included pagination in this data field which will help in readablity of each chain data in the blockchain field. This marks the end of frontend for Blockchain, next I will try to get the frontend of cryptocurrency done in this section.
9897

99-
*This will also be updated on a later basis*
98+
- **Day 9(18/11/2020)**: Today I have completed the frontend part of cryptocurrency system hence marking an overall conclusion to this project. Here we had made use of react-hooks of useState and useEffect for fetching data from our backend built in this project. I have also included certain links to make this project a multi page one. This includes the blockchain part of the project, transaction pool, mining button which will mine the transactions. Now we have also terminated the use of Postman as we have made a frontend which will link the transactions in the transaction entry method which will convert itself into a JSON method which will also gets updated. I have also included a function which allows us to update our transactions in 10 seconds. This marks the end of our course project.
99+
100+
- **CONCLUSION** : This project has been fun to work on. Although there are certain functions we need to work on, since this is a prototype.
101+
- An account based system, where an account can be created on giving credentials.
102+
- A non miner application where non miners can also transact between peers.
103+
- A system where the blockchain can catch up.
104+
- This system is similar to a centralised blockchain. There is only a root node (one with the localhost address 5000). Control needs to be shifted to another node when this node is taken down so that there will be no loss of data.
105+
- More information regarding API endpoints etc.
106+
- And last, a better functional UI.
107+
108+
- I have tried to cover my best to get this project functional and running. On the later part I have to set up a system which can run the scripts automatically on opening the application. This is just some part of the process which has been completed
109+
110+
- Thanks to anyone who has kept track till here. MAYBE I'll work more on it and hoping I will be able to completely make this application a full fledged cryptocurrency system.
111+
100112
___
101113
## ACKNOWLEDGEMENTS
102114

‎backend/app/__init__.py

Copy file name to clipboardExpand all lines: backend/app/__init__.py
+20-1Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ def route_wallet_transact():
8080
def route_wallet_info():
8181
return jsonify({'address':wallet.address, 'balance': wallet.balance })
8282

83+
@app.route('/known/addresses')
84+
def route_known_addresses():
85+
known_address = set()
86+
for block in blockchain.chain:
87+
for transaction in block.data:
88+
known_address.update(transaction['output'].keys())
89+
90+
return jsonify(list(known_address))
91+
92+
@app.route('/transactions')
93+
def route_transactions():
94+
return jsonify(transaction_pool.transaction_data())
95+
96+
8397

8498
ROOT_PORT = 5000
8599
PORT = ROOT_PORT
@@ -99,7 +113,12 @@ def route_wallet_info():
99113
blockchain.addBlock([
100114
Transactions(Wallet(),Wallet().address,random.randint(2,50)).to_json(),
101115
Transactions(Wallet(),Wallet().address,random.randint(2,50)).to_json()
102-
])
116+
])
117+
118+
for i in range(3):
119+
transaction_pool.set_transaction(
120+
Transactions(Wallet(),Wallet().address,random.randint(2,50))
121+
)
103122

104123

105124
app.run(port=PORT)
520 Bytes
Binary file not shown.

‎frontend/package-lock.json

Copy file name to clipboardExpand all lines: frontend/package-lock.json
+96Lines changed: 96 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎frontend/package.json

Copy file name to clipboardExpand all lines: frontend/package.json
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
"@testing-library/jest-dom": "^5.11.6",
77
"@testing-library/react": "^11.1.2",
88
"@testing-library/user-event": "^12.2.2",
9+
"history": "^4.9.0",
910
"react": "^17.0.1",
1011
"react-bootstrap": "^1.4.0",
1112
"react-dom": "^17.0.1",
13+
"react-router": "^5.0.1",
14+
"react-router-dom": "^5.0.1",
1215
"react-scripts": "4.0.0",
1316
"web-vitals": "^0.2.4"
1417
},

‎frontend/src/components/App.js

Copy file name to clipboardExpand all lines: frontend/src/components/App.js
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React, {useState,useEffect} from 'react';
2+
import {Link} from 'react-router-dom'
23
import logo from '../assets/logo.png';
34
import {API_BASE_URL} from '../config'
4-
import Blockchain from './Blockchain'
5+
56

67
function App() {
78
const [walletInfo,setWalletInfo] = useState({})
@@ -19,13 +20,13 @@ function App() {
1920
<img className='logo' src={logo} alt='App Logo'/>
2021
<h3>Welcome to ProtoCrit</h3>
2122
<br/>
23+
<Link to="/blockchain" >Blockchain</Link>
24+
<Link to="/conduct-transaction">Conduct transaction</Link>
25+
<Link to="/transaction-pool">Transaction pool</Link>
2226
<div className='WalletInfo'>
2327
<div>Address: {address}</div>
2428
<div>Balance: {balance}</div>
2529
</div>
26-
<br/>
27-
<Blockchain/>
28-
2930
</div>
3031
)
3132
}

‎frontend/src/components/Blockchain.js

Copy file name to clipboardExpand all lines: frontend/src/components/Blockchain.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React,{useState,useEffect} from 'react'
2+
import {Link} from 'react-router-dom'
23
import { Button } from 'react-bootstrap';
34
import { API_BASE_URL } from '../config';
45
import Block from './Block'
@@ -34,7 +35,9 @@ function Blockchain(){
3435
}
3536

3637
return (
37-
<div>
38+
<div className="Blockchain">
39+
<Link to="/">Home</Link>
40+
<hr/>
3841
<h3>Blockchain</h3>
3942
<div>
4043
{
+91Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import React, {useState, useEffect} from 'react'
2+
import {Link} from 'react-router-dom'
3+
import {FormGroup, FormControl, Button} from 'react-bootstrap'
4+
import {API_BASE_URL} from '../config'
5+
import history from '../history'
6+
7+
function ConductTransactions(){
8+
const [amount, setAmount] = useState(0)
9+
const [recepient, setRecepient] = useState('')
10+
const [knownAddresses, setKnownAddresses] = useState([])
11+
12+
useEffect(() => {
13+
fetch(`${API_BASE_URL}/known/addresses`)
14+
.then(response => response.json())
15+
.then(json => setKnownAddresses(json))
16+
},[])
17+
18+
const updateRecepient = event => {
19+
setRecepient(event.target.value)
20+
}
21+
22+
const updateAmount = event => {
23+
setAmount(Number(event.target.value))
24+
}
25+
26+
const submitTransaction = () => {
27+
fetch(`${API_BASE_URL}/wallet/transact`,{
28+
method: 'POST',
29+
headers: {'Content-Type':'application/json'},
30+
body :JSON.stringify({recepient, amount})
31+
}).then(response => response.json())
32+
.then(json => {
33+
console.log('submitTransaction json',json)
34+
alert("SUCCESS!")
35+
history.push('/transaction-pool')
36+
} )
37+
}
38+
39+
return(
40+
<div className='ConductTransaction' >
41+
<Link to="/">Home</Link>
42+
<hr/>
43+
<h3>
44+
Conduct a transaction
45+
</h3>
46+
<br/>
47+
<FormGroup>
48+
<FormControl
49+
input = "text"
50+
placeholder = "recepient"
51+
value = {recepient}
52+
onChange = {updateRecepient}
53+
/>
54+
</FormGroup>
55+
<FormGroup>
56+
<FormControl
57+
input = "number"
58+
placeholder = "amount"
59+
value = {amount}
60+
onChange = {updateAmount}
61+
/>
62+
</FormGroup>
63+
<div>
64+
<Button
65+
variant="danger"
66+
onClick = {submitTransaction}
67+
>
68+
Submit
69+
</Button>
70+
</div>
71+
<br/>
72+
<h4>
73+
Known addresses
74+
</h4>
75+
<div>
76+
{
77+
knownAddresses.map((knownAddress,i) =>(
78+
<span key={knownAddress}>
79+
<u>{knownAddress}</u>
80+
{i !== knownAddresses.length - 1 ? ', ' : ''}
81+
</span>
82+
))
83+
}
84+
</div>
85+
86+
</div>
87+
)
88+
89+
}
90+
91+
export default ConductTransactions

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.