Browse Source

Raise exception if transaction is not related to wallet

3.1
Johann Bauer 7 years ago
parent
commit
8676e870f3
  1. 11
      gui/qt/history_list.py
  2. 1
      lib/commands.py
  3. 12
      lib/wallet.py

11
gui/qt/history_list.py

@ -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()

1
lib/commands.py

@ -632,7 +632,6 @@ class Commands:
@command('w')
def addtransaction(self, tx):
""" Add a transaction to the wallet history """
#fixme: we should ensure that tx is related to wallet
tx = Transaction(tx)
self.wallet.add_transaction(tx.txid(), tx)
self.wallet.save_transactions()

12
lib/wallet.py

@ -154,6 +154,11 @@ 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 Abstract_Wallet(PrintError):
"""
Wallet classes are created to handle various address generation methods.
@ -674,6 +679,7 @@ class Abstract_Wallet(PrintError):
def add_transaction(self, tx_hash, tx):
is_coinbase = tx.inputs()[0]['type'] == 'coinbase'
related = False
with self.transaction_lock:
# add inputs
self.txi[tx_hash] = d = {}
@ -687,6 +693,7 @@ class Abstract_Wallet(PrintError):
addr = self.find_pay_to_pubkey_address(prevout_hash, prevout_n)
# find value from prev output
if addr and self.is_mine(addr):
related = True
dd = self.txo.get(prevout_hash, {})
for n, v, is_cb in dd.get(addr, []):
if n == prevout_n:
@ -709,6 +716,7 @@ class Abstract_Wallet(PrintError):
else:
addr = None
if addr and self.is_mine(addr):
related = True
if d.get(addr) is None:
d[addr] = []
d[addr].append((n, v, is_coinbase))
@ -720,6 +728,10 @@ class Abstract_Wallet(PrintError):
if dd.get(addr) is None:
dd[addr] = []
dd[addr].append((ser, v))
if not related:
raise UnrelatedTransactionException()
# save
self.transactions[tx_hash] = tx

Loading…
Cancel
Save