Skip to content
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

Return invoice on successful lnurl-withdraw #436

Merged
merged 8 commits into from
Sep 23, 2023

Conversation

ok300
Copy link
Contributor

@ok300 ok300 commented Sep 7, 2023

Include the LNInvoice as inner data in the Ok result of BreezServices::lnurl_withdraw.

Subtasks:

Fixes #427

@ok300 ok300 requested a review from roeierez September 7, 2023 10:45
@ok300 ok300 force-pushed the ok300-lnurl-withdraw-extend-ok branch from 085f429 to 145fa91 Compare September 7, 2023 10:46
@ok300
Copy link
Contributor Author

ok300 commented Sep 7, 2023

@roeierez it's ready for review.

I will add the RN bindings as last step, once we agree on the general structure.

@dangeross
Copy link
Collaborator

I will add the RN bindings as last step, once we agree on the general structure.

It could be the first use of the RN codegen 😎

@ok300
Copy link
Contributor Author

ok300 commented Sep 7, 2023

The PR simply adds the invoice in the withdraw Ok response.

However, if the goal is to be able to link a payment with a LNURL-withdraw request, an alternative way to do this is to extend LnPaymentDetails, which is a field of Payment

pub struct LnPaymentDetails {
pub payment_hash: String,
pub label: String,
pub destination_pubkey: String,
pub payment_preimage: String,
pub keysend: bool,
pub bolt11: String,
/// Only set for [PaymentType::Sent] payments that are part of a LNURL-pay workflow where
/// the endpoint returns a success action
pub lnurl_success_action: Option<SuccessActionProcessed>,
/// Only set for [PaymentType::Sent] payments that are sent to a Lightning Address
pub ln_address: Option<String>,
/// Only set for [PaymentType::Sent] payments where the receiver endpoint returned LNURL metadata
pub lnurl_metadata: Option<String>,
}

with an lnurl_withdraw_endpoint: Optional<String>, where we can store the LNURL-w endpoint associated with this Payment.

That may be preferable to the approach in this PR, because with the PR, our LNURL handling becomes inconsistent:

  • lnurl_pay service call result has no reference to the invoice, but LnPaymentDetails has a few pay-related optional fields:
    /// Only set for [PaymentType::Sent] payments that are part of a LNURL-pay workflow where
    /// the endpoint returns a success action
    pub lnurl_success_action: Option<SuccessActionProcessed>,
    /// Only set for [PaymentType::Sent] payments that are sent to a Lightning Address
    pub ln_address: Option<String>,
    /// Only set for [PaymentType::Sent] payments where the receiver endpoint returned LNURL metadata
    pub lnurl_metadata: Option<String>,
  • lnurl_withdraw has the reverse: invoice in the service call result, but no reference in the Payment

What do you think? Is the PR approach ok? Or better switch to the above? Or do both?

@danielgranhao
Copy link
Contributor

If possible, as a user, I would like to have both :) that way, I can avoid always searching for the correct payment after making an LNURL withdrawal.

Otherwise, the withdrawal flow is:

  1. Start withdrawal
  2. Search for the created payment associated with the withdrawal
  3. Wait for BreezEvent::InvoicePaid that includes the hash of the withdrawal payment

If we have what the current version of this PR proposes, the middle step can be discarded.

@ok300 ok300 force-pushed the ok300-lnurl-withdraw-extend-ok branch 2 times, most recently from 08aaabf to 335e61f Compare September 15, 2023 13:45
@ok300
Copy link
Contributor Author

ok300 commented Sep 15, 2023

@dangeross I took your RN generator for a test-drive and ran it on this PR.

Can you please doublecheck if all looks good? fe8884d

Copy link
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general. There seems to be lots of linting changes with the kotlin files though. Can you give me your ktlint and kotlin versions?

ktlint --version
kotlin -version

@ok300
Copy link
Contributor Author

ok300 commented Sep 15, 2023

ktlint --version

1.0.0

kotlin -version

Kotlin version 1.9.10-release-459 (JRE 20.0.2)

@dangeross
Copy link
Collaborator

ktlint --version

1.0.0

Ok, seems to be a version difference. I've upgraded to 1.0.0

@roeierez
Copy link
Member

@ok300 the PR looks good to me. As for your comment above do you want to add the step of associated the withdraw endpoint with the payment in the storage or not? Another option is in a separate PR.

Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! We need a corresponding c-breez PR as I believe this breaks it.

@ok300
Copy link
Contributor Author

ok300 commented Sep 18, 2023

If possible, as a user, I would like to have both :)

Then I'll add both in this PR.

