1
+ from jsonrpc import ServiceProxy
2
+ import sys
3
+ import string
4
+
5
+ # ===== BEGIN USER SETTINGS =====
6
+ # if you do not set these you will be prompted for a password for every command
7
+ rpcuser = ""
8
+ rpcpass = ""
9
+ # ====== END USER SETTINGS ======
10
+
11
+
12
+ if rpcpass == "" :
13
+ access = ServiceProxy ("http://127.0.0.1:8332" )
14
+ else :
15
+ access = ServiceProxy ("http://" + rpcuser + ":" + rpcpass + "@127.0.0.1:8332" )
16
+ cmd = sys .argv [1 ].lower ()
17
+
18
+ if cmd == "backupwallet" :
19
+ try :
20
+ path = raw_input ("Enter destination path/filename: " )
21
+ print access .backupwallet (path )
22
+ except :
23
+ print "\n ---An error occurred---\n "
24
+
25
+ elif cmd == "getaccount" :
26
+ try :
27
+ addr = raw_input ("Enter a Identifi address: " )
28
+ print access .getaccount (addr )
29
+ except :
30
+ print "\n ---An error occurred---\n "
31
+
32
+ elif cmd == "getaccountaddress" :
33
+ try :
34
+ acct = raw_input ("Enter an account name: " )
35
+ print access .getaccountaddress (acct )
36
+ except :
37
+ print "\n ---An error occurred---\n "
38
+
39
+ elif cmd == "getaddressesbyaccount" :
40
+ try :
41
+ acct = raw_input ("Enter an account name: " )
42
+ print access .getaddressesbyaccount (acct )
43
+ except :
44
+ print "\n ---An error occurred---\n "
45
+
46
+ elif cmd == "getbalance" :
47
+ try :
48
+ acct = raw_input ("Enter an account (optional): " )
49
+ mc = raw_input ("Minimum confirmations (optional): " )
50
+ try :
51
+ print access .getbalance (acct , mc )
52
+ except :
53
+ print access .getbalance ()
54
+ except :
55
+ print "\n ---An error occurred---\n "
56
+
57
+ elif cmd == "getblockbycount" :
58
+ try :
59
+ height = raw_input ("Height: " )
60
+ print access .getblockbycount (height )
61
+ except :
62
+ print "\n ---An error occurred---\n "
63
+
64
+ elif cmd == "getblockcount" :
65
+ try :
66
+ print access .getblockcount ()
67
+ except :
68
+ print "\n ---An error occurred---\n "
69
+
70
+ elif cmd == "getblocknumber" :
71
+ try :
72
+ print access .getblocknumber ()
73
+ except :
74
+ print "\n ---An error occurred---\n "
75
+
76
+ elif cmd == "getconnectioncount" :
77
+ try :
78
+ print access .getconnectioncount ()
79
+ except :
80
+ print "\n ---An error occurred---\n "
81
+
82
+ elif cmd == "getdifficulty" :
83
+ try :
84
+ print access .getdifficulty ()
85
+ except :
86
+ print "\n ---An error occurred---\n "
87
+
88
+ elif cmd == "getgenerate" :
89
+ try :
90
+ print access .getgenerate ()
91
+ except :
92
+ print "\n ---An error occurred---\n "
93
+
94
+ elif cmd == "gethashespersec" :
95
+ try :
96
+ print access .gethashespersec ()
97
+ except :
98
+ print "\n ---An error occurred---\n "
99
+
100
+ elif cmd == "getinfo" :
101
+ try :
102
+ print access .getinfo ()
103
+ except :
104
+ print "\n ---An error occurred---\n "
105
+
106
+ elif cmd == "getnewaddress" :
107
+ try :
108
+ acct = raw_input ("Enter an account name: " )
109
+ try :
110
+ print access .getnewaddress (acct )
111
+ except :
112
+ print access .getnewaddress ()
113
+ except :
114
+ print "\n ---An error occurred---\n "
115
+
116
+ elif cmd == "getreceivedbyaccount" :
117
+ try :
118
+ acct = raw_input ("Enter an account (optional): " )
119
+ mc = raw_input ("Minimum confirmations (optional): " )
120
+ try :
121
+ print access .getreceivedbyaccount (acct , mc )
122
+ except :
123
+ print access .getreceivedbyaccount ()
124
+ except :
125
+ print "\n ---An error occurred---\n "
126
+
127
+ elif cmd == "getreceivedbyaddress" :
128
+ try :
129
+ addr = raw_input ("Enter a Identifi address (optional): " )
130
+ mc = raw_input ("Minimum confirmations (optional): " )
131
+ try :
132
+ print access .getreceivedbyaddress (addr , mc )
133
+ except :
134
+ print access .getreceivedbyaddress ()
135
+ except :
136
+ print "\n ---An error occurred---\n "
137
+
138
+ elif cmd == "gettransaction" :
139
+ try :
140
+ txid = raw_input ("Enter a transaction ID: " )
141
+ print access .gettransaction (txid )
142
+ except :
143
+ print "\n ---An error occurred---\n "
144
+
145
+ elif cmd == "getwork" :
146
+ try :
147
+ data = raw_input ("Data (optional): " )
148
+ try :
149
+ print access .gettransaction (data )
150
+ except :
151
+ print access .gettransaction ()
152
+ except :
153
+ print "\n ---An error occurred---\n "
154
+
155
+ elif cmd == "help" :
156
+ try :
157
+ cmd = raw_input ("Command (optional): " )
158
+ try :
159
+ print access .help (cmd )
160
+ except :
161
+ print access .help ()
162
+ except :
163
+ print "\n ---An error occurred---\n "
164
+
165
+ elif cmd == "listaccounts" :
166
+ try :
167
+ mc = raw_input ("Minimum confirmations (optional): " )
168
+ try :
169
+ print access .listaccounts (mc )
170
+ except :
171
+ print access .listaccounts ()
172
+ except :
173
+ print "\n ---An error occurred---\n "
174
+
175
+ elif cmd == "listreceivedbyaccount" :
176
+ try :
177
+ mc = raw_input ("Minimum confirmations (optional): " )
178
+ incemp = raw_input ("Include empty? (true/false, optional): " )
179
+ try :
180
+ print access .listreceivedbyaccount (mc , incemp )
181
+ except :
182
+ print access .listreceivedbyaccount ()
183
+ except :
184
+ print "\n ---An error occurred---\n "
185
+
186
+ elif cmd == "listreceivedbyaddress" :
187
+ try :
188
+ mc = raw_input ("Minimum confirmations (optional): " )
189
+ incemp = raw_input ("Include empty? (true/false, optional): " )
190
+ try :
191
+ print access .listreceivedbyaddress (mc , incemp )
192
+ except :
193
+ print access .listreceivedbyaddress ()
194
+ except :
195
+ print "\n ---An error occurred---\n "
196
+
197
+ elif cmd == "listtransactions" :
198
+ try :
199
+ acct = raw_input ("Account (optional): " )
200
+ count = raw_input ("Number of transactions (optional): " )
201
+ frm = raw_input ("Skip (optional):" )
202
+ try :
203
+ print access .listtransactions (acct , count , frm )
204
+ except :
205
+ print access .listtransactions ()
206
+ except :
207
+ print "\n ---An error occurred---\n "
208
+
209
+ elif cmd == "move" :
210
+ try :
211
+ frm = raw_input ("From: " )
212
+ to = raw_input ("To: " )
213
+ amt = raw_input ("Amount:" )
214
+ mc = raw_input ("Minimum confirmations (optional): " )
215
+ comment = raw_input ("Comment (optional): " )
216
+ try :
217
+ print access .move (frm , to , amt , mc , comment )
218
+ except :
219
+ print access .move (frm , to , amt )
220
+ except :
221
+ print "\n ---An error occurred---\n "
222
+
223
+ elif cmd == "sendfrom" :
224
+ try :
225
+ frm = raw_input ("From: " )
226
+ to = raw_input ("To: " )
227
+ amt = raw_input ("Amount:" )
228
+ mc = raw_input ("Minimum confirmations (optional): " )
229
+ comment = raw_input ("Comment (optional): " )
230
+ commentto = raw_input ("Comment-to (optional): " )
231
+ try :
232
+ print access .sendfrom (frm , to , amt , mc , comment , commentto )
233
+ except :
234
+ print access .sendfrom (frm , to , amt )
235
+ except :
236
+ print "\n ---An error occurred---\n "
237
+
238
+ elif cmd == "sendmany" :
239
+ try :
240
+ frm = raw_input ("From: " )
241
+ to = raw_input ("To (in format address1:amount1,address2:amount2,...): " )
242
+ mc = raw_input ("Minimum confirmations (optional): " )
243
+ comment = raw_input ("Comment (optional): " )
244
+ try :
245
+ print access .sendmany (frm ,to ,mc ,comment )
246
+ except :
247
+ print access .sendmany (frm ,to )
248
+ except :
249
+ print "\n ---An error occurred---\n "
250
+
251
+ elif cmd == "sendtoaddress" :
252
+ try :
253
+ to = raw_input ("To (in format address1:amount1,address2:amount2,...): " )
254
+ amt = raw_input ("Amount:" )
255
+ comment = raw_input ("Comment (optional): " )
256
+ commentto = raw_input ("Comment-to (optional): " )
257
+ try :
258
+ print access .sendtoaddress (to ,amt ,comment ,commentto )
259
+ except :
260
+ print access .sendtoaddress (to ,amt )
261
+ except :
262
+ print "\n ---An error occurred---\n "
263
+
264
+ elif cmd == "setaccount" :
265
+ try :
266
+ addr = raw_input ("Address: " )
267
+ acct = raw_input ("Account:" )
268
+ print access .setaccount (addr ,acct )
269
+ except :
270
+ print "\n ---An error occurred---\n "
271
+
272
+ elif cmd == "setgenerate" :
273
+ try :
274
+ gen = raw_input ("Generate? (true/false): " )
275
+ cpus = raw_input ("Max processors/cores (-1 for unlimited, optional):" )
276
+ try :
277
+ print access .setgenerate (gen , cpus )
278
+ except :
279
+ print access .setgenerate (gen )
280
+ except :
281
+ print "\n ---An error occurred---\n "
282
+
283
+ elif cmd == "settxfee" :
284
+ try :
285
+ amt = raw_input ("Amount:" )
286
+ print access .settxfee (amt )
287
+ except :
288
+ print "\n ---An error occurred---\n "
289
+
290
+ elif cmd == "stop" :
291
+ try :
292
+ print access .stop ()
293
+ except :
294
+ print "\n ---An error occurred---\n "
295
+
296
+ elif cmd == "validateaddress" :
297
+ try :
298
+ addr = raw_input ("Address: " )
299
+ print access .validateaddress (addr )
300
+ except :
301
+ print "\n ---An error occurred---\n "
302
+
303
+ elif cmd == "walletpassphrase" :
304
+ try :
305
+ pwd = raw_input ("Enter wallet passphrase: " )
306
+ access .walletpassphrase (pwd , 60 )
307
+ print "\n ---Wallet unlocked---\n "
308
+ except :
309
+ print "\n ---An error occurred---\n "
310
+
311
+ elif cmd == "walletpassphrasechange" :
312
+ try :
313
+ pwd = raw_input ("Enter old wallet passphrase: " )
314
+ pwd2 = raw_input ("Enter new wallet passphrase: " )
315
+ access .walletpassphrasechange (pwd , pwd2 )
316
+ print
317
+ print "\n ---Passphrase changed---\n "
318
+ except :
319
+ print
320
+ print "\n ---An error occurred---\n "
321
+ print
322
+
323
+ else :
324
+ print "Command not found or not supported"
0 commit comments