forked from siddharthkul/coffee-coin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlock.py
30 lines (26 loc) · 1.05 KB
/
Block.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import hashlib as hasher
import datetime as date
# We define a block and the genesis block creation method within this file to enfore
# modularity
# Originally adapted from [https://gist.github.com/aunyks/47d157f8bc7d1829a729c2a6a919c173]
# Authored by Siddharth Kulkarni and Sharan Duggirala November 18th, 2017
# Define what a Coffeecoin block is, and what it contains as a class
class Block:
def __init__(self, index, timestamp, data, previous_hash):
self.index = index
self.timestamp = timestamp
self.data = data
self.previous_hash = previous_hash
self.hash = self.hash_block()
# Currently using the SHA 256 Hashing function #### THIS SHOULD BE MODIFIED ####
def hash_block(self):
sha = hasher.sha256()
sha.update(str(self.index) + str(self.timestamp) + str(self.data) + str(self.previous_hash))
return sha.hexdigest()
# Generate genesis block
def create_genesis_block():
# Manually construct a block with
# index zero and arbitrary previous hash
return Block(0, date.datetime.now(), {
"transactions": None
}, "0")