diff --git a/bitcoinlib/services/bitcoind.py b/bitcoinlib/services/bitcoind.py index 6bdb1878..62b34e91 100644 --- a/bitcoinlib/services/bitcoind.py +++ b/bitcoinlib/services/bitcoind.py @@ -53,10 +53,13 @@ class BitcoindClient(BaseClient): """ @staticmethod + @deprecated def from_config(configfile=None, network='bitcoin', *args): """ Read settings from bitcoind config file + Obsolete: does not work anymore, passwords are not stored in bitcoin config, only hashed password. + :param configfile: Path to config file. Leave empty to look in default places :type: str :param network: Bitcoin mainnet or testnet. Default is bitcoin mainnet @@ -129,6 +132,7 @@ def __init__(self, network='bitcoin', base_url='', denominator=100000000, *args) if isinstance(network, Network): network = network.name if not base_url: + _logger.warning("Please provide rpc connection url to bitcoind node") bdc = self.from_config('', network) base_url = bdc.base_url network = bdc.network @@ -332,12 +336,9 @@ def getinfo(self): from pprint import pprint - # 1. Connect by specifying connection URL - # base_url = 'http://bitcoinrpc:passwd@host:8332' - # bdc = BitcoindClient(base_url=base_url) - - # 2. Or connect using default settings or settings from config file - bdc = BitcoindClient() + # Connect by specifying connection URL + base_url = 'http://bitcoinrpc:passwd@host:8332' + bdc = BitcoindClient(base_url=base_url) print("\n=== SERVERINFO ===") pprint(bdc.proxy.getnetworkinfo()) diff --git a/docs/_static/manuals.setup-bcoin.rst b/docs/_static/manuals.setup-bcoin.rst index 8a1d3ba8..2f173ef1 100644 --- a/docs/_static/manuals.setup-bcoin.rst +++ b/docs/_static/manuals.setup-bcoin.rst @@ -1,4 +1,42 @@ -How to connect bitcoinlib to a Bcoin node +How to connect Bitcoinlib to a Bcoin node ========================================= -\ \ No newline at end of file +Bcoin is a full bitcoin node implementation, which can be used to parse the blockchain, send transactions and run a +wallet. With a Bcoin node you can retrieve transaction and utxo information for specific addresses, this is not easily +possible with a `Bitcoind `_ node. So if you want to use Bitcoinlib with a +wallet and not be dependant on external providers the best option is to run a local Bcoin node. + + +Install Bcoin node +------------------ + +You can find some instructions on how to install a bcoin node on https://coineva.com/install-bcoin-node-ubuntu.html. + +There are also some Docker images available. We have created a Docker image with the most optimal settings for +bitcoinlib. You can install them with the following command. + +.. code-block:: bash + + docker pull blocksmurfer/bcoin + + +Use Bcoin node with Bitcoinlib +------------------------------ + +To use Bcoin with bitcoinlib add the credentials to the providers.json configuration file in the .bitcoilib directory. + +.. code-block:: text + + "bcoin": { + "provider": "bcoin", + "network": "bitcoin", + "client_class": "BcoinClient", + "provider_coin_id": "", + "url": "https://user:pass@localhost:8332/", + "api_key": "", + "priority": 10, + "denominator": 100000000, + "network_overrides": null + }, + +You can increase the priority so the Service object always connects to the Bcoin node first. diff --git a/docs/_static/manuals.setup-bitcoind-connection.rst b/docs/_static/manuals.setup-bitcoind-connection.rst index 5854d0c6..f20e297e 100644 --- a/docs/_static/manuals.setup-bitcoind-connection.rst +++ b/docs/_static/manuals.setup-bitcoind-connection.rst @@ -37,33 +37,10 @@ and remove the 'testnet=1' line. rpcallowip=192.168.0.0/24 -Connect using config files --------------------------- - -Bitcoinlib looks for bitcoind config files on localhost. So if you running a full bitcoin node from -your local PC as the same user everything should work out of the box. - -Config files are read from the following files in this order: -* [USER_HOME_DIR]/.bitcoinlib/bitcoin.conf -* [USER_HOME_DIR]/.bitcoin/bitcoin.conf - -If your config files are at another location, you can specify this when you create a BitcoindClient -instance. - -.. code-block:: python - - from bitcoinlib.services.bitcoind import BitcoindClient - - bdc = BitcoindClient.from_config('/usr/local/src/.bitcoinlib/bitcoin.conf') - txid = 'e0cee8955f516d5ed333d081a4e2f55b999debfff91a49e8123d20f7ed647ac5' - rt = bdc.getrawtransaction(txid) - print("Raw: %s" % rt) - - Connect using provider settings ------------------------------- -Connection settings can also be added to the service provider settings file in +Connection settings can be added to the service provider settings file in .bitcoinlib/config/providers.json Example: @@ -86,7 +63,7 @@ Example: Connect using base_url argument ------------------------------- -Another options is to pass the 'base_url' argument to the BitcoindClient object directly. +You can also directly pass connection string wit the 'base_url' argument in the BitcoindClient object. This provides more flexibility but also the responsibility to store user and password information in a secure way. @@ -101,11 +78,27 @@ This provides more flexibility but also the responsibility to store user and pas print("Raw: %s" % rt) +You can directly r + +.. code-block:: python + + from bitcoinlib.services.bitcoind import BitcoindClient + + # Retrieve some blockchain information and statistics + bdc.proxy.getblockchaininfo() + bdc.proxy.getchaintxstats() + bdc.proxy.getmempoolinfo() + + # Add a node to the node list + bdc.proxy.addnode('blocksmurfer.io', 'add') + + + Please note: Using a remote bitcoind server ------------------------------------------- Using RPC over a public network is unsafe, so since bitcoind version 0.18 remote RPC for all network interfaces -is disabled. The rpcallowip option cannot be used to listen on all network interfaces and rpcbind has to be used to +are disabled. The rpcallowip option cannot be used to listen on all network interfaces and rpcbind has to be used to define specific IP addresses to listen on. See https://bitcoin.org/en/release/v0.18.0#configuration-option-changes You could setup a openvpn or ssh tunnel to connect to a remote server to avoid this issues. diff --git a/docs/index.rst b/docs/index.rst index 6fc68ca1..e466b2a4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -203,8 +203,9 @@ For more examples see https://github.com/1200wd/bitcoinlib/tree/master/examples Installation and Settings source/_static/manuals.command-line-wallet - Add Service Provider Bitcoind Node + Bcoin Node + Add Service Provider Databases Encrypted Database Security & Privacy