generated from Quang7hong81/bitcoin.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cryptotool
60 lines (58 loc) · 1.65 KB
/
cryptotool
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
#!/usr/bin/python
from cryptos import *
import json
coins = {
'bch': BitcoinCash,
'btc': Bitcoin,
'dash': Dash,
'doge': Doge,
'ltc': Litecoin
}
if len(sys.argv) == 1:
print("pybtctool <command> <arg1> <arg2> ...")
else:
coin = Bitcoin
testnet = False
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] == '--testnet':
testnet = True
i += 1
elif sys.argv[i] == '--coin':
coinname = sys.argv[i+1].lower()
try:
coin = coins[coinname]
except KeyError:
raise Exception('Coin %s not recognised. Choose from: %s ' % (coin, ','.join(coins.keys())))
i += 2
elif 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:]
try:
c = coin(testnet=testnet)
o = getattr(c, cmd)(*args, **kwargs)
except AttributeError:
o = vars()[cmd](*args, **kwargs)
if isinstance(o, (list, dict)):
print(json.dumps(o))
else:
print(o)