URI: 
       tMerge pull request #6842 from spesmilo/save_height_in_invoices - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 91cdd12fa274e29d45a8684d7faf2942b23dfbd9
   DIR parent a83805e00b39e7a621f7181ca31632e97a4ae615
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Fri, 11 Dec 2020 19:56:59 +0100
       
       Merge pull request #6842 from spesmilo/save_height_in_invoices
       
       Save height in invoices, use it to determine invoice status
       Diffstat:
         M electrum/invoices.py                |       1 +
         M electrum/wallet.py                  |      14 +++++++++++---
       
       2 files changed, 12 insertions(+), 3 deletions(-)
       ---
   DIR diff --git a/electrum/invoices.py b/electrum/invoices.py
       t@@ -118,6 +118,7 @@ class OnchainInvoice(Invoice):
            outputs = attr.ib(kw_only=True, converter=_decode_outputs)  # type: List[PartialTxOutput]
            bip70 = attr.ib(type=str, kw_only=True)  # type: Optional[str]
            requestor = attr.ib(type=str, kw_only=True)  # type: Optional[str]
       +    height = attr.ib(type=int, default=0, kw_only=True, validator=attr.validators.instance_of(int))
        
            def get_address(self) -> str:
                """returns the first address, to be displayed in GUI"""
   DIR diff --git a/electrum/wallet.py b/electrum/wallet.py
       t@@ -717,16 +717,18 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
                    exp = URI.get('exp')
                timestamp = timestamp or int(time.time())
                exp = exp or 0
       +        _id = bh2u(sha256d(repr(outputs) + "%d"%timestamp))[0:10]
                invoice = OnchainInvoice(
                    type=PR_TYPE_ONCHAIN,
                    amount_sat=amount,
                    outputs=outputs,
                    message=message,
       -            id=bh2u(sha256(repr(outputs))[0:16]),
       +            id=_id,
                    time=timestamp,
                    exp=exp,
                    bip70=None,
                    requestor=None,
       +            height=self.get_local_height(),
                )
                return invoice
        
       t@@ -822,8 +824,13 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
                    for invoice_scriptpubkey, invoice_amt in invoice_amounts.items():
                        scripthash = bitcoin.script_to_scripthash(invoice_scriptpubkey.hex())
                        prevouts_and_values = self.db.get_prevouts_by_scripthash(scripthash)
       -                relevant_txs += [prevout.txid.hex() for prevout, v in prevouts_and_values]
       -                total_received = sum([v for prevout, v in prevouts_and_values])
       +                total_received = 0
       +                for prevout, v in prevouts_and_values:
       +                    height = self.get_tx_height(prevout.txid.hex()).height
       +                    if height > 0 and height <= invoice.height:
       +                        continue
       +                    total_received += v
       +                    relevant_txs.append(prevout.txid.hex())
                        # check that there is at least one TXO, and that they pay enough.
                        # note: "at least one TXO" check is needed for zero amount invoice (e.g. OP_RETURN)
                        if len(prevouts_and_values) == 0:
       t@@ -1901,6 +1908,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
                    id=_id,
                    bip70=None,
                    requestor=None,
       +            height=self.get_local_height(),
                )
        
            def sign_payment_request(self, key, alias, alias_addr, password):  # FIXME this is broken