-
Notifications
You must be signed in to change notification settings - Fork 0
/
nugget.py
62 lines (43 loc) · 1.55 KB
/
nugget.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#Impot
import hashlib
#open nugget blockchain
f = open('Blockchain/1.block', "w")
g = open('Blockchain/2.block', "w")
h = open('Blockchain/3.block', "w")
#Block ///every block contains 2 transactions
class NuggetCoinBlock:
def __init__(self, previous_block_hash, transaction_list):
self.previous_block_hash = previous_block_hash
self.transaction_list = transaction_list
self.block_data = "\n-\n".join(transaction_list) + "\n-\n" + previous_block_hash
self.block_hash = hashlib.sha256(self.block_data.encode()).hexdigest()
#transactions
t1 = "Michael sends 2 NC to Eli"
t2 = "Luke sends 4 NC to Cain"
t3 = "Martin sends 67 NC to Passi"
t4 = "Thomas sends 0.3 NC to Eli"
t5 = "Passi sends 42.8 NC to Martin"
t6 = "Cain sends 17 NC to Luke"
# 2 transactions per block
#initial Block (first block)
initial_block = NuggetCoinBlock("Initial Sctring", [t1, t2])
print(initial_block.block_data)
print(initial_block.block_hash + "\n")
print("")
f.write(initial_block.block_hash)
#second block
second_block = NuggetCoinBlock(initial_block.block_hash, [t3, t4])
print(second_block.block_data)
print(second_block.block_hash + "\n")
print("")
g.write(initial_block.block_hash + "\n" + second_block.block_hash)
#third block
third_block = NuggetCoinBlock(initial_block.block_hash, [t5, t6])
print(third_block.block_data)
print(third_block.block_hash + "\n")
print("")
h.write(second_block.block_hash + "\n" + third_block.block_hash)
#close nugget blockchain
f.close()
g.close()
h.close()