Browse Source

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.
skip-invalid-blocks
Dagur Valberg Johannsson 6 years ago
committed by Roman Zeyde
parent
commit
1ea6a50325
No known key found for this signature in database GPG Key ID: 87CAE5FA46917CBB
  1. 13
      src/app.rs
  2. 2
      src/bin/electrs.rs
  3. 8
      src/config.rs
  4. 4
      src/daemon.rs
  5. 4
      src/query.rs
  6. 2
      src/rpc.rs

13
src/app.rs

@ -1,12 +1,13 @@
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()?
))
}
}

2
src/bin/electrs.rs

@ -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);

8
src/config.rs

@ -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

4
src/daemon.rs

@ -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")
}

4
src/query.rs

@ -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()
}
}

2
src/rpc.rs

@ -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> {

Loading…
Cancel
Save