use crate::disk;
use crate::hex_utils;
use crate::{
- ChannelManager, FilesystemLogger, HTLCDirection, HTLCStatus, MillisatAmount, PaymentInfo,
- PaymentInfoStorage, PeerManager,
+ ChannelManager, FilesystemLogger, HTLCStatus, MillisatAmount, PaymentInfo, PaymentInfoStorage,
+ PeerManager,
};
use bitcoin::hashes::sha256::Hash as Sha256Hash;
use bitcoin::hashes::Hash;
use lightning::routing::router;
use lightning::routing::router::RouteHint;
use lightning::util::config::UserConfig;
+use lightning_invoice::{Currency, Invoice, InvoiceBuilder, Route, RouteHop};
use rand;
use rand::Rng;
use std::env;
pub(crate) async fn poll_for_user_input(
peer_manager: Arc<PeerManager>, channel_manager: Arc<ChannelManager>,
router: Arc<NetGraphMsgHandler<Arc<dyn chain::Access>, Arc<FilesystemLogger>>>,
- payment_storage: PaymentInfoStorage, node_privkey: SecretKey, event_notifier: mpsc::Sender<()>,
- ldk_data_dir: String, logger: Arc<FilesystemLogger>, network: Network,
+ inbound_payments: PaymentInfoStorage, outbound_payments: PaymentInfoStorage,
+ node_privkey: SecretKey, event_notifier: mpsc::Sender<()>, ldk_data_dir: String,
+ logger: Arc<FilesystemLogger>, network: Network,
) {
println!("LDK startup successful. To view available commands: \"help\".\nLDK logs are available at <your-supplied-ldk-data-dir-path>/.ldk/logs");
let stdin = io::stdin();
continue;
}
- let invoice_res = lightning_invoice::Invoice::from_str(invoice_str.unwrap());
+ let invoice_res = Invoice::from_str(invoice_str.unwrap());
if invoice_res.is_err() {
println!("ERROR: invalid invoice: {:?}", invoice_res.unwrap_err());
print!("> ");
continue;
}
let invoice = invoice_res.unwrap();
- let route_hints: Vec<lightning_invoice::Route> =
+ let route_hints: Vec<Route> =
invoice.routes().iter().map(|&route| route.clone()).collect();
let amt_pico_btc = invoice.amount_pico_btc();
route_hints,
router.clone(),
channel_manager.clone(),
- payment_storage.clone(),
+ outbound_payments.clone(),
logger.clone(),
);
}
}
get_invoice(
amt_msat.unwrap(),
- payment_storage.clone(),
+ inbound_payments.clone(),
node_privkey.clone(),
channel_manager.clone(),
network,
}
}
"listchannels" => list_channels(channel_manager.clone()),
- "listpayments" => list_payments(payment_storage.clone()),
+ "listpayments" => {
+ list_payments(inbound_payments.clone(), outbound_payments.clone())
+ }
"closechannel" => {
let channel_id_str = words.next();
if channel_id_str.is_none() {
println!("]");
}
-fn list_payments(payment_storage: PaymentInfoStorage) {
- let payments = payment_storage.lock().unwrap();
+fn list_payments(inbound_payments: PaymentInfoStorage, outbound_payments: PaymentInfoStorage) {
+ let inbound = inbound_payments.lock().unwrap();
+ let outbound = outbound_payments.lock().unwrap();
print!("[");
- for (payment_hash, payment_info) in payments.deref() {
- let direction_str = match payment_info.direction {
- HTLCDirection::Inbound => "inbound",
- HTLCDirection::Outbound => "outbound",
- };
+ for (payment_hash, payment_info) in inbound.deref() {
+ println!("");
+ println!("\t{{");
+ println!("\t\tamount_millisatoshis: {},", payment_info.amt_msat);
+ println!("\t\tpayment_hash: {},", hex_utils::hex_str(&payment_hash.0));
+ println!("\t\thtlc_direction: inbound,");
+ println!(
+ "\t\thtlc_status: {},",
+ match payment_info.status {
+ HTLCStatus::Pending => "pending",
+ HTLCStatus::Succeeded => "succeeded",
+ HTLCStatus::Failed => "failed",
+ }
+ );
+
+ println!("\t}},");
+ }
+
+ for (payment_hash, payment_info) in outbound.deref() {
println!("");
println!("\t{{");
println!("\t\tamount_millisatoshis: {},", payment_info.amt_msat);
println!("\t\tpayment_hash: {},", hex_utils::hex_str(&payment_hash.0));
- println!("\t\thtlc_direction: {},", direction_str);
+ println!("\t\thtlc_direction: outbound,");
println!(
"\t\thtlc_status: {},",
match payment_info.status {
fn send_payment(
payee: PublicKey, amt_msat: u64, final_cltv: u32, payment_hash: PaymentHash,
payment_secret: Option<PaymentSecret>, payee_features: Option<InvoiceFeatures>,
- mut route_hints: Vec<lightning_invoice::Route>,
+ mut route_hints: Vec<Route>,
router: Arc<NetGraphMsgHandler<Arc<dyn chain::Access>, Arc<FilesystemLogger>>>,
channel_manager: Arc<ChannelManager>, payment_storage: PaymentInfoStorage,
logger: Arc<FilesystemLogger>,
PaymentInfo {
preimage: None,
secret: payment_secret,
- direction: HTLCDirection::Outbound,
status,
amt_msat: MillisatAmount(Some(amt_msat)),
},
let payment_hash = Sha256Hash::hash(&preimage);
let our_node_pubkey = channel_manager.get_our_node_id();
- let mut invoice = lightning_invoice::InvoiceBuilder::new(match network {
- Network::Bitcoin => lightning_invoice::Currency::Bitcoin,
- Network::Testnet => lightning_invoice::Currency::BitcoinTestnet,
- Network::Regtest => lightning_invoice::Currency::Regtest,
+ let mut invoice = InvoiceBuilder::new(match network {
+ Network::Bitcoin => Currency::Bitcoin,
+ Network::Testnet => Currency::BitcoinTestnet,
+ Network::Regtest => Currency::Regtest,
Network::Signet => panic!("Signet invoices not supported"),
})
.payment_hash(payment_hash)
if forwarding_info.cltv_expiry_delta > min_final_cltv_expiry {
min_final_cltv_expiry = forwarding_info.cltv_expiry_delta;
}
- invoice = invoice.route(vec![lightning_invoice::RouteHop {
+ invoice = invoice.route(vec![RouteHop {
pubkey: channel.remote_network_id,
short_channel_id,
fee_base_msat: forwarding_info.fee_base_msat,
// Otherwise lnd errors with "destination hop doesn't understand payment addresses"
// (for context, lnd calls payment secrets "payment addresses").
secret: None,
- direction: HTLCDirection::Inbound,
status: HTLCStatus::Pending,
amt_msat: MillisatAmount(Some(amt_msat)),
},