-
Notifications
You must be signed in to change notification settings - Fork 43
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
Conversation
|
||
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 |
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.
Typo?
@@ -3018,6 +3023,15 @@ class BreezSDKMapper { | |||
"type": "endpointError", | |||
"data": dictionaryOf(lnUrlErrorData: data), | |||
] | |||
|
|||
case let .payError( | |||
paymentHashreason |
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.
Typo?
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.
Seemed to be an issue with the rn codegen. I moved the LnUrlPayResult
data into wrapper structs, which resolved the issue.
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'll investigate the RN codegen issue
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 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.
27b2847
to
6d5e659
Compare
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.
Looks good otherwise. Just a comment around naming
libs/sdk-core/src/breez_services.rs
Outdated
data: maybe_sa_processed, | ||
data: LnUrlSuccessData { | ||
payment_hash: details.payment_hash.clone(), | ||
data: maybe_sa_processed, |
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.
Can I propose we change data
to success_action
to avoid data.data
?
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.
Would make sense IMO.
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.
Left a few comments, otherwise looks good!
}, | ||
EndpointSuccess { data: LnUrlSuccessData }, | ||
EndpointError { data: LnUrlErrorData }, | ||
PayError { data: LnUrlPayErrorData }, |
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.
@dleutenegger Useful new error type! Can you please add a line about it in the method's rustdoc?
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 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?
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 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.
libs/sdk-bindings/src/breez_sdk.udl
Outdated
@@ -444,10 +444,20 @@ dictionary BitcoinAddressData { | |||
string? message; | |||
}; | |||
|
|||
dictionary LnUrlSuccessData { |
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 only applies to LNURL-pay, so a more accurate name is LnUrlPaySuccessData
IMO.
libs/sdk-core/src/breez_services.rs
Outdated
Err(SdkError::SendPaymentFailed { err }) => { | ||
let invoice = parse_invoice(cb.pr.as_str())?; | ||
|
||
return Ok(LnUrlPayResult::PayError { |
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.
Two points here:
- for consistency, I would remove the
return ...;
and just place theOk(..)
on the last line of the block, just like the other two branches ofmatch
- is this really an
Ok(..)
and not anErr(..)
?
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 this needs to stay as is.
- The return is explicitly required as we want to exit the function and return the
PayError
to the caller. - It must be an
Ok(..)
instead of anErr(..)
as this is the current way the method handles errors, as pointed out by @roeierez Add payment hash tolnurl_pay()
return type #550 (comment).
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 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 anErr(..)
as this is the current way the method handles errors, as pointed out by @roeierez Add payment hash tolnurl_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.
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.
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.
libs/sdk-core/src/breez_services.rs
Outdated
data: maybe_sa_processed, | ||
data: LnUrlSuccessData { | ||
payment_hash: details.payment_hash.clone(), | ||
data: maybe_sa_processed, |
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.
Would make sense IMO.
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.
LGTM!
7b6b7f0
to
bb1b3b4
Compare
Seems there is a conflict @dleutenegger. Can you take a look? |
bb1b3b4
to
82044db
Compare
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
from sdk-flutter directory. |
82044db
to
8bd80b5
Compare
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. |
8bd80b5
to
5ed953a
Compare
5ed953a
to
097f53a
Compare
Resolves #540