Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
1c44c0d
initial upload.
HourGlss Sep 9, 2018
d1eb994
fixed verifiability and some security issues without making things co…
Sep 10, 2018
3827e0b
blockchain validation works
Sep 11, 2018
afe3f4b
improved networking so that if someone downloads out chains, we add t…
Sep 11, 2018
4ca5f7c
Transactions should now propagate through network. this is untested s…
Sep 11, 2018
b6fc334
removed printing
Sep 11, 2018
5f94e08
updated validation
Sep 11, 2018
02a8b19
updated pow / effort so that it's more controllable
Sep 11, 2018
fc10ca6
changed structure of Block due to oversight
Sep 11, 2018
675e97e
changed amt of work needed per block
HourGlss Sep 11, 2018
8769981
dumped the proof of work
Sep 11, 2018
52f4128
made a current user for github
Sep 11, 2018
e378fe1
Wallet was generating non-usable keys? I'll have to fix the encoding.
Sep 11, 2018
7a2ddba
something is going on with the Pipe
Sep 11, 2018
1ab037d
Queue now instead of Pipe. we no longer need sql for storing the bloc…
Sep 11, 2018
f223a32
fixed for effort
Sep 12, 2018
1ac5ac0
Fixed Validation and structure of block creation
HourGlss Sep 12, 2018
4960e3a
removed printing
HourGlss Sep 12, 2018
a4855c5
removed printing, changed export
HourGlss Sep 12, 2018
b2626a0
removed printing, changed export
HourGlss Sep 12, 2018
4c96954
fixed block movement
HourGlss Sep 12, 2018
87809cf
Attempting to fix network
Sep 13, 2018
82be7d6
removed printing, changed export
HourGlss Sep 13, 2018
1addd1a
Attempting to fix network
Sep 13, 2018
d02241c
Attempting to fix network
Sep 13, 2018
60e09d0
removed printing, changed export
HourGlss Sep 13, 2018
5e4df41
removed printing, changed export
HourGlss Sep 13, 2018
7b8b040
removed printing, changed export
HourGlss Sep 13, 2018
d2d18b1
fixing networking
HourGlss Sep 13, 2018
a7ae380
Fixing networked mining
HourGlss Sep 14, 2018
4023b38
FIXING NETWORK
HourGlss Sep 14, 2018
24cad59
fixing networking
HourGlss Sep 14, 2018
517ca28
Fixing network
HourGlss Sep 14, 2018
8ce9bef
Fixing networking
HourGlss Sep 14, 2018
e02b2b4
Fixing networks
HourGlss Sep 14, 2018
8b9026d
Fixing networking
HourGlss Sep 14, 2018
ed3904d
Fixing networking
HourGlss Sep 14, 2018
dff7c25
Fix Networking
HourGlss Sep 14, 2018
d0f5289
removed printing, changed export
HourGlss Sep 14, 2018
fe0d32e
removed printing, changed export
HourGlss Sep 15, 2018
52c7826
fixing network
HourGlss Sep 15, 2018
676d83f
fixing network
HourGlss Sep 15, 2018
9a5f1f0
fixing network
HourGlss Sep 15, 2018
72e7d01
fix networking
HourGlss Sep 15, 2018
c31eae9
removed printing, changed export
HourGlss Sep 15, 2018
31627dc
removed printing, changed export
HourGlss Sep 15, 2018
77ab0ad
removed printing, changed export
HourGlss Sep 15, 2018
0abf395
fixing networking
HourGlss Sep 15, 2018
c57a852
fixed netorking?
HourGlss Sep 15, 2018
c857e1b
dammit
HourGlss Sep 15, 2018
2c1ecc1
dammit
HourGlss Sep 15, 2018
663bf04
removed printing, changed export
HourGlss Sep 15, 2018
6dc27c2
removed printing, changed export
HourGlss Sep 15, 2018
5950ea6
networking
HourGlss Sep 15, 2018
5c06aed
removed printing, changed export
HourGlss Sep 15, 2018
b89df0e
simplecoin is broken
HourGlss Sep 27, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
*.pyc
*.pyc
*scratch.py
xyf.txt
*user.py
*miner_config.py
69 changes: 1 addition & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1 @@
# SimpleCoin
Just a really simple, insecure and incomplete implementation of a blockchain for a cryptocurrency made in Python. The goal of this project is to make a working blockchain currency, keeping it as simple as possible and to be used as educational material.

