From bb98235ba689d79ab83e8d72fa2e4c46e7985dbc Mon Sep 17 00:00:00 2001 From: Cryp Toon Date: Tue, 24 Dec 2024 18:19:09 +0100 Subject: [PATCH] Add code for provider_name again --- bitcoinlib/services/services.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bitcoinlib/services/services.py b/bitcoinlib/services/services.py index 855d9a80..7b7e1ac1 100644 --- a/bitcoinlib/services/services.py +++ b/bitcoinlib/services/services.py @@ -113,13 +113,19 @@ def __init__(self, network=DEFAULT_NETWORK, min_providers=1, max_providers=1, pr raise ServiceError("Provider '%s' not found in provider definitions" % p) self.providers = {} - for p in self.providers_defined: - if ((self.providers_defined[p]['network'] == network or self.providers_defined[p]['network'] == '') and \ - (not providers or self.providers_defined[p]['provider'] in providers) - and (providers or self.providers_defined[p]['priority'])): - self.providers.update({p: self.providers_defined[p]}) - exclude_providers_keys = {pi: self.providers[pi]['provider'] for pi in self.providers if self.providers[pi]['provider'] in exclude_providers}.keys() - + if provider_name: + if provider_name not in self.providers_defined: + raise ServiceError("Provider with name '%s' not found in provider definitions" % provider_name) + if self.providers_defined[provider_name]['network'] != self.network: + raise ServiceError("Network from provider '%s' is different than Service network" % provider_name) + self.providers.update({provider_name: self.providers_defined[provider_name]}) + else: + for p in self.providers_defined: + 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]}) + 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])