Skip to content

Commit

Permalink
Merge pull request #41 from idky137/add_conf_toml
Browse files Browse the repository at this point in the history
Expose conf
  • Loading branch information
idky137 authored Sep 4, 2024
2 parents 7ac06f7 + 62f3030 commit a4357a4
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ The walletside Nym implementations are moving to ease wallet integration but the
From zingolib: [get_lightd_info and send_transaction commands sent with this build will be sent over the mixnet]
6) Run `$ cargo run --release --package zingo-cli -- --chain "testnet" --server "127.0.0.1:8088" --data-dir ~/wallets/testnet_wallet`

Note:
Configuration data can be set using a .toml file (an example zindexer.toml is given in zingo-indexer/zindexer.toml) and can be set at runtime using the --config arg:
- Run `$ cargo run --config zingo-indexerd/zindexer.toml`
3 changes: 3 additions & 0 deletions zingo-indexerd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ thiserror = { workspace = true }
# Miscellaneous Crate
tower = { version = "0.4.13" }
hyper = { version = "0.14.28", features = ["full"] } # { version = "1.4.1", features = ["full"] }
serde = { version = "1.0.201", features = ["derive"] } # { version = "1.0.204", features = ["derive"] }
ctrlc = "3.2.1" # "3.4.4"
toml = "0.5"
clap = { version = "4.0", features = ["derive"] }
20 changes: 18 additions & 2 deletions zingo-indexerd/src/bin/zingoindexerd.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
//! Zingo-Indexer daemon

use zingoindexerlib::{config::IndexerConfig, indexer::Indexer};
use clap::Parser;
use std::path::PathBuf;
use zingoindexerlib::{config::load_config, indexer::Indexer};

#[derive(Parser, Debug)]
#[command(name = "zindexer", about = "A server for Zingo-Indexer")]
struct Args {
/// Path to the configuration file
#[arg(short, long, value_name = "FILE")]
config: Option<PathBuf>,
}

#[tokio::main]
async fn main() {
Indexer::start(IndexerConfig::default()).await.unwrap();
Indexer::start(load_config(
&Args::parse()
.config
.unwrap_or_else(|| PathBuf::from("./zingo-indexerd/zindexer.toml")),
))
.await
.unwrap();
}
30 changes: 27 additions & 3 deletions zingo-indexerd/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! Zingo-Indexer config.

use std::path::Path;

use crate::error::IndexerError;
use std::path::Path;

/// Config information required for Zingo-Indexer.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Deserialize)]
pub struct IndexerConfig {
/// Sets the TcpIngestor's status.
pub tcp_active: bool,
Expand Down Expand Up @@ -103,3 +102,28 @@ impl Default for IndexerConfig {
}
}
}

/// Attempts to load config data from a toml file at the specified path.
pub fn load_config(file_path: &std::path::PathBuf) -> IndexerConfig {
let mut config = IndexerConfig::default();

if let Ok(contents) = std::fs::read_to_string(file_path) {
if let Ok(parsed_config) = toml::from_str::<IndexerConfig>(&contents) {
config = IndexerConfig {
tcp_active: parsed_config.tcp_active,
listen_port: parsed_config.listen_port.or(config.listen_port),
nym_active: parsed_config.nym_active,
nym_conf_path: parsed_config.nym_conf_path.or(config.nym_conf_path),
lightwalletd_port: parsed_config.lightwalletd_port,
zebrad_port: parsed_config.zebrad_port,
node_user: parsed_config.node_user.or(config.node_user),
node_password: parsed_config.node_password.or(config.node_password),
max_queue_size: parsed_config.max_queue_size,
max_worker_pool_size: parsed_config.max_worker_pool_size,
idle_worker_pool_size: parsed_config.idle_worker_pool_size,
};
}
}

config
}
34 changes: 34 additions & 0 deletions zingo-indexerd/zindexer.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Configuration for Zingo-Indexer

# Sets the TcpIngestor's status (true or false)
tcp_active = true

# Optional TcpIngestors listen port (use None or specify a port number)
listen_port = 8137

# Sets the NymIngestor's and NymDispatchers status (true or false)
nym_active = true

# Optional Nym conf path used for micnet client conf
nym_conf_path = "/tmp/indexer/nym"

# LightWalletD listen port [DEPRECATED]
lightwalletd_port = 9067

# Full node / validator listen port
zebrad_port = 18232

# Optional full node Username
node_user = "xxxxxx"

# Optional full node Password
node_password = "xxxxxx"

# Maximum requests allowed in the request queue
max_queue_size = 1024

# Maximum workers allowed in the worker pool
max_worker_pool_size = 64

# Minimum number of workers held in the worker pool when idle
idle_worker_pool_size = 4

0 comments on commit a4357a4

Please sign in to comment.