1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 18:10:51 +01:00

Allow specifying DB directory

This commit is contained in:
Roman Zeyde 2018-06-11 12:26:35 +03:00
parent c0a4f7a520
commit f8a577b396
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
2 changed files with 12 additions and 6 deletions

View File

@ -19,7 +19,7 @@ fn run_server(config: &Config) -> Result<()> {
let signal = Waiter::new(Duration::from_secs(5));
let store = DBStore::open(
config.db_path,
&config.db_path,
StoreOptions {
// compact manually after the first run has finished successfully
auto_compact: false,
@ -30,7 +30,7 @@ fn run_server(config: &Config) -> Result<()> {
store.compact_if_needed();
drop(store); // to be re-opened soon
let store = DBStore::open(config.db_path, StoreOptions { auto_compact: true });
let store = DBStore::open(&config.db_path, StoreOptions { auto_compact: true });
let app = App::new(store, index, daemon);
let query = Query::new(app.clone());

View File

@ -10,7 +10,7 @@ pub struct Config {
pub log_level: simplelog::LevelFilter,
pub restart: bool,
pub network_type: Network, // bitcoind JSONRPC endpoint
pub db_path: &'static str, // RocksDB directory path
pub db_path: String, // RocksDB directory path
pub rpc_addr: SocketAddr, // for serving Electrum clients
}
@ -19,7 +19,8 @@ impl Config {
let mut testnet = false;
let mut verbose = false;
let mut restart = false;
let mut log_file = "".to_string();
let mut log_file = "".to_owned();
let mut db_dir = "./db".to_owned();
{
let mut parser = ArgumentParser::new();
parser.set_description("Bitcoin indexing server.");
@ -43,6 +44,11 @@ impl Config {
Store,
"Write the log into specified file",
);
parser.refer(&mut db_dir).add_option(
&["-d", "--db-dir"],
Store,
"Directory to store index database",
);
parser.parse_args_or_exit();
}
let network_type = match testnet {
@ -59,8 +65,8 @@ impl Config {
restart,
network_type,
db_path: match network_type {
Network::Mainnet => "./db/mainnet",
Network::Testnet => "./db/testnet",
Network::Mainnet => format!("{}/mainnet", db_dir),
Network::Testnet => format!("{}/testnet", db_dir),
},
rpc_addr: match network_type {
Network::Mainnet => "127.0.0.1:50001",