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 support for paying to BOLT12 #549

Merged
merged 33 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1e1a00d
Add initial version of paying to a BOLT12 offer
ok300 Nov 6, 2024
06e6529
Bump sdk-common
ok300 Nov 10, 2024
f4d6a3b
SendDestination: Bolt12 type stores amount in addition to offer
ok300 Nov 10, 2024
5521b1e
prepare_send_payment: remove fetching Bolt12 invoice
ok300 Nov 10, 2024
8244e1c
Re-generate RN bindings
ok300 Nov 10, 2024
e76c8f9
Bump sdk-common with new Bolt12Offer(String)
ok300 Nov 13, 2024
47841e4
Update lib/core/src/sdk.rs
ok300 Nov 13, 2024
96a12b2
Merge branch 'main' into ok300-add-bolt12
ok300 Nov 13, 2024
f5839e6
Re-generate RN bindings
ok300 Nov 13, 2024
68449c2
Fix tests
ok300 Nov 13, 2024
790d8f2
Address invoice description persistence
ok300 Nov 13, 2024
0219b99
Bump sdk-common to use new InputType variant
ok300 Nov 13, 2024
690e2e6
Cargo fmt
ok300 Nov 13, 2024
43a0bfe
Bump sdk-common to include fixed type reference
ok300 Nov 13, 2024
bb18d10
Update SendDestination::Bolt12 to include LNOffer
ok300 Nov 13, 2024
4a53177
Re-generate RN bindings
ok300 Nov 13, 2024
2928ed9
Bump sdk-common, propagate changes
ok300 Nov 14, 2024
f9b9d54
Update cli/src/commands.rs
ok300 Nov 14, 2024
10fbefa
Bump sdk-common, propagate changes
ok300 Nov 14, 2024
9ae1f6c
Clarify CLI invoice description
ok300 Nov 14, 2024
83ccce0
Address MRH TODO
ok300 Nov 14, 2024
b54da49
Address self-transfer TODO
ok300 Nov 14, 2024
6be99de
Add Bolt12 invoice validation before paying
ok300 Nov 15, 2024
ead0438
Extract Bolt12 invoice validation to own method
ok300 Nov 15, 2024
2423180
Persist bolt12_offer in DB
ok300 Nov 18, 2024
9920648
prepare_send_payment: validate user chosen amount
ok300 Nov 18, 2024
380f2a1
boltz-client: switch to latest upstream
ok300 Nov 18, 2024
c069f99
verify_payment_hash: handle bolt11 and bolt12 invoices
ok300 Nov 18, 2024
eec205e
Rename LNOfferBlindedPath to LnOfferBlindedPath
ok300 Nov 18, 2024
290e04e
Update notification plugin
ok300 Nov 19, 2024
13ebcfe
Simplify migration
ok300 Nov 19, 2024
7124f6d
Bump sdk-common
ok300 Nov 19, 2024
81eeb66
When sending to Bolt12 offers, treat the offer as destination
ok300 Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 141 additions & 8 deletions cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 26 additions & 22 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;
use std::thread;
use std::time::Duration;

use anyhow::Result;
use anyhow::{anyhow, Result};
use breez_sdk_liquid::prelude::*;
use clap::{arg, Parser};
use qrcode_rs::render::unicode;
Expand All @@ -21,10 +21,14 @@ use serde_json::to_string_pretty;
pub(crate) enum Command {
/// Send a payment directly or via a swap
SendPayment {
/// Invoice which has to be paid
/// Invoice which has to be paid (BOLT11 or BOLT12)
#[arg(long)]
invoice: Option<String>,

/// BOLT12 offer. If specified, amount_sat must also be set.
#[arg(long)]
offer: Option<String>,

/// Either BIP21 URI or Liquid address we intend to pay to
#[arg(long)]
address: Option<String>,
Expand Down Expand Up @@ -286,12 +290,12 @@ pub(crate) async fn handle_command(
InputType::Bolt11 { invoice } => result.push_str(&build_qr_text(&invoice.bolt11)),
InputType::LiquidAddress { address } => {
result.push_str(&build_qr_text(&address.to_uri().map_err(|e| {
anyhow::anyhow!("Could not build BIP21 from address data: {e:?}")
anyhow!("Could not build BIP21 from address data: {e:?}")
})?))
}
InputType::BitcoinAddress { address } => {
result.push_str(&build_qr_text(&address.to_uri().map_err(|e| {
anyhow::anyhow!("Could not build BIP21 from address data: {e:?}")
anyhow!("Could not build BIP21 from address data: {e:?}")
})?))
}
_ => {}
Expand All @@ -308,24 +312,24 @@ pub(crate) async fn handle_command(
}
Command::SendPayment {
invoice,
offer,
address,
amount_sat,
delay,
} => {
let destination = match (invoice, address) {
(None, None) => {
return Err(anyhow::anyhow!(
"Must specify either an invoice or a direct/BIP21 address."
))
}
(Some(invoice), None) => invoice,
(None, Some(address)) => address,
(Some(_), Some(_)) => {
return Err(anyhow::anyhow!(
"Cannot specify both invoice and address at the same time."
let destination = match (invoice, offer, address) {
(Some(invoice), None, None) => Ok(invoice),
(None, Some(offer), None) => match amount_sat {
Some(_) => Ok(offer),
None => Err(anyhow!(
"Must specify either a BOLT11 invoice, a BOLT12 offer or a direct/BIP21 address."
ok300 marked this conversation as resolved.
Show resolved Hide resolved
))
}
};
},
(None, None, Some(address)) => Ok(address),
_ => Err(anyhow!(
"Must specify either a BOLT11 invoice, a BOLT12 offer or a direct/BIP21 address."
))
}?;

let prepare_response = sdk
.prepare_send_payment(&PrepareSendRequest {
Expand Down Expand Up @@ -368,7 +372,7 @@ pub(crate) async fn handle_command(
let amount = match drain.unwrap_or(false) {
true => PayOnchainAmount::Drain,
false => PayOnchainAmount::Receiver {
amount_sat: receiver_amount_sat.ok_or(anyhow::anyhow!(
amount_sat: receiver_amount_sat.ok_or(anyhow!(
"Must specify `receiver_amount_sat` if not draining"
))?,
},
Expand Down Expand Up @@ -482,7 +486,7 @@ pub(crate) async fn handle_command(
match maybe_payment {
Some(payment) => command_result!(payment),
None => {
return Err(anyhow::anyhow!("Payment not found."));
return Err(anyhow!("Payment not found."));
}
}
}
Expand Down Expand Up @@ -585,7 +589,7 @@ pub(crate) async fn handle_command(
.await?;
Ok(pay_res)
}
_ => Err(anyhow::anyhow!("Invalid input")),
_ => Err(anyhow!("Invalid input")),
}?;

command_result!(res)
Expand All @@ -609,7 +613,7 @@ pub(crate) async fn handle_command(
.await?;
Ok(withdraw_res)
}
_ => Err(anyhow::anyhow!("Invalid input")),
_ => Err(anyhow!("Invalid input")),
}?;

command_result!(res)
Expand All @@ -622,7 +626,7 @@ pub(crate) async fn handle_command(
let auth_res = sdk.lnurl_auth(ad).await?;
serde_json::to_string_pretty(&auth_res).map_err(|e| e.into())
}
_ => Err(anyhow::anyhow!("Unexpected result type")),
_ => Err(anyhow!("Unexpected result type")),
}?;

command_result!(res)
Expand Down
Loading
Loading