-
Notifications
You must be signed in to change notification settings - Fork 110
Expose Bolt11Invoice type in bindings #522
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,14 +30,37 @@ use lightning::routing::router::{PaymentParameters, RouteParameters}; | |
|
||
use lightning_types::payment::{PaymentHash, PaymentPreimage}; | ||
|
||
use lightning_invoice::Bolt11Invoice; | ||
use lightning_invoice::Bolt11Invoice as LdkBolt11Invoice; | ||
use lightning_invoice::Bolt11InvoiceDescription as LdkBolt11InvoiceDescription; | ||
|
||
use bitcoin::hashes::sha256::Hash as Sha256; | ||
use bitcoin::hashes::Hash; | ||
|
||
use std::sync::{Arc, RwLock}; | ||
|
||
#[cfg(not(feature = "uniffi"))] | ||
type Bolt11Invoice = LdkBolt11Invoice; | ||
#[cfg(feature = "uniffi")] | ||
type Bolt11Invoice = Arc<crate::uniffi_types::Bolt11Invoice>; | ||
|
||
#[cfg(not(feature = "uniffi"))] | ||
pub(crate) fn maybe_wrap_invoice(invoice: LdkBolt11Invoice) -> Bolt11Invoice { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm starting to wonder if we really need type-dependant methods for everything we wrap. I think we should look to DRY them up, e.g., to be reused for Probably fine to leave as-is here, but in the next PR we should start DRYing the wrapping code where we can (i.e., will probably also make sense to move these to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, good point. Will try a couple of things for the types to come |
||
invoice | ||
} | ||
#[cfg(feature = "uniffi")] | ||
pub(crate) fn maybe_wrap_invoice(invoice: LdkBolt11Invoice) -> Bolt11Invoice { | ||
Arc::new(invoice.into()) | ||
} | ||
|
||
#[cfg(not(feature = "uniffi"))] | ||
pub fn maybe_convert_invoice(invoice: &Bolt11Invoice) -> &LdkBolt11Invoice { | ||
invoice | ||
} | ||
#[cfg(feature = "uniffi")] | ||
pub fn maybe_convert_invoice(invoice: &Bolt11Invoice) -> &LdkBolt11Invoice { | ||
&invoice.inner | ||
} | ||
|
||
#[cfg(not(feature = "uniffi"))] | ||
type Bolt11InvoiceDescription = LdkBolt11InvoiceDescription; | ||
#[cfg(feature = "uniffi")] | ||
|
@@ -101,6 +124,7 @@ impl Bolt11Payment { | |
pub fn send( | ||
&self, invoice: &Bolt11Invoice, sending_parameters: Option<SendingParameters>, | ||
) -> Result<PaymentId, Error> { | ||
let invoice = maybe_convert_invoice(invoice); | ||
let rt_lock = self.runtime.read().unwrap(); | ||
if rt_lock.is_none() { | ||
return Err(Error::NotRunning); | ||
|
@@ -209,6 +233,7 @@ impl Bolt11Payment { | |
&self, invoice: &Bolt11Invoice, amount_msat: u64, | ||
sending_parameters: Option<SendingParameters>, | ||
) -> Result<PaymentId, Error> { | ||
let invoice = maybe_convert_invoice(invoice); | ||
let rt_lock = self.runtime.read().unwrap(); | ||
if rt_lock.is_none() { | ||
return Err(Error::NotRunning); | ||
|
@@ -441,7 +466,8 @@ impl Bolt11Payment { | |
&self, amount_msat: u64, description: &Bolt11InvoiceDescription, expiry_secs: u32, | ||
) -> Result<Bolt11Invoice, Error> { | ||
let description = maybe_convert_description!(description); | ||
self.receive_inner(Some(amount_msat), description, expiry_secs, None) | ||
let invoice = self.receive_inner(Some(amount_msat), description, expiry_secs, None)?; | ||
Ok(maybe_wrap_invoice(invoice)) | ||
} | ||
|
||
/// Returns a payable invoice that can be used to request a payment of the amount | ||
|
@@ -463,7 +489,9 @@ impl Bolt11Payment { | |
payment_hash: PaymentHash, | ||
) -> Result<Bolt11Invoice, Error> { | ||
let description = maybe_convert_description!(description); | ||
self.receive_inner(Some(amount_msat), description, expiry_secs, Some(payment_hash)) | ||
let invoice = | ||
self.receive_inner(Some(amount_msat), description, expiry_secs, Some(payment_hash))?; | ||
Ok(maybe_wrap_invoice(invoice)) | ||
} | ||
|
||
/// Returns a payable invoice that can be used to request and receive a payment for which the | ||
|
@@ -474,7 +502,8 @@ impl Bolt11Payment { | |
&self, description: &Bolt11InvoiceDescription, expiry_secs: u32, | ||
) -> Result<Bolt11Invoice, Error> { | ||
let description = maybe_convert_description!(description); | ||
self.receive_inner(None, description, expiry_secs, None) | ||
let invoice = self.receive_inner(None, description, expiry_secs, None)?; | ||
Ok(maybe_wrap_invoice(invoice)) | ||
} | ||
|
||
/// Returns a payable invoice that can be used to request a payment for the given payment hash | ||
|
@@ -495,13 +524,14 @@ impl Bolt11Payment { | |
&self, description: &Bolt11InvoiceDescription, expiry_secs: u32, payment_hash: PaymentHash, | ||
) -> Result<Bolt11Invoice, Error> { | ||
let description = maybe_convert_description!(description); | ||
self.receive_inner(None, description, expiry_secs, Some(payment_hash)) | ||
let invoice = self.receive_inner(None, description, expiry_secs, Some(payment_hash))?; | ||
Ok(maybe_wrap_invoice(invoice)) | ||
} | ||
|
||
pub(crate) fn receive_inner( | ||
&self, amount_msat: Option<u64>, invoice_description: &LdkBolt11InvoiceDescription, | ||
expiry_secs: u32, manual_claim_payment_hash: Option<PaymentHash>, | ||
) -> Result<Bolt11Invoice, Error> { | ||
) -> Result<LdkBolt11Invoice, Error> { | ||
let invoice = { | ||
let invoice_params = Bolt11InvoiceParameters { | ||
amount_msats: amount_msat, | ||
|
@@ -571,13 +601,14 @@ impl Bolt11Payment { | |
max_total_lsp_fee_limit_msat: Option<u64>, | ||
) -> Result<Bolt11Invoice, Error> { | ||
let description = maybe_convert_description!(description); | ||
self.receive_via_jit_channel_inner( | ||
let invoice = self.receive_via_jit_channel_inner( | ||
Some(amount_msat), | ||
description, | ||
expiry_secs, | ||
max_total_lsp_fee_limit_msat, | ||
None, | ||
) | ||
)?; | ||
Ok(maybe_wrap_invoice(invoice)) | ||
} | ||
|
||
/// Returns a payable invoice that can be used to request a variable amount payment (also known | ||
|
@@ -596,20 +627,21 @@ impl Bolt11Payment { | |
max_proportional_lsp_fee_limit_ppm_msat: Option<u64>, | ||
) -> Result<Bolt11Invoice, Error> { | ||
let description = maybe_convert_description!(description); | ||
self.receive_via_jit_channel_inner( | ||
let invoice = self.receive_via_jit_channel_inner( | ||
None, | ||
description, | ||
expiry_secs, | ||
None, | ||
max_proportional_lsp_fee_limit_ppm_msat, | ||
) | ||
)?; | ||
Ok(maybe_wrap_invoice(invoice)) | ||
} | ||
|
||
fn receive_via_jit_channel_inner( | ||
&self, amount_msat: Option<u64>, description: &LdkBolt11InvoiceDescription, | ||
expiry_secs: u32, max_total_lsp_fee_limit_msat: Option<u64>, | ||
max_proportional_lsp_fee_limit_ppm_msat: Option<u64>, | ||
) -> Result<Bolt11Invoice, Error> { | ||
) -> Result<LdkBolt11Invoice, Error> { | ||
let liquidity_source = | ||
self.liquidity_source.as_ref().ok_or(Error::LiquiditySourceUnavailable)?; | ||
|
||
|
@@ -709,6 +741,7 @@ impl Bolt11Payment { | |
/// amount times [`Config::probing_liquidity_limit_multiplier`] won't be used to send | ||
/// pre-flight probes. | ||
pub fn send_probes(&self, invoice: &Bolt11Invoice) -> Result<(), Error> { | ||
let invoice = maybe_convert_invoice(invoice); | ||
let rt_lock = self.runtime.read().unwrap(); | ||
if rt_lock.is_none() { | ||
return Err(Error::NotRunning); | ||
|
@@ -741,6 +774,7 @@ impl Bolt11Payment { | |
pub fn send_probes_using_amount( | ||
&self, invoice: &Bolt11Invoice, amount_msat: u64, | ||
) -> Result<(), Error> { | ||
let invoice = maybe_convert_invoice(invoice); | ||
let rt_lock = self.runtime.read().unwrap(); | ||
if rt_lock.is_none() { | ||
return Err(Error::NotRunning); | ||
|
Uh oh!
There was an error while loading. Please reload this page.