Always index the blockchain
This commit is contained in:
parent
3a451a8dbd
commit
4404f120a1
|
@ -7,8 +7,7 @@ extern crate simplelog;
|
|||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use argparse::{ArgumentParser, StoreFalse, StoreTrue};
|
||||
use bitcoin::util::hash::Sha256dHash;
|
||||
use argparse::{ArgumentParser, StoreTrue};
|
||||
use indexrs::{daemon, index, query, rpc, store};
|
||||
use std::fs::OpenOptions;
|
||||
use std::thread;
|
||||
|
@ -17,7 +16,6 @@ use std::time::Duration;
|
|||
#[derive(Debug)]
|
||||
struct Config {
|
||||
log_file: String,
|
||||
enable_indexing: bool,
|
||||
testnet: bool,
|
||||
}
|
||||
|
||||
|
@ -25,17 +23,11 @@ impl Config {
|
|||
pub fn from_args() -> Config {
|
||||
let mut config = Config {
|
||||
log_file: "indexrs.log".to_string(),
|
||||
enable_indexing: true,
|
||||
testnet: false,
|
||||
};
|
||||
{
|
||||
let mut parser = ArgumentParser::new();
|
||||
parser.set_description("Bitcoin indexing server.");
|
||||
parser.refer(&mut config.enable_indexing).add_option(
|
||||
&["--disable-indexing"],
|
||||
StoreFalse,
|
||||
"Disable indexing server (allow queries on existing DB)",
|
||||
);
|
||||
parser.refer(&mut config.testnet).add_option(
|
||||
&["--testnet"],
|
||||
StoreTrue,
|
||||
|
@ -73,20 +65,17 @@ impl Config {
|
|||
fn run_server(config: &Config) {
|
||||
let index = index::Index::new();
|
||||
let daemon = daemon::Daemon::new(config.daemon_addr());
|
||||
let mut tip = Sha256dHash::default();
|
||||
{
|
||||
let store = store::Store::open(
|
||||
config.db_path(),
|
||||
store::StoreOptions {
|
||||
// compact manually after the first run has finished successfully
|
||||
auto_compact: false,
|
||||
},
|
||||
);
|
||||
if config.enable_indexing {
|
||||
tip = index.update(&store, &daemon);
|
||||
store.compact_if_needed();
|
||||
}
|
||||
}
|
||||
|
||||
let store = store::Store::open(
|
||||
config.db_path(),
|
||||
store::StoreOptions {
|
||||
// compact manually after the first run has finished successfully
|
||||
auto_compact: false,
|
||||
},
|
||||
);
|
||||
let mut tip = index.update(&store, &daemon);
|
||||
store.compact_if_needed();
|
||||
drop(store);
|
||||
|
||||
let store = store::Store::open(config.db_path(), store::StoreOptions { auto_compact: true });
|
||||
let query = query::Query::new(&store, &daemon, &index);
|
||||
|
@ -101,7 +90,7 @@ fn run_server(config: &Config) {
|
|||
let current_tip = daemon
|
||||
.getbestblockhash()
|
||||
.expect("failed to get latest blockhash");
|
||||
if tip == current_tip || !config.enable_indexing {
|
||||
if tip == current_tip {
|
||||
continue;
|
||||
}
|
||||
tip = index.update(&store, &daemon);
|
||||
|
|
Loading…
Reference in New Issue
Block a user