-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (38 loc) · 1.04 KB
/
main.py
File metadata and controls
41 lines (38 loc) · 1.04 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
from blockchain.Blockchain import Blockchain
from blockchain.TX import TX
from blockchain.NodeMaster import NodeMaster
import time
import json
master = NodeMaster()
nodeA = master.generate_node("127.0.0.1", 5001)
nodeB = master.generate_node("127.0.0.1", 5002)
nodeC = master.generate_node("127.0.0.1", 5003)
nodeD = master.generate_node("127.0.0.1", 5004)
nodeA.start()
nodeB.start()
nodeC.start()
nodeD.start()
nodeA.send("127.0.0.1", 5001, "hello")
bc = Blockchain()
a = bc.create_wallet()
a.balance = 105
bc.init_system_account()
bc.transact(a.send("REC", 10))
bc.transact(a.send("REC", 10))
bc.transact(a.send("REC", 10))
bc.transact(a.send("REC", 10))
bc.transact(a.send("REC", 10))
print(a.balance)
block = bc.chain[1].to_dict()
tx = bc.chain[1].transactions[0].to_dict()
TX(a.address, a.public_key, "REC", 10).from_dict(tx)
try:
time.sleep(2)
nodeA.send("127.0.0.1", 5002,json.dumps({"from":"nodeA","message":"hi"}))
while True:
time.sleep(1)
except KeyboardInterrupt:
nodeA.kill()
nodeB.kill()
nodeC.kill()
nodeD.kill()