Module lightning_invoice::payment [−][src]
Expand description
A module for paying Lightning invoices.
Defines an InvoicePayer
utility for paying invoices, 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
.
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 = "...";
let invoice = invoice.parse::<Invoice>().unwrap();
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.
Number of attempts to retry payment path failures for an Invoice
.
Enums
An error that may occur when making a payment.