Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/79 | Add logger #84

Merged
merged 6 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 96 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ serde_derive = "1.0.126"
ln-types = { version = "0.1.3", features = ["serde", "parse_arg"] }
configure_me = "0.4.0"
qrcode-generator = "4.1.6"
log = "0.4.17"
env_logger = "0.9.3"

[build-dependencies]
configure_me_codegen = "0.4.3"
Expand Down
5 changes: 3 additions & 2 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::path::Path;
use bip78::receiver::*;
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Method, Request, Response, Server, StatusCode};
use log::info;
use qrcode_generator::QrCodeEcc;

use crate::lsp::Quote;
Expand Down Expand Up @@ -33,7 +34,7 @@ pub async fn serve(sched: Scheduler, bind_addr: SocketAddr) -> Result<(), hyper:
});

let server = Server::bind(&bind_addr).serve(new_service);
println!("Listening on: http://{}", bind_addr);
info!("Listening on: http://{}", bind_addr);
server.await
}

Expand Down Expand Up @@ -81,7 +82,7 @@ async fn serve_public_file(path: &str) -> Result<Response<Body>, HttpError> {
}

async fn handle_pj(scheduler: Scheduler, req: Request<Body>) -> Result<Response<Body>, HttpError> {
dbg!(req.uri().query());
info!("{:?}", req.uri().query());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: If display isn't implemented, this is probably debug, not info


let headers = Headers(req.headers().to_owned());
let query = {
Expand Down
7 changes: 3 additions & 4 deletions src/lnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use bitcoin::consensus::Decodable;
use bitcoin::psbt::PartiallySignedTransaction;
use bitcoin::{Address, Amount};
use ln_types::P2PAddress;
use log::{info, warn};
use tokio::sync::Mutex as AsyncMutex;
use tonic_lnd::lnrpc::funding_transition_msg::Trigger;
use tonic_lnd::lnrpc::{
Expand Down Expand Up @@ -46,9 +47,7 @@ impl LndClient {
if version < (0, 14, 0) {
return Err(LndError::LNDTooOld(version_str.clone()));
} else if version < (0, 14, 2) {
eprintln!(
"WARNING: LND older than 0.14.2. Using with an empty LND wallet is impossible."
);
warn!("WARNING: LND older than 0.14.2. Using with an empty LND wallet is impossible.");
}

Ok(Self(Arc::new(AsyncMutex::new(client))))
Expand Down Expand Up @@ -128,7 +127,7 @@ impl LndClient {
Update::PsbtFund(ready) => {
let psbt = PartiallySignedTransaction::consensus_decode(&mut &*ready.psbt)
.map_err(LndError::Decode)?;
eprintln!(
info!(
"PSBT received from LND for pending chan id {:?}: {:#?}",
pending_chan_id, psbt
);
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod lnd;
mod lsp;
pub mod scheduler;

use log::info;
use scheduler::Scheduler;

use crate::args::parse_args;
Expand All @@ -16,6 +17,8 @@ configure_me::include_config!();

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init_from_env(
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"));
let (config, args) =
Config::including_optional_config_files(std::iter::empty::<&str>()).unwrap_or_exit();

Expand All @@ -25,7 +28,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

if let Some(batch) = channel_batch {
let (bip21, _, _) = scheduler.schedule_payjoin(batch).await?;
println!("{}", bip21);
info!("{}", bip21);
}

let bind_addr = (config.bind_ip, config.bind_port).into();
Expand Down
9 changes: 5 additions & 4 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use bitcoin::consensus::Encodable;
use bitcoin::psbt::PartiallySignedTransaction;
use bitcoin::{Address, Amount, Script, TxOut};
use ln_types::P2PAddress;
use log::{error, info};
use tonic_lnd::lnrpc::OpenChannelRequest;
use url::Url;

Expand Down Expand Up @@ -163,7 +164,7 @@ impl ScheduledPayJoin {
for (chan_id, handle) in handles {
match handle.await.unwrap()? {
Some(vout) => funding_txos.push((chan_id, vout)),
None => eprintln!("failed to receive funding psbt after channel open request. !this case is not handled!"),
None => error!("failed to receive funding psbt after channel open request. !this case is not handled!"),
};
}

Expand Down Expand Up @@ -247,7 +248,7 @@ impl ScheduledPayJoin {
// psbt should have outputs same length as contained unsigned tx
proposal_psbt.outputs.resize_with(proposal_psbt.unsigned_tx.output.len(), Default::default);

eprintln!("channel funding Proposal PSBT created: {:#?}", proposal_psbt);
info!("channel funding Proposal PSBT created: {:#?}", proposal_psbt);

proposal_psbt
}
Expand Down Expand Up @@ -341,7 +342,7 @@ impl Scheduler {
.assume_no_inputs_seen_before(); // TODO

let mut original_psbt = request.psbt().clone();
eprintln!("Received psbt: {:#?}", original_psbt);
info!("Received psbt: {:#?}", original_psbt);

// prepare proposal psbt (psbt, owned_vout, ScheduledPayJoin)
let (owned_vout, pj) =
Expand Down Expand Up @@ -392,7 +393,7 @@ impl Scheduler {
let proposal_psbt =
PartiallySignedTransaction::from_unsigned_tx(proposal_psbt.unsigned_tx.clone())
.expect("resetting tx failed");
eprintln!("Proposal PSBT that will be returned: {:#?}", proposal_psbt);
info!("Proposal PSBT that will be returned: {:#?}", proposal_psbt);

let mut psbt_bytes = Vec::new();
proposal_psbt.consensus_encode(&mut psbt_bytes)?;
Expand Down
Loading