-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcoin-jumble.py
589 lines (505 loc) · 25.6 KB
/
coin-jumble.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
'''
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import sys, base64, textwrap, re, datetime, traceback, string
from decimal import Decimal
from PyQt4 import QtCore
from PyQt4.QtGui import *
from bitcoin import *
#https://gist.github.com/e000/869791
import socks
from socksipyhandler import SocksiPyHandler
#TODO get all the url lookups out of the GUI thread, make a worker thread that waits on a queue and executes a
# function pointer, so do all your work with lambda functions
#MORE THOUGHTS
# use a new tor circuit for each tx part. i asked on #tor and its pointless for hidden services
# cache invalidated when app closed
# what is the point of ascii armor? really?
# answer= checksum, small size since b64, short line width, for larger tx the head/foot organises it i.e. a label
# for really small tx like on irc you can remove the head/foot
# allow changing width of textwrap in ascii_armor() in settings e.g. 500 for irc
# tx fee label in signoff
def get_network():
if settingsTab.useTestnetCheckbox.checkState() == QtCore.Qt.Checked:
return 'testnet'
else:
return 'btc'
def get_vbyte():
if get_network() == 'testnet':
return 0x6f
else:
return 0x00
CACHE_TTL = datetime.timedelta(1) #one day
fetchtx_cache_mem = {}
#TODO tell vbuterin to include network='btc' in fetchtx()
#TODO cache to a file too
#TODO cache unspent() calls too
def blockr_fetchtx_cache(txhash, network='btc'):
if txhash in fetchtx_cache_mem:
if datetime.datetime.strptime(fetchtx_cache_mem[txhash]['expire'], '%Y/%m/%d %H:%M:%S') > datetime.datetime.now():
return fetchtx_cache_mem[txhash]['tx'] #cache valid
else:
del fetchtx_cache_mem[txhash] #cache expired
tx = blockr_fetchtx(txhash, network)
fetchtx_cache_mem[txhash] = {'tx': tx, 'expire': (datetime.datetime.now() + CACHE_TTL).strftime('%Y/%m/%d %H:%M:%S')}
return tx
#TODO line breaks could be a cross-platform problem... test
BITCOIN_ASCII_ARMOR_HEADER = '-----BEGIN BITCOIN RAW TRANSACTION-----'
BITCOIN_ASCII_ARMOR_FOOTER = '-----END BITCOIN RAW TRANSACTION-----'
TESTNET_ASCII_ARMOR_HEADER = '-----BEGIN TESTNET BITCOIN RAW TRANSACTION-----'
TESTNET_ASCII_ARMOR_FOOTER = '-----END TESTNET BITCOIN RAW TRANSACTION-----'
def get_ascii_head_foot(network):
head = BITCOIN_ASCII_ARMOR_HEADER
foot = BITCOIN_ASCII_ARMOR_FOOTER
if network == 'testnet':
head = TESTNET_ASCII_ARMOR_HEADER
foot = TESTNET_ASCII_ARMOR_FOOTER
return head, foot
def ascii_armor_tx_ex(tx, network, lineWidth):
txb = tx.decode('hex')
b64tx = base64.b64encode(txb + bin_dbl_sha256(txb)[:4])
b64wrapped = textwrap.fill(b64tx, lineWidth)
head, foot = get_ascii_head_foot(network)
return head + '\n' + b64wrapped + '\n' + foot
def ascii_armor_tx(tx):
return ascii_armor_tx_ex(tx, get_network(), settingsTab.asciiArmorLengthEdit.value())
#TypeError for a bad base64 bit (char not in charset, say)
#raises TypeError if somethings wrong
def unascii_armor_tx_ex(armor, network):
armor = textwrap.dedent(armor).strip()
head, foot = get_ascii_head_foot(network)
if not armor.startswith(head) or \
not armor.endswith(foot):
raise TypeError('Bad header/footer lines. Are you on the right network? (testnet / mainnet)')
for w in string.whitespace:
armor = armor.replace(w, '')
head = head.replace(w, '')
foot = foot.replace(w, '')
armor = armor[len(head):] #strip header
armor = armor[:-len(foot)]
payload = base64.b64decode(armor)
tx = payload[:-4]
checksum = bin_dbl_sha256(tx)[:4]
p_checksum = payload[-4:]
if checksum != p_checksum:
raise TypeError('Bad checksum')
return tx.encode('hex')
def unascii_armor_tx(armor):
return unascii_armor_tx_ex(armor, get_network())
def unascii_armor_tx_gui(parent, armor):
try:
if re.match('^[0-9a-fA-F]*$', armor):
return armor
else:
return unascii_armor_tx(armor)
except TypeError as e:
QMessageBox.critical(parent, 'Error', str(e))
return None
class QLabelSelectable(QLabel):
def __init__(self, *args, **kwargs):
super(QLabelSelectable, self).__init__(*args, **kwargs)
self.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
class ListUnspentCoinsTab(QScrollArea):
def __init__(self):
super(ListUnspentCoinsTab, self).__init__()
self.initUI()
#list of a few utxo addresses to try
#1G6sQHBvKobCuCcF8z8ZnYHQUqDyHaqDzy - 1 utxo
#1PYcCM1TgkX995oqEFEHLa6oMJjTKZUdM3 - 3 utxo
#3M8XGFBKwkf7miBzpkU3x2DoWwAVrD1mhk - 55 utxo, the coinjoin bounty address
def initUI(self): #TODO have a look at using QFormLayout here
listUnspentTab = QWidget()
self.setWidget(listUnspentTab)
self.setWidgetResizable(True)
self.grid = QGridLayout()
listUnspentTab.setLayout(self.grid)
self.grid.setSpacing(10)
self.grid.addWidget(QLabel('Address :'), 1, 0)
self.addressInputEdit = QLineEdit()
self.grid.addWidget(self.addressInputEdit, 1, 1)
listCoinsButton = QPushButton("List Unspent Coins")
listCoinsButton.clicked.connect(self.clickedListCoinsButton)
self.grid.addWidget(listCoinsButton, 1, 2)
self.unspentCoinDisplayList = []
def clickedListCoinsButton(self, checked):
for ucdl in self.unspentCoinDisplayList:
for wid in ucdl:
self.grid.removeWidget(wid)
wid.hide()
self.unspentCoinDisplayList = []
#TODO check for well-formed address, check if its p2sh and explain this program cant do that yet
#TODO suggest to vbuterin that b58check_to_bin() raise another exception instead of Assertion since its not so great to catch
utxos = blockr_unspent(str(self.addressInputEdit.text()), get_network())
print(str(len(utxos)) + ' found utxo')
for utxo in utxos: #TODO value needs to go in a QLineEdit so it can be copypasted away
unspentCoinDisplay = ( #not so urgent though since most people will be coinjoining round numbers
QLabelSelectable('Value: ' + str(Decimal(utxo['value'])/Decimal(1e8)) + 'btc'),
#TODO create subclass of QLineEdit that isnt editable and highlights it when you click
#plus right-click option to copy, and responds to ctrl+c
QLineEdit(utxo['output'])
)
unspentCoinDisplay[1].setReadOnly(True)
self.unspentCoinDisplayList.append(unspentCoinDisplay)
for i in range(2):
self.grid.addWidget(unspentCoinDisplay[i], len(self.unspentCoinDisplayList)+1, i)
#TODO this maybe needs a way to edit a tx, so if you make a mistake you dont have to start
# over again copypasting in utxos
class CreateTransactionPartTab(QWidget):
def __init__(self):
super(CreateTransactionPartTab, self).__init__()
self.initUI()
def initUI(self):
self.grid = QGridLayout()
self.setLayout(self.grid)
self.grid.setSpacing(10)
columns = [0, 2, 3]
charCounts = [66, 36, 7] #expected number of chars in that QLineEdit
dummy = QLineEdit()
for c, cc in zip(columns, charCounts):
self.grid.setColumnMinimumWidth(c, dummy.fontMetrics().boundingRect('U'*cc).width())
#self.grid.setColumnMinimumWidth(0, 480)
#self.grid.setColumnMinimumWidth(2, 270)
#self.grid.setColumnMinimumWidth(3, 10)
#USE QSPLITTER HERE ?
self.txEdit = QPlainTextEdit(self)
self.txEdit.setLineWrapMode(QPlainTextEdit.WidgetWidth)
self.grid.addWidget(self.txEdit, 0, 0, 1, 4)
createTxPartButton = QPushButton('Create Tx Part', self)
createTxPartButton.clicked.connect(self.clickedCreateTxPartButton)
self.grid.addWidget(createTxPartButton, 1, 0, 1, 4)
addUnspentCoinButton = QPushButton('Add Unspent Coin', self)
addUnspentCoinButton.clicked.connect(self.clickedAddUnspentCoinButton)
self.grid.addWidget(addUnspentCoinButton, 2, 0, 1, 2)
addOutputButton = QPushButton('Add Output', self)
addOutputButton.clicked.connect(self.clickedAddOutputButton)
self.grid.addWidget(addOutputButton, 2, 2, 1, 2)
self.grid.addWidget(QLabel('Unspent Coins'), 3, 0, 1, 2, QtCore.Qt.AlignHCenter)
self.grid.addWidget(QLabel('Output Address'), 3, 2, 1, 1, QtCore.Qt.AlignHCenter)
self.grid.addWidget(QLabel('Output Value/btc'), 3, 3, 1, 1, QtCore.Qt.AlignHCenter)
self.unspentCoinEditList = []
self.outputEditList = []
#for i in range(self.grid.columnCount()):
# print('i, mWidth, stretch = ' + str(i) + ', ' +
# str(self.grid.columnMinimumWidth(i)) + ', ' + str(self.grid.columnStretch(i)))
def clickedCreateTxPartButton(self, checked):
utxo = []
for ucel in self.unspentCoinEditList:
newutxo = str(ucel.text()).strip()
if len(newutxo) < 66 or not re.match('^[0-9a-fA-F:]*$', newutxo) or\
newutxo[64] != ':' or not newutxo[65:].isdigit():
QMessageBox.critical(self, 'Create Transaction Part', 'Invalid unspent coin format',
QMessageBox.Ok, QMessageBox.NoButton)
return
utxo.append({'output': newutxo})
self.grid.removeWidget(ucel)
ucel.hide()
self.unspentCoinEditList = []
outs = [] #TODO verify formats of all these inputs
for oel in self.outputEditList:
addr = str(oel[0].text()).strip()
#use Decimal for accounting numbers
value = int( Decimal(str(oel[1].text()).strip()) * Decimal(1e8) )
if addr != '' and value != '':
outs.append( {'address': addr, 'value': value} )
for wid in oel:
self.grid.removeWidget(wid)
wid.hide()
self.outputEditList = []
try:
self.txEdit.setPlainText(ascii_armor_tx(mktx(utxo, outs)))
except RuntimeError as e:
traceback.print_exc()
QMessageBox.critical(self, 'Create Transaction Part', 'Runtime Error with make transaction. See terminal.',
QMessageBox.Ok, QMessageBox.NoButton)
self.txEdit.selectAll()
def clickedAddUnspentCoinButton(self, checked):
new_utxoEdit = QLineEdit()
self.grid.addWidget(new_utxoEdit, len(self.unspentCoinEditList) + 4, 0, 1, 2)
self.unspentCoinEditList.append(new_utxoEdit)
def clickedAddOutputButton(self, checked):
new_output = (QLineEdit(), QLineEdit())
self.grid.addWidget(new_output[0], len(self.outputEditList) + 4, 2, 1, 1)
self.grid.addWidget(new_output[1], len(self.outputEditList) + 4, 3, 1, 1)
self.outputEditList.append(new_output)
class CombineTransactionPartsTab(QWidget):
def __init__(self):
super(CombineTransactionPartsTab, self).__init__()
self.initUI()
def initUI(self):
grid = QGridLayout()
self.setLayout(grid)
grid.setSpacing(10)
self.txEdit = QPlainTextEdit(self)
self.txEdit.setLineWrapMode(QPlainTextEdit.WidgetWidth)
grid.addWidget(QLabel('Tx Parts'), 0, 0)
grid.addWidget(self.txEdit, 0, 1)
combineTxPartsButton = QPushButton('Combine Transaction Parts', self)
combineTxPartsButton.clicked.connect(self.clickedCombineTxPartsButton)
grid.addWidget(combineTxPartsButton, 1, 1)
self.resultEdit = QPlainTextEdit(self) #TODO make this one uneditable maybe?
self.resultEdit.setLineWrapMode(QPlainTextEdit.WidgetWidth) #and select-all when you click?
grid.addWidget(QLabel('Result'), 2, 0)
grid.addWidget(self.resultEdit, 2, 1)
def clickedCombineTxPartsButton(self, checked):
head, foot = get_ascii_head_foot(get_network())
matches = re.finditer('(' + head + '[0-9A-Za-z+/=\n\t ]*' + foot + ')',
str(self.txEdit.toPlainText()), re.MULTILINE | re.DOTALL)
result = None
for m in matches:
tx = deserialize(unascii_armor_tx(m.group(1)))
if result == None:
result = tx
else:
result['ins'] = result['ins'] + tx['ins']
result['outs'] = result['outs'] + tx['outs']
if not result:
QMessageBox.critical(self, 'Combine Transaction Parts', 'Unable to parse transaction parts',
QMessageBox.Ok, QMessageBox.NoButton)
return
self.resultEdit.setPlainText(ascii_armor_tx(serialize(result)))
self.resultEdit.selectAll()
#self.txEdit.setPlainText('')
#TODO somewhere do checking that sum of outputs <= sum of inputs
# and other simple checks that a node or client would do
# then again, the site connected to by pushtx() will do these checks
class SignOffTab(QScrollArea):
def __init__(self):
super(SignOffTab, self).__init__()
self.initUI()
def initUI(self):
signOffTab = QWidget()
self.setWidget(signOffTab)
self.setWidgetResizable(True)
self.grid = QGridLayout()
signOffTab.setLayout(self.grid)
self.grid.setSpacing(10)
self.txEdit = QPlainTextEdit(self)
self.txEdit.setLineWrapMode(QPlainTextEdit.WidgetWidth)
self.grid.addWidget(self.txEdit, 0, 0, 1, 4)
viewTxButton = QPushButton('View Transaction', self)
viewTxButton.clicked.connect(self.clickedViewTxButton)
self.grid.addWidget(viewTxButton, 1, 0, 1, 4)
self.unspentCoinsLabel = QLabel('<u>Unspent Coins</u>')
self.outputsLabel = QLabel('<u>Outputs</u>')
self.minerFeeLabel = QLabel('')
self.grid.addWidget(self.unspentCoinsLabel, 2, 1, 1, 1, QtCore.Qt.AlignHCenter)
self.grid.addWidget(self.outputsLabel, 2, 3, 1, 1, QtCore.Qt.AlignHCenter)
self.grid.addWidget(self.minerFeeLabel, 2, 2, 1, 1, QtCore.Qt.AlignHCenter)
self.broadcastTxButton = QPushButton('Broadcast Transaction', self)
self.broadcastTxButton.setEnabled(False)
self.broadcastTxButton.clicked.connect(self.clickedBroadcastTxButton)
self.grid.addWidget(self.broadcastTxButton, 3, 0, 1, 4)
self.unspentCoinsWidgetList = []
self.outputsWidgetList = []
self.signedCount = 0
def clickedViewTxButton(self, checked):
tx = unascii_armor_tx_gui(self, str(self.txEdit.toPlainText()))
if tx == None:
return
self.txEdit.setPlainText(ascii_armor_tx(tx))
txd = deserialize(tx)
for ucwl in self.unspentCoinsWidgetList:
for wid in ucwl:
self.grid.removeWidget(wid)
wid.hide()
self.unspentCoinsWidgetList = []
for owl in self.outputsWidgetList:
self.grid.removeWidget(owl)
owl.hide()
self.outputsWidgetList = []
self.grid.removeWidget(self.broadcastTxButton)
self.signedCount = 0
self.unspentCount = 0
self.inputSum = 0 #in satoshi
self.outputSum = 0
for index, inputs in enumerate(txd['ins']):
#print('fetchtx ' + inputs['outpoint']['hash'])
#TODO catch the Exception if these lookups fail, maybe display the tx anyway
# with (lookup err) where value and addr should be
#on second thoughts, the signing depends on this so lookup failure should be
# a proper error that you need a popup box asking if your internet works
ftx = blockr_fetchtx_cache(inputs['outpoint']['hash'], get_network())
scr_val = deserialize(ftx)['outs'][inputs['outpoint']['index']]
self.inputSum += scr_val['value']
buttonText = 'Unsigned'
if inputs['script'] != '':
if verify_tx_input(tx, index, scr_val['script'], *deserialize_script(inputs['script'])):
buttonText = 'Signed'
self.signedCount += 1
else:
buttonText = 'Failed'
signButton = QPushButton(buttonText)
signButton.setEnabled(buttonText != 'Signed')
signButton.clicked.connect(self.clickedSignButton)
utxo = inputs['outpoint']['hash'] + ':' + str(inputs['outpoint']['index'])
addr = script_to_address(scr_val['script'], get_vbyte())
utxoList = blockr_unspent(addr, get_network())
utxoList = [u['output'] for u in utxoList]
spentStatus = 'Unspent' if utxo in utxoList else '<font color="red">Spent</font>'
if spentStatus == 'Unspent':
self.unspentCount += 1
unspentCoinsWidgets = (
signButton,
QLabelSelectable('<b>' + utxo +
'</b> (' + str(Decimal(scr_val['value'])/Decimal(1e8)) + 'btc)'),
QLabelSelectable(addr + ' <b>' + spentStatus + '</b>')
)
self.grid.addWidget(unspentCoinsWidgets[0], len(self.unspentCoinsWidgetList)*2 + 3, 0)
self.grid.addWidget(unspentCoinsWidgets[1], len(self.unspentCoinsWidgetList)*2 + 3, 1)
self.grid.addWidget(unspentCoinsWidgets[2], len(self.unspentCoinsWidgetList)*2 + 4, 1, QtCore.Qt.AlignHCenter)
self.unspentCoinsWidgetList.append(unspentCoinsWidgets)
for o in txd['outs']:
outputWidgets = QLabelSelectable('<b>' + script_to_address(o['script'], get_vbyte()) +
'</b> (' + str(Decimal(o['value'])/Decimal(1e8)) + 'btc)')
self.outputSum += o['value']
self.grid.addWidget(outputWidgets, len(self.outputsWidgetList)*2 + 3, 3)
self.outputsWidgetList.append(outputWidgets)
self.grid.addWidget(QLabel('=====>'), 3, 2, 1, 1, QtCore.Qt.AlignHCenter)
self.unspentCoinsLabel.setText('<u>Unspent Coins</u> Total value: ' +
str(Decimal(self.inputSum)/Decimal(1e8)) + 'btc')
self.outputsLabel.setText('<u>Outputs</u> Total value: ' +
str(Decimal(self.outputSum)/Decimal(1e8)) + 'btc')
self.minerFeeLabel.setText('Miner fee: ' +
str(Decimal(self.inputSum - self.outputSum)/Decimal(1e8)) + 'btc')
broadcastRow = max(len(self.unspentCoinsWidgetList), len(self.outputsWidgetList))*2 + 5
self.grid.addWidget(self.broadcastTxButton, broadcastRow, 0, 1, 4)
canBroadcast = self.signedCount == len(self.unspentCoinsWidgetList) and \
self.unspentCount == len(self.unspentCoinsWidgetList)
self.broadcastTxButton.setEnabled(canBroadcast)
def clickedSignButton(self, checked):
index = -1
for i, ucwl in enumerate(self.unspentCoinsWidgetList):
if ucwl[0] == self.sender():
index = i
break
assert index != -1
tx = unascii_armor_tx_gui(self, str(self.txEdit.toPlainText()))
if tx == None:
return
utxo = str(re.search('<b>([0-9a-fA-F]*:[0-9]*)</b>', self.unspentCoinsWidgetList[index][1].text()).group(1))
privkey, ok = QInputDialog.getText(self, 'Sign Transaction', 'Input private key\nFor ' + utxo)
if not ok:
return
#TODO format checking here, put in try: and show error
newtx = sign(tx, index, str(privkey).strip())
ftx = blockr_fetchtx_cache(utxo[:64], get_network()) #since we already looked it this is just a cache query
scr_val = deserialize(ftx)['outs'][int(utxo[65:])]
scri = deserialize(newtx)['ins'][index]['script']
buttonText = 'Failed'
if verify_tx_input(tx, index, scr_val['script'], *deserialize_script(scri)):
buttonText = 'Signed'
self.txEdit.setPlainText(ascii_armor_tx(newtx))
self.txEdit.selectAll()
self.signedCount += 1
self.broadcastTxButton.setEnabled(self.signedCount == len(self.unspentCoinsWidgetList))
self.sender().setText(buttonText)
self.sender().setEnabled(buttonText != 'Signed')
def clickedBroadcastTxButton(self, checked):
tx = unascii_armor_tx_gui(self, str(self.txEdit.toPlainText()))
if tx == None:
return
#TODO its possible for someone to change what's in txEdit and broadcast that, which is bad
print('txhash = ' + tx)
reply = QMessageBox.question(self, 'Broadcast Transaction', 'Are you sure you want to broadcast?\n\n' +
'Miner fees: ' + str(Decimal(self.inputSum - self.outputSum)/Decimal(1e8)) + 'btc\n\n' +
'Sum of Unspent Coins: ' + str(Decimal(self.inputSum)/Decimal(1e8)) + 'btc\nSum of Outputs: ' +
str(Decimal(self.outputSum)/Decimal(1e8)) + 'btc', QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.No:
return
ret = blockr_pushtx(tx, get_network()) #TODO tell vbuterin to have a single pushtx() function that could use many services
QMessageBox.information(self, 'Push Transaction', str(ret)) #blockr_pushtx() eligis_pushtx()
print(ret)
#TODO change denominations, mbtc, ubtc, bits
# make a satoshi_to_unit() and unit_to_satoshi()
class SettingsTab(QWidget):
def __init__(self):
super(SettingsTab, self).__init__()
self.initUI()
def initUI(self):
QLabel('<b>Proxy Server</b> - For example using tor', self).move(550, 30)
QLabel('Host', self).move(560, 64)
self.proxyHostEdit = QLineEdit('localhost', self)
self.proxyHostEdit.move(590, 60)
QLabel('Port', self).move(560, 104)
self.proxyPortEdit = QSpinBox(self)
self.proxyPortEdit.move(590, 100)
self.proxyPortEdit.setRange(0, 65535)
self.proxyPortEdit.setValue(9150)
useProxyCheckbox = QCheckBox('Use Socks5 Proxy', self)
useProxyCheckbox.setCheckState(False)
useProxyCheckbox.move(590, 135)
useProxyCheckbox.stateChanged.connect(self.useProxyCheckboxChanged)
self.useTestnetCheckbox = QCheckBox('Testnet', self)
self.useTestnetCheckbox.setCheckState(False)
self.useTestnetCheckbox.move(30, 120)
self.useTestnetCheckbox.stateChanged.connect(self.useTestnetCheckboxChanged)
clearFetchTxCache = QPushButton('Clear FetchTx() Cache', self)
clearFetchTxCache.move(300, 50)
clearFetchTxCache.clicked.connect(lambda checked: fetchtx_cache_mem.clear())
QLabel('Ascii Armor Line Length', self).move(30, 50)
self.asciiArmorLengthEdit = QSpinBox(self)
self.asciiArmorLengthEdit.move(30, 70)
self.asciiArmorLengthEdit.setRange(1, 2048)
self.asciiArmorLengthEdit.setValue(64)
aboutButton = QPushButton('About', self)
aboutButton.move(200, 100)
aboutButton.clicked.connect(lambda checked: QMessageBox.about(self, 'About',
'Coin Jumble coded by Belcher\nA small application to make it easier to do' +
' CoinJoin transactions.\nIf my program is useful to you, I take donations at' +
' 1DnGHcMAJBtPXSMuQxiXDg93TXRwd9fGzD'))
aboutQtButton = QPushButton("About Qt", self)
#aboutQtButton.resize(aboutQtButton.sizeHint())
aboutQtButton.move(200, 50)
aboutQtButton.clicked.connect(lambda checked: QMessageBox.aboutQt(self, 'About Qt'))
def useProxyCheckboxChanged(self, state):
self.proxyHostEdit.setEnabled(state == QtCore.Qt.Unchecked)
self.proxyPortEdit.setEnabled(state == QtCore.Qt.Unchecked)
if state == QtCore.Qt.Checked:
host = str(self.proxyHostEdit.text())
port = self.proxyPortEdit.value()
bci_set_proxy(SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, host, port))
else:
bci_set_proxy(None)
def useTestnetCheckboxChanged(self, checked):
add = ''
if checked:
add = ' - Testnet'
w.setWindowTitle(appWindowTitle + add)
if len(sys.argv) == 2:
sys.exit(0)
app = QApplication(sys.argv)
w = QMainWindow()
tabWidget = QTabWidget(w)
tabWidget.addTab(ListUnspentCoinsTab(), "List Unspent Coins")
tabWidget.addTab(CreateTransactionPartTab(), "Create Transaction Part")
tabWidget.addTab(CombineTransactionPartsTab(), "Combine Transaction Parts")
#should it contain the word 'verify' ? because this tab is probably the only one you can view and unarmor/deserialize tx
# but if thats the case it should have the word 'view' instead? or 'un-armor' or 'deserialize', the last two words being too long
tabWidget.addTab(SignOffTab(), "Sign Off Transaction")
settingsTab = SettingsTab()
tabWidget.addTab(settingsTab, "Settings")
#TODO proxy (for tor), with a message that if you dont want your ip linked with those unspent coins or pushtx()
# honestly though (the message should say) odds are your ip IS linked with the unspent coins unless you're really careful
# combobox choosing bc.i or blockr or both randomly, combobox choosing where to pushtx()
# testnet, about button/message box
# maybe a thing that generates testnet privkeys and addresses so people can play around
#QMessageBox has about() and aboutQt() which is nice
#have a py2exe version
#but also mention you can easily run the single file python script on tails
#TODO w.setStatusBar() is maybe useful, for when stuff is downloading
w.resize(700, 300)
#w.move(300, 300)
appWindowTitle = 'Coin Jumble GUI'
w.setWindowTitle(appWindowTitle)
w.setCentralWidget(tabWidget)
w.show()
sys.exit(app.exec_())