Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryandsilva/blockchain-simulation
Simulation of A BlockChain in the Python Programming Language :sparkles:
https://github.com/ryandsilva/blockchain-simulation
blockchain cryptocurrency css flask html javascript mining proof-of-work python sha256 simulation vuejs web-application
Last synced: about 21 hours ago
JSON representation
Simulation of A BlockChain in the Python Programming Language :sparkles:
- Host: GitHub
- URL: https://github.com/ryandsilva/blockchain-simulation
- Owner: RyanDsilva
- License: apache-2.0
- Created: 2018-09-13T09:51:53.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-03T17:01:32.000Z (over 5 years ago)
- Last Synced: 2024-04-24T07:14:32.937Z (5 months ago)
- Topics: blockchain, cryptocurrency, css, flask, html, javascript, mining, proof-of-work, python, sha256, simulation, vuejs, web-application
- Language: Python
- Homepage:
- Size: 112 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Blockchain Simulation (CryptoCurrency)
### Simulation of A BlockChain in the Python Programming Language
## Features:
[1. SHA-256 Hashing](#sha-256)
[2. Proof Of Work](#proof-of-work)
[3. Mining Rewards](#mining-rewards)
---
## Implemenation:
### SHA-256
- Using Python's in-built `hashlib` library to hash the blocks with SHA-256
```python
# Creating the String
hashString = str(nonce) + str(transaction) + ..
# Converting to Bytes
hashString = hashString.encode()
# Hashing
currentHash = hashlib.sha256(hashString)
```### Proof Of Work
- Proof Of Work is a concept that allows the blockchain not to be spammed by thousands of pending blocks every second.
- It sets a requirement that the hash generated has to be in a specific format
- For example, hash should start with 0000
- In this example you can set the `PROOF_OF_WORK` value```python
#Checking whether the first characters of hash are equal to the proof of work
while currentHash[:len(PROOF_OF_WORK)] != PROOF_OF_WORK:
#Update Nonce
nonce += 1
#Re-calculate Hash
currentHash = calculateHash()
```- Since the hash cannot be changed without changing any value in the block, a `nonce` value is added that can be modified to calculate hash according to requirements.
### Mining Rewards
- Because of this proof of work concept, it takes resources to `mine` blocks and hence miners need to be rewarded for this in order to add blocks at a constant rate and help maintain the blockchain.
- The mining reward is pre-defined value for that specific block.```python
# After the block is mined, pending transactions is set to have just the reward transaction
def minePendingTransactions(address):
......
block.mineBlock(PROOF_OF_WORK)
# Adding to chain
blocks.append(block)
# Reward Transaction
pendingTransactions = [Transaction(address, None, miningReward)]
```---
## References:
[Savjee Coin](https://github.com/SavjeeTutorials/SavjeeCoin)
> © 2018 Ryan Dsilva