Skip to content

Commit

Permalink
Merge bugfix-2024-apr in release-v07
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryp Toon committed Apr 8, 2024
2 parents 482e9bc + 254d375 commit 2917687
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 61 deletions.
38 changes: 23 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ Python Bitcoin Library
Bitcoin cryptocurrency Library writen in Python.

Allows you to create a fully functional Bitcoin wallet with a single line of code.
Use this library to create and manage transactions, addresses/keys, wallets, mnemonic password phrases and blocks with
simple and straightforward Python code.
Use this library to create and manage transactions, addresses/keys, wallets, mnemonic password phrases
and blocks with simple and straightforward Python code.

You can use this library at a high level and create and manage wallets from the command line or at a low level
and create your own custom made transactions, scripts, keys or wallets.

The BitcoinLib connects to various service providers automatically to update wallets, transaction and
blockchain information.
blockchain information. You can also connect to a local
`Bitcoin <https://bitcoinlib.readthedocs.io/en/latest/source/_static/manuals.setup-bitcoind-connection.html>`_ or
`Bcoin node <https://bitcoinlib.readthedocs.io/en/latest/source/_static/manuals.setup-bcoin.html>`_.


.. image:: https://github.com/1200wd/bitcoinlib/actions/workflows/unittests.yaml/badge.svg
:target: https://github.com/1200wd/bitcoinlib/actions/workflows/unittests.yaml
Expand All @@ -30,7 +33,7 @@ blockchain information.
Install
-------

Installed required packages
Install required packages on Ubuntu or related Linux systems:

.. code-block:: bash
Expand All @@ -42,9 +45,11 @@ Then install using pip
$ pip install bitcoinlib
For more detailed installation instructions, how to install on other systems or troubleshooting please read https://bitcoinlib.readthedocs.io/en/latest/source/_static/manuals.install.html
Check out the `more detailed installation instructions <https://bitcoinlib.readthedocs.io/en/latest/source/_static/manuals.install.html>`_ to read how to install on other systems or for
troubleshooting.

If you are using docker you can check some Dockerfiles to create images in the docker directory.
If you are using docker you can check some Dockerfiles to create images in the
`docker <https://github.com/1200wd/bitcoinlib/tree/master/docker>`_ directory.

Documentation
-------------
Expand All @@ -65,7 +70,7 @@ Example: Create wallet and generate new address (key) to receive bitcoins
>>> from bitcoinlib.wallets import Wallet
>>> w = Wallet.create('Wallet1')
>>> w.get_key().address
'1Fo7STj6LdRhUuD1AiEsHpH65pXzraGJ9j'
'bc1qk25wwkvz3am9smmm3372xct5s7cwf0hmnq8szj'
Now send a small transaction to your wallet and use the scan() method to update transactions and UTXO's

Expand All @@ -79,23 +84,27 @@ If successful a transaction ID is returned

.. code-block:: pycon
>>> t = w.send_to('1PWXhWvUH3bcDWn6Fdq3xhMRPfxRXTjAi1', '0.001 BTC', offline=False)
>>> t = w.send_to('bc1qemtr8ywkzg483g8m34ukz2l4pl3730776vzq54', '0.001 BTC', offline=False)
'b7feea5e7c79d4f6f343b5ca28fa2a1fcacfe9a2b7f44f3d2fd8d6c2d82c4078'
>>> t.info # Shows transaction information and send results
More examples
-------------

Checkout the documentation page https://bitcoinlib.readthedocs.io/en/latest/ or take a look at some
more examples at https://github.com/1200wd/bitcoinlib/tree/master/examples
You can find many more examples in the `documentation <https://bitcoinlib.readthedocs.io/en/latest/>`_
for instance about the `Wallet.create() <https://bitcoinlib.readthedocs.io/en/latest/source/bitcoinlib.wallets.html#bitcoinlib.wallets.Wallet.create>`_ method.

There are many working examples on how to create wallets, specific transactions, encrypted databases, parse the
blockchain, connect to specific service providers in the `examples directory <https://github.com/1200wd/bitcoinlib/tree/master/examples>`_ in the source code of this library.

Some more specific examples can be found on the `Coineva website <https://coineva.com/category/bitcoinlib.html>`_.

Contact
-------

If you have any questions, encounter a problem or want to share an idea, please use Github Discussions
https://github.com/1200wd/bitcoinlib/discussions
If you have any questions, encounter a problem or want to share an idea, please use `Github Discussions
<https://github.com/1200wd/bitcoinlib/discussions>`_


