Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afab0fe059 | ||
|
|
ec9f0e1b36 | ||
|
|
f55195618f | ||
|
|
bec6a801bf | ||
|
|
fe8edb6a00 | ||
|
|
9de5492201 |
@@ -0,0 +1,5 @@
|
||||
.git
|
||||
docker-compose.yml
|
||||
Dockerfile
|
||||
README.md
|
||||
test
|
||||
@@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from time import time
|
||||
from flask import Flask, request
|
||||
import json
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
"""Block chain according to me."""
|
||||
|
||||
import hashlib
|
||||
from time import time
|
||||
import json
|
||||
@@ -8,6 +11,7 @@ DIFFICULTY = 4
|
||||
|
||||
|
||||
class Block:
|
||||
"""Block according to me."""
|
||||
def __init__(self, index, timestamp, transactions, previous_hash, proof):
|
||||
self.index = index
|
||||
self.timestamp = timestamp
|
||||
@@ -17,6 +21,7 @@ class Block:
|
||||
self.hash = self.hash()
|
||||
|
||||
def hash(self):
|
||||
"""Hash a block using sha256."""
|
||||
data = self.__dict__
|
||||
data["transactions"] = [t.__dict__ for t in self.transactions]
|
||||
block_string = json.dumps(data, sort_keys=True).encode()
|
||||
@@ -27,16 +32,19 @@ class Block:
|
||||
|
||||
|
||||
class Transaction:
|
||||
"""Transaction of Samy coin."""
|
||||
def __init__(self, sender, recipient, amount):
|
||||
self.sender = sender
|
||||
self.recipient = recipient
|
||||
self.amount = amount
|
||||
|
||||
def __str__(self):
|
||||
"""String representation of a transaction."""
|
||||
return f"FROM: {self.sender} TO: {self.recipient} AMOUNT: {self.amount}"
|
||||
|
||||
|
||||
class Blockchain:
|
||||
"""Blockchain"""
|
||||
def __init__(self):
|
||||
self.blocks = []
|
||||
self.blocks.append(self.create_first_block())
|
||||
|
||||
Reference in New Issue
Block a user