Skip to content

Commit

Permalink
Expose log_debug_info method
Browse files Browse the repository at this point in the history
  • Loading branch information
dleutenegger committed Oct 5, 2023
1 parent fb72171 commit f561efb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
8 changes: 8 additions & 0 deletions examples/3l-node/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ pub(crate) fn poll_for_user_input(node: &LightningNode, log_file_path: &str) {
Err(e) => println!("{}", e.red()),
}
}
"logdebug" => {
if let Err(e) = node.log_debug_info() {
println!("{}", e.to_string().red());
}
}
"foreground" => {
node.foreground();
}
Expand Down Expand Up @@ -226,6 +231,7 @@ fn setup_editor(history_path: &Path) -> Editor<CommandHinter, DefaultHistory> {
"paymentuuid",
));
hints.insert(CommandHint::new("sweep <address>", "sweep"));
hints.insert(CommandHint::new("logdebug", "logdebug"));
hints.insert(CommandHint::new("foreground", "foreground"));
hints.insert(CommandHint::new("background", "background"));
hints.insert(CommandHint::new("stop", "stop"));
Expand Down Expand Up @@ -263,6 +269,8 @@ fn help() {
println!();
println!(" sweep <address>");
println!();
println!(" logdebug");
println!();
println!(" foreground");
println!(" background");
println!();
Expand Down
27 changes: 26 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use email_address::EmailAddress;
use honey_badger::secrets::{generate_keypair, KeyPair};
use honey_badger::{Auth, AuthLevel, CustomTermsAndConditions};
use iban::Iban;
use log::trace;
use log::{info, trace};
use logger::init_logger_once;
use num_enum::TryFromPrimitive;
use perro::Error::RuntimeError;
Expand Down Expand Up @@ -854,6 +854,31 @@ impl LightningNode {
.txid
.to_hex())
}

pub fn log_debug_info(&self) -> Result<()> {
let peers = self
.rt
.handle()
.block_on(self.sdk.execute_dev_command("listpeers".to_string()))
.map_to_runtime_error(
RuntimeErrorCode::NodeUnavailable,
"Couldn't execute `listpeers` command",
)?;

let peer_channels = self
.rt
.handle()
.block_on(self.sdk.execute_dev_command("listpeerchannels".to_string()))
.map_to_runtime_error(
RuntimeErrorCode::NodeUnavailable,
"Couldn't execute `listpeerchannels` command",
)?;

info!("List of peers:\n{}", peers);
info!("List of peer channels:\n{}", peer_channels);

Ok(())
}
}

fn to_offer(topup_info: TopupInfo, current_rate: &Option<ExchangeRate>) -> OfferInfo {
Expand Down
6 changes: 6 additions & 0 deletions src/lipalightninglib.udl
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ interface LightningNode {
// Returns the txid of the sweeping transaction.
[Throws=LnError]
string sweep(string address, u32 onchain_fee);

// Prints additional debug information to the logs.
//
// Throws an error in case that the necessary information can't be received.
[Throws=LnError]
void log_debug_info();
};

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

0 comments on commit f561efb

Please sign in to comment.