Skip to content

Commit

Permalink
Node information cli requests
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Nov 1, 2020
1 parent 62fe24f commit 567c435
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 73 deletions.
58 changes: 50 additions & 8 deletions Cargo.lock

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

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ name = "lnp-cli"
required-features = ["cli"]

[dependencies]
# Rust language
# LNP/BP crates
amplify = "~2.2.1"
amplify_derive = "~2.2.1"
amplify_derive = "~2.2.2"
lnpbp = { git = "git://github.com/LNP-BP/rust-lnpbp", features = ["lnp", "url", "websockets"] }
lnpbp_derive = { git = "git://github.com/LNP-BP/rust-lnpbp" }
lnpbp_services = { git = "git://github.com/LNP-BP/rust-lnpbp" }
lazy_static = "~1.4.0"
# Rust language
nix = { version = "~0.19.0", optional = true }
chrono = "~0.4.19"
# Bitcoin
electrum-client = { version = "=0.3.0-beta.1", optional = true }
# Serialization & parsing
Expand Down Expand Up @@ -70,7 +72,7 @@ zmq = { version = "~0.9.2", optional = true }

[build-dependencies]
amplify = "~2.2.1"
amplify_derive = "~2.2.1"
amplify_derive = "~2.2.2"
lnpbp = { git = "git://github.com/LNP-BP/rust-lnpbp", features = ["lnp", "url", "websockets"] }
lnpbp_services = { git = "git://github.com/LNP-BP/rust-lnpbp" }
clap = "=3.0.0-beta.2"
Expand Down Expand Up @@ -117,8 +119,8 @@ shell = [
# This feature results in building with features not required for CLI
node = ["serde", "lnpbp/keygen", "tokio", "lnpbp/tokio", "zmq", "lnpbp_services/node",
"url", "lnpbp/url"]
serde = ["serde_crate", "serde_with", "toml", "amplify/serde", "lnpbp/serde",
"lnpbp_services/serde"]
serde = ["serde_crate", "serde_with", "serde_yaml", "toml",
"amplify/serde", "lnpbp/serde", "lnpbp_services/serde"]

[package.metadata.configure_me]
spec = "config_spec.toml"
4 changes: 2 additions & 2 deletions src/bin/lnp-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern crate log;
use clap::Clap;

use lnp_node::cli::{Opts, Runtime};
use lnp_node::Config;
use lnp_node::{Config, LogStyle};
use lnpbp_services::shell::Exec;

fn main() {
Expand All @@ -42,5 +42,5 @@ fn main() {
trace!("Executing command: {:?}", opts.command);
opts.command
.exec(&mut runtime)
.unwrap_or_else(|err| error!("{}", err));
.unwrap_or_else(|err| eprintln!("{}", err.err()));
}
8 changes: 4 additions & 4 deletions src/channeld/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Runtime {
) -> Result<(), Error> {
let mut notify_cli = None;
match request {
Request::LnpwpMessage(Messages::AcceptChannel(accept_channel)) => {
Request::SendMessage(Messages::AcceptChannel(accept_channel)) => {
info!(
"{} from the remote peer {} with temporary id {}",
"Accepting channel".promo(),
Expand All @@ -86,7 +86,7 @@ impl Runtime {
)));
}

Request::LnpwpMessage(_) => {
Request::SendMessage(_) => {
// Ignore the rest of LN peer messages
}

Expand Down Expand Up @@ -131,7 +131,7 @@ impl Runtime {
ServiceBus::Msg,
self.identity(),
peerd,
Request::LnpwpMessage(Messages::OpenChannel(channel_req)),
Request::SendMessage(Messages::OpenChannel(channel_req)),
)?;
notify_cli = Some((report_to, msg))
}
Expand Down Expand Up @@ -168,7 +168,7 @@ impl Runtime {
ServiceBus::Msg,
self.identity(),
peerd,
Request::LnpwpMessage(Messages::AcceptChannel(
Request::SendMessage(Messages::AcceptChannel(
accept_channel,
)),
)?;
Expand Down
15 changes: 15 additions & 0 deletions src/cli/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ impl Exec for Command {
fn exec(&self, runtime: &mut Self::Runtime) -> Result<(), Self::Error> {
debug!("Performing {:?}: {}", self, self);
match self {
Command::Info => {
runtime.request(ServiceId::Lnpd, Request::GetInfo)?;
runtime.report_response()?;
}

Command::Peers => {
runtime.request(ServiceId::Lnpd, Request::ListPeers)?;
runtime.report_response()?;
}

Command::Channels => {
runtime.request(ServiceId::Lnpd, Request::ListChannels)?;
runtime.report_response()?;
}

Command::Listen {
ip_addr,
port,
Expand Down
17 changes: 17 additions & 0 deletions src/cli/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ impl Runtime {
Ok(())
}

pub fn report_response(&mut self) -> Result<(), Error> {
for (_, _, rep) in self.esb.recv_poll()? {
match rep {
Request::Failure(fail) => {
eprintln!(
"{}: {}",
"Request failure".err(),
fail.err_details()
);
Err(Error::from(fail))?
}
resp => println!("{:#}", resp),
}
}
Ok(())
}

pub fn report_progress(&mut self) -> Result<usize, Error> {
let mut counter = 0;
let mut finished = false;
Expand Down
2 changes: 1 addition & 1 deletion src/gossipd/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Runtime {
request: Request,
) -> Result<(), Error> {
match request {
Request::LnpwpMessage(_message) => {
Request::SendMessage(_message) => {
// TODO: Process message
}
_ => {
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ extern crate amplify_derive;
#[macro_use]
extern crate lnpbp_derive;

#[cfg(feature = "serde")]
#[macro_use]
extern crate serde_crate as serde;

#[cfg(feature = "shell")]
extern crate clap;
#[cfg(feature = "shell")]
Expand Down
Loading

0 comments on commit 567c435

Please sign in to comment.