mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-29 08:21:27 +00:00
invoices: make sure that OnchainInvoice .exp and .time are not None
related: #6284
This commit is contained in:
parent
2db0ad10db
commit
dee5d52948
3 changed files with 30 additions and 6 deletions
|
@ -113,9 +113,9 @@ class Invoice(StoredObject):
|
||||||
@attr.s
|
@attr.s
|
||||||
class OnchainInvoice(Invoice):
|
class OnchainInvoice(Invoice):
|
||||||
message = attr.ib(type=str, kw_only=True)
|
message = attr.ib(type=str, kw_only=True)
|
||||||
amount_sat = attr.ib(kw_only=True) # type: Union[None, int, str] # in satoshis. can be '!'
|
amount_sat = attr.ib(kw_only=True) # type: Union[int, str] # in satoshis. can be '!'
|
||||||
exp = attr.ib(type=int, kw_only=True)
|
exp = attr.ib(type=int, kw_only=True, validator=attr.validators.instance_of(int))
|
||||||
time = attr.ib(type=int, kw_only=True)
|
time = attr.ib(type=int, kw_only=True, validator=attr.validators.instance_of(int))
|
||||||
id = attr.ib(type=str, kw_only=True)
|
id = attr.ib(type=str, kw_only=True)
|
||||||
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]
|
||||||
|
|
|
@ -691,14 +691,21 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
||||||
amount = '!'
|
amount = '!'
|
||||||
else:
|
else:
|
||||||
amount = sum(x.value for x in outputs)
|
amount = sum(x.value for x in outputs)
|
||||||
|
timestamp = None
|
||||||
|
exp = None
|
||||||
|
if URI:
|
||||||
|
timestamp = URI.get('time')
|
||||||
|
exp = URI.get('exp')
|
||||||
|
timestamp = timestamp or int(time.time())
|
||||||
|
exp = exp or 0
|
||||||
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=bh2u(sha256(repr(outputs))[0:16]),
|
||||||
time=URI.get('time') if URI else int(time.time()),
|
time=timestamp,
|
||||||
exp=URI.get('exp') if URI else 0,
|
exp=exp,
|
||||||
bip70=None,
|
bip70=None,
|
||||||
requestor=None,
|
requestor=None,
|
||||||
)
|
)
|
||||||
|
@ -1776,6 +1783,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
||||||
amount_sat = amount_sat or 0
|
amount_sat = amount_sat or 0
|
||||||
timestamp = int(time.time())
|
timestamp = int(time.time())
|
||||||
_id = bh2u(sha256d(address + "%d"%timestamp))[0:10]
|
_id = bh2u(sha256d(address + "%d"%timestamp))[0:10]
|
||||||
|
expiration = expiration or 0
|
||||||
return OnchainInvoice(
|
return OnchainInvoice(
|
||||||
type=PR_TYPE_ONCHAIN,
|
type=PR_TYPE_ONCHAIN,
|
||||||
outputs=[(TYPE_ADDRESS, address, amount_sat)],
|
outputs=[(TYPE_ADDRESS, address, amount_sat)],
|
||||||
|
|
|
@ -52,7 +52,7 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
OLD_SEED_VERSION = 4 # electrum versions < 2.0
|
OLD_SEED_VERSION = 4 # electrum versions < 2.0
|
||||||
NEW_SEED_VERSION = 11 # electrum versions >= 2.0
|
NEW_SEED_VERSION = 11 # electrum versions >= 2.0
|
||||||
FINAL_SEED_VERSION = 30 # electrum >= 2.7 will set this to prevent
|
FINAL_SEED_VERSION = 31 # electrum >= 2.7 will set this to prevent
|
||||||
# old versions from overwriting new format
|
# old versions from overwriting new format
|
||||||
|
|
||||||
|
|
||||||
|
@ -178,6 +178,7 @@ class WalletDB(JsonDB):
|
||||||
self._convert_version_28()
|
self._convert_version_28()
|
||||||
self._convert_version_29()
|
self._convert_version_29()
|
||||||
self._convert_version_30()
|
self._convert_version_30()
|
||||||
|
self._convert_version_31()
|
||||||
self.put('seed_version', FINAL_SEED_VERSION) # just to be sure
|
self.put('seed_version', FINAL_SEED_VERSION) # just to be sure
|
||||||
|
|
||||||
self._after_upgrade_tasks()
|
self._after_upgrade_tasks()
|
||||||
|
@ -667,6 +668,21 @@ class WalletDB(JsonDB):
|
||||||
raise Exception(f"unknown invoice type: {_type}")
|
raise Exception(f"unknown invoice type: {_type}")
|
||||||
self.data['seed_version'] = 30
|
self.data['seed_version'] = 30
|
||||||
|
|
||||||
|
def _convert_version_31(self):
|
||||||
|
if not self._is_upgrade_method_needed(30, 30):
|
||||||
|
return
|
||||||
|
|
||||||
|
from .invoices import PR_TYPE_ONCHAIN
|
||||||
|
requests = self.data.get('payment_requests', {})
|
||||||
|
invoices = self.data.get('invoices', {})
|
||||||
|
for d in [invoices, requests]:
|
||||||
|
for key, item in list(d.items()):
|
||||||
|
if item['type'] == PR_TYPE_ONCHAIN:
|
||||||
|
item['amount_sat'] = item['amount_sat'] or 0
|
||||||
|
item['exp'] = item['exp'] or 0
|
||||||
|
item['time'] = item['time'] or 0
|
||||||
|
self.data['seed_version'] = 31
|
||||||
|
|
||||||
def _convert_imported(self):
|
def _convert_imported(self):
|
||||||
if not self._is_upgrade_method_needed(0, 13):
|
if not self._is_upgrade_method_needed(0, 13):
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue