electrum

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

commit a041a0c0755159a7dfe0fd9ca6f30fe50545c8ff
parent 34612c671e0c37418c0aab02dbeb90402b195193
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue, 21 Jan 2020 16:50:45 +0100

wallet: log when saving already paid invoice

(maybe it should not be allowed?)

Diffstat:
Melectrum/wallet.py | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/electrum/wallet.py b/electrum/wallet.py @@ -614,6 +614,8 @@ class Abstract_Wallet(AddressSynchronizer, ABC): if invoice_type == PR_TYPE_LN: key = invoice['rhash'] elif invoice_type == PR_TYPE_ONCHAIN: + if self.is_onchain_invoice_paid(invoice): + self.logger.info("saving invoice... but it is already paid!") key = bh2u(sha256(repr(invoice))[0:16]) invoice['id'] = key outputs = invoice['outputs'] # type: List[PartialTxOutput] @@ -643,7 +645,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC): item = copy.copy(self.invoices[key]) request_type = item.get('type') if request_type == PR_TYPE_ONCHAIN: - item['status'] = PR_PAID if self._is_onchain_invoice_paid(item)[0] else PR_UNPAID + item['status'] = PR_PAID if self.is_onchain_invoice_paid(item) else PR_UNPAID elif self.lnworker and request_type == PR_TYPE_LN: item['status'] = self.lnworker.get_payment_status(bfh(item['rhash'])) else: @@ -666,7 +668,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC): for txout in outputs: self._invoices_from_scriptpubkey_map[txout.scriptpubkey].add(invoice_key) - def _is_onchain_invoice_paid(self, invoice) -> Tuple[bool, Sequence[str]]: + def _is_onchain_invoice_paid(self, invoice: dict) -> Tuple[bool, Sequence[str]]: """Returns whether on-chain invoice is satisfied, and list of relevant TXIDs.""" assert invoice.get('type') == PR_TYPE_ONCHAIN invoice_amounts = defaultdict(int) # type: Dict[bytes, int] # scriptpubkey -> value_sats @@ -687,6 +689,9 @@ class Abstract_Wallet(AddressSynchronizer, ABC): return False, [] return True, relevant_txs + def is_onchain_invoice_paid(self, invoice: dict) -> bool: + return self._is_onchain_invoice_paid(invoice)[0] + def _maybe_set_tx_label_based_on_invoices(self, tx: Transaction) -> bool: tx_hash = tx.txid() with self.transaction_lock: