forked from vbuterin/pybitcointools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pybtctool
executable file
·36 lines (35 loc) · 1.02 KB
/
pybtctool
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
#!/usr/bin/python
import sys, json, re
from bitcoin import *
if len(sys.argv) == 1:
print "pybtctool <command> <arg1> <arg2> ..."
else:
cmdargs, preargs, kwargs = [], [], {}
i = 2
# Process first arg tag
if sys.argv[1] == '-s':
preargs.extend(re.findall(r'\S\S*', sys.stdin.read()))
elif sys.argv[1] == '-B':
preargs.extend([sys.stdin.read()])
elif sys.argv[1] == '-b':
preargs.extend([sys.stdin.read()[:-1]])
elif sys.argv[1] == '-j':
preargs.extend([json.loads(sys.stdin.read())])
elif sys.argv[1] == '-J':
preargs.extend(json.loads(sys.stdin.read()))
else:
i = 1
while i < len(sys.argv):
if sys.argv[i][:2] == '--':
kwargs[sys.argv[i][2:]] = sys.argv[i+1]
i += 2
else:
cmdargs.append(sys.argv[i])
i += 1
cmd = cmdargs[0]
args = preargs + cmdargs[1:]
o = vars()[cmd](*args, **kwargs)
if isinstance(o, (list, dict)):
print json.dumps(o)
else:
print o