This repository has been archived by the owner on Jul 2, 2022. It is now read-only.
/
smartcoin
executable file
·122 lines (96 loc) · 2.68 KB
/
smartcoin
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/python
#
# smartcoin
#
# Distributed under the MIT/X11 software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
import sys
import re
import gdbm
import scdb
import scsettings
import scjson
import Log
def smartcoin_create(db, log, settings):
try:
filename = settings.d['f']
except KeyError:
filename = 'input.json'
issue = scjson.jsonfile_to_issue(filename)
if issue is None:
log.write("cannot convert " + filename + " to JSON issue")
return
id = issue.display_shortname
if id in db.issues:
log.write("issue already exists with that name")
return
db.put_issue(issue)
print "OK"
def smartcoin_delete(db, log, settings):
try:
id = settings.d['id']
except KeyError:
log.write("Missing 'id' key for deletion")
return
rc = db.del_issue(id)
if rc:
print "OK"
else:
print "FAIL"
def smartcoin_show(db, log, settings):
try:
id = settings.d['id']
except KeyError:
log.write("Missing 'id' key for show")
return
issue = db.get_issue(id)
if not issue:
print "FAIL"
print str(issue)
def smartcoin_issues(db, log, settings):
for name in db.issues:
print name
if __name__ == '__main__':
settings = scsettings.Settings()
settings.read(sys.argv)
if 'smartcoin_rpchost' not in settings.d:
settings.d['smartcoin_rpchost'] = '127.0.0.1'
if 'smartcoin_rpcport' not in settings.d:
settings.d['smartcoin_rpcport'] = 19332
if 'payment_rpchost' not in settings.d:
settings.d['payment_rpchost'] = '127.0.0.1'
if 'payment_rpcport' not in settings.d:
settings.d['payment_rpcport'] = 18332
if 'db' not in settings.d:
settings.d['db'] = './smartcoin.db'
if 'chain' not in settings.d:
settings.d['chain'] = 'testnet3'
chain = settings.d['chain']
if 'log' not in settings.d or (settings.d['log'] == '-'):
settings.d['log'] = None
if ('smartcoin_rpcuser' not in settings.d or
'smartcoin_rpcpass' not in settings.d or
'payment_rpcuser' not in settings.d or
'payment_rpcpass' not in settings.d):
print "You must set the following in config: {payment,smartcoin}_rpc{user,pass}"
sys.exit(1)
settings.d['smartcoin_rpcport'] = int(settings.d['smartcoin_rpcport'])
settings.d['payment_rpcport'] = int(settings.d['payment_rpcport'])
log = Log.Log(settings.d['log'])
log.write("\n\n\n\n")
db = scdb.SCDb(settings.d['db'], log)
if 'mode' in settings.d:
mode = settings.d['mode']
elif 'm' in settings.d:
mode = settings.d['m']
else:
mode = None
if mode == 'create':
smartcoin_create(db, log, settings)
elif mode == 'delete':
smartcoin_delete(db, log, settings)
elif mode == 'show':
smartcoin_show(db, log, settings)
elif mode == 'issues':
smartcoin_issues(db, log, settings)