Skip to content

Commit

Permalink
feat: add expiry_date property for Bolt11 model
Browse files Browse the repository at this point in the history
included some tests for `dt` and `expiry_date` aswell
  • Loading branch information
dni committed Oct 10, 2023
1 parent b97b9bd commit fa3dd6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bolt11/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ def expiry(self) -> Optional[int]:
tag = self.tags.get(TagChar.expire_time)
return tag.data if tag else None

@property
def expiry_date(self) -> Optional[datetime]:
if not self.expiry:
return None
return datetime.fromtimestamp(self.date + self.expiry)

@property
def features(self) -> Optional[Features]:
tag = self.tags.get(TagChar.features)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_bolt11_examples.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from bolt11.decode import decode
from bolt11.encode import encode
from bolt11.models.fallback import Fallback
Expand Down Expand Up @@ -127,7 +129,9 @@ def test_example_2(self):
decoded = decode(ex["payment_request"])
assert decoded.currency == ex["currency"]
assert decoded.date == ex["date"]
assert decoded.dt == datetime.fromtimestamp(ex["date"])
assert decoded.expiry == ex["expiry"]
assert decoded.expiry_date == datetime.fromtimestamp(ex["date"] + ex["expiry"])
assert decoded.payment_hash == ex["payment_hash"]
assert decoded.payment_secret == ex["payment_secret"]
assert decoded.amount_msat == ex["amount_msat"]
Expand Down

0 comments on commit fa3dd6c

Please sign in to comment.