-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REFACTOR: paid
flag -> PaymentResult
object
#619
Closed
Closed
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
38e7e22
`PaymentResult`
lollerfirst 26eb30c
ledger: rely on PaymentResult instead of paid flag. Double check for …
lollerfirst 0cba761
Merge remote-tracking branch 'origin/main' into payment-result
lollerfirst 012178c
`None` is `PENDING`
lollerfirst 5b818b8
make format
lollerfirst 22e8be4
reflected changes API tests where `PaymentStatus` is used + reflected…
lollerfirst 82ff6c5
reflect changes in blink backend and tests
lollerfirst 0aa3c97
fix lnbits get_payment_status
lollerfirst 12b4185
remove paid flag
callebtc e1f1590
fix mypy
callebtc 2695929
remove more paid flags
callebtc 904eb6d
fix strike mypy
callebtc 6faa0a1
green
callebtc fbba4c8
shorten all state checks
callebtc 4bf0ca2
fix
callebtc e3d5706
fix some tests
callebtc 19bb7bf
gimme ✅
callebtc 55c3fc9
fix............
callebtc 71e680c
fix lnbits
callebtc 9f0c3f7
Update cashu/mint/ledger.py
callebtc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,5 +1,6 @@ | ||||
from abc import ABC, abstractmethod | ||||
from typing import AsyncGenerator, Coroutine, Optional, Union | ||||
from enum import Enum | ||||
|
||||
from pydantic import BaseModel | ||||
|
||||
|
@@ -33,36 +34,79 @@ class InvoiceResponse(BaseModel): | |||
payment_request: Optional[str] = None | ||||
error_message: Optional[str] = None | ||||
|
||||
class PaymentResult(Enum): | ||||
FAILED = 0 | ||||
SETTLED = 1 | ||||
PENDING = 2 | ||||
|
||||
UNKNOWN = 3 | ||||
|
||||
def __str__(self): | ||||
return self.name | ||||
|
||||
# We assume `None` is `FAILED` | ||||
@classmethod | ||||
def from_paid_flag(cls, paid: Optional[bool]): | ||||
if paid is None or paid == False: | ||||
return cls.FAILED | ||||
elif paid == True: | ||||
return cls.SETTLED | ||||
|
||||
class PaymentResponse(BaseModel): | ||||
result: PaymentResult | ||||
ok: Optional[bool] = None # True: paid, False: failed, None: pending or unknown | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I suggest we remove all legacy flags |
||||
checking_id: Optional[str] = None | ||||
fee: Optional[Amount] = None | ||||
preimage: Optional[str] = None | ||||
error_message: Optional[str] = None | ||||
|
||||
@property | ||||
def pending(self) -> bool: | ||||
return self.result == PaymentResult.PENDING | ||||
|
||||
@property | ||||
def settled(self) -> bool: | ||||
return self.result == PaymentResult.SETTLED | ||||
|
||||
@property | ||||
def failed(self) -> bool: | ||||
return self.result == PaymentResult.FAILED | ||||
|
||||
@property | ||||
def unknown(self) -> bool: | ||||
return self.result == PaymentResult.UNKNOWN | ||||
|
||||
class PaymentStatus(BaseModel): | ||||
result: PaymentResult | ||||
paid: Optional[bool] = None | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
fee: Optional[Amount] = None | ||||
preimage: Optional[str] = None | ||||
error_message: Optional[str] = None | ||||
|
||||
@property | ||||
def pending(self) -> bool: | ||||
return self.paid is not True | ||||
return self.result == PaymentResult.PENDING | ||||
|
||||
@property | ||||
def settled(self) -> bool: | ||||
return self.result == PaymentResult.SETTLED | ||||
|
||||
@property | ||||
def failed(self) -> bool: | ||||
return self.paid is False | ||||
return self.result == PaymentResult.FAILED | ||||
|
||||
@property | ||||
def unknown(self) -> bool: | ||||
return self.result == PaymentResult.UNKNOWN | ||||
|
||||
def __str__(self) -> str: | ||||
if self.paid is True: | ||||
if self.result == PaymentResult.SETTLED: | ||||
return "settled" | ||||
elif self.paid is False: | ||||
elif self.result == PaymentResult.FAILED: | ||||
return "failed" | ||||
elif self.paid is None: | ||||
elif self.result == PaymentResult.PENDING: | ||||
return "still pending" | ||||
else: | ||||
else: # self.result == PaymentResult.UNKNOWN: | ||||
return "unknown (should never happen)" | ||||
|
||||
|
||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that
None
should bePENDING
, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you are right. But we also used
None
to signal what now would beUNKNOWN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't matter too much, though. One shouldn't be using that. I only ever created it to use it in
FakeWallet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I suggest to change this code to assume that
None
isPENDING
.That way it is consistent with rest of the old and new code.