electrum: check connectivity before creating client

This commit is contained in:
Michael Mallan 2024-09-06 09:05:51 +01:00
parent 8b76a6b977
commit 0f48db7a88
No known key found for this signature in database
GPG Key ID: 5177CDCEDB0EABEB

View File

@ -55,6 +55,12 @@ pub struct Client(electrum_client::Client);
impl Client {
/// Create a new client and perform sanity checks.
pub fn new(electrum_config: &config::ElectrumConfig) -> Result<Self, Error> {
// First use a dummy config to check connectivity (no retries, short timeout).
let dummy_config = Config::builder().retry(0).timeout(Some(3)).build();
bdk_electrum::electrum_client::Client::from_config(&electrum_config.addr, dummy_config)
.map_err(Error::Server)?;
// Now connection has been checked, create client with required retries and timeout.
let config = Config::builder()
.retry(RETRY_LIMIT)
.timeout(Some(RPC_SOCKET_TIMEOUT))