-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
47 lines (40 loc) · 1.21 KB
/
script.py
File metadata and controls
47 lines (40 loc) · 1.21 KB
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
from blockchain import Blockchain
# The blockchain I have built only exists on a local machine
# It is important to know that actual blockchain applications
# operate on multiple computers in a decentralized manner
block_one_transactions = {
"sender": "Xava",
"receiver": "Neill",
"amount": "100"
}
block_two_transactions = {
"sender": "Neill",
"receiver": "Michael",
"amount": "20"
}
block_three_transactions = {
"sender": "Neill",
"receiver": "Jason",
"amount": "50"
}
fake_transactions = {
"sender": "Neill",
"receiver": "Michael",
"amount": "0"
}
# create a local blockchain instance from Blockchain class
local_blockchain = Blockchain()
# adds three blocks with transactions
local_blockchain.add_block(block_one_transactions)
local_blockchain.add_block(block_two_transactions)
local_blockchain.add_block(block_three_transactions)
# prints all blocks
local_blockchain.print_blocks()
# checks that blockchain is valid - returns valid
local_blockchain.validate_chain()
# changes a block
local_blockchain.chain[2].transactions = fake_transactions
# prints all blocks
local_blockchain.print_blocks()
# checks that blockchain is valid - returns invalid
local_blockchain.validate_chain()