Skip to content

Commit 51a5610

Browse files
authored
Merge pull request #576 from bob-collective/fix/add-missing-methods-use-in-gateway
Fix: add missing methods used in gateway + update constants
2 parents f1a1d38 + c54dd19 commit 51a5610

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

crates/utils/src/bitcoin_core.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ impl BitcoinCoreInstance {
6464
client.generate_to_address(101, &address)?;
6565
Ok(())
6666
}
67+
68+
pub fn fund_to_specific_address(&self, address: &bitcoin::Address) -> Result<()> {
69+
let client = self.client(None)?;
70+
client.generate_to_address(101, address)?;
71+
Ok(())
72+
}
6773
}
6874

6975
impl Drop for BitcoinCoreInstance {

crates/utils/src/esplora_client.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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};
66
use reqwest::{Client, Url};
77
use serde::Deserialize;
88
use std::str::FromStr;
99
use 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";
1313
const 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

Comments
 (0)