commit 06589df812d85597b0dc635f8d4e502cbdcfb5a6
parent fc85dcead64fbd5c808b72bccd98bf7083bb96d1
Author: ThomasV <thomasv@electrum.org>
Date: Sat, 23 Nov 2019 12:46:43 +0100
simplify add_transaction
Diffstat:
4 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py
@@ -207,11 +207,11 @@ class AddressSynchronizer(Logger):
conflicting_txns -= {tx_hash}
return conflicting_txns
- def add_transaction(self, tx_hash, tx: Transaction, allow_unrelated=False) -> bool:
+ def add_transaction(self, tx: Transaction, allow_unrelated=False) -> bool:
"""Returns whether the tx was successfully added to the wallet history."""
- assert tx_hash, tx_hash
assert tx, tx
assert tx.is_complete()
+ tx_hash = tx.txid()
# assert tx_hash == tx.txid() # disabled as expensive; test done by Synchronizer.
# we need self.transaction_lock but get_tx_height will take self.lock
# so we need to take that too here, to enforce order of locks
@@ -339,7 +339,7 @@ class AddressSynchronizer(Logger):
def receive_tx_callback(self, tx_hash, tx, tx_height):
self.add_unverified_tx(tx_hash, tx_height)
- self.add_transaction(tx_hash, tx, allow_unrelated=True)
+ self.add_transaction(tx, allow_unrelated=True)
def receive_history_callback(self, addr: str, hist, tx_fees: Dict[str, int]):
with self.lock:
@@ -360,7 +360,7 @@ class AddressSynchronizer(Logger):
tx = self.db.get_transaction(tx_hash)
if tx is None:
continue
- self.add_transaction(tx_hash, tx, allow_unrelated=True)
+ self.add_transaction(tx, allow_unrelated=True)
# Store fees
for tx_hash, fee_sat in tx_fees.items():
@@ -386,7 +386,7 @@ class AddressSynchronizer(Logger):
continue
tx = self.db.get_transaction(tx_hash)
if tx is not None:
- self.add_transaction(tx_hash, tx, allow_unrelated=True)
+ self.add_transaction(tx, allow_unrelated=True)
def remove_local_transactions_we_dont_have(self):
for txid in itertools.chain(self.db.list_txi(), self.db.list_txo()):
@@ -569,7 +569,7 @@ class AddressSynchronizer(Logger):
def add_future_tx(self, tx: Transaction, num_blocks: int) -> None:
assert num_blocks > 0, num_blocks
with self.lock:
- self.add_transaction(tx.txid(), tx)
+ self.add_transaction(tx)
self.future_tx[tx.txid()] = num_blocks
def get_tx_height(self, tx_hash: str) -> TxMinedInfo:
diff --git a/electrum/commands.py b/electrum/commands.py
@@ -819,7 +819,7 @@ class Commands:
async def addtransaction(self, tx, wallet: Abstract_Wallet = None):
""" Add a transaction to the wallet history """
tx = Transaction(tx)
- if not wallet.add_transaction(tx.txid(), tx):
+ if not wallet.add_transaction(tx):
return False
wallet.storage.write()
return tx.txid()
diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
@@ -2973,7 +2973,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
def save_transaction_into_wallet(self, tx: Transaction):
win = self.top_level_window()
try:
- if not self.wallet.add_transaction(tx.txid(), tx):
+ if not self.wallet.add_transaction(tx):
win.show_error(_("Transaction could not be saved.") + "\n" +
_("It conflicts with current history."))
return False
diff --git a/electrum/tests/test_wallet_vertical.py b/electrum/tests/test_wallet_vertical.py
@@ -2289,7 +2289,7 @@ class TestWalletHistory_EvilGapLimit(TestCaseForTestnet):
w.storage.put('stored_height', 1316917 + 100)
for txid in self.transactions:
tx = Transaction(self.transactions[txid])
- w.add_transaction(tx.txid(), tx)
+ w.add_transaction(tx)
# txn A is an external incoming txn paying to addr (3) and (15)
# txn B is an external incoming txn paying to addr (4) and (25)
# txn C is an internal transfer txn from addr (25) -- to -- (1) and (25)
@@ -2339,7 +2339,7 @@ class TestWalletHistory_DoubleSpend(TestCaseForTestnet):
config=self.config)['wallet']
for txid in self.transactions:
tx = Transaction(self.transactions[txid])
- w.add_transaction(tx.txid(), tx)
+ w.add_transaction(tx)
# txn A is an external incoming txn funding the wallet
# txn B is an outgoing payment to an external address
# txn C is double-spending txn B, to a wallet address
@@ -2353,15 +2353,15 @@ class TestWalletHistory_DoubleSpend(TestCaseForTestnet):
config=self.config)['wallet']
# txn A is an external incoming txn funding the wallet
txA = Transaction(self.transactions["a3849040f82705151ba12a4389310b58a17b78025d81116a3338595bdefa1625"])
- w.add_transaction(txA.txid(), txA)
+ w.add_transaction(txA)
# txn B is an outgoing payment to an external address
txB = Transaction(self.transactions["0e2182ead6660790290371516cb0b80afa8baebd30dad42b5e58a24ceea17f1c"])
- w.add_transaction(txB.txid(), txB)
+ w.add_transaction(txB)
# now the user manually deletes txn B to attempt the double spend
# txn C is double-spending txn B, to a wallet address
# rationale1: user might do this with opt-in RBF transactions
# rationale2: this might be a local transaction, in which case the GUI even allows it
w.remove_transaction(txB)
txC = Transaction(self.transactions["2c9aa33d9c8ec649f9bfb84af027a5414b760be5231fe9eca4a95b9eb3f8a017"])
- w.add_transaction(txC.txid(), txC)
+ w.add_transaction(txC)
self.assertEqual(999890, sum(w.get_balance()))