-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
53 lines (41 loc) · 1.24 KB
/
main.py
File metadata and controls
53 lines (41 loc) · 1.24 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
48
49
50
51
52
53
from blockchain import Blockchain
from block import Block
import uuid
BLOCK_SIZE = 25
if __name__=="__main__":
# init blockchain and genesis block
bc = Blockchain()
g = Block(BLOCK_SIZE)
# init addresses
bob = uuid.uuid4().hex
alice = uuid.uuid4().hex
trudy = uuid.uuid4().hex
# populate addresses with some cash through faucet
bc.faucet(bob)
bc.faucet(alice)
# check initial balances
print("Bob's balance: ", bc.get_balance(bob))
print("Alice's balance: ", bc.get_balance(alice))
# do some transactions
g.tx(bob, alice)
g.tx(bob, alice)
g.tx(bob, alice)
g.tx(bob, alice)
g.tx(alice, bob)
# add the genesis block
bc.add_block(g)
# add 100 empty blocks
for i in range(100):
bc.add_block(Block(BLOCK_SIZE))
# add some populated blocks
for i in range(50):
new = Block(BLOCK_SIZE)
new.tx(bob, trudy)
bc.add_block(new)
# check updated state (balances)
print("Bob's balance: ", bc.get_balance(bob))
print("Alice's balance: ", bc.get_balance(alice))
print("Trudy's balance: ", bc.get_balance(trudy))
# fetch some blocks from chain
genesis = bc.get_block(1)
hundreth = bc.get_block(100)