Merge #1277: electrum: check connectivity before creating client

0f48db7a88b1dcaee68190a6a6ee5e73b5630f01 electrum: check connectivity before creating client (Michael Mallan)

Pull request description:

  This is to resolve https://github.com/wizardsardine/liana/issues/1276.

  Tested that this change stops GUI freezing in https://github.com/wizardsardine/liana/pull/1241 when using invalid address in Electrum settings.

ACKs for top commit:
  darosior:
    utACK 0f48db7a88b1dcaee68190a6a6ee5e73b5630f01

Tree-SHA512: b176ceafda887c4ef97110c6a87807787136da6fd67fb8a2af0b63c102a7d0145f46df5d75b61a10b45cf4cbc91ad27535de7abaf13409e259d1c75881abcef3
This commit is contained in:
Antoine Poinsot 2024-09-06 11:17:21 +02:00
commit c6e3053edf
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304

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))