-
Notifications
You must be signed in to change notification settings - Fork 7
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 support for paying to BOLT12 #549
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Ross Savage <551697+dangeross@users.noreply.github.com>
# Conflicts: # cli/src/commands.rs # lib/core/src/sdk.rs
Don't try to extract invoice description, because it is added later during persist.
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.
Looking good
_ => Err(PaymentError::amount_missing( | ||
"Expected PayAmount of type Receiver when processing a Bolt12 offer", | ||
)), |
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 it's fine to not handle the drain case now, there are issues to inverse calculate the Boltz fee #559.
Co-authored-by: Ross Savage <551697+dangeross@users.noreply.github.com>
MRH with Bolt12 is not possible because receive is not yet supported.
Removed self-transfer check TODO, because self-transfers are not possible with Bolt12 when receive is not supported.
a3477b4
to
9920648
Compare
// Add bolt12_offer column for Send Swaps | ||
" | ||
ALTER TABLE send_swaps RENAME TO send_swaps_old; | ||
|
||
CREATE TABLE send_swaps ( | ||
id TEXT NOT NULL PRIMARY KEY, | ||
invoice TEXT NOT NULL UNIQUE, | ||
bolt12_offer TEXT, | ||
preimage TEXT, | ||
payer_amount_sat INTEGER NOT NULL, | ||
receiver_amount_sat INTEGER NOT NULL, | ||
create_response_json TEXT NOT NULL, | ||
refund_private_key TEXT NOT NULL, | ||
lockup_tx_id TEXT, | ||
refund_tx_id TEXT, | ||
created_at INTEGER NOT NULL, | ||
state INTEGER NOT NULL, | ||
description TEXT, | ||
id_hash TEXT, | ||
payment_hash TEXT | ||
) STRICT; | ||
|
||
INSERT INTO send_swaps ( | ||
id, | ||
invoice, | ||
bolt12_offer, | ||
preimage, | ||
payer_amount_sat, | ||
receiver_amount_sat, | ||
create_response_json, | ||
refund_private_key, | ||
lockup_tx_id, | ||
refund_tx_id, | ||
created_at, | ||
state, | ||
description, | ||
id_hash, | ||
payment_hash | ||
) SELECT | ||
id, | ||
invoice, | ||
NULL, | ||
preimage, | ||
payer_amount_sat, | ||
receiver_amount_sat, | ||
create_response_json, | ||
refund_private_key, | ||
lockup_tx_id, | ||
refund_tx_id, | ||
created_at, | ||
state, | ||
description, | ||
id_hash, | ||
payment_hash | ||
FROM send_swaps_old; | ||
|
||
DROP TABLE send_swaps_old; | ||
", |
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.
If we're adding a nullable column, do we need to recreate the table?
bolt11: match maybe_send_swap_bolt12_offer.is_some() { | ||
true => None, // We don't expose the Bolt12 invoice | ||
false => maybe_send_swap_invoice, | ||
}, | ||
bolt12_offer: maybe_send_swap_bolt12_offer, |
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.
Why don't we expose the bolt12 invoice? The bolt11
is used as the payment destination in the send swap case, so we need to use either the offer or invoice.
Lightning(string swap_id, string description, string? preimage, string? bolt11, string? payment_hash, string? refund_tx_id, u64? refund_tx_amount_sat); | ||
Lightning(string swap_id, string description, string? preimage, string? bolt11, string? bolt12_offer, string? payment_hash, string? refund_tx_id, u64? refund_tx_amount_sat); |
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.
RN needs regenerating
@@ -533,7 +533,7 @@ interface GetPaymentRequest { | |||
|
|||
[Enum] | |||
interface PaymentDetails { | |||
Lightning(string swap_id, string description, string? preimage, string? bolt11, string? payment_hash, string? refund_tx_id, u64? refund_tx_amount_sat); | |||
Lightning(string swap_id, string description, string? preimage, string? bolt11, string? bolt12_offer, string? payment_hash, string? refund_tx_id, u64? refund_tx_amount_sat); |
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 change I think requires the notification plugin to be updated
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.
Other than @dangeross comments I think it looks good!
This PR adds support for paying to a BOLT12 offer.
The flow is as follows:
send_payment_via_swap
with the BOLT12 invoice as argument, instead of the usual BOLT11Open questions
PaymentDetails::Lightning
with a new field forbolt12_invoice
? And / or an optionalbolt12_offer
?bolt11
field toinvoice
, so it means either BOLT11 or BOLT12 invoice?prepare
? This may take a long time for slow endpoints (Phoenix), causing the user to wait a few seconds forprepare
to return.sdk_common::input_parser
to parse BOLT12 offers / invoice? Or keep changes local to the Liquid SDK?Open TODOs
Detect / handle MRH in BOLT12 invoiceslist_payments
shows payments asPending
list_payments
shows the bolt12 invoice underbolt11
(should show offer instead)