Author SHA1 Message Date
marc afab0fe059 started the fix 2022-02-23 21:59:45 +01:00
Samy Haffoudhi ec9f0e1b36 Merge pull request #4 from MarcPartensky/dockerignore
dockerignore
2022-02-23 21:31:10 +01:00
Samy Haffoudhi f55195618f Merge pull request #3 from MarcPartensky/pipenv
pipenv
2022-02-23 21:30:23 +01:00
marc bec6a801bf dockerignore 2022-02-23 21:30:15 +01:00
Samy Haffoudhi fe8edb6a00 Merge pull request #2 from MarcPartensky/shebang
shebang
2022-02-23 21:27:19 +01:00
marc 9de5492201 shebang 2022-02-23 21:24:49 +01:00
3 changed files with 15 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
.git
docker-compose.yml
Dockerfile
README.md
test
+2
View File
@@ -1,3 +1,5 @@
#!/usr/bin/env python
from time import time
from flask import Flask, request
import json
+8
View File
@@ -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())