sweep privkeys in gui
This commit is contained in:
parent
b21cfc2746
commit
46c0dda3b9
|
@ -293,6 +293,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
labels_menu.addAction(_("&Export"), self.do_export_labels)
|
labels_menu.addAction(_("&Export"), self.do_export_labels)
|
||||||
|
|
||||||
self.private_keys_menu = wallet_menu.addMenu(_("&Private keys"))
|
self.private_keys_menu = wallet_menu.addMenu(_("&Private keys"))
|
||||||
|
self.private_keys_menu.addAction(_("&Sweep"), self.sweep_key_dialog)
|
||||||
self.private_keys_menu.addAction(_("&Import"), self.do_import_privkey)
|
self.private_keys_menu.addAction(_("&Import"), self.do_import_privkey)
|
||||||
self.private_keys_menu.addAction(_("&Export"), self.export_privkeys_dialog)
|
self.private_keys_menu.addAction(_("&Export"), self.export_privkeys_dialog)
|
||||||
|
|
||||||
|
@ -2044,6 +2045,32 @@ class ElectrumWindow(QMainWindow):
|
||||||
QMessageBox.critical(None,_("Unable to create csv"), export_error_label + "\n" + str(reason))
|
QMessageBox.critical(None,_("Unable to create csv"), export_error_label + "\n" + str(reason))
|
||||||
|
|
||||||
|
|
||||||
|
def sweep_key_dialog(self):
|
||||||
|
d = QDialog(self)
|
||||||
|
d.setWindowTitle(_('Sweep private keys'))
|
||||||
|
|
||||||
|
vbox = QVBoxLayout(d)
|
||||||
|
vbox.addWidget(QLabel(_("Enter private keys")))
|
||||||
|
|
||||||
|
keys_e = QTextEdit()
|
||||||
|
keys_e.setTabChangesFocus(True)
|
||||||
|
vbox.addWidget(keys_e)
|
||||||
|
vbox.addStretch(1)
|
||||||
|
hbox, button = ok_cancel_buttons2(d, _('Sweep'))
|
||||||
|
vbox.addLayout(hbox)
|
||||||
|
button.setEnabled(False)
|
||||||
|
|
||||||
|
keys_e.textChanged.connect(lambda: button.setEnabled(Wallet.is_private_key(str(keys_e.toPlainText()).strip())))
|
||||||
|
if not d.exec_():
|
||||||
|
return
|
||||||
|
|
||||||
|
text = str(keys_e.toPlainText()).strip()
|
||||||
|
privkeys = text.split()
|
||||||
|
to_address = self.wallet.addresses()[0]
|
||||||
|
fee = self.wallet.fee
|
||||||
|
tx = Transaction.sweep(privkeys, self.network, to_address, fee)
|
||||||
|
self.show_transaction(tx)
|
||||||
|
|
||||||
|
|
||||||
@protected
|
@protected
|
||||||
def do_import_privkey(self, password):
|
def do_import_privkey(self, password):
|
||||||
|
|
|
@ -264,18 +264,8 @@ class Commands:
|
||||||
|
|
||||||
|
|
||||||
def sweep(self, privkey, to_address, fee = 0.0001):
|
def sweep(self, privkey, to_address, fee = 0.0001):
|
||||||
pubkey = public_key_from_private_key(privkey)
|
fee = int(Decimal(fee)*100000000)
|
||||||
address = address_from_private_key(privkey)
|
return Transaction.sweep([privkey], self.network, to_address, fee)
|
||||||
pay_script = Transaction.pay_script(address)
|
|
||||||
unspent = self.network.synchronous_get([ ('blockchain.address.listunspent',[address])])[0]
|
|
||||||
if not unspent:
|
|
||||||
return
|
|
||||||
total = sum( map(lambda x:int(x.get('value')), unspent) ) - int(Decimal(fee)*100000000)
|
|
||||||
inputs = map(lambda i: {'prevout_hash': i['tx_hash'], 'prevout_n':i['tx_pos'], 'scriptPubKey':pay_script, 'redeemPubkey':pubkey}, unspent)
|
|
||||||
outputs = [(to_address, total)]
|
|
||||||
tx = Transaction.from_io(inputs, outputs)
|
|
||||||
tx.sign({ pubkey:privkey })
|
|
||||||
return tx
|
|
||||||
|
|
||||||
|
|
||||||
def signmessage(self, address, message):
|
def signmessage(self, address, message):
|
||||||
|
|
|
@ -386,7 +386,6 @@ class Transaction:
|
||||||
self.outputs = map(lambda x: (x['address'],x['value']), self.outputs)
|
self.outputs = map(lambda x: (x['address'],x['value']), self.outputs)
|
||||||
self.locktime = self.d['lockTime']
|
self.locktime = self.d['lockTime']
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.raw
|
return self.raw
|
||||||
|
|
||||||
|
@ -398,6 +397,31 @@ class Transaction:
|
||||||
self.outputs = outputs
|
self.outputs = outputs
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def sweep(klass, privkeys, network, to_address, fee):
|
||||||
|
inputs = []
|
||||||
|
for privkey in privkeys:
|
||||||
|
pubkey = public_key_from_private_key(privkey)
|
||||||
|
address = address_from_private_key(privkey)
|
||||||
|
u = network.synchronous_get([ ('blockchain.address.listunspent',[address])])[0]
|
||||||
|
pay_script = klass.pay_script(address)
|
||||||
|
for item in u:
|
||||||
|
item['scriptPubKey'] = pay_script
|
||||||
|
item['redeemPubkey'] = pubkey
|
||||||
|
item['address'] = address
|
||||||
|
item['prevout_hash'] = item['tx_hash']
|
||||||
|
item['prevout_n'] = item['tx_pos']
|
||||||
|
inputs += u
|
||||||
|
|
||||||
|
if not inputs:
|
||||||
|
return
|
||||||
|
|
||||||
|
total = sum( map(lambda x:int(x.get('value')), inputs) ) - fee
|
||||||
|
outputs = [(to_address, total)]
|
||||||
|
self = klass.from_io(inputs, outputs)
|
||||||
|
self.sign({ pubkey:privkey })
|
||||||
|
return self
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def multisig_script(klass, public_keys, num=None):
|
def multisig_script(klass, public_keys, num=None):
|
||||||
n = len(public_keys)
|
n = len(public_keys)
|
||||||
|
|
Loading…
Reference in New Issue