-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaddBlock.py
41 lines (31 loc) · 1.14 KB
/
addBlock.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
import hashlib as hasher
import datetime as date
#importing the block
from block import Block
#importing the chain
import jupiter_block as jb
import pluto_block as pb
import neptune_block as nb
# Generate all later blocks in the blockchain
def next_block(last_block):
this_index = last_block.index + 1
this_timestamp = date.datetime.now()
this_data = last_block.data
this_hash = last_block.hash
return Block(this_index, this_timestamp, this_data, this_hash)
# Create the blockchain and add the genesis block
blockchain = [jb.create_jupiter_block()]
previous_block = blockchain[0]
# How many blocks should we add to the chain
# after the genesis block
num_of_blocks_to_add = 20
# Add blocks to the chain
for i in range(0, num_of_blocks_to_add):
block_to_add = next_block(previous_block)
blockchain.append(block_to_add)
previous_block = block_to_add
# Tell everyone about it
print("Block #{} added ".format(block_to_add.data))
print("Hash: {}".format(block_to_add.hash))
print("TimeStamp: {}".format(block_to_add.timestamp))
print("Previous hash: {} \n".format(block_to_add.previous_hash))