|
|
@ -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: |
|
|
|