Remove assumed "/api" prefix from esplora
It is not necessary that esplora is hosted with a /api prefix
This commit is contained in:
parent
7b58a4ad6f
commit
6a2d0db674
@ -31,7 +31,7 @@
|
|||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! # use magical::blockchain::esplora::EsploraBlockchain;
|
//! # 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>(())
|
//! # Ok::<(), magical::Error>(())
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
@ -81,8 +81,6 @@ impl std::convert::From<UrlClient> for EsploraBlockchain {
|
|||||||
|
|
||||||
impl EsploraBlockchain {
|
impl EsploraBlockchain {
|
||||||
/// Create a new instance of the client from a base URL
|
/// 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 {
|
pub fn new(base_url: &str) -> Self {
|
||||||
EsploraBlockchain(Some(UrlClient {
|
EsploraBlockchain(Some(UrlClient {
|
||||||
url: base_url.to_string(),
|
url: base_url.to_string(),
|
||||||
@ -180,7 +178,7 @@ impl UrlClient {
|
|||||||
async fn _get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, EsploraError> {
|
async fn _get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, EsploraError> {
|
||||||
let resp = self
|
let resp = self
|
||||||
.client
|
.client
|
||||||
.get(&format!("{}/api/tx/{}/raw", self.url, txid))
|
.get(&format!("{}/tx/{}/raw", self.url, txid))
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@ -193,7 +191,7 @@ impl UrlClient {
|
|||||||
|
|
||||||
async fn _broadcast(&self, transaction: &Transaction) -> Result<(), EsploraError> {
|
async fn _broadcast(&self, transaction: &Transaction) -> Result<(), EsploraError> {
|
||||||
self.client
|
self.client
|
||||||
.post(&format!("{}/api/tx", self.url))
|
.post(&format!("{}/tx", self.url))
|
||||||
.body(serialize(transaction).to_hex())
|
.body(serialize(transaction).to_hex())
|
||||||
.send()
|
.send()
|
||||||
.await?
|
.await?
|
||||||
@ -205,7 +203,7 @@ impl UrlClient {
|
|||||||
async fn _get_height(&self) -> Result<u32, EsploraError> {
|
async fn _get_height(&self) -> Result<u32, EsploraError> {
|
||||||
let req = self
|
let req = self
|
||||||
.client
|
.client
|
||||||
.get(&format!("{}/api/blocks/tip/height", self.url))
|
.get(&format!("{}/blocks/tip/height", self.url))
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@ -223,7 +221,7 @@ impl UrlClient {
|
|||||||
result.extend(
|
result.extend(
|
||||||
self.client
|
self.client
|
||||||
.get(&format!(
|
.get(&format!(
|
||||||
"{}/api/scripthash/{}/txs/mempool",
|
"{}/scripthash/{}/txs/mempool",
|
||||||
self.url, scripthash
|
self.url, scripthash
|
||||||
))
|
))
|
||||||
.send()
|
.send()
|
||||||
@ -251,7 +249,7 @@ impl UrlClient {
|
|||||||
let response = self
|
let response = self
|
||||||
.client
|
.client
|
||||||
.get(&format!(
|
.get(&format!(
|
||||||
"{}/api/scripthash/{}/txs/chain/{}",
|
"{}/scripthash/{}/txs/chain/{}",
|
||||||
self.url, scripthash, last_txid
|
self.url, scripthash, last_txid
|
||||||
))
|
))
|
||||||
.send()
|
.send()
|
||||||
@ -286,7 +284,7 @@ impl UrlClient {
|
|||||||
Ok(self
|
Ok(self
|
||||||
.client
|
.client
|
||||||
.get(&format!(
|
.get(&format!(
|
||||||
"{}/api/scripthash/{}/utxo",
|
"{}/scripthash/{}/utxo",
|
||||||
self.url,
|
self.url,
|
||||||
Self::script_to_scripthash(script)
|
Self::script_to_scripthash(script)
|
||||||
))
|
))
|
||||||
@ -307,7 +305,7 @@ impl UrlClient {
|
|||||||
async fn _get_fee_estimates(&self) -> Result<HashMap<String, f64>, EsploraError> {
|
async fn _get_fee_estimates(&self) -> Result<HashMap<String, f64>, EsploraError> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.client
|
.client
|
||||||
.get(&format!("{}/api/fee-estimates", self.url,))
|
.get(&format!("{}/fee-estimates", self.url,))
|
||||||
.send()
|
.send()
|
||||||
.await?
|
.await?
|
||||||
.error_for_status()?
|
.error_for_status()?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user