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

Add payment hash to lnurl_pay() return type #550

Merged
merged 6 commits into from
Nov 7, 2023

Conversation

dleutenegger
Copy link
Contributor

Resolves #540


throw SdkError.Generic(message: "Invalid enum variant \(type) for enum LnUrlPayResult")
}

static func dictionaryOf(lnUrlPayResult: LnUrlPayResult) -> [String: Any?] {
switch lnUrlPayResult {
case let .endpointSuccess(
data
datapaymentHash
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo?

@@ -3018,6 +3023,15 @@ class BreezSDKMapper {
"type": "endpointError",
"data": dictionaryOf(lnUrlErrorData: data),
]

case let .payError(
paymentHashreason
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seemed to be an issue with the rn codegen. I moved the LnUrlPayResult data into wrapper structs, which resolved the issue.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll investigate the RN codegen issue

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think your change is the preferred (common) way we handle interface variants anyway. But it seems variants with multiple tuple/struct like data attributes are not being rendered correctly in swift.

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 otherwise. Just a comment around naming

data: maybe_sa_processed,
data: LnUrlSuccessData {
payment_hash: details.payment_hash.clone(),
data: maybe_sa_processed,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can I propose we change data to success_action to avoid data.data?

Copy link
Contributor

Choose a reason for hiding this comment

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

Would make sense IMO.

Copy link
Contributor

@ok300 ok300 left a comment

Choose a reason for hiding this comment

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

Left a few comments, otherwise looks good!

},
EndpointSuccess { data: LnUrlSuccessData },
EndpointError { data: LnUrlErrorData },
PayError { data: LnUrlPayErrorData },
Copy link
Contributor

Choose a reason for hiding this comment

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

@dleutenegger Useful new error type! Can you please add a line about it in the method's rustdoc?

Copy link
Member

Choose a reason for hiding this comment

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

This makes me think that perhaps the right way here is to return the errors as rust errors as right now we are mixing both success and error in the success case (We don't use rust error here).
I do understand the change as the mixture has been existed before this change so I am OK to leave it as is but perhaps after we merge the error code PR @dangeross we can think of changing here to use rust errors if that make sense of course?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the error code PR would give a clean way to return the payment hash (and the reason) of the failed payment, which was the intent of the original issue.

@@ -444,10 +444,20 @@ dictionary BitcoinAddressData {
string? message;
};

dictionary LnUrlSuccessData {
Copy link
Contributor

Choose a reason for hiding this comment

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

This only applies to LNURL-pay, so a more accurate name is LnUrlPaySuccessData IMO.

Err(SdkError::SendPaymentFailed { err }) => {
let invoice = parse_invoice(cb.pr.as_str())?;

return Ok(LnUrlPayResult::PayError {
Copy link
Contributor

Choose a reason for hiding this comment

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

Two points here:

  • for consistency, I would remove the return ...; and just place the Ok(..) on the last line of the block, just like the other two branches of match
  • is this really an Ok(..) and not an Err(..)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this needs to stay as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

The return is explicitly required as we want to exit the function and return the PayError to the caller.

We unwrap the result (and throw this error as well, if it would be wrapped as Err) just a few lines below in L317.

It must be an Ok(..) instead of an Err(..) as this is the current way the method handles errors, as pointed out by @roeierez Add payment hash to lnurl_pay() return type #550 (comment).

  • The current way (before the PR): we are not mixing success and error in the success case
  • The current way (in this PR): we are mixing them with the Ok(..) I mentioned above

So changing the Ok(..) into an Err(..) would address Roei's point around mixing result types. It would also make future migrations to SdkError simpler IMO.

Copy link
Contributor

@ok300 ok300 Oct 25, 2023

Choose a reason for hiding this comment

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

Nevermind, my bad.

You want to return LnUrlPayResult in the success case, so Ok(..) is correct.

The generic anyhow::Error thrown now only takes a string as arg, so cannot be used to wrap anything more meaningful. The send_payment step already throws an SdkError, but that's converted back to anyhow::Error when unwrapping on L317.

All this can be handled better with SdkError in the future.

data: maybe_sa_processed,
data: LnUrlSuccessData {
payment_hash: details.payment_hash.clone(),
data: maybe_sa_processed,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would make sense IMO.

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.

LGTM!

@dangeross
Copy link
Collaborator

Seems there is a conflict @dleutenegger. Can you take a look?

@dangeross
Copy link
Collaborator

Still some issues, can you rerun the flutter_rust_bridge?

@erdemyerebasmaz
Copy link
Contributor

Seems there is a conflict @dleutenegger. Can you take a look?
Still some issues, can you rerun the flutter_rust_bridge?

@dangeross This is likely due to latest Flutter SDK & flutter_rust_bridge_codegen upgrade.

@dleutenegger Could you rebase your branch on top of main first then run

make clean
make init
make dev 

from sdk-flutter directory.

@dangeross
Copy link
Collaborator

Hi @dleutenegger, would you mind rebasing and rerunning the RN codegen? I've just merged the error code PR #469 and there is a small conflict.

@dangeross dangeross merged commit 6b1b0d5 into breez:main Nov 7, 2023
7 checks passed
@dleutenegger dleutenegger deleted the lnurlp-expose-payment-hash branch November 8, 2023 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Return payment hash after trying to pay an LNURL-pay
5 participants