Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from xn3cr0nx/feat/state-of-the-art
Browse files Browse the repository at this point in the history
Refactor project to the "state of the art"
  • Loading branch information
dr-orlovsky authored Nov 13, 2021
2 parents 429d627 + 9ec1595 commit 0d4089e
Show file tree
Hide file tree
Showing 37 changed files with 828 additions and 599 deletions.
40 changes: 29 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,48 @@ version = "0.1.0"
authors = ["Dr. Maxim Orlovsky <[email protected]>"]
keywords = ["bitcoin", "node"]
license = "MIT"
edition = "2018"
edition = "2021"
readme = "README.md"

[lib]
name = "bp_node"

[[bin]]
name = "queryd"
path = "src/bin/queryd.rs"

[[bin]]
name = "bp-cli"
path = "src/bin/bp-cli.rs"

[[bin]]
name = "bp-indexer"
path = "src/bin/bp-indexer.rs"

[dependencies]
dotenv = "~0.15"
clap = "=3.0.0-beta.1"
clap = "=3.0.0-beta.5"
chrono = "~0.4"
derive_wrapper = "~0.1"
async-trait = "~0.1"
log = { version = "~0.4", features = ["max_level_trace", "release_max_level_debug"] }
env_logger = "~0.7"
diesel = { version = "~1.4", features = ["postgres", "uuid", "numeric", "chrono"] }
tokio = { version = "~0.2", features = ["full"] }
futures = "~0.3"
zmq = "~0.9"
tiny_http = "~0.6"
prometheus = "~0.8"
amplify = "~3.9.1"
bp-core = "0.5.0-rc.1"
microservices = { version = "0.5.0-beta.1", default-features = false, features = ["peer"] }
internet2 = "0.5.0-alpha.2"
bitcoin = "0.27.1"
bitcoin_hashes = "0.10.0"
miniscript = "6.0.1"

[dependencies.lnpbp]
git = "https://github.com/lnp-bp/rust-lnpbp"
tag = "v0.1.0-alpha.3"
features = ["tor", "tokio", "log", "daemons", "serde"]
branch = "master"

# lnpbp requires custom version of bitcoin, so to maintain type compatibility
# we have to use library through lnpbp::bitcoin handle and not via direct
# dependency
#bitcoin = "~0.23"
[patch.crates-io]
# Remove this once https://github.com/jean-airoldie/zeromq-src-rs/pull/15 got merged
zeromq-src = { git = "https://github.com/LNP-BP/zeromq-src-rs", branch = "fix/cmake" }
bp-core = { git = "https://github.com/xn3cr0nx/bp-core", branch = "pub-short-id" }
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ different indexing servers (like Electrum) for efficient and extended
queries against bitcoin blockchain (see the drawing below).

The daemon is made with focus on:
* non-blocking/async IO and APIs
* ZMQ APIs for the clients
* efficient indexing with
[LNPBP-5 standard](https://github.com/LNP-BP/lnpbps/blob/master/lnpbp-0005.md)
Expand Down
49 changes: 30 additions & 19 deletions src/bin/bp-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,52 @@
// along with this software.
// If not, see <https://opensource.org/licenses/MIT>.

#![feature(never_type)]

use std::env;
#![recursion_limit = "256"]
// Coding conventions
#![deny(
non_upper_case_globals,
non_camel_case_types,
non_snake_case,
unused_mut,
unused_imports,
dead_code,
// missing_docs
)]

use clap::Parser;
use log::*;
use clap::derive::Clap;

use bp_node::cli::*;
use std::env;

use bp_node::cli::{Command, Config, Opts, Runtime};

#[tokio::main]
async fn main() -> Result<(), String> {
fn main() -> Result<(), String> {
// TODO: Parse config file as well
let opts: Opts = Opts::parse();
let config: Config = opts.clone().into();

if env::var("RUST_LOG").is_err() {
env::set_var("RUST_LOG", match config.verbose {
0 => "error",
1 => "warn",
2 => "info",
3 => "debug",
4 => "trace",
_ => "trace",
});
env::set_var(
"RUST_LOG",
match config.verbose {
0 => "error",
1 => "warn",
2 => "info",
3 => "debug",
4 => "trace",
_ => "trace",
},
);
}
env_logger::init();
log::set_max_level(LevelFilter::Trace);

let runtime = Runtime::init(config).await?;
let runtime = Runtime::init(config)?;

// Non-interactive command processing:
debug!("Parsing and processing a command");
match opts.command {
Command::Query { query } => runtime.command_query(query).await?,
_ => unimplemented!()
Command::Query { query } => runtime.command_query(query)?,
_ => unimplemented!(),
}

Ok(())
Expand Down
61 changes: 35 additions & 26 deletions src/bin/bp-indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,56 @@
// along with this software.
// If not, see <https://opensource.org/licenses/MIT>.

#![feature(never_type)]
#![recursion_limit = "256"]
// Coding conventions
#![deny(
non_upper_case_globals,
non_camel_case_types,
non_snake_case,
unused_mut,
unused_imports,
dead_code,
// missing_docs
)]


use std::env;
use bp_node::indexer::{Command, Config, Error, Opts, Runtime};
use clap::Parser;
use log::*;
use clap::derive::Clap;

use lnpbp::TryService;

use bp_node::indexer::*;

use microservices::node::TryService;
use std::env;