>This project is just being made for fun. If you want to make your own cryptocurrency you should probably take a look at the [Bitcoin Repository](https://github.com/bitcoin/bitcoin).


## What is a blockchain?

Taking a look at the [Bitcoin organization wiki website](https://en.bitcoin.it/wiki/Main_Page) we can find this definition:

>A block chain is a transaction database shared by all nodes participating in a system based on the Bitcoin protocol. A full copy of a currency's block chain contains every transaction ever executed in the currency. With this information, one can find out how much value belonged to each address at any point in history.

You can find more information in the original [Bitcoin Paper](https://bitcoin.org/bitcoin.pdf).

## How to run it

First, install ```requirements.txt```.

```
pip install -r requirements.txt
```

Then you have 2 options:

- Run ```miner.py``` to become a node and start mining
- Run ```wallet.py``` to become a user and send transactions (to send transactions you must run a node, in other words, you must run ```miner.py``` too)

> Important: DO NOT run it in the python IDLE, run it in your console. The ```miner.py``` uses parallel processing that doesn't work in the python IDLE.

## How this code work?

There are 2 main scripts:

- ```miner.py```
- ```wallet.py```

### Miner.py

This file is probably the most important. Running it will create a node (like a server). From here you can connect to the blockchain and process transactions (that other users send) by mining. As a reward for this work, you recieve some coins. The more nodes exist, the more secure the blockchain gets.

```miner.py``` has 2 processes running in parallel:

1. The first process takes care of mining, updating new blockchains and finding the proof of work.

2. The second process runs the flask server where peer nodes and users can connect to ask for the entire blockchain or sumbmit new transactions.

> Parallel processes don't run in python IDLE, so make sure you are running it from the console.

![miner](https://k60.kn3.net/3/B/3/F/E/C/013.png)

### Wallet.py

This file is for those who don't want to be nodes but simple users. Running this file allows you to generate a new address, send coins and check your transaction history (keep in mind that if you are running this in a local server, you will need a "miner" to process your transaction).
When creating a wallet address, a new file will be generated with all your security credentials. You are supposed to keep it safe.

![wallet](https://k60.kn3.net/6/F/E/3/8/2/887.png)


## Contribution

Anybody is welcome to collaborate in this project. Feel free to push any pull request (even if you are new to coding). See ```CONTRIBUTING.md``` to learn how to contribute.

Note: the idea of this project is to build a **really simple** blockchain system, so make sure all your code is easy to read (avoid too much code in 1 line) and don't introduce complex updates if they are not critical. In other words, keep it simple.


## Disclaimer

By no means this project should be used for real purposes, it lacks security and may contain several bugs.
# SimpleCoin is fundamentally broken. HourCrypto is built on the same ideas, but works. look at that repo instead.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Flask
ecdsa
requests
flask-sqlalchemy
79 changes: 79 additions & 0 deletions simpleCoin/Block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import hashlib
import ast
class Block():
def __init__(self, index=-1, timestamp=-1, pow=-1, effort=-1,data=-1, previous_hash=-1):
"""Returns a new Block object. Each block is "chained" to its previous
by calling its unique hash.

Args:
index (int): Block number.
timestamp (int): Block creation timestamp.
data (dict): Data to be sent.
previous_hash(str): String representing previous block unique hash.

Attrib:
index (int): Block number.
timestamp (int): Block creation timestamp.
data (dict): Data to be sent.
previous_hash(str): String representing previous block unique hash.
hash(str): Current block unique hash.

"""
self.index = index
self.timestamp = timestamp

self.proof_of_work = pow
self.effort = effort
self.data = data
'''
data contains:
transactions: list
'''
self.previous_hash = previous_hash
self.hash = self.hash_block()

def hash_block(self):
"""Creates the unique hash for the block. It uses sha256."""
m = hashlib.sha256()
m.update((str(self.index) + str(self.timestamp) +str(self.proof_of_work)+ str(self.effort) + str(self.data) + str(self.previous_hash)).encode('utf-8'))
return m.hexdigest()

def exportjson(self):
return {
"index": str(self.index),
"timestamp": str(self.timestamp),
"pow": str(self.proof_of_work),
"effort": str(self.effort),
"data": str(self.data),
"previous": str(self.previous_hash),
"hash": str(self.hash)
}

def importjson(self,json):
self.index = int(json['index'])
self.timestamp = float(json['timestamp'])
self.proof_of_work = str(json['pow'])
self.effort = str(json['effort'])
self.data = ast.literal_eval(json['data'])
self.previous_hash = str(json['previous'])
self.hash = self.hash_block()

def __repr__(self):
#def __init__(self, index, timestamp, pow, effort,data, previous_hash):
return "Block({},{},'{}','{}',{},'{}')".format(self.index,self.timestamp,self.proof_of_work,self.effort,self.data,self.previous_hash)

def __str__(self):
return "i: {} time: {} \tpow: {} effort: {} data: {} \tprevious: {} hash: {}".format(self.index, self.timestamp,self.proof_of_work, self.effort, self.data, self.previous_hash, self.hash)

def buildpow(index,timestamp,effort,data,previous_hash):
m = hashlib.sha256()
m.update((str(index) + str(timestamp) + str(effort) + str(data) + str(previous_hash)).encode('utf-8'))
return m
def validate(block):
if block.index == 0:
return True
pow = buildpow(block.index,block.timestamp,block.effort,block.data,block.previous_hash)
if block.proof_of_work == pow.hexdigest():
return True
print("bad block",block.index)
return False
Loading