Skip to content

Commit

Permalink
Implement Electrum RPC on top of new indexes and query
Browse files Browse the repository at this point in the history
  • Loading branch information
shesek committed Feb 23, 2019
1 parent 2210d7a commit 823b68e
Show file tree
Hide file tree
Showing 8 changed files with 795 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/bin/electrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::time::Duration;
use electrs::{
config::Config,
daemon::Daemon,
electrum::RPC as ElectrumRPC,
errors::*,
metrics::Metrics,
new_index::{precache, ChainQuery, FetchFrom, Indexer, Mempool, Query, Store},
Expand Down Expand Up @@ -80,20 +81,30 @@ fn run_server(config: Arc<Config>) -> Result<()> {
Arc::clone(&daemon),
));

let server = rest::run_server(config, query);
// TODO: configuration for which servers to start
let rest_server = rest::run_server(Arc::clone(&config), Arc::clone(&query));
let electrum_server =
ElectrumRPC::start(config.electrum_rpc_addr, Arc::clone(&query), &metrics);

loop {
if let Err(err) = signal.wait(Duration::from_secs(5)) {
info!("stopping server: {}", err);
server.stop();
rest_server.stop();
break;
}

// Index new blocks
let current_tip = daemon.getbestblockhash()?;
if current_tip != tip {
indexer.update(&daemon)?;
tip = current_tip;
};

// Update mempool
mempool.write().unwrap().update(&daemon)?;

// Update subscribed clients
electrum_server.notify();
}
info!("server stopped");
Ok(())
Expand Down
Loading

0 comments on commit 823b68e

Please sign in to comment.