Module lightning_invoice::payment [−][src]
Expand description
A module for paying Lightning invoices and sending spontaneous payments.
Defines an InvoicePayer
utility for sending payments, parameterized by Payer
and
Router
traits. Implementations of Payer
provide the payer’s node id, channels, and means
to send a payment over a Route
. Implementations of Router
find a Route
between payer
and payee using information provided by the payer and from the payee’s Invoice
, when
applicable.
InvoicePayer
is parameterized by a LockableScore
, which it uses for scoring failed and
successful payment paths upon receiving Event::PaymentPathFailed
and
Event::PaymentPathSuccessful
events, respectively.
InvoicePayer
is capable of retrying failed payments. It accomplishes this by implementing
EventHandler
which decorates a user-provided handler. It will intercept any
Event::PaymentPathFailed
events and retry the failed paths for a fixed number of total
attempts or until retry is no longer possible. In such a situation, InvoicePayer
will pass
along the events to the user-provided handler.
Example
let event_handler = |event: &Event| {
match event {
Event::PaymentPathFailed { .. } => println!("payment failed after retries"),
Event::PaymentSent { .. } => println!("payment successful"),
_ => {},
}
};
let invoice_payer = InvoicePayer::new(&payer, router, &scorer, &logger, event_handler, RetryAttempts(2));
let invoice = "...";
if let Ok(invoice) = invoice.parse::<Invoice>() {
invoice_payer.pay_invoice(&invoice).unwrap();
loop {
event_provider.process_pending_events(&invoice_payer);
}
}
Note
The Route
is computed before each payment attempt. Any updates affecting path finding such
as updates to the network graph or changes to channel scores should be applied prior to
retries, typically by way of composing EventHandler
s accordingly.
Structs
A utility for paying Invoice
s and sending spontaneous payments.
Number of attempts to retry payment path failures for an Invoice
.
Enums
An error that may occur when making a payment.