Skip to content

Commit

Permalink
grow to 0.6.2 (#115)
Browse files Browse the repository at this point in the history
* updates my info

* grow to 0.6.2

* Fix automatic sphinx documentation
  • Loading branch information
bjarnemagnussen committed Jul 10, 2020
1 parent e868993 commit de1942a
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 121 deletions.
2 changes: 1 addition & 1 deletion AUTHORS.rst
Expand Up @@ -12,4 +12,4 @@ Any PGP key fingerprints are enclosed in parentheses.

- Ofek Lev <ofekmeister@gmail.com> (FFB6 B92B 30B1 7848 546E 9912 972F E913 DAD5 A46E)
- Teran McKinney <sega01@go-beyond.org> (B372 6B4F 1567 9D12 6041 7D43 649B 929C 02EF 2CF2)
- Bjarne Magnussen <bjarne.magnussen@gmail.com>
- Bjarne Magnussen <bjarne@magnussen.casa> (F407 022B 0951 2719 7668 3BE0 B0A9 ADF6 B24C E67F)
9 changes: 8 additions & 1 deletion HISTORY.rst
Expand Up @@ -4,6 +4,13 @@ Release History
Unreleased (see `master <https://github.com/ofek/bit>`_)
--------------------------------------------------------

0.6.2 (2020-07-10)
------------------

- Fix of critical bug that could lead to paying high fees (see PR #116)
- Better fee calculation by estimating transaction sizes for multisig correctly
- Lots of Network API improvements: Removed deprecated Bitpay API and added Blockstream, Blockchair and Bitcore.

0.6.1 (2020-02-16)
------------------

Expand Down Expand Up @@ -40,7 +47,7 @@ Unreleased (see `master <https://github.com/ofek/bit>`_)
0.4.3 (2018-03-11)
------------------

- Fixed fee calculation when ``combine=False`
- Fixed fee calculation when ``combine=False``
- **Breaking:** Exceptions will now be raised when using pay2sh addresses (until implemented)

0.4.2 (2017-12-09)
Expand Down
2 changes: 1 addition & 1 deletion bit/__init__.py
Expand Up @@ -4,4 +4,4 @@
from bit.network.services import set_service_timeout
from bit.wallet import Key, PrivateKey, PrivateKeyTestnet, wif_to_key, MultiSig, MultiSigTestnet

__version__ = '0.6.1'
__version__ = '0.6.2'
10 changes: 9 additions & 1 deletion docs/source/dev/api.rst
Expand Up @@ -43,11 +43,19 @@ Network
:members:
:undoc-members:

.. autoclass:: bit.network.services.BitpayAPI
.. autoclass:: bit.network.services.BitCoreAPI
:members:
:undoc-members:
:inherited-members:

.. autoclass:: bit.network.services.BlockchairAPI
:members:
:undoc-members:

.. autoclass:: bit.network.services.BlockstreamAPI
:members:
:undoc-members:

.. autoclass:: bit.network.services.BlockchainAPI
:members:
:undoc-members:
Expand Down
4 changes: 2 additions & 2 deletions docs/source/guide/keys.rst
Expand Up @@ -77,7 +77,7 @@ sort the public keys internally in lexicographical order similar to how
`Electrum`_ behaves.
If the public keys are provided with a list, then the ordering of the public
keys of that list are used, similar to how Bitcoin Core behaves.
Calling :param:`~bit.MultiSig.public_keys` will always return a list with the
Calling :func:`~bit.MultiSig.public_keys` will always return a list with the
public keys in the order they are being used by in the multisignature contract.

Public Point
Expand All @@ -100,7 +100,7 @@ Public Key
----------

A public key is a public point serialized to bytes. By default all keys will
use the compressed version unless :ref:`you explicitly need otherwise <hextowif>`.
use the compressed version unless :ref:`you explicitly need otherwise <bytestowif>`.
This reduces the size of each transaction and thus fees.

Access it like so:
Expand Down
112 changes: 107 additions & 5 deletions docs/source/guide/network.rst
Expand Up @@ -138,14 +138,116 @@ many (1000+) transactions.
In those cases where the API may raise errors due to :class:`~bit.exceptions.ExcessiveAddress`
it is advised to use your own remote Bitcoin node to poll, see below.

Connect To Remote Node
----------------------
Using a Remote Bitcoin Core Node
================================

Bit can alternatively use a remote Bitcoin node to interact with the blockchain.

See the dedicated guide under :ref:`remote node <remotenode>` to configure Bit
to use a remote Bitcoin node instead of relying on web APIs for blockchain
interaction.
Instead of using web APIs to interact with the Bitcoin blockchain it is
possible to connect to a remote Bitcoin Core node. Bitcoin Core however is not
meant as a full-fledged blockchain explorer and does only keep track of
addresses associated with its wallet.

Transaction Database Index and ``txindex``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

By default Bitcoin Core does not maintain any transaction-level data except for
those transactions
- in the mempool or relay set
- pertinent to addresses in your wallet
- pertinent to your "watch-only" addresses

If querying arbitrary transactions is important then the option ``txindex`` must
be set to true (1) inside the Bitcoin Core configuration file. Setting this
option does not allow querying for arbitrary data on addresses, but only for
those that are added to the wallet in for Bitcoin Core to be fetched.

Configuring Bitcoin Core
^^^^^^^^^^^^^^^^^^^^^^^^

To use Bitcoin Core as a remote node it must accept remote procedure call (RPC)
methods from the host running Bit. A username and password for the RPC must be
defined inside the Bitcoin Core configuration file.

Adding a RPC user and password can be done with the ``rpcauth`` option that uses a
hashed password. The field comes in the format: ``<USERNAME>:<SALT>$<HASH>``. A
canonical python script is included inside Bitcoin Core's `share/rpcuser <https://github.com/bitcoin/bitcoin/tree/master/share/rpcauth>`_
directory. This python script creates such a user/password combination
(note that you are given the password, you do not get to specify it yourself).

Run the script, e.g.:

.. code-block:: python
>>> python ./rpcuser.py username
String to be appended to bitcoin.conf:
rpcauth=username:a14191e6892facf70686a397b126423$ddd6f7480817bd6f8083a2e07e24b93c4d74e667f3a001df26c5dd0ef5eafd0d
Your password:
VX3z87LBVc_X7NBLABLABLABLA
Note that this option can be specified multiple times.

Finally, make sure that Bitcoin Core will accept RPC methods from the host
running Bit. The option ``rpcallowip=<ip>`` allows RPC connections from specified
host IP. The default port used to listen to RPC methods can be set with the
option ``rpcport=<port>``; the default values being ``8332`` for mainnet, ``18332`` for
testnet and ``18443`` for regtest.

A default configuration file can be found inside the Bitcoin Core directory
under `share/examples/bitcoin.conf <https://github.com/bitcoin/bitcoin/blob/master/share/examples/bitcoin.conf>`_.

Connecting To The Node
^^^^^^^^^^^^^^^^^^^^^^

Connecting to a remote Bitcoin Core node from Bit is straight forward. It can be
done by calling :func:`~bit.network.services.NetworkAPI.connect_to_node`, e.g.

.. code-block:: python
>>> from bit.network import NetworkAPI
>>> NetworkAPI.connect_to_node(user='username', password='password', host='localhost', port=18443, use_https=False, testnet=True)
It is possible to connect to both a testnet and mainnet node by calling
:func:`~bit.network.services.NetworkAPI.connect_to_node` twice with the
arguments accordingly.

Using The Remote Bitcoin Core Node
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

After connecting to the remote node all API calls done by
:class:`~bit.network.services.NetworkAPI` are seamlessly redirected to it.

Adding An Address To The Internal Wallet Of A Node
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Bit will poll the node for data on an address using Bitcoin Core's internal
wallet. An address to poll must therefore first be imported to Bitcoin Core's
wallet.

We can directly access the Bitcoin Core node's RPC and then use ``importaddress``
to import a specific address as follows:

.. code-block:: python
>>> import bit
>>> from bit.network import NetworkAPI
>>> # Get the `node` object for direct access:
>>> node = NetworkAPI.connect_to_node(user='username', password='password', host='localhost', port=18443, use_https=False, testnet=True)
>>> key = bit.PrivateKeyTestnet()
>>> # Import an address to the node's wallet:
>>> node.importaddress(key.segwit_address, "optional-label", False)
You can read more about the RPC ``importaddress`` `here <https://bitcoincore.org/en/doc/0.18.0/rpc/wallet/importaddress/>`_.

As we had just created the new address we set the last argument in
``importaddress`` to ``False``, which defines that the node will not rescan the
blockchain for the address as it will not have any transactions yet. If you are
importing a *used* address you must set the rescan parameter to ``True``, as you
will otherwise receive incorrect information from your node!

Performing a rescan can take several minutes.


.. _satoshi: https://en.bitcoin.it/wiki/Satoshi_(unit)
.. _blockchain: https://en.bitcoin.it/wiki/Block_chain
Expand Down
110 changes: 0 additions & 110 deletions docs/source/guide/remotenode.rst

This file was deleted.

0 comments on commit de1942a

Please sign in to comment.