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

Get Payment #476

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Get Payment #476

wants to merge 6 commits into from

Conversation

dangeross
Copy link
Collaborator

@dangeross dangeross commented Sep 5, 2024

This PR adds a method to lookup a payment using payment query arguments, which can be one of:

  • Lightning invoice
  • Invoice payment hash
  • Liquid BIP21 URI / address destination
  • Bitcoin address

Fixes #473

lib/core/src/persist/mod.rs Outdated Show resolved Hide resolved
@dangeross dangeross marked this pull request as ready for review September 6, 2024 10:33
.get_connection()?
.query_row(
&self.select_payment_query(
Some("(rs.invoice = ?1 OR ss.invoice = ?1 OR cs.claim_address = ?1 OR pd.destination = ?1)"),
Copy link
Member

@roeierez roeierez Sep 9, 2024

Choose a reason for hiding this comment

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

It seems that a payment may have multiple destinations? This means that get_payment_by_destination may return same result for different destinations? for example for invoice and bip21 that was parsed as input?

Copy link
Collaborator

@hydra-yse hydra-yse Sep 9, 2024

Choose a reason for hiding this comment

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

@roeierez Currently there's no case where this can happen. Specifically, here's the cases:

  • Receive Swap/Chain Swap: No payment details set, no conflict can occur
  • Send swap using Boltz: No payment details set, no conflict can occur
  • Direct Send/Send "swap" with invoice MRH: We persist data as a Liquid payment, therefore there is no data in the swap tables
  • Generic non-SDK payment (as of Set PaymentDetails as mandatory, default to LiquidAddress #474): We persist the tx's output's script pubkey in the payment details. We have no data in the swap tables.

So in all cases the swap/details are mutually exclusive, meaning there's no way for two inputs to return the same payment.

Note: We may want to change the MRH behavior in the future (since we were considering to store also the invoice so we can index by it). So if that's planned then I agree we will have a conflict

Copy link
Member

Choose a reason for hiding this comment

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

I see, so I guess only removing the claim address is needed? @dangeross

Copy link
Member

Choose a reason for hiding this comment

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

@dangeross do you think it makes sense instead of a string to use an enum so the query will be more intuitive and search will look up for the specific identifier?

PaymentDestination {
  Lightning(bolt11),
  Liquid(address),
  Bitcoin(address)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@roeierez Yeah, it does make it more intuitive and fits in with other functions of the SDK.

@dangeross dangeross force-pushed the savage-payment-by-destination branch 2 times, most recently from 40e92fd to e20fc03 Compare September 9, 2024 18:45
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

Copy link
Collaborator

@hydra-yse hydra-yse left a comment

Choose a reason for hiding this comment

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

Just a comment regarding naming, everything else looks good 😄

Comment on lines 1988 to 2021
pub async fn payment_by_destination(
&self,
destination: &PaymentDestination,
) -> Result<Option<Payment>, PaymentError> {
self.ensure_is_started().await?;

Ok(self.persister.get_payment_by_destination(destination)?)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking back on the changes, wouldn't it be better to name this get_payment_by_destination like the persister method? I'm afraid this could be misinterpreted as executing a payment by destination.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, I've since added payment_hash as a query option so get_payment() makes more sense now

@dangeross dangeross changed the title Get payment by destination Get Payment Sep 30, 2024
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.

Add a method to lookup a payment
4 participants