-fn send_payment(
- payee: PublicKey, amt_msat: u64, final_cltv: u32, payment_hash: PaymentHash,
- payment_secret: Option<PaymentSecret>, payee_features: Option<InvoiceFeatures>,
- route_hints: Vec<&RouteHint>,
- router: Arc<NetGraphMsgHandler<Arc<dyn chain::Access + Send + Sync>, Arc<FilesystemLogger>>>,
+fn send_payment<E: EventHandler>(
+ invoice_payer: &InvoicePayer<E>, invoice: &Invoice, payment_storage: PaymentInfoStorage,
+) {
+ let status = match invoice_payer.pay_invoice(invoice) {
+ Ok(_payment_id) => {
+ let payee_pubkey = invoice.recover_payee_pub_key();
+ let amt_msat = invoice.amount_milli_satoshis().unwrap();
+ println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
+ print!("> ");
+ HTLCStatus::Pending
+ }
+ Err(PaymentError::Invoice(e)) => {
+ println!("ERROR: invalid invoice: {}", e);
+ print!("> ");
+ return;
+ }
+ Err(PaymentError::Routing(e)) => {
+ println!("ERROR: failed to find route: {}", e.err);
+ print!("> ");
+ return;
+ }
+ Err(PaymentError::Sending(e)) => {
+ println!("ERROR: failed to send payment: {:?}", e);
+ print!("> ");
+ HTLCStatus::Failed
+ }
+ };
+ let payment_hash = PaymentHash(invoice.payment_hash().clone().into_inner());
+ let payment_secret = Some(invoice.payment_secret().clone());
+
+ let mut payments = payment_storage.lock().unwrap();
+ payments.insert(
+ payment_hash,
+ PaymentInfo {
+ preimage: None,
+ secret: payment_secret,
+ status,
+ amt_msat: MillisatAmount(invoice.amount_milli_satoshis()),
+ },
+ );
+}
+
+fn keysend(
+ payee_pubkey: PublicKey, amt_msat: u64, network_graph: Arc<NetworkGraph>,