• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

bitcoin/H06-Mar-2020-12,6199,781

python_bitcoinlib.egg-info/H03-May-2022-12885

LICENSEH A D25-Sep-20148 KiB178136

MANIFEST.inH A D24-Dec-201852 32

PKG-INFOH A D06-Mar-20205.3 KiB12885

README.mdH A D03-Oct-20193.9 KiB11674

setup.cfgH A D06-Mar-202038 53

setup.pyH A D24-Dec-2018840 3023

README.md

1# python-bitcoinlib
2
3This Python3 library provides an easy interface to the bitcoin data
4structures and protocol. The approach is low-level and "ground up", with a
5focus on providing tools to manipulate the internals of how Bitcoin works.
6
7"The Swiss Army Knife of the Bitcoin protocol." - Wladimir J. van der Laan
8
9
10## Requirements
11
12    sudo apt-get install libssl-dev
13
14The RPC interface, `bitcoin.rpc`, is designed to work with Bitcoin Core v0.16.0.
15Older versions may work but there do exist some incompatibilities.
16
17
18## Structure
19
20Everything consensus critical is found in the modules under bitcoin.core. This
21rule is followed pretty strictly, for instance chain parameters are split into
22consensus critical and non-consensus-critical.
23
24    bitcoin.core            - Basic core definitions, datastructures, and
25                              (context-independent) validation
26    bitcoin.core.key        - ECC pubkeys
27    bitcoin.core.script     - Scripts and opcodes
28    bitcoin.core.scripteval - Script evaluation/verification
29    bitcoin.core.serialize  - Serialization
30
31In the future the bitcoin.core may use the Satoshi sourcecode directly as a
32library. Non-consensus critical modules include the following:
33
34    bitcoin          - Chain selection
35    bitcoin.base58   - Base58 encoding
36    bitcoin.bloom    - Bloom filters (incomplete)
37    bitcoin.net      - Network communication (in flux)
38    bitcoin.messages - Network messages (in flux)
39    bitcoin.rpc      - Bitcoin Core RPC interface support
40    bitcoin.wallet   - Wallet-related code, currently Bitcoin address and
41                       private key support
42
43Effort has been made to follow the Satoshi source relatively closely, for
44instance Python code and classes that duplicate the functionality of
45corresponding Satoshi C++ code uses the same naming conventions: CTransaction,
46CBlockHeader, nValue etc. Otherwise Python naming conventions are followed.
47
48
49## Mutable vs. Immutable objects
50
51Like the Bitcoin Core codebase CTransaction is immutable and
52CMutableTransaction is mutable; unlike the Bitcoin Core codebase this
53distinction also applies to COutPoint, CTxIn, CTxOut, and CBlock.
54
55
56## Endianness Gotchas
57
58Rather confusingly Bitcoin Core shows transaction and block hashes as
59little-endian hex rather than the big-endian the rest of the world uses for
60SHA256. python-bitcoinlib provides the convenience functions x() and lx() in
61bitcoin.core to convert from big-endian and little-endian hex to raw bytes to
62accomodate this. In addition see b2x() and b2lx() for conversion from bytes to
63big/little-endian hex.
64
65
66## Module import style
67
68While not always good style, it's often convenient for quick scripts if
69`import *` can be used. To support that all the modules have `__all__` defined
70appropriately.
71
72
73# Example Code
74
75See `examples/` directory. For instance this example creates a transaction
76spending a pay-to-script-hash transaction output:
77
78    $ PYTHONPATH=. examples/spend-pay-to-script-hash-txout.py
79    <hex-encoded transaction>
80
81
82## Selecting the chain to use
83
84Do the following:
85
86    import bitcoin
87    bitcoin.SelectParams(NAME)
88
89Where NAME is one of 'testnet', 'mainnet', or 'regtest'. The chain currently
90selected is a global variable that changes behavior everywhere, just like in
91the Satoshi codebase.
92
93
94## Unit tests
95
96Under bitcoin/tests using test data from Bitcoin Core. To run them:
97
98    python3 -m unittest discover
99
100Alternately, if Tox (see https://tox.readthedocs.org/) is available on your
101system, you can run unit tests for multiple Python versions:
102
103    ./runtests.sh
104
105HTML coverage reports can then be found in the htmlcov/ subdirectory.
106
107## Documentation
108
109Sphinx documentation is in the "doc" subdirectory. Run "make help" from there
110to see how to build. You will need the Python "sphinx" package installed.
111
112Currently this is just API documentation generated from the code and
113docstrings. Higher level written docs would be useful, perhaps starting with
114much of this README. Pages are written in reStructuredText and linked from
115index.rst.
116