#[tokio::main]
async fn main() -> Result<(), Error> {
fn main() -> Result<(), Error> {
// TODO: Parse config file as well
let opts: Opts = Opts::parse();
let config: Config = opts.clone().into();

if env::var("RUST_LOG").is_err() {
env::set_var("RUST_LOG", match config.verbose {
0 => "error",
1 => "warn",
2 => "info",
3 => "debug",
4 => "trace",
_ => "trace",
});
env::set_var(
"RUST_LOG",
match config.verbose {
0 => "error",
1 => "warn",
2 => "info",
3 => "debug",
4 => "trace",
_ => "trace",
},
);
}
env_logger::init();
log::set_max_level(LevelFilter::Trace);

let mut runtime = Runtime::init(config)?;

match opts.command {
Command::ClearIndex => {
runtime.clear_db()
},
Command::ClearIndex => runtime.clear_db(),
Command::IndexBlockchain { clear, .. } => {
if clear.unwrap_or(false) { runtime.clear_db()?; }
runtime.run_or_panic("Indexer runtime").await
},
_ => unimplemented!()
if clear.unwrap_or(false) {
runtime.clear_db()?;
}
runtime.run_or_panic("Indexer runtime");
unreachable!()
}
_ => unimplemented!(),
}
}
52 changes: 33 additions & 19 deletions src/bin/queryd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,50 @@
// along with this software.
// If not, see <https://opensource.org/licenses/MIT>.

#![feature(never_type)]
#![recursion_limit = "256"]
// Coding conventions
#![deny(
non_upper_case_globals,
non_camel_case_types,
non_snake_case,
unused_mut,
unused_imports,
dead_code,
// missing_docs
)]

use std::env;
use clap::Parser;
use log::*;
use clap::derive::Clap;

use lnpbp::TryService;
use microservices::node::TryService;
use std::env;

use bp_node::BootstrapError;
use bp_node::queryd::*;
use bp_node::{
queryd::{Config, Opts, Runtime},
BootstrapError,
};

#[tokio::main]
async fn main() -> Result<(), BootstrapError> {
fn main() -> Result<(), BootstrapError> {
// TODO: Parse config file as well
let opts: Opts = Opts::parse();
let config: Config = opts.into();

if env::var("RUST_LOG").is_err() {
env::set_var("RUST_LOG", match config.verbose {
0 => "error",
1 => "warn",
2 => "info",
3 => "debug",
4 => "trace",
_ => "trace",
});
env::set_var(
"RUST_LOG",
match config.verbose {
0 => "error",
1 => "warn",
2 => "info",
3 => "debug",
4 => "trace",
_ => "trace",
},
);
}
env_logger::init();
log::set_max_level(LevelFilter::Trace);

let runtime = Runtime::init(config).await?;
runtime.run_or_panic("Queryd runtime").await
let runtime = Runtime::init(config)?;
runtime.run_or_panic("Queryd runtime");
unreachable!()
}
39 changes: 24 additions & 15 deletions src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,61 @@
// along with this software.
// If not, see <https://opensource.org/licenses/MIT>.


use clap::Clap;
use clap::Parser;

use crate::msgbus::constants::*;


#[derive(Clap, Clone, Debug, Display)]
#[derive(Parser, Clone, Debug, Display)]
#[display_from(Debug)]
#[clap(
name = "bp-cli",
version = "0.0.1",
author = "Dr Maxim Orlovsky <[email protected]>",
about = "BP node command-line interface; part of Bitcoin protocol node"
about = "BP node command-line interface; part of Bitcoin protocol node"
)]
pub struct Opts {
/// Path and name of the configuration file
#[clap(global = true, short = "c", long = "config", default_value = "./cli.toml")]
#[clap(
global = true,
short = 'c',
long = "config",
default_value = "./cli.toml"
)]
pub config: String,

/// Sets verbosity level; can be used multiple times to increase verbosity
#[clap(global = true, short = "v", long = "verbose", min_values = 0, max_values = 4, parse(from_occurrences))]
#[clap(
global = true,
short = 'v',
long = "verbose",
min_values = 0,
max_values = 4,
parse(from_occurrences)
)]
pub verbose: u8,

/// IPC connection string for queryd daemon API
#[clap(global = true, short = "w", long = "queryd-api", default_value = MSGBUS_PEER_API_ADDR, env="BP_CLI_QUERYD_API_ADDR")]
#[clap(global = true, short = 'w', long = "queryd-api", default_value = MSGBUS_PEER_API_ADDR, env="BP_CLI_QUERYD_API_ADDR")]
pub queryd_api_socket_str: String,

/// IPC connection string for queryd daemon push notifications on perr status updates
#[clap(global = true, short = "W", long = "queryd-push", default_value = MSGBUS_PEER_PUSH_ADDR, env="BP_CLI_QUERYD_PUSH_ADDR")]
#[clap(global = true, short = 'W', long = "queryd-push", default_value = MSGBUS_PEER_PUSH_ADDR, env="BP_CLI_QUERYD_PUSH_ADDR")]
pub queryd_push_socket_str: String,

#[clap(subcommand)]
pub command: Command
pub command: Command,
}

#[derive(Clap, Clone, Debug, Display)]
#[derive(Parser, Clone, Debug, Display)]
#[display_from(Debug)]
pub enum Command {
/// Sends command to a wired daemon to connect to the new peer
Query {
/// Query to run against Bitcoin blockchain & transaction index
query: String
query: String,
},
}


// We need config structure since not all of the parameters can be specified
// via environment and command-line arguments. Thus we need a config file and
// default set of configuration
Expand Down Expand Up @@ -85,7 +94,7 @@ impl Default for Config {
Self {
verbose: 0,
msgbus_peer_api_addr: MSGBUS_PEER_API_ADDR.to_string(),
msgbus_peer_sub_addr: MSGBUS_PEER_PUSH_ADDR.to_string()
msgbus_peer_sub_addr: MSGBUS_PEER_PUSH_ADDR.to_string(),
}
}
}
}
Loading

0 comments on commit 0d4089e

Please sign in to comment.