From 6a2d0db674156c19ea15c8c892c3b5650ba05311 Mon Sep 17 00:00:00 2001 From: LLFourn Date: Sat, 5 Sep 2020 14:00:50 +1000 Subject: [PATCH] Remove assumed "/api" prefix from esplora It is not necessary that esplora is hosted with a /api prefix --- src/blockchain/esplora.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/blockchain/esplora.rs b/src/blockchain/esplora.rs index be83bbde..7eaf4b57 100644 --- a/src/blockchain/esplora.rs +++ b/src/blockchain/esplora.rs @@ -31,7 +31,7 @@ //! //! ```no_run //! # use magical::blockchain::esplora::EsploraBlockchain; -//! let blockchain = EsploraBlockchain::new("https://blockstream.info/testnet/"); +//! let blockchain = EsploraBlockchain::new("https://blockstream.info/testnet/api"); //! # Ok::<(), magical::Error>(()) //! ``` @@ -81,8 +81,6 @@ impl std::convert::From for EsploraBlockchain { impl EsploraBlockchain { /// Create a new instance of the client from a base URL - /// - /// The client internally adds the `/api` prefix to `base_url` before making any requests pub fn new(base_url: &str) -> Self { EsploraBlockchain(Some(UrlClient { url: base_url.to_string(), @@ -180,7 +178,7 @@ impl UrlClient { async fn _get_tx(&self, txid: &Txid) -> Result, EsploraError> { let resp = self .client - .get(&format!("{}/api/tx/{}/raw", self.url, txid)) + .get(&format!("{}/tx/{}/raw", self.url, txid)) .send() .await?; @@ -193,7 +191,7 @@ impl UrlClient { async fn _broadcast(&self, transaction: &Transaction) -> Result<(), EsploraError> { self.client - .post(&format!("{}/api/tx", self.url)) + .post(&format!("{}/tx", self.url)) .body(serialize(transaction).to_hex()) .send() .await? @@ -205,7 +203,7 @@ impl UrlClient { async fn _get_height(&self) -> Result { let req = self .client - .get(&format!("{}/api/blocks/tip/height", self.url)) + .get(&format!("{}/blocks/tip/height", self.url)) .send() .await?; @@ -223,7 +221,7 @@ impl UrlClient { result.extend( self.client .get(&format!( - "{}/api/scripthash/{}/txs/mempool", + "{}/scripthash/{}/txs/mempool", self.url, scripthash )) .send() @@ -251,7 +249,7 @@ impl UrlClient { let response = self .client .get(&format!( - "{}/api/scripthash/{}/txs/chain/{}", + "{}/scripthash/{}/txs/chain/{}", self.url, scripthash, last_txid )) .send() @@ -286,7 +284,7 @@ impl UrlClient { Ok(self .client .get(&format!( - "{}/api/scripthash/{}/utxo", + "{}/scripthash/{}/utxo", self.url, Self::script_to_scripthash(script) )) @@ -307,7 +305,7 @@ impl UrlClient { async fn _get_fee_estimates(&self) -> Result, EsploraError> { Ok(self .client - .get(&format!("{}/api/fee-estimates", self.url,)) + .get(&format!("{}/fee-estimates", self.url,)) .send() .await? .error_for_status()?