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

feat: bolt12 #370

Closed
wants to merge 27 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0848ad4
feat: pay bolt12 (backends not impl)
thesimplekid Sep 27, 2024
b1b6d4c
feat: phd pay offer
thesimplekid Oct 1, 2024
1c2c7a3
feat: cdk-cli melt bolt12
thesimplekid Oct 1, 2024
880fcc5
chore: update phd-rs
thesimplekid Oct 2, 2024
cd591ab
fix: check phd has valid payment id
thesimplekid Oct 2, 2024
f1494c5
fix: add unknown state to sql
thesimplekid Oct 2, 2024
113a449
feat: cln fetch invoice
thesimplekid Oct 2, 2024
fc046b7
feat: cln pay bolt12
thesimplekid Oct 2, 2024
de6e75e
feat: logging amoints
thesimplekid Oct 3, 2024
0933111
fix: phd fee
thesimplekid Oct 3, 2024
0b1464a
feat: bolt12 mint endpoints
thesimplekid Oct 3, 2024
d249f65
chore: clippy
thesimplekid Oct 4, 2024
bed9543
feat: cln mint via bolt12
thesimplekid Oct 4, 2024
25d8fde
feat: cdk-cli mint bolt12
thesimplekid Oct 4, 2024
98d7489
feat: mint cli
thesimplekid Oct 4, 2024
aa0ccab
feat: bolt12 info
thesimplekid Oct 4, 2024
f364fad
feat: wait any invoice, use offer id
thesimplekid Oct 5, 2024
2ac7c08
feat: add bolt12 router
thesimplekid Oct 6, 2024
bc2d114
feat: add cancel to wait invoice
thesimplekid Oct 6, 2024
590ad0d
feat: nut18/19 settings
thesimplekid Oct 7, 2024
122130e
feat: nut18/19 mint melt settings
thesimplekid Oct 7, 2024
10d8435
refactor: ln backend set up helpers
thesimplekid Oct 8, 2024
b34aa44
refactor: ln routers
thesimplekid Oct 8, 2024
24b637e
fix: rename cdk-mintd bin
thesimplekid Oct 8, 2024
baee4ea
fix: itest kill script
thesimplekid Oct 8, 2024
6bbfd56
feat: mint builder
thesimplekid Oct 8, 2024
54b783a
feat: use mintbuilder
thesimplekid Oct 9, 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
Prev Previous commit
Next Next commit
feat: cln pay bolt12
thesimplekid committed Oct 6, 2024
commit fc046b75c4dfb6bbaa1cf187c50705ec72be0418
78 changes: 75 additions & 3 deletions crates/cdk-cln/src/lib.rs
Original file line number Diff line number Diff line change
@@ -526,11 +526,83 @@ impl MintLightning for Cln {

async fn pay_bolt12_offer(
&self,
_melt_quote: mint::MeltQuote,
melt_quote: mint::MeltQuote,
_amount: Option<Amount>,
_max_fee_amount: Option<Amount>,
max_fee: Option<Amount>,
) -> Result<PayInvoiceResponse, Self::Err> {
todo!()
let bolt12 = &match melt_quote.request {
PaymentRequest::Bolt12 { offer: _, invoice } => invoice.ok_or(Error::UnknownInvoice)?,
PaymentRequest::Bolt11 { .. } => return Err(Error::WrongPaymentType.into()),
};

let pay_state = self
.check_outgoing_payment(&melt_quote.request_lookup_id)
.await?;

match pay_state.status {
MeltQuoteState::Unpaid | MeltQuoteState::Unknown | MeltQuoteState::Failed => (),
MeltQuoteState::Paid => {
tracing::debug!("Melt attempted on invoice already paid");
return Err(Self::Err::InvoiceAlreadyPaid);
}
MeltQuoteState::Pending => {
tracing::debug!("Melt attempted on invoice already pending");
return Err(Self::Err::InvoicePaymentPending);
}
}

let mut cln_client = self.cln_client.lock().await;
let cln_response = cln_client
.call(Request::Pay(PayRequest {
bolt11: bolt12.to_string(),
amount_msat: None,
label: None,
riskfactor: None,
maxfeepercent: None,
retry_for: None,
maxdelay: None,
exemptfee: None,
localinvreqid: None,
exclude: None,
maxfee: max_fee
.map(|a| {
let msat = to_unit(a, &melt_quote.unit, &CurrencyUnit::Msat)?;
Ok::<cln_rpc::primitives::Amount, Self::Err>(CLN_Amount::from_msat(
msat.into(),
))
})
.transpose()?,
description: None,
partial_msat: None,
}))
.await;

let response = match cln_response {
Ok(cln_rpc::Response::Pay(pay_response)) => {
let status = match pay_response.status {
PayStatus::COMPLETE => MeltQuoteState::Paid,
PayStatus::PENDING => MeltQuoteState::Pending,
PayStatus::FAILED => MeltQuoteState::Failed,
};
PayInvoiceResponse {
payment_preimage: Some(hex::encode(pay_response.payment_preimage.to_vec())),
payment_lookup_id: pay_response.payment_hash.to_string(),
status,
total_spent: to_unit(
pay_response.amount_sent_msat.msat(),
&CurrencyUnit::Msat,
&melt_quote.unit,
)?,
unit: melt_quote.unit,
}
}
_ => {
tracing::error!("Error attempting to pay invoice: {}", bolt12);
return Err(Error::WrongClnResponse.into());
}
};

Ok(response)
}
}