mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 09:21:39 +00:00
Raise exception if transaction is not related to wallet
This commit is contained in:
parent
e184ac888f
commit
8676e870f3
3 changed files with 20 additions and 4 deletions
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue