forked from p2pool/p2pool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_networks.py
60 lines (48 loc) · 1.58 KB
/
convert_networks.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import sys
f = open(sys.argv[1])
while True:
if f.readline().strip() == 'nets = dict(': break
def nesting(l):
res = 0
for c in l:
if c == '(': res += 1
if c == ')': res -= 1
return res
def write_header(f, name):
if sys.argv[3] == 'p2pool':
f2.write('from p2pool.bitcoin import networks\n\n')
if name == 'bitcoin':
f2.write('''# CHAIN_LENGTH = number of shares back client keeps
# REAL_CHAIN_LENGTH = maximum number of shares back client uses to compute payout
# REAL_CHAIN_LENGTH must always be <= CHAIN_LENGTH
# REAL_CHAIN_LENGTH must be changed in sync with all other clients
# changes can be done by changing one, then the other
''')
elif sys.argv[3] == 'bitcoin':
f2.write('''import os
import platform
from twisted.internet import defer
from .. import data, helper
from p2pool.util import pack
''')
else: assert False, 'invalid type argument'
while True:
l = f.readline()
if not l.strip(): continue
if l.strip() == ')': break
name = l.strip().split('=')[0]
lines = []
while True:
l = f.readline()
if not l.strip(): continue
if l.strip() == '),': break
while nesting(l) != 0:
l += f.readline()
lines.append(l.split('=', 1))
with open(sys.argv[2] + name + '.py', 'wb') as f2:
write_header(f2, name)
for a, b in lines:
if ', #' in b: b = b.replace(', #', ' #')
elif b.strip().endswith(','): b = b.strip()[:-1]
else: assert False, b
f2.write('%s = %s\n' % (a.strip(), b.strip()))