From a2784a1ba2798bd7deef262d19b97265c299e169 Mon Sep 17 00:00:00 2001 From: Cryp Toon Date: Mon, 6 May 2024 17:45:52 +0200 Subject: [PATCH] Fix issue with excluded service providers for non-bitcoin networks --- bitcoinlib/services/services.py | 9 +++++---- tests/test_wallets.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bitcoinlib/services/services.py b/bitcoinlib/services/services.py index 59934ec3..7c476f97 100644 --- a/bitcoinlib/services/services.py +++ b/bitcoinlib/services/services.py @@ -113,9 +113,9 @@ def __init__(self, network=DEFAULT_NETWORK, min_providers=1, max_providers=1, pr if (self.providers_defined[p]['network'] == network or self.providers_defined[p]['network'] == '') and \ (not providers or self.providers_defined[p]['provider'] in providers): self.providers.update({p: self.providers_defined[p]}) - for nop in exclude_providers: - if nop in self.providers: - del(self.providers[nop]) + exclude_providers_keys = {pi: self.providers[pi]['provider'] for pi in self.providers if self.providers[pi]['provider'] in exclude_providers}.keys() + for provider_key in exclude_providers_keys: + del(self.providers[provider_key]) if not self.providers: raise ServiceError("No providers found for network %s" % network) @@ -141,7 +141,8 @@ def __init__(self, network=DEFAULT_NETWORK, min_providers=1, max_providers=1, pr self.ignore_priority = ignore_priority self.strict = strict if self.min_providers > 1: - self._blockcount = Service(network=network, cache_uri=cache_uri).blockcount() + self._blockcount = Service(network=network, cache_uri=cache_uri, providers=providers, + exclude_providers=exclude_providers, timeout=timeout).blockcount() else: self._blockcount = self.blockcount() diff --git a/tests/test_wallets.py b/tests/test_wallets.py index 837f5dd2..a010b488 100644 --- a/tests/test_wallets.py +++ b/tests/test_wallets.py @@ -2365,7 +2365,7 @@ def test_wallet_anti_fee_sniping(self): w = wallet_create_or_open('antifeesnipingtestwallet', network='testnet', db_uri=self.database_uri) w.utxo_add(w.get_key().address, 1234567, os.urandom(32).hex(), 1) t = w.send_to('tb1qrjtz22q59e76mhumy0p586cqukatw5vcd0xvvz', 123456) - block_height = Service(network='testnet', exclude_providers=['bitgo', 'bitaps']).blockcount() + block_height = Service(network='testnet', exclude_providers=['bitgo', 'bitaps'], cache_uri='').blockcount() # Bitaps and Bitgo return incorrect blockcount for testnet, so set delta self.assertAlmostEqual(t.locktime, block_height+1, delta=3)