Skip to content

Commit

Permalink
Add bcoin documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryp Toon committed Apr 3, 2024
1 parent 67d39a5 commit 2792f0f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 35 deletions.
13 changes: 7 additions & 6 deletions bitcoinlib/services/bitcoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
42 changes: 40 additions & 2 deletions docs/_static/manuals.setup-bcoin.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
How to connect bitcoinlib to a Bcoin node
How to connect Bitcoinlib to a Bcoin node
=========================================

\
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 <manuals.setup-bitcoind-connection.html>`_ 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.
45 changes: 19 additions & 26 deletions docs/_static/manuals.setup-bitcoind-connection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.

Expand All @@ -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.
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ For more examples see https://github.com/1200wd/bitcoinlib/tree/master/examples

Installation and Settings <source/_static/manuals.install>
source/_static/manuals.command-line-wallet
Add Service Provider <source/_static/manuals.add-provider>
Bitcoind Node <source/_static/manuals.setup-bitcoind-connection>
Bcoin Node <source/_static/manuals.setup-bcoin>
Add Service Provider <source/_static/manuals.add-provider>
Databases <source/_static/manuals.databases>
Encrypted Database <source/_static/manuals.sqlcipher>
Security & Privacy <source/_static/manuals.security>
Expand Down

0 comments on commit 2792f0f

Please sign in to comment.