Skip to content

Commit 80e8d4c

Browse files
committed
[skip ci] Expose log_debug_info method
1 parent e32fafe commit 80e8d4c

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

examples/3l-node/cli.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ pub(crate) fn poll_for_user_input(node: &LightningNode, log_file_path: &str) {
132132
Ok(uuid) => println!("{uuid}"),
133133
Err(message) => eprintln!("{}", message.red()),
134134
},
135+
"logdebug" => {
136+
if let Err(e) = node.log_debug_info() {
137+
println!("{}", e.to_string().red());
138+
}
139+
}
135140
"foreground" => {
136141
node.foreground();
137142
}
@@ -205,6 +210,7 @@ fn setup_editor(history_path: &Path) -> Editor<CommandHinter, DefaultHistory> {
205210
"paymentuuid <payment hash>",
206211
"paymentuuid",
207212
));
213+
hints.insert(CommandHint::new("logdebug", "logdebug"));
208214
hints.insert(CommandHint::new("foreground", "foreground"));
209215
hints.insert(CommandHint::new("background", "background"));
210216
hints.insert(CommandHint::new("stop", "stop"));
@@ -240,6 +246,8 @@ fn help() {
240246
println!(" listpayments");
241247
println!(" paymentuuid <payment hash>");
242248
println!();
249+
println!(" logdebug");
250+
println!();
243251
println!(" foreground");
244252
println!(" background");
245253
println!();

src/lib.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use email_address::EmailAddress;
6262
use honey_badger::secrets::{generate_keypair, KeyPair};
6363
use honey_badger::{Auth, AuthLevel, CustomTermsAndConditions};
6464
use iban::Iban;
65-
use log::trace;
65+
use log::{info, trace};
6666
use logger::init_logger_once;
6767
use num_enum::TryFromPrimitive;
6868
use perro::Error::RuntimeError;
@@ -828,6 +828,31 @@ impl LightningNode {
828828
.store_payment_info(hash, user_preferences, exchange_rates, offer)
829829
.map_to_permanent_failure("Failed to persist payment info")
830830
}
831+
832+
pub fn log_debug_info(&self) -> Result<()> {
833+
let peers = self
834+
.rt
835+
.handle()
836+
.block_on(self.sdk.execute_dev_command("listpeers".to_string()))
837+
.map_to_runtime_error(
838+
RuntimeErrorCode::NodeUnavailable,
839+
"Couldn't execute `listpeers` command",
840+
)?;
841+
842+
let peer_channels = self
843+
.rt
844+
.handle()
845+
.block_on(self.sdk.execute_dev_command("listpeerchannels".to_string()))
846+
.map_to_runtime_error(
847+
RuntimeErrorCode::NodeUnavailable,
848+
"Couldn't execute `listpeerchannels` command",
849+
)?;
850+
851+
info!("List of peers:\n{}", peers);
852+
info!("List of peer channels:\n{}", peer_channels);
853+
854+
Ok(())
855+
}
831856
}
832857

833858
fn to_offer(topup_info: TopupInfo, current_rate: &Option<ExchangeRate>) -> OfferInfo {

src/lipalightninglib.udl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ interface LightningNode {
163163
// The payment hash must be in the hex representation.
164164
[Throws=LnError]
165165
string get_payment_uuid(string payment_hash);
166+
167+
// Prints additional debug information to the logs.
168+
//
169+
// Throws an error in case that the necessary information can't be received.
170+
[Throws=LnError]
171+
void log_debug_info();
166172
};
167173

168174
// An object that holds all configuration needed to start a LightningNode instance.

0 commit comments

Comments
 (0)