Raise exception if transaction is not related to wallet
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
|
||||||
|
from electrum.wallet import UnrelatedTransactionException
|
||||||
from .util import *
|
from .util import *
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.util import block_explorer_URL
|
from electrum.util import block_explorer_URL
|
||||||
@@ -211,6 +212,10 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop):
|
|||||||
def onFileAdded(self, fn):
|
def onFileAdded(self, fn):
|
||||||
with open(fn) as f:
|
with open(fn) as f:
|
||||||
tx = self.parent.tx_from_text(f.read())
|
tx = self.parent.tx_from_text(f.read())
|
||||||
self.wallet.add_transaction(tx.txid(), tx)
|
try:
|
||||||
self.wallet.save_transactions(write=True)
|
self.wallet.add_transaction(tx.txid(), tx)
|
||||||
self.on_update()
|
except UnrelatedTransactionException as e:
|
||||||
|
self.parent.show_error(e)
|
||||||
|
else:
|
||||||
|
self.wallet.save_transactions(write=True)
|
||||||
|
self.on_update()
|
||||||
|
|||||||
@@ -632,7 +632,6 @@ class Commands:
|
|||||||
@command('w')
|
@command('w')
|
||||||
def addtransaction(self, tx):
|
def addtransaction(self, tx):
|
||||||
""" Add a transaction to the wallet history """
|
""" Add a transaction to the wallet history """
|
||||||
#fixme: we should ensure that tx is related to wallet
|
|
||||||
tx = Transaction(tx)
|
tx = Transaction(tx)
|
||||||
self.wallet.add_transaction(tx.txid(), tx)
|
self.wallet.add_transaction(tx.txid(), tx)
|
||||||
self.wallet.save_transactions()
|
self.wallet.save_transactions()
|
||||||
|
|||||||
@@ -154,6 +154,11 @@ def sweep(privkeys, network, config, recipient, fee=None, imax=100):
|
|||||||
return tx
|
return tx
|
||||||
|
|
||||||
|
|
||||||
|
class UnrelatedTransactionException(Exception):
|
||||||
|
def __init__(self):
|
||||||
|
self.args = ("Transaction is unrelated to this wallet ", )
|
||||||
|
|
||||||
|
|
||||||
class Abstract_Wallet(PrintError):
|
class Abstract_Wallet(PrintError):
|
||||||
"""
|
"""
|
||||||
Wallet classes are created to handle various address generation methods.
|
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):
|
def add_transaction(self, tx_hash, tx):
|
||||||
is_coinbase = tx.inputs()[0]['type'] == 'coinbase'
|
is_coinbase = tx.inputs()[0]['type'] == 'coinbase'
|
||||||
|
related = False
|
||||||
with self.transaction_lock:
|
with self.transaction_lock:
|
||||||
# add inputs
|
# add inputs
|
||||||
self.txi[tx_hash] = d = {}
|
self.txi[tx_hash] = d = {}
|
||||||
@@ -687,6 +693,7 @@ class Abstract_Wallet(PrintError):
|
|||||||
addr = self.find_pay_to_pubkey_address(prevout_hash, prevout_n)
|
addr = self.find_pay_to_pubkey_address(prevout_hash, prevout_n)
|
||||||
# find value from prev output
|
# find value from prev output
|
||||||
if addr and self.is_mine(addr):
|
if addr and self.is_mine(addr):
|
||||||
|
related = True
|
||||||
dd = self.txo.get(prevout_hash, {})
|
dd = self.txo.get(prevout_hash, {})
|
||||||
for n, v, is_cb in dd.get(addr, []):
|
for n, v, is_cb in dd.get(addr, []):
|
||||||
if n == prevout_n:
|
if n == prevout_n:
|
||||||
@@ -709,6 +716,7 @@ class Abstract_Wallet(PrintError):
|
|||||||
else:
|
else:
|
||||||
addr = None
|
addr = None
|
||||||
if addr and self.is_mine(addr):
|
if addr and self.is_mine(addr):
|
||||||
|
related = True
|
||||||
if d.get(addr) is None:
|
if d.get(addr) is None:
|
||||||
d[addr] = []
|
d[addr] = []
|
||||||
d[addr].append((n, v, is_coinbase))
|
d[addr].append((n, v, is_coinbase))
|
||||||
@@ -720,6 +728,10 @@ class Abstract_Wallet(PrintError):
|
|||||||
if dd.get(addr) is None:
|
if dd.get(addr) is None:
|
||||||
dd[addr] = []
|
dd[addr] = []
|
||||||
dd[addr].append((ser, v))
|
dd[addr].append((ser, v))
|
||||||
|
|
||||||
|
if not related:
|
||||||
|
raise UnrelatedTransactionException()
|
||||||
|
|
||||||
# save
|
# save
|
||||||
self.transactions[tx_hash] = tx
|
self.transactions[tx_hash] = tx
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user