@ok300 ok300 force-pushed the ok300-lnurl-withdraw-extend-ok branch 2 times, most recently from e779168 to fd8c3d7 Compare September 20, 2023 16:20
Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Dropped a NIT comment.

@@ -1114,6 +1117,18 @@ pub enum LnUrlCallbackStatus {
},
}

/// [LnUrlCallbackStatus] specific to LNURL-withdraw, where the success case contains the invoice.
#[derive(Serialize)]
pub enum LnUrlWithdrawCallbackStatus {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps if we are introducing new types here we can use better naming?
LnUrlWithdrawCallbackStatus => LnUrlWithdrawResult
LnUrlWithdrawOkData => LnurlWithdrawSuccess
LnUrlErrorData => LnurlError

@ok300 ok300 added the c-breez label Sep 21, 2023
erdemyerebasmaz added a commit to breez/c-breez that referenced this pull request Sep 21, 2023
Persist failed payments breez/breez-sdk#463
Return invoice on successful lnurl-withdraw breez/breez-sdk#436
@erdemyerebasmaz
Copy link
Contributor

@ok300 @roeierez
Shouldn't we apply these naming changes to LnUrlCallbackStatus used on lnurl_auth as well?

@ok300
Copy link
Contributor Author

ok300 commented Sep 21, 2023

@erdemyerebasmaz how about LnUrlCallbackStatus => LnUrlCallbackResult ?

It's used not only in LNURL-auth, but also as intermediary step in LNURL-withdraw.

@erdemyerebasmaz
Copy link
Contributor

erdemyerebasmaz commented Sep 21, 2023

@erdemyerebasmaz how about LnUrlCallbackStatus => LnUrlCallbackResult ?

It's used not only in LNURL-auth, but also as intermediary step in LNURL-withdraw.

@ok300 I see, isn't it supposed to be LnUrlResult according to:

Perhaps if we are introducing new types here we can use better naming?
LnUrlWithdrawCallbackStatus => LnUrlWithdrawResult
LnUrlWithdrawOkData => LnurlWithdrawSuccess
LnUrlErrorData => LnurlError

The naming was fine and consistent with other parts of the app before these changes imo.

@ok300
Copy link
Contributor Author

ok300 commented Sep 21, 2023

Well, there are 2 naming conventions which don't overlap:

  • one is for the LNURL-withdraw specific case. Calling the struct LnUrlWithdrawResult makes sense.
  • one is for a generic case that affects several callback types. LnUrlResult gives the wrong impression that its what a LNURL-workflow is supposed to end in, but it's only the case for auth. It's an intermediary result in withdraw. IMO LnUrlCallbackResult better captures the nature if it.

@erdemyerebasmaz
Copy link
Contributor

Well, there are 2 naming conventions which don't overlap:

  • one is for the LNURL-withdraw specific case. Calling the struct LnUrlWithdrawResult makes sense.
  • one is for a generic case that affects several callback types. LnUrlResult gives the wrong impression that its what a LNURL-workflow is supposed to end in, but it's only the case for auth. It's an intermediary result in withdraw. IMO LnUrlCallbackResult better captures the nature if it.

Thanks for the clarification, second item was what made it confusing for me. If that's the case, I see no issue with keeping LnUrlCallbackStatus as it is.

@ok300
Copy link
Contributor Author

ok300 commented Sep 21, 2023

Then @roeierez this PR is ready for final review.

I also linked the c-breez PR by @erdemyerebasmaz in the description above.

@ok300 ok300 requested a review from roeierez September 21, 2023 13:18
@ok300 ok300 force-pushed the ok300-lnurl-withdraw-extend-ok branch from 8e1096e to d8ccf23 Compare September 21, 2023 13:21
erdemyerebasmaz added a commit to breez/c-breez that referenced this pull request Sep 21, 2023
Persist failed payments breez/breez-sdk#463
Return invoice on successful lnurl-withdraw breez/breez-sdk#436
Copy link
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ok300 ok300 merged commit 9420ed5 into main Sep 23, 2023
5 checks passed
@ok300 ok300 deleted the ok300-lnurl-withdraw-extend-ok branch September 23, 2023 07:55
erdemyerebasmaz added a commit to breez/c-breez that referenced this pull request Sep 25, 2023
Persist failed payments breez/breez-sdk#463
Return invoice on successful lnurl-withdraw breez/breez-sdk#436
erdemyerebasmaz added a commit to breez/c-breez that referenced this pull request Sep 25, 2023
Persist failed payments breez/breez-sdk#463
Return invoice on successful lnurl-withdraw breez/breez-sdk#436
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: return payment hash on a successful LNURL withdrawal
5 participants