1
0

Merge branch 'local_tx'

This commit is contained in:
ThomasV
2018-01-30 00:22:02 +01:00
4 changed files with 61 additions and 21 deletions

View File

@@ -25,6 +25,7 @@
import webbrowser
from electrum.wallet import UnrelatedTransactionException
from .util import *
from electrum.i18n import _
from electrum.util import block_explorer_URL
@@ -211,6 +212,10 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop):
def onFileAdded(self, fn):
with open(fn) as f:
tx = self.parent.tx_from_text(f.read())
self.wallet.add_transaction(tx.txid(), tx)
self.wallet.save_transactions(write=True)
self.on_update()
try:
self.wallet.add_transaction(tx.txid(), tx)
except UnrelatedTransactionException as e:
self.parent.show_error(e)
else:
self.wallet.save_transactions(write=True)
self.on_update()

View File

@@ -35,6 +35,8 @@ from electrum.i18n import _
from electrum.plugins import run_hook
from electrum.util import bfh
from electrum.wallet import UnrelatedTransactionException
from .util import *
dialogs = [] # Otherwise python randomly garbage collects the dialogs...
@@ -98,8 +100,13 @@ class TxDialog(QDialog, MessageBoxMixin):
self.broadcast_button = b = QPushButton(_("Broadcast"))
b.clicked.connect(self.do_broadcast)
self.save_button = b = QPushButton(_("Save"))
b.clicked.connect(self.save)
self.save_button = QPushButton(_("Save"))
self.save_button.setDisabled(True)
self.save_button.setToolTip(_("Please sign this transaction in order to save it"))
self.save_button.clicked.connect(self.save)
self.export_button = b = QPushButton(_("Export"))
b.clicked.connect(self.export)
self.cancel_button = b = QPushButton(_("Close"))
b.clicked.connect(self.close)
@@ -112,9 +119,9 @@ class TxDialog(QDialog, MessageBoxMixin):
self.copy_button = CopyButton(lambda: str(self.tx), parent.app)
# Action buttons
self.buttons = [self.sign_button, self.broadcast_button, self.cancel_button]
self.buttons = [self.sign_button, self.broadcast_button, self.save_button, self.cancel_button]
# Transaction sharing buttons
self.sharing_buttons = [self.copy_button, self.qr_button, self.save_button]
self.sharing_buttons = [self.copy_button, self.qr_button, self.export_button]
run_hook('transaction_dialog', self)
@@ -155,6 +162,8 @@ class TxDialog(QDialog, MessageBoxMixin):
if success:
self.prompt_if_unsaved = True
self.saved = False
self.save_button.setDisabled(False)
self.save_button.setToolTip("")
self.update()
self.main_window.pop_top_level_window(self)
@@ -163,12 +172,23 @@ class TxDialog(QDialog, MessageBoxMixin):
self.main_window.sign_tx(self.tx, sign_done)
def save(self):
self.wallet.add_transaction(self.tx.txid(), self.tx)
self.wallet.save_transactions(write=True)
self.main_window.history_list.update()
self.save_button.setDisabled(True)
self.show_message(_("Transaction saved successfully"))
self.saved = True
def export(self):
name = 'signed_%s.txn' % (self.tx.txid()[0:8]) if self.tx.is_complete() else 'unsigned.txn'
fileName = self.main_window.getSaveFileName(_("Select where to save your signed transaction"), name, "*.txn")
if fileName:
with open(fileName, "w+") as f:
f.write(json.dumps(self.tx.as_dict(), indent=4) + '\n')
self.show_message(_("Transaction saved successfully"))
self.show_message(_("Transaction exported successfully"))
self.saved = True
def update(self):