Skip to content

Commit

Permalink
Fix issue with excluded service providers for non-bitcoin networks
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryp Toon committed May 6, 2024
1 parent 814abfe commit a2784a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions bitcoinlib/services/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit a2784a1

Please sign in to comment.