@@ -2,15 +2,16 @@ use bitcoin::{
22 block:: Header , consensus, hashes:: hex:: FromHex , BlockHash , CompactTarget , MerkleBlock , Network ,
33 Transaction , TxMerkleNode , Txid ,
44} ;
5- use eyre:: Result ;
5+ use eyre:: { Error , Result } ;
66use reqwest:: { Client , Url } ;
77use serde:: Deserialize ;
88use std:: str:: FromStr ;
99use tracing:: * ;
1010
11- const ESPLORA_MAINNET_URL : & str = "https://blockstream.info/api/ " ;
12- const ESPLORA_TESTNET_URL : & str = "https://blockstream.info/testnet/api/ " ;
11+ const ESPLORA_TESTNET_URL : & str = "https://btc-testnet.interlay.io " ;
12+ const ESPLORA_MAINNET_URL : & str = "https://btc-mainnet.interlay.io " ;
1313const ESPLORA_LOCALHOST_URL : & str = "http://localhost:3002" ;
14+ const ESPLORA_SIGNET_URL : & str = "https://btc-signet.gobob.xyz" ;
1415
1516// https://github.com/Blockstream/electrs/blob/adedee15f1fe460398a7045b292604df2161adc0/src/util/transaction.rs#L17-L26
1617#[ derive( Debug , Deserialize ) ]
@@ -76,6 +77,7 @@ impl EsploraClient {
7677 match network {
7778 Network :: Bitcoin => ESPLORA_MAINNET_URL ,
7879 Network :: Testnet => ESPLORA_TESTNET_URL ,
80+ Network :: Signet => ESPLORA_SIGNET_URL ,
7981 _ => ESPLORA_LOCALHOST_URL ,
8082 }
8183 . to_owned ( )
@@ -180,6 +182,18 @@ impl EsploraClient {
180182 }
181183 }
182184 }
185+
186+ pub async fn get_bitcoin_network ( & self ) -> Result < Network > {
187+ let url_str = self . url . as_str ( ) ;
188+
189+ match url_str {
190+ _ if url_str. contains ( ESPLORA_MAINNET_URL ) => Ok ( Network :: Bitcoin ) ,
191+ _ if url_str. contains ( ESPLORA_TESTNET_URL ) => Ok ( Network :: Testnet ) ,
192+ _ if url_str. contains ( ESPLORA_LOCALHOST_URL ) => Ok ( Network :: Regtest ) ,
193+ _ if url_str. contains ( ESPLORA_SIGNET_URL ) => Ok ( Network :: Signet ) ,
194+ _ => Err ( Error :: msg ( "Unknown network for URL: {url_str}" ) ) ,
195+ }
196+ }
183197}
184198
185199#[ cfg( test) ]
0 commit comments