diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ce74f8..e39cf25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,8 @@ - HTTP API: Fix `GET /block/tip` (#46) +- HTTP API: Add `GET /banner.txt` (#44) + - Tests: Upgrade to Electrum v4 ## 0.1.4 - 2020-06-22 diff --git a/README.md b/README.md index 576c381..5adfb3b 100644 --- a/README.md +++ b/README.md @@ -1143,6 +1143,11 @@ Dumps the contents of the index store as JSON. Dumps the contents of the index store as a debug string. +#### `GET /banner.txt` + +Get the welcome banner text. +([example](https://gist.githubusercontent.com/shesek/4986c4291df1a7c6de62c20bc72e58bf/raw/42539cd10f1836ae511f4c2ec7b4fc82ad52252a/bwt-welcome-banner.txt)) + ## Web Hooks > If you're building bwt from source, you'll need to set `--features webhooks` to enable web hooks support. This will also require to `apt install libssl-dev pkg-config`. diff --git a/src/app.rs b/src/app.rs index a4ad1b6..d822039 100644 --- a/src/app.rs +++ b/src/app.rs @@ -59,7 +59,7 @@ impl App { wait_bitcoind(&rpc)?; if config.startup_banner { - println!("{}", banner::get_welcome_banner(&query)?); + println!("{}", banner::get_welcome_banner(&query, false)?); } // do an initial sync without keeping track of updates diff --git a/src/banner.rs b/src/banner.rs index 1674fe6..b31f760 100644 --- a/src/banner.rs +++ b/src/banner.rs @@ -13,7 +13,7 @@ const TARGET_BLOCK_SPACING: u64 = constants::TARGET_BLOCK_SPACING as u64; const INITIAL_REWARD: u64 = 50 * constants::COIN_VALUE; const HALVING_INTERVAL: u64 = 210_000; -pub fn get_welcome_banner(query: &Query) -> Result { +pub fn get_welcome_banner(query: &Query, omit_donation: bool) -> Result { let rpc = query.rpc(); let net_info = rpc.get_network_info_()?; @@ -116,8 +116,8 @@ pub fn get_welcome_banner(query: &Query) -> Result { MEMPOOL: 💭 {mempool_size} / {mempool_n_tx} / ᴍɪɴ {mempool_min_fee} sᴀᴛ/ᴠʙ FEES EST: 🏷️ 20 ᴍɪɴᴜᴛᴇs: {est_20m} / 3 ʜᴏᴜʀs: {est_3h} / 1 ᴅᴀʏ: {est_1d} (sᴀᴛ/ᴠʙ) - SUPPORT DEV: 🚀 bc1qmuagsjvq0lh3admnafk0qnlql0vvxv08au9l2d / https://btcpay.shesek.info -"#, +{donation_frag}"#, + modes = modes.join(" "), client_name = to_widetext(&net_info.subversion), chain_name = to_smallcaps(&chain_name), connected_peers = net_info.connections, @@ -144,10 +144,14 @@ pub fn get_welcome_banner(query: &Query) -> Result { est_20m = est_20m, est_3h = est_3h, est_1d = est_1d, - modes = modes.join(" "), ver_line1 = ver_lines.0, ver_line2 = ver_lines.1, ver_line3 = ver_lines.2, + donation_frag = if !omit_donation { + " SUPPORT DEV: 🚀 bc1qmuagsjvq0lh3admnafk0qnlql0vvxv08au9l2d / https://btcpay.shesek.info\n" + } else { + "" + }, )) } diff --git a/src/electrum/server.rs b/src/electrum/server.rs index 2066ecc..fdaf29a 100644 --- a/src/electrum/server.rs +++ b/src/electrum/server.rs @@ -74,7 +74,7 @@ impl Connection { } fn server_banner(&self) -> Result { - Ok(json!(get_welcome_banner(&self.query)?)) + Ok(json!(get_welcome_banner(&self.query, false)?)) } fn server_donation_address(&self) -> Result { diff --git a/src/http.rs b/src/http.rs index 1a8d7bc..52508b5 100644 --- a/src/http.rs +++ b/src/http.rs @@ -14,7 +14,7 @@ use bitcoin_hashes::hex::FromHex; use crate::error::{fmt_error_chain, BwtError, Error, OptionExt}; use crate::types::{BlockId, ScriptHash}; -use crate::{store, IndexChange, Query}; +use crate::{banner, store, IndexChange, Query}; type SyncChanSender = Arc>>; @@ -414,6 +414,13 @@ async fn run( .and(query.clone()) .map(|query: Arc| query.debug_index()); + // GET /banner.txt + let banner_handler = warp::get() + .and(warp::path!("banner.txt")) + .and(query.clone()) + .map(|query: Arc| banner::get_welcome_banner(&query, true)) + .map(handle_error); + // POST /sync let sync_handler = warp::post() .and(warp::path!("sync")) @@ -455,6 +462,7 @@ async fn run( fee_estimate_handler, dump_handler, debug_handler, + banner_handler, sync_handler, warp::any().map(|| StatusCode::NOT_FOUND) )