use crate::disk;
use crate::hex_utils;
use crate::{
- ChannelManager, FilesystemLogger, HTLCStatus, MillisatAmount, PaymentInfo,
- PaymentInfoStorage, PeerManager,
+ ChannelManager, FilesystemLogger, HTLCStatus, MillisatAmount, PaymentInfo, PaymentInfoStorage,
+ PeerManager,
};
use bitcoin::hashes::sha256::Hash as Sha256Hash;
use bitcoin::hashes::Hash;
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();
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() {
+ 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 {
async fn handle_ldk_events(
channel_manager: Arc<ChannelManager>, chain_monitor: Arc<ChainMonitor>,
bitcoind_client: Arc<BitcoindClient>, keys_manager: Arc<KeysManager>,
- payment_storage: PaymentInfoStorage, network: Network,
+ inbound_payments: PaymentInfoStorage, outbound_payments: PaymentInfoStorage, network: Network,
) {
loop {
let loop_channel_manager = channel_manager.clone();
.unwrap();
}
Event::PaymentReceived { payment_hash, .. } => {
- let mut payments = payment_storage.lock().unwrap();
+ let mut payments = inbound_payments.lock().unwrap();
if let Some(payment) = payments.get_mut(&payment_hash) {
assert!(loop_channel_manager.claim_funds(
payment.preimage.unwrap().clone(),
}
Event::PaymentSent { payment_preimage } => {
let hashed = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
- let mut payments = payment_storage.lock().unwrap();
+ let mut payments = outbound_payments.lock().unwrap();
for (payment_hash, payment) in payments.iter_mut() {
if *payment_hash == hashed {
payment.preimage = Some(payment_preimage);
print!("> ");
io::stdout().flush().unwrap();
- let mut payments = payment_storage.lock().unwrap();
+ let mut payments = outbound_payments.lock().unwrap();
if payments.contains_key(&payment_hash) {
let payment = payments.get_mut(&payment_hash).unwrap();
payment.status = HTLCStatus::Failed;
let chain_monitor_event_listener = chain_monitor.clone();
let keys_manager_listener = keys_manager.clone();
// TODO: persist payment info to disk
- let payment_info: PaymentInfoStorage = Arc::new(Mutex::new(HashMap::new()));
- let payment_info_for_events = payment_info.clone();
+ let inbound_payments: PaymentInfoStorage = Arc::new(Mutex::new(HashMap::new()));
+ let outbound_payments: PaymentInfoStorage = Arc::new(Mutex::new(HashMap::new()));
+ let inbound_pmts_for_events = inbound_payments.clone();
+ let outbound_pmts_for_events = outbound_payments.clone();
let network = args.network;
let bitcoind_rpc = bitcoind_client.clone();
tokio::spawn(async move {
chain_monitor_event_listener,
bitcoind_rpc,
keys_manager_listener,
- payment_info_for_events,
+ inbound_pmts_for_events,
+ outbound_pmts_for_events,
network,
)
.await;
peer_manager.clone(),
channel_manager.clone(),
router.clone(),
- payment_info,
+ inbound_payments,
+ outbound_payments,
keys_manager.get_node_secret(),
event_ntfn_sender,
ldk_data_dir.clone(),