Skip to content

Commit

Permalink
fixed lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Hergy Fongue committed Nov 25, 2023
1 parent 20653ba commit c7261ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
25 changes: 14 additions & 11 deletions src/lnd/client.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::{settings, utils};
use hex;
use std::collections::HashMap;
use std::error::Error;
use std::fs;
use config::Config;
use lnd_grpc_rust::{invoicesrpc, LndClient, lnrpc, routerrpc};

use hex;
use lnd_grpc_rust::{lnrpc, LndClient};
use tokio::sync::{Mutex, MutexGuard};
use crate::schema::scripts::address;

use crate::{settings, utils};

#[derive(Clone)]
pub struct LNDConfig {
Expand All @@ -27,16 +26,18 @@ pub fn get_lnd_config(cfg: &settings::Config) -> Result<LNDConfig, LNDGatewayErr

// extract all files necessaty to connect to lnd
let host = "localhost:8081".to_string();
let cert_bytes = fs::read("/Users/rjtch/.polar/networks/1/volumes/lnd/alice/tls.cert").expect("FailedToReadTlsCertFile");
let mac_bytes = fs::read("/Users/rjtch/.polar/networks/1/volumes/lnd/alice/data/chain/bitcoin/regtest/admin.macaroon").expect("FailedToReadMacaroonFile");
let cert_bytes = fs::read("/Users/rjtch/.polar/networks/1/volumes/lnd/alice/tls.cert")
.expect("FailedToReadTlsCertFile");
let mac_bytes = fs::read("/Users/rjtch/.polar/networks/1/volumes/lnd/alice/data/chain/bitcoin/regtest/admin.macaroon")
.expect("FailedToReadMacaroonFile");

// Convert the bytes to a hex string
let cert = buffer_as_hex(cert_bytes);
let macaroon = buffer_as_hex(mac_bytes);

Ok(LNDConfig {
cert_path: cert,
macaroon_path:macaroon,
macaroon_path: macaroon,
address: host,
invoice_lifetime: invoice_lifetime as i64,
})
Expand Down Expand Up @@ -86,7 +87,7 @@ impl LNDGateway {
self.client.lock().await
}

/* pub async fn get_info(&self) -> Result<lnrpc::, lnd_grpc_rust::LndClientError> {
/* pub async fn get_info(&self) -> Result<lnrpc::, lnd_grpc_rust::LndClientError> {
let mut client = self.get_client().await;
let resp = client.lightning().get_info(lnrpc::GetInfoRequest {}).await;
match resp {
Expand Down Expand Up @@ -286,8 +287,10 @@ impl LNDGateway {
}

pub fn buffer_as_hex(bytes: Vec<u8>) -> String {
let hex_str = bytes.iter().map(|b| format!("{:02x}", b)).collect::<String>();

let hex_str = bytes
.iter()
.map(|b| format!("{:02x}", b))
.collect::<String>();
return hex_str;
}

Expand Down
30 changes: 14 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,27 @@ async fn main() {
}

async fn run() {

let cfg = settings::build_config().unwrap();
let db = DB::new(&cfg);
let migration_conn = &mut db.get_conn().unwrap();
db::run_migrations(migration_conn).unwrap();

match wallet::LooperWallet::new(&cfg) {
Ok(wallet) => {
match LNDGateway::new().await {
Ok(lndg) => {
let loopout_svc = services::loop_out::LoopOutService::new(&cfg, db, wallet, lndg).unwrap();
let server = api::server::LooperServer::new(loopout_svc);
server.start();
let stdin = io::stdin();
let _line = stdin.lock().lines().next().unwrap().unwrap();
},
Err(err)=> {
panic!("could not start the lndGateway {} ", err.msg);
}
Ok(wallet) => match LNDGateway::new().await {
Ok(lndg) => {
let loopout_svc =
services::loop_out::LoopOutService::new(&cfg, db, wallet, lndg).unwrap();
let server = api::server::LooperServer::new(loopout_svc);
server.start();
let stdin = io::stdin();
let _line = stdin.lock().lines().next().unwrap().unwrap();
}
Err(err) => {
panic!("could not start the lndGateway {} ", err.msg);
}
},
Err(err)=> {
panic!("could not create the wallet {} ", err.message);
}
Err(err) => {
panic!("could not create the wallet {} ", err.message);
}
}
}

0 comments on commit c7261ac

Please sign in to comment.