Browse Source

Merge pull request #6842 from spesmilo/save_height_in_invoices

Save height in invoices, use it to determine invoice status
patch-4
ThomasV 4 years ago
committed by GitHub
parent
commit
91cdd12fa2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      electrum/invoices.py
  2. 14
      electrum/wallet.py

1
electrum/invoices.py

@ -118,6 +118,7 @@ class OnchainInvoice(Invoice):
outputs = attr.ib(kw_only=True, converter=_decode_outputs) # type: List[PartialTxOutput] outputs = attr.ib(kw_only=True, converter=_decode_outputs) # type: List[PartialTxOutput]
bip70 = attr.ib(type=str, kw_only=True) # type: Optional[str] bip70 = attr.ib(type=str, kw_only=True) # type: Optional[str]
requestor = 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: def get_address(self) -> str:
"""returns the first address, to be displayed in GUI""" """returns the first address, to be displayed in GUI"""

14
electrum/wallet.py

@ -717,16 +717,18 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
exp = URI.get('exp') exp = URI.get('exp')
timestamp = timestamp or int(time.time()) timestamp = timestamp or int(time.time())
exp = exp or 0 exp = exp or 0
_id = bh2u(sha256d(repr(outputs) + "%d"%timestamp))[0:10]
invoice = OnchainInvoice( invoice = OnchainInvoice(
type=PR_TYPE_ONCHAIN, type=PR_TYPE_ONCHAIN,
amount_sat=amount, amount_sat=amount,
outputs=outputs, outputs=outputs,
message=message, message=message,
id=bh2u(sha256(repr(outputs))[0:16]), id=_id,
time=timestamp, time=timestamp,
exp=exp, exp=exp,
bip70=None, bip70=None,
requestor=None, requestor=None,
height=self.get_local_height(),
) )
return invoice return invoice
@ -822,8 +824,13 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
for invoice_scriptpubkey, invoice_amt in invoice_amounts.items(): for invoice_scriptpubkey, invoice_amt in invoice_amounts.items():
scripthash = bitcoin.script_to_scripthash(invoice_scriptpubkey.hex()) scripthash = bitcoin.script_to_scripthash(invoice_scriptpubkey.hex())
prevouts_and_values = self.db.get_prevouts_by_scripthash(scripthash) prevouts_and_values = self.db.get_prevouts_by_scripthash(scripthash)
relevant_txs += [prevout.txid.hex() for prevout, v in prevouts_and_values] total_received = 0
total_received = sum([v for prevout, v in prevouts_and_values]) 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. # 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) # note: "at least one TXO" check is needed for zero amount invoice (e.g. OP_RETURN)
if len(prevouts_and_values) == 0: if len(prevouts_and_values) == 0:
@ -1901,6 +1908,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
id=_id, id=_id,
bip70=None, bip70=None,
requestor=None, requestor=None,
height=self.get_local_height(),
) )
def sign_payment_request(self, key, alias, alias_addr, password): # FIXME this is broken def sign_payment_request(self, key, alias, alias_addr, password): # FIXME this is broken

Loading…
Cancel
Save