Separate main to src/bin/index_server.rs

This commit is contained in:
Roman Zeyde 2018-04-13 22:51:04 +03:00
parent a02502f46d
commit 9af0df224f
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
6 changed files with 40 additions and 40 deletions

View File

@ -1,35 +1,8 @@
extern crate bincode;
extern crate bitcoin;
extern crate crypto;
extern crate itertools;
extern crate pbr;
extern crate reqwest;
extern crate rocksdb;
extern crate serde;
extern crate simplelog;
extern crate time;
extern crate zmq;
#[macro_use]
extern crate arrayref;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
extern crate indexrs;
mod daemon;
mod index;
mod store;
mod timer;
mod waiter;
use bitcoin::blockdata::block::BlockHeader;
use bitcoin::util::hash::Sha256dHash;
use std::collections::HashMap;
use store::{Store, StoreOptions};
type Bytes = Vec<u8>;
type HeaderMap = HashMap<Sha256dHash, BlockHeader>;
use indexrs::{daemon, index, store, waiter};
fn setup_logging() {
use simplelog::*;
@ -45,14 +18,13 @@ fn setup_logging() {
]).unwrap();
}
fn main() {
setup_logging();
fn run_server() {
let waiter = waiter::Waiter::new("tcp://localhost:28332");
let daemon = daemon::Daemon::new("http://localhost:8332");
{
let mut store = Store::open(
let mut store = store::Store::open(
"db/mainnet",
StoreOptions {
store::StoreOptions {
auto_compact: false,
},
);
@ -60,7 +32,7 @@ fn main() {
store.compact_if_needed();
}
let mut store = Store::open("db/mainnet", StoreOptions { auto_compact: true });
let mut store = store::Store::open("db/mainnet", store::StoreOptions { auto_compact: true });
loop {
if store.read_header(&waiter.wait()).is_some() {
continue;
@ -68,3 +40,8 @@ fn main() {
index::update(&mut store, &daemon);
}
}
fn main() {
setup_logging();
run_server()
}

View File

@ -7,7 +7,7 @@ use reqwest;
use std::collections::VecDeque;
use std::io::Cursor;
use {Bytes, HeaderMap, Sha256dHash};
use types::{Bytes, HeaderMap, Sha256dHash};
const HEADER_SIZE: usize = 80;

View File

@ -12,8 +12,7 @@ use pbr;
use store::{Row, Store};
use time;
use timer::Timer;
use {Bytes, HeaderMap};
use types::{Bytes, HeaderMap};
const HASH_LEN: usize = 32;
const HASH_PREFIX_LEN: usize = 8;

25
src/lib.rs Normal file
View File

@ -0,0 +1,25 @@
extern crate bincode;
extern crate bitcoin;
extern crate crypto;
extern crate itertools;
extern crate pbr;
extern crate reqwest;
extern crate rocksdb;
extern crate serde;
extern crate time;
extern crate zmq;
#[macro_use]
extern crate arrayref;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
pub mod daemon;
pub mod index;
pub mod store;
pub mod waiter;
mod timer;
mod types;

View File

@ -3,8 +3,7 @@ use bitcoin::network::serialize::deserialize;
use rocksdb;
use time::{Duration, PreciseTime};
use Bytes;
use HeaderMap;
use types::{Bytes, HeaderMap};
pub struct Store {
db: rocksdb::DB,

View File

@ -1,6 +1,6 @@
use zmq;
use Bytes;
use types::Bytes;
pub struct Waiter {
sock: zmq::Socket,