Browse Source

Extract code generating mempool.space URLs to avoid duplication

chore/leaner-release-process
Mariusz Klochowicz 3 years ago
parent
commit
1ddab68188
No known key found for this signature in database GPG Key ID: 470C865699C8D4D
  1. 11
      daemon/src/routes_taker.rs
  2. 17
      daemon/src/tx.rs

11
daemon/src/routes_taker.rs

@ -5,7 +5,7 @@ use daemon::model::{Leverage, Price, Usd, WalletInfo};
use daemon::projection::{CfdAction, Feeds};
use daemon::routes::EmbeddedFileExt;
use daemon::to_sse_event::{CfdsWithAuxData, ToSseEvent};
use daemon::{bitmex_price_feed, monitor, oracle, taker_cfd, wallet};
use daemon::{bitmex_price_feed, monitor, oracle, taker_cfd, tx, wallet};
use http_api_problem::{HttpApiProblem, StatusCode};
use rocket::http::{ContentType, Status};
use rocket::response::stream::EventStream;
@ -263,12 +263,5 @@ pub async fn post_withdraw_request(
.detail(e.to_string())
})?;
let url = match network.inner() {
Network::Bitcoin => format!("https://mempool.space/tx/{}", txid),
Network::Testnet => format!("https://mempool.space/testnet/tx/{}", txid),
Network::Signet => format!("https://mempool.space/signet/tx/{}", txid),
Network::Regtest => txid.to_string(),
};
Ok(url)
Ok(tx::to_mempool_url(txid, *network.inner()))
}

17
daemon/src/tx.rs

@ -9,16 +9,21 @@ pub struct TxUrl {
pub url: String,
}
/// Construct a mempool.space URL for a given txid
pub fn to_mempool_url(txid: Txid, network: Network) -> String {
match network {
Network::Bitcoin => format!("https://mempool.space/tx/{}", txid),
Network::Testnet => format!("https://mempool.space/testnet/tx/{}", txid),
Network::Signet => format!("https://mempool.space/signet/tx/{}", txid),
Network::Regtest => txid.to_string(),
}
}
impl TxUrl {
pub fn new(txid: Txid, network: Network, label: TxLabel) -> Self {
Self {
label,
url: match network {
Network::Bitcoin => format!("https://mempool.space/tx/{}", txid),
Network::Testnet => format!("https://mempool.space/testnet/tx/{}", txid),
Network::Signet => format!("https://mempool.space/signet/tx/{}", txid),
Network::Regtest => txid.to_string(),
},
url: to_mempool_url(txid, network),
}
}
}

Loading…
Cancel
Save