-
Notifications
You must be signed in to change notification settings - Fork 46
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
Split Payment
struct depending on method
#761
base: main
Are you sure you want to change the base?
Split Payment
struct depending on method
#761
Conversation
/// Represents a sent and pending payment, not yet persisted into the storage, | ||
/// including its [PaymentType] and [PaymentDetails] | ||
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] | ||
pub struct PendingPayment { |
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 am not sure we need this struct as what we really want to return from send_payment & send_spontaneous_payment is something that describes the lightning payment right?
So why not just return the LnPaymentDetails from these methods?
cc @JssDWt as the issue opener.
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.
The main goal is to make a cleaner api, where the fields returned from an api call describe exactly what you did, and contain all the relevant information. The main issue with the send_payment and send_spontaneous_payment is the details
field right now. That contains either ClosedChannelPaymentDetails or LnPaymentDetails. It would improve, by returning only LnPaymentDetails, but still it would contain many fields that you don't need, like the lnurl and swap fields. The reason for creating the issue, is to get rid of the ClosedChannelPaymentDetails in the response to a payment.
I do like the idea of having internal structs that represent exactly the information available at any point in the code. That reduces the amount of things you have to keep in mind when developing on this stuff. When you see a struct, you should know what information it contains and not have to scavenge through the codebase looking for potential other uses of the same struct. So I do like the idea of introducing a new struct for this case. LnPaymentDetails can be used as an aggregate. Either for persistence purposes or to include in the payment list. But ideally every subcall has its own response type.
Looking at the 'PendingPayment' struct, it still contains the PaymentDetails, with the LnPaymentDetails/ClosedChannelPaymentDetails. I would like this struct to represent a 'lightning payment' alone, without any wrappers for lnurl/swaps/closed channels whatsoever. So when there has been a lightning payment somewhere in the code, it's clear that at that point we're looking at a lightning payment, and nothing else.
Another comment about the PendingPayment struct is that the name implies it is pending. But it might not be pending. So we'd need to make clear whether the payment is pending or not.
As for the struct exposed to the client, maybe we can fill fields of the SendPaymentResponse itself, or indeed return the PendingPayment struct.
Generally it's a good idea in terms of code isolation to at least use different structs for
- persistence
- the api you expose
- the api you call
That helps with being able to feely modify the code for specific purposes in different parts of the codebase.
(sorry about the long reply)
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.
Not at all @JssDWt, now I have a clearer idea of what you had in mind. I'll try to split everything as best as I can, so let the reviews continue!
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.
Added some comments in the UDL as an addition to the comment I left above.
What I do really like about renaming Payment
to PaymentListItem
, it is immediately clear where the Payment
struct was 'abused' before, in the sense that this specific struct is not the right one for every usecase.
@@ -360,7 +360,7 @@ dictionary LogEntry { | |||
dictionary InvoicePaidDetails { | |||
string payment_hash; | |||
string bolt11; | |||
Payment? payment; | |||
PaymentListItem? payment; |
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.
An InvoicePaid event maybe shouldn't include A PaymentListItem, but only the data relevant to the paid invoice.
@@ -378,7 +378,7 @@ interface BreezEvent { | |||
NewBlock(u32 block); | |||
InvoicePaid(InvoicePaidDetails details); | |||
Synced(); | |||
PaymentSucceed(Payment details); | |||
PaymentSucceed(PaymentListItem details); |
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 this can be LNPaymentDetails
@@ -697,7 +697,7 @@ dictionary SendSpontaneousPaymentRequest { | |||
}; | |||
|
|||
dictionary SendPaymentResponse { | |||
Payment payment; | |||
PaymentListItem payment; |
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.
This should probably contain the PendingPayment
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 both here and in PaymentSucceed event we should contain the same struct/data.
@JssDWt @hydra-yse how about using the LNPaymentDetails here and there? This way we don't need to introduce another struct (PendingPayment).
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.
Question: How would you feel about extending the PaymentDetails enum with variants for lnurl_pay, ln_address, lnurl_withdraw, swap and reverse swap? And make LnPaymentDetails basically the thing we mean with PendingPayment here?
Fixes #563.