-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiner.py
More file actions
93 lines (82 loc) · 2.45 KB
/
Copy pathMiner.py
File metadata and controls
93 lines (82 loc) · 2.45 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import sys
sys.path.append('../')
import Rigs
from Rigs import Network
from Rigs import Node
import time
import ast
import socket
import time
BlockLength = 1
RECV_ADDR = '7ZAJEBDFLr8FYmBqKA8G5L2MMeRiJKPHQJTiircmuRoS'
#def SendTransaction(data):
#def Ping():
#def GetTransactions():
#def BlockChainLength():
#def CheckBlockChain(BCLength):
#def GetBlockChain():
#def SendBlock(block):
Network = Network.Network()
Node = Node.Node()
Node.Start()
def CheckBlockChain():
bc = Rigs.BlockChain()
data = bc.Load()
if(Network.CheckBlockChain(len(data)) == False):
print('[*] Found Larger BlockChain')
bc.blockchain = Network.GetBlockChain()
V = bc.VerifyBlockChain()
if(V):
print('[+] New BlockChain Saved')
bc.OverwriteSave()
else:
print('[-] New BlockChain Invalid: '+str(V))
def Add(transactions,get):
res = []
for i in transactions:
if i not in res:
res.append(i)
for i in get:
if i not in res:
res.append(i)
return res
def main():
transactions = []
while True:
MinedBlock = False
transactions = Add(transactions,Node.take)
Node.take = []
#print(transactions)
if(len(transactions) >= BlockLength):
print('[*] Got Enough Transactions for a Block')
bc = Rigs.BlockChain().Load()
try:
block = Rigs.Block(bc[-1]['hash'])
except:
block = Rigs.Block('0'*64)
for i in transactions:
block.AddRawTransaction(i)
transactions = []
MinedBlock = block.Mine(RECV_ADDR)
if(MinedBlock == True):
print('[+] Block Mined')
bc = Rigs.BlockChain()
bc.Load()
bc.AddBlock(block)
V = bc.VerifyBlockChain()
if(V != True):
print(V)
continue
bc.OverwriteSave()
#Network.SendBlock(block.Build())
#print('[*] Block Sent To Network')
print('[+] '+str(block.REWARD)+' Coins Earned')
else:
if(MinedBlock != False):
print(block.transactions)
print('[-] Block Invalid: '+str(MinedBlock))
time.sleep(5)
transactions = Add(transactions,Network.GetTransactions())
time.sleep(5)
CheckBlockChain()
main()