Unverified Commit 1ea6a503 authored by Dagur Valberg Johannsson's avatar Dagur Valberg Johannsson Committed by Roman Zeyde
Browse files

Let server banner be configurable

This lets the operator set a custom server banner using the
configuration flag --server-banner. In addition it adds the daemon
version to the banner.
parent 07eb413f
use bitcoin::util::hash::Sha256dHash;
use std::sync::{Arc, Mutex};
use crate::{daemon, errors::*, index, signal::Waiter, store};
use crate::{config::Config, daemon, errors::*, index, signal::Waiter, store};
pub struct App {
store: store::DBStore,
index: index::Index,
daemon: daemon::Daemon,
banner: String,
tip: Mutex<Sha256dHash>,
}
......@@ -15,11 +16,13 @@ impl App {
store: store::DBStore,
index: index::Index,
daemon: daemon::Daemon,
config: &Config,
) -> Result<Arc<App>> {
Ok(Arc::new(App {
store,
index,
daemon: daemon.reconnect()?,
banner: config.server_banner.clone(),
tip: Mutex::new(Sha256dHash::default()),
}))
}
......@@ -46,4 +49,12 @@ impl App {
}
Ok(new_block)
}
pub fn get_banner(&self) -> Result<String> {
Ok(format!(
"{}\n{}",
self.banner,
self.daemon.get_subversion()?
))
}
}
......@@ -54,7 +54,7 @@ fn run_server(config: &Config) -> Result<()> {
}
.enable_compaction(); // enable auto compactions before starting incremental index updates.
let app = App::new(store, index, daemon)?;
let app = App::new(store, index, daemon, &config)?;
let tx_cache = TransactionCache::new(config.tx_cache_size);
let query = Query::new(app.clone(), &metrics, tx_cache);
......
......@@ -26,6 +26,7 @@ pub struct Config {
pub index_batch_size: usize,
pub bulk_index_threads: usize,
pub tx_cache_size: usize,
pub server_banner: String,
}
impl Config {
......@@ -108,6 +109,12 @@ impl Config {
.help("Number of transactions to keep in for query LRU cache")
.default_value("10000") // should be enough for a small wallet.
)
.arg(
Arg::with_name("server_banner")
.long("server-banner")
.help("The banner to be shown in the Electrum console")
.default_value("Welcome to electrs (Electrum Rust Server)!")
)
.get_matches();
let network_name = m.value_of("network").unwrap_or("mainnet");
......@@ -192,6 +199,7 @@ impl Config {
index_batch_size: value_t_or_exit!(m, "index_batch_size", usize),
bulk_index_threads,
tx_cache_size: value_t_or_exit!(m, "tx_cache_size", usize),
server_banner: value_t_or_exit!(m, "server_banner", String),
};
eprintln!("{:?}", config);
config
......
......@@ -441,6 +441,10 @@ impl Daemon {
Ok(from_value(info).chain_err(|| "invalid network info")?)
}
pub fn get_subversion(&self) -> Result<String> {
Ok(self.getnetworkinfo()?.subversion)
}
pub fn getbestblockhash(&self) -> Result<Sha256dHash> {
parse_hash(&self.request("getbestblockhash", json!([]))?).chain_err(|| "invalid blockhash")
}
......
......@@ -486,4 +486,8 @@ impl Query {
}
last_fee_rate * 1e-5 // [BTC/kB] = 10^5 [sat/B]
}
pub fn get_banner(&self) -> Result<String> {
self.app.get_banner()
}
}
......@@ -106,7 +106,7 @@ impl Connection {
}
fn server_banner(&self) -> Result<Value> {
Ok(json!("Welcome to RustElectrum Server!\n"))
Ok(json!(self.query.get_banner()?))
}
fn server_donation_address(&self) -> Result<Value> {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment