Merge pull request #3923 from SomberNight/gui_add_tx_ismine
local tx: restructure exception handling wrt wallet.add_transaction and QT
This commit is contained in:
commit
0d43820ab7
|
@ -26,7 +26,7 @@
|
|||
import webbrowser
|
||||
import datetime
|
||||
|
||||
from electrum.wallet import UnrelatedTransactionException, TX_HEIGHT_LOCAL
|
||||
from electrum.wallet import AddTransactionException, TX_HEIGHT_LOCAL
|
||||
from .util import *
|
||||
from electrum.i18n import _
|
||||
from electrum.util import block_explorer_URL
|
||||
|
@ -356,16 +356,12 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop):
|
|||
self.parent.need_update.set()
|
||||
|
||||
def onFileAdded(self, fn):
|
||||
try:
|
||||
with open(fn) as f:
|
||||
tx = self.parent.tx_from_text(f.read())
|
||||
try:
|
||||
self.wallet.add_transaction(tx.txid(), tx)
|
||||
except UnrelatedTransactionException as e:
|
||||
self.parent.save_transaction_into_wallet(tx)
|
||||
except IOError as e:
|
||||
self.parent.show_error(e)
|
||||
else:
|
||||
self.wallet.save_transactions(write=True)
|
||||
# need to update at least: history_list, utxo_list, address_list
|
||||
self.parent.need_update.set()
|
||||
|
||||
def export_history_dialog(self):
|
||||
d = WindowModalDialog(self, _('Export History'))
|
||||
|
|
|
@ -51,7 +51,7 @@ from electrum.util import (format_time, format_satoshis, PrintError,
|
|||
from electrum import Transaction
|
||||
from electrum import util, bitcoin, commands, coinchooser
|
||||
from electrum import paymentrequest
|
||||
from electrum.wallet import Multisig_Wallet
|
||||
from electrum.wallet import Multisig_Wallet, AddTransactionException
|
||||
|
||||
from .amountedit import AmountEdit, BTCAmountEdit, MyLineEdit, FeerateEdit
|
||||
from .qrcodewidget import QRCodeWidget, QRDialog
|
||||
|
@ -3125,3 +3125,21 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||
if is_final:
|
||||
new_tx.set_rbf(False)
|
||||
self.show_transaction(new_tx, tx_label)
|
||||
|
||||
def save_transaction_into_wallet(self, tx):
|
||||
try:
|
||||
if not self.wallet.add_transaction(tx.txid(), tx):
|
||||
self.show_error(_("Transaction could not be saved.") + "\n" +
|
||||
_("It conflicts with current history."))
|
||||
return False
|
||||
except AddTransactionException as e:
|
||||
self.show_error(e)
|
||||
return False
|
||||
else:
|
||||
self.wallet.save_transactions(write=True)
|
||||
# need to update at least: history_list, utxo_list, address_list
|
||||
self.need_update.set()
|
||||
self.show_message(_("Transaction saved successfully"))
|
||||
return True
|
||||
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ from electrum.i18n import _
|
|||
from electrum.plugins import run_hook
|
||||
|
||||
from electrum.util import bfh
|
||||
from electrum.wallet import UnrelatedTransactionException
|
||||
from electrum.wallet import AddTransactionException
|
||||
|
||||
from .util import *
|
||||
|
||||
|
@ -179,16 +179,8 @@ class TxDialog(QDialog, MessageBoxMixin):
|
|||
self.main_window.sign_tx(self.tx, sign_done)
|
||||
|
||||
def save(self):
|
||||
if not self.wallet.add_transaction(self.tx.txid(), self.tx):
|
||||
self.show_error(_("Transaction could not be saved. It conflicts with current history."))
|
||||
return
|
||||
self.wallet.save_transactions(write=True)
|
||||
|
||||
# need to update at least: history_list, utxo_list, address_list
|
||||
self.main_window.need_update.set()
|
||||
|
||||
if self.main_window.save_transaction_into_wallet(self.tx):
|
||||
self.save_button.setDisabled(True)
|
||||
self.show_message(_("Transaction saved successfully"))
|
||||
self.saved = True
|
||||
|
||||
|
||||
|
|
|
@ -157,9 +157,18 @@ def sweep(privkeys, network, config, recipient, fee=None, imax=100):
|
|||
return tx
|
||||
|
||||
|
||||
class UnrelatedTransactionException(Exception):
|
||||
def __init__(self):
|
||||
self.args = ("Transaction is unrelated to this wallet ", )
|
||||
class AddTransactionException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class UnrelatedTransactionException(AddTransactionException):
|
||||
def __str__(self):
|
||||
return _("Transaction is unrelated to this wallet.")
|
||||
|
||||
|
||||
class NotIsMineTransactionException(AddTransactionException):
|
||||
def __str__(self):
|
||||
return _("Only transactions with inputs owned by the wallet can be added.")
|
||||
|
||||
|
||||
class Abstract_Wallet(PrintError):
|
||||
|
@ -768,7 +777,7 @@ class Abstract_Wallet(PrintError):
|
|||
# do not save if tx is local and not mine
|
||||
if tx_height == TX_HEIGHT_LOCAL and not is_mine:
|
||||
# FIXME the test here should be for "not all is_mine"; cannot detect conflict in some cases
|
||||
return False
|
||||
raise NotIsMineTransactionException()
|
||||
# raise exception if unrelated to wallet
|
||||
is_for_me = any([self.is_mine(self.get_txout_address(txo)) for txo in tx.outputs()])
|
||||
if not is_mine and not is_for_me:
|
||||
|
|
Loading…
Reference in New Issue