electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 40bf049c82f9c6850fa0124ed5524b5e42d36406
parent 8e6904c7b70f8ec4e4f12f440237d1bf8414c104
Author: SomberNight <somber.night@protonmail.com>
Date:   Wed, 20 Feb 2019 18:01:43 +0100

commands: introduce 'removelocaltx'

see #5137

Diffstat:
Melectrum/address_synchronizer.py | 11++++++-----
Melectrum/commands.py | 20+++++++++++++++++++-
2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py @@ -336,11 +336,12 @@ class AddressSynchronizer(PrintError): def get_depending_transactions(self, tx_hash): """Returns all (grand-)children of tx_hash in this wallet.""" - children = set() - for other_hash in self.spent_outpoints[tx_hash].values(): - children.add(other_hash) - children |= self.get_depending_transactions(other_hash) - return children + with self.transaction_lock: + children = set() + for other_hash in self.spent_outpoints[tx_hash].values(): + children.add(other_hash) + children |= self.get_depending_transactions(other_hash) + return children def receive_tx_callback(self, tx_hash, tx, tx_height): self.add_unverified_tx(tx_hash, tx_height) diff --git a/electrum/commands.py b/electrum/commands.py @@ -35,7 +35,7 @@ from decimal import Decimal from typing import Optional, TYPE_CHECKING from .import util, ecc -from .util import bfh, bh2u, format_satoshis, json_decode, print_error, json_encode +from .util import bfh, bh2u, format_satoshis, json_decode, print_error, json_encode, is_hash256_str from . import bitcoin from .bitcoin import is_address, hash_160, COIN, TYPE_ADDRESS from . import bip32 @@ -46,6 +46,7 @@ from .synchronizer import Notifier from .storage import WalletStorage from . import keystore from .wallet import Wallet, Imported_Wallet, Abstract_Wallet +from .address_synchronizer import TX_HEIGHT_LOCAL from .mnemonic import Mnemonic if TYPE_CHECKING: @@ -763,6 +764,23 @@ class Commands: fee_level = Decimal(fee_level) return self.config.fee_per_kb(dyn=dyn, mempool=mempool, fee_level=fee_level) + @command('w') + def removelocaltx(self, txid): + """Remove a 'local' transaction from the wallet, and its dependent + transactions. + """ + if not is_hash256_str(txid): + raise Exception(f"{repr(txid)} is not a txid") + height = self.wallet.get_tx_height(txid).height + to_delete = {txid} + if height != TX_HEIGHT_LOCAL: + raise Exception(f'Only local transactions can be removed. ' + f'This tx has height: {height} != {TX_HEIGHT_LOCAL}') + to_delete |= self.wallet.get_depending_transactions(txid) + for tx_hash in to_delete: + self.wallet.remove_transaction(tx_hash) + self.wallet.save_transactions(write=True) + @command('') def help(self): # for the python console