Implements the following Bitcoin Improvement Proposals
Expand All @@ -115,13 +124,12 @@ Implements the following Bitcoin Improvement Proposals
Future / Roadmap
----------------

- Support advanced scripts
- Fully support timelocks
- Support for lightning network
- Support Taproot and Schnorr signatures
- Support advanced scripts
- Support for Trezor wallet or other hardware wallets
- Allow to scan full blockchain
- Integrate simple SPV client
- Support Schnorr signatures


Disclaimer
Expand Down
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
19 changes: 16 additions & 3 deletions bitcoinlib/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def wallets_list(db_uri=None, include_cosigners=False, db_password=None):
:type db_uri: str
:param include_cosigners: Child wallets for multisig wallets are for internal use only and are skipped by default
:type include_cosigners: bool
:param db_password: Password to use for encrypted database. Requires the installation of sqlcipher (see
documentation).
:param db_password: Password to use for encrypted database. Requires the installation of sqlcipher (see documentation).
:type db_password: str
:return dict: Dictionary of wallets defined in database
Expand Down Expand Up @@ -528,6 +527,20 @@ def name(self, value):
self._dbkey.name = value
self._commit()

@property
def keys_public(self):
if self.key_type == 'multisig':
return [k.public_byte for k in self.key()]
else:
return [self.key_public]

@property
def keys_private(self):
if self.key_type == 'multisig':
return [k.private_byte for k in self.key() if k.private_byte]
else:
return [self.key_private] if self.key_private else []

def key(self):
"""
Get HDKey object for current WalletKey
Expand Down Expand Up @@ -1442,7 +1455,7 @@ def __del__(self):
pass

def __repr__(self):
db_uri = self.db_uri.split('?')[0]
db_uri = '' if not self.db_uri else self.db_uri.split('?')[0]
if DEFAULT_DATABASE in db_uri:
return "<Wallet(name=\"%s\")>" % self.name
return "<Wallet(name=\"%s\", db_uri=\"%s\")>" % \
Expand Down
10 changes: 8 additions & 2 deletions docker/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@ Dockerfiles

You can find some basic Dockerfiles here for various system images.

These are used for testing and are not optimized for size and configuration. If you run the container is will
start all unittests.
These are used for testing and are not optimized for size and configuration. If you run the container it will
run all unittests.

.. code-block:: bash
$ cd <move to directory with the Dockerfile you want to use>
$ docker build -t bitcoinlib .
$ docker run -it bitcoinlib
22 changes: 22 additions & 0 deletions docker/mint/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM linuxmintd/mint22-amd64
MAINTAINER Cryp Toon <[email protected]>

WORKDIR /code

RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y \
software-properties-common git \
build-essential python3-dev libgmp3-dev python3-pip python3.12-venv

ENV TZ=Europe/Brussels
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get install -y postgresql postgresql-contrib mariadb-server libpq-dev pkg-config default-libmysqlclient-dev
RUN apt-get clean

RUN git clone https://github.com/1200wd/bitcoinlib.git

WORKDIR /code/bitcoinlib
RUN python3 -m venv /opt/venv
RUN /opt/venv/bin/python3 -m pip install .[dev]

CMD /opt/venv/bin/python3 -m unittest
71 changes: 71 additions & 0 deletions docs/_static/manuals.faq.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Frequently Asked Questions
==========================

Can I use Bitcoinlib on my system?
----------------------------------

BitcoinLib is platform independent and should run on your system.
Bitcoinlib is mainly developed on Ubuntu linux and runs unittests on every commit on Ubuntu and Windows.
Dockerfiles are available for Alpine, Kali and Fedora. You can find all dockerfiles on https://github.com/1200wd/bitcoinlib/tree/master/docker

I run into an error 'x' when installing Bitcoinlib
--------------------------------------------------

1. Check the `installation page <manuals.install.html>`_ and see if you have installed all the requirements.
2. Install the required packages one-by-one using pip install, and see if you get any specific errors.
3. Check for help in `Github Discussions <https://github.com/1200wd/bitcoinlib/discussions>`_.
4. See if you find any known `issue <https://github.com/1200wd/bitcoinlib/issues>`_.
5. If it doesn't work out, do not hesitate to ask you question in the github discussions or post an issue!

Does Bitcoinlib support 'x'-coin
--------------------------------

Bitcoinlib main focus is on Bitcoin. But besides Bitcoin it supports Litecoin and Dogecoin. For testing
it supports Bitcoin testnet3, Bitcoin regtest, Litecoin testnet and Dogecoin testnet.

Support for Dash, Bitcoin Cash and Bitcoin SV has been dropped.

There are currently no plans to support other coins. Main problem with supporting new coins is the lack of
service provides with a working and stable API.

My wallet transactions are not (correctly) updating!
----------------------------------------------------

Most likely cause is a problem with a specific service provider.

Please set log level to 'debug' and check the logs in bitcoinlib.log to see if you can pin down the specific error.
You could then disable the provider and post the `issue <https://github.com/1200wd/bitcoinlib/issues>`_.

To avoid these kind of errors it is adviced to run your local `Bcoin node <manuals.setup-bcoin.html>`_.
With a local Bcoin node you do not depend on external Service providers which increases reliability, security, speed
and privacy.

Can I use Bitcoinlib with another database besides SQLite?
----------------------------------------------------------

Yes, the library can also work with PostgreSQL or MySQL / MariaDB databases.
For more information see: `Databases <manuals.databases.html>`_.

I found a bug!
--------------

Please help out project and post your `issue <https://github.com/1200wd/bitcoinlib/issues>`_ on Github.
Try to include all code and data so we can reproduce and solve the issue.

I have another question
-----------------------

Maybe your question already has an answer om `Github Discussions <https://github.com/1200wd/bitcoinlib/discussions>`_.
Or search for an answer is this `documentation <https://bitcoinlib.readthedocs.io/en/latest/>`_.

If that does not answer your question, please post your question on on the
`Github Discussions Q&A <https://github.com/1200wd/bitcoinlib/discussions/categories/q-a>`_.



..
My transaction is not confirming
I have imported a private key but address from other wallet does not match Bitcoinlib's address
Is Bitcoinlib secure?
Donations?
14 changes: 9 additions & 5 deletions docs/_static/manuals.install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,19 @@ location for a config file in the BCL_CONFIG_FILE:
os.environ['BCL_CONFIG_FILE'] = '/var/www/blocksmurfer/bitcoinlib.ini'
Tweak BitcoinLib
----------------
Service providers and local nodes
---------------------------------

You can `Add another service Provider <manuals.add-provider.html>`_ to this library by updating settings
and write a new service provider class.

If you use this library in a production environment it is advised to run your own Bcoin, Bitcoin, Litecoin or Dash node,
both for privacy and reliability reasons. More setup information:
`Setup connection to bitcoin node <manuals.setup-bitcoind-connection.html>`_
To increase reliability, speed and privacy or if you use this library in a production environment it
is advised to run your own Bcoin or Bitcoin node.

More setup information:

* `Setup connection to Bcoin node <manuals.setup-bcoin.html>`_
* `Setup connection to Bitcoin node <manuals.setup-bitcoind-connection.html>`_

Some service providers require an API key to function or allow additional requests.
You can add this key to the provider settings file in .bitcoinlib/providers.json
6 changes: 3 additions & 3 deletions docs/_static/manuals.security.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
10 Security and Privacy Tips
============================
Frequently Asked Questions
==========================

Ten tips for more privacy and security when using Bitcoin and Bitcoinlib:

1. Run your own `Bitcoin <https://bitcoinlib.readthedocs.io/en/latest/source/_static/manuals.setup-bitcoind-connection.html>`_
or Bcoin node, so you are not depending on external Blockchain API service providers anymore.
or `Bcoin <manuals.setup-bcoin.html>`_ node, so you are not depending on external Blockchain API service providers anymore.
This not only increases your privacy, but also makes your application much faster and more reliable. And as extra bonus
you support the Bitcoin network.
2. Use multi-signature wallets. So you are able to store your private keys in separate (offline) locations.
Expand Down
42 changes: 42 additions & 0 deletions docs/_static/manuals.setup-bcoin.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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 .bitcoinlib directory.

.. code-block:: text
"bcoin": {
"provider": "bcoin",
"network": "bitcoin",
"client_class": "BcoinClient",
"provider_coin_id": "",
"url": "https://user:pass@localhost:8332/",
"api_key": "",
"priority": 20,
"denominator": 100000000,
"network_overrides": null
},
You can increase the priority so the Service object always connects to the Bcoin node first.
Loading

0 comments on commit 2917687

Please sign in to comment.