Skip to content

Commit

Permalink
Move bitcoind wallet name to providerclient
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryp Toon committed Apr 8, 2024
1 parent 41bd1bc commit b267e67
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion bitcoinlib/services/baseclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __str__(self):
class BaseClient(object):

def __init__(self, network, provider, base_url, denominator, api_key='', provider_coin_id='',
network_overrides=None, timeout=TIMEOUT_REQUESTS, latest_block=None, strict=True):
network_overrides=None, timeout=TIMEOUT_REQUESTS, latest_block=None, strict=True, wallet_name=''):
try:
self.network = network
if not isinstance(network, Network):
Expand All @@ -62,6 +62,7 @@ def __init__(self, network, provider, base_url, denominator, api_key='', provide
if network_overrides is not None:
self.network_overrides = network_overrides
self.strict = strict
self.wallet_name = wallet_name
except Exception:
raise ClientError("This Network is not supported by %s Client" % provider)

Expand Down
7 changes: 5 additions & 2 deletions bitcoinlib/services/bitcoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def from_config(configfile=None, network='bitcoin', **kwargs):
url = "http://%s:%s@%s:%s" % (config.get('rpc', 'rpcuser'), config.get('rpc', 'rpcpassword'), server, port)
return BitcoindClient(network, url, **kwargs)

def __init__(self, network='bitcoin', base_url='', denominator=100000000, wallet_name='', *args):
def __init__(self, network='bitcoin', base_url='', denominator=100000000, *args):
"""
Open connection to bitcoin node
Expand All @@ -128,6 +128,8 @@ def __init__(self, network='bitcoin', base_url='', denominator=100000000, wallet
:type: str
:param denominator: Denominator for this currency. Should be always 100000000 (Satoshi's) for bitcoin
:type: str
:param wallet_name: Name of Bitcoin core wallet to use. Make sure the wallet exists, otherwise connection will fail.
:type str
"""
if isinstance(network, Network):
network = network.name
Expand All @@ -136,8 +138,9 @@ def __init__(self, network='bitcoin', base_url='', denominator=100000000, wallet
bdc = self.from_config('', network)
base_url = bdc.base_url
network = bdc.network
wallet_name = '' if not len(args) >= 6 else args[6]
if wallet_name:
base_url += "/wallet/%s" % wallet_name
base_url = base_url.replace("{wallet_name}", wallet_name)
_logger.info("Connect to bitcoind")
self.proxy = AuthServiceProxy(base_url)
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args)
Expand Down
9 changes: 3 additions & 6 deletions bitcoinlib/services/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,11 @@ def _provider_execute(self, method, *arguments):
client = getattr(services, self.providers[sp]['provider'])
providerclient = getattr(client, self.providers[sp]['client_class'])

base_url = self.providers[sp]['url']
if 'bitcoind' in sp and self.wallet_name is not None:
base_url = f"{base_url}/wallet/{self.wallet_name}"

pc_instance = providerclient(
self.network, base_url, self.providers[sp]['denominator'],
self.network, self.providers[sp]['url'], self.providers[sp]['denominator'],
self.providers[sp]['api_key'], self.providers[sp]['provider_coin_id'],
self.providers[sp]['network_overrides'], self.timeout, self._blockcount, self.strict)
self.providers[sp]['network_overrides'], self.timeout, self._blockcount, self.strict,
self.wallet_name)
if not hasattr(pc_instance, method):
_logger.debug("Method %s not found for provider %s" % (method, sp))
continue
Expand Down

0 comments on commit b267e67

Please sign in to comment.