Browse Source

commands: introduce 'removelocaltx'

see #5137
sqlite_db
SomberNight 6 years ago
parent
commit
40bf049c82
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 11
      electrum/address_synchronizer.py
  2. 20
      electrum/commands.py

11
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)

20
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

Loading…
Cancel